AppKernel.php 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /*
  3. * Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. namespace JMS\DiExtraBundle\Tests\Functional;
  18. require_once __DIR__.'/../bootstrap.php';
  19. use Symfony\Component\Filesystem\Filesystem;
  20. use Symfony\Component\Config\Loader\LoaderInterface;
  21. use Symfony\Component\HttpKernel\Kernel;
  22. class AppKernel extends Kernel
  23. {
  24. private $config;
  25. public function __construct($config, $debug = true)
  26. {
  27. parent::__construct('test', $debug);
  28. $fs = new Filesystem();
  29. if (!$fs->isAbsolutePath($config)) {
  30. $config = __DIR__.'/config/'.$config;
  31. }
  32. if (!file_exists($config)) {
  33. throw new \RuntimeException(sprintf('The config file "%s" does not exist.', $config));
  34. }
  35. $this->config = $config;
  36. }
  37. public function registerBundles()
  38. {
  39. return array(
  40. new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
  41. new \Symfony\Bundle\SecurityBundle\SecurityBundle(),
  42. new \Symfony\Bundle\TwigBundle\TwigBundle(),
  43. new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
  44. new \Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
  45. new \JMS\AopBundle\JMSAopBundle(),
  46. new \JMS\DiExtraBundle\Tests\Functional\Bundle\TestBundle\JMSDiExtraTestBundle(),
  47. new \JMS\DiExtraBundle\JMSDiExtraBundle($this),
  48. new \JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
  49. );
  50. }
  51. public function registerContainerConfiguration(LoaderInterface $loader)
  52. {
  53. $loader->load($this->config);
  54. }
  55. public function getCacheDir()
  56. {
  57. return sys_get_temp_dir().'/JMSDiExtraBundle/'.substr(sha1($this->config), 0, 6);
  58. }
  59. public function serialize()
  60. {
  61. return serialize(array($this->config, $this->isDebug()));
  62. }
  63. public function unserialize($str)
  64. {
  65. call_user_func_array(array($this, '__construct'), unserialize($str));
  66. }
  67. }