Creating a package system

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Zeggy
Forum Newbie
Posts: 6
Joined: Tue Jan 08, 2008 11:19 am

Creating a package system

Post 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?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Re: Creating a package system

Post by Ambush Commander »

Check out PEAR and PEAR_PackageFileManager2
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Creating a package system

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Zeggy
Forum Newbie
Posts: 6
Joined: Tue Jan 08, 2008 11:19 am

Re: Creating a package system

Post 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... :/
Zeggy
Forum Newbie
Posts: 6
Joined: Tue Jan 08, 2008 11:19 am

Re: Creating a package system

Post 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?
Post Reply