public function testOpenContainerInstanceByName() { $container = new Container(); $container->name = 'instanceName'; $container->secure = true; $this->matchInstances($container, Container::open('instanceName', false, true)); }
public function __construct() { $this->container = parent::open('ServerData', true, true); foreach ($_SERVER as $key => $value) { $this->container->add($key, $value); } }
/** * @param string $name Name of the config to be added. * @param string $src Path to the config. */ public function add($name, $src = '') { $config = $this->path . $name . '.php'; if (!empty($src)) { $config = $src . $name . '.php'; } if (!FileSystem::has($config) || FileSystem::getVisibility($config) !== 'public') { throw new Exception("Config file does not exist or is not readable ({$config})"); } $this->configList[$name] = (require vibius_BASEPATH . $config); $config = (require vibius_BASEPATH . $config); $c_[$name] = Container::open("Config.{$name}", true, true); foreach ($config as $key => $value) { $c_[$name]->add($key, $value); } $this->container->add("Config.{$name}", $c_[$name]); }
/** * Method used to handle static calls to aliasies. */ public static function __callStatic($method, $parameters) { $container = Container::open('aliases'); $class = get_called_class(); $class = strtolower($class); if (!$container->exists($class)) { $newClass = $class::getFacadeIdentifier(); $container->add($class, $newClass); } if ($container->exists($class)) { $instance = $container->get($class); } if (!method_exists($instance, $method)) { throw new Exception(" Method ({$method}) of class ({$class}) does not exist"); } return call_user_func_array(array($instance, $method), $parameters); }
function __construct() { $this->container = parent::open('RequestData', true, true); $this->postData = parent::open('POST', true, true); $this->getData = parent::open('GET', true, true); $this->requestData = parent::open('REQUEST', true, true); $this->cookieData = parent::open('COOKIE', true, true); $this->sessionData = parent::open('SESSION', true, true); if (!empty($_SERVER['REDIRECT_URL'])) { $appRoot = explode(Server::get('DOCUMENT_ROOT'), vibius_INDEXPATH); if (!empty($appRoot[1])) { $appRoot = $appRoot[1]; $reqUri = explode($appRoot, Server::get('REDIRECT_URL')); } else { $reqUri = Server::get('REDIRECT_URL'); } } else { $reqUri = []; } if (!isset($reqUri[1])) { $reqUri = '/'; } else { $reqUri = $reqUri[1]; } foreach ($_GET as $key => $value) { $this->getData->add($key, $value); } foreach ($_POST as $key => $value) { $this->postData->add($key, $value); } foreach ($_REQUEST as $key => $value) { $this->requestData->add($key, $value); } foreach ($_COOKIE as $key => $value) { $this->cookieData->add($key, $value); } $this->container->add('get', $this->getData); $this->container->add('post', $this->postData); $this->container->add('request', $this->requestData); $this->container->add('session', $this->sessionData); $this->container->add('cookie', $this->cookieData); $this->uri = $reqUri; }
/** * This method is used to find a component from composer's psr4, which serves requested alias. * @param string $class Name of the alias to be looked for in psr4 autoloading array. * @return boolean True if alias was found and created. */ public function findAlias($class) { $container = Container::open('aliases'); if ($container->exists($class)) { $instance = $container->get($class); $config['provider'] = $instance; if (is_object($instance)) { Container::open('instances')->add($class, $instance); $config['provider'] = 'PlaceHolderClass'; } $result = $this->createAlias($class, $config); return $result; } if (!isset($this->manifestResolver)) { $psr4 = (require vibius_BASEPATH . 'vendor/composer/autoload_psr4.php'); $manifestResolver = new ManifestResolver($psr4); $this->manifestResolver = $manifestResolver; $manifestResolver->findManifests(); } $manifestResolver = $this->manifestResolver; foreach ($manifestResolver->manifests as $manifestName => $manifestSrc) { $manifest = $manifestResolver->getManifest($manifestSrc); if ($manifestData = $manifestResolver->verifyManifest($manifest)) { foreach ($manifestData['components'] as $component => $componentConfig) { if ($manifestResolver->verifyComponent($componentConfig)) { if ($class === $componentConfig['alias']) { $componentSrc = explode('../manifest.php', $manifestSrc)[0]; $result = $this->createAlias($class, $componentConfig); return $result; } } } } } }