当前位置: 首页>>代码示例>>PHP>>正文


PHP FileLocator::locate方法代码示例

本文整理汇总了PHP中Symfony\Component\Config\FileLocator::locate方法的典型用法代码示例。如果您正苦于以下问题:PHP FileLocator::locate方法的具体用法?PHP FileLocator::locate怎么用?PHP FileLocator::locate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Config\FileLocator的用法示例。


在下文中一共展示了FileLocator::locate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setWorkingDirectory

 /**
  * @param string $path the working directory for filesystem operations
  *
  * @throws \InvalidArgumentException
  * @throws IOException
  */
 public function setWorkingDirectory($path)
 {
     $directory = preg_replace('#/+#', '/', $path);
     // remove multiple slashes
     try {
         $directory = $this->locator->locate($directory);
         if (false === is_string($directory)) {
             $directory = strval(reset($directory));
             $this->logger->alert(sprintf('Ambiguous filename %s, choosing %s', $path, $directory));
         }
     } catch (\InvalidArgumentException $exception) {
         // continue to check if dir exists even if locator doesn't locate
     }
     $exists = $this->filesystem->exists($directory);
     if (!$exists) {
         try {
             $this->filesystem->mkdir($directory);
             $this->logger->notice("Working directory created at " . $directory);
         } catch (IOException $exception) {
             $this->logger->error("An error occurred while creating directory at " . $exception->getPath(), $exception->getTrace());
             throw $exception;
         }
     }
     $this->directory = $directory;
 }
开发者ID:florianajir,项目名称:datanova-bundle,代码行数:31,代码来源:Finder.php

示例2: load

 /**
  * {@inheritDoc}
  */
 public function load(array $configs, ContainerBuilder $container)
 {
     $configuration = new Configuration();
     $config = $this->processConfiguration($configuration, $configs);
     $this->bindParameters($container, $this->getAlias(), $config);
     // Fallback for missing intl extension
     $intlExtensionInstalled = extension_loaded('intl');
     $container->setParameter('lunetics_locale.intl_extension_installed', $intlExtensionInstalled);
     $iso3166 = array();
     $iso639one = array();
     $iso639two = array();
     $localeScript = array();
     if (!$intlExtensionInstalled) {
         $yamlParser = new YamlParser();
         $file = new FileLocator(__DIR__ . '/../Resources/config');
         $iso3166 = $yamlParser->parse(file_get_contents($file->locate('iso3166-1-alpha-2.yml')));
         $iso639one = $yamlParser->parse(file_get_contents($file->locate('iso639-1.yml')));
         $iso639two = $yamlParser->parse(file_get_contents($file->locate('iso639-2.yml')));
         $localeScript = $yamlParser->parse(file_get_contents($file->locate('locale_script.yml')));
     }
     $container->setParameter('lunetics_locale.intl_extension_fallback.iso3166', $iso3166);
     $mergedValues = array_merge($iso639one, $iso639two);
     $container->setParameter('lunetics_locale.intl_extension_fallback.iso639', $mergedValues);
     $container->setParameter('lunetics_locale.intl_extension_fallback.script', $localeScript);
     $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
     $loader->load('validator.xml');
     $loader->load('guessers.xml');
     $loader->load('services.xml');
     $loader->load('switcher.xml');
     $loader->load('form.xml');
     if (!$config['strict_match']) {
         $container->removeDefinition('lunetics_locale.best_locale_matcher');
     }
 }
开发者ID:Sententiaregum,项目名称:LocaleBundle,代码行数:37,代码来源:LuneticsLocaleExtension.php

示例3: execute

 /**
  * {@inheritdoc}
  */
 public function execute(ImageInterface $image, $parameters)
 {
     $maskPath = isset($parameters['image']) ? $this->fileLocator->locate($parameters['image']) : null;
     if (!$maskPath) {
         return $image;
     }
     $originalWidth = $image->getSize()->getWidth();
     $originalHeight = $image->getSize()->getHeight();
     $top = isset($parameters['top']) ? $parameters['top'] : 0;
     $left = isset($parameters['left']) ? $parameters['left'] : 0;
     $width = isset($parameters['width']) ? $parameters['width'] : $originalWidth;
     $height = isset($parameters['height']) ? $parameters['height'] : $originalHeight;
     // imagine will error when mask is bigger then the given image
     // this could happen in forceRatio true mode so we need also scale the mask
     if ($width > $originalWidth) {
         $width = $originalWidth;
         $height = (int) ($height / $width * $originalWidth);
     }
     if ($height > $originalHeight) {
         $height = $originalHeight;
         $width = (int) ($width / $height * $originalHeight);
     }
     // create mask
     $mask = $this->createMask($maskPath, $width, $height);
     // add mask to image
     $image->paste($mask, new Point($top, $left));
     return $image;
 }
