Skip to content

Commit

Permalink
Update documentation / example
Browse files Browse the repository at this point in the history
Thanks to @llaville for pointing this out
  • Loading branch information
theseer committed Feb 14, 2022
1 parent f2de922 commit 52d5517
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ If you only need this library during development, for instance to run your proje

composer require --dev phar-io/manifest

## Usage
## Usage Examples

### Read from `manifest.xml`
```php
use PharIo\Manifest\ManifestLoader;
use PharIo\Manifest\ManifestSerializer;
Expand All @@ -24,3 +25,30 @@ var_dump($manifest);

echo (new ManifestSerializer)->serializeToString($manifest);
```

### Create via API
```php
$bundled = new \PharIo\Manifest\BundledComponentCollection();
$bundled->add(
new \PharIo\Manifest\BundledComponent('vendor/packageA', new \PharIo\Version\Version('1.2.3-dev')
)
);

$manifest = new PharIo\Manifest\Manifest(
new \PharIo\Manifest\ApplicationName('vendor/package'),
new \PharIo\Version\Version('1.0.0'),
new \PharIo\Manifest\Library(),
new \PharIo\Manifest\CopyrightInformation(
new \PharIo\Manifest\AuthorCollection(),
new \PharIo\Manifest\License(
'BSD-3-Clause',
new \PharIo\Manifest\Url('https://spdx.org/licenses/BSD-3-Clause.html')
)
),
new \PharIo\Manifest\RequirementCollection(),
$bundled
);

echo (new ManifestSerializer)->serializeToString($manifest);
```

1 change: 1 addition & 0 deletions examples/example-01.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
$manifest->getName()->asString(),
$manifest->getVersion()->getVersionString()
);

echo (new ManifestSerializer)->serializeToString($manifest);
50 changes: 50 additions & 0 deletions examples/example-02.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php declare(strict_types = 1);
/**
* Thanks to @llaville for this example
*/
use PharIo\Manifest\ManifestSerializer;

require __DIR__ . '/../vendor/autoload.php';

$bundledComponentCollection = new \PharIo\Manifest\BundledComponentCollection();
$bundledComponentCollection->add(
new \PharIo\Manifest\BundledComponent(
'vendor/packageA',
new \PharIo\Version\Version('0.0.0-dev')
)
);

$manifest = new PharIo\Manifest\Manifest(
new \PharIo\Manifest\ApplicationName('vendor/package'),
new \PharIo\Version\Version('1.0.0'),
new \PharIo\Manifest\Library(),
new \PharIo\Manifest\CopyrightInformation(
new \PharIo\Manifest\AuthorCollection(),
new \PharIo\Manifest\License(
'BSD-3-Clause',
new \PharIo\Manifest\Url('https://spdx.org/licenses/BSD-3-Clause.html')
)
),
new \PharIo\Manifest\RequirementCollection(),
$bundledComponentCollection
);

echo (new ManifestSerializer)->serializeToString($manifest);

/*
* Output produced
*
<?xml version="1.0" encoding="UTF-8"?>
<phar xmlns="https://phar.io/xml/manifest/1.0">
<contains name="vendor/package" version="1.0.0" type="library"/>
<copyright>
<license type="BSD-3-Clause" url="https://spdx.org/licenses/BSD-3-Clause.html"/>
</copyright>
<requires>
<php version="*"/>
</requires>
<bundles>
<component name="vendor/packageA" version="0.0.0-dev"/>
</bundles>
</phar>
*/

0 comments on commit 52d5517

Please sign in to comment.