Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ncou committed Jul 24, 2019
1 parent bb01d98 commit bbacbcf
Show file tree
Hide file tree
Showing 31 changed files with 1,767 additions and 81 deletions.
11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@
"psr/http-server-middleware": "^1.0",
"psr/log": "^1.0",
"nikic/fast-route": "^1.3",
"chiron/http": "^1.0",
"chiron/http-exceptions": "^2.0",
"chiron/psr17factoryfinder": "^0.1",
"chiron/crypt-engine": "^0.1",
"chiron/container": "^3.0",
"chiron/container": "^3.1",
"chiron/pipeline": "^3.2",
"chiron/config": "^1.1",
"nyholm/psr7-server": "^0.3.0"
"nyholm/psr7-server": "^0.3",
"vlucas/phpdotenv": "^3.3",
"monolog/monolog": "^1.24"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.0",
"phpunit/phpunit": "^7.0",
"phpstan/phpstan": "^0.9.2",
"filp/whoops": "^2.2",
"chiron/logger": "^0.2",
"chiron/template": "^1.1"
"chiron/template": "^1.1",
"nyholm/psr7": "^1.1"
},
"suggest": {
"filp/whoops": "Enables use of the debug displayer."
Expand Down
92 changes: 92 additions & 0 deletions config/logging.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler;

return [

/*
|--------------------------------------------------------------------------
| Default Log Channel
|--------------------------------------------------------------------------
|
| This option defines the default log channel that gets used when writing
| messages to the logs. The name specified in this option should match
| one of the channels defined in the "channels" configuration array.
|
*/

'default' => env('LOG_CHANNEL', 'stack'),

/*
|--------------------------------------------------------------------------
| Log Channels
|--------------------------------------------------------------------------
|
| Here you may configure the log channels for your application. Out of
| the box, Chiron uses the Monolog PHP logging library. This gives
| you a variety of powerful log handlers / formatters to utilize.
|
| Available Drivers: "single", "daily", "slack", "syslog",
| "errorlog", "monolog",
| "custom", "stack"
|
*/

'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['daily'],
],

'single' => [
'driver' => 'single',
'path' => storage_path('logs/chiron.log'),
'level' => 'debug',
],

'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/chiron.log'),
'level' => 'debug',
'days' => 14,
],

'slack' => [
'driver' => 'slack',
'url' => env('LOG_SLACK_WEBHOOK_URL'),
'username' => 'Chiron Log',
'emoji' => ':boom:',
'level' => 'critical',
],

'papertrail' => [
'driver' => 'monolog',
'level' => 'debug',
'handler' => SyslogUdpHandler::class,
'handler_with' => [
'host' => env('PAPERTRAIL_URL'),
'port' => env('PAPERTRAIL_PORT'),
],
],

'stderr' => [
'driver' => 'monolog',
'handler' => StreamHandler::class,
'handler_with' => [
'stream' => 'php://stderr',
],
],

'syslog' => [
'driver' => 'syslog',
'level' => 'debug',
],

'errorlog' => [
'driver' => 'errorlog',
'level' => 'debug',
],
],

];
62 changes: 62 additions & 0 deletions src/Chiron/Boot/Directories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace Chiron\Boot;

use InvalidArgumentException;

/**
* Manage application directories set.
*/
// TODO : permettre d'utiliser les helpers ArrayAccess pour faire un truc du genre "$directories['config']"
final class Directories implements DirectoriesInterface
{
/** @var array */
private $directories = [];
/**
* @param array $directories
*/
public function __construct(array $directories)
{
foreach ($directories as $name => $directory) {
$this->set($name, $directory);
}
}
/**
* {@inheritdoc}
*/
public function set(string $name, string $path): DirectoriesInterface
{
$path = str_replace(['\\', '//'], '/', $path);
$this->directories[$name] = rtrim($path, '/') . '/';

return $this;
}
/**
* {@inheritdoc}
*/
public function get(string $name): string
{
if (! $this->has($name)) {
throw new InvalidArgumentException("Undefined directory '{$name}'");
}

return $this->directories[$name];
}
/**
* {@inheritdoc}
*/
public function has(string $name): bool
{
return array_key_exists($name, $this->directories);
}
/**
* {@inheritdoc}
*/
// TODO : renommer cette méthode en "all()" ????
public function getAll(): array
{
return $this->directories;
}
}
41 changes: 41 additions & 0 deletions src/Chiron/Boot/DirectoriesInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Chiron\Boot;

