itsgoingd/slim-facades
Composer 安装命令:
composer require itsgoingd/slim-facades
包简介
"Static" interface for various Slim features
关键字:
README 文档
README
SlimFacades is a collection of facades for Slim PHP microframework, providing simple "static" interface for various Slim features.
For example, turn this:
$app->get('/hello-world', function() { $app = Slim::getInstance(); $app->view()->display('hello.html', array('name' => $app->request()->get('name', 'world'))); })
Into this:
Route::get('/hello-world', function() { View::display('hello.html', array('name' => Input::get('name', 'world'))); })
This library is based on the Laravel 4 Facade class, more info about facades in the Laravel documentation.
Installation
To install latest version simply add it to your composer.json:
"itsgoingd/slim-facades": "dev-master"
Once the package is installed, you need to initialize the Facade class:
require 'vendor/autoload.php'; use SlimFacades\Facade; $app = new Slim\Slim(); // initialize the Facade class Facade::setFacadeApplication($app); Facade::registerAliases(); // now you can start using the facades Config::set('debug', true); Route::get('/hello/:name', function($name) { View::display('hello.html', array( 'name' => Input::get('name', $name) )); }); App::run();
Following facades are available:
App
- facade for Slim instance and following additional methods:
- make($key) - returns $key from Slim's DI container
$request = App::make('request'); App::flash('message', 'Som Kuli, ovladam kozmicku lod.'); App::halt();
Config
- facade for Slim instance and following additional methods:
- get($key) - returns value of $app->config($key)
- set($key, $value = null) - calls $app->config($key, $value)
$debug = Config::get('debug'); Config::set('log.enable', true);
Input
- facade for Slim\Http\Request instance and following additional methods:
- file($name) - returns $_FILES[$name], or null if the file was not sent in the request
$username = Input::get('username', 'default'); $password = Input::post('password'); $avatar = Input::file('avatar');
Log
- facade for Slim\Log instance
Log::info('Tomi Popovic predava miliony albumov po celom svete.'); Log::debug('Okamizte na pozorovanie.');
Request
- facade for Slim\Http\Request instance
if (Request::isAjax()) { ... } $host = Request::headers('host', 'localhost'); $path = Request::getPath();
Response
- facade for Slim\Http\Response instance
Response::redirect('/success');
Route
- facade for Slim\Router instance and following methods:
- map, get, post, put, patch, delete, options, group, any - calls the methods on Slim instance
Route::get('/users/new', 'UsersController:index'); Route::post('/users', 'UsersController:insert');
View
- facade for Slim\View instance
View::display('hello.html'); $output = View::render('world.html');
Custom facades
You can create a custom facades by extending SlimFacades\Facade class.
class MyFacade extends SlimFacades\Facade { // return the name of the component from the DI container protected static function getFacadeAccessor() { return 'my_component'; } }
You can register custom facades by passing the aliases to the Facade::registerAliases() function.
Facade::registerAliases(array( 'App' => 'SlimFacades\App', 'Config' => 'SlimFacades\Config', 'Input' => 'SlimFacades\Input', // 'Log' => 'SlimFacades\Log', 'Log' => 'CustomLogFacade', 'Request' => 'SlimFacades\Request', 'Response' => 'SlimFacades\Response', 'Route' => 'SlimFacades\Route', 'View' => 'SlimFacades\View', ));
Note that calling Facade::registerAliases() with a list of aliases will register ONLY the specified facades, if you want to register default facades as well as custom ones, you can call the function two times, with and without the array argument.
Links
- SlimStatic - alternative implementation with similar API, without dependency on Laravel components by John Stevenson
Licence
Copyright (c) 2013 Miroslav Rigler
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
itsgoingd/slim-facades 适用场景与选型建议
itsgoingd/slim-facades 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 53.67k 次下载、GitHub Stars 达 74, 最近一次更新时间为 2013 年 12 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「microframework」 「slim」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 itsgoingd/slim-facades 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 itsgoingd/slim-facades 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 itsgoingd/slim-facades 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Secure session middleware for Slim 3 framework
A lightweight, secure-by-default PHP microframework built on Slim – providing Laravel-like features (ORM, authentication, migrations, caching) without the bloat. Perfect for building REST APIs and small-to-medium PHP applications.
Adds request-parameter validation to the SLIM 3.x PHP framework
Slim Framework 3 CSRF protection middleware utilities
Slim starter / Slim skeleton package to boost your development with Slim framework
Extension for Slim Framework 3 view helper built on top of the Twig 2 templating component
统计信息
- 总下载量: 53.67k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 76
- 点击次数: 31
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-12-16