PathFinder::locate PHP Méthode

locate() public méthode

The third argument can also be 'location', in which case a :php:class:PathFinder_Location object will be returned. If file is not found anywhere, then :php:class:Exception_PathFinder is thrown unless you set $throws_exception to false, and then method would return null.
public locate ( string $type, string $filename = '', string $return = 'relative', $throws_exception = true ) : string | object | array
$type string Type of resource to search surch as "php"
$filename string Name of the file to search for
$return string 'relative','url','path' or 'location'
Résultat string | object | array
    public function locate($type, $filename = '', $return = 'relative', $throws_exception = true)
    {
        $attempted_locations = array();
        if (!$return) {
            $return = 'relative';
        }
        foreach ($this->elements as $key => $location) {
            if (!$location instanceof PathFinder_Location) {
                continue;
            }
            $path = $location->locate($type, $filename, $return);
            if (is_string($path) || is_object($path)) {
                return $path;
            } elseif (is_array($path)) {
                if ($return === 'array' && @isset($path['name'])) {
                    return $path;
                }
                $attempted_locations = array_merge($attempted_locations, $path);
            }
        }
        if ($throws_exception) {
            throw $this->exception('File not found')->addMoreInfo('file', $filename)->addMoreInfo('type', $type)->addMoreInfo('attempted_locations', $attempted_locations);
        }
    }

Usage Example

Exemple #1
0
 /**
  * Return full system path to specified resource.
  *
  * @param string $type
  * @param string $filename
  *
  * @return string|object|array
  */
 public function locatePath($type, $filename = '')
 {
     return $this->pathfinder->locate($type, $filename, 'path');
 }