예제 #1
0
 /**
  * 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;
 }
예제 #2
0
 /**
  * @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;
     });
 }
예제 #3
0
파일: IoC.php 프로젝트: hushibing/EvaEngine
 /**
  * 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);
 }
예제 #4
0
 /**
  * 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);
 }
예제 #5
0
 /**
  * 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', function ($event, $dispatcher, $exception) {
             switch ($exception->getCode()) {
                 case \Phalcon\Mvc\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                 case \Phalcon\Mvc\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                     $dispatcher->forward(['module' => self::MODULE, 'namespace' => 'Modules\\' . self::MODULE . '\\Controllers\\', 'controller' => 'error', 'action' => 'notFound']);
                     return false;
                     break;
                 default:
                     $dispatcher->forward(['module' => self::MODULE, 'namespace' => 'Modules\\' . self::MODULE . '\\Controllers\\', 'controller' => 'error', 'action' => 'uncaughtException']);
                     return false;
                     break;
             }
         });
         $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']['viewsFront'])->setMainView('layout');
         return $view;
     });
     return require_once APP_PATH . '/Modules/' . self::MODULE . '/config/services.php';
 }
예제 #6
0
 private function getDi()
 {
     $di = new PhalconDi();
     $di->set('request', function () {
         return new PhalconRequest();
     });
     return $di;
 }
예제 #7
0
 /**
  * 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;
 }
예제 #8
0
 /**
  * Initializes the request object and returns it
  *
  * @author Nikolaos Dimopoulos <*****@*****.**>
  * @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;
 }
 /**
  * @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;
 }
예제 #10
0
 public function testRegisterRoutes()
 {
     $this->testable->registerRoutes();
     /* @var Router $router */
     $router = $this->testable->getRouter();
     $this->assertFalse($this->di->has('router'));
     $this->assertNotEmpty($router->getRoutes());
     $this->assertTrue(is_array($router->getRoutes()));
     $this->assertCount(8, $router->getRoutes());
     $this->assertInstanceOf('Phalcon\\Mvc\\Router\\Route', $router->getRouteByName('fifi'));
     $this->assertInstanceOf('Phalcon\\Mvc\\Router\\Route', $router->getRouteByName('get-all'));
 }
예제 #11
0
 /**
  * @param DI $di
  */
 public function registerServices($di)
 {
     $this->registerAutoloaders();
     $di->setShared('session', function () {
         $session = new \Phalcon\Session\Adapter\Files();
         $session->start();
         return $session;
     });
     $di->set('view', function () use($di) {
         $view = new View();
         $view->setViewsDir(MINI_ADMIN_ROOT . '/views/');
         return $view;
     });
 }
예제 #12
0
파일: CrudTest.php 프로젝트: szytko/core
 public function setUp()
 {
     parent::setUp();
     $config = DI::getDefault()->get('config');
     require_once $config->application->moduleDir . '/Test/forms/Fake.php';
     $this->prepareFakeObject();
 }
 /**
  * @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();
 }
예제 #14
0
 /**
  * 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);
 }
예제 #15
0
파일: Mongo.php 프로젝트: vegas-cmf/acl
 /**
  * @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;
 }
예제 #16
0
 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;
 }
예제 #17
0
파일: Regex.php 프로젝트: biggtfish/cms
 /**
  * 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);
 }
예제 #18
0
파일: RouterTest.php 프로젝트: ovide/phest
 public function testSerialization()
 {
     $router = \Phalcon\DI::getDefault()->getShared('router');
     $serialized = serialize($router);
     $unserialized = unserialize($serialized);
     $this->assertEquals($unserialized, $router);
 }
예제 #19
0
 /**
  * Get DI
  *
  * @return DI
  */
 public function getDi()
 {
     if (empty($this->di)) {
         $this->di = DI::getDefault();
     }
     return $this->di;
 }
예제 #20
0
 /**
  * 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);
 }
예제 #21
0
파일: Db.php 프로젝트: rj28/test
 /**
  * @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;
     }
 }
예제 #22
0
 /**
  * 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;
 }
예제 #23
0
 /**
  * Create object.
  *
  * @param DiInterface|DIBehaviour $di Dependency injection container.
  */
 public function __construct($di = null)
 {
     if ($di == null) {
         $di = DI::getDefault();
     }
     $this->setDI($di);
 }
예제 #24
0
 /**
  * @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);
 }
예제 #25
0
 public static function tearDownAfterClass()
 {
     if (self::$previousDependencyInjector instanceof DI) {
         DI::setDefault(self::$previousDependencyInjector);
     }
     spl_autoload_unregister(array(__CLASS__, 'autoloadModels'));
 }
예제 #26
0
 public static function tearDownAfterClass()
 {
     $di = DI::getDefault();
     $di->get('db')->execute('DROP TABLE IF EXISTS fake_table ');
     $di->get('mongo')->selectCollection('fake_with_dao')->remove([]);
     $di->get('mongo')->selectCollection('fake_without_dao')->remove([]);
 }
예제 #27
0
 public function setAdditionalOptions()
 {
     $format = new \Vegas\Forms\Element\Text('format');
     $format->setLabel("Format");
     $this->additionalOptions[] = $format;
     DI::getDefault()->get('assets')->addJs('assets/js/lib/vegas/formbuilder/datepicker.js');
 }
예제 #28
0
 protected function _getDI()
 {
     DI::reset();
     $di = new DI();
     $di->set('modelsManager', function () {
         return new Manager();
     });
     $di->set('modelsMetadata', function () {
         return new Memory();
     });
     $di->set('db', function () {
         require PATH_CONFIG . 'config.db.php';
         return new Mysql($configMysql);
     });
     return $di;
 }
예제 #29
0
 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(), 'messages' => $this->messages);
     if (!$req->get('type') || $req->get('type') == 'json') {
         $response = new \Base\Framework\Responses\JSONResponse();
         $response->send($error, true);
         return;
     } else {
         if ($req->get('type') == 'csv') {
             $response = new \Base\Framework\Responses\CSVResponse();
             $response->send(array($error));
             return;
         }
     }
     error_log('HTTPException: ' . $this->getFile() . ' at ' . $this->getLine());
     return true;
 }
예제 #30
0
 /**
  * Init
  */
 protected function setUp()
 {
     $this->getTester()->setDi(DI::getDefault());
     $this->getTester()->setTestableConfig($this->getTestableConfig());
     parent::setUp();
     $this->testable = new ModuleTestable();
 }