fileviewfinder.php,[李景山php]每天laravel-20161114|FileViewFinder-2.php

/**

* Get the path to a template with a named path.

*

* @param string $name

* @return string

*/

protected function findNamedPathView($name)

{

list($namespace, $view) = $this->getNamespaceSegments($name);// get this namespace and view

return $this->findInPaths($view, $this->hints[$namespace]);// findInPaths

}// Get the path to a template with a named path

/**

* Get the segments of a template with a named path.

*

* @param string $name

* @return array

*

* @throws \InvalidArgumentException

*/

protected function getNamespaceSegments($name)

{// Get the segments of a template with a named path.

$segments = explode(static::HINT_PATH_DELIMITER, $name);// get a segments

// in this segments

if (count($segments) != 2) {

throw new InvalidArgumentException("View [$name] has an invalid name.");

}// if the result not like as we think, so threw exception

if (! isset($this->hints[$segments[0]])) {

throw new InvalidArgumentException("No hint path defined for [{$segments[0]}].");

}// if no hints , we will throw Exception

return $segments;// return segments

}

/**

* Find the given view in the list of paths.

*

* @param string $name

* @param array $paths

* @return string

*

* @throws \InvalidArgumentException

*/

protected function findInPaths($name, $paths)

{//Find the given view in the list of paths.

foreach ((array) $paths as $path) {

foreach ($this->getPossibleViewFiles($name) as $file) {

if ($this->files->exists($viewPath = $path.'/'.$file)) {

return $viewPath;// if find it just return

}

}// get Possible View Files

}// loop path

throw new InvalidArgumentException("View [$name] not found.");// default throw Exception

}

/**

* Get an array of possible view files.

*

* @param string $name

* @return array

*/

protected function getPossibleViewFiles($name)

{//get Possible View Files

return array_map(function ($extension) use ($name) {

return str_replace('.', '/', $name).'.'.$extension;

}, $this->extensions);// two powerfull

}//Get an array of possible view files.

/**

* Add a location to the finder.

*

* @param string $location

* @return void

*/

public function addLocation($location)

{

$this->paths[] = $location;// add location to path

}//Add a location to the finder

/**

* Add a namespace hint to the finder.

*

* @param string $namespace

* @param string|array $hints

* @return void

*/

public function addNamespace($namespace, $hints)

{//add a namespace hint to the finder

$hints = (array) $hints;// get the array hints

if (isset($this->hints[$namespace])) {

$hints = array_merge($this->hints[$namespace], $hints);

}// if it is isset, combine it with new hints

$this->hints[$namespace] = $hints;// then reset it

}

/**

* Prepend a namespace hint to the finder.

*

* @param string $namespace

* @param string|array $hints

* @return void

*/

public function prependNamespace($namespace, $hints)

{//Prepend a namespace hint to the finder.

$hints = (array) $hints;// get a right hints

if (isset($this->hints[$namespace])) {

$hints = array_merge($hints, $this->hints[$namespace]);

}// this is a good way to hints

$this->hints[$namespace] = $hints;// rewrite it

}

/**

* Register an extension with the view finder.

*

* @param string $extension

* @return void

*/

public function addExtension($extension)

{//register an extension with the view finder.

if (($index = array_search($extension, $this->extensions)) !== false) {

unset($this->extensions[$index]);

}// index

array_unshift($this->extensions, $extension);

}// add function use this system function to add it

/**

* Returns whether or not the view specify a hint information.

*

* @param string $name

* @return bool

*/

public function hasHintInformation($name)

{

return strpos($name, static::HINT_PATH_DELIMITER) > 0;

}// Returns whether or not the view specify a hint information.

/**

* Get the filesystem instance.

*

* @return \Illuminate\Filesystem\Filesystem

*/

public function getFilesystem()

{

return $this->files;// return files

}// get the filesystem instance.

/**

* Get the active view paths.

*

* @return array

*/

public function getPaths()

{

return $this->paths;

}//get paths

/**

* Get the namespace to file path hints.

*

* @return array

*/

public function getHints()

{

return $this->hints;

}//get hints

/**

* Get registered extensions.

*

* @return array

*/

public function getExtensions()

{

return $this->extensions;

}// get extensions

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值