Skip to content

Commit

Permalink
Add some documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Nov 15, 2015
1 parent fbb7fc7 commit 3cedc1e
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/Clue/PharComposer/Package/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

/**
* Provides access to pathes defined in package autoload configuration.
*
* @see Package
*/
class Autoload
{
Expand Down
2 changes: 1 addition & 1 deletion src/Clue/PharComposer/Package/Bundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ public function getIterator()
{
return new \ArrayIterator($this->resources);
}
}
}
3 changes: 3 additions & 0 deletions src/Clue/PharComposer/Package/Bundler/BundlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Clue\PharComposer\Package\Bundler;

/**
* The Bundler is responsible for creating a Bundle containing all files which belong to a given package
*/
interface BundlerInterface
{
/**
Expand Down
4 changes: 3 additions & 1 deletion src/Clue/PharComposer/Package/Bundler/Complete.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Clue\PharComposer\Package\Package;
use Symfony\Component\Finder\Finder;

/**
* The default Bundler instance which bundles the whole package directory
*/
class Complete implements BundlerInterface
{
/**
Expand Down Expand Up @@ -44,5 +47,4 @@ public function bundle()
$this->logger->log(' Adding whole project directory "' . $this->package->getDirectory() . '"');
return $bundle->addDir($iterator);
}

}
3 changes: 3 additions & 0 deletions src/Clue/PharComposer/Package/Bundler/Explicit.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Clue\PharComposer\Package\Autoload;
use Symfony\Component\Finder\Finder;

/**
* Only bundle files explicitly defined in this package's bin and autoload section
*/
class Explicit implements BundlerInterface
{
/**
Expand Down
63 changes: 63 additions & 0 deletions src/Clue/PharComposer/Package/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,38 @@
use Clue\PharComposer\Package\Autoload;
use Clue\PharComposer\Logger;

/**
* The package represents either the main/root package or one of the vendor packages.
*/
class Package
{
/**
* Instantiate package
*
* @param array $package package information (parsed composer.json)
* @param string $directory base directory of this package
*/
public function __construct(array $package, $directory)
{
$this->package = $package;
$this->directory = $directory;
}

/**
* get package name as defined in composer.json
*
* @return string
*/
public function getName()
{
return isset($this->package['name']) ? $this->package['name'] : 'unknown';
}

/**
* Get path to vendor directory (relative to package directory)
*
* @return string
*/
public function getPathVendorRelative()
{
$vendor = 'vendor';
Expand All @@ -30,16 +49,32 @@ public function getPathVendorRelative()
return $vendor;
}

/**
* Get absolute path to vendor directory
*
* @return string
*/
public function getPathVendor()
{
return $this->getAbsolutePath($this->getPathVendorRelative() . '/');
}

/**
* Get package directory (the directory containing its composer.json)
*
* @return string
*/
public function getDirectory()
{
return $this->directory;
}

/**
* Get Bundler instance to bundle this package
*
* @param Logger $logger
* @return BundlerInterface
*/
public function getBundler(Logger $logger)
{
$bundlerName = 'complete';
Expand All @@ -57,11 +92,23 @@ public function getBundler(Logger $logger)
}
}

/**
* Get Autoload instance containing all autoloading information
*
* Only used for ExplicitBundler at the moment.
*
* @return Autoload
*/
public function getAutoload()
{
return new Autoload(isset($this->package['autoload']) ? $this->package['autoload'] : array());
}

/**
* Get list of files defined as "bin" (absolute paths)
*
* @return string[]
*/
public function getBins()
{
if (!isset($this->package['bin'])) {
Expand All @@ -76,6 +123,13 @@ public function getBins()
return $bins;
}

/**
* Get blacklisted files which are not to be included
*
* Hardcoded to exclude composer.phar and phar-composer.phar at the moment.
*
* @return string[]
*/
public function getBlacklist()
{
return array(
Expand All @@ -85,6 +139,9 @@ public function getBlacklist()
}

/**
* Gets a filter function to exclude blacklisted files
*
* Only used for CompleteBundler at the moment
*
* @return Closure
* @uses self::getBlacklist()
Expand All @@ -98,6 +155,12 @@ public function getBlacklistFilter()
};
}

/**
* Get absolute path for the given package-relative path
*
* @param string $path
* @return string
*/
public function getAbsolutePath($path)
{
return $this->directory . ltrim($path, '/');
Expand Down
3 changes: 3 additions & 0 deletions src/Clue/PharComposer/Phar/PharComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
use Clue\PharComposer\Package\Bundle;
use Clue\PharComposer\Package\Package;

/**
* The PharComposer is responsible for collecting options and then building the target phar
*/
class PharComposer
{
private $pathProject;
Expand Down
2 changes: 1 addition & 1 deletion src/Clue/PharComposer/Phar/TargetPhar.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ public function addFromString($local, $contents)
{
$this->box->addFromString($local, $contents);
}
}
}

0 comments on commit 3cedc1e

Please sign in to comment.