PK ^GMD\C .travis.ymlnu W+A os:
- linux
language: php
before_install:
- wget https://phar.io/releases/phive.phar
- wget https://phar.io/releases/phive.phar.asc
- gpg --keyserver hkps.pool.sks-keyservers.net --recv-keys 0x9B2D5D79
- gpg --verify phive.phar.asc phive.phar
- chmod +x phive.phar
- sudo mv phive.phar /usr/bin/phive
install:
- ant setup
script: ./tools/phpunit
php:
- 5.6
- 7.0
- 7.1
- 7.0snapshot
- 7.1snapshot
- master
matrix:
allow_failures:
- php: master
fast_finish: true
notifications:
email: false
PK ^GMKr .php_csnu W+A files()
->in('src')
->in('tests')
->name('*.php');
return Symfony\CS\Config\Config::create()
->setUsingCache(true)
->level(\Symfony\CS\FixerInterface::NONE_LEVEL)
->fixers(
array(
'align_double_arrow',
'align_equals',
'concat_with_spaces',
'duplicate_semicolon',
'elseif',
'empty_return',
'encoding',
'eof_ending',
'extra_empty_lines',
'function_call_space',
'function_declaration',
'indentation',
'join_function',
'line_after_namespace',
'linefeed',
'list_commas',
'lowercase_constants',
'lowercase_keywords',
'method_argument_space',
'multiple_use',
'namespace_no_leading_whitespace',
'no_blank_lines_after_class_opening',
'no_empty_lines_after_phpdocs',
'parenthesis',
'php_closing_tag',
'phpdoc_indent',
'phpdoc_no_access',
'phpdoc_no_empty_return',
'phpdoc_no_package',
'phpdoc_params',
'phpdoc_scalar',
'phpdoc_separation',
'phpdoc_to_comment',
'phpdoc_trim',
'phpdoc_types',
'phpdoc_var_without_name',
'remove_lines_between_uses',
'return',
'self_accessor',
'short_array_syntax',
'short_tag',
'single_line_after_imports',
'single_quote',
'spaces_before_semicolon',
'spaces_cast',
'ternary_spaces',
'trailing_spaces',
'trim_array_spaces',
'unused_use',
'visibility',
'whitespacy_lines'
)
)
->finder($finder);
PK ^GMr$ phive.xmlnu W+A
PK ^GMVh README.mdnu W+A # Manifest
Component for reading [phar.io](https://phar.io/) manifest information from a [PHP Archive (PHAR)](http://php.net/phar).
[![Build Status](https://travis-ci.org/phar-io/manifest.svg?branch=master)](https://travis-ci.org/phar-io/manifest)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/phar-io/manifest/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/phar-io/manifest/?branch=master)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/d8cc6035-69ad-477d-bd1a-ccc605480fd7/mini.png)](https://insight.sensiolabs.com/projects/d8cc6035-69ad-477d-bd1a-ccc605480fd7)
## Installation
You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):
composer require phar-io/manifest
If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:
composer require --dev phar-io/manifest
## Usage
```php
use PharIo\Manifest\ManifestLoader;
use PharIo\Manifest\ManifestSerializer;
$manifest = ManifestLoader::fromFile('manifest.xml');
var_dump($manifest);
echo (new ManifestSerializer)->serializeToString($manifest);
```
PK ^GM걩N N
.gitignorenu W+A /.idea
/.php_cs.cache
/composer.lock
/src/autoload.php
/tools
/vendor
/build
PK ^GMR examples/example-01.phpnu W+A , Sebastian Heuer , Sebastian Bergmann
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use PharIo\Manifest\ManifestLoader;
use PharIo\Manifest\ManifestSerializer;
require __DIR__ . '/../vendor/autoload.php';
$manifest = ManifestLoader::fromFile(__DIR__ . '/../tests/_fixture/phpunit-5.6.5.xml');
echo sprintf(
"Manifest for %s (%s):\n\n",
$manifest->getName(),
$manifest->getVersion()->getVersionString()
);
echo (new ManifestSerializer)->serializeToString($manifest);
PK ^GM@ phpunit.xmlnu W+A
tests
src
PK ^GM@ src/ManifestDocumentMapper.phpnu W+A , Sebastian Heuer , Sebastian Bergmann
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
use PharIo\Version\Version;
use PharIo\Version\Exception as VersionException;
use PharIo\Version\VersionConstraintParser;
class ManifestDocumentMapper {
/**
* @param ManifestDocument $document
*
* @returns Manifest
*
* @throws ManifestDocumentMapperException
*/
public function map(ManifestDocument $document) {
try {
$contains = $document->getContainsElement();
$type = $this->mapType($contains);
$copyright = $this->mapCopyright($document->getCopyrightElement());
$requirements = $this->mapRequirements($document->getRequiresElement());
$bundledComponents = $this->mapBundledComponents($document);
return new Manifest(
new ApplicationName($contains->getName()),
new Version($contains->getVersion()),
$type,
$copyright,
$requirements,
$bundledComponents
);
} catch (VersionException $e) {
throw new ManifestDocumentMapperException($e->getMessage(), $e->getCode(), $e);
} catch (Exception $e) {
throw new ManifestDocumentMapperException($e->getMessage(), $e->getCode(), $e);
}
}
/**
* @param ContainsElement $contains
*
* @return Type
*
* @throws ManifestDocumentMapperException
*/
private function mapType(ContainsElement $contains) {
switch ($contains->getType()) {
case 'application':
return Type::application();
case 'library':
return Type::library();
case 'extension':
return $this->mapExtension($contains->getExtensionElement());
}
throw new ManifestDocumentMapperException(
sprintf('Unsupported type %s', $contains->getType())
);
}
/**
* @param CopyrightElement $copyright
*
* @return CopyrightInformation
*
* @throws InvalidUrlException
* @throws InvalidEmailException
*/
private function mapCopyright(CopyrightElement $copyright) {
$authors = new AuthorCollection();
foreach($copyright->getAuthorElements() as $authorElement) {
$authors->add(
new Author(
$authorElement->getName(),
new Email($authorElement->getEmail())
)
);
}
$licenseElement = $copyright->getLicenseElement();
$license = new License(
$licenseElement->getType(),
new Url($licenseElement->getUrl())
);
return new CopyrightInformation(
$authors,
$license
);
}
/**
* @param RequiresElement $requires
*
* @return RequirementCollection
*
* @throws ManifestDocumentMapperException
*/
private function mapRequirements(RequiresElement $requires) {
$collection = new RequirementCollection();
$phpElement = $requires->getPHPElement();
$parser = new VersionConstraintParser;
try {
$versionConstraint = $parser->parse($phpElement->getVersion());
} catch (VersionException $e) {
throw new ManifestDocumentMapperException(
sprintf('Unsupported version constraint - %s', $e->getMessage()),
$e->getCode(),
$e
);
}
$collection->add(
new PhpVersionRequirement(
$versionConstraint
)
);
if (!$phpElement->hasExtElements()) {
return $collection;
}
foreach($phpElement->getExtElements() as $extElement) {
$collection->add(
new PhpExtensionRequirement($extElement->getName())
);
}
return $collection;
}
/**
* @param ManifestDocument $document
*
* @return BundledComponentCollection
*/
private function mapBundledComponents(ManifestDocument $document) {
$collection = new BundledComponentCollection();
if (!$document->hasBundlesElement()) {
return $collection;
}
foreach($document->getBundlesElement()->getComponentElements() as $componentElement) {
$collection->add(
new BundledComponent(
$componentElement->getName(),
new Version(
$componentElement->getVersion()
)
)
);
}
return $collection;
}
/**
* @param ExtensionElement $extension
*
* @return Extension
*
* @throws ManifestDocumentMapperException
*/
private function mapExtension(ExtensionElement $extension) {
try {
$parser = new VersionConstraintParser;
$versionConstraint = $parser->parse($extension->getCompatible());
return Type::extension(
new ApplicationName($extension->getFor()),
$versionConstraint
);
} catch (VersionException $e) {
throw new ManifestDocumentMapperException(
sprintf('Unsupported version constraint - %s', $e->getMessage()),
$e->getCode(),
$e
);
}
}
}
PK ^GMc c src/values/ApplicationName.phpnu W+A , Sebastian Heuer , Sebastian Bergmann
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
class ApplicationName {
/**
* @var string
*/
private $name;
/**
* ApplicationName constructor.
*
* @param string $name
*
* @throws InvalidApplicationNameException
*/
public function __construct($name) {
$this->ensureIsString($name);
$this->ensureValidFormat($name);
$this->name = $name;
}
/**
* @return string
*/
public function __toString() {
return $this->name;
}
public function isEqual(ApplicationName $name) {
return $this->name === $name->name;
}
/**
* @param string $name
*
* @throws InvalidApplicationNameException
*/
private function ensureValidFormat($name) {
if (!preg_match('#\w/\w#', $name)) {
throw new InvalidApplicationNameException(
sprintf('Format of name "%s" is not valid - expected: vendor/packagename', $name),
InvalidApplicationNameException::InvalidFormat
);
}
}
private function ensureIsString($name) {
if (!is_string($name)) {
throw new InvalidApplicationNameException(
'Name must be a string',
InvalidApplicationNameException::NotAString
);
}
}
}
PK ^GMpn src/values/Type.phpnu W+A , Sebastian Heuer , Sebastian Bergmann
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
use PharIo\Version\VersionConstraint;
abstract class Type {
/**
* @return Application
*/
public static function application() {
return new Application;
}
/**
* @return Library
*/
public static function library() {
return new Library;
}
/**
* @param ApplicationName $application
* @param VersionConstraint $versionConstraint
*
* @return Extension
*/
public static function extension(ApplicationName $application, VersionConstraint $versionConstraint) {
return new Extension($application, $versionConstraint);
}
/**
* @return bool
*/
public function isApplication() {
return false;
}
/**
* @return bool
*/
public function isLibrary() {
return false;
}
/**
* @return bool
*/
public function isExtension() {
return false;
}
}
PK ^GMf] src/values/Url.phpnu W+A , Sebastian Heuer , Sebastian Bergmann
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
class Url {
/**
* @var string
*/
private $url;
/**
* @param string $url
*
* @throws InvalidUrlException
*/
public function __construct($url) {
$this->ensureUrlIsValid($url);
$this->url = $url;
}
/**
* @return string
*/
public function __toString() {
return $this->url;
}
/**
* @param string $url
*
* @throws InvalidUrlException
*/
private function ensureUrlIsValid($url) {
if (filter_var($url, \FILTER_VALIDATE_URL) === false) {
throw new InvalidUrlException;
}
}
}
PK ^GMn , src/values/RequirementCollectionIterator.phpnu W+A , Sebastian Heuer , Sebastian Bergmann
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
class RequirementCollectionIterator implements \Iterator {
/**
* @var Requirement[]
*/
private $requirements = [];
/**
* @var int
*/
private $position;
public function __construct(RequirementCollection $requirements) {
$this->requirements = $requirements->getRequirements();
}
public function rewind() {
$this->position = 0;
}
/**
* @return bool
*/
public function valid() {
return $this->position < count($this->requirements);
}
/**
* @return int
*/
public function key() {
return $this->position;
}
/**
* @return Requirement
*/
public function current() {
return $this->requirements[$this->position];
}
public function next() {
$this->position++;
}
}
PK ^GM} 1 src/values/BundledComponentCollectionIterator.phpnu W+A , Sebastian Heuer , Sebastian Bergmann
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
class BundledComponentCollectionIterator implements \Iterator {
/**
* @var BundledComponent[]
*/
private $bundledComponents = [];
/**
* @var int
*/
private $position;
public function __construct(BundledComponentCollection $bundledComponents) {
$this->bundledComponents = $bundledComponents->getBundledComponents();
}
public function rewind() {
$this->position = 0;
}
/**
* @return bool
*/
public function valid() {
return $this->position < count($this->bundledComponents);
}
/**
* @return int
*/
public function key() {
return $this->position;
}
/**
* @return BundledComponent
*/
public function current() {
return $this->bundledComponents[$this->position];
}
public function next() {
$this->position++;
}
}
PK ^GMGr src/values/AuthorCollection.phpnu W+A , Sebastian Heuer , Sebastian Bergmann
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
class AuthorCollection implements \Countable, \IteratorAggregate {
/**
* @var Author[]
*/
private $authors = [];
public function add(Author $author) {
$this->authors[] = $author;
}
/**
* @return Author[]
*/
public function getAuthors() {
return $this->authors;
}
/**
* @return int
*/
public function count() {
return count($this->authors);
}
/**
* @return AuthorCollectionIterator
*/
public function getIterator() {
return new AuthorCollectionIterator($this);
}
}
PK ^GMtbx x # src/values/CopyrightInformation.phpnu W+A , Sebastian Heuer , Sebastian Bergmann
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
class CopyrightInformation {
/**
* @var AuthorCollection
*/
private $authors;
/**
* @var License
*/
private $license;
public function __construct(AuthorCollection $authors, License $license) {
$this->authors = $authors;
$this->license = $license;
}
/**
* @return AuthorCollection
*/
public function getAuthors() {
return $this->authors;
}
/**
* @return License
*/
public function getLicense() {
return $this->license;
}
}
PK ^GM6VAp p src/values/Requirement.phpnu W+A , Sebastian Heuer , Sebastian Bergmann
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
interface Requirement {
}
PK ^GM-Ũ src/values/BundledComponent.phpnu W+A , Sebastian Heuer , Sebastian Bergmann
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
use PharIo\Version\Version;
class BundledComponent {
/**
* @var string
*/
private $name;
/**
* @var Version
*/
private $version;
/**
* @param string $name
* @param Version $version
*/
public function __construct($name, Version $version) {
$this->name = $name;
$this->version = $version;
}
/**
* @return string
*/
public function getName() {
return $this->name;
}
/**
* @return Version
*/
public function getVersion() {
return $this->version;
}
}
PK ^GM* src/values/License.phpnu W+A , Sebastian Heuer , Sebastian Bergmann
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
class License {
/**
* @var string
*/
private $name;
/**
* @var Url
*/
private $url;
public function __construct($name, Url $url) {
$this->name = $name;
$this->url = $url;
}
/**
* @return string
*/
public function getName() {
return $this->name;
}
/**
* @return Url
*/
public function getUrl() {
return $this->url;
}
}
PK ^GMD src/values/Manifest.phpnu W+A , Sebastian Heuer , Sebastian Bergmann
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
use PharIo\Version\Version;
class Manifest {
/**
* @var ApplicationName
*/
private $name;
/**
* @var Version
*/
private $version;
/**
* @var Type
*/
private $type;
/**
* @var CopyrightInformation
*/
private $copyrightInformation;
/**
* @var RequirementCollection
*/
private $requirements;
/**
* @var BundledComponentCollection
*/
private $bundledComponents;
public function __construct(ApplicationName $name, Version $version, Type $type, CopyrightInformation $copyrightInformation, RequirementCollection $requirements, BundledComponentCollection $bundledComponents) {
$this->name = $name;
$this->version = $version;
$this->type = $type;
$this->copyrightInformation = $copyrightInformation;
$this->requirements = $requirements;
$this->bundledComponents = $bundledComponents;
}
/**
* @return ApplicationName
*/
public function getName() {
return $this->name;
}
/**
* @return Version
*/
public function getVersion() {
return $this->version;
}
/**
* @return Type
*/
public function getType() {
return $this->type;
}
/**
* @return CopyrightInformation
*/
public function getCopyrightInformation() {
return $this->copyrightInformation;
}
/**
* @return RequirementCollection
*/
public function getRequirements() {
return $this->requirements;
}
/**
* @return BundledComponentCollection
*/
public function getBundledComponents() {
return $this->bundledComponents;
}
/**
* @return bool
*/
public function isApplication() {
return $this->type->isApplication();
}
/**
* @return bool
*/
public function isLibrary() {
return $this->type->isLibrary();
}
/**
* @return bool
*/
public function isExtension() {
return $this->type->isExtension();
}
/**
* @param ApplicationName $application
* @param Version|null $version
*
* @return bool
*/
public function isExtensionFor(ApplicationName $application, Version $version = null) {
if (!$this->isExtension()) {
return false;
}
/** @var Extension $type */
$type = $this->type;
if ($version !== null) {
return $type->isCompatibleWith($application, $version);
}
return $type->isExtensionFor($application);
}
}
PK ^GMc M src/values/Email.phpnu W+A , Sebastian Heuer , Sebastian Bergmann
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
class Email {
/**
* @var string
*/
private $email;
/**
* @param string $email
*
* @throws InvalidEmailException
*/
public function __construct($email) {
$this->ensureEmailIsValid($email);
$this->email = $email;
}
/**
* @return string
*/
public function __toString() {
return $this->email;
}
/**
* @param string $url
*
* @throws InvalidEmailException
*/
private function ensureEmailIsValid($url) {
if (filter_var($url, \FILTER_VALIDATE_EMAIL) === false) {
throw new InvalidEmailException;
}
}
}
PK ^GMW8% % src/values/Author.phpnu W+A , Sebastian Heuer , Sebastian Bergmann
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
class Author {
/**
* @var string
*/
private $name;
/**
* @var Email
*/
private $email;
/**
* @param string $name
* @param Email $email
*/
public function __construct($name, Email $email) {
$this->name = $name;
$this->email = $email;
}
/**
* @return string
*/
public function getName() {
return $this->name;
}
/**
* @return Email
*/
public function getEmail() {
return $this->email;
}
/**
* @return string
*/
public function __toString() {
return sprintf(
'%s <%s>',
$this->name,
$this->email
);
}
}
PK ^GMFz src/values/Library.phpnu W+A , Sebastian Heuer , Sebastian Bergmann
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
class Library extends Type {
/**
* @return bool
*/
public function isLibrary() {
return true;
}
}
PK ^GM0 src/values/Extension.phpnu W+A , Sebastian Heuer , Sebastian Bergmann
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
use PharIo\Version\Version;
use PharIo\Version\VersionConstraint;
class Extension extends Type {
/**
* @var ApplicationName
*/
private $application;
/**
* @var VersionConstraint
*/
private $versionConstraint;
/**
* @param ApplicationName $application
* @param VersionConstraint $versionConstraint
*/
public function __construct(ApplicationName $application, VersionConstraint $versionConstraint) {
$this->application = $application;
$this->versionConstraint = $versionConstraint;
}
/**
* @return ApplicationName
*/
public function getApplicationName() {
return $this->application;
}
/**
* @return VersionConstraint
*/
public function getVersionConstraint() {
return $this->versionConstraint;
}
/**
* @return bool
*/
public function isExtension() {
return true;
}
/**
* @param ApplicationName $name
*
* @return bool
*/
public function isExtensionFor(ApplicationName $name) {
return $this->application->isEqual($name);
}
/**
* @param ApplicationName $name
* @param Version $version
*
* @return bool
*/
public function isCompatibleWith(ApplicationName $name, Version $version) {
return $this->isExtensionFor($name) && $this->versionConstraint->complies($version);
}
}
PK ^GMa a ' src/values/AuthorCollectionIterator.phpnu W+A , Sebastian Heuer , Sebastian Bergmann
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
class AuthorCollectionIterator implements \Iterator {
/**
* @var Author[]
*/
private $authors = [];
/**
* @var int
*/
private $position;
public function __construct(AuthorCollection $authors) {
$this->authors = $authors->getAuthors();
}
public function rewind() {
$this->position = 0;
}
/**
* @return bool
*/
public function valid() {
return $this->position < count($this->authors);
}
/**
* @return int
*/
public function key() {
return $this->position;
}
/**
* @return Author
*/
public function current() {
return $this->authors[$this->position];
}
public function next() {
$this->position++;
}
}
PK ^GM
( ( ) src/values/BundledComponentCollection.phpnu W+A , Sebastian Heuer , Sebastian Bergmann
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
class BundledComponentCollection implements \Countable, \IteratorAggregate {
/**
* @var BundledComponent[]
*/
private $bundledComponents = [];
public function add(BundledComponent $bundledComponent) {
$this->bundledComponents[] = $bundledComponent;
}
/**
* @return BundledComponent[]
*/
public function getBundledComponents() {
return $this->bundledComponents;
}
/**
* @return int
*/
public function count() {
return count($this->bundledComponents);
}
/**
* @return BundledComponentCollectionIterator
*/
public function getIterator() {
return new BundledComponentCollectionIterator($this);
}
}
PK ^GM< &