Skip to content

Commit

Permalink
[Foundation] added the missing parts of Symfony Foundation
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Feb 17, 2010
1 parent 4a002d7 commit 38aef98
Show file tree
Hide file tree
Showing 14 changed files with 1,776 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Symfony/Foundation/Bundle/Bundle.php
@@ -0,0 +1,31 @@
<?php

namespace Symfony\Foundation\Bundle;

use Symfony\Components\DependencyInjection\ContainerInterface;

/*
* This file is part of the symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

/**
*
*
* @package symfony
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
abstract class Bundle implements BundleInterface
{
public function buildContainer(ContainerInterface $container)
{
}

public function boot(ContainerInterface $container)
{
}
}
27 changes: 27 additions & 0 deletions src/Symfony/Foundation/Bundle/BundleInterface.php
@@ -0,0 +1,27 @@
<?php

namespace Symfony\Foundation\Bundle;

use Symfony\Components\DependencyInjection\ContainerInterface;

/*
* This file is part of the symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

/**
*
*
* @package symfony
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
interface BundleInterface
{
public function buildContainer(ContainerInterface $container);

public function boot(ContainerInterface $container);
}
41 changes: 41 additions & 0 deletions src/Symfony/Foundation/Bundle/KernelBundle.php
@@ -0,0 +1,41 @@
<?php

namespace Symfony\Foundation\Bundle;

use Symfony\Foundation\Bundle\Bundle;
use Symfony\Foundation\ClassCollectionLoader;
use Symfony\Components\DependencyInjection\ContainerInterface;
use Symfony\Components\DependencyInjection\Container;
use Symfony\Components\DependencyInjection\Loader\Loader;
use Symfony\Components\Debug\ErrorHandler;

/*
* This file is part of the symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

/**
*
*
* @package symfony
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class KernelBundle extends Bundle
{
public function buildContainer(ContainerInterface $container)
{
Loader::registerExtension(new KernelExtension());
}

public function boot(ContainerInterface $container)
{
$container->getErrorHandlerService();

// load core classes
ClassCollectionLoader::load($container->getParameter('kernel.compiled_classes'), $container->getParameter('kernel.cache_dir'), 'classes', $container->getParameter('kernel.debug'));
}
}
106 changes: 106 additions & 0 deletions src/Symfony/Foundation/Bundle/KernelExtension.php
@@ -0,0 +1,106 @@
<?php

namespace Symfony\Foundation\Bundle;

/*
* This file is part of the symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Components\DependencyInjection\BuilderConfiguration;

/**
*
* @package Symfony
* @author Fabien Potencier <fabien.potencier@symfony-project.org>
*/
class KernelExtension extends LoaderExtension
{
public function configLoad($config)
{
$configuration = new BuilderConfiguration();

$loader = new XmlFileLoader(array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config'));
$configuration->merge($loader->load('services.xml'));

if (isset($config['charset']))
{
$configuration->setParameter('kernel.charset', $config['charset']);
}

if (!array_key_exists('compilation', $config))
{
$classes = array(
'Symfony\\Components\\Routing\\Router',
'Symfony\\Components\\Routing\\RouterInterface',
'Symfony\\Components\\EventDispatcher\\Event',
'Symfony\\Components\\Routing\\Matcher\\UrlMatcherInterface',
'Symfony\\Components\\Routing\\Matcher\\UrlMatcher',
'Symfony\\Components\\RequestHandler\\RequestInterface',
'Symfony\\Components\\RequestHandler\\Request',
'Symfony\\Components\\RequestHandler\\RequestHandler',
'Symfony\\Components\\RequestHandler\\ResponseInterface',
'Symfony\\Components\\RequestHandler\\Response',
'Symfony\\Components\\Templating\\Loader\\LoaderInterface',
'Symfony\\Components\\Templating\\Loader\\Loader',
'Symfony\\Components\\Templating\\Loader\\FilesystemLoader',
'Symfony\\Components\\Templating\\Engine',
'Symfony\\Components\\Templating\\Renderer\\RendererInterface',
'Symfony\\Components\\Templating\\Renderer\\Renderer',
'Symfony\\Components\\Templating\\Renderer\\PhpRenderer',
'Symfony\\Components\\Templating\\Storage\\Storage',
'Symfony\\Components\\Templating\\Storage\\FileStorage',
'Symfony\\Framework\\WebBundle\\Controller',
'Symfony\\Framework\\WebBundle\\Listener\\RequestParser',
'Symfony\\Framework\\WebBundle\\Listener\\ControllerLoader',
'Symfony\\Framework\\WebBundle\\Listener\\ResponseFilter',
'Symfony\\Framework\\WebBundle\\Templating\\Engine',
);
}
else
{
$classes = array();
foreach (explode("\n", $config['compilation']) as $class)
{
if ($class)
{
$classes[] = trim($class);
}
}
}
$configuration->setParameter('kernel.compiled_classes', $classes);

if (array_key_exists('error_handler_level', $config))
{
$configuration->setParameter('error_handler.level', $config['error_handler_level']);
}

return $configuration;
}

/**
* Returns the base path for the XSD files.
*
* @return string The XSD base path
*/
public function getXsdValidationBasePath()
{
return false;
}

public function getNamespace()
{
return 'http://www.symfony-project.org/schema/dic/symfony/kernel';
}

public function getAlias()
{
return 'kernel';
}
}
113 changes: 113 additions & 0 deletions src/Symfony/Foundation/ClassCollectionLoader.php
@@ -0,0 +1,113 @@
<?php

namespace Symfony\Foundation;

/*
* This file is part of the symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

/**
*
*
* @package symfony
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class ClassCollectionLoader
{
static public function load($classes, $cacheDir, $name, $autoReload)
{
$cache = $cacheDir.'/'.$name.'.php';

// auto-reload
$reload = false;
if ($autoReload)
{
$metadata = $cacheDir.'/'.$name.'.meta';
if (!file_exists($metadata) || !file_exists($cache))
{
$reload = true;
}
else
{
$time = filemtime($cache);
$meta = unserialize(file_get_contents($metadata));

if ($meta[1] != $classes)
{
$reload = true;
}
else
{
foreach ($meta[0] as $resource)
{
if (!file_exists($resource) || filemtime($resource) > $time)
{
$reload = true;

break;
}
}
}
}
}

if (!$reload && file_exists($cache))
{
require_once $cache;

return;
}

$files = array();
$content = '';
foreach ($classes as $class)
{
if (!class_exists($class) && !interface_exists($class))
{
throw new \InvalidArgumentException(sprintf('Unable to load class "%s"', $class));
}

$r = new \ReflectionClass($class);
$files[] = $r->getFileName();

$content .= preg_replace(array('/^\s*<\?php/', '/\?>\s*$/'), '', file_get_contents($r->getFileName()));
}

// cache the core classes
if (!is_dir(dirname($cache)))
{
mkdir(dirname($cache), 0777, true);
}
self::writeCacheFile($cache, Kernel::stripComments('<?php '.$content));

if ($autoReload)
{
// save the resources
self::writeCacheFile($metadata, serialize(array($files, $classes)));
}
}

static protected function writeCacheFile($file, $content)
{
$tmpFile = tempnam(dirname($file), basename($file));
if (!$fp = @fopen($tmpFile, 'wb'))
{
die(sprintf('Failed to write cache file "%s".', $tmpFile));
}
@fwrite($fp, $content);
@fclose($fp);

if ($content != file_get_contents($tmpFile))
{
die(sprintf('Failed to write cache file "%s" (cache corrupted).', $tmpFile));
}

@rename($tmpFile, $file);
chmod($file, 0644);
}
}
22 changes: 22 additions & 0 deletions src/Symfony/Foundation/Debug/ErrorException.php
@@ -0,0 +1,22 @@
<?php

namespace Symfony\Foundation\Debug;

/*
* This file is part of the symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

/**
*
*
* @package symfony
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class ErrorException extends \Exception
{
}

0 comments on commit 38aef98

Please sign in to comment.