示例#1
0
文件: Tpl.php 项目: arhcmf/1
 /**
  * @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');
 }
示例#2
0
文件: Tpl.php 项目: arhcms/1.2
 /**
  * @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');
 }
示例#3
0
文件: Modules.php 项目: arhcms/1.2
 /**
  * @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');
 }
示例#4
0
文件: Log.php 项目: haohong725/xmvc
 public function __construct($file)
 {
     $config = DI::get('config');
     $logDir = $config->dir->log;
     $this->file = $logDir . $file;
     $this->fp = fopen($this->file, 'a+');
 }
示例#5
0
 /**
  * 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;
 }
 /**
  * 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);
 }
示例#7
0
文件: DITest.php 项目: omerucel/di
 public function testService()
 {
     $di = new DI();
     $di->setService('fake_service', 'OU\\UniqidService');
     $this->assertNotEquals($di->get('fake_service'), $di->get('fake_service'));
 }
示例#8
0
 public function call()
 {
     return $this->container->get('translation')->__get($this->argument);
 }
示例#9
0
 protected function getPayloadSaver()
 {
     return DI::get('payload.saver', new PayloadSaver());
 }
示例#10
0
文件: DI.php 项目: 2liang/MyClass
     * @param  [type] $offset [description]
     * @param  [type] $value  [description]
     * @return [type]         [description]
     */
    public function offsetSet($offset, $value)
    {
        return self::set($offset, $value);
    }
    /**
     * ArrayAccess接口,以unset($di[$name])方式卸载服务
     * @param  [type] $offset [description]
     * @return [type]         [description]
     */
    public function offsetUnset($offset)
    {
        return self::remove($offset);
    }
}
class A
{
    public function abc()
    {
        echo 'a';
    }
}
$di = new DI();
$di->set('B', function () {
    return new A();
});
var_dump($di->get('B'));
示例#11
0
 public function call()
 {
     return $this->container->get('translation')->getLang();
 }
示例#12
0
文件: Modules.php 项目: arhcmf/1
 /**
  * @param DI $DI
  */
 function __construct(DI $DI)
 {
     $this->Exception = $DI->get('\\arh\\library\\Exception');
     self::$modules = $this->getAll();
     self::$current = $this->getInfo('arh');
 }
示例#13
0
文件: Access.php 项目: arhcms/1.2
 /**
  * @param DI $DI
  */
 function __construct(DI $DI)
 {
     $this->Exception = $DI->get('\\library\\Exception');
 }
示例#14
0
 /**
  * Tests the exception is thrown when we ask for a service that has not
  * been registered.
  * @expectedException \Exception
  * @expectedExceptionMessage No element registered for key: TestElement
  */
 public function testMissingServiceThrowsException()
 {
     $di = new DI();
     $di->get('TestElement');
 }
示例#15
0
 public function call()
 {
     $request = $this->container->get('request');
     $address = sprintf("%s://%s%s", $request->getScheme(), $request->getHttpHost(), $this->argument);
     return file_get_contents($address);
 }