Author: Fabien Potencier (fabien@symfony.com)
 /**
  * @param string $cacheDir
  */
 public function warmUp($cacheDir)
 {
     $mapFile = $cacheDir . '/classes.map';
     if (is_file($mapFile)) {
         ClassCollectionLoader::load(include $mapFile, $cacheDir, 'classes', $this->kernel->isDebug(), false, '.php');
     }
 }
Example #2
0
 protected function createClassCache($cacheDir, $debug)
 {
     $classmap = $cacheDir . '/classes.map';
     if (is_file($classmap)) {
         ClassCollectionLoader::load(include $classmap, $cacheDir, 'classes', $debug, false, '.php');
     }
 }
Example #3
0
 /**
  * Warms up the cache.
  *
  * @param string $cacheDir The cache directory
  */
 public function warmUp($cacheDir)
 {
     $classmap = $cacheDir . '/classes.map';
     if (!is_file($classmap)) {
         return;
     }
     ClassCollectionLoader::load(include $classmap, $cacheDir, 'classes', false);
 }
Example #4
0
 public static function doBuildBootstrap($appDir)
 {
     $file = $appDir . '/bootstrap.php.cache';
     if (file_exists($file)) {
         unlink($file);
     }
     ClassCollectionLoader::load(array('Symfony\\Component\\DependencyInjection\\ContainerAwareInterface', 'Symfony\\Component\\DependencyInjection\\Container', 'Symfony\\Component\\HttpKernel\\Kernel', 'Symfony\\Component\\ClassLoader\\ClassCollectionLoader', 'Symfony\\Component\\ClassLoader\\ApcClassLoader', 'Symfony\\Component\\HttpKernel\\Bundle\\Bundle', 'Symfony\\Component\\Config\\ConfigCache', 'Symfony\\Bundle\\FrameworkBundle\\HttpKernel'), dirname($file), basename($file, '.php.cache'), false, false, '.php.cache');
     file_put_contents($file, sprintf("<?php\n\nnamespace { \$loader = require_once __DIR__.'/autoload.php'; }\n\n%s\n\nnamespace { return \$loader; }\n            ", substr(file_get_contents($file), 5)));
 }
