Symfony\Component\HttpKernel\DataCollector\ConfigDataCollector::collect PHP Метод

collect() публичный Метод

public collect ( Request $request, Response $response, Exception $exception = null )
$request Symfony\Component\HttpFoundation\Request
$response Symfony\Component\HttpFoundation\Response
$exception Exception
    public function collect(Request $request, Response $response, \Exception $exception = null)
    {
        $this->data = array(
            'app_name' => $this->name,
            'app_version' => $this->version,
            'token' => $response->headers->get('X-Debug-Token'),
            'symfony_version' => Kernel::VERSION,
            'symfony_state' => 'unknown',
            'name' => isset($this->kernel) ? $this->kernel->getName() : 'n/a',
            'env' => isset($this->kernel) ? $this->kernel->getEnvironment() : 'n/a',
            'debug' => isset($this->kernel) ? $this->kernel->isDebug() : 'n/a',
            'php_version' => PHP_VERSION,
            'php_architecture' => PHP_INT_SIZE * 8,
            'php_intl_locale' => class_exists('Locale', false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a',
            'php_timezone' => date_default_timezone_get(),
            'xdebug_enabled' => extension_loaded('xdebug'),
            'apcu_enabled' => extension_loaded('apcu') && ini_get('apc.enabled'),
            'zend_opcache_enabled' => extension_loaded('Zend OPcache') && ini_get('opcache.enable'),
            'bundles' => array(),
            'sapi_name' => PHP_SAPI,
        );

        if (isset($this->kernel)) {
            foreach ($this->kernel->getBundles() as $name => $bundle) {
                $this->data['bundles'][$name] = $bundle->getPath();
            }

            $this->data['symfony_state'] = $this->determineSymfonyState();
            $this->data['symfony_minor_version'] = sprintf('%s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION);
            $eom = \DateTime::createFromFormat('m/Y', Kernel::END_OF_MAINTENANCE);
            $eol = \DateTime::createFromFormat('m/Y', Kernel::END_OF_LIFE);
            $this->data['symfony_eom'] = $eom->format('F Y');
            $this->data['symfony_eol'] = $eol->format('F Y');
        }

        if (preg_match('~^(\d+(?:\.\d+)*)(.+)?$~', $this->data['php_version'], $matches) && isset($matches[2])) {
            $this->data['php_version'] = $matches[1];
            $this->data['php_version_extra'] = $matches[2];
        }
    }

Usage Example

Пример #1
0
 public function testCollect()
 {
     $kernel = new KernelForTest('test', true);
     $c = new ConfigDataCollector();
     $c->setCacheVersionInfo(false);
     $c->setKernel($kernel);
     $c->collect(new Request(), new Response());
     $this->assertSame('test', $c->getEnv());
     $this->assertTrue($c->isDebug());
     $this->assertSame('config', $c->getName());
     $this->assertSame('testkernel', $c->getAppName());
     $this->assertSame(PHP_VERSION, $c->getPhpVersion());
     $this->assertSame(Kernel::VERSION, $c->getSymfonyVersion());
     $this->assertNull($c->getToken());
     // if else clause because we don't know it
     if (extension_loaded('xdebug')) {
         $this->assertTrue($c->hasXDebug());
     } else {
         $this->assertFalse($c->hasXDebug());
     }
     // if else clause because we don't know it
     if (extension_loaded('eaccelerator') && ini_get('eaccelerator.enable') || extension_loaded('apc') && ini_get('apc.enabled') || extension_loaded('Zend OPcache') && ini_get('opcache.enable') || extension_loaded('xcache') && ini_get('xcache.cacher') || extension_loaded('wincache') && ini_get('wincache.ocenabled')) {
         $this->assertTrue($c->hasAccelerator());
     } else {
         $this->assertFalse($c->hasAccelerator());
     }
 }