本文整理汇总了PHP中Phalcon\DI\FactoryDefault::set方法的典型用法代码示例。如果您正苦于以下问题:PHP FactoryDefault::set方法的具体用法?PHP FactoryDefault::set怎么用?PHP FactoryDefault::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\DI\FactoryDefault
的用法示例。
在下文中一共展示了FactoryDefault::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: modulesClosure
public function modulesClosure(IntegrationTester $I)
{
$I->wantTo('handle request and get content by using single modules strategy (closure)');
Di::reset();
$_GET['_url'] = '/login';
$di = new FactoryDefault();
$di->set('router', function () {
$router = new Router(false);
$router->add('/index', ['controller' => 'index', 'module' => 'frontend', 'namespace' => 'Phalcon\\Test\\Modules\\Frontend\\Controllers']);
$router->add('/login', ['controller' => 'login', 'module' => 'backend', 'namespace' => 'Phalcon\\Test\\Modules\\Backend\\Controllers']);
return $router;
});
$application = new Application();
$view = new View();
$application->registerModules(['frontend' => function ($di) use($view) {
/** @var \Phalcon\DiInterface $di */
$di->set('view', function () use($view) {
$view->setViewsDir(PATH_DATA . 'modules/frontend/views/');
return $view;
});
}, 'backend' => function ($di) use($view) {
/** @var \Phalcon\DiInterface $di */
$di->set('view', function () use($view) {
$view->setViewsDir(PATH_DATA . 'modules/backend/views/');
return $view;
});
}]);
$application->setDI($di);
$I->assertEquals('<html>here</html>' . PHP_EOL, $application->handle()->getContent());
}
示例2: setServices
private function setServices()
{
$di = new FactoryDefault();
$di->set('config', $this->setConfig());
$this->setAutoloaders();
$di->set('url', $this->setUrl(), true);
$di->set('router', $this->setRouter());
$this->setDI($di);
$di->set('view', $this->setView(), true);
$di->set('db', $this->setDb());
$di->set('modelsMetadata', $this->setModelsMetadata());
$di->set('session', $this->setSession());
$this->setDI($di);
}
示例3: setUpBeforeClass
public static function setUpBeforeClass()
{
$basedir = realpath(__DIR__ . '/../../');
$testdir = $basedir . '/tests';
self::$viewsdir = realpath($testdir . '/views/') . '/';
include_once $basedir . "/vendor/autoload.php";
$di = new DI();
$di->set('form', "Logikos\\Forms\\Form");
$di->set('url', function () {
$url = new \Phalcon\Mvc\Url();
$url->setBaseUri('/');
return $url;
});
static::$di = $di;
}
示例4: __construct
/**
* Constructor.
*/
public function __construct()
{
/**
* Create default DI.
*/
$di = new DI\FactoryDefault();
/**
* Get config.
*/
$this->_config = Config::factory();
if (!$this->_config->installed) {
define('CHECK_REQUIREMENTS', true);
require_once PUBLIC_PATH . '/requirements.php';
}
/**
* Setup Registry.
*/
$registry = new Registry();
$registry->modules = array_merge([self::SYSTEM_DEFAULT_MODULE, 'user'], $this->_config->modules->toArray());
$registry->widgets = $this->_config->widgets->toArray();
$registry->directories = (object) ['engine' => ROOT_PATH . '/app/engine/', 'modules' => ROOT_PATH . '/app/modules/', 'plugins' => ROOT_PATH . '/app/plugins/', 'widgets' => ROOT_PATH . '/app/widgets/', 'libraries' => ROOT_PATH . '/app/libraries/'];
$di->set('registry', $registry);
// Store config in the DI container.
$di->setShared('config', $this->_config);
parent::__construct($di);
}
示例5: setUp
public function setUp()
{
$this->task = new ImportDmmTask();
$di = new Di\FactoryDefault();
$db = function () {
return new Mysql(array("host" => $GLOBALS['db_host'], "username" => $GLOBALS['db_username'], "password" => $GLOBALS['db_password'], "dbname" => 'yinxing'));
};
$di->set('dbSlave', $db);
$di->set('dbMaster', $db);
$di->set('moduleManager', function () {
return new ModuleManager();
});
/** @var Mysql $mysql */
$mysql = $di->get('dbMaster');
$mysql->query(file_get_contents(__DIR__ . '/../../sql/evamovie_2015-10-20.sql'));
}
示例6: registerServices
/**
* Register the services here to make them general or register in the ModuleDefinition to make them module-specific
*/
public function registerServices()
{
$di = new FactoryDefault();
$loader = new Loader();
$namespaces = [];
$map = (require_once __DIR__ . '/../autoload_namespaces.php');
foreach ($map as $k => $values) {
$k = trim($k, '\\');
if (!isset($namespaces[$k])) {
$dir = '/' . str_replace('\\', '/', $k) . '/';
$namespaces[$k] = implode($dir . ';', $values) . $dir;
}
}
$loader->registerNamespaces($namespaces);
$loader->register();
/**
* Register a router
*/
$di->set('router', function () {
$router = new Router();
$router->setDefaultModule('frontend');
//set frontend routes
$router->mount(new FrontendRoutes());
//
return $router;
});
$this->setDI($di);
}
示例7: testSendCatchExceptionsForNotConfiguredProviders
/**
* @dataProvider additionEmptyDataProvider
* @expectedException \SMSFactory\Exceptions\BaseException
* @expectedExceptionCode 500
*/
public function testSendCatchExceptionsForNotConfiguredProviders($provider)
{
$this->di->set('config', function () {
return new Config(require './phpunit/data/empty.php');
});
$callInstance = new Sender($this->di);
$this->assertInstanceOf('SMSFactory\\Sender', $callInstance, "[-] Provider instance error");
$callInstance->call($provider)->setRecipient($this->phone)->send($this->message);
}
示例8: registerServices
/**
* Registers the services in di container.
*
* @return void
*/
private function registerServices()
{
$di = new FactoryDefault();
$di->set('config', function () {
ob_start();
$config = (include APPLICATION_ENV . '.php');
ob_end_clean();
return new Config($config);
});
$di->set('dispatcher', function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace('Application\\Controllers\\');
return $dispatcher;
});
$di->set('view', function () {
$view = new View();
$view->setViewsDir(ROOT_PATH . '/application/views/');
return $view;
});
$this->setDI($di);
}
示例9: createDependencies
/**
* @return $this
*/
public function createDependencies()
{
$dependency = new FactoryDefault();
$dependency->set('db', function () {
return $this->getDatabase();
});
$dependency->set('router', function () {
$router = new Router(false);
$routes = Routes::get();
foreach ($routes as $group => $controllers) {
foreach ($controllers as $controller) {
$router->add($controller['route'], ['namespace' => "App\\Controllers\\{$group}", 'controller' => $controller['class'], 'action' => 'run'], $controller['method']);
}
}
$router->notFound(['namespace' => 'PhRest\\Controllers', 'controller' => 'Missing', 'action' => 'run']);
return $router;
});
$dependency->set('view', function () {
return new View();
}, true);
$this->setDI($dependency);
return $this;
}
示例10: setUp
/**
* Sets the test up by loading the DI container and other stuff
*
* @author Nikos Dimopoulos <nikos@phalconphp.com>
* @since 2012-09-30
* @param \Phalcon\DiInterface $di
* @param \Phalcon\Config $config
* @return void
*/
protected function setUp(DiInterface $di = null, Config $config = null)
{
$this->checkExtension('phalcon');
if (!is_null($config)) {
$this->config = $config;
}
if (is_null($di)) {
// Reset the DI container
DI::reset();
// Instantiate a new DI container
$di = new FactoryDefault();
// Set the URL
$di->set('url', function () {
$url = new Url();
$url->setBaseUri('/');
return $url;
});
$di->set('escaper', function () {
return new \Phalcon\Escaper();
});
}
$this->di = $di;
}
示例11: registerServices
/**
* Register the services here to make them general or register in the ModuleDefinition to make them module-specific
*/
protected function registerServices()
{
$di = new FactoryDefault();
require '../../../autoloader.php';
$loader = new Loader();
/**
* We're a registering a set of directories taken from the configuration file
*/
$loader->registerDirs(array(__DIR__ . '/../apps/library/'))->register();
$router = new Router();
$router->setDefaultModule("frontend");
//Registering a router
$di->set('router', function () use($router) {
return $router;
});
$this->setDI($di);
}
示例12: setUp
public function setUp(Phalcon\DiInterface $di = NULL, Phalcon\Config $config = NULL)
{
$this->checkExtension('phalcon');
if (!is_null($config)) {
$this->config = $config;
}
if (is_null($di)) {
// Reset the DI container
DI::reset();
// Instantiate a new DI container
$di = new FactoryDefault();
// Set the URL
$di->set('collectionManager', function () {
return new CollectionManager();
}, true);
}
$this->di = $di;
}
示例13: registerServices
/**
* Register the services here to make them general or register in the ModuleDefinition to make them module-specific
*/
protected function registerServices()
{
$di = new FactoryDefault();
$loader = new Loader();
/**
* We're a registering a set of directories taken from the configuration file
*/
$loader->registerDirs(array(__DIR__ . '/../apps/library/'))->register();
//Registering a router
$di->set('router', function () {
$router = new Router();
$router->setDefaultModule("frontend");
$router->add('/:controller/:action', array('module' => 'frontend', 'controller' => 1, 'action' => 2));
$router->add("/login", array('module' => 'backend', 'controller' => 'login', 'action' => 'index'));
$router->add("/admin/products/:action", array('module' => 'backend', 'controller' => 'products', 'action' => 1));
$router->add("/products/:action", array('module' => 'frontend', 'controller' => 'products', 'action' => 1));
return $router;
});
$this->setDI($di);
}
示例14: __construct
/**
* Constructor of the App
*/
public function __construct()
{
$di = new DI\FactoryDefault();
$this->_config = config('config');
$registry = new Registry();
$registry->directories = (object) ['modules' => APP_PATH . '/modules/', 'engine' => APP_PATH . '/engine/', 'library' => APP_PATH . '/library/'];
$di->set('registry', $registry);
$di->setShared('config', $this->_config);
$eventsManager = new EventsManager();
$this->setEventsManager($eventsManager);
$this->_initLogger($di, $this->_config);
$this->_initLoader($di, $this->_config, $eventsManager);
foreach ($this->_loaders as $service) {
$serviceName = ucfirst($service);
$eventsManager->fire('init:before' . $serviceName, null);
$result = $this->{'_init' . $serviceName}($di, $this->_config, $eventsManager);
$eventsManager->fire('init:after' . $serviceName, $result);
}
$di->setShared('eventsManager', $eventsManager);
$this->_noAuthPages = array();
}
示例15: __construct
/**
* Constructor.
*/
public function __construct()
{
/**
* Create default DI.
*/
$di = new DI\FactoryDefault();
/**
* Get config.
*/
$this->_config = Config::factory();
/**
* Adding modules to registry to load.
* Module namespace - directory will be load from here.
*/
$registry = new PhRegistry();
$registry->modules = array_merge([self::SYSTEM_DEFAULT_MODULE], $this->_config->modules->toArray());
$registry->directories = (object) ['engine' => ROOT_PATH . '/app/engine/', 'modules' => ROOT_PATH . '/app/modules/'];
$di->set('registry', $registry);
/**
* Store config in the DI container.
*/
$di->setShared('config', $this->_config);
parent::__construct($di);
}