/**
  * [container description]
  * @return [type] [description]
  */
 public static function container()
 {
     if (is_null(static::$container)) {
         static::$container = new Feed();
     }
     return static::$container;
 }
Example #2
0
 /**
  * @throws \Exception
  */
 protected function init()
 {
     $this->setEnvironment();
     // Load class aliases
     $aliases = Config::get('aliases');
     foreach ($aliases as $orig => $new) {
         class_alias($orig, $new, true);
     }
     static::$container = new Container();
     Session::init();
     Request::init();
     $this->initRouter();
     $databaseConfig = Config::get('database');
     if ($databaseConfig !== null && is_array($databaseConfig)) {
         $this->capsule = new Capsule();
         foreach ($databaseConfig as $name => $conf) {
             if (array_key_exists('name', $conf) && strlen($conf['name']) > 0) {
                 $name = $conf['name'];
                 unset($conf['name']);
             }
             $this->capsule->addConnection($conf, $name);
         }
         $this->capsule->bootEloquent();
     }
     $hookConfig = Config::get('hooks');
     if (is_array($hookConfig)) {
         foreach ($hookConfig as $event => $callable) {
             EventHandler::addListener($event, $callable);
         }
     }
     EventHandler::triggerEvent('whirlpool-initialized', $this);
 }
Example #3
0
 public function __construct(array $values = array())
 {
     parent::__construct($values);
     if (is_null(static::$container)) {
         static::$container = $this;
     }
 }
Example #4
0
 public static function setUpBeforeClass()
 {
     static::$client = static::createClient();
     static::$router = self::$client->getContainer()->get('router');
     static::$em = self::$client->getContainer()->get('doctrine.orm.entity_manager');
     static::$container = self::getContainer();
 }
 /**
  * __construct function.
  * 
  * @access public
  * @param mixed $name (default: null)
  * @return void
  */
 public function __construct($name = null)
 {
     parent::__construct($name);
     static::$kernel = static::createKernel();
     static::$kernel->boot();
     static::$container = static::$kernel->getContainer();
 }
Example #6
0
 public static function forget()
 {
     $cookie = Config::get('session.cookie');
     static::$container = [];
     setcookie(static::$name, '', time() - 3600, $cookie['path'], $cookie['domain'], $cookie['secure'], $cookie['httponly']);
     unset($_COOKIE[static::$name]);
 }
 /**
  * Registers services to the container.
  *
  * @param ContainerBuilder $container
  *   The ContainerBuilder to register services to.
  */
 public function register(ContainerBuilder $container)
 {
     static::$container = $container;
     $class_map = $this->AutoloaderInit();
     $ns = [];
     foreach ($class_map as $name => $path) {
         $path = preg_replace("/\\.php\$/i", '', $path);
         $path = explode(DIRECTORY_SEPARATOR, $path);
         $name = explode('\\', $name);
         while (end($path) === end($name)) {
             array_pop($path);
             array_pop($name);
         }
         $path = implode(DIRECTORY_SEPARATOR, $path);
         $name = implode('\\', $name);
         if (is_dir($path)) {
             if (is_dir($path . '/Plugin') || is_dir($path . '/Entity') || is_dir($path . '/Element')) {
                 $ns[$name][] = $path;
             }
         }
     }
     foreach ($ns as $name => $path) {
         $path = array_unique($path);
         $ns[$name] = count($path) == 1 ? reset($path) : $path;
     }
     $ns += $container->getParameter('container.namespaces');
     $container->setParameter('container.namespaces', $ns);
     $yaml_loader = new YamlFileLoader($container);
     foreach (static::getFiles('/^.+\\.services\\.yml$/i') as $file) {
         $yaml_loader->load($file);
     }
 }
Example #8
0
 /**
  * Gets container instance
  * @return object
  */
 private static function getContainer()
 {
     if (!static::$container) {
         static::$container = Container::getInstance();
     }
     return static::$container;
 }
