Esempio n. 1
0
 /**
  * {@inheritDoc}
  */
 public function getRepository($name)
 {
     @(list($bundle, $name) = explode(':', $name));
     if (!$name) {
         return parent::getRepository($bundle);
     }
     $bundle = $this->kernel->getBundle($bundle);
     return parent::getRepository($bundle->getNamespace() . '\\' . $name);
 }
 /**
  * @param string $bundle
  * @return $this
  */
 public function addMappingBundle($bundle)
 {
     $path = $this->kernel->getBundle($bundle)->getPath();
     $path .= DIRECTORY_SEPARATOR . 'Resources';
     $path .= DIRECTORY_SEPARATOR . 'config';
     $path .= DIRECTORY_SEPARATOR . 'doctrine';
     $this->addMappingPath($path);
     return $this;
 }
 /**
  * {@inheritdoc}
  *
  * @param string $resourcePath Eg. "@AcmeBundle/Resources/views/template.html.twig"
  */
 public function locateResource($resourcePath, ThemeInterface $theme)
 {
     $this->assertResourcePathIsValid($resourcePath);
     $bundleName = $this->getBundleNameFromResourcePath($resourcePath);
     $resourceName = $this->getResourceNameFromResourcePath($resourcePath);
     $bundles = $this->kernel->getBundle($bundleName, false);
     foreach ($bundles as $bundle) {
         $path = sprintf('%s/%s/%s', $theme->getPath(), $bundle->getName(), $resourceName);
         if ($this->filesystem->exists($path)) {
             return $path;
         }
     }
     throw new ResourceNotFoundException($resourcePath, $theme);
 }
 public function resolvePath(string $path) : string
 {
     $resourcePathExploded = explode('/', $path);
     $resourcePathRoot = array_shift($resourcePathExploded);
     if (strpos($resourcePathRoot, '@') === 0) {
         $mappingFileBundle = ltrim($resourcePathRoot, '@');
         $bundle = $this->kernel->getBundle($mappingFileBundle);
         if ($bundle instanceof BundleInterface) {
             $resourcePathRoot = $bundle->getPath();
         }
     }
     array_unshift($resourcePathExploded, $resourcePathRoot);
     return implode('/', $resourcePathExploded);
 }
Esempio n. 5
0
 /**
  *
  * @return array
  */
 protected function getFixturesByBundles()
 {
     if (empty($this->bundles)) {
         throw new \RuntimeException('Bundles are not defined');
     }
     $paths = array();
     foreach ($this->bundles as $name) {
         $bundle = $this->kernel->getBundle($name);
         if (!$bundle) {
             throw new \RuntimeException(sprintf('unknown bundle %s', $bundle));
         }
         $paths[] = $bundle->getPath() . '/Resources/fixtures';
     }
     return $paths;
 }
