Registers the errorHandler component as a PHP error handler.

@param array $config application config
503508
protected function registerErrorHandler(&$config)
    {
        if (Zilf_ENABLE_ERROR_HANDLER) {
            if (!isset($config['components']['errorHandler']['class'])) {
                echo "Error: no errorHandler component is configured.\n";
                exit(1);
            }
            $this->set('errorHandler', $config['components']['errorHandler']);
            unset($config['components']['errorHandler']);
            $this->getErrorHandler()->register();
        }
    }
1145411
public static function init($config = [])
    {
        if (!self::$config) {
            self::$config = include __DIR__ ."/default-config.php";
        }
        self::$config = Arr::array_merge_multi(self::$config, $config);
    }
1151310
protected function configureDefaults(array $config)
    {
        $defaults = [
            'http_errors' => true,
            'decode_content' => true,
            'verify' => true,
        ];

        // TODO finish defaults config feature

        $this->configs = array_replace($defaults, $config);

        // TODO add cookies settings after session and cookies feature finished
    }
722727
protected function platformConnectHandler(Config $config)
    {
        $this->database = $config->database;

        if ($config->readOnly === true) {
            $this->handle = new \Sqlite3($config->database, SQLITE3_OPEN_READONLY);
        } else {
            $this->handle = new \Sqlite3($config->database, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE);
        }

        // Enable throwing exceptions
        $this->handle->enableExceptions(true);

        // Set busy timeout
        if ($config->offsetExists('busyTimeout')) {
            if ($config->busyTimeout != 0) {
                $this->handle->busyTimeout($config->busyTimeout);
            }
        }
    }
199160
protected function treatRoutesConfig(array $config): void
    {
        if (!\array_key_exists('routes', $config)) {
            return;
        }

        if (!\is_array($config['routes'])) {
            throw new RouterException('Config routes has to be an array');
        }

        foreach ($config['routes'] as $route) {
            if (!\array_key_exists('methods', $route)) {
                throw new RouterException('Config routes/methods is mandatory');
            }

            if (!\array_key_exists('url', $route)) {
                throw new RouterException('Config routes/url is mandatory');
            }

            if (!\array_key_exists('callback', $route)) {
                throw new RouterException('Config routes/callback is mandatory');
            }

            $newRoute = new Route($route['methods'], $route['url'], $route['callback']);

            if (\array_key_exists('constraints', $route)) {
                $newRoute->setParametersConstraints($route['constraints']);
            }

            if (\array_key_exists('middlewares', $route)) {
                if (!\is_array($route['middlewares'])) {
                    throw new RouterException('Config routes/middlewares has to be an array');
                }

                foreach ($route['middlewares'] as $middleware) {
                    $newRoute->addMiddleware($middleware);
                }
            }

            if (\array_key_exists('name', $route)) {
                if (!\is_string($route['name'])) {
                    throw new RouterException('Config routes/name has to be a string');
                }

                $newRoute->setName($route['name']);
            }

            if (\array_key_exists('host', $route)) {
                if (!\is_string($route['host'])) {
                    throw new RouterException('Config routes/host has to be a string');
                }

                $newRoute->setHost($route['host']);
            }

            if (\array_key_exists('host_constraints', $route)) {
                if (!\is_array($route['host_constraints'])) {
                    throw new RouterException('Config routes/host_constraints has to be an array');
                }

                $newRoute->setHostConstraints($route['host_constraints']);
            }

            if (\array_key_exists('optionals_parameters', $route)) {
                if (!\is_array($route['optionals_parameters'])) {
                    throw new RouterException('Config routes/optionals_parameters has to be an array');
                }

                $newRoute->setOptionalsParameters($route['optionals_parameters']);
            }

            $this->addRoute($newRoute);
        }
    }
786985
public function initialize(array $config)
    {
        $config = Hash::merge($this->_defaultConfig, $config);
        $this->setConfig($config);
    }