开发者ID:sulu,项目名称:sulu,代码行数:31,代码来源:PasteTransformation.php

示例4: prepend

 /** {@inheritdoc} */
 public function prepend(ContainerBuilder $container)
 {
     $configs = Yaml::parse($this->fileLocator->locate('redis.yml'));
     foreach ($configs as $name => $config) {
         $container->prependExtensionConfig($name, $config);
     }
 }
开发者ID:sergeyz,项目名称:oro-redis,代码行数:8,代码来源:OroRedisExtension.php

示例5: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     $yamlParser = new YamlParser();
     $file = new FileLocator(__DIR__ . '/../../Resources/config');
     self::$iso3166 = $yamlParser->parse(file_get_contents($file->locate('iso3166-1-alpha-2.yml')));
     self::$iso639 = array_merge($yamlParser->parse(file_get_contents($file->locate('iso639-1.yml'))), $yamlParser->parse(file_get_contents($file->locate('iso639-2.yml'))));
     self::$script = $yamlParser->parse(file_get_contents($file->locate('locale_script.yml')));
 }
开发者ID:Sententiaregum,项目名称:LocaleBundle,代码行数:8,代码来源:BaseMetaValidator.php

示例6: validate

 /**
  * Validates the received data with the given json schema
  *
  * @param Schema $annotation
  * @param array $data
  *
  * @throws JsonSchemaException
  */
 public function validate(Schema $annotation, $data)
 {
     $schemaUrl = $this->fileLocator->locate($annotation->getPathToSchema());
     $schema = json_decode(file_get_contents($schemaUrl));
     $data = json_decode(json_encode($data));
     if (!$this->validator->isValid($data, $schema)) {
         throw new JsonSchemaException($this->validator->getErrors());
     }
 }
开发者ID:michaelzangerle,项目名称:RestValidationPlayground,代码行数:17,代码来源:KernelListener.php

示例7: getConfiguration

 /**
  * Get configuration
  *
  * @return array
  */
 public function getConfiguration()
 {
     $configurationFiles = $this->locator->locate('config.yml', null, false);
     $configurations = [];
     foreach ($configurationFiles as $path) {
         $configurations[] = $this->loader->load($path);
     }
     return $this->processor->processConfiguration($this->configuration, $configurations);
 }
开发者ID:phpillip,项目名称:phpillip,代码行数:14,代码来源:Configurator.php

示例8: prepend

 /** {@inheritdoc} */
 public function prepend(ContainerBuilder $container)
 {
     if ($container->hasParameter('redis_dsn')) {
         $configs = Yaml::parse($this->fileLocator->locate('redis.yml'));
     } else {
         $configs = Yaml::parse($this->fileLocator->locate('redis_dummy.yml'));
     }
     foreach ($configs as $name => $config) {
         $container->prependExtensionConfig($name, $config);
     }
 }
开发者ID:vdrizheruk,项目名称:oro-redis-config,代码行数:12,代码来源:OroRedisConfigExtension.php