Esempio n. 6
0
 /**
  * {@inheritDoc}
  * Add the new bundle to the BundleBundle loader infrastructure instead of main kernel
  *
  * @param QuestionHelper  $questionHelper dialog
  * @param InputInterface  $input          input
  * @param OutputInterface $output         output
  * @param KernelInterface $kernel         kernel
  * @param string          $namespace      namespace
  * @param string          $bundle         bundle
  *
  * @return string[]
  */
 protected function updateKernel(QuestionHelper $questionHelper, InputInterface $input, OutputInterface $output, KernelInterface $kernel, $namespace, $bundle)
 {
     // skip if kernel manipulation disabled by options (defaults to true)
     $doUpdate = $input->getOption('doUpdateKernel');
     if ($doUpdate == 'false') {
         return;
     }
     $auto = true;
     if ($input->isInteractive()) {
         $auto = $questionHelper->doAsk($output, $questionHelper->getQuestion('Confirm automatic update of your core bundle', 'yes', '?'));
     }
     $output->write('Enabling the bundle inside the core bundle: ');
     $coreBundle = $kernel->getBundle($input->getOption('loaderBundleName'));
     if (!is_a($coreBundle, '\\Graviton\\BundleBundle\\GravitonBundleInterface')) {
         throw new \LogicException('GravitonCoreBundle does not implement GravitonBundleInterface');
     }
     $manip = new BundleBundleManipulator($coreBundle);
     try {
         $ret = $auto ? $manip->addBundle($namespace . '\\' . $bundle) : false;
         if (!$ret) {
             $reflected = new \ReflectionObject($kernel);
             return array(sprintf('- Edit <comment>%s</comment>', $reflected->getFilename()), '  and add the following bundle in the <comment>GravitonCoreBundle::getBundles()</comment> method:', '', sprintf('    <comment>new %s(),</comment>', $namespace . '\\' . $bundle), '');
         }
     } catch (\RuntimeException $e) {
         return array(sprintf('Bundle <comment>%s</comment> is already defined in <comment>%s)</comment>.', $namespace . '\\' . $bundle, 'sGravitonCoreBundle::getBundles()'), '');
     }
 }
 /**
  * @param string         $resourcePath
  * @param ThemeInterface $theme
  */
 protected function getBundlePaths($resourcePath, ThemeInterface $theme)
 {
     $bundleName = $this->getBundleNameFromResourcePath($resourcePath);
     $resourceName = $this->getResourceNameFromResourcePath($resourcePath);
     $bundles = $this->kernel->getBundle($bundleName, false);
     $paths = [];
     if (is_array($bundles)) {
         foreach ($bundles as $bundle) {
             if ($this->deviceDetection->getType() !== null) {
                 $paths[] = sprintf('%s/%s/%s/%s', $theme->getPath(), $this->deviceDetection->getType(), $bundle->getName(), $resourceName);
             }
             $paths[] = sprintf('%s/%s/%s', $theme->getPath(), $bundle->getName(), $resourceName);
         }
     }
     return $paths;
 }
Esempio n. 8
0
 /**
  * {@inheritdoc}
  */
 public function getBundle($name, $first = true)
 {
     if (!empty($this->excludeBundleNames) && in_array($name, $this->excludeBundleNames)) {
         throw new \InvalidArgumentException(sprintf('Bundle "%s" is in exclude list.', $name));
     }
     return $this->kernel->getBundle($name, $first);
 }
 function it_uses_suite_name_as_a_bundle_name_if_no_provided(KernelInterface $kernel, BundleInterface $bundle)
 {
     $kernel->getBundle('my_suite')->willReturn($bundle);
     $suite = $this->generateSuite('my_suite', array());
     $suite->shouldBeAnInstanceOf('Behat\\Symfony2Extension\\Suite\\SymfonyBundleSuite');
     $suite->getBundle()->shouldReturn($bundle);
     $suite->getSetting('bundle')->shouldReturn('my_suite');
 }
 function it_locates_resource(PathCheckerInterface $pathChecker, KernelInterface $kernel, BundleInterface $bundle)
 {
     $bundle->getName()->willReturn("Bundle");
     $bundle->getPath()->willReturn("/app/bundle");
     $kernel->getBundle("Bundle", false)->willReturn([$bundle]);
     $pathChecker->processPaths(Argument::type('array'), Argument::type('array'), [])->shouldBeCalled()->willReturn("/app/bundle/resource");
     $this->locateResource("@Bundle/Resources/resource", [])->shouldReturn("/app/bundle/resource");
 }
 /**
  * If there is a parameter named like the driver locator path, replace it
  * with the value of such parameter.
  *
  * @param SimpleDoctrineMappingLocator $locator Locator
  *
  * @throws ConfigurationInvalidException Configuration invalid
  */
 public function configure(SimpleDoctrineMappingLocator $locator)
 {
     $path = $locator->getPaths()[0];
     $resourcePathExploded = explode('/', $path);
     $resourcePathRoot = array_shift($resourcePathExploded);
     if (strpos($resourcePathRoot, '@') === 0) {
         $mappingFileBundle = ltrim($resourcePathRoot, '@');
         $bundle = $this->kernel->getBundle($mappingFileBundle);
         if ($bundle instanceof BundleInterface) {
             $resourcePathRoot = $bundle->getPath();
         }
     }
     array_unshift($resourcePathExploded, $resourcePathRoot);
     $path = implode('/', $resourcePathExploded);
     if (!file_exists($path)) {
         throw new ConfigurationInvalidException('Mapping file "' . $path . '" does not exist');
     }
     $locator->setPaths([$path]);
 }
 /**
  * {@inheritdoc}
  */
 public function parse($name)
 {
     if ($name instanceof TemplateReferenceInterface) {
         return $name;
     } elseif (isset($this->cache[$name])) {
         return $this->cache[$name];
     }
     if (!preg_match('/^(?:@([^\\/]*)|)(?:\\/(.+))?\\/(.+)\\.([^\\.]+)\\.([^\\.]+)$/', $name, $matches)) {
         return $this->decoratedParser->parse($name);
     }
     $template = new TemplateReference($matches[1] ? $matches[1] . 'Bundle' : '', $matches[2], $matches[3], $matches[4], $matches[5]);
     if ($template->get('bundle')) {
         try {
             $this->kernel->getBundle($template->get('bundle'));
         } catch (\Exception $e) {
             throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid.', $name), 0, $e);
         }
     }
     return $this->cache[$name] = $template;
 }
 function it_throws_an_exception_if_resource_can_not_be_located(Filesystem $filesystem, KernelInterface $kernel, ThemeInterface $theme, BundleInterface $childBundle, BundleInterface $parentBundle)
 {
     $kernel->getBundle('ParentBundle', false)->willReturn([$childBundle, $parentBundle]);
     $childBundle->getName()->willReturn('ChildBundle');
     $parentBundle->getName()->willReturn('ParentBundle');
     $theme->getName()->willReturn('theme/name');
     $theme->getPath()->willReturn('/theme/path');
     $filesystem->exists('/theme/path/ChildBundle/views/index.html.twig')->shouldBeCalled()->willReturn(false);
     $filesystem->exists('/theme/path/ParentBundle/views/index.html.twig')->shouldBeCalled()->willReturn(false);
     $this->shouldThrow(ResourceNotFoundException::class)->during('locateResource', ['@ParentBundle/Resources/views/index.html.twig', $theme]);
 }
