find() public static method

Find class
public static find ( string $class, string $namespace = null, string $rootns = null ) : string
$class string Class
$namespace string Namespace
$rootns string Root namespace
return string
 /**
  * Gets instance of application
  * @param  string  $appName  Application name
  * @param  string  $instance Instance name
  * @param  boolean $spawn    If true, we spawn an instance if absent
  * @param  boolean $preload  If true, worker is at the preload stage
  * @return object $instance AppInstance
  */
 public function getInstance($appName, $instance = '', $spawn = true, $preload = false)
 {
     $class = ClassFinder::find($appName, 'Applications');
     if (isset(Daemon::$appInstances[$class][$instance])) {
         return Daemon::$appInstances[$class][$instance];
     }
     if (!$spawn) {
         return false;
     }
     $fullname = $this->getAppFullname($appName, $instance);
     if (!class_exists($class)) {
         Daemon::$process->log(__METHOD__ . ': unable to find application class ' . $class . '\'');
         return false;
     }
     if (!is_subclass_of($class, '\\PHPDaemon\\Core\\AppInstance')) {
         Daemon::$process->log(__METHOD__ . ': class ' . $class . '\' found, but skipped as long as it is not subclass of \\PHPDaemon\\Core\\AppInstance');
         return false;
     }
     $fullnameClass = $this->getAppFullname($class, $instance);
     if ($fullname !== $fullnameClass && isset(Daemon::$config->{$fullname})) {
         Daemon::$config->renameSection($fullname, $fullnameClass);
     }
     if (!$preload) {
         /** @noinspection PhpUndefinedVariableInspection */
         if (!$class::$runOnDemand) {
             return false;
         }
         if (isset(Daemon::$config->{$fullnameClass}->limitinstances)) {
             return false;
         }
     }
     return new $class($instance);
 }
Exemplo n.º 2
0
 public function getObject($type, $cond = null, $objOrCb = null)
 {
     $class = ClassFinder::find($type, $this->name, $this->ns);
     if (!class_exists($class)) {
         Daemon::log(get_class($this) . ': undefined class: ' . $class);
         return false;
     }
     return new $class($cond, $objOrCb, $this);
 }
Exemplo n.º 3
0
 /**
  * Constructor.
  * @return void
  */
 protected function init()
 {
     if ($this->isEnabled()) {
         list($class, $name) = explode(':', $this->name . ':');
         $realclass = ClassFinder::find($class);
         $e = explode('\\', $realclass);
         if ($e[sizeof($e) - 1] !== 'Pool' && class_exists($realclass . '\\Pool')) {
             $realclass .= '\\Pool';
         }
         if ($realclass !== $class) {
             $base = '\\PHPDaemon\\Core\\Pool:';
             Daemon::$config->renameSection($base . $class . ($name !== '' ? ':' . $name : ''), $base . $realclass . ($name !== '' ? ':' . $name : ''));
         }
         if (!class_exists($realclass)) {
             Daemon::log($realclass . ' class not exists.');
             return;
         }
         $this->pool = call_user_func([$realclass, 'getInstance'], $name);
         $this->pool->appInstance = $this;
     }
 }