Example #1
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));
 }
Example #2
0
 /**
  * Headers Management Class Constructor
  */
 public function __construct()
 {
     parent::__construct();
     // Setting Up Headers Lists
     $this->headers = new Lists();
     // Extend Object Headers' List
     $this->extend(new Invoker($this, $this->headers));
 }
Example #3
0
 /**
  * Datatype Constructor
  *
  * @param mixed|optional $value
  *   Value to set
  *
  * @throws InvalidArgumentException
  *   Given argument ois not acceptable by concrete datatype class
  */
 public function __construct($value = NULL)
 {
     parent::__construct();
     // If a value was defined...
     if (!is_null($value)) {
         // ... let's cCheck its acceptance before set
         if ($this->accept($value) === FALSE) {
             throw new \InvalidArgumentException('Argument is not a ' . $this);
         }
     }
     // Prototyping (even without value)...
     $this->prototype($value);
     $this->value =& $value;
 }
 /**
  * Controller Constructor
  *
  * <p>
  *     If an Application Object is provided, the Controller will
  *     be configured.
  * </p>
  *
  * <p>
  *     An Application is NOT passed only in concrete classes extending
  *     Next\Application\AbstractApplication, when building
  *     Application Chain
  * </p>
  *
  * @param Next\Application\Application|optional $application
  *
  *   <p>Application Object</p>
  *
  *   <p>
  *       With Standard Router, used only when
  *       <em>DEVELOPMENT_MODE<em> is not <strong>2</strong>
  *   </p>
  */
 public final function __construct(Application $application = NULL)
 {
     parent::__construct();
     // If we an Application (dispatching process), let's handle it
     if (!is_null($application)) {
         // Request Object
         $this->_application =& $application;
         // Application's View Engine
         $this->view = $application->getView();
         // HTTP GET Params (a.k.a. Dynamic Params) as Template Variables
         $this->view->assign($application->getRequest()->getQuery());
         // Executing Extra Initialization Routines
         $this->init();
     }
 }
Example #5
0
 /**
  * Table Manager Constructor
  *
  * @param Next\DB\Driver\Driver $driver
  *   Connection Driver
  *
  * @param Next\DB\Table\Table $table
  *   Table Object
  */
 public function __construct(Driver $driver, Table $table)
 {
     parent::__construct();
     // Setting Up resources
     $this->driver =& $driver;
     $this->table =& $table;
     /**
      * @internal Data Source
      *
      * By default Table Manager will work with original Table Fields.
      *
      * When a UPDATE Statement is executed, however, the Manager will
      * work with Row/RowSet Fields computed from the difference between
      * original fields and modified fields
      */
     $this->source = $table->getFields();
     // Extend Object Context to QueryBuilder Class
     $this->extend(new Invoker($this, new Builder($driver->getRenderer())));
 }
Example #6
0
 /**
  * Request Constructor
  *
  * If only one argument is provided, it'll be checked against
  * Next\HTTP\Stream\Adapter\Adapter.
  *
  * If it passes, it will be used and Request URI will be retrieved
  * from it
  *
  * Otherwise, this argument will be THE Request URI
  *
  * The second argument is the Request Method, also optional.
  *
  * If no arguments are entered (case of Routed Requests), default
  * values will take place: REQUEST_URI from $_SERVER and GET as
  * Request Method
  */
 public function __construct()
 {
     parent::__construct();
     // Cookies Management Object
     $this->cookies = new Cookies();
     // Request Headers Management Object
     $this->headers = new Headers\RequestHeaders();
     // Extend Object Context to Headers', Cookies and Browser Classes
     $this->extend(new Invoker($this, $this->headers))->extend(new Invoker($this, $this->cookies))->extend(new Invoker($this, new Request\Browser()));
     // Initializing Data Properties with superglobals
     $this->queryData = $_GET;
     $this->postData = $_POST;
     //---------------------------
     list($mixed, $method) = func_get_args() + array($_SERVER['REQUEST_URI'], $_SERVER['REQUEST_METHOD']);
     // Setting Up Basic Informations
     // Do we have an HTTP Stream Adapter?
     if ($mixed instanceof Adapter) {
         $this->adapter =& $mixed;
         // If so, let's use its file/url as URI
         $this->uri = $mixed->getFilename();
     } else {
         // No? So let's use first argument as URI
         $this->uri =& $mixed;
     }
     // Request Method
     $this->method = strtoupper($method);
     //---------------------------
     // Server Protocol
     $this->protocol = new \stdClass();
     $data = parse_url($this->uri);
     if (array_key_exists('scheme', $data)) {
         // Protocol... "name"
         $this->protocol->name = $data['scheme'];
         // URI Basepath
         /**
          * @internal
          * This implementation can be reliable because
          * an external request without HTTP Scheme (e.g. http://)
          * will not be opened successfully anyway
          */
         if (array_key_exists('path', $data)) {
             $this->basepath = ltrim($data['path'], '/');
         }
     } else {
         // Protocol... "name"
         preg_match(self::PROTOCOL_REGEXP, $_SERVER['SERVER_PROTOCOL'], $match);
         if (array_key_exists('protocol', $match)) {
             $this->protocol->name = strtolower($match['protocol']);
         }
         if (array_key_exists('version', $match)) {
             $this->protocol->version = $match['version'];
         }
         // URI Basepath
         /**
          * @internal
          * By default, the basepath is the basename of directory name
          * index.php is located
          */
         $this->basepath = basename(dirname($_SERVER['SCRIPT_FILENAME']));
         // Default Request Headers. Internal Requests only.
         if (defined('TURBO_MODE') && TURBO_MODE === FALSE) {
             $this->addDefaultHeaders();
         }
     }
 }
 /**
  * Check if an Objects exists
  *
  * @param Next\Components\Object $object
  *   Object to check if it's present in Collection
  *
  * @return boolean
  *   TRUE if given Object is already present in Collection and FALSE otherwise
  */
 public function contains(Object $object)
 {
     return in_array($object->getHash(), $this->references->getArrayCopy());
 }