Example #5
0
 /**
  * Warms up the cache.
  *
  * @param string $cacheDir The cache directory
  */
 public function warmUp($cacheDir)
 {
     $classmap = $cacheDir . '/classes.map';
     if (!is_file($classmap)) {
         return;
     }
     if (file_exists($cacheDir . '/classes.php')) {
         return;
     }
     $declared = null !== $this->declaredClasses ? $this->declaredClasses : array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits());
     ClassCollectionLoader::inline(include $classmap, $cacheDir . '/classes.php', $declared);
 }
 /**
  * {@inheritDoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $kernel = $this->getContainer()->get('kernel');
     $classmap = $kernel->getCacheDir() . '/classes.map';
     if (!is_file($classmap)) {
         throw new \RuntimeException(sprintf('The file %s does not exist', $classmap));
     }
     $name = 'classes';
     $extension = '.php';
     $output->write("<info>Writing cache file ...</info>");
     ClassCollectionLoader::load(include $classmap, $kernel->getCacheDir(), $name, $kernel->isDebug(), false, $extension);
     $output->writeln(" done!");
 }
 /**
  * Boots the Bundle.
  */
 public function boot()
 {
     // load core classes
     ClassCollectionLoader::load($this->container->getParameter('kernel.compiled_classes'), $this->container->getParameter('kernel.cache_dir'), 'classes', $this->container->getParameter('kernel.debug'), true);
     if ($this->container->has('error_handler')) {
         $this->container->get('error_handler');
     }
     if ($this->container->hasParameter('document_root')) {
         File::setDocumentRoot($this->container->getParameter('document_root'));
     }
     if (file_exists($this->container->getParameter('kernel.cache_dir') . '/autoload.php')) {
         $classloader = new MapFileClassLoader($this->container->getParameter('kernel.cache_dir') . '/autoload.php');
         $classloader->register(true);
     }
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $kernel = $this->getContainer()->get('kernel');
     $output->writeln(sprintf('Warming up the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
     $warmer = $this->getContainer()->get('cache_warmer');
     if (!$input->getOption('no-optional-warmers')) {
         $warmer->enableOptionalWarmers();
     }
     $cacheDir = $this->getContainer()->getParameter('kernel.cache_dir');
     $warmer->warmUp($cacheDir);
     $classmap = $cacheDir . '/classes.map';
     if (is_file($classmap)) {
         ClassCollectionLoader::load(include $classmap, $cacheDir, 'classes', $kernel->isDebug(), false, '.php');
     }
 }
    public function testFixNamespaceDeclarations()
    {
        $source = <<<EOF
<?php

namespace Foo;
class Foo {}
namespace   Bar ;
class Foo {}
namespace Foo\\Bar;
class Foo {}
namespace Foo\\Bar\\Bar
{
    class Foo {}
}
namespace
{
    class Foo {}
}
EOF;
        $expected = <<<EOF
<?php

namespace Foo
{
class Foo {}
}
namespace   Bar 
{
class Foo {}
}
namespace Foo\\Bar
{
class Foo {}
}
namespace Foo\\Bar\\Bar
{
    class Foo {}
}
namespace
{
    class Foo {}
}
EOF;
        $this->assertEquals($expected, ClassCollectionLoader::fixNamespaceDeclarations($source));
    }
Example #10
0
 * file that was distributed with this source code.
 */
$argv = $_SERVER['argv'];
// allow the base path to be passed as the first argument, or default
if (isset($argv[1])) {
    $baseDir = $argv[1];
} else {
    if (!($baseDir = realpath(__DIR__ . '/..'))) {
        exit('Looks like you don\'t have a standard layout.');
    }
}
require_once $baseDir . '/vendor/symfony/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
use Symfony\Component\ClassLoader\UniversalClassLoader;
use Symfony\Component\ClassLoader\ClassCollectionLoader;
$loader = new UniversalClassLoader();
$loader->registerNamespaces(array('Symfony' => $baseDir . '/vendor/symfony/symfony/src'));
$loader->register();
$file = $baseDir . '/app/bootstrap.php.cache';
if (file_exists($file)) {
    unlink($file);
}
ClassCollectionLoader::load(array('Symfony\\Component\\DependencyInjection\\ContainerAwareInterface', 'Symfony\\Component\\DependencyInjection\\ContainerInterface', 'Symfony\\Component\\DependencyInjection\\Container', 'Symfony\\Component\\HttpKernel\\HttpKernelInterface', 'Symfony\\Component\\HttpKernel\\KernelInterface', 'Symfony\\Component\\HttpKernel\\Kernel', 'Symfony\\Component\\ClassLoader\\ClassCollectionLoader', 'Symfony\\Component\\ClassLoader\\UniversalClassLoader', 'Symfony\\Component\\HttpKernel\\Bundle\\Bundle', 'Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface', 'Symfony\\Component\\Config\\ConfigCache'), dirname($file), basename($file, '.php.cache'), false, false, '.php.cache');
file_put_contents($file, "<?php\n\nnamespace { require_once __DIR__.'/autoload.php'; }\n\n" . substr(file_get_contents($file), 5));
Example #11
0
#!/usr/bin/env php
<?php 
// Compiles EmailMakr into one big PHP file
// Ported from Sismo https://github.com/fabpot/Sismo
use Symfony\Component\ClassLoader\ClassCollectionLoader;
require_once __DIR__ . '/vendor/autoload.php';
@mkdir(__DIR__ . '/build', 0777, true);
@unlink(__DIR__ . '/build/emailmakr.php');
$classes = array('Pimple', 'Sensio\\Command\\Build', 'Symfony\\Component\\Console\\Application', 'Symfony\\Component\\Console\\Command\\Command', 'Symfony\\Component\\Console\\Command\\HelpCommand', 'Symfony\\Component\\Console\\Command\\ListCommand', 'Symfony\\Component\\Console\\Descriptor\\ApplicationDescription', 'Symfony\\Component\\Console\\Descriptor\\JsonDescriptor', 'Symfony\\Component\\Console\\Descriptor\\MarkdownDescriptor', 'Symfony\\Component\\Console\\Descriptor\\TextDescriptor', 'Symfony\\Component\\Console\\Descriptor\\XmlDescriptor', 'Symfony\\Component\\Console\\Formatter\\OutputFormatter', 'Symfony\\Component\\Console\\Formatter\\OutputFormatterStyle', 'Symfony\\Component\\Console\\Formatter\\OutputFormatterStyleStack', 'Symfony\\Component\\Console\\Helper\\DescriptorHelper', 'Symfony\\Component\\Console\\Helper\\DialogHelper', 'Symfony\\Component\\Console\\Helper\\FormatterHelper', 'Symfony\\Component\\Console\\Helper\\Helper', 'Symfony\\Component\\Console\\Helper\\HelperSet', 'Symfony\\Component\\Console\\Helper\\ProgressHelper', 'Symfony\\Component\\Console\\Helper\\TableHelper', 'Symfony\\Component\\Console\\Input\\ArgvInput', 'Symfony\\Component\\Console\\Input\\ArrayInput', 'Symfony\\Component\\Console\\Input\\Input', 'Symfony\\Component\\Console\\Input\\InputArgument', 'Symfony\\Component\\Console\\Input\\InputDefinition', 'Symfony\\Component\\Console\\Input\\InputOption', 'Symfony\\Component\\Console\\Input\\StringInput', 'Symfony\\Component\\Console\\Output\\ConsoleOutput', 'Symfony\\Component\\Console\\Output\\NullOutput', 'Symfony\\Component\\Console\\Output\\Output', 'Symfony\\Component\\Console\\Output\\StreamOutput', 'Symfony\\Component\\Console\\Shell', 'Twig_Autoloader', 'Twig_Compiler', 'Twig_Environment', 'Twig_Error', 'Twig_Error_Loader', 'Twig_Error_Runtime', 'Twig_Error_Syntax', 'Twig_ExpressionParser', 'Twig_Extension_Core', 'Twig_Extension_Debug', 'Twig_Extension_Escaper', 'Twig_Extension_Optimizer', 'Twig_Extension_Sandbox', 'Twig_Extension_Staging', 'Twig_Filter_Function', 'Twig_Filter_Method', 'Twig_Filter_Node', 'Twig_Function_Function', 'Twig_Function_Method', 'Twig_Function_Node', 'Twig_Lexer', 'Twig_Loader_Array', 'Twig_Loader_Chain', 'Twig_Loader_Filesystem', 'Twig_Loader_String', 'Twig_Markup', 'Twig_Node', 'Twig_Node_AutoEscape', 'Twig_Node_Block', 'Twig_Node_BlockReference', 'Twig_Node_Body', 'Twig_Node_Do', 'Twig_Node_Embed', 'Twig_Node_Expression_Array', 'Twig_Node_Expression_AssignName', 'Twig_Node_Expression_Binary_Add', 'Twig_Node_Expression_Binary_And', 'Twig_Node_Expression_Binary_BitwiseAnd', 'Twig_Node_Expression_Binary_BitwiseOr', 'Twig_Node_Expression_Binary_BitwiseXor', 'Twig_Node_Expression_Binary_Concat', 'Twig_Node_Expression_Binary_Div', 'Twig_Node_Expression_Binary_Equal', 'Twig_Node_Expression_Binary_FloorDiv', 'Twig_Node_Expression_Binary_Greater', 'Twig_Node_Expression_Binary_GreaterEqual', 'Twig_Node_Expression_Binary_In', 'Twig_Node_Expression_Binary_Less', 'Twig_Node_Expression_Binary_LessEqual', 'Twig_Node_Expression_Binary_Mod', 'Twig_Node_Expression_Binary_Mul', 'Twig_Node_Expression_Binary_NotEqual', 'Twig_Node_Expression_Binary_NotIn', 'Twig_Node_Expression_Binary_Or', 'Twig_Node_Expression_Binary_Power', 'Twig_Node_Expression_Binary_Range', 'Twig_Node_Expression_Binary_Sub', 'Twig_Node_Expression_BlockReference', 'Twig_Node_Expression_Conditional', 'Twig_Node_Expression_Constant', 'Twig_Node_Expression_ExtensionReference', 'Twig_Node_Expression_Filter', 'Twig_Node_Expression_Filter_Default', 'Twig_Node_Expression_Function', 'Twig_Node_Expression_GetAttr', 'Twig_Node_Expression_MethodCall', 'Twig_Node_Expression_Name', 'Twig_Node_Expression_Parent', 'Twig_Node_Expression_TempName', 'Twig_Node_Expression_Test', 'Twig_Node_Expression_Test_Constant', 'Twig_Node_Expression_Test_Defined', 'Twig_Node_Expression_Test_Divisibleby', 'Twig_Node_Expression_Test_Even', 'Twig_Node_Expression_Test_Null', 'Twig_Node_Expression_Test_Odd', 'Twig_Node_Expression_Test_Sameas', 'Twig_Node_Expression_Unary_Neg', 'Twig_Node_Expression_Unary_Not', 'Twig_Node_Expression_Unary_Pos', 'Twig_Node_Flush', 'Twig_Node_For', 'Twig_Node_ForLoop', 'Twig_Node_If', 'Twig_Node_Import', 'Twig_Node_Include', 'Twig_Node_Macro', 'Twig_Node_Module', 'Twig_Node_Print', 'Twig_Node_Sandbox', 'Twig_Node_SandboxedModule', 'Twig_Node_SandboxedPrint', 'Twig_Node_Set', 'Twig_Node_SetTemp', 'Twig_Node_Spaceless', 'Twig_Node_Text', 'Twig_NodeTraverser', 'Twig_NodeVisitor_Escaper', 'Twig_NodeVisitor_Optimizer', 'Twig_NodeVisitor_SafeAnalysis', 'Twig_NodeVisitor_Sandbox', 'Twig_Parser', 'Twig_Sandbox_SecurityError', 'Twig_Sandbox_SecurityPolicy', 'Twig_SimpleFilter', 'Twig_SimpleFunction', 'Twig_SimpleTest', 'Twig_Template', 'Twig_Token', 'Twig_TokenParser_AutoEscape', 'Twig_TokenParser_Block', 'Twig_TokenParser_Do', 'Twig_TokenParser_Embed', 'Twig_TokenParser_Extends', 'Twig_TokenParser_Filter', 'Twig_TokenParser_Flush', 'Twig_TokenParser_For', 'Twig_TokenParser_From', 'Twig_TokenParser_If', 'Twig_TokenParser_Import', 'Twig_TokenParser_Include', 'Twig_TokenParser_Macro', 'Twig_TokenParser_Sandbox', 'Twig_TokenParser_Set', 'Twig_TokenParser_Spaceless', 'Twig_TokenParser_Use', 'Twig_TokenParserBroker', 'Twig_TokenStream');
$ccl = new ClassCollectionLoader();
$ccl->load($classes, __DIR__ . '/build', 'emailmakr', false);
$classes = str_replace('<?php', '', file_get_contents(__DIR__ . '/build/emailmakr.php'));
$classes = str_replace("eval('?>'.", 'eval(', $classes);
$app = 'namespace {' . str_replace('<?php', '', file_get_contents(__DIR__ . '/emailmakr')) . '}';
$app = str_replace('#!/usr/bin/env php', '', $app);
$license = file_get_contents(__DIR__ . '/LICENSE');
$content = "#!/usr/bin/env php\n<?php\n\n/*\n{$license}\n*/\n{$classes}\n{$app}\n";
// remove require_once calls
$content = preg_replace('#require_once[^;]+?;#', '', $content);
file_put_contents(__DIR__ . '/build/emailmakr.php', $content);
@chmod(__DIR__ . '/build/emailmakr.php', 0755);
 public static function doBuildBootstrap($appDir)
 {
     $file = $appDir . '/bootstrap.php.cache';
     if (file_exists($file)) {
         unlink($file);
     }
     $classes = array('Symfony\\Component\\HttpFoundation\\ParameterBag', 'Symfony\\Component\\HttpFoundation\\HeaderBag', 'Symfony\\Component\\HttpFoundation\\FileBag', 'Symfony\\Component\\HttpFoundation\\ServerBag', 'Symfony\\Component\\HttpFoundation\\Request', 'Symfony\\Component\\HttpFoundation\\Response', 'Symfony\\Component\\HttpFoundation\\ResponseHeaderBag', 'Symfony\\Component\\DependencyInjection\\ContainerAwareInterface', 'Symfony\\Component\\DependencyInjection\\Container', 'Symfony\\Component\\HttpKernel\\Kernel', 'Symfony\\Component\\ClassLoader\\ClassCollectionLoader', 'Symfony\\Component\\ClassLoader\\ApcClassLoader', 'Symfony\\Component\\HttpKernel\\Bundle\\Bundle', 'Symfony\\Component\\Config\\ConfigCache');
     // introspect the autoloader to get the right file
     // we cannot use class_exist() here as it would load the class
     // which won't be included into the cache then.
     // we know that composer autoloader is first (see bin/build_bootstrap.php)
     $autoloaders = spl_autoload_functions();
     if ($autoloaders[0][0]->findFile('Symfony\\Bundle\\FrameworkBundle\\HttpKernel')) {
         $classes[] = 'Symfony\\Bundle\\FrameworkBundle\\HttpKernel';
     } else {
         $classes[] = 'Symfony\\Component\\HttpKernel\\DependencyInjection\\ContainerAwareHttpKernel';
     }
     ClassCollectionLoader::load($classes, dirname($file), basename($file, '.php.cache'), false, false, '.php.cache');
     file_put_contents($file, sprintf("<?php\n\nnamespace { \$loader = require_once __DIR__.'/autoload.php'; }\n\n%s\n\nnamespace { return \$loader; }\n            ", substr(file_get_contents($file), 5)));
 }
Example #13
0
#!/usr/bin/env php
<?php 
// Compiles the SDK and required Libs into one PHP file.
use Symfony\Component\ClassLoader\ClassCollectionLoader;
use Symfony\Component\Finder\Finder;
require_once __DIR__ . '/../vendor/autoload.php';
// Ensure the build directory is writtable and that any previous
// compiles are deleted.
@mkdir(__DIR__ . '/../build', 0777, true);
@unlink(__DIR__ . '/../build/recensus.php');
$withDeps = getenv('COMPILE_DEPS');
if ($withDeps) {
    $classes = array('Zend_Exception', 'Zend_Registry', 'Zend_Uri', 'Zend_Uri_Exception', 'Zend_Http_Client', 'Zend_Http_Exception', 'Zend_Http_Response', 'Zend_Http_Client_Exception', 'Zend_Http_Client_Adapter_Curl', 'Zend_Http_Client_Adapter_Exception', 'Zend_Http_Client_Adapter_Interface', 'Zend_Http_Client_Adapter_Proxy', 'Zend_Http_Client_Adapter_Socket', 'Zend_Http_Client_Adapter_Stream', 'Zend_Http_Client_Adapter_Test', 'Zend_Http_Response_Stream', 'Zend_Uri_Http', 'Zend_Validate_Abstract', 'Zend_Validate_Exception', 'Zend_Validate_Hostname', 'Zend_Validate_Interface', 'Zend_Validate_Ip', 'Zend_Loader', 'Zend_Loader_Autoloader', 'Zend_Validate_Hostname_Biz', 'Zend_Validate_Hostname_Cn', 'Zend_Validate_Hostname_Com', 'Zend_Validate_Hostname_Jp');
} else {
    $classes = array();
}
$classesToCompile = array_merge($classes, array("Recensus_Api", "Recensus_Api_Exception", "Recensus_Widget", "Recensus_Widget_Exception"));
$ccl = new ClassCollectionLoader();
$ccl->load($classesToCompile, __DIR__ . '/../build', 'recensus', false);
$debug = getenv('COMPILE_DEBUG');
if (!$debug) {
    file_put_contents(__DIR__ . '/../build/recensus.php', "<?php " . str_replace('<?php', '', php_strip_whitespace(__DIR__ . '/../build/recensus.php')));
}
 public function writeCache($file)
 {
     ClassCollectionLoader::load($this->getClassList(), dirname($file), basename($file, '.php.cache'), false, false, '.php.cache');
     $bootstrapContent = substr(file_get_contents($file), $this->phpHeaderOpenTagLength);
     file_put_contents($file, sprintf("<?php\n%s", $bootstrapContent));
 }
Example #15
0
    public function testCommentStripping()
    {
        if (is_file($file = sys_get_temp_dir() . '/bar.php')) {
            unlink($file);
        }
        spl_autoload_register($r = function ($class) {
            if (0 === strpos($class, 'Namespaced') || 0 === strpos($class, 'Pearlike_')) {
                require_once __DIR__ . '/Fixtures/' . str_replace(array('\\', '_'), '/', $class) . '.php';
            }
        });
        ClassCollectionLoader::load(array('Namespaced\\WithComments', 'Pearlike_WithComments'), sys_get_temp_dir(), 'bar', false);
        spl_autoload_unregister($r);
        $this->assertEquals(<<<EOF
namespace Namespaced
{
class WithComments
{
public static \$loaded = true;
}
\$string ='string shoult not be   modified {\$string}';
\$heredoc = (<<<HD


Heredoc should not be   modified {\$string}


HD
);
\$nowdoc =<<<'ND'


Nowdoc should not be   modified {\$string}


ND
;
}
namespace
{
class Pearlike_WithComments
{
public static \$loaded = true;
}
}
EOF
, str_replace("<?php \n", '', file_get_contents($file)));
        unlink($file);
    }
Example #16
0
    public static function doBuildBootstrap($appDir)
    {
        $file = $appDir.'/bootstrap.php.cache';
        if (file_exists($file)) {
            unlink($file);
        }

        $classes = array(
            'Symfony\\Component\\DependencyInjection\\ContainerAwareInterface',
            // Cannot be included because annotations will parse the big compiled class file
            //'Symfony\\Component\\DependencyInjection\\ContainerAware',
            'Symfony\\Component\\DependencyInjection\\Container',
            'Symfony\\Component\\HttpKernel\\Kernel',
            'Symfony\\Component\\ClassLoader\\ClassCollectionLoader',
            'Symfony\\Component\\ClassLoader\\ApcClassLoader',
            'Symfony\\Component\\HttpKernel\\Bundle\\Bundle',
            'Symfony\\Component\\Config\\ConfigCache',
            // cannot be included as commands are discovered based on the path to this class via Reflection
            //'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle',
        );

        // introspect the autoloader to get the right file
        // we cannot use class_exist() here as it would load the class
        // which won't be included into the cache then.
        // we know that composer autoloader is first (see bin/build_bootstrap.php)
        $autoloaders = spl_autoload_functions();
        if ($autoloaders[0][0]->findFile('Symfony\\Bundle\\FrameworkBundle\\HttpKernel')) {
            $classes[] = 'Symfony\\Bundle\\FrameworkBundle\\HttpKernel';
        } else {
            $classes[] = 'Symfony\\Component\\HttpKernel\\DependencyInjection\\ContainerAwareHttpKernel';
        }

        ClassCollectionLoader::load($classes, dirname($file), basename($file, '.php.cache'), false, false, '.php.cache');

        file_put_contents($file, sprintf("<?php

namespace { \$loader = require_once __DIR__.'/autoload.php'; }

%s

namespace { return \$loader; }
            ", substr(file_get_contents($file), 5)));
    }
 /**
  * @expectedException InvalidArgumentException
  */
 public function testUnableToLoadClassException()
 {
     ClassCollectionLoader::load(array('SomeNotExistingClass'), '', 'foo', false);
 }
    public function testInline()
    {
        $this->assertTrue(class_exists(WarmedClass::class, true));
        @unlink($cache = sys_get_temp_dir() . '/inline.php');
        $classes = array(WarmedClass::class);
        $excluded = array(DeclaredClass::class);
        ClassCollectionLoader::inline($classes, $cache, $excluded);
        $this->assertSame(<<<'EOTXT'
<?php 
namespace Symfony\Component\ClassLoader\Tests\Fixtures
{
interface WarmedInterface
{
}
}
namespace Symfony\Component\ClassLoader\Tests\Fixtures
{
class WarmedClass extends DeclaredClass implements WarmedInterface
{
}
}
EOTXT
, file_get_contents($cache));
        unlink($cache);
    }
    public static function doBuildBootstrap($bootstrapDir)
    {
        $file = $bootstrapDir . '/bootstrap.php.cache';
        if (file_exists($file)) {
            unlink($file);
        }
        $classes = array('Symfony\\Component\\HttpFoundation\\ParameterBag', 'Symfony\\Component\\HttpFoundation\\HeaderBag', 'Symfony\\Component\\HttpFoundation\\FileBag', 'Symfony\\Component\\HttpFoundation\\ServerBag', 'Symfony\\Component\\HttpFoundation\\Request', 'Symfony\\Component\\HttpKernel\\Kernel', 'Symfony\\Component\\ClassLoader\\ClassCollectionLoader', 'Symfony\\Component\\ClassLoader\\ApcClassLoader');
        if (method_exists('Symfony\\Component\\ClassLoader\\ClassCollectionLoader', 'inline')) {
            ClassCollectionLoader::inline($classes, $file, array());
        } else {
            ClassCollectionLoader::load($classes, dirname($file), basename($file, '.php.cache'), false, false, '.php.cache');
        }
        $bootstrapContent = substr(file_get_contents($file), 5);
        file_put_contents($file, sprintf(<<<'EOF'
<?php

%s

EOF
, $bootstrapContent));
    }
Example #20
0
<?php

require_once __DIR__ . '/../../../ClassLoader/UniversalClassLoader.php';
/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
use Symfony\Component\ClassLoader\UniversalClassLoader;
use Symfony\Component\ClassLoader\ClassCollectionLoader;
$loader = new UniversalClassLoader();
$loader->registerNamespaces(array('Symfony' => __DIR__ . '/../../../../..'));
$loader->register();
if (file_exists(__DIR__ . '/../../bootstrap.php')) {
    unlink(__DIR__ . '/../../bootstrap.php');
}
ClassCollectionLoader::load(array('Symfony\\Component\\DependencyInjection\\ContainerInterface', 'Symfony\\Component\\DependencyInjection\\Container', 'Symfony\\Component\\DependencyInjection\\ContainerAwareInterface', 'Symfony\\Component\\DependencyInjection\\ContainerAware', 'Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface', 'Symfony\\Component\\HttpKernel\\Bundle\\Bundle', 'Symfony\\Component\\HttpKernel\\Debug\\ErrorHandler', 'Symfony\\Component\\HttpKernel\\HttpKernelInterface', 'Symfony\\Component\\HttpKernel\\HttpKernel', 'Symfony\\Component\\HttpKernel\\KernelInterface', 'Symfony\\Component\\HttpKernel\\Kernel', 'Symfony\\Component\\HttpFoundation\\ParameterBag', 'Symfony\\Component\\HttpFoundation\\FileBag', 'Symfony\\Component\\HttpFoundation\\ServerBag', 'Symfony\\Component\\HttpFoundation\\HeaderBag', 'Symfony\\Component\\HttpFoundation\\Request', 'Symfony\\Component\\HttpFoundation\\ApacheRequest', 'Symfony\\Component\\ClassLoader\\ClassCollectionLoader', 'Symfony\\Component\\ClassLoader\\UniversalClassLoader', 'Symfony\\Component\\ClassLoader\\MapFileClassLoader'), __DIR__ . '/../..', 'bootstrap', false);
if (file_exists(__DIR__ . '/../../bootstrap_cache.php')) {
    unlink(__DIR__ . '/../../bootstrap_cache.php');
}
ClassCollectionLoader::load(array('Symfony\\Component\\HttpKernel\\KernelInterface', 'Symfony\\Component\\HttpKernel\\Kernel', 'Symfony\\Component\\HttpKernel\\HttpKernelInterface', 'Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache', 'Symfony\\Component\\HttpKernel\\HttpCache\\StoreInterface', 'Symfony\\Component\\HttpKernel\\HttpCache\\Store', 'Symfony\\Component\\HttpKernel\\HttpCache\\Esi', 'Symfony\\Component\\HttpFoundation\\ParameterBag', 'Symfony\\Component\\HttpFoundation\\FileBag', 'Symfony\\Component\\HttpFoundation\\ServerBag', 'Symfony\\Component\\HttpFoundation\\HeaderBag', 'Symfony\\Component\\HttpFoundation\\Request', 'Symfony\\Component\\HttpFoundation\\ApacheRequest', 'Symfony\\Component\\HttpFoundation\\ResponseHeaderBag', 'Symfony\\Component\\HttpFoundation\\Response', 'Symfony\\Component\\ClassLoader\\UniversalClassLoader'), __DIR__ . '/../..', 'bootstrap_cache', false);
Example #21
0
    /**
     * Loads the PHP class cache.
     *
     * @param string  $name      The cache name prefix
     * @param string  $extension File extension of the resulting file
     */
    public function loadClassCache($name = 'classes', $extension = '.php')
    {
        if (!$this->booted) {
            $this->boot();
        }

        if ($this->classes) {
            ClassCollectionLoader::load($this->classes, $this->getCacheDir(), $name, $this->debug, true, $extension);
        }
    }
    public function testCommentStripping()
    {
        if (is_file($file = sys_get_temp_dir() . '/bar.php')) {
            unlink($file);
        }
        spl_autoload_register($r = function ($class) {
            require_once __DIR__ . '/Fixtures/' . str_replace(array('\\', '_'), '/', $class) . '.php';
        });
        ClassCollectionLoader::load(array('Namespaced\\WithComments', 'Pearlike_WithComments'), sys_get_temp_dir(), 'bar', false);
        spl_autoload_unregister($r);
        $this->assertEquals(<<<EOF
<?php  



namespace Namespaced
{

class WithComments
{
    
    public static \$loaded = true;
}
}
 
namespace
{




class Pearlike_WithComments
{
    
    public static \$loaded = true;
}

}

EOF
, file_get_contents($file));
        unlink($file);
    }
Example #23
0
 /**
  * Loads the PHP class cache.
  *
  * @param string  $name      The cache name prefix
  * @param string  $extension File extension of the resulting file
  */
 public function loadClassCache($name = 'classes', $extension = '.php')
 {
     if (!$this->booted && file_exists($this->getCacheDir() . '/classes.map')) {
         ClassCollectionLoader::load(include $this->getCacheDir() . '/classes.map', $this->getCacheDir(), $name, $this->debug, false, $extension);
     }
 }
Example #24
0
    public static function doBuildBootstrap($bootstrapDir, $autoloadDir = null, $useNewDirectoryStructure = false)
    {
        $file = $bootstrapDir . '/bootstrap.php.cache';
        if (file_exists($file)) {
            unlink($file);
        }
        $classes = array('Symfony\\Component\\HttpFoundation\\ParameterBag', 'Symfony\\Component\\HttpFoundation\\HeaderBag', 'Symfony\\Component\\HttpFoundation\\FileBag', 'Symfony\\Component\\HttpFoundation\\ServerBag', 'Symfony\\Component\\HttpFoundation\\Request', 'Symfony\\Component\\HttpFoundation\\Response', 'Symfony\\Component\\HttpFoundation\\ResponseHeaderBag', 'Symfony\\Component\\DependencyInjection\\ContainerAwareInterface', 'Symfony\\Component\\DependencyInjection\\Container', 'Symfony\\Component\\HttpKernel\\Kernel', 'Symfony\\Component\\ClassLoader\\ClassCollectionLoader', 'Symfony\\Component\\ClassLoader\\ApcClassLoader', 'Symfony\\Component\\HttpKernel\\Bundle\\Bundle', 'Symfony\\Component\\Config\\ConfigCache');
        // introspect the autoloader to get the right file
        // we cannot use class_exist() here as it would load the class
        // which won't be included into the cache then.
        // we know that composer autoloader is first (see bin/build_bootstrap.php)
        $autoloaders = spl_autoload_functions();
        if (is_array($autoloaders[0]) && method_exists($autoloaders[0][0], 'findFile') && $autoloaders[0][0]->findFile('Symfony\\Bundle\\FrameworkBundle\\HttpKernel')) {
            $classes[] = 'Symfony\\Bundle\\FrameworkBundle\\HttpKernel';
        } else {
            $classes[] = 'Symfony\\Component\\HttpKernel\\DependencyInjection\\ContainerAwareHttpKernel';
        }
        ClassCollectionLoader::load($classes, dirname($file), basename($file, '.php.cache'), false, false, '.php.cache');
        $fs = new Filesystem();
        $bootstrapContent = substr(file_get_contents($file), 5);
        if ($useNewDirectoryStructure) {
            $cacheDir = $fs->makePathRelative($bootstrapDir, $autoloadDir);
            $bootstrapContent = str_replace(array("return \$this->rootDir.'/logs", "return \$this->rootDir.'/cache"), array("return \$this->rootDir.'/" . $cacheDir . "logs", "return \$this->rootDir.'/" . $cacheDir . "cache"), $bootstrapContent);
        }
        if ($autoloadDir) {
            $fs = new Filesystem();
            $autoloadDir = $fs->makePathRelative($autoloadDir, $bootstrapDir);
        }
        file_put_contents($file, sprintf(<<<'EOF'
<?php

namespace {
    error_reporting(error_reporting() & ~E_USER_DEPRECATED);
    $loader = require_once __DIR__.'/%sautoload.php';
}

%s

namespace { return $loader; }

EOF
, $autoloadDir, $bootstrapContent));
    }
 public function testLoadTwiceClass()
 {
     ClassCollectionLoader::load(array('Foo'), '', 'foo', false);
     ClassCollectionLoader::load(array('Foo'), '', 'foo', false);
 }
Example #26
0
use Symfony\Component\ClassLoader\ClassCollectionLoader;

$loader = new UniversalClassLoader();
$loader->registerNamespaces(array('Symfony' => $baseDir.'/vendor/symfony/src'));
$loader->register();

$file = $baseDir.'/app/bootstrap.php.cache';
if (file_exists($file)) {
    unlink($file);
}

ClassCollectionLoader::load(array(
    'Symfony\\Component\\DependencyInjection\\ContainerAwareInterface',
    // Cannot be included because annotations will parse the big compiled class file
    //'Symfony\\Component\\DependencyInjection\\ContainerAware',
    'Symfony\\Component\\DependencyInjection\\ContainerInterface',
    'Symfony\\Component\\DependencyInjection\\Container',
    'Symfony\\Component\\HttpKernel\\HttpKernelInterface',
    'Symfony\\Component\\HttpKernel\\KernelInterface',
    'Symfony\\Component\\HttpKernel\\Kernel',
    'Symfony\\Component\\ClassLoader\\ClassCollectionLoader',
    'Symfony\\Component\\ClassLoader\\UniversalClassLoader',
    'Symfony\\Component\\HttpKernel\\Bundle\\Bundle',
    'Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface',
    'Symfony\\Component\\Config\\ConfigCache',
    // cannot be included as commands are discovered based on the path to this class via Reflection
    //'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle',
), dirname($file), basename($file, '.php.cache'), false, false, '.php.cache');

file_put_contents($file, "<?php\n\nnamespace { require_once __DIR__.'/autoload.php'; }\n\n".substr(file_get_contents($file), 5));
Example #27
0
 protected function doLoadClassCache($name, $extension)
 {
     if (!$this->booted && is_file($this->getCacheDir().'/classes.map')) {
         ClassCollectionLoader::load(include($this->getCacheDir().'/classes.map'), $this->getCacheDir(), $name, $this->debug, false, $extension);
     }
 }
Example #28
0
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../vendor/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
use Symfony\Component\ClassLoader\UniversalClassLoader;
use Symfony\Component\ClassLoader\ClassCollectionLoader;
$loader = new UniversalClassLoader();
$loader->registerNamespaces(array('Symfony' => __DIR__ . '/../vendor/symfony/src'));
$loader->register();
$file = __DIR__ . '/../app/bootstrap.php.cache';
if (file_exists($file)) {
    unlink($file);
}
ClassCollectionLoader::load(array('Symfony\\Component\\DependencyInjection\\ContainerInterface', 'Symfony\\Component\\DependencyInjection\\Container', 'Symfony\\Component\\DependencyInjection\\ContainerAwareInterface', 'Symfony\\Component\\DependencyInjection\\ContainerAware', 'Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface', 'Symfony\\Component\\HttpKernel\\Bundle\\Bundle', 'Symfony\\Component\\HttpKernel\\Debug\\ErrorHandler', 'Symfony\\Component\\HttpKernel\\HttpKernelInterface', 'Symfony\\Component\\HttpKernel\\HttpKernel', 'Symfony\\Component\\HttpKernel\\KernelInterface', 'Symfony\\Component\\HttpKernel\\Kernel', 'Symfony\\Component\\HttpFoundation\\ParameterBag', 'Symfony\\Component\\HttpFoundation\\FileBag', 'Symfony\\Component\\HttpFoundation\\ServerBag', 'Symfony\\Component\\HttpFoundation\\HeaderBag', 'Symfony\\Component\\HttpFoundation\\Request', 'Symfony\\Component\\HttpFoundation\\ApacheRequest', 'Symfony\\Component\\ClassLoader\\ClassCollectionLoader', 'Symfony\\Component\\ClassLoader\\UniversalClassLoader', 'Symfony\\Component\\ClassLoader\\MapFileClassLoader', 'Symfony\\Component\\Config\\ConfigCache'), dirname($file), basename($file, '.php.cache'), false, false, '.php.cache');
file_put_contents($file, "<?php\n\nnamespace { require_once __DIR__.'/autoload.php'; }\n\n" . substr(file_get_contents($file), 5));
$file = __DIR__ . '/../app/bootstrap_cache.php.cache';
if (file_exists($file)) {
    unlink($file);
}
ClassCollectionLoader::load(array('Symfony\\Component\\HttpKernel\\KernelInterface', 'Symfony\\Component\\HttpKernel\\Kernel', 'Symfony\\Component\\HttpKernel\\HttpKernelInterface', 'Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache', 'Symfony\\Component\\HttpKernel\\HttpCache\\StoreInterface', 'Symfony\\Component\\HttpKernel\\HttpCache\\Store', 'Symfony\\Component\\HttpKernel\\HttpCache\\Esi', 'Symfony\\Component\\HttpFoundation\\ParameterBag', 'Symfony\\Component\\HttpFoundation\\FileBag', 'Symfony\\Component\\HttpFoundation\\ServerBag', 'Symfony\\Component\\HttpFoundation\\HeaderBag', 'Symfony\\Component\\HttpFoundation\\Request', 'Symfony\\Component\\HttpFoundation\\ApacheRequest', 'Symfony\\Component\\HttpFoundation\\ResponseHeaderBag', 'Symfony\\Component\\HttpFoundation\\Response', 'Symfony\\Component\\ClassLoader\\UniversalClassLoader'), dirname($file), basename($file, '.php.cache'), false, false, '.php.cache');
file_put_contents($file, "<?php\n\nnamespace { require_once __DIR__.'/autoload.php'; }\n\n" . substr(file_get_contents($file), 5));