Example #9
0
 /**
  * @implement route_alter_variants
  * @fast
  */
 static function route_alter_variants()
 {
     $alters = [];
     static::$container = \Drupal::getContainer();
     foreach (static::getFiles('/^.+\\.routing\\.yml/i') as $file) {
         $info = static::yamlDecode($file)['alter_variants'] ?? [];
         $alters = NestedArray::mergeDeep($alters, $info);
     }
     foreach ($alters as $name => $variants) {
         foreach ($variants as $k => $variant) {
             if (isset($variant['cache'])) {
                 $variant['controller'] = new CacheController($variant['cache'], $variant['controller']);
                 unset($variant['cache']);
             }
             if (isset($variant['redirect'])) {
                 $variant['controller'] = new RedirectController($variant['redirect']);
                 unset($variant['redirect']);
             }
             if (isset($variant['error'])) {
                 $variant['controller'] = new ErrorController($variant['error']);
                 unset($variant['error']);
             }
             if (is_string($variant)) {
                 $variant = ['controller' => $variant];
             }
             if (isset($variant['controller']) && is_string($variant['controller']) && strpos($variant['controller'], '::') !== FALSE) {
                 $variant['controller'] = explode('::', $variant['controller']);
             }
             static::appliesRuleDetect($variant);
             $variants[$k] = $variant;
         }
         $alters[$name] = static::sortByPriority($variants);
     }
     return $alters;
 }
Example #10
0
 private function __construct()
 {
     static::$instance = $this;
     static::$container = Forge::getInstance();
     $this->installErrorHandling();
     $this->detectEnvironment();
 }
Example #11
0
 /**
  * @implement submodule_library_info
  * @fast
  */
 static function submoduleLibraryInfo()
 {
     static $libraries = [];
     if ($libraries) {
         return $libraries;
     }
     static::$container = Drupal::getContainer();
     foreach (static::getFiles('/^.+\\.libraries\\.yml/i') as $file) {
         $name_prefix = str_replace('.libraries.yml', '', basename($file));
         $path = dirname($file);
         $info = self::yamlDecode($file);
         foreach ($info as $name => $library) {
             $library += ['js' => [], 'css' => []];
             $src = [&$library['js']];
             foreach (array_keys($library['css']) as $key) {
                 $src[] =& $library['css'][$key];
             }
             foreach ($src as $src_index => $src_type) {
                 foreach ($src_type as $source => $data) {
                     if ($source[0] !== '/' && file_exists($path . '/' . $source)) {
                         $src[$src_index]['/' . $path . '/' . $source] = $data;
                         unset($src[$src_index][$source]);
                     }
                 }
             }
             $libraries[$name_prefix][$name] = $library;
         }
     }
     return $libraries;
 }
 private static function initKernel()
 {
     static::$kernel = static::createKernel();
     static::$kernel->boot();
     static::$container = static::$kernel->getContainer();
     static::$doctrine = static::$container->get('doctrine');
     static::$om = static::$doctrine->getManager();
 }
 /**
  * Instantiate service container if it's not instantiated yet.
  */
 protected static function instantiateServiceContainer()
 {
     $container = Container::getInstance();
     if (!$container) {
         $container = new Container();
         Container::setInstance($container);
     }
     static::$container = $container;
 }
 /**
  * {@inheritdoc}
  */
 protected function tearDown()
 {
     $this->rollbackTransaction();
     BaseWebTestCase::tearDown();
     static::$client = null;
     static::$container = null;
     static::$kernel = null;
     $this->cleanFixtures();
 }
Example #15
0
 /**
  * Forge is a final Singleton.
  *
  * The Forge requires the illuminate/container for compatibility.
  * Although the constructor exposes the dependency and auto-instantiates
  * the illuminate/container, the option is provided to instantiate the
  * illuminate/container outside of the Forge.
  *
  * @param IlluminateContainer $container
  */
 public function __construct(IlluminateContainer $container = NULL)
 {
     if (!static::$instance) {
         static::$container = $container ?: new IlluminateContainer();
         static::$instance = $this;
         $this->register_aliases();
     }
     return static::$instance;
 }
