作者:stanislav-we
项目:phalcon-developmen
/**
* Registration services for specific module
* @param \Phalcon\DI $di
* @access public
* @return mixed
*/
public function registerServices($di)
{
// Dispatch register
$di->set('dispatcher', function () use($di) {
$eventsManager = $di->getShared('eventsManager');
$eventsManager->attach('dispatch:beforeException', new \Plugins\Dispatcher\NotFoundPlugin());
$dispatcher = new \Phalcon\Mvc\Dispatcher();
$dispatcher->setEventsManager($eventsManager);
$dispatcher->setDefaultNamespace('Modules\\' . self::MODULE . '\\Controllers');
return $dispatcher;
}, true);
// Registration of component representations (Views)
$di->set('view', function () {
$view = new View();
$view->setViewsDir($this->_config['application']['viewsBack'])->setMainView('auth-layout')->setPartialsDir('partials');
return $view;
});
require_once APP_PATH . '/Modules/' . self::MODULE . '/config/services.php';
// call profiler
if ($this->_config->database->profiler === true) {
new \Plugins\Debugger\Develop($di);
}
if (APPLICATION_ENV == 'development') {
// share Fabfuel topbar
$profiler = new \Fabfuel\Prophiler\Profiler();
$di->setShared('profiler', $profiler);
$pluginManager = new \Fabfuel\Prophiler\Plugin\Manager\Phalcon($profiler);
$pluginManager->register();
// add toolbar in your basic BaseController
}
return;
}
作者:moaljazaer
项目:phalcon-module-admi
/**
* @param DI $di
*/
public function registerServices($di)
{
//Registering a dispatcher
$di->setShared('dispatcher', function () use($di) {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace("Admin");
$eventsManager = $di->getShared('eventsManager');
$eventsManager->attach('dispatch', new AdminSecurity($di));
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
});
$auto_admin = new \AutoAdmin\Module();
$auto_admin->registerServices($di);
$di->setShared('admin_views_dir', function () {
return ADMINROOT . '/views/';
});
$di->setShared('session', function () {
$session = new Session();
$session->start();
return $session;
});
$di->setShared('config', function () use($di) {
$configFront = (require COREROOT . '/app/config/config.php');
$configBack = (require ADMINROOT . '/config/config.php');
$configFront->merge($configBack);
return $configFront;
});
}
作者:hushibin
项目:EvaEngin
/**
* Registers a service in the services container
*
* @param string $name
* @param mixed $definition
* @param boolean $shared
* @throws RuntimeException
* @return \Phalcon\DI\ServiceInterface
*/
public static function set($name, $definition, $shared = null)
{
if (self::$di == null) {
throw new RuntimeException('IoC container is null!');
}
self::$di->set($name, $definition, $shared);
}
作者:danzaba
项目:phalcon-cl
/**
* Set up test vars
*
* @return void
* @author Dan Cox
*/
public function setUp()
{
$di = new DI();
$di->setShared('output', new Output());
$di->setShared('input', new Input());
$this->helpers = new Helpers($di);
}
作者:acwtool
项目:cphalco
/**
* Return flash instance
*/
protected function getFlash()
{
$flash = new PhFlash($this->classes);
$di = new PhDI();
$di->set('session', new Helper\InMemorySession(), true);
$flash->setDI($di);
return $flash;
}
作者:lison
项目:cphalco
/**
* Initializes the request object and returns it
*
* @author Nikolaos Dimopoulos <nikos@phalconphp.com>
* @since 2014-10-05
*
* @return PhRequest
*/
protected function getRequestObject()
{
PhDI::reset();
$di = new PhDI();
$di->set('filter', function () {
return new PhTFilter();
});
$request = new PhTRequest();
$request->setDI($di);
return $request;
}
作者:phalett
项目:platt
/**
* @return DummyLatteTemplateAdapter
*/
public static function create()
{
$view = new PhView();
$di = new PhDi();
$di->set('tag', new PhTag());
$di->set('security', new PhSecurity());
$di->set('url', new PhUrl());
$latteFactory = new LatteFactory();
$latteFactory->setTempDir(TEMP_DIR);
$adapter = new DummyLatteTemplateAdapter($view, $di, $latteFactory);
return $adapter;
}
作者:szytk
项目:cor
public function setUp()
{
parent::setUp();
$config = DI::getDefault()->get('config');
require_once $config->application->moduleDir . '/Test/forms/Fake.php';
$this->prepareFakeObject();
}
作者:minhlaole
项目:phalcon-debugba
/**
* @param DI $di
*/
public function __construct(DI $di = null)
{
if (!class_exists('\\Whoops\\Run')) {
return;
}
if (!$di) {
$di = DI::getDefault();
}
// There's only ever going to be one error page...right?
$di->setShared('whoops.pretty_page_handler', function () use($di) {
return (new DebugbarHandler())->setDi($di);
});
// There's only ever going to be one error page...right?
$di->setShared('whoops.json_response_handler', function () {
$jsonHandler = new JsonResponseHandler();
$jsonHandler->onlyForAjaxRequests(true);
return $jsonHandler;
});
$di->setShared('whoops', function () use($di) {
$run = new Run();
$run->silenceErrorsInPaths(array('/phalcon-debugbar/'), E_ALL);
$run->pushHandler($di['whoops.pretty_page_handler']);
$run->pushHandler($di['whoops.json_response_handler']);
return $run;
});
$di['whoops']->register();
}
作者:biggtfis
项目:cm
/**
* Get table name.
*
* @return string
*/
public static function getTableName()
{
$reader = DI::getDefault()->get('annotations');
$reflector = $reader->get(get_called_class());
$annotations = $reflector->getClassAnnotations();
return $annotations->get('Source')->getArgument(0);
}
作者:vegas-cm
项目:ac
/**
* @param array $options
* @throws \Exception
*/
public function __construct($options = array())
{
if (empty($options)) {
$options = array('db' => DI::getDefault()->get('mongo'), 'roles' => 'vegas_acl_roles', 'resources' => 'vegas_acl_resources', 'resourcesAccesses' => 'vegas_acl_resources_accesses', 'accessList' => 'vegas_acl_access_list');
}
if (!is_array($options)) {
throw new Exception("Acl options must be an array");
}
if (!isset($options['db'])) {
throw new Exception("Parameter 'db' is required");
}
if (!isset($options['roles'])) {
throw new Exception("Parameter 'roles' is required");
}
if (!isset($options['resources'])) {
throw new Exception("Parameter 'resources' is required");
}
if (!isset($options['resourcesAccesses'])) {
throw new Exception("Parameter 'resourcesAccesses' is required");
}
if (!isset($options['accessList'])) {
throw new Exception("Parameter 'accessList' is required");
}
$this->options = $options;
$this->_defaultAccess = Acl::DENY;
}
作者:sarahsampa
项目:compare-ap
public function send()
{
$di = \Phalcon\DI::getDefault();
$res = $di->get('response');
$req = $di->get('request');
//query string, filter, default
if (!$req->get('suppress_response_codes', null, null)) {
$res->setStatusCode($this->getCode(), $this->response)->sendHeaders();
} else {
$res->setStatusCode('200', 'OK')->sendHeaders();
}
$error = array('errorCode' => $this->getCode(), 'userMessage' => $this->getMessage(), 'devMessage' => $this->devMessage, 'more' => $this->additionalInfo, 'applicationCode' => $this->errorCode);
if (!$req->get('type') || $req->get('type') == 'json' | $req->get('type') == 'option') {
$response = new JSONResponse();
$response->send($error, true);
return;
} else {
if ($req->get('type') == 'xml') {
$response = new XMLResponse();
$response->send($error, true);
return;
} else {
if ($req->get('type') == 'csv') {
$response = new CSVResponse();
$response->send(array($error));
return;
}
}
}
error_log('HTTPException: ' . $this->getFile() . ' at ' . $this->getLine());
return true;
}
作者:biggtfis
项目:cm
/**
* Create regex validator.
*
* @param array $params Validator parameters.
*/
public function __construct($params = [])
{
if (isset($params['message'])) {
$params['message'] = DI::getDefault()->get('i18n')->_($params['message']);
}
parent::__construct($params);
}
作者:ovid
项目:phes
public function testSerialization()
{
$router = \Phalcon\DI::getDefault()->getShared('router');
$serialized = serialize($router);
$unserialized = unserialize($serialized);
$this->assertEquals($unserialized, $router);
}
作者:kachi
项目:phalcon-li
/**
* Get DI
*
* @return DI
*/
public function getDi()
{
if (empty($this->di)) {
$this->di = DI::getDefault();
}
return $this->di;
}
作者:siciare
项目:suggeste
/**
* Returns the translation related to the given key
*
* @param string $index
* @param array $placeholders
* @return string
*/
public function query($index, $placeholders = null)
{
if (!empty($index) and !array_key_exists($index, $this->_translate)) {
$transdir = \Phalcon\DI::getDefault()->getConfig()->dirs->translations;
$new = [$index => $index . '*'];
$this->_translate = $new + $this->_translate;
$d = dir($transdir);
while (($file = $d->read()) !== false) {
if (!preg_match('/^[a-z]{2}\\.php$/', $file)) {
continue;
}
$messages = [];
$dict = $transdir . DIRECTORY_SEPARATOR . $file;
require $dict;
// Check if $index exists in given dictionary:
if (!array_key_exists($index, $messages)) {
$messages = $new + $messages;
$content = sprintf("<?php\n\n// app/config/translations/%s\n\n\$messages = %s;", $file, var_export($messages, true));
file_put_contents($dict, $content);
}
}
$d->close();
}
return parent::query($index, $placeholders);
}
作者:rj2
项目:tes
/**
* @param $param1 AdapterInterface|Closure
* @param $param2 Closure|null
*
* @throws Exception
* @return mixed
*/
public static function transaction()
{
switch (func_num_args()) {
case 1:
$db = DI::getDefault()['db'];
$callback = func_get_arg(0);
break;
case 2:
$db = func_get_arg(0);
$callback = func_get_arg(1);
break;
default:
throw new Exception("Bad parameter count");
}
/** @var $db AdapterInterface */
/** @var $callback Closure */
//Assert::true($db instanceof AdapterInterface);
Assert::true($callback instanceof Closure);
$db->begin();
try {
$ret = $callback($db);
$db->commit();
return $ret;
} catch (Exception $e) {
$db->rollback();
throw $e;
}
}
作者:al35m
项目:Phalcon-Rocke
/**
* Check Recaptcha
*
* @param $privateKey
* @param $remoteIP
* @param $response
* @return array|bool
*/
public static function check($remoteIP, $response)
{
$privateKey = \Phalcon\DI::getDefault()->getShared('config')->recaptcha->private or die(self::RECAPTCHA_ERROR_KEY);
$result = array();
$result['success'] = FALSE;
$result['error-codes'] = FALSE;
$result = json_decode(file_get_contents(self::RECAPTCHA_VERIFY_SERVER . "?secret={$privateKey}&response=" . $response . "&remoteip=" . $remoteIP), true);
if ($result['success'] == FALSE) {
// errors
if (is_array($result['error-codes'])) {
if ($result['error-codes'][0] == 'missing-input-response') {
return array('success' => FALSE, 'error' => __('Please verify you are human'));
} else {
if ($result['error-codes'][0] == 'invalid-input-response') {
return array('success' => FALSE, 'error' => __('You have failed the human verification test!'));
}
}
} else {
return array('success' => FALSE, 'error' => __('There was an unknown error!'));
}
} else {
return array('success' => TRUE, 'error' => FALSE);
}
return FALSE;
}
作者:biggtfis
项目:cm
/**
* Create object.
*
* @param DiInterface|DIBehaviour $di Dependency injection container.
*/
public function __construct($di = null)
{
if ($di == null) {
$di = DI::getDefault();
}
$this->setDI($di);
}
作者:tienrocke
项目:pauthenticatio
/**
* @param $string
* @param array $params
* @return string
*/
public static function _($string, array $params = [])
{
if (static::$translate == null) {
global $config;
//Ask browser what is the best language
$locale = DI::getDefault()->get('request')->get('lang', 'string', DI::getDefault()->get('request')->getBestLanguage());
if (empty($config->application->langDir) || !file_exists($config->application->langDir)) {
$config->application->langDir = __DIR__ . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR;
}
//Check if we have a translation file for that lang
if (!file_exists($config->application->langDir . $locale)) {
$locale = 'en_US';
}
// clear cache in dev environment
$default_domain = 'auth';
if (defined('ENVIRONMENT') && ENVIRONMENT == 'development') {
$default_domain = sprintf('%s.%s', $default_domain, time());
if (file_exists($default_domain)) {
}
}
//Init translate object
static::$translate = new \Phalcon\Translate\Adapter\Gettext(['locale' => $locale, 'defaultDomain' => $default_domain, 'directory' => $config->application->langDir]);
}
return static::$translate->_($string, $params);
}