Page 1 of 1
Creating a package system
Posted: Sat Jan 12, 2008 9:43 am
by Zeggy
Hi, I want to learn how to create a package system like SMF's package system so that I can release modifications to my script easily.
Does anybody know how the package system in SMF works, and how I could code something similar? It doesn't need to be very advanced, just a simple one will do.
Or, does anybody know of another way in which I can release code modifications easily?
Re: Creating a package system
Posted: Sat Jan 12, 2008 4:32 pm
by Ambush Commander
Check out PEAR and PEAR_PackageFileManager2
Re: Creating a package system
Posted: Sat Jan 12, 2008 6:30 pm
by s.dot
Your system can be incredibly simple. It can be as simple as defining a constant in your package release like so:
Code: Select all
<?php
define('PACKAGE_VERSION', 1.0.11);
?>
And having a text file or something on the central download site with the current version of the package.
Then you'd just need a page or a portion of a page to check against the central download site:
[code="php"]<?php
if ($currentVersion = @file_get_contents('http://www.example.com'))
{
if ($currentVersion > PACKAGE_VERSION)
{
echo 'your package is out of date!';
}
}
This assumes allow_url_fopen in php.ini, but is workable.
Re: Creating a package system
Posted: Sun Jan 13, 2008 9:51 am
by Zeggy
Um, I have a version constant and a version check in my script, the problem is having the script download a package and automatically patch the files, like in SMF.
I'll take a look at PEAR_PackageFileManager2, but I'm confused about how PEAR works... :/
Re: Creating a package system
Posted: Mon Jan 14, 2008 1:32 pm
by Zeggy
Okay, I've looked at PEAR_PackageFileManager2, but it seems to be for managing PEAR packages.
I was wondering how I could code something similar, but simple, myself.
I was thinking about SMF as an example. Here's an old type of package file that they used to use:
Code: Select all
-- This information needs to be the same as that in the package-info.xml. --
<id>username:testing123</id>
<version>1.0</version>
-- Edit a specific file.. --
<edit file>$sourcedir/Filename.php</edit file>
-- The code to search for. --
<search for>
Search for some code to add stuff after.
</search for>
-- Add this text when we find it, after what we found. -->
<add after>
This is what to add.
</add after>
<search for>
Another search operation?
</search for>
<replace>
Yes, another. This time, replacing!
</replace>
And to install a package, they'd just have different files that will tell a script what to do.
I'm just stuck on how I could parse this kind of file and then perform the actions. What functions would I use for what?