123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- <?php
- abstract class sfRequest
- {
- const GET = 'GET';
- const POST = 'POST';
- const PUT = 'PUT';
- const DELETE = 'DELETE';
- const HEAD = 'HEAD';
- protected
- $dispatcher = null,
- $method = null,
- $options = array(),
- $parameterHolder = null,
- $attributeHolder = null;
-
- public function __construct(sfEventDispatcher $dispatcher, $parameters = array(), $attributes = array(), $options = array())
- {
- $this->initialize($dispatcher, $parameters, $attributes, $options);
- }
-
- public function initialize(sfEventDispatcher $dispatcher, $parameters = array(), $attributes = array(), $options = array())
- {
- $this->dispatcher = $dispatcher;
- $this->options = $options;
- if (!isset($this->options['logging']))
- {
- $this->options['logging'] = false;
- }
-
- $this->parameterHolder = new sfParameterHolder();
- $this->attributeHolder = new sfParameterHolder();
- $this->parameterHolder->add($parameters);
- $this->attributeHolder->add($attributes);
- }
-
- public function extractParameters($names)
- {
- $array = array();
- $parameters = $this->parameterHolder->getAll();
- foreach ($parameters as $key => $value)
- {
- if (in_array($key, $names))
- {
- $array[$key] = $value;
- }
- }
- return $array;
- }
-
- public function getMethod()
- {
- return $this->method;
- }
-
- public function setMethod($method)
- {
- if (!in_array(strtoupper($method), array(self::GET, self::POST, self::PUT, self::DELETE, self::HEAD)))
- {
- throw new sfException(sprintf('Invalid request method: %s.', $method));
- }
- $this->method = strtoupper($method);
- }
-
- public function getParameterHolder()
- {
- return $this->parameterHolder;
- }
-
- public function getAttributeHolder()
- {
- return $this->attributeHolder;
- }
-
- public function getAttribute($name, $default = null)
- {
- return $this->attributeHolder->get($name, $default);
- }
-
- public function hasAttribute($name)
- {
- return $this->attributeHolder->has($name);
- }
-
- public function setAttribute($name, $value)
- {
- $this->attributeHolder->set($name, $value);
- }
-
- public function getParameter($name, $default = null)
- {
- return $this->parameterHolder->get($name, $default);
- }
-
- public function hasParameter($name)
- {
- return $this->parameterHolder->has($name);
- }
-
- public function setParameter($name, $value)
- {
- $this->parameterHolder->set($name, $value);
- }
-
- public function __call($method, $arguments)
- {
- $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'request.method_not_found', array('method' => $method, 'arguments' => $arguments)));
- if (!$event->isProcessed())
- {
- throw new sfException(sprintf('Call to undefined method %s::%s.', get_class($this), $method));
- }
- return $event->getReturnValue();
- }
- public function __clone()
- {
- $this->parameterHolder = clone $this->parameterHolder;
- $this->attributeHolder = clone $this->attributeHolder;
- }
- }
|