for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App;
use ArrayObject;
use InvalidArgumentException;
use Symfony\Component\Yaml\Yaml;
class Config extends ArrayObject
{
/**
* Construct a new config
*
* @param string $filename
* @return void
*/
public function __construct(array $input = [])
parent::__construct($input + [
// 'workdir' => getcwd(),
'port' => 9501,
'events' => [],
]);
$this->sanitize();
}
* load config.yaml
public function loadYaml(string $filename)
$config = Yaml::parseFile($filename);
$this->exchangeArray($config + $this->getArrayCopy());
* Sanitize config values.
* @throws \InvalidArgumentException
private function sanitize(): void
// Well-known ports: 0 to 1023
// Registered/user ports: 1024 to 49151
// Dynamic/private ports: 49152 to 65535
$port = filter_var($this['port'], FILTER_VALIDATE_INT, [
'options' => ['min_range' => 0, 'max_range' => 49151]
if ($port === false) {
throw new InvalidArgumentException('Invalid port: '.$this['port'].'.', 1001);
$this['port'] = $port;