Overview

Namespaces

  • Contrib
    • Bundle
      • CoverallsBundle
        • Console
        • Entity
      • CoverallsV1Bundle
        • Api
        • Collector
        • Command
        • Config
        • Entity
          • Git
    • Component
      • File
      • Log
      • System
        • Git
  • Guzzle
    • Batch
      • Exception
    • Cache
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
      • QueryAggregator
    • Inflection
    • Iterator
    • Log
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Async
      • Backoff
      • Cache
      • Cookie
        • CookieJar
        • Exception
      • CurlAuth
      • ErrorResponse
        • Exception
      • History
      • Log
      • Md5
      • Mock
      • Oauth
    • Service
      • Builder
      • Command
        • Factory
        • LocationVisitor
          • Request
          • Response
      • Description
      • Exception
      • Resource
    • Stream
  • PHP
  • Psr
    • Log
  • Symfony
    • Component
      • Config
        • Definition
          • Builder
          • Exception
        • Exception
        • Loader
        • Resource
        • Util
      • Console
        • Command
        • Formatter
        • Helper
        • Input
        • Output
        • Tester
      • EventDispatcher
        • Debug
      • Finder
        • Adapter
        • Comparator
        • Exception
        • Expression
        • Iterator
        • Shell
      • Stopwatch
      • Yaml
        • Exception

Classes

  • ConfigCache
  • FileLocator

Interfaces

  • FileLocatorInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
  1: <?php
  2: 
  3: /*
  4:  * This file is part of the Symfony package.
  5:  *
  6:  * (c) Fabien Potencier <fabien@symfony.com>
  7:  *
  8:  * For the full copyright and license information, please view the LICENSE
  9:  * file that was distributed with this source code.
 10:  */
 11: 
 12: namespace Symfony\Component\Config;
 13: 
 14: /**
 15:  * FileLocator uses an array of pre-defined paths to find files.
 16:  *
 17:  * @author Fabien Potencier <fabien@symfony.com>
 18:  */
 19: class FileLocator implements FileLocatorInterface
 20: {
 21:     protected $paths;
 22: 
 23:     /**
 24:      * Constructor.
 25:      *
 26:      * @param string|array $paths A path or an array of paths where to look for resources
 27:      */
 28:     public function __construct($paths = array())
 29:     {
 30:         $this->paths = (array) $paths;
 31:     }
 32: 
 33:     /**
 34:      * Returns a full path for a given file name.
 35:      *
 36:      * @param mixed   $name        The file name to locate
 37:      * @param string  $currentPath The current path
 38:      * @param Boolean $first       Whether to return the first occurrence or an array of filenames
 39:      *
 40:      * @return string|array The full path to the file|An array of file paths
 41:      *
 42:      * @throws \InvalidArgumentException When file is not found
 43:      */
 44:     public function locate($name, $currentPath = null, $first = true)
 45:     {
 46:         if ($this->isAbsolutePath($name)) {
 47:             if (!file_exists($name)) {
 48:                 throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $name));
 49:             }
 50: 
 51:             return $name;
 52:         }
 53: 
 54:         $filepaths = array();
 55:         if (null !== $currentPath && file_exists($file = $currentPath.DIRECTORY_SEPARATOR.$name)) {
 56:             if (true === $first) {
 57:                 return $file;
 58:             }
 59:             $filepaths[] = $file;
 60:         }
 61: 
 62:         foreach ($this->paths as $path) {
 63:             if (file_exists($file = $path.DIRECTORY_SEPARATOR.$name)) {
 64:                 if (true === $first) {
 65:                     return $file;
 66:                 }
 67:                 $filepaths[] = $file;
 68:             }
 69:         }
 70: 
 71:         if (!$filepaths) {
 72:             throw new \InvalidArgumentException(sprintf('The file "%s" does not exist (in: %s%s).', $name, null !== $currentPath ? $currentPath.', ' : '', implode(', ', $this->paths)));
 73:         }
 74: 
 75:         return array_values(array_unique($filepaths));
 76:     }
 77: 
 78:     /**
 79:      * Returns whether the file path is an absolute path.
 80:      *
 81:      * @param string $file A file path
 82:      *
 83:      * @return Boolean
 84:      */
 85:     private function isAbsolutePath($file)
 86:     {
 87:         if ($file[0] == '/' || $file[0] == '\\'
 88:             || (strlen($file) > 3 && ctype_alpha($file[0])
 89:                 && $file[1] == ':'
 90:                 && ($file[2] == '\\' || $file[2] == '/')
 91:             )
 92:             || null !== parse_url($file, PHP_URL_SCHEME)
 93:         ) {
 94:             return true;
 95:         }
 96: 
 97:         return false;
 98:     }
 99: }
100: 
php-coveralls API documentation generated by ApiGen 2.8.0