當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DI\FactoryDefault類代碼示例

本文整理匯總了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());
 }
開發者ID:phalcon,項目名稱:cphalcon,代碼行數:30,代碼來源:ApplicationCest.php

示例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);
 }
開發者ID:phalconeye,項目名稱:framework,代碼行數:29,代碼來源:Application.php

示例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);
 }
開發者ID:adrianeavaz,項目名稱:manager.io,代碼行數:31,代碼來源:Application.php

示例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);
     }
 }
開發者ID:shatkovskiy,項目名稱:phalcon-sms-factory,代碼行數:14,代碼來源:Sender.php

示例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");
     }
 }
開發者ID:ovide,項目名稱:phest,代碼行數:39,代碼來源:App.php

示例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);
 }
開發者ID:xsat,項目名稱:www.walker.com,代碼行數:14,代碼來源:MainApplication.php

示例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);
 }
開發者ID:ChrisClement,項目名稱:Core,代碼行數:34,代碼來源:Email.php

示例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;
}
開發者ID:ChrisClement,項目名稱:Core,代碼行數:13,代碼來源:function.apretaste_support_email.php

示例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);
 }
開發者ID:phannguyenvn,項目名稱:test-git,代碼行數:12,代碼來源:Logs.php

示例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'));
 }
開發者ID:AlloVince,項目名稱:yinxing,代碼行數:16,代碼來源:DmmHtmlTest.php

示例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;
 }
開發者ID:stratoss,項目名稱:phalcon2rest,代碼行數:29,代碼來源:UserRepository.php

示例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;
 }
開發者ID:stratoss,項目名稱:phalcon2rest,代碼行數:34,代碼來源:ClientRepository.php

示例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);
 }
開發者ID:sb15,項目名稱:phalcon-ext,代碼行數:7,代碼來源:UrlHelper.php

示例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;
 }
開發者ID:logikostech,項目名稱:forms,代碼行數:15,代碼來源:FormTest.php

示例15: getShared

 public function getShared($name, $parameters = null)
 {
     if ($this->_init) {
         $this->checkPermission($name);
     }
     return parent::getShared($name, $parameters);
 }
開發者ID:skullab,項目名稱:thunderhawk,代碼行數:7,代碼來源:DI.php


注:本文中的Phalcon\DI\FactoryDefault類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。