use InvalidArgumentException;
/**
* Manages application directories.
*/
interface DirectoriesInterface
{
/**
* @param string $name Directory alias, ie. "framework".
* @param string $path Directory path without ending slash.
*/
public function set(string $name, string $path);

/**
* Get directory value.
*
* @param string $name
* @return string
*
* @throws InvalidArgumentException When no directory found.
*/
public function get(string $name): string;

/**
* @param string $name
* @return bool
*/
public function has(string $name): bool;

/**
* List all registered directories.
*
* @return array
*/
public function getAll(): array;
}
153 changes: 153 additions & 0 deletions src/Chiron/Config/AbstractInjectableConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?php

declare(strict_types=1);

namespace Chiron\Config;

use InvalidArgumentException;
use LogicException;

use ArrayIterator;
use IteratorAggregate;
use ArrayAccess;

/**
* Generic implementation of array based configuration.
*/
// TODO : il faudrait pas aussi ajouter une interface Countable ???? => https://github.com/slimphp/Slim/blob/3.x/Slim/Collection.php
abstract class AbstractInjectableConfig implements InjectableInterface, IteratorAggregate, ArrayAccess
{
// TODO : à virer
//public const INJECTOR = ConfigsInterface::class;

/**
* Configuration data.
*
* @var array
*/
protected $config = [];
/**
* At this moment on array based configs can be supported.
*
* @param array $config
*/
public function __construct(array $config = [])
{
// TODO : faire plutot un $this->merge() qu'un remplacement direct de variables !!!!
$this->config = $config;
//$this->merge($config);
}

//abstract public function getLinkedFile(): string;

/**
* @param array $config
*/
public function merge(array $config): void
{
$this->config = $this->recursiveMerge($this->config, $config);
}

/**
* @param mixed $origin
* @param mixed $appender
*
* @return mixed
*/
// TODO : on dirait que les deux paramétres sont des tableaux. et que la valeur de retour sera aussi un tableau. modifier le typehint
private function recursiveMerge($origin, $appender)
{
if (is_array($origin)
&& array_values($origin) !== $origin
&& is_array($appender)
&& array_values($appender) !== $appender) {
foreach ($appender as $key => $value) {
if (isset($origin[$key])) {
$origin[$key] = $this->recursiveMerge($origin[$key], $value);
} else {
$origin[$key] = $value;
}
}

return $origin;
}

return $appender;
}

/**
* {@inheritdoc}
*/
public function toArray(): array
{
return $this->config;
}
/**
* {@inheritdoc}
*/
public function offsetExists($offset)
{
return array_key_exists($offset, $this->config);
}
/**
* {@inheritdoc}
*/
public function offsetGet($offset)
{
if (!$this->offsetExists($offset)) {
throw new InvalidArgumentException("Undefined configuration key '{$offset}'");
}
return $this->config[$offset];
}
/**
*{@inheritdoc}
*
* @throws ConfigException
*/
public function offsetSet($offset, $value)
{
throw new LogicException(
'Unable to change configuration data, configs are treated as immutable by default'
);
}
/**
*{@inheritdoc}
*
* @throws ConfigException
*/
public function offsetUnset($offset)
{
throw new LogicException(
'Unable to change configuration data, configs are treated as immutable by default'
);
}
/**
* {@inheritdoc}
*/
public function getIterator()
{
return new ArrayIterator($this->config);
}
/**
* Restoring state.
*
* @param array $an_array
*
* @return static
*/
// TODO : vérifier l'utilité de cette fonction !!!!
public static function __set_state($an_array)
{
return new static($an_array['config']);
}

/**
* Get number of items in collection
*
* @return int
*/
public function count()
{
return count($this->config);
}
}
Loading

0 comments on commit bbacbcf

Please sign in to comment.