Example #1
0
 public function __destruct()
 {
     if ($this->loader) {
         $this->loader->unregister();
         $this->loader = NULL;
     }
 }
Example #2
0
 /**
  * Runa a command in and returns the commandTester object. This method can
  * run either a blend command or a sub-application command
  * @param string $projectFolder
  * @param string $commandName
  * @param string $params
  * @param string $app In case of null it will be set to blend. In case of
  * className as string, the application's class name will be used
  * @return CommandTester
  */
 public static function runCommand($projectFolder, $commandName, array $params = [], $app = null, $runOptions = [])
 {
     $loader = new ClassLoader();
     $curDir = getcwd();
     chdir($projectFolder);
     if ($app === null) {
         $app = new SetupApplication($projectFolder);
     } else {
         if (is_string($app)) {
             $classes = explode('\\', $app);
             $loader->addPsr4("{$classes[0]}\\", $projectFolder . '/src/');
             $loader->register(true);
             $c = new Container();
             $c->defineSingletonWithInterface('app', $app, ['scriptPath' => $projectFolder . '/bin']);
             $app = $c->get('app');
         }
     }
     $commandTester = new CommandTester($app->find($commandName));
     $commandTester->execute($params, $runOptions);
     chdir($curDir);
     $c = null;
     if ($loader) {
         $loader->unregister();
     }
     return $commandTester;
 }
Example #3
0
 /**
  * Builds internal request handling objects.
  *
  * @return $this
  */
 public function build()
 {
     if ($this->cache) {
         $loader = new ClassLoader();
         if ($this->apc) {
             $apcLoader = new ApcClassLoader(sha1('ReactServer'), $loader);
             $loader->unregister();
             $apcLoader->register(true);
         }
     }
     require_once $this->root_dir . '/AppKernel.php';
     define('KERNEL_ROOT', $this->root_dir);
     $kernel = new ReactKernel($this->env, $this->env === 'dev' ? true : false);
     $this->loop = Factory::create();
     // TODO make config for this part
     if (class_exists('\\Doctrine\\DBAL\\Driver\\PingableConnection')) {
         $this->loop->addPeriodicTimer(15, function () use($kernel) {
             foreach ($kernel->getContainer()->get('doctrine')->getConnections() as $connection) {
                 if ($connection instanceof \Doctrine\DBAL\Driver\PingableConnection) {
                     $connection->ping();
                 }
             }
         });
     }
     $this->socket = new SocketServer($this->loop);
     $http = new HttpServer($this->socket, $this->loop);
     $http->on('request', $this->handleRequest($kernel));
     return $this;
 }
Example #4
0
 static function activate(ClassLoader $loader)
 {
     self::$loader = $loader;
     self::$loader->unregister();
     self::$activated = [__CLASS__ => __CLASS__];
     self::$included = [__CLASS__ => __CLASS__];
     self::$error_reporting = error_reporting();
     // Регистрация метода-обработчика автозагрузки классов
     spl_autoload_register(['\\boolive\\core\\Core', 'loadClass'], true, true);
     // Регистрация метода-обработчка завершения выполнения системы
     register_shutdown_function(['\\boolive\\core\\Core', 'deactivate']);
     // Регистрация обработчика исключений
     set_exception_handler(['\\boolive\\core\\Core', 'exception']);
     // Регистрация обработчика ошибок
     set_error_handler(['\\boolive\\core\\Core', 'error']);
     // Временая зона
     date_default_timezone_set('UTC');
     // Настройка кодировки
     mb_internal_encoding('UTF-8');
     mb_regex_encoding('UTF-8');
     mb_http_output('UTF-8');
     // При необходимости, каждый класс может автоматически подключиться и активироваться, обработав событие Core::activate.
     \boolive\core\events\Events::trigger('Core::activate');
 }
Example #5
0
 /**
  * @covers ::findFile
  */
 public function testFindFile()
 {
     $finder = new ClassFinder();
     // The full path is returned therefore only tests with
     // assertStringEndsWith() so the test is portable.
     $this->assertStringEndsWith('core/tests/Drupal/Tests/UnitTestCase.php', $finder->findFile(UnitTestCase::class));
     $class = 'Not\\A\\Class';
     $this->assertNull($finder->findFile($class));
     // Register an autoloader that can find this class.
     $loader = new ClassLoader();
     $loader->addClassMap([$class => __FILE__]);
     $loader->register();
     $this->assertEquals(__FILE__, $finder->findFile($class));
     // This shouldn't prevent us from finding the original file.
     $this->assertStringEndsWith('core/tests/Drupal/Tests/UnitTestCase.php', $finder->findFile(UnitTestCase::class));
     // Clean up the additional autoloader after the test.
     $loader->unregister();
 }
