Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix docs, typehint #11

Merged
merged 1 commit into from Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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