Пример #1
0
 function resolveViewName($viewName, $locale)
 {
     if (!AppContext::service_exists($viewName)) {
         // Allow for ViewResolver chaining.
         return null;
     }
     return AppContext::service($viewName);
 }
Пример #2
0
function log_enabled($level)
{
    $log =& AppContext::service('Log');
    if ($log != null) {
        return $log->enabled($level);
    } else {
        return false;
    }
}
Пример #3
0
 function &getHandler(&$request)
 {
     $handler =& $this->getHandlerInternal($request);
     if ($handler == null) {
         $handler =& $this->defaultHandler;
     }
     if ($handler == null) {
         return $handler;
     }
     // Service name or resolved handler?
     if (is_string($handler)) {
         $handler =& AppContext::service($handler);
     }
     $hec =& new HandlerExecutionChain(&$handler, &$this->interceptors);
     return $hec;
 }
Пример #4
0
 function _resolveService($serviceName)
 {
     if ($this->{$serviceName} == NULL) {
         $this->{$serviceName} =& AppContext::service($serviceName);
         if ($this->{$serviceName} == NULL) {
             $this->{$serviceName} =& $this->_getDefaultStrategy($serviceName);
         }
     }
     if (log_enabled(LOG_DEBUG)) {
         log_message(LOG_DEBUG, 'Using ' . $serviceName . ' [' . get_class($this->{$serviceName}) . ']');
     }
 }
Пример #5
0
 function &instantiate()
 {
     if ($this->className == null) {
         return _null();
     }
     if (!class_exists($this->className)) {
         if (!is_file($this->base . $this->filename) || !file_exists($this->base . $this->filename)) {
             show_error('Instantiator Error', "File not found for '{$this->className}': " . $this->base . $this->filename);
         }
         include $this->base . $this->filename;
     }
     $class = $this->className;
     if (!is_array($this->definition)) {
         $instance =& new $class();
     } else {
         # parameters
         $parameters = false;
         if (isset($this->definition['parameters'])) {
             if (!is_array($parameters = $this->definition['parameters'])) {
                 $parameters = array($parameters);
             }
         }
         # instantiate
         if (!$parameters) {
             $instance =& new $class();
         } else {
             $instance =& $this->_create_obj_array($class, $parameters);
         }
         # autowire?
         if (isset($this->definition['autowire']) && $this->definition['autowire'] == true) {
             $vars = get_object_vars($instance);
             foreach ($vars as $name => $val) {
                 $service =& AppContext::service($name);
                 if ($service != null) {
                     $instance->{$name} =& $service;
                 }
             }
         }
         # properties
         if (isset($this->definition['properties'])) {
             $properties = array_map(array(&$this, '_get_typed_value'), $this->definition['properties']);
             foreach ($properties as $name => $value) {
                 $instance->{$name} =& $properties[$name];
             }
         }
         # invoke
         if (isset($this->definition['invoke'])) {
             foreach ($this->definition['invoke'] as $name => $value) {
                 if (!is_array($value)) {
                     $value = array($value);
                 }
                 call_user_func_array(array(&$instance, $name), $value);
             }
         }
         # initialize-method
         if (isset($this->definition['initialize-method'])) {
             call_user_func(array(&$instance, $this->definition['initialize-method']));
         }
     }
     return $instance;
 }