Example #16
0
File: Proxy.php Project: yunaid/yf
 public static function container($container = null)
 {
     if ($container === null) {
         // get container
         return static::$container;
     } else {
         // set container
         static::$container = $container;
     }
 }
 protected function getContainer(array $options = array())
 {
     if (!static::$container) {
         if (!static::$kernel) {
             static::$kernel = static::createKernel($options);
         }
         static::$kernel->boot();
         static::$container = static::$kernel->getContainer();
     }
     return static::$container;
 }
 /**
  * @return ServiceContainer
  */
 public static function loadContainer($configFile)
 {
     if (!static::$container) {
         $container = new ServiceContainer();
         $iocBinder = new IocBinder($container);
         $iocBinder->preBind();
         $config = (require $configFile);
         $iocBinder->postBind($config);
         static::$container = $container;
     }
     return static::$container;
 }
Example #19
0
 /**
  * Set up before class.
  *
  * @throws RuntimeException unable to start the application
  */
 public static function setUpBeforeClass()
 {
     try {
         static::$kernel = static::createKernel();
         static::$kernel->boot();
         static::$application = new Application(static::$kernel);
         static::$application->setAutoExit(false);
         static::$container = static::$kernel->getContainer();
     } catch (Exception $e) {
         throw new RuntimeException(sprintf('Unable to start the application: %s', $e->getMessage()), $e->getCode(), $e);
     }
     static::createSchema();
 }
Example #20
0
 /**
  * {@inheritdoc}
  */
 public static final function setUpBeforeClass()
 {
     static::$kernel = static::createKernel();
     static::$kernel->boot();
     static::$container = static::$kernel->getContainer();
     if (self::emExists()) {
         static::$em = static::$container->get('doctrine.orm.entity_manager');
     }
     if (static::getIsolationLevel() == self::IM_CLASS && self::emExists()) {
         static::$em->getConnection()->beginTransaction();
     }
     static::doSetUpBeforeClass();
 }
 public static function reset()
 {
     static::$object = null;
     $clname = function_exists('get_called_class') ? get_called_class() : static::$class;
     $class = new ReflectionClass($clname);
     $arr = array_keys($class->getStaticProperties());
     unset($arr[array_search('class', $arr)], $arr[array_search('stack', $arr)], $arr[array_search('object', $arr)], $arr[array_search('container', $arr)], $arr[array_search('variables', $arr)]);
     static::$variables = $arr;
     unset($arr[array_search('stack', $arr)]);
     foreach ($arr as $var) {
         static::${$var} = null;
     }
     static::$container = array();
 }
Example #22
0
 private function scanImplementations()
 {
     static::$container = Drupal::getContainer();
     static::$classes = $this->AutoloaderInit();
     foreach (static::getFiles('/^.+\\.(inc|php)$/i') as $submodule) {
         $code = file_get_contents($submodule);
         preg_match('/\\s+namespace\\s+([^\\s]+)\\s*;/i', $code, $matches);
         $namespace = $matches ? $matches[1] : '';
         preg_match('/\\s+(class|trait|interface)\\s+([^\\s]+)/i', $code, $matches);
         $class = $matches ? $matches[2] : '';
         if ($class && $namespace) {
             $class = $namespace . '\\' . $class;
         }
         if ($class && class_exists($class) && (new ReflectionClass($class))->isInstantiable()) {
             $functions = array_map(function ($method) {
                 return $method->name;
             }, (new ReflectionClass($class))->getMethods(ReflectionMethod::IS_PUBLIC));
         } elseif (!$class) {
             preg_match_all('/\\s+function\\s+([^\\s]+)\\s*\\(/i', $code, $matches);
             $functions = $matches[1];
         } else {
             continue;
         }
         require_once $submodule;
         foreach ($functions as $function) {
             if (!$class && $namespace) {
                 $function = $namespace . '\\' . $function;
             }
             if (!$class && function_exists($function)) {
                 $function_info = new ReflectionFunction($function);
             } elseif ($class && method_exists($class, $function)) {
                 $function_info = new ReflectionMethod($class, $function);
             } else {
                 continue;
             }
             $doc_block = new DocBlock($function_info->getDocComment() ?: '');
             $function = $class ? "{$class}::{$function}" : $function;
             if ($doc_block->event) {
                 $this->events[] = ['name' => $doc_block->event, 'listener' => $class ? $function : $this->generateCallbackName($function), 'priority' => (int) $doc_block->priority];
                 if (!$class) {
                     $doc_block->implement = 'callback';
                 }
             }
             if ($doc_block->implement) {
                 $this->implementations[$doc_block->implement][] = ['uri' => $class ? NULL : $submodule, 'class' => $class, 'function' => $function, 'doc_block' => $doc_block, 'arguments' => $this->convertParametersToString($function_info->getParameters())];
             }
         }
     }
 }