Esempio n. 14
0
 /**
  * Guesses and returns the template name to render based on the controller
  * and action names.
  *
  * @param  array                     $controller An array storing the controller object and action method
  * @param  Request                   $request    A Request instance
  * @param  string                    $engine
  * @return TemplateReference         template reference
  * @throws \InvalidArgumentException
  */
 public function guessTemplateName($controller, Request $request, $engine = 'twig')
 {
     $className = class_exists('Doctrine\\Common\\Util\\ClassUtils') ? ClassUtils::getClass($controller[0]) : get_class($controller[0]);
     if (!preg_match('/Controller\\\\(.+)Controller$/', $className, $matchController)) {
         throw new \InvalidArgumentException(sprintf('The "%s" class does not look like a controller class (it must be in a "Controller" sub-namespace and the class name must end with "Controller")', get_class($controller[0])));
     }
     if (!preg_match('/^(.+)Action$/', $controller[1], $matchAction)) {
         throw new \InvalidArgumentException(sprintf('The "%s" method does not look like an action method (it does not end with Action)', $controller[1]));
     }
     $bundle = $this->getBundleForClass($className);
     while ($bundleName = $bundle->getName()) {
         if (null === ($parentBundleName = $bundle->getParent())) {
             $bundleName = $bundle->getName();
             break;
         }
         $bundles = $this->kernel->getBundle($parentBundleName, false);
         $bundle = array_pop($bundles);
     }
     return new TemplateReference($bundleName, $matchController[1], $matchAction[1], $request->getRequestFormat(), $engine);
 }
 public function guessTemplateName($controllerClassName, $actionName)
 {
     if (!preg_match('/Controller\\\\(.+)Controller$/', $controllerClassName, $matchController)) {
         throw new \InvalidArgumentException(sprintf(''));
     }
     $bundle = $this->getBundleForClass($controllerClassName);
     if ($bundle) {
         while ($bundleName = $bundle->getName()) {
             if (null === ($parentBundleName = $bundle->getParent())) {
                 $bundleName = $bundle->getName();
                 break;
             }
             $bundles = $this->kernel->getBundle($parentBundleName, false);
             $bundle = array_pop($bundles);
         }
     } else {
         $bundleName = null;
     }
     return new TemplateReference($bundleName, $matchController[1], $actionName, 'html', 'twig');
 }
