public function setUp() { DI::reset(); DI::setDefault($di = new DI()); $this->instance = m::mock('Phalcore\\Di\\Facade'); $di->setShared('foo', m::mock('foo')); }
/** * @param DI $DI */ function __construct(DI $DI) { $this->Modules = $DI->get('\\arh\\library\\Modules'); $this->Settings = $DI->get('\\arh\\library\\Settings'); $this->Access = $DI->get('\\arh\\library\\Access'); $this->Exception = $DI->get('\\arh\\library\\Exception'); }
/** * @expectedException \Phalcon\Mvc\Model\Exception * @expectedExceptionMessage Field name must be a string */ public function testValidateIncorrectFieldType() { $di = new DI(); $di->set('modelsManager', new Manager()); require_once __DIR__ . '/resources/TestCardNumberIncorrectField.php'; $obj = new \TestCardNumberIncorrectField(); $obj->validation(); }
public function setUp() { DI::reset(); $this->instance = new ExceptionHandler(); $this->instance->setDI($di = new DI()); $di->setShared('config', m::mock('Phalcon\\Config')); $this->instance->register(); }
public function setUp() { DI::reset(); $this->instance = new Module(); $this->instance->setDI($di = new DI()); $di->setShared('application', m::mock('Phalcore\\Mvc\\Application')->makePartial()); $this->instance->register(); }
public function setUp() { DI::reset(); $this->instance = new LoadEnvironmentVariables(); $this->instance->setDI($di = new DI()); $this->application = m::mock('Phalcore\\Mvc\\Application')->makePartial(); $di->setShared('application', $this->application); }
public function setUp() { DI::reset(); $this->instance = new RegisterConfig(); $this->instance->setDI($di = new DI()); $this->application = m::mock('Phalcore\\Mvc\\Application')->makePartial(); $di->setShared('application', $this->application); $this->instance->boot(); }
/** * @param DI $DI */ function __construct(DI $DI) { $this->ROOT_DIR = $DI->get('ROOT_DIR'); $this->Exception = $DI->get('\\library\\Exception'); $this->configDir = $this->ROOT_DIR . '/' . $this->configDir; $this->modulesDir = $this->ROOT_DIR . '/' . $this->modulesDir; self::$modules = $this->getAll(); self::$current = $this->getInfo('arh'); }
public function setUp() { DI::reset(); $this->instance = new Router(); $this->instance->setDI($di = new DI()); $config = m::mock('Phalcore\\Config'); $config->files = m::mock('Phalcon\\Config'); $config->files->routes = APP_PATH . '/config/routes.php'; $di->setShared('config', $config); $this->instance->register(); }
public function setUp() { DI::reset(); $this->instance = new Dispatcher(); $this->instance->setDI($di = new DI()); $config = m::mock('Phalcon\\Config')->makePartial(); $config->offsetSet('namespaces', ['controllers' => 'barFoo']); $di->setShared('config', $config); $di->setShared('router', m::mock('Phalcore\\Mvc\\Router')->makePartial()); $this->instance->register(); }
public function setUp() { DI::reset(); $this->instance = new Logger(); $this->instance->setDI($di = new DI()); $config = m::mock('Phalcon\\Config'); $config->files = m::mock('Phalcon\\Config'); $config->files->logs = m::mock('Phalcon\\Config'); $config->files->logs->error = APP_PATH . '/trash/foo'; $di->setShared('config', $config); $this->instance->register(); }
public function setUp() { DI::reset(); $this->instance = new View(); $this->instance->setDI($di = new DI()); $config = m::mock('Phalcon\\Config'); $config->paths = m::mock('Phalcon\\Config'); $config->debug = true; $config->paths->cache = 'foo/cache'; $config->paths->views = 'foo/views'; $this->config = $config; $di->setShared('config', $config); $this->instance->register(); }
protected function _before() { if (!extension_loaded('MongoDB')) { $this->markTestSkipped("MongoDB extension not loaded, test skipped"); return; } Di::reset(); $di = new DI(); $di->set('mongo', function () { $mongo = new MongoClient('mongodb://' . TEST_MONGODB_HOST . ':' . TEST_MONGODB_PORT); return $mongo->selectDatabase('phalcon_test'); }); $di->set('collectionManager', function () { return new Manager(); }); }
public function setUp() { $config = (include __DIR__ . '/../config.php'); $this->config = $config; $this->di = DI::getDefault(); $this->loadAnnotations(); }
public function setUp() { DI::reset(); $this->instance = new Db(); $this->instance->setDI($di = new DI()); $this->instance->register(); }
public function __construct($file) { $config = DI::get('config'); $logDir = $config->dir->log; $this->file = $logDir . $file; $this->fp = fopen($this->file, 'a+'); }
/** * Set the host and port of the endpoint * * @param string $host * @param integer $port */ public function __construct($host = 'localhost', $port = 7474) { $this->host = $host; $this->port = $port; if (DI::isRegistered("dbPath")) { $this->path = DI::resolve("dbPath"); } }
/** * add an object as singleton * @param object $obj * @return void */ public static function addInstance($obj) { if (null === self::$instances) { self::$instances = (object) array(); } $key = get_class($obj); self::$instances->{$key} = $obj; }
/** * start all registered classes * @return void */ public static function go() { foreach (self::$startup as $classname) { $classname::startup(); } foreach (self::$DIstartup as $classname) { \DI::getInstanceOf($classname)->startup(); } }
/** * @return void */ public static function go() { self::$used = true; $msqlo = new MySQLi(app::get('mysql')->host, app::get('mysql')->user, app::get('mysql')->password, app::get('mysql')->database); \DI::addInstance($msqlo); $modelob = new \Observer\ModelObserver(); \DI::addInstance($modelob); \StartupAll::startup(); }
/** * Set up the test environment * @return void */ public function setUp() { //$this->controller = new LoginController; $this->controller = new LoginController(); $this->view = new View(); $this->view->disable(); $this->di = DI::getDefault(); parent::setUp(); }
/** * {@inheritdoc} */ public function handle(\Request $request) { $responseObject = new \Response(); self::$response = $responseObject; self::$request = $request; \DI::addInstance($responseObject); \Route::map(); $connection = new \Connection(self::$request, self::$response); return $connection->close(); }
public function __get($var_name) { $di = DI::getDefault(); if ($di->hasService($var_name)) { return $di->getService($var_name); } if ($var_name == "di") { return $di; } }
/** * Redirects to another page. * * @param string $location The path to redirect to * @param int $status Status code to use * @return bool False if $location is not set */ public static function redirect($location, $status = 302) { $request = DI::get('request'); if ($location == '') { header("Location: " . $request->get_uri('site_url'), true, $status); exit; } header("Location: " . $request->get_uri('site_url') . $location, true, $status); exit; }
/** * Set up the test environment * @return void */ public function setUp() { //need to use mock feature to remove contructor and exit functions $this->controller = new MockApiController(); //setup our view if needed $this->view = new View(); $this->di = DI::getDefault(); //call parent setup if any parent::setUp(); }
/** * Check if \Phalcon\Di has session service * * @return bool */ private function hasSession() { if (DI::getDefault()->has('session') === true) { // get instance of session class $this->session = DI::getDefault()->getSession(); if ($this->session->getId() === '') { $this->session->start(); } return true; } return false; }
/** * get a service from the di * @param $what * @return mixed the service object */ public function get($what) { if (!$this->registered($what)) { $file = $this->directory . "/{$what}.php"; $service = (include $file); if (!is_callable($service)) { throw new Exception(sprintf('Bad service type. The file%s should return a callable', $file)); } $this->set($what, $service); } return parent::get($what); }
/** * @param DI $DI */ function __construct(DI $DI) { $this->ROOT_DIR = $DI->get('ROOT_DIR'); $this->Modules = $DI->get('\\library\\Modules'); $this->Config = $DI->get('\\library\\Config'); $this->Access = $DI->get('\\library\\Access'); $this->Exception = $DI->get('\\library\\Exception'); }
/** * {@inheritDoc} * * @todo if logged in * @todo set user in config!!! */ public function run(array $args, $required = true) { $user = new \Authentication\User($args['session'], \DI::prepare("\\Model\\" . \app::get("user"))); $loggedIn = $user->isAuthenticated(); // if loggedin if ($loggedIn) { $this->assignTplVar("loggedIn", true); $this->assignTplVar("user", $user); return true; } elseif (!$loggedIn && $required) { $this->error("Not authorized to access this page!"); return false; } else { $this->assignTplVar("loggedIn", false); return true; } return false; }
/** * @param string $path * @return void */ public function go($path) { $this->cache = \DI::getInstanceOf('Cache', ['css']); if ('css' == self::$prefered) { $out = $this->css($path); if (!$out) { $out = $this->less($path); } } else { $out = $this->less($path); if (!$out) { $out = $this->css($path); } } if (!$out) { $this->response->errorCode(404)->out(sprintf("<h1>%s!</h1>", __('File not found'))); } }