本文整理汇总了PHP中Phalcon\DI\FactoryDefault类的典型用法代码示例。如果您正苦于以下问题:PHP FactoryDefault类的具体用法?PHP FactoryDefault怎么用?PHP FactoryDefault使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FactoryDefault类的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: __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);
}
示例3: 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);
}
示例4: __construct
/**
* Inject of Phalcon dependency container
*
* @param \Phalcon\DI\FactoryDefault $dependency
* @throws BaseException
*/
public function __construct(\Phalcon\DI\FactoryDefault $dependency)
{
if ($dependency->has('config') === true) {
$this->config = $dependency->get('config')->sms->toArray();
} else {
throw new BaseException('SMS', 'Please setup your configuration to $dependency', 500);
}
}
示例5: __construct
/**
* Constructs the app.
*
* Checks singleton instance
* Adds a dependency injector if none provided
* Sets the notFound handler
*
* @param FactoryDefault $dependencyInjector
* @throws \RuntimeException
*/
public function __construct($dependencyInjector = null)
{
if (self::$app === null) {
if ($dependencyInjector === null) {
$dependencyInjector = new FactoryDefault();
}
$dependencyInjector->setShared('response', Response::class);
$dependencyInjector->setShared('router', Router::class);
if (!$dependencyInjector->has('eventsManager')) {
$dependencyInjector->setShared('eventsManager', \Phalcon\Events\Manager::class);
}
if (!$dependencyInjector->has('request')) {
$dependencyInjector->setShared('request', \Phalcon\Http\Request::class);
}
parent::__construct($dependencyInjector);
self::$app = $this;
$this->setEventsManager($dependencyInjector->getShared('eventsManager'));
$this->addHeaderHandler(new HeaderHandler\Accept());
$app = self::$app;
$this->_errorHandler = function (\Exception $ex) {
return $this->errorHandler($ex);
};
$this->_notFoundHandler = function () {
return $this->notFoundHandler();
};
} else {
throw new \RuntimeException("Can't instance App more than once");
}
}
示例6: 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);
}
示例7: sendEmail
/**
* Sends an email using MailGun
* @author salvipascual
* @param String $to, email address of the receiver
* @param String $subject, subject of the email
* @param String $body, body of the email in HTML
* @param Array $images, paths to the images to embeb
* @param Array $attachments, paths to the files to attach
* */
public function sendEmail($to, $subject, $body, $images = array(), $attachments = array())
{
// do not email if there is an error
$response = $this->deliveryStatus($to);
if ($response != 'ok') {
return;
}
// select the from email using the jumper
$from = $this->nextEmail($to);
$domain = explode("@", $from)[1];
// create the list of images
if (!empty($images)) {
$images = array('inline' => $images);
}
// crate the list of attachments
// TODO add list of attachments
// create the array send
$message = array("from" => "Apretaste <{$from}>", "to" => $to, "subject" => $subject, "html" => $body, "o:tracking" => false, "o:tracking-clicks" => false, "o:tracking-opens" => false);
// get the key from the config
$di = \Phalcon\DI\FactoryDefault::getDefault();
$mailgunKey = $di->get('config')['mailgun']['key'];
// send the email via MailGun
$mgClient = new Mailgun($mailgunKey);
$result = $mgClient->sendMessage($domain, $message, $images);
}
示例8: smarty_function_apretaste_support_email
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsFunction
*/
function smarty_function_apretaste_support_email($params, $template)
{
// get the support email from the configs
$di = \Phalcon\DI\FactoryDefault::getDefault();
$supportEmail = $di->get("config")["contact"]["support"];
return $supportEmail;
}
示例9: log
/**
* @param $name
* @param $message
* @param $type
*/
public static function log($name, $message, $type)
{
$typeName = self::getTypeString($type);
$logger = FactoryDefault::getDefault()->get('logger');
$logger->name = $name;
$logger->{$typeName}($message);
}
示例10: 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'));
}
示例11: getUserEntityByUserCredentials
/**
* {@inheritdoc}
*/
public function getUserEntityByUserCredentials($username, $password, $grantType, ClientEntityInterface $clientEntity)
{
$di = new Di();
/** @var Security $security */
$security = $di->getShared('security');
$user = Users::query()->where("username = :username:")->bind(['username' => $username])->limit(1)->execute()->toArray();
$correctDetails = false;
if (count($user) === 1) {
$user = current($user);
if ($security->checkHash($password, $user['password'])) {
$correctDetails = true;
} else {
$security->hash(rand());
}
} else {
// prevent timing attacks
$security->hash(rand());
}
if ($correctDetails) {
//$scope = new ScopeEntity();
//$scope->setIdentifier('email');
//$scopes[] = $scope;
return new UserEntity($user);
}
return null;
}
示例12: getClientEntity
/**
* {@inheritdoc}
*/
public function getClientEntity($clientIdentifier, $grantType, $clientSecret = null, $mustValidateSecret = true)
{
$di = new Di();
/** @var Security $security */
$security = $di->getShared('security');
$client = Clients::query()->where("id = :id:")->bind(['id' => $clientIdentifier])->limit(1)->execute()->toArray();
$correctDetails = false;
if (count($client) === 1) {
$client = current($client);
if ($mustValidateSecret) {
if ($security->checkHash($clientSecret, $client['secret'])) {
$correctDetails = true;
} else {
$security->hash(rand());
}
} else {
$correctDetails = true;
}
} else {
// prevent timing attacks
$security->hash(rand());
}
if ($correctDetails) {
$clientEntity = new ClientEntity();
$clientEntity->setIdentifier($clientIdentifier);
$clientEntity->setName($client['name']);
$clientEntity->setRedirectUri($client['redirect_url']);
return $clientEntity;
}
return null;
}
示例13: get
public function get($routeName, $routeParams = array())
{
$url = $this->di->get('url');
$options = array('for' => $routeName);
$options = array_merge($options, $routeParams);
return $url->get($options);
}
示例14: 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;
}
示例15: getShared
public function getShared($name, $parameters = null)
{
if ($this->_init) {
$this->checkPermission($name);
}
return parent::getShared($name, $parameters);
}