Skip to content

Joilson/phalcon-service-loader

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Phalcon service loader

Service loader for Phalcon PHP Framework

Phalconist

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' => '[email protected]'
		]),
		'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',
                ]],
            ]],
        ],
    ],

About

Service loader for Phalcon PHP Framework

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%