Esempio n. 16
0
 /**
  * Get relative path
  *
  * @param string $bundle_name The name of the bundle
  * @param string $asset       The name of the file
  *
  * @return string
  * @throws RuntimeException
  */
 public function getBundleRelativeWebPath($bundle_name, $asset)
 {
     $elements_path = $this->configuration->getPaths()->getElements();
     $root_path = $this->kernel->getRootDir();
     $bundle_path = $this->kernel->getBundle($bundle_name)->getPath();
     $common_path = $this->findCommonPath([$root_path, $bundle_path]);
     if (!$common_path || strpos($bundle_path, $common_path) !== 0) {
         throw new RuntimeException('Could not determine path to the src/ directory.');
     }
     $bundle_path = ltrim(substr($bundle_path, strlen($common_path)), '/');
     return "/../{$bundle_path}/Resources/public/{$elements_path}/{$asset}";
 }
Esempio n. 17
0
 /**
  * {@inheritdoc}
  */
 public function locateResource($name)
 {
     if ('@' !== $name[0]) {
         throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).', $name));
     }
     if (false !== strpos($name, '..')) {
         throw new \RuntimeException(sprintf('File name "%s" contains invalid characters (..).', $name));
     }
     $bundleName = substr($name, 1);
     $path = '';
     if (false !== strpos($bundleName, '/')) {
         list($bundleName, $path) = explode('/', $bundleName, 2);
     }
     // $overridePath = substr($path, 9);
     $overridePath = '/' . $path;
     // FIXME THIS
     $bundle = $this->kernel->getBundle($bundleName, true);
     if (file_exists($file = $bundle->getPath() . '/' . $overridePath)) {
         return $file;
     }
     throw new \InvalidArgumentException(sprintf('Unable to find file "%s".', $name));
 }
Esempio n. 18
0
 /**
  * Return route collection for injected plugins
  *
  * @return RouteCollection Collection generated
  */
 protected function addPluginRoutesCollection(Plugin $plugin)
 {
     $routes = new RouteCollection();
     $bundleName = $plugin->getBundleName();
     $bundle = $this->kernel->getBundle($bundleName);
     $routingFilePath = '/Resources/config/routing.yml';
     $resourcePath = $bundle->getPath() . $routingFilePath;
     $type = 'yaml';
     if (file_exists($resourcePath)) {
         $routes->addCollection($this->import('@' . $bundle->getName() . $routingFilePath, $type));
     }
     return $routes;
 }
Esempio n. 19
0
 /**
  * {@inheritdoc}
  */
 public function locateTemplate($name)
 {
     if (!$this->isValidFilename($name)) {
         throw new \RuntimeException(sprintf('File name "%s" contains invalid characters (..).', $name));
     }
     list($bundleName, $path) = $this->getBundleNameAndPath($name);
     if (0 !== strpos($path, 'Resources')) {
         throw new \RuntimeException('Template files have to be in Resources.');
     }
     $bundles = $this->kernel->getBundle($bundleName, false);
     $parameters = ['%themes_path%' => $this->getThemesDirectory(), '%current_theme%' => $this->getCurrentThemeFolder(), '%template%' => substr($path, strlen('Resources/views/'))];
     return $this->locateBundlesResource($bundles, $parameters, $path);
 }
 /**
  * {@inheritdoc}
  */
 public function locateResource($resourceName, array $themes = [])
 {
     if (false !== strpos($resourceName, '..')) {
         throw new \RuntimeException(sprintf('File name "%s" contains invalid characters (..).', $resourceName));
     }
     $bundleName = substr($resourceName, 1);
     $resourcePath = '';
     if (false !== strpos($bundleName, '/')) {
         list($bundleName, $resourcePath) = explode('/', $bundleName, 2);
     }
     if (0 !== strpos($resourcePath, 'Resources')) {
         throw new \RuntimeException('Template files have to be in Resources.');
     }
     $bundles = $this->kernel->getBundle($bundleName, false);
     $parameters = array_merge($this->parameters, ['%override_path%' => substr($resourcePath, strlen('Resources/'))]);
     foreach ($bundles as $bundle) {
         $parameters = array_merge($parameters, ['%bundle_name%' => $bundle->getName(), '%bundle_path%' => $bundle->getPath()]);
         $checkedPath = $this->pathChecker->processPaths($this->paths, $parameters, $themes);
         if (null !== $checkedPath) {
             return $checkedPath;
         }
     }
     return null;
 }
