Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Foundation] added the missing parts of Symfony Foundation
- Loading branch information
Showing
14 changed files
with
1,776 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
{ | ||
} |
Oops, something went wrong.