-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,767 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
], | ||
], | ||
|
||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.