inline() public static method

Generates a file where classes and their parents are inlined.
public static inline ( array $classes, string $cache, array $excluded ) : array
$classes array An array of classes to load
$cache string The file where classes are inlined
$excluded array An array of classes that won't be inlined
return array The source map of inlined classes, with classes as keys and files as values
Esempio n. 1
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);
 }
    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));
    }