Skip to content

Commit

Permalink
Merge pull request #11 from harikt/docs-issue-1
Browse files Browse the repository at this point in the history
Fix docs, typehint
  • Loading branch information
harikt committed Feb 17, 2017
2 parents 1cfa157 + c5f3852 commit 90bd951
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 18 deletions.
56 changes: 41 additions & 15 deletions README.md
Expand Up @@ -4,10 +4,17 @@ Asset management for PHP. This package is a fork of [Aura.Asset_Bundle](https://

## Foreword

### Requriements

* [PSR-7 implementation](https://packagist.org/providers/psr/http-message-implementation).
* [Proposed PSR-17 implementation](https://github.com/http-interop/http-factory)

If you are not familiar with both, choose [http-interop/http-factory-diactoros](https://packagist.org/packages/http-interop/http-factory-diactoros)

### Installation

```
composer require hkt/psr7-asset
composer require hkt/psr7-asset http-interop/http-factory-diactoros
```

### Tests
Expand All @@ -21,14 +28,15 @@ vendor/bin/phpunit

### PSR Compliance

This attempts to comply with [PSR-1][], [PSR-2][], [PSR-4][] and [PSR-7][]. If
This attempts to comply with [PSR-1][], [PSR-2][], [PSR-4][], [PSR-7][] and the proposed [PSR-17][]. If
you notice compliance oversights, please send a patch via pull request.

[PSR-1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md
[PSR-2]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
[PSR-4]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md

[PSR-7]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md
[PSR-17]: https://github.com/php-fig/fig-standards/blob/master/proposed/http-factory/http-factory.md

## Structure of Package

Expand Down Expand Up @@ -91,17 +99,35 @@ Like [puli](https://github.com/puli) it is possible that you can override the st
## Configuration via Aura.Di

```php
$di->params['Hkt\Psr7Asset\AssetLocator']['map'] = [
'vendor/package/css/hello.css' => '/path/to/web/css/test.css',
'vendor/package' => dirname(dirname(__DIR__)) . '/web',
];

$di->set('Hkt\Psr7Asset\AssetLocator', $di->lazyNew('Hkt\Psr7Asset\AssetLocator'));

$di->params['Hkt\Psr7Asset\AssetAction'] = array(
'domain' => $di->lazyNew('Hkt\Psr7Asset\AssetService'),
'responder' => $di->lazyNew('Hkt\Psr7Asset\AssetResponder'),
);

$di->set('Hkt\Psr7Asset\AssetAction', $di->lazyNew('Hkt\Psr7Asset\AssetAction'));
<?php
namespace Hkt\Psr7Asset;

use Aura\Di\Container;
use Aura\Di\ContainerConfigInterface;

class AssetConfig implements ContainerConfigInterface
{
public function define(Container $di)
{
// Choose one of the PSR-17 implementation
// $di->params['Hkt\Psr7Asset\AssetResponder']['responseFactory'] = $di->lazyNew('Http\Factory\Diactoros\ResponseFactory');

$di->set('Hkt\Psr7Asset\AssetLocator', $di->lazyNew('Hkt\Psr7Asset\AssetLocator'));

$di->params['Hkt\Psr7Asset\AssetAction'] = array(
'domain' => $di->lazyNew('Hkt\Psr7Asset\AssetService'),
'responder' => $di->lazyNew('Hkt\Psr7Asset\AssetResponder'),
);

$di->set('Hkt\Psr7Asset\AssetAction', $di->lazyNew('Hkt\Psr7Asset\AssetAction'));
}

public function modify(Container $di)
{
$assetLocator = $di->get('Hkt\Psr7Asset\AssetLocator');
$assetLocator->set('vendor/package/css/hello.css', '/path/to/web/css/test.css');
$assetLocator->set('vendor/package', dirname(dirname(__DIR__)) . '/web');
// Map more paths and location as above.
}
}
```
3 changes: 1 addition & 2 deletions composer.json
Expand Up @@ -28,8 +28,7 @@
},
"autoload": {
"psr-4": {
"Hkt\\Psr7Asset\\":"src/",
"Hkt\\Psr7Asset\\_Config\\":"config/"
"Hkt\\Psr7Asset\\":"src/"
}
},
"autoload-dev": {
Expand Down
36 changes: 36 additions & 0 deletions example/AssetConfig.php
@@ -0,0 +1,36 @@
<?php
namespace Hkt\Psr7Asset;

use Aura\Di\Container;
use Aura\Di\ContainerConfigInterface;

class AssetConfig implements ContainerConfigInterface
{
public function define(Container $di)
{
$di->params['Hkt\Psr7Asset\AssetResponder']['responseFactory'] = $di->lazyNew('Http\Factory\Diactoros\ResponseFactory');

// Alternative way than adding all into Constructor
// $di->params['Hkt\Psr7Asset\AssetLocator']['map'] = [
// 'vendor/package/css/hello.css' => '/path/to/web/css/test.css',
// 'vendor/package' => dirname(dirname(__DIR__)) . '/web',
// ];

$di->set('Hkt\Psr7Asset\AssetLocator', $di->lazyNew('Hkt\Psr7Asset\AssetLocator'));

$di->params['Hkt\Psr7Asset\AssetAction'] = array(
'domain' => $di->lazyNew('Hkt\Psr7Asset\AssetService'),
'responder' => $di->lazyNew('Hkt\Psr7Asset\AssetResponder'),
);

$di->set('Hkt\Psr7Asset\AssetAction', $di->lazyNew('Hkt\Psr7Asset\AssetAction'));
}

public function modify(Container $di)
{
$assetLocator = $di->get('Hkt\Psr7Asset\AssetLocator');
$assetLocator->set('vendor/package/css/hello.css', '/path/to/web/css/test.css');
$assetLocator->set('vendor/package', dirname(dirname(__DIR__)) . '/web');
// Map more paths and location as above.
}
}
3 changes: 2 additions & 1 deletion src/AssetResponder.php
@@ -1,6 +1,7 @@
<?php
namespace Hkt\Psr7Asset;

use Interop\Http\Factory\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use SplFileObject;

Expand Down Expand Up @@ -32,7 +33,7 @@ class AssetResponder
* Constructor.
*
*/
public function __construct($responseFactory)
public function __construct(ResponseFactoryInterface $responseFactory)
{
$this->data = (object) array();
$this->responseFactory = $responseFactory;
Expand Down

0 comments on commit 90bd951

Please sign in to comment.