⬆️ ⬇️

Easy publication of PEAR packages

I will say right away: it took me about an hour to create a PEAR channel and publish a package. But, if we reject all dead-end ways, save on Google, and do not use questionable utilities, then it is quite possible to keep within 10 minutes.



PHP programmers have more reasons to dislike PEAR than to love. Indeed, it seems that over the past 5 years, neither the libraries in the repositories, nor the installer itself, have changed much.

However, so far, installing the PHP library is easiest through PEAR. This, of course, provided that it will be equally in demand for the entire system. For example, products such as PHPUnit and Docblox are installed through PEAR, and it is extremely inconvenient to install them in other ways: for example, by cloning a GitHub repository.



Most likely you have a library that you would like to share with the community. Well, or sometime will appear. It does not matter. The important thing is that sooner or later you will want to make sure that your product can be installed in just 2 teams ...



Such is the introduction. Further there will be purely practical recommendations.

One of them: documentation from pear.php.net can not only help but also harm. Understanding all these PEAR, PEAR2, Pyrus, PEAR_PackageFileManager2, as well as the package.xml structure, is equivalent to studying the service instructions of a nuclear power plant. You see, we can do without all this. In addition, we are limited in time, and we definitely will not have enough time to study the extra details of 10 minutes. And hours too.

')

We will be pragmatists, rationalists, well, just lazy.

For example, we are too lazy to create our own PEAR server somewhere on our hosting. And why? It is better to adapt GitHub for this business.



First we need Pirum . This is a lightweight PEAR channel manager.



It is installed, oddly enough, also through PEAR:

$ pear channel-discover pear.pirum-project.org $ pear install pirum/Pirum 


The server itself, configured for GitHub, can be found here: github.com/saucelabs/pear



Follow the instructions:

Create a pear repository on the githaba.



Create a local repository:

 $ mkdir pear $ cd pear $ git init $ git remote add origin git@github.com:[username]/pear.git 


Create a configuration file pirum.xml:

 <?xml version="1.0" encoding="UTF-8" ?> <server> <name>[username].github.com/pear</name> <summary>[channel name]</summary> <alias>[shortname]</alias> <url>http://[username].github.com/pear</url> </server> 




Execute commands

 $ pirum build . $ git add . $ git commit -m "Initial server build" 


Fill our repository on githab, disguised as github pages:

 $ git branch -m master gh-pages $ git push origin gh-pages 


Let me remind you, the githab allows you to own your static site, for which a special branch is used: gh-pages.

After we uploaded the repository to the server, the new channel will already be located at https: // [username] .github.com / pear.

There, by the way, and instructions for its use. It is a pity that there is nothing to put from there.



We correct this defect. We need a properly created pear package for our library.

Pearfarm utility will help to create it. This is not only a utility, but also a website with the hosting of pear-packages, but unfortunately, it is not very popular.

In fact, we would not need to go through the steps above if there were more confidence in Pearfarm.



However, the utility itself works and significantly simplifies life when creating a package from scratch.

Install it ... That's right, also through PEAR:

 $ pear install pearfarm.pearfarm.org/pearfarm 


In the directory with your library run the command:

 $ pearfarm init 




It creates a file pearfarm.spec, let's call it a meta package. In essence, this is a PHP file that in a convenient form determines the settings for creating a package.

Here he is:



 <?php $spec = Pearfarm_PackageSpec::create(array(Pearfarm_PackageSpec::OPT_BASEDIR => dirname(__FILE__))) ->setName('[dirname]') ->setChannel('TODO: Release channel here') ->setSummary('TODO: One-line summary of your PEAR package') ->setDescription('TODO: Longer description of your PEAR package') ->setReleaseVersion('0.0.1') ->setReleaseStability('alpha') ->setApiVersion('0.0.1') ->setApiStability('alpha') ->setLicense(Pearfarm_PackageSpec::LICENSE_MIT) ->setNotes('Initial release.') ->addMaintainer('lead', 'TODO: Your name here', 'TODO: Your username here', 'TODO: Your email here') ->addGitFiles() ->addExecutable('[dirname]') ; 




You just have to go through all the fields and fill them. Please note how easy it is to fill out a license! By default, all files from the git repository will be included in the package; you can remove some of them using the addExcludeFilesRegex () method.

More information on configuring here: pearfarm.org/help/spec



After filling in all the fields, connect to our pear-channel:

 $ pear channel-discover [username].github.com/pear 




And create a package.

 $ pearfarm build 


And if everything went well, you will receive a package.xml file (package configuration for PEAR) and a fresh build of your library in the output.



Add the build to the server:

 $ pirum add [---pear-] [--] 


Fill in the updated githab server:

 $ git add . $ git commit -m "first package added" $ git push origin gh-pages 




Done! Now you can easily publish your open-source libraries and no longer hide them in the depths of local web servers.



And to make sure everything works, let's go to:



http: // [username] .github.com / pear /



And we will see that our package is already there. All commands for installing your library are also listed there.

Create useful libraries, publish them, write about them on Habré.



Thanks for attention.



Also note that:

- Everything works on Windows.

- You should not use upper case in the name of the channel server. PEAR is not friendly with them.

Source: https://habr.com/ru/post/134833/



All Articles