Skip to content
Browse files

Basic package bundling supported

  • Loading branch information...
1 parent e5ebf90 commit 3371aeaa77588dd9de11618df38e974da6cde755 @lox committed May 24, 2011
View
2 Pharkspec
@@ -8,7 +8,7 @@ $spec
->phpVersion('>=5.3.1')
->summary('A package manager for PHP5.3+')
->description('Phark manages packages, making it easy to install, upgrade and remove, either per project or globally.')
- ->devDependency('simpletest','>=2.0.1beta')
+ ->dependency('simpletest','>=1.1.0beta')
->files('phark.php','lib/**','bin/**')
->includePath('lib')
->executables('bin/phark')
View
7 STATUS.md
@@ -14,6 +14,7 @@ What's working?
* Local package installation. `phark install <directory>`.
* Listing local packages and project packages `phark list`
* Show working environment with `phark environment`
+* Basic bundling
What needs doing?
-----------------
@@ -26,11 +27,13 @@ What needs doing?
What's left for the future
--------------------------
+
+* Package signing, web of trust
* Web app for pharkphp.org (signup, register cert, accept package)
* Submitting phark files to pharkphp.org. `phark publish`
* Searching remote specifications (proper search)
-* Package signing (needed for publishing files)
* Support grouped dependencies (developent deps only, for instance)
* GIT support in Pharkdeps
* SVN support in Pharkdeps
-* Dependency locking. `Pharkdeps.lock
+* PEAR support in Pharkdeps
+* Dependency locking. `Pharkdeps.lock`
View
2 bin/phark
@@ -15,6 +15,8 @@ $commandline
->register("help", new \Phark\Command\HelpCommand())
->register("environment", new \Phark\Command\EnvironmentCommand())
->register("list", new \Phark\Command\ListCommand())
+ ->register("deps", new \Phark\Command\DependenciesCommand())
+ ->register("bundle", new \Phark\Command\BundleCommand())
;
// show help
View
33 lib/Phark/Bundler.php
@@ -7,14 +7,17 @@
*/
class Bundler
{
- private $_package;
+ const FORMAT_VERSION=1;
+
+ private $_package, $_env;
/**
* Constructor
*/
- public function __construct($package)
+ public function __construct($package, $env=null)
{
$this->_package = $package;
+ $this->_env = $env ?: new Environment();
}
/**
@@ -30,19 +33,31 @@ public function pharfile()
* Builds a {@link Phar} archive in the specified directory
* @return Phar
*/
- public function bundle($dirname)
+ public function bundle($dirname, $overwrite=false)
{
- if(ini_get('phar.readonly'))
+ if(!\Phar::canWrite())
throw new Exception("unable to bundle packages when phar.readonly=1 (php.ini)");
- $filename = new Path($dirname, $this->pharfile());
+ $filename = (string)new Path($dirname, $this->pharfile());
+
+ if($this->_env->shell()->isfile($filename))
+ {
+ if($overwrite)
+ $this->_env->shell()->unlink($filename);
+ else
+ throw new Exception("$filename already exists");
+ }
- //TODO: write as TAR and convert to PHAR on the serverside?
- $p = new \Phar($filename, 0, $this->pharfile());
+ $phar = new \Phar($filename, 0, $this->pharfile());
foreach($this->_package->spec()->files() as $file)
- $p->addFile(new Path($this->_package->directory(), $file), $file);
+ $phar->addFile(new Path($this->_package->directory(), $file), $file);
+
+ $phar->setMetadata(array(
+ 'pharkversion'=>\Phark::VERSION,
+ 'bundleversion'=>Bundler::FORMAT_VERSION,
+ ));
- return $p;
+ return $phar;
}
}
View
33 lib/Phark/Command/BundleCommand.php
@@ -0,0 +1,33 @@
+<?php
+
+namespace Phark\Command;
+
+use \Phark\Path;
+use \Phark\Exception;
+
+class BundleCommand implements \Phark\Command
+{
+ public function summary()
+ {
+ return 'Bundle the current directory into a package';
+ }
+
+ public function execute($args, $env)
+ {
+ $opts = new \Phark\Options($args);
+ $result = $opts->parse(array('-f'), array('command'));
+
+ $shell = $env->shell();
+ $package = new \Phark\Package($shell->getcwd());
+
+ $shell->printf(" * bundling %s %s\n",
+ $package->spec()->name(), $package->spec()->version());
+
+ $bundler = new \Phark\Bundler($package);
+ $phar = $bundler->bundle($shell->getcwd(), isset($result->opts['-f']));
+
+ $shell->printf(" * wrote %d files into %s √\n", count($phar), $bundler->pharfile());
+ }
+}
+
+
View
4 lib/Phark/Command/InstallCommand.php
@@ -12,10 +12,10 @@ public function summary()
public function execute($args, $env)
{
$opts = new \Phark\Options($args);
- $result = $opts->parse(array('f'), array('command','package'));
+ $result = $opts->parse(array('-f'), array('command','package'));
// if a directory is specified
- if($realpath = realpath($result->params['package']))
+ if($realpath = $env->shell()->realpath($result->params['package']))
{
$env->shell()->printf(" * installing from %s\n", $realpath);
View
2 lib/Phark/Project.php
@@ -52,7 +52,7 @@ public static function locate($env=null)
else
$dir = dirname($dir);
}
- while(!$projectRoot && $dir);
+ while(!$projectRoot && $dir != '/');
if($projectRoot)
return new self($projectRoot);
View
31 lib/Phark/Shell.php
@@ -36,6 +36,22 @@ public function glob($basedir, $pattern)
return $files;
}
+ /**
+ * Enumerates directories in a directory
+ * @return array
+ */
+ public function dirs($basedir)
+ {
+ $dirs = array();
+
+ foreach (new \DirectoryIterator($basedir) as $fileInfo) {
+ if(!$fileInfo->isDot() && $fileInfo->isDir())
+ $dirs []= (string) $fileInfo;
+ }
+
+ return $dirs;
+ }
+
public function mkdir($dir, $perms=0755)
{
if(!is_dir($dir))
@@ -73,10 +89,8 @@ public function copy($source, $dest)
if(!is_dir(dirname($dest)))
$this->mkdir(dirname($dest));
- $source = realpath($source);
-
if(!@copy($source, $dest))
- throw new ShellException("Unable to copy $source to $dir: ".$this->_lastError());
+ throw new ShellException("Unable to copy $source to $dest: ".$this->_lastError());
return $this;
}
@@ -115,6 +129,17 @@ public function printf($string)
return $this;
}
+ public function putContents($file, $string, $flags=0)
+ {
+ file_put_contents($file, $string, $flags);
+ return $this;
+ }
+
+ public function realpath($path)
+ {
+ return realpath($path);
+ }
+
private function _lastError()
{
$last = error_get_last();
View
1 lib/Phark/Source.php
@@ -6,6 +6,7 @@
{
/**
* Finds matching packages
+ * @return Specification
*/
public function find($name, Requirement $requirement=null);
}

0 comments on commit 3371aea

Please sign in to comment.
Something went wrong with that request. Please try again.