Ejemplo n.º 1
0
 function it_falls_back_to_decorated_template_locator_if_there_are_no_themes_active(FileLocatorInterface $decoratedFileLocator, ThemeContextInterface $themeContext, ThemeHierarchyProviderInterface $themeHierarchyProvider, TemplateReferenceInterface $template)
 {
     $themeContext->getTheme()->willReturn(null);
     $themeHierarchyProvider->getThemeHierarchy(null)->willReturn([]);
     $decoratedFileLocator->locate($template, Argument::cetera())->willReturn('/app/template/path');
     $this->locate($template)->shouldReturn('/app/template/path');
 }
Ejemplo n.º 2
0
 /**
  * Load esprima script.
  *
  * @access public
  * @return string
  */
 public function load()
 {
     if (!$this->esprima) {
         $this->esprima = $this->loadFile($this->locator->locate($this->file));
     }
     return $this->esprima;
 }
 /**
  * @inheritdoc
  */
 public function visit(TreeNodeInterface $node, &$data)
 {
     if ($this->getContentTypeIdentifier($node) !== 'ezimage') {
         return null;
     }
     return $this->fileLocator->locate($data);
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function import($file, FileLocatorInterface $locator)
 {
     $path = $locator->locate($file, null, true);
     $path = is_array($path) ? current($path) : $path;
     $xml = $this->parseFile($path);
     $this->importItems($xml);
 }
 public function load($id, $file)
 {
     $class = $this->getDefinitionSourceClass();
     $definition = new Definition($class, [$this->locator->locate($file)]);
     $definition->addTag('di.definition_source');
     $this->container->setDefinition($id, $definition);
 }
Ejemplo n.º 6
0
 /**
  * Get a manipulable image instance.
  *
  * @param string $file the image path
  *
  * @return ImageHandler a manipulable image instance
  */
 public function open($file)
 {
     if (strlen($file) >= 1 && $file[0] == '@') {
         $file = $this->fileLocator instanceof FileLocatorInterface ? $this->fileLocator->locate($file) : $this->fileLocator->locateResource($file);
     }
     return $this->createInstance($file);
 }
Ejemplo n.º 7
0
 /**
  * Load procedure instance by id.
  *
  * @access public
  * @param  string                                         $id
  * @return \JonnyW\PhantomJs\Procedure\ProcedureInterface
  */
 public function load($id)
 {
     $path = $this->locator->locate(sprintf('%s.proc', $id));
     $content = $this->loadFile($path);
     $procedure = $this->procedureFactory->createProcedure();
     $procedure->load($content);
     return $procedure;
 }
Ejemplo n.º 8
0
 function it_does_not_crash_if_themes_not_found(ContainerBuilder $containerBuilder, Definition $themeRepositoryDefinition, LoaderInterface $themeLoader, FileLocatorInterface $themeLocator)
 {
     $themeLocator->locate("theme.json", Argument::any(), false)->shouldBeCalled()->willThrow(new \InvalidArgumentException());
     $containerBuilder->findDefinition("sylius.theme.repository")->shouldBeCalled()->willReturn($themeRepositoryDefinition);
     $containerBuilder->get("sylius.theme.locator")->shouldBeCalled()->willReturn($themeLocator);
     $containerBuilder->get("sylius.theme.loader")->shouldBeCalled()->willReturn($themeLoader);
     $this->process($containerBuilder);
 }
 /**
  * Resolve path to absolute if any bundle is mentioned
  * @param string $path
  * @return string
  */
 private function resolvePath($path)
 {
     try {
         return $this->locator->locate($this->templateNameParser->parse($path));
     } catch (\InvalidArgumentException $e) {
         // happens when path is not bundle relative
         return $this->webRoot . '/' . $path;
     }
 }
Ejemplo n.º 10
0
 public function testParameters()
 {
     $path = Path::join([DATAFIXTURES_DIR, 'config', 'test-parameters.json']);
     $this->locator->locate('test-parameters.json')->willReturn($path);
     $this->container->addResource(Argument::that(function (FileResource $resource) use($path) {
         return $resource->getResource() === $path;
     }))->shouldBeCalled();
     $this->container->loadFromExtension('test-parameters', ['name' => 'test'])->shouldBeCalled();
     $this->container->setParameter('test', 'value')->shouldBeCalled();
     $this->loader->load('test-parameters.json');
 }
Ejemplo n.º 11
0
 /**
  * Loads an XML file.
  *
  * @param mixed  $file The resource
  * @param string $type The resource type
  */
 public function load($file, $type = null)
 {
     $schema = array();
     $path = $this->locator->locate($file);
     $xml = $this->parseFile($path);
     $document = $xml->documentElement;
     /** @var \DOMElement $setting */
     $prefix = $document->hasAttribute('prefix') ? $document->getAttribute('prefix') . '.' : '';
     foreach ($document->getElementsByTagName('parameter') as $node) {
         $this->parseParameter($node, $schema, $prefix);
     }
     return $schema;
 }
Ejemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function locate($template, $currentPath = null, $first = true)
 {
     if (!$template instanceof TemplateReferenceInterface) {
         throw new \InvalidArgumentException('The template must be an instance of TemplateReferenceInterface.');
     }
     $themes = $this->themeHierarchyProvider->getThemeHierarchy($this->themeContext->getTheme());
     foreach ($themes as $theme) {
         try {
             return $this->templateLocator->locateTemplate($template, $theme);
         } catch (ResourceNotFoundException $exception) {
             // Ignore if resource cannot be found in given theme.
         }
     }
     return $this->decoratedFileLocator->locate($template, $currentPath, $first);
 }
 /**
  * {@inheritdoc}
  */
 public function warmUp($cacheDir)
 {
     $templates = [];
     $themes = $this->themeRepository->findAll();
     /** @var TemplateReferenceInterface $template */
     foreach ($this->finder->findAllTemplates() as $template) {
         $this->themeContext->clear();
         foreach ($themes as $theme) {
             $this->themeContext->setTheme($theme);
             $path = $this->locator->locate($template);
             $templates[$template->getLogicalName() . "|" . $theme->getLogicalName()] = $path;
         }
         $templates[$template->getLogicalName()] = $this->locator->locate($template);
     }
     $this->writeCacheFile($cacheDir . '/templates.php', sprintf('<?php return %s;', var_export($templates, true)));
 }
 /**
  * @param FileLocatorInterface $fileLocator
  */
 public function __construct(FileLocatorInterface $fileLocator)
 {
     $yaml = new Parser();
     $configuration = array();
     try {
         $configFilePath = $fileLocator->locate(self::CONFIG_RESOURCE);
         $configuration = $yaml->parse(file_get_contents($configFilePath));
     } catch (\InvalidArgumentException $e) {
         printf("Configuration file not found from resource: %s", self::CONFIG_RESOURCE);
     } catch (ParseException $e) {
         printf("Unable to parse the YAML string: %s", $e->getMessage());
     }
     $configuration['show_configuration'] = isset($configuration['show_configuration']) ? $configuration['show_configuration'] : array();
     $configuration['edit_configuration'] = isset($configuration['edit_configuration']) ? $configuration['edit_configuration'] : array();
     $this->configuration = $configuration;
 }
Ejemplo n.º 15
0
 /**
  * Get a manipulable image instance.
  *
  * @param string $file the image path
  *
  * @return ImageHandler a manipulable image instance
  */
 public function open($file)
 {
     if (strlen($file) >= 1 && $file[0] == '@') {
         try {
             if ($this->fileLocator instanceof FileLocatorInterface) {
                 $file = $this->fileLocator->locate($file);
             } else {
                 $this->fileLocator->locateResource($file);
             }
         } catch (\InvalidArgumentException $exception) {
             if ($this->throwException || false == $this->fallbackImage) {
                 throw $exception;
             }
             $file = $this->fallbackImage;
         }
     }
     return $this->createInstance($file);
 }
Ejemplo n.º 16
0
 /**
  * @param TemplateReferenceInterface|string $template
  *
  * @return string
  */
 private function findTemplate($template)
 {
     $logicalName = (string) $template;
     if (isset($this->cache[$logicalName])) {
         return $this->cache[$logicalName];
     }
     $template = $this->templateNameParser->parse($template);
     $file = $this->templateLocator->locate($template);
     return $this->cache[$logicalName] = $file;
 }
Ejemplo n.º 17
0
 /**
  * @param string $file
  *
  * @return array|null
  *
  * @throws ConfigNotFoundException
  * @throws InvalidFileTypeException
  * @throws InvalidFormatException
  */
 public function load($file)
 {
     try {
         $path = $this->locator->locate($file);
     } catch (\InvalidArgumentException $e) {
         throw new ConfigNotFoundException($e->getMessage(), 1);
     }
     if (!is_string($path)) {
         return null;
     }
     if (!$this->supports($path)) {
         throw new InvalidFileTypeException(sprintf('File "%s" is not in YAML format', $file), 1);
     }
     $content = $this->loadFile($path);
     try {
         $config = $this->processor->processConfiguration($this->configuration, array($content));
     } catch (InvalidTypeException $e) {
         throw new InvalidFormatException($e->getMessage(), 1);
     }
     $this->parseImports($config, $path);
     return $config;
 }
Ejemplo n.º 18
0
 public function load($resource, $type = null)
 {
     $collection = new RouteCollection();
     $thirdPartyDir = $this->kernel->getRootDir() . '/../thirdparty';
     $fs = new Filesystem();
     if ($fs->exists($thirdPartyDir)) {
         $finder = new Finder();
         $finder->files()->in($thirdPartyDir);
         foreach ($finder as $file) {
             /** @var \Symfony\Component\Finder\SplFileInfo $file */
             $bundleConfig = json_decode(file_get_contents($file->getRealpath()), true);
             if ($bundleConfig) {
                 if (isset($bundleConfig['extra']) && isset($bundleConfig['extra']['bundle-class'])) {
                     if (class_exists($bundleConfig['extra']['bundle-class'])) {
                         $bundleClassParts = explode('\\', $bundleConfig['extra']['bundle-class']);
                         $bundleClassRef = end($bundleClassParts);
                         $resource = '@' . $bundleClassRef . '/Resources/config/routing.yml';
                         $type = 'yaml';
                         try {
                             $this->fileLocator->locate($resource);
                         } catch (\InvalidArgumentException $e) {
                             $resource = '@' . $bundleClassRef . '/Resources/config/routing.xml';
                             $type = 'xml';
                             try {
                                 $this->fileLocator->locate($resource);
                             } catch (\InvalidArgumentException $e) {
                                 continue;
                             }
                         }
                         $importedRoutes = $this->import($resource, $type);
                         $collection->addCollection($importedRoutes);
                     }
                 }
             }
         }
     }
     return $collection;
 }
 /**
  * Locates and appends template to an array
  *
  * @param FileLocatorInterface $locator
  * @param TemplateReference    $template
  * @param array                $templates
  */
 protected function locateTemplate(FileLocatorInterface $locator, TemplateReference $template, array &$templates)
 {
     $templates[$template->getLogicalName()] = $locator->locate($template->getPath());
 }
Ejemplo n.º 20
0
 public function testTwigErrorIfLocatorReturnsFalse()
 {
     $this->setExpectedException('Twig_Error_Loader');
     $this->locator->expects($this->once())->method('locate')->will($this->returnValue(false));
     $this->loader->getCacheKey('name.format.engine');
 }
Ejemplo n.º 21
0
 /**
  * @param DefinitionInterface $definition
  * @return array
  */
 public function loadConfigByDefinition(DefinitionInterface $definition)
 {
     $configFile = $this->locator->locate($definition->getRootNode() . '.yml', null, true);
     $configData = Yaml::parse($configFile);
     return $this->processor->processConfiguration($definition, $configData);
 }
Ejemplo n.º 22
0
 /**
  * Load procedure template by id.
  *
  * @access public
  * @param  string $id
  * @param  string $extension (default: 'proc')
  * @return string
  */
 public function loadTemplate($id, $extension = 'proc')
 {
     $path = $this->locator->locate(sprintf('%s.%s', $id, $extension));
     return $this->loadFile($path);
 }
Ejemplo n.º 23
0
 /**
  * @param string      $name
  * @param string      $file
  * @param string|null $filename
  *
  * @Given I set the field ":name" with file ":file"
  * @Given I set the field ":name" with file ":file" and filename ":filename"
  */
 public function setFile($name, $file, $filename = null)
 {
     $path = $this->fileLocator->locate($file);
     $this->resources[] = $resource = fopen($path, 'r');
     $this->getMultipartStreamBuilder()->addResource($name, $resource, ['filename' => $filename]);
 }
Ejemplo n.º 24
0
 public function getPathToFile($identifier)
 {
     $path = $this->fileLocator->locate($identifier);
     return str_replace('\\', '/', substr($path, strlen($this->zikulaRoot) + 1));
 }
Ejemplo n.º 25
0
 /**
  * {@inheritdoc}
  */
 public function getDefaultValue()
 {
     return $this->getData('image/png', file_get_contents($this->fileLocator->locate('@OroUIBundle/Resources/public/img/info-user.png')));
 }