示例9: fetchAction

 public function fetchAction()
 {
     $em = $this->getDoctrine()->getEntityManager();
     // TODO move to a cron job
     // TODO move google credentials to symfony parameters file
     $configDirectories = array(__DIR__ . '/../Resources/config');
     $locator = new FileLocator($configDirectories);
     $clientSecret = $locator->locate('client_secret.json');
     $credentialsPath = $locator->locate('calendar-api-quickstart.json');
     // Get the API client and construct the service object.
     $client = new \Google_Client();
     $client->setApplicationName('Google Calendar API Quickstart');
     $client->setScopes(implode(' ', array(\Google_Service_Calendar::CALENDAR_READONLY)));
     $client->setAuthConfigFile($clientSecret);
     $client->setAccessType('offline');
     // Load previously authorized credentials from a file.
     if (file_exists($credentialsPath)) {
         $accessToken = file_get_contents($credentialsPath);
     } else {
         //TODO this should be accomplished with an error status
         return $this->render('TechlancasterWebBundle:Default:calendar.html.twig', array('message' => 'Invalid Credentials'));
     }
     $client->setAccessToken($accessToken);
     // Refresh the token if it's expired.
     if ($client->isAccessTokenExpired()) {
         $client->refreshToken($client->getRefreshToken());
         file_put_contents($credentialsPath, $client->getAccessToken());
     }
     $service = new \Google_Service_Calendar($client);
     $calendarId = '6l7e832ee9bemt1i9c42vltrug@group.calendar.google.com';
     $optParams = array('maxResults' => 29, 'orderBy' => 'startTime', 'singleEvents' => true, 'timeMin' => date('c'));
     $results = $service->events->listEvents($calendarId, $optParams);
     $events = array();
     $connection = $em->getConnection();
     $platform = $connection->getDatabasePlatform();
     $connection->executeUpdate($platform->getTruncateTableSQL('event', false));
     /**
      * @var $googleEvent Google_Service_Calendar_Event
      */
     foreach ($results->getItems() as $googleEvent) {
         $event = new Event();
         $event->setId($googleEvent->getId());
         $event->setDescription($googleEvent->getDescription());
         $event->setLocation($googleEvent->getLocation());
         $event->setStart(new \DateTime($googleEvent->getStart()->dateTime));
         $event->setEnd(new \DateTime($googleEvent->getEnd()->dateTime));
         $event->setSummary($googleEvent->getSummary());
         $em->persist($event);
         $events[] = $event;
     }
     $em->flush();
     return $this->render('TechlancasterWebBundle:Default:calendar.html.twig', array('message' => json_encode($events)));
 }
开发者ID:amayer5125,项目名称:tl-website,代码行数:53,代码来源:DefaultController.php

示例10: getMimetypeIcon

 /**
  * Returns the file path to an image file which represents the passed mimetype.
  *
  * @param string $mimetype The mimetype
  *
  * @return string A path to the mimetype icon
  */
 public function getMimetypeIcon($mimetype)
 {
     $file = str_replace('/', '-', $mimetype) . '.svg';
     $iconDirectory = $this->container->getParameter('partkeepr.directories.mimetype_icons');
     $fileLocator = new FileLocator($iconDirectory);
     try {
         $iconFile = $fileLocator->locate($file);
     } catch (\InvalidArgumentException $e) {
         $file = 'empty.svg';
         $iconFile = $fileLocator->locate($file);
     }
     return $iconFile;
 }
开发者ID:partkeepr,项目名称:PartKeepr,代码行数:20,代码来源:MimetypeIconService.php

示例11: setUp

 public function setUp()
 {
     $kernel = static::createKernel();
     $kernel->boot();
     if ($kernel->getContainer()->getParameter('database_driver') == 'pdo_sqlite') {
         $this->markTestSkipped("The SQLite does not support joins.");
     }
     $this->em = $kernel->getContainer()->get('knp_bundles.entity_manager');
     $fileLocator = new FileLocator(__DIR__ . '/fixtures/');
     $path = $fileLocator->locate('trending-bundles.yml');
     $data = Yaml::parse($path);
     $developer = new Developer();
     $developer->setName('someName');
     $developer->setScore(0);
     $this->em->persist($developer);
     foreach ($data['bundles'] as $bundleName => $bundleData) {
         $bundle = new Bundle('vendor/' . $bundleName);
         $bundle->setDescription('some description');
         $bundle->setScore(100);
         $bundle->setOwner($developer);
         foreach ($bundleData['scores'] as $scoreData) {
             $bundle->setDescription(md5(time() . serialize($scoreData)));
             $score = new Score();
             $score->setDate(new \DateTime($scoreData['date']));
             $score->setBundle($bundle);
             $score->setValue($scoreData['value']);
             $this->em->persist($score);
         }
         $this->em->persist($bundle);
     }
     $this->em->flush();
 }
开发者ID:KnpLabs,项目名称:KnpBundles,代码行数:32,代码来源:KbUpdateTrendsCommandTest.php

