Esempio n. 1
0
 /**
  * Development Mode Exception Handler
  *
  * @param Exception $e
  *   Exception thrown
  */
 public static function development(\Exception $e)
 {
     // Enforcing Error Handler
     if ($e instanceof ErrorException) {
         return self::error(2, $e->getMessage(), $e->getFile(), $e->getLine());
     }
     $code = 406;
     // Default Code NOT ACCEPTABLE
     if (method_exists($e, 'getResponseCode')) {
         $code = $e->getResponseCode();
     }
     self::handle('Next\\Components\\Debug\\Handlers\\Controllers\\ExceptionController', 'development', array('e' => $e), $code);
 }
Esempio n. 2
0
    /**
     * Allow extended Objects to be called in this Object context
     *
     * IMPORTANT!
     *
     * Watch out when use Fluent Interfaces, because the "bridging"
     * feature WILL return the METHOD called, not the invoker object
     *
     * @param string $method
     *   Method trying to be invoked
     *
     * @param array|optional $args
     *   Variable list of arguments to the method
     *
     * @return mixed|boolean
     *   Return what extended method returns
     *
     * @throws Next\Components\Debug\Exception
     *   Object Constructor was overwritten without invoking it through
     *   parent:: context
     */
    public function __call($method, array $args = array())
    {
        if (is_null($this->context)) {
            throw \Next\Components\Debug\Exception::unfullfilledRequirements('<p>
                    Method <strong>%s</strong> is not known by
                    <strong>%s</strong> and was not trapped by
                    <em>__call()</em>.
                </p>

                <p>
                    Could you possibly overwrote <em>Object::__construct()</em>
                    without invoke it under parent context?
                </p>', array($method, $this));
        }
        // Trying to call as an extended method
        try {
            return $this->context->call($this, $method, $args);
        } catch (\Next\Components\Debug\Exception $e) {
            // Trying to call as a prototyped method
            return $this->call($this, $method, $args);
        }
    }
Esempio n. 3
0
 /**
  * Invoke an extended resource from a caller context
  *
  * @param Next\Components\Object $caller
  *   Caller Object
  *
  * @param string $method
  *   Callable resource name
  *
  * @param array $args
  *   Calling Arguments
  *
  * @return mixed|boolean
  *   Return what extended method returns.
  *
  *   If invoking process fail, false will returned.
  *
  * @throws Next\Components\Debug\Exception
  *   Called resource is not known as an extended method
  */
 public function call(Object $caller, $method, array $args = array())
 {
     $caller = $caller->getClass()->getName();
     if (array_key_exists($caller, $this->callables)) {
         $offset = ArrayUtils::search($this->callables[$caller], $method);
         if ($offset != -1) {
             try {
                 $reflector = new \ReflectionMethod($this->callables[$caller][$offset][0], $method);
                 return $reflector->invokeArgs($this->callables[$caller][$offset][0], $args);
             } catch (\ReflectionException $e) {
                 return FALSE;
             }
         }
     }
     // Unknown Method
     throw \Next\Components\Debug\Exception::wrongUse('Method <strong>%s</strong> could not be matched against any
         methods in extended Context', array($method));
 }
Esempio n. 4
0
 /**
  * Exception Constructor
  */
 public function __construct()
 {
     $args = func_get_args();
     // Exception Message
     $message = array_shift($args);
     // Listing Additional Exception Components
     list($code, $replacements, $responseCode) = $args + array(self::UNKNOWN, array(), 200);
     // Checking Exception Components...
     $this->checkComponents($message, (array) $replacements, $code, $responseCode);
     // ... and settle them up
     $this->replacements = (array) $replacements;
     $this->responseCode = $responseCode;
     // Constructing the Exception
     parent::__construct($this->_getMessage($message), $code);
 }
Esempio n. 5
0
 /**
  * Invoke a prototyped resource from a caller context
  *
  * @param Next\Components\Object $caller
  *   Caller Object
  *
  * @param string $method
  *   Callable resource name
  *
  * @param array $args
  *   Calling Arguments
  *
  * @return Next\Components\Object
  *   Caller Object updated
  *
  * @throws Next\Components\Debug\Exception
  *   Called resource is not known as a prototype nor as a extended method
  */
 public function call(Object $caller, $method, array $args = array())
 {
     if (isset(self::$prototypes[$method])) {
         // Merging always optional arguments with called arguments
         if (count($args) > 0) {
             ArrayUtils::insert(self::$prototypes[$method][1], $args);
         } else {
             // Nothing to Merge? OK!
             $args =& self::$prototypes[$method][1];
         }
         $result = call_user_func_array(self::$prototypes[$method][0], $args);
         /**
          * @internal
          *
          * If operation results in an Object, let's return it
          *
          * This ensures operations of one type can return a different type
          */
         if ($result instanceof Object) {
             return $result;
         }
         // Otherwise let's update caller Object
         return $caller->set($result);
     }
     throw \Next\Components\Debug\Exception::wrongUse('Method <strong>%s</strong> could not be matched against any
         methods in extended Context or prototyped functions', array($method));
 }