Example #23
0
 protected function init()
 {
     if (static::$container === null) {
         switch ($this->type) {
             case 'memcache':
                 static::$container = Suricate::CacheMemcache(true);
                 break;
             case 'apc':
                 static::$container = Suricate::CacheApc(true);
                 break;
             default:
                 throw new \Exception("Unknown cache type " . $this->type);
                 break;
         }
     }
 }
Example #24
0
 public static function bootstrap($errorCallbacks)
 {
     // Only bootstrap once.
     if (static::$bootstrapped) {
         return;
     }
     // Load helper functions.
     require_once __DIR__ . '/../../../illuminate/support/Illuminate/Support/helpers.php';
     // Directories.
     $basePath = str_finish(realpath(__DIR__ . '/..'), '/');
     $controllersDirectory = $basePath . 'Controllers';
     $modelsDirectory = $basePath . 'Models';
     // Register the autoloader and add directories.
     ClassLoader::register();
     ClassLoader::addDirectories(array($controllersDirectory, $modelsDirectory));
     // Instantiate the container.
     $app = new Container();
     static::$container = $app;
     // Tell facade about the application instance.
     Facade::setFacadeApplication($app);
     // Register application instance with container
     $app['app'] = $app;
     // Set environment.
     $app['env'] = 'production';
     // Enable HTTP Method Override.
     Request::enableHttpMethodParameterOverride();
     // Create the request.
     $app['request'] = Request::createFromGlobals();
     // Register services.
     with(new EventServiceProvider($app))->register();
     with(new RoutingServiceProvider($app))->register();
     // Register aliases.
     foreach (static::$aliases as $alias => $class) {
         class_alias($class, $alias);
     }
     // Load the routes file if it exists.
     if (file_exists($basePath . 'routes.php')) {
         require_once $basePath . 'routes.php';
     }
     // Dispatch on shutdown.
     register_shutdown_function('Seytar\\Routing\\Router::dispatch', $errorCallbacks);
     // Mark bootstrapped.
     static::$bootstrapped = true;
 }
Example #25
0
 /**
  * @implement theme
  * @return array
  */
 public static function load()
 {
     $themes = [];
     static::$container = Drupal::getContainer();
     foreach (static::getFiles('/^.+\\.themes\\.yml/i') as $file) {
         $path = dirname($file);
         $info = static::yamlDecode($file);
         foreach ($info['themes'] ?? [] as $name => $theme) {
             if (!isset($theme['variables'])) {
                 $theme['render element'] = $theme['render element'] ?? 'scope';
             }
             $theme['path'] = $path . '/' . ($theme['path'] ?? 'templates');
             $theme['template'] = $theme['template'] ?? $name;
             $theme += ['pattern' => FALSE, 'preprocess functions' => [], 'override preprocess functions' => TRUE];
             foreach ($theme['preprocess functions'] as $k => $function) {
                 $theme['preprocess functions'][$k] = Submodules::generateCallbackName($function);
             }
             $themes[$name] = $theme;
         }
     }
     return $themes;
 }
