mixed) */ private $properties = array(); /** * Creates a new controller object and sets all the request variables as class variables. * * @throws ezcMvcControllerException if the action method is empty * @param string $action * @param ezcMvcRequest $request */ public function __construct( $action, ezcMvcRequest $request ) { if ( ezcBase::inDevMode() && ( !is_string( $action ) || strlen( $action ) == 0 ) ) { throw new ezcMvcControllerException( "The '" . get_class( $this ) . "' controller requires an action." ); } $this->action = $action; $this->setRequestVariables( $request ); } /** * Sets the property $name to $value. * * @throws ezcBasePropertyNotFoundException if the property does not exist. * @throws ezcBaseValueException if a the value for a property is out of * range. * @param string $name * @param mixed $value * @ignore */ public function __set( $name, $value ) { switch ( $name ) { case 'router': if ( !$value instanceof ezcMvcRouter ) { throw new ezcBaseValueException( $name, $value, 'ezcMvcRouter' ); } $this->properties[$name] = $value; break; default: throw new ezcBasePropertyNotFoundException( $name ); } } /** * Returns the value of the property $name. * * @throws ezcBasePropertyNotFoundException if the property does not exist. * @param string $name * @ignore */ public function __get( $name ) { switch ( $name ) { case 'router': return $this->properties[$name]; default: if ( isset( $this->properties[$name] ) ) { return $this->properties[$name]; } } throw new ezcBasePropertyNotFoundException( $name ); } /** * Returns true if the property $name is set, otherwise false. * * @param string $name * @return bool * @ignore */ public function __isset( $name ) { switch ( $name ) { case 'router': return isset( $this->properties[$name] ); default: return false; } // if there is no default case before: return parent::__isset( $name ); } /** * Loops over all the variables in the request, and sets them as object properties. * * @param ezcMvcRequest $request */ protected function setRequestVariables( ezcMvcRequest $request ) { foreach ( $request->variables as $key => $value ) { $this->properties[$key] = $value; } $this->request = $request; } /** * Creates a method name to call from an $action name. * * @param string $action * @return string */ public static function createActionMethodName( $action ) { $actionMethod = 'do' . preg_replace( '@[^A-Za-z]@', '', preg_replace( '@[A-Za-z]+@e', 'ucfirst( "\\0" )', $action ) ); return $actionMethod; } /** * Runs the controller to process the query and return variables usable * to render the view. * * @throws ezcMvcActionNotFoundException if the action method could not be found * @return ezcMvcResult|ezcMvcInternalRedirect */ public function createResult() { $actionMethod = $this->createActionMethodName( $this->action ); if ( method_exists( $this, $actionMethod ) ) { return $this->$actionMethod(); } throw new ezcMvcActionNotFoundException( $this->action ); } } ?>