protected function __construct() { $services = Config::getInstance()->get('service_manager'); $this->factories = isset($services[self::FACTORIES]) ? $services[self::FACTORIES] : array(); $this->instances = isset($services[self::INSTANCES]) ? $services[self::INSTANCES] : array(); $this->singletons = isset($services[self::SINGLETONS]) ? $services[self::SINGLETONS] : array(); $this->closures = isset($services[self::CLOSURES]) ? $services[self::CLOSURES] : array(); }
public function __construct() { parent::__construct(); $config = Config::getInstance()->get('view_manager'); $this->config = $config['module'][Router::getInstance()->getModule()]; $this->viewstack = isset($this->config['template_path_stack']) ? $this->config['template_path_stack'] : ""; // get the variables given }
protected function __construct() { // get available modules $this->modules = Config::getInstance()->get("modules"); // get the router configurations $config = Config::getInstance()->get("router"); $this->routes = $config['routes']; // then get the query string $this->querystring = Request::getInstance()->getQuery(); $this->parseRequest(); }
public function __construct($arrayOfItems = array()) { parent::__construct(); $config = Config::getInstance()->get('view_manager'); $this->config = $config['module'][Router::getInstance()->getModule()]; $this->viewstack = isset($this->config['template_path_stack']) ? $this->config['template_path_stack'] : ""; // get the variables given foreach ($arrayOfItems as $key => $value) { $this->{$key} = $value; } }
/** * * @param string $configarray Array with fields host, username, password, database, driver * If not given it'll fall back to the config class db field * @throws \RuntimeException */ public function __construct($configarray = null) { if ($configarray == null) { $configarray = Config::getInstance()->get('db'); } // fall back to the default configuration switch ($configarray['driver']) { case 'Pdo_MySql': $this->driver = PdoDriver::getInstance(); break; default: throw new \RuntimeException("The '" . $configarray['driver'] . "' is not a valid Sql driver."); } $this->driver->init($configarray['host'], $configarray['database'], $configarray['username'], $configarray['password']); }
public function __construct($configarray = null) { if ($configarray == null) { $configarray = Config::getInstance()->get('storage'); // get default configuration } switch ($configarray['driver']) { case 'Filesystem': $this->driver = FileSystem::getInstance(); break; case 'Memcached': $this->driver = Memcached::getInstance(); break; default: throw new \RuntimeException("The '" . $configarray['driver'] . "' is not a valid Sql driver."); } $this->driver->init($configarray['prefix'], $configarray['ttl'], $configarray['cache_dir']); }
public function init() { $config = Config::getInstance()->get('translator'); $module = Router::getInstance()->getModule(); $dir = $config['module'][$module]['directory']; $content = file_get_contents($dir . $this->locale . ".po"); preg_match_all('$msgid "[^"]*$', $content, $keys); foreach ($keys[0] as $key) { $Keys[] = rtrim(substr($key, 7), "\""); } // array_shift($Keys); // get the first item from the header preg_match_all('$msgstr "[^"]*"$', $content, $values); array_shift($Keys); array_shift($values[0]); array_walk($values[0], function (&$key) { $key = rtrim($key, "\""); $key = substr($key, strlen("msgstr ") + 1, strlen($key)); }); $this->textdomain = array_combine($Keys, $values[0]); }
/** * An url built up by our router configuration * @param string $routeName * @param array $options * @return string */ public function toRoute($routeName, $options = array(), $getParams = array()) { if (!is_string($routeName)) { throw new \Exception("Invalid type for routename"); } $router = Config::getInstance()->get('router'); // check if there is a route with that name in the configuration if (array_key_exists($routeName, $router['routes'])) { // literal route, so return the basepath to it if ($router['routes'][$routeName]['type'] == "Literal") { $url = BASEPATH . $router['routes'][$routeName]['options']['base']; if (!empty($getParams)) { $url .= "?"; } foreach ($getParams as $key => $value) { $url .= "{$key}={$value}&"; } return rtrim($url, "&"); } elseif ($router['routes'][$routeName]['type'] == "Segment") { $url = rtrim(BASEPATH . $router['routes'][$routeName]['options']['base'], "/"); foreach ($router['routes'][$routeName]['options']['segments'] as $segment) { if (is_array($options) && array_key_exists($segment, $options)) { $url .= "/" . $options[$segment]; } } if (!empty($getParams)) { $url .= "?"; } foreach ($getParams as $key => $value) { $url .= "{$key}={$value}&"; } return rtrim($url, "&"); } else { throw new \Exception("Invalide configuration for route '{$routeName}'"); } } else { return BASEPATH; } }
/** * The redirector method * @param string $routeName The route name specified in routing configuration * @param array $options Options to that route * @throws \Exception */ public function toRoute($routeName, $options = array()) { $router = Config::getInstance()->get('router'); // check if there is a route with that name in the configuration if (array_key_exists($routeName, $router['routes'])) { // literal route, so return the basepath to it if ($router['routes'][$routeName]['type'] == "Literal") { $route['controller'] = $router['routes'][$routeName]['options']['defaults']['controller']; $route['module'] = $router['routes'][$routeName]['options']['defaults']['module']; $route['action'] = $router['routes'][$routeName]['options']['defaults']['action']; Router::getInstance()->setRoute($route); } elseif ($router['routes'][$routeName]['type'] == "Segment") { $options = array_merge($options, $router['routes'][$routeName]['options']['defaults']); Router::getInstance()->setRoute($options); } else { throw new \Exception("Invalid configuration for route '{$routeName}'"); } } else { throw new \Exception("No route specified with name '{$routeName}'"); } try { $newrouter = Router::getInstance(); // assign a new controller $controller = $newrouter->getController(); // and action $action = $newrouter->getAction(); $c = new $controller(); $view = $c->{$action}(); $c->getLayout()->render($view); } catch (\RuntimeException $e) { die($e->getMessage()); } catch (\Exception $e) { die($e->getMessage()); $this->displayFatalErrors($e); } exit; // terminate the request }
public function __construct() { $this->view_config = Config::getInstance()->get('view_manager'); }
<?php use NoahBuscher\Macaw\Macaw; use System\Helper\Container\Container; use Whoops\Run as Whoops; use Whoops\Handler\PrettyPageHandler; use Illuminate\Database\Capsule\Manager as Capsule; use System\Helper\Config; use System\Services\Redis; $config = new Config(ROOT_PATH . '/config/config.yaml', Config::RESULT_AS_ARRAY); $config->toArray(); $container = new Container(); // Route Service $container->set('route', function () { return Macaw::class; }); // Redis Service $container->set('redis', function () use(&$config) { return new Redis($config['redis']); }); // View Service $container->set('view', function () use(&$config) { $loader = new Twig_Loader_Filesystem(ROOT_PATH . $config['path']['template']); $twig = new Twig_Environment($loader, ['cache' => ROOT_PATH . $config['path']['cache']]); return $twig; }); // Debug Service $container->set('debug', function () { // whoops 错误提醒 $whoops = new Whoops(); $whoops->pushHandler(new PrettyPageHandler());