Example #8
0
 /**
  * Response Constructor
  *
  * @param string|optional $data
  *   Response Data
  *
  * @param array|optional $metaData
  *   Response Meta Data
  */
 public function __construct($data = NULL, array $metaData = array())
 {
     parent::__construct();
     // Headers Management Object
     $this->headers = new Headers\ResponseHeaders();
     // Extend Object Context to Headers', Cookies and Browser Classes
     $this->extend(new Invoker($this, $this->headers));
     /**
      * @internal
      * When dealing with Routed (internal) Requests, no data will
      * be available because the Front Controller did not send the
      * Response yet.
      *
      * In External Requests, the Response is not sent anyways,
      * so we condition the buffer length to not hide any output
      * manually added, like a debugging purposes var_dump()
      */
     if (empty($data) || ob_get_length()) {
         if (defined('TURBO_MODE') && TURBO_MODE === FALSE) {
             if (function_exists('apache_response_headers')) {
                 try {
                     $this->headers->addHeader(apache_response_headers());
                 } catch (FieldsException $e) {
                     /**
                      * @internal
                      * We're silencing the FieldsException in order to not
                      * break the Response Flow
                      *
                      * However, if this Exception is caught, no Response
                      * Headers will be available
                      */
                 }
             } else {
                 $headers = headers_list();
                 foreach ($headers as $data) {
                     list($header, $value) = explode(':', $data, 2);
                     try {
                         $this->headers->addHeader($header, $value);
                     } catch (FieldsException $e) {
                         // Same explanation as above
                     }
                 }
             }
         }
     } else {
         $this->appendBody($data);
         if (count($metaData) != 0 && (defined('TURBO_MODE') && TURBO_MODE === FALSE)) {
             $this->addResponseData($metaData);
         }
     }
 }
Example #9
0
 /**
  * Merge Options
  *
  * @param mixed $param
  *
  *   Argument to merge as Parameter Options
  *
  *   Acceptable values are:
  *
  *   <ul>
  *
  *       <li>Array</li>
  *
  *       <li>
  *
  *           An {@link http://php.net/manual/en/reserved.classes.php stdClass Object}
  *       </li>
  *
  *       <li>Next\Components\Object object</li>
  *
  *       <li>Next\Components\Parameter Object</li>
  *
  *   </ul>
  *
  * @throws Next\Components\Debug\Exception
  *   Any option is not an associative array, because
  *   doesn't make sense to have a public property just to store NULL
  */
 public function merge($param)
 {
     // Converting, if needed
     if (is_array($param)) {
         $param = parent::map($param);
     }
     if ($param instanceof Object || $param instanceof Parameter || $param instanceof \stdClass) {
         // Merging...
         foreach ($param as $property => $value) {
             if (is_int($property)) {
                 throw new \Next\Components\Debug\Exception('All options must be an associative array');
             } else {
                 $this->{$property} = $value;
             }
         }
     }
 }
Example #10
0
 /**
  * Decorator Constructor
  *
  *  @param string $message
  *    Resource to decorate
  */
 public function __construct($resource)
 {
     parent::__construct();
     $this->resource =& $resource;
 }
Example #11
0
 /**
  * Match Path Annotation
  *
  * Path Annotations start with !Path
  *
  * @param Next\Components\Object $application
  *   Application Object
  *
  * @return string
  *   Found Annotation
  */
 private function matchPathAnnotation(Object $application)
 {
     $path = preg_grep(sprintf('/%s/', self::PATH_PREFIX), preg_split('/[\\n\\r]+/', $application->getClass()->getDocComment()));
     $path = preg_replace(sprintf('/.*?%s\\s*/', self::PATH_PREFIX), '', $path);
     return array_shift($path);
 }