Ejemplo n.º 1
0
 /**
  * Test if the loader throws a `MissingDeclarationException` if the class isn't declared in the file
  * which matches the class name.
  */
 public function testForMissingDeclarationException()
 {
     try {
         $this->loader->load(self::NOT_DECLARED);
     } catch (ClassNotFoundException $e) {
         $this->assertInstanceOf('com\\mohiva\\common\\io\\exceptions\\MissingDeclarationException', $e->getPrevious());
     } catch (Exception $e) {
         $this->fail($e->getMessage());
     }
 }
Ejemplo n.º 2
0
 /**
  * Register the `load` method of the `ClassLoader`
  * implementation with the spl autoload stack.
  *
  * @param boolean $throw This parameter specifies whether `register()` should throw
  * exceptions on error.
  *
  * @param boolean $prepend If true, `register()` will prepend the autoloader on the
  * autoload stack instead of appending it.
  *
  * @throws ClassNotFoundException if the policy is set to `POLICY_EXCEPTION` and the class couldn't be found.
  */
 public function register($throw = true, $prepend = true)
 {
     $this->callback = function ($fqn) {
         if ($this->namespaceCnt && !$this->matchNamespace($fqn)) {
             return;
         }
         try {
             $this->classLoader->load($fqn);
         } catch (ClassNotFoundException $e) {
             if ($this->policy === self::POLICY_EXCEPTION) {
                 throw $e;
             }
         }
     };
     spl_autoload_register($this->callback, $throw, $prepend);
 }