示例12: initialize

 /**
  * Initialize the service container (and extensions), and load the config file
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  *
  * @throws \Exception if user-provided configuration file causes an error
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     $root = $input->getArgument('root');
     // Setup container
     $containerBuilder = new ContainerBuilder();
     $extension = new BrancherExtension();
     $containerBuilder->registerExtension($extension);
     $containerBuilder->addCompilerPass(new ExtensionCompilerPass());
     $containerBuilder->addCompilerPass(new RegisterListenersPass('event_dispatcher', 'brancher.event_listener', 'brancher.event_subscriber'));
     // Try and load config file
     $locator = new FileLocator([getcwd(), $input->getArgument('root'), __DIR__ . '/../']);
     /** @var \Symfony\Component\DependencyInjection\Loader\FileLoader $loader */
     $loader = new DelegatingLoader(new LoaderResolver([new YamlFileLoader($containerBuilder, $locator), new XmlFileLoader($containerBuilder, $locator), new PhpFileLoader($containerBuilder, $locator), new IniFileLoader($containerBuilder, $locator)]));
     $config = null;
     try {
         $config = $locator->locate($input->getOption('config'));
         $loader->load($input->getOption('config'));
     } catch (\Exception $ex) {
         // Only rethrow if the issue was with the user-provided value
         if ($input->getOption('config') !== '_config.yml') {
             throw $ex;
         }
     }
     // Add in final config from command line options
     $containerBuilder->setParameter('castlepointanime.brancher.build.config', $config);
     $containerBuilder->loadFromExtension($extension->getAlias(), ['build' => array_filter(['config' => dirname($config) ?: $root, 'root' => $root, 'special' => $input->getOption('special'), 'output' => $input->getArgument('output'), 'templates' => array_filter(array_map('realpath', $input->getOption('template-dir')), 'is_dir'), 'data' => $input->getOption('data-dir'), 'exclude' => $input->getOption('exclude')])]);
     $containerBuilder->compile();
     $this->setContainer($containerBuilder);
 }
开发者ID:castlepointanime,项目名称:brancher,代码行数:37,代码来源:BuildCommand.php

示例13: locate

 /**
  * Returns a full path for a given template
  *
  * @param mixed       $name
  * @param string|null $dir
  * @param bool        $first
  *
  * @return array|string
  */
 public function locate($name, $dir = null, $first = true)
 {
     if ('@' === $name[0]) {
         return $this->themeManager->locateTemplate($name);
     }
     return parent::locate($name, $dir, $first);
 }
开发者ID:Newman101,项目名称:WellCommerce,代码行数:16,代码来源:FileLocator.php

示例14: __construct

    /**
     * 
     * @param string $configDirectories
     * @param string $configFiles
     * @param string $cachePath
     * @param bool $debug
     */
    public function __construct($configDirectories, $configFiles, $cachePath, $debug = false)
    {
        $this->configDirectories = (array) $configDirectories;
        $this->configFiles = (array) $configFiles;
        $this->cachePath = $cachePath . '/faker_config.php';
        $configCache = new ConfigCache($this->cachePath, $debug);
        if (!$configCache->isFresh()) {
            $locator = new FileLocator($this->configDirectories);
            $loaderResolver = new LoaderResolver([new YamlLoader($locator)]);
            $delegatingLoader = new DelegatingLoader($loaderResolver);
            $resources = [];
            $config = [];
            foreach ($this->configFiles as $configFile) {
                $path = $locator->locate($configFile);
                $config = array_merge($config, $delegatingLoader->load($path));
                $resources[] = new FileResource($path);
            }
            $exportConfig = var_export($this->parseRawConfig(isset($config['faker']) ? $config['faker'] : []), true);
            $code = <<<PHP
<?php
return {$exportConfig};
PHP;
            $configCache->write($code, $resources);
        }
        if (file_exists($this->cachePath)) {
            $this->config = (include $this->cachePath);
        }
    }
开发者ID:csanquer,项目名称:fakery-generator,代码行数:35,代码来源:FakerConfig.php

示例15: load

 /**
  * Loads the configuration file data.
  */
 public function load($workingDir)
 {
     $locator = new FileLocator($this->getPotentialDirectories($workingDir));
     $loader = new YamlLoader($locator);
     // Config validation.
     $processor = new Processor();
     $schema = new BuddySchema();
     $files = $locator->locate(static::FILENAME, NULL, FALSE);
     foreach ($files as $file) {
         // After loading the raw data from the yaml file, we validate given
         // configuration.
         $raw = $loader->load($file);
         $conf = $processor->processConfiguration($schema, array('buddy' => $raw));
         if (isset($conf['commands'])) {
             foreach ($conf['commands'] as $command => $specs) {
                 if (!isset($this->commands[$command])) {
                     $this->commands[$command] = array('options' => $specs, 'file' => $file);
                 }
             }
         }
         // In the case 'root' is set, we do not process any parent buddy files.
         if (!empty($values['root'])) {
             break;
         }
     }
     return $this;
 }
开发者ID:derhasi,项目名称:buddy,代码行数:30,代码来源:Config.php


注:本文中的Symfony\Component\Config\FileLocator::locate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。