serebro / phalcon-service-loader
phalcon service loader
2.0
2014-10-10 13:26 UTC
Requires
- php: >=5.4
- ext-phalcon: >=1.3.0
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2025-02-15 18:02:11 UTC
README
Service loader for Phalcon PHP Framework
Requirements
Installation
{ "require": { "serebro/phalcon-service-loader": "dev-master" } }
Get started
index.php
<?php defined('APP_PATH') || define('APP_PATH', dirname(__FILE__) . '/../app'); defined('WEB_PATH') || define('WEB_PATH', dirname(__FILE__)); defined('ENV') || define('ENV', getenv('ENV') ? getenv('ENV') : 'development'); $services = APP_PATH . '/config/services.php'; // OR $services = APP_PATH . '/config/' . ENV . '.php'; //Create a DI $di = new Phalcon\DI\FactoryDefault(); // Service loading $serviceLoader = new \Phalcon\DI\Service\Loader($di); $serviceLoader->setDefinitions($services, ['loader', 'env']); //Handle the request $app = new \Phalcon\Mvc\Application($di); echo $app->handle()->getContent();
services.php
<?php return new \Phalcon\Config([ 'config' => new \Phalcon\Config([ 'adminEmail' => 'admin@example.com' ]), 'loader' => [ // ... ], 'logger' => [ // ... 'shared' => false, ], 'cache' => function($di) { // ... return $cache; } ]);
Phalcon services
See more "DI - complex registration"
#####Reserved
- "shared" - register the service as "always shared". Default: true.
"Loader"
'loader' => [ 'className' => '\Phalcon\Loader', 'calls' => [ ['method' => 'registerDirs', 'arguments' => [ ['type' => 'parameter', 'value' => [ 'controllers' => APP_PATH . '/controllers/', 'models' => APP_PATH . '/models/', 'library' => APP_PATH . '/library/', ]] ]], ['method' => 'register'], ], ],
"Environment" (Production)
'env' => function($di) { error_reporting(0); ini_set('log_errors', 1); ini_set('display_errors', 0); ini_set('display_startup_errors', 0); },
"Logger"
'logger' => [ 'className' => '\Phalcon\Logger\Adapter\Syslog', 'arguments' => [ ['type' => 'parameter', 'value' => null], ], ],
"MySQL"
'db' => [ 'className' => '\Phalcon\Db\Adapter\Pdo\Mysql', 'arguments' => [ ['type' => 'parameter', 'value' => [ 'host' => 'localhost', 'username' => 'root', 'password' => 'secret', 'dbname' => 'test_db' ]], ], ],
"Memcache"
'cache' => [ 'className' => '\Phalcon\Cache\Backend\Memcache', 'arguments' => [ [ 'type' => 'instance', 'className' => '\Phalcon\Cache\Frontend\Data', 'arguments' => ['lifetime' => 60] ], ], ],
File cache
'fileCache' => [ 'className' => '\Phalcon\Cache\Backend\File', 'arguments' => [[ 'type' => 'instance', 'className' => '\Phalcon\Cache\Frontend\Data', 'arguments' => ['lifetime' => 3600] ],[ 'type' => 'parameter', 'value' => ['cacheDir' => APP_PATH . '/../cache/files/'] ], ], ],
File log
'log' => [ 'className' => '\Phalcon\Logger\Adapter\File', 'arguments' => [ ['type' => 'parameter', 'value' => APP_PATH . '/../logs/app.log'], ], ],
"Session"
'session' => [ 'className' => '\Phalcon\Session\Adapter\Files', 'calls' => [ ['method' => 'start'] ], ],
"Cookie"
'cookie' => [ 'className' => '\Phalcon\Http\Response\Cookies', 'calls' => [[ 'method' => 'useEncryption', 'arguments' => [ ['type' => 'parameter', 'value' => true], ]], ], ],
"Url"
'url' => [ 'className' => '\Phalcon\Mvc\Url', 'calls' => [ ['method' => 'setBaseUri', 'arguments' => [ ['type' => 'parameter', 'value' => '/'], ]], ], ],
"View"
'view' => [ 'className' => '\Phalcon\Mvc\View', 'calls' => [ ['method' => 'setViewsDir', 'arguments' => [ ['type' => 'parameter', 'value' => APP_PATH . '/views/'], ]], ['method' => 'registerEngines', 'arguments' => [ ['type' => 'parameter', 'value' => [ '.phtml' => 'Phalcon\Mvc\View\Engine\Php', ]], ]], ], ],