DataSift\Storyplayer\PlayerLib\Prose_Loader::loadProse PHP Method

loadProse() public method

public loadProse ( StoryTeller $st, string $className, $constructorArgs )
$st StoryTeller
$className string
    public function loadProse(StoryTeller $st, $className, $constructorArgs)
    {
        // can we find the class?
        foreach ($this->namespaces as $namespace) {
            // what is the full name of the class (inc namespace) to
            // search for?
            $namespacedClassName = $namespace . "\\" . $className;
            // is there such a class?
            if (class_exists($namespacedClassName)) {
                // yes there is!!
                //
                // create an instance of the class
                $return = new $namespacedClassName($st, $constructorArgs);
                // make sure our new object is an instance of 'Prose'
                if (!$return instanceof Prose) {
                    throw new E5xx_NotAProseClass($namespacedClassName);
                }
                // return our newly-minted object
                return $return;
            }
        }
        // if we get there, then we cannot find a suitable class in
        // any of the namespaces that we know about
        return null;
    }

Usage Example

Beispiel #1
0
 /**
  *
  * @param  string $methodName
  * @param  array  $methodArgs
  * @return mixed
  */
 public function __call($methodName, $methodArgs)
 {
     // what class do we want?
     $className = $this->proseLoader->determineProseClassFor($methodName);
     // use the Prose Loader to create the object to call
     $obj = $this->proseLoader->loadProse($this, $className, $methodArgs);
     // did we find something?
     if (!is_object($obj)) {
         // alas, no
         throw new E5xx_NoMatchingActions($methodName);
     }
     // all done
     return $obj;
 }