代码拉取完成,页面将自动刷新
<?php
namespace Sinta\Laravel\Addons;
use UnexpectedValueException;
use Illuminate\Contracts\Foundation\Application as ContractApplication;
class Environment
{
protected $addons = null;
protected $spacePaths = [];
protected $app;
public function __construct(ContractApplication $app)
{
$this->app = $app;
$this->makeAddonsPaths();
}
private function makeAddonsPaths()
{
$addonsDirPath = $this->path();
$this->spacePaths[''] = $addonsDirPath;
foreach ($this->app['config']->get('addon.additional_paths', []) as $name => $path) {
$this->addSpace($name, $path);
}
}
public function addSpace($name, $path)
{
$this->spacePaths[$name] = $this->app->basePath().'/'.$path;
}
public function path($name = null)
{
if ($name !== null) {
return $this->path().'/'.$name;
} else {
return $this->app->basePath().'/'.$this->app['config']->get('addon.path', 'addons');
}
}
public function spacePath($space, $name = null)
{
$path = $space ? array_get($this->spacePaths, $space) : $this->path();
if ($path === null) {
throw new UnexpectedValueException("addon space '{$space}' is not found.");
}
if ($name !== null) {
return $path.'/'.$name;
} else {
return $path;
}
}
public function exists($name)
{
if ($this->existsOnSpace(null, $name)) {
return true;
}
foreach ($this->spacePaths as $space => $path) {
if ($this->existsOnSpace($space, $name)) {
return true;
}
}
return false;
}
public function existsOnSpace($space, $name)
{
return is_dir($this->spacePath($space, $name));
}
public function classToPath($relativeClassName)
{
return str_replace('\\', '/', $relativeClassName).'.php';
}
public function pathToClass($relativePath)
{
if (strpos($relativePath, '/') !== false) {
$relativePath = dirname($relativePath).'/'.basename($relativePath, '.php');
} else {
$relativePath = basename($relativePath, '.php');
}
return str_replace('/', '\\', $relativePath);
}
public function loadAddons()
{
$files = $this->app['files'];
$ignore_pattern = $this->app['config']->get('addon.ignore_pattern', '/^@/');
$name_pattern = $this->app['config']->get('addon.name_pattern', '/^(.+)$/');
$addons = [];
foreach ($this->spacePaths as $path) {
// make directory
if (!$files->exists($path)) {
$files->makeDirectory($path);
}
// load addons
foreach ($files->directories($path) as $dir) {
// test ignore pattern
if (preg_match($ignore_pattern, basename($dir))) {
continue;
}
// test name pattern
if (! preg_match($name_pattern, basename($dir), $matches)) {
continue;
}
$name = count($matches) >= 2 ? $matches[1] : $matches[0];
$addon = Addon::create($this->app, $name, $dir);
$addons[$addon->name()] = $addon;
}
}
return $addons;
}
public function addons()
{
if ($this->addons === null) {
$this->addons = $this->loadAddons();
}
return $this->addons;
}
public function addon($name)
{
return array_get($this->addons(), $name ?: '', null);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。