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); }
/** * 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); }
/** * 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); }
/** * 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; }
/** * 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; } }
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'); }
/** * 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; }
/** * {@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); }
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'); }
/** * {@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); }
/** * {@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))); }
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); }
/** * 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); }
/** * @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; }
/** * @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; }
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; }
/** * @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; }
public function getPathToFile($identifier) { $path = $this->fileLocator->locate($identifier); return str_replace('\\', '/', substr($path, strlen($this->zikulaRoot) + 1)); }
/** * {@inheritdoc} */ public function getDefaultValue() { return $this->getData('image/png', file_get_contents($this->fileLocator->locate('@OroUIBundle/Resources/public/img/info-user.png'))); }
/** * @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]); }
/** * 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()); }
/** * 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); }
/** * @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); }