Esempio n. 21
0
 /**
  * Guesses and returns the template name to render based on the controller
  * and action names.
  *
  * @param callable $controller An array storing the controller object and action method
  * @param Request  $request    A Request instance
  * @param string   $engine
  *
  * @return TemplateReference template reference
  *
  * @throws \InvalidArgumentException
  */
 public function guessTemplateName($controller, Request $request, $engine = 'twig')
 {
     if (is_object($controller) && method_exists($controller, '__invoke')) {
         $controller = array($controller, '__invoke');
     } elseif (!is_array($controller)) {
         throw new \InvalidArgumentException(sprintf('First argument of %s must be an array callable or an object defining the magic method __invoke. "%s" given.', __METHOD__, gettype($controller)));
     }
     $className = class_exists('Doctrine\\Common\\Util\\ClassUtils') ? ClassUtils::getClass($controller[0]) : get_class($controller[0]);
     $matchController = null;
     foreach ($this->controllerPatterns as $pattern) {
         if (preg_match($pattern, $className, $tempMatch)) {
             $matchController = $tempMatch;
             break;
         }
     }
     if (null === $matchController) {
         throw new \InvalidArgumentException(sprintf('The "%s" class does not look like a controller class (its FQN must match one of the following regexps: "%s")', get_class($controller[0]), implode('", "', $this->controllerPatterns)));
     }
     if ($controller[1] === '__invoke') {
         $matchAction = $matchController;
         $matchController = null;
     } elseif (!preg_match('/^(.+)Action$/', $controller[1], $matchAction)) {
         $matchAction = array(null, $controller[1]);
     }
     $bundle = $this->getBundleForClass($className);
     if ($bundle) {
         while ($bundleName = $bundle->getName()) {
             if (null === ($parentBundleName = $bundle->getParent())) {
                 $bundleName = $bundle->getName();
                 break;
             }
             $bundles = $this->kernel->getBundle($parentBundleName, false);
             $bundle = array_pop($bundles);
         }
     } else {
         $bundleName = null;
     }
     return new TemplateReference($bundleName, $matchController[1], $matchAction[1], $request->getRequestFormat(), $engine);
 }
 protected function getFinalSchemas(KernelInterface $kernel, BundleInterface $bundle = null)
 {
     $aclSchema = new \SplFileInfo($kernel->locateResource('@PropelBundle/Resources/acl_schema.xml'));
     return array((string) $aclSchema => array($kernel->getBundle('PropelBundle'), $aclSchema));
 }
 function it_throws_an_exception_if_namespaced_path_references_not_existing_bundle(KernelInterface $kernel)
 {
     $kernel->getBundle('AcmeBundle')->willThrow(\Exception::class);
     $this->shouldThrow(\InvalidArgumentException::class)->during('parse', ['@Acme/app.html.twig']);
 }
 /**
  * @param string $source
  * @param string $locale
  *
  * @return MessageCatalogueInterface | null
  */
 public function extract($source, $locale)
 {
     if (!$this->isSourceAvailable($source)) {
         return;
     }
     $fs = new Filesystem();
     /* @var Bundle $foundBundle */
     $foundBundle = $this->kernel->getBundle($this->bundle);
     // load any messages from templates
     $extractedCatalogue = new MessageCatalogue($locale);
     $resourcesDir = $this->resolveResourcesDirectory($foundBundle);
     if ($fs->exists($resourcesDir)) {
         $this->extractor->extract($resourcesDir, $extractedCatalogue);
     }
     // load any existing messages from the translation files
     $translationsDir = $foundBundle->getPath() . '/Resources/translations';
     if ($fs->exists($translationsDir)) {
         $currentCatalogue = new MessageCatalogue($locale);
         $this->loader->loadMessages($translationsDir, $currentCatalogue);
         foreach ($extractedCatalogue->getDomains() as $domain) {
             $messages = $currentCatalogue->all($domain);
             if (count($messages)) {
                 $extractedCatalogue->add($messages, $domain);
             }
         }
     }
     return $extractedCatalogue;
 }