Skip to content

Commit

Permalink
prepare to lib
Browse files Browse the repository at this point in the history
  • Loading branch information
frostealth committed May 18, 2016
1 parent 44457c6 commit 65e8445
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 34 deletions.
21 changes: 18 additions & 3 deletions app/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,31 @@
*/
class App extends \DI\Bridge\Slim\App
{
/** @var \livetyping\hermitage\app\Sources */
private $sources;

/**
* App constructor.
*
* @param \livetyping\hermitage\app\Sources $sources
*/
public function __construct(Sources $sources)
{
$this->sources = $sources;

parent::__construct();
}

/**
* @inheritdoc
*/
protected function configureContainer(ContainerBuilder $builder)
{
$builder->setDefinitionCache(new ApcuCache());

$builder->addDefinitions(__DIR__ . '/config/settings.php');
$builder->addDefinitions(__DIR__ . '/config/definitions.php');
$builder->addDefinitions(__DIR__ . '/config/decorators.php');
foreach ($this->sources->all() as $source) {
$builder->addDefinitions($source);
}
}

/**
Expand Down
63 changes: 63 additions & 0 deletions app/Sources.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace livetyping\hermitage\app;

/**
* Class Sources
*
* @package livetyping\hermitage\app
*/
final class Sources
{
/** @var string[] */
protected $files = [];

/**
* Sources constructor.
*
* @param array $files
*/
public function __construct(array $files = [])
{
$this->files = $this->core();
foreach ($files as $file) {
$this->add((string)$file);
}
}

/**
* Adds file containing definitions
*
* @param string $file the name of a file containing definitions
*
* @return $this
*/
public function add(string $file)
{
$this->files[] = $file;

return $this;
}

/**
* Returns the list of files containing definitions
*
* @return array
*/
public function all(): array
{
return $this->files;
}

/**
* @return string[]
*/
protected function core(): array
{
return [
__DIR__ . '/config/settings.php',
__DIR__ . '/config/definitions.php',
__DIR__ . '/config/decorators.php'
];
}
}
22 changes: 11 additions & 11 deletions app/config/definitions/images.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,34 @@
use function DI\string;

return [
// processor
'images.processor.versions' => [
'images.versions' => [
'mini' => [
'type' => 'resize',
'height' => 200,
'width' => 200,
],
'small' => [
'type' => 'resize',
'height' => 600,
'width' => 600,
'height' => 400,
'width' => 400,
],
'thumb' => [
'type' => 'fit',
'height' => 100,
'width' => 100,
],
],
'images.processor.optimization-params' => ['maxHeight' => 800, 'maxWidth' => 800],
'images.processor.manipulator-map' => [],
'images.processor.manager.config' => ['driver' => 'gd'],
'images.optimization-params' => ['maxHeight' => 800, 'maxWidth' => 800],
'images.manipulator-map' => [],
'images.manager-config' => ['driver' => 'gd'],

'images.processor.manager' => object(ImageManager::class)->constructor(get('images.processor.manager.config')),
// processor
'images.processor.manager' => object(ImageManager::class)->constructor(get('images.manager-config')),
'images.processor' => object(Processor::class)
->constructor(get('images.processor.manager'))
->method('addManipulatorMap', get('images.processor.manipulator-map'))
->method('setVersions', get('images.processor.versions'))
->method('setOptimizationParams', get('images.processor.optimization-params')),
->method('addManipulatorMap', get('images.manipulator-map'))
->method('setVersions', get('images.versions'))
->method('setOptimizationParams', get('images.optimization-params')),
ProcessorContract::class => get('images.processor'),

// generator
Expand Down
7 changes: 0 additions & 7 deletions bootstrap/app.php

This file was deleted.

7 changes: 0 additions & 7 deletions bootstrap/environment.php

This file was deleted.

31 changes: 31 additions & 0 deletions bootstrap/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace livetyping\hermitage\bootstrap;

use Dotenv\Dotenv;
use livetyping\hermitage\app\App;
use livetyping\hermitage\app\Sources;

/**
* @param \livetyping\hermitage\app\Sources $sources
*
* @return \livetyping\hermitage\app\App
*/
function app(Sources $sources): App
{
$app = new App($sources);
require __DIR__ . '/../app/routes.php';

return $app;
}

/**
* @param string $path
*/
function load_dotenv(string $path)
{
$path = rtrim($path, '/');
if (file_exists($path . '/.env')) {
(new Dotenv($path))->load();
}
}
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
"psr-4": {
"livetyping\\hermitage\\app\\": "app/",
"livetyping\\hermitage\\foundation\\": "foundation/"
}
},
"files": [
"bootstrap/functions.php"
]
}
}
8 changes: 3 additions & 5 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

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

require __DIR__ . '/../bootstrap/environment.php';
$sources = new \livetyping\hermitage\app\Sources();

/** @var \livetyping\hermitage\app\App $app */
$app = require_once __DIR__ . '/../bootstrap/app.php';

$app->run();
livetyping\hermitage\bootstrap\load_dotenv(dirname(__DIR__));
livetyping\hermitage\bootstrap\app($sources)->run();

0 comments on commit 65e8445

Please sign in to comment.