Skip to content

Installing libraries for usage in pantrfiles

pago edited this page Apr 15, 2011 · 3 revisions

Since pantr has been created to automate your usual processes, you might want to make certain libraries available in all your pantrfiles. A rather stupid solution is to install those libraries using pear. It’s stupid since it’ll force you to use that library version in all of your php projects. You could fix that if you lay out your include path properly but easy is usually better than smart, thus pantr provides a set of commands to manage a pear repository which is made available to your pantrfiles but not outside of those.

To access these specific pear commands, use the :bundle command:

$ pantr :bundle channel-discover pear.pagosoft.com
$ pantr :bundle install pgs/util

and so on. pantr stores these files in PANTR_HOME (default: ~/.pantr and ~/Library/Application Support/pantr on mac – unless ~/.pantr exists).
It is managed with pear but you can place any files you’d like to be available in all your pantrfiles in that directory. This includes configuration files (the config facade) and any php file.

Since version 0.8.1 there is also an alternative way to install packages directly from within the pantrfile.

<?php
namespace pantr\file;

use pantr\pantr;
use Pearfarm_PackageSpec;

if(!class_exists('Pearfarm_PackageSpec')) {
	// try to install it now
	silent(function() {
		$repo = pantr::getRepository();
		if(!$repo->hasChannel('pearfarm')) {
			$repo->discoverChannel('pearfarm.pearfarm.org');
		}
		$repo->install('pearfarm/pearfarm');
	});
	
	if(!class_exists('Pearfarm_PackageSpec')) {
		throw new \Exception('Pearfarm is not installed!');
	} else {
		writeAction('install', 'Pearfarm');
	}
}

The code above is used to install Pearfarm on demand.

Clone this wiki locally