387685
public static function validateOptions(array $config)
    {
        if (!isset($config['expected'])) {
            throw new \InvalidArgumentException('expected is required');
        }

        if (!is_callable($config['expected'])) {
            throw new \InvalidArgumentException('expected must be callable');
        }

        if (!isset($config['hash'])) {
            throw new \InvalidArgumentException('hash is required');
        }

        if (!($config['hash']) instanceof HashInterface) {
            throw new \InvalidArgumentException('hash must be an instance of '
                . __NAMESPACE__ . '\\HashInterface');
        }
    }
469559
public function initialize(array $config) {
		$controller = $this->_registry->getController();
		$this->setEventManager($controller->getEventManager());

		$this->Captchas = $controller->Captchas;
	}
11703
public function initialize(array $config)
    {
        parent::initialize($config);

        $this->Controller = $this->_registry->getController();

        $this->_setRecipientList();
    }
547525
private function resolveConfig(array $config)
    {
        if (!isset($config['httpHandler'])) {
            $config['httpHandler'] = HttpHandlerFactory::build();
        }

        if (!isset($config['asyncHttpHandler'])) {
            $isGuzzleHandler = $config['httpHandler'] instanceof Guzzle6HttpHandler
                || $config['httpHandler'] instanceof Guzzle5HttpHandler;
            $config['asyncHttpHandler'] = $isGuzzleHandler
                ? [$config['httpHandler'], 'async']
                : [HttpHandlerFactory::build(), 'async'];
        }

        return array_merge($this->config, $config);
    }
383699
private function configureDefaults(array $config)
    {
        $defaults = [
            'allow_redirects' => RedirectMiddleware::$defaultSettings,
            'http_errors'     => true,
            'decode_content'  => true,
            'verify'          => true,
            'cookies'         => false
        ];

        // Use the standard Linux HTTP_PROXY and HTTPS_PROXY if set.

        // We can only trust the HTTP_PROXY environment variable in a CLI
        // process due to the fact that PHP has no reliable mechanism to
        // get environment variables that start with "HTTP_".
        if (php_sapi_name() == 'cli' && getenv('HTTP_PROXY')) {
            $defaults['proxy']['http'] = getenv('HTTP_PROXY');
        }

        if ($proxy = getenv('HTTPS_PROXY')) {
            $defaults['proxy']['https'] = $proxy;
        }

        if ($noProxy = getenv('NO_PROXY')) {
            $cleanedNoProxy = str_replace(' ', '', $noProxy);
            $defaults['proxy']['no'] = explode(',', $cleanedNoProxy);
        }

        $this->config = $config + $defaults;

        if (!empty($config['cookies']) && $config['cookies'] === true) {
            $this->config['cookies'] = new CookieJar();
        }

        // Add the default user-agent header.
        if (!isset($this->config['headers'])) {
            $this->config['headers'] = ['User-Agent' => default_user_agent()];
        } else {
            // Add the User-Agent header if one was not already set.
            foreach (array_keys($this->config['headers']) as $name) {
                if (strtolower($name) === 'user-agent') {
                    return;
                }
            }
            $this->config['headers']['User-Agent'] = default_user_agent();
        }
    }
343031
protected function _errorHandler($enable, $options = [])
    {
        $defaults = ['handler' => null];
        $options += $defaults;
        if (!$enable) {
            return restore_error_handler();
        }
        $handler = function ($code, $message, $file, $line = 0, $args = []) {
            if (error_reporting() === 0) {
                return;
            }
            $trace = debug_backtrace();
            $trace = array_slice($trace, 1, count($trace));
            $message = "`" . Debugger::errorType($code) . "` {$message}";
            $code = 0;
            $exception = compact('code', 'message', 'file', 'line', 'trace');
            throw new PhpErrorException($exception);
        };
        $options['handler'] = $options['handler'] ?: $handler;
        set_error_handler($options['handler'], error_reporting());
    }
1050694
protected function configureEncoding(array $config)
	{
		if( isset($config['charset']))
		{
			$this->pdo->prepare(
				"set names '{$config['charset']}'".$this->getCollation($config)
			)->execute();
		}
	}