Example #26
0
 /**
  * Set container
  *
  * @param  ContainerInterface $container
  * @access public
  * @api
  */
 public function setContainer(ContainerInterface $container)
 {
     static::$container = $container;
 }
 public function setUp()
 {
     $kernel = new \AppKernel('test', true);
     $kernel->boot();
     static::$container = $kernel->getContainer();
 }
Example #28
0
 /**
  * Unsets the global container.
  */
 public static function unsetContainer()
 {
     static::$container = NULL;
 }
Example #29
0
 public static function rebuildContainer()
 {
     static::$container = null;
     static::$container = new TestContainer(array('componentName' => 'com_fakeapp'));
 }
Example #30
0
File: App.php Project: sugiphp/sugi
 public function __construct(array $settings = [])
 {
     parent::__construct();
     foreach ($settings as $key => $value) {
         $this->set($key, $value);
     }
     // Set the default encoding
     mb_internal_encoding("UTF-8");
     // Set output encoding
     mb_http_output("UTF-8");
     // The base path is essential, and should be set on creation, but if it is not - try do guess it.
     $this->conditionalSet("base_path", function () {
         return dirname(dirname(dirname(dirname(__DIR__)))) . "/";
     });
     // web root path
     $this->conditionalSet("www_path", function () {
         return rtrim($this["base_path"], "/") . "/www/";
     });
     // application path
     $this->conditionalSet("app_path", function () {
         return rtrim($this["base_path"], "/") . "/app/";
     });
     // the path to store temporary files
     $this->conditionalSet("temp_path", function () {
         return rtrim($this["base_path"], "/") . "/tmp/";
     });
     // log path
     $this->conditionalSet("log_path", function () {
         return rtrim($this["base_path"], "/") . "/log/";
     });
     // config path
     $this->conditionalSet("config_path", function () {
         return rtrim($this["app_path"], "/") . "/config/";
     });
     // ServerRequest based on PSR-7 ServerRequestInterface
     $this->conditionalSet("request", function () {
         // ServerRequest instance, using values from superglobals
         return ServerRequestFactory::fromGlobals();
     });
     // URI based on PSR-7 UriInterface
     $this->conditionalSet("uri", function () {
         return $this["request"]->getUri();
     });
     // Configuration reader
     $this->conditionalSet("config", function () {
         return $this->prepareConfig($this["config_path"]);
     });
     // File Logger
     $this->conditionalSet("logger", function () {
         return $this->prepareLogger((array) $this->config("logger"));
     });
     // Router
     $this->conditionalSet("router", function () {
         return $this->prepareRouter((array) $this->config("router"));
     });
     // Events
     $this->conditionalSet("dispatcher", function () {
         return $this->prepareDispatcher((array) $this->config("dispatcher"));
     });
     // Caching
     $this->conditionalSet("cache", function () {
         return $this->prepareCache((array) $this->config("cache"));
     });
     //  Are we on development or on production server
     $this->conditionalSet("mode", function () {
         /*
          * To set development environment add the following code in your Apache configuration file
          * <code>
          *  SetEnv APPLICATION_ENV development
          * </code>
          *
          * When PHP runs from CLI (Linux bash) you can set it with
          * export APPLICATION_ENV=development
          * this can be also added in your ~/.bashrc file
          */
         if (defined("APPLICATION_ENV")) {
             return APPLICATION_ENV;
         } elseif ($envMode = getenv("APPLICATION_ENV")) {
             return $envMode;
         } else {
             return "production";
         }
     });
     // Set debug based on setting and/or environment
     $this->conditionalSet("debug", function () {
         if (defined("DEBUG")) {
             return (bool) DEBUG;
         } else {
             return (bool) ($this["mode"] == "development");
         }
     });
     if (!static::$container) {
         static::$container = $this;
     }
 }