fol/core

该包已 废弃 且不再维护。作者建议使用 oscarotero/fol 包。

FOL框架的核心


README

Build Status Scrutinizer Code Quality

这是一个简单的类,用作应用的容器。它具有以下功能

Container-interop

container-interop接口兼容,这允许与其他容器交互。您可以指定依赖项或添加其他容器

$app = new Fol();

//Definir dependencias:
$app->set('database', function () {
    return new MyDatabaseClass($config);
});

//Engadir outros conenedores compatibles con Container-Interop
$app->add($container);

//Engadir un ServiceProviderInterface
$app->register(new MyServiceProvider());

//Obter as dependencias
$database = $app->get('database');

//Tamén podes usar a interface de array para engadir/obter dependencias:
$database = $app['database'];

$app['templates'] = function () {
    return new TemplatesEngine();
};

Path

除了作为容器外,还用于定义应用的路径。路径只是应用程序目录的绝对路径

$app = new Fol();

//Dame a ruta
$app->getPath(); // /var/www/sitioweb/app

//Dame a ruta xuntándolle estas pezas:
$app->getPath('dir/subdir', '../outro'); // /var/www/sitioweb/dir/outro

//O path calculase automaticamente (o directorio onde se atopa a clase instanciada) pero podes cambialo:
$path->setPath(__DIR__); //Nunca pode rematar en "/"

Url

另一个功能是保存从何处访问我们应用的公共URL,这对于生成链接等很有用

$app = new Fol();

//Define unha url
$app->setUrl('http://localhost/o-meu-sitio');

//Dame a url
$app->getUrl(); // http://localhost/o-meu-sitio

//Dame só o path
$app->getUrlPath(); // /o-meu-sitio

//Dame só o host
$app->getUrlHost(); // http://localhost

//Tamén podes engadirlle pezas:
$app->getUrl('post/1', 'ver'); // http://localhost/o-meu-sitio/post/1/ver

$app->getUrlPath('post/1', 'ver'); // /o-meu-sitio/post/1/ver

Namespace

最后,有一个实用程序可以返回应用的命名空间。这对于实例化相关类很有用。

namespace App;

use Fol;

class App extends Fol {
    
}

$app = new App();

//Dame o namespace
$app->getNamespace(); // App

//Tamén podes engadirlle pezas
$app->getNamespace('Controllers\\Base'); // App\\Controllers\\Base;