483182
protected function applyRoles(array $config) : void
    {
        $this->stdout("Init roles: " . count($config) . "\n", Console::FG_YELLOW);
        foreach ($config as $item) {
            if ($role = $this->applyRole($item)) {
                $this->stdout("\t- success: " . $role->name . "\n", Console::FG_GREEN);
            } else {
                $this->stdout("\t- error config role: " . Json::encode($item) . "\n", Console::FG_RED);
            }
        }
    }
197528
public function initialize(array $config)
    {
        parent::initialize($config);

        $this->dir     = Configure::read('Cms.docDir');
        $this->locale  = Configure::read('App.defaultLocale');
        $this->charset = Str::low(Configure::read('App.encoding'));
        $this->eol     = (Configure::read('debug')) ? PHP_EOL : '';
        $this->tab     = (Configure::read('debug')) ? Configure::read('Cms.lineTab') : '';
    }
1327578
public static function start(&$config)
    {
        $config = array_merge(array(
        
            /* @var bool */
            'catch_errors'           => false,
            
            /* @var bool */
            'throw_errors'           => false,
            
            /* Which view to render when an error occurs
             * @var string */
            'error_view'             => 'errors/error',
            
            /* Which view to render when an error occurs
             * @var string */
            '404_view'               => 'errors/404',
            
            /* @var array */
            'error_report_attrs'     => array(
                'atomik-error'               => 'style="padding: 10px"',
                'atomik-error-title'         => 'style="font-size: 1.3em; font-weight: bold; color: #FF0000"',
                'atomik-error-lines'         => 'style="width: 100%; margin-bottom: 20px; background-color: #fff;'
                                              . 'border: 1px solid #000; font-size: 0.8em"',
                'atomik-error-line'          => '',
                'atomik-error-line-error'    => 'style="background-color: #ffe8e7"',
                'atomik-error-line-number'   => 'style="background-color: #eeeeee"',
                'atomik-error-line-text'     => '',
                'atomik-error-stack'         => ''
            )
            
        ), $config);
        self::$config = &$config;

        Atomik::registerHelper('renderException', 'Atomik\Errors::render');
        
        // checks if we are in the CLI
        if (PHP_SAPI === 'cli') {
            return false;
        }
    }
364971
public function init( $config = [ ] )
    {
        if ( isset( $_SERVER[ 'HTTP_USER_AGENT' ] ) )
        {
            $this->userAgent = $_SERVER[ 'HTTP_USER_AGENT' ];
        }
        if ( isset( $_SERVER[ 'SERVER_NAME' ] ) )
        {
            $this->server = $_SERVER[ 'SERVER_NAME' ];
        }
        if ( isset( $_SERVER[ 'SERVER_PORT' ] ) )
        {
            $this->port = $_SERVER[ 'SERVER_PORT' ];
        }
        if ( isset( $_SERVER[ 'REQUEST_METHOD' ] ) )
        {
            $this->method = $_SERVER[ 'REQUEST_METHOD' ];
        }
        if ( isset( $_SERVER[ 'QUERY_STRING' ] ) )
        {
            $this->query = $_SERVER[ 'QUERY_STRING' ];
        }
        if ( isset( $_SERVER[ 'SCRIPT_NAME' ] ) )
        {
            $this->script = $_SERVER[ 'SCRIPT_NAME' ];
        }
        if ( isset( $_SERVER[ 'REQUEST_URI' ] ) )
        {
            $this->requestUri = $_SERVER[ 'REQUEST_URI' ];
        }
        if ( isset( $_SERVER[ 'REQUEST_SCHEME' ] ) )
        {
            $this->scheme = $_SERVER[ 'REQUEST_SCHEME' ];
        }

        $request = str_replace( $_SERVER[ 'SCRIPT_NAME' ], '', $this->requestUri );

        $elements = explode( '/', $request );

        if ( '' === $elements[ 0 ] )
        {
            array_shift( $elements );
        }

        if ( 2 <= count( $elements ) )
        {
            $this->route = $elements[ 0 ] . '/' . $elements[ 1 ];

            array_shift( $elements );
            array_shift( $elements );

            if ( 0 < count( $elements ) )
            {
                $this->params = $elements;
            }
        }
        else if ( 1 === count( $elements ) )
        {
            $this->route = $elements[ 0 ];

            array_shift( $elements );
        }
    }