Example #6
0
 /**
  * Builds internal request handling objects.
  *
  * @return $this
  */
 public function build()
 {
     if ($this->cache) {
         $loader = new ClassLoader();
         if ($this->apc) {
             $apcLoader = new ApcClassLoader(sha1('ReactServer'), $loader);
             $loader->unregister();
             $apcLoader->register(true);
         }
     }
     require_once $this->root_dir . '/AppKernel.php';
     define('KERNEL_ROOT', $this->root_dir);
     $kernel = new ReactKernel($this->env, $this->env === 'dev' ? true : false);
     $this->loop = Factory::create();
     $this->socket = new SocketServer($this->loop);
     $http = new HttpServer($this->socket, $this->loop);
     $http->on('request', $this->handleRequest($kernel));
     return $this;
 }
Example #7
0
 public static function run(ClassLoader $autoloader)
 {
     // Converts warnings to exceptions
     ErrorHandler::register();
     $config = self::loadConfig();
     if (isset($config['extension_autoloader']) && $config['extension_autoloader']) {
         $autoloadFile = $config['extension_autoloader'];
         if (!file_exists($autoloadFile)) {
             throw new \InvalidArgumentException(sprintf('Could not find extension autoload file "%s"', $autoloadFile));
         }
         $autoloader->unregister();
         include $autoloadFile;
         $autoloader->register(true);
     }
     $extensions = $config['extensions'];
     $extensions[] = 'PhpBench\\Extension\\CoreExtension';
     unset($config['extensions']);
     $container = new Container($extensions, $config);
     $container->init();
     $container->get('console.application')->run();
 }
Example #8
0
 /**
  * Registers this instance as an autoloader.
  *
  * @param bool $prepend Whether to prepend the autoloader or not
  */
 public function register($prepend = false)
 {
     $this->composerClassLoader->unregister();
     spl_autoload_register(array($this, 'loadClassWithAlias'), true, $prepend);
 }
Example #9
0
 /**
  * Locate site path and initialize settings singleton.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request.
  *
  * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
  *   In case the host name in the request is not trusted.
  */
 protected function initializeSettings(Request $request)
 {
     $site_path = static::findSitePath($request);
     $this->setSitePath($site_path);
     $class_loader_class = get_class($this->classLoader);
     Settings::initialize($this->root, $site_path, $this->classLoader);
     // Initialize our list of trusted HTTP Host headers to protect against
     // header attacks.
     $host_patterns = Settings::get('trusted_host_patterns', array());
     if (PHP_SAPI !== 'cli' && !empty($host_patterns)) {
         if (static::setupTrustedHosts($request, $host_patterns) === FALSE) {
             throw new BadRequestHttpException('The provided host name is not valid for this server.');
         }
     }
     // If the class loader is still the same, possibly upgrade to the APC class
     // loader.
     if ($class_loader_class == get_class($this->classLoader) && Settings::get('class_loader_auto_detect', TRUE) && function_exists('apcu_fetch')) {
         $prefix = Settings::getApcuPrefix('class_loader', $this->root);
         $apc_loader = new ApcClassLoader($prefix, $this->classLoader);
         $this->classLoader->unregister();
         $apc_loader->register();
         $this->classLoader = $apc_loader;
     }
 }
Example #10
0
 /**
  * @param ComposerClassLoader $composerClassLoader
  */
 public function __construct(ComposerClassLoader $composerClassLoader)
 {
     $composerClassLoader->unregister();
     $this->composerClassLoader = $composerClassLoader;
 }
Example #11
0
 /**
  * Reloac class loader
  */
 protected function reloadClassLoader()
 {
     $this->classLoader->unregister();
     $this->classLoader = $this->generateClassLoader($this->getComposer());
     $this->classLoader->register();
 }
 private function unRegisterLoader()
 {
     $this->loader->unregister();
 }