/**
  * Set the given options
  *
  * @param   array   $options
  *
  * @return  $this
  */
 public function setOptions(array $options)
 {
     foreach ($options as $name => $value) {
         $setter = 'set' . StringHelper::cname($name);
         if (method_exists($this, $setter)) {
             $this->{$setter}($value);
         }
     }
 }
Beispiel #2
0
 /**
  * Dispatch request to a controller and action
  *
  * @param   Zend_Controller_Request_Abstract  $request
  * @param   Zend_Controller_Response_Abstract $response
  *
  * @throws  Zend_Controller_Dispatcher_Exception    If the controller is not an instance of
  *                                                  Zend_Controller_Action_Interface
  * @throws  Exception                               If dispatching the request fails
  */
 public function dispatch(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response)
 {
     $this->setResponse($response);
     $controllerName = $request->getControllerName();
     if (!$controllerName) {
         parent::dispatch($request, $response);
         return;
     }
     $controllerName = StringHelper::cname($controllerName, '-') . 'Controller';
     $moduleName = $request->getModuleName();
     if ($moduleName === null || $moduleName === $this->_defaultModule) {
         $controllerClass = 'Icinga\\' . self::CONTROLLER_NAMESPACE . '\\' . $controllerName;
     } else {
         $controllerClass = 'Icinga\\Module\\' . ucfirst($moduleName) . '\\' . self::CONTROLLER_NAMESPACE . '\\' . $controllerName;
     }
     if (!class_exists($controllerClass)) {
         parent::dispatch($request, $response);
         return;
     }
     $controller = new $controllerClass($request, $response, $this->getParams());
     if (!$controller instanceof Zend_Controller_Action && !$controller instanceof Zend_Controller_Action_Interface) {
         throw new Zend_Controller_Dispatcher_Exception('Controller "' . $controllerClass . '" is not an instance of Zend_Controller_Action_Interface');
     }
     $action = $this->getActionMethod($request);
     $request->setDispatched(true);
     // Buffer output by default
     $disableOb = $this->getParam('disableOutputBuffering');
     $obLevel = ob_get_level();
     if (empty($disableOb)) {
         ob_start();
     }
     try {
         $controller->dispatch($action);
     } catch (Exception $e) {
         // Clean output buffer on error
         $curObLevel = ob_get_level();
         if ($curObLevel > $obLevel) {
             do {
                 ob_get_clean();
                 $curObLevel = ob_get_level();
             } while ($curObLevel > $obLevel);
         }
         throw $e;
     }
     if (empty($disableOb)) {
         $content = ob_get_clean();
         $response->appendBody($content);
     }
 }
Beispiel #3
0
 /**
  * Join alias or column $name into $table using $query
  *
  * Attempts to find a valid table for the given alias or column name and a method labelled join<TableName>
  * to process the actual join logic. If neither of those is found, null is returned.
  * The method is called with the same parameters but in reversed order.
  *
  * @param   string              $name       The alias or column name to join into $target
  * @param   string              $target     The table to join $name into
  * @param   RepositoryQUery     $query      The query to apply the JOIN-clause on
  *
  * @return  string|null                     The resolved alias or $name, null if no join logic is found
  */
 public function joinColumn($name, $target, RepositoryQuery $query)
 {
     if (!($tableName = $this->findTableName($name))) {
         return;
     }
     if (($column = $this->resolveQueryColumnAlias($tableName, $name)) === null) {
         $column = $name;
     }
     if (($joinIdentifier = $this->resolveTableAlias($tableName)) === null) {
         $joinIdentifier = $this->prependTablePrefix($tableName);
     }
     if ($query->getQuery()->hasJoinedTable($joinIdentifier)) {
         return $column;
     }
     $joinMethod = 'join' . StringHelper::cname($tableName);
     if (!method_exists($this, $joinMethod)) {
         throw new ProgrammingError('Unable to join table "%s" into "%s". Method "%s" not found', $tableName, $target, $joinMethod);
     }
     $this->{$joinMethod}($query, $target, $name);
     return $column;
 }
 /**
  * Return the form for the given type of navigation item
  *
  * @param   string  $type
  *
  * @return  Form
  */
 protected function getItemForm($type)
 {
     $className = StringHelper::cname($type, '-') . 'Form';
     $form = null;
     foreach (Icinga::app()->getModuleManager()->getLoadedModules() as $module) {
         $classPath = 'Icinga\\Module\\' . ucfirst($module->getName()) . '\\' . static::FORM_NS . '\\' . $className;
         if (class_exists($classPath)) {
             $form = new $classPath();
             break;
         }
     }
     if ($form === null) {
         $classPath = 'Icinga\\' . static::FORM_NS . '\\' . $className;
         if (class_exists($classPath)) {
             $form = new $classPath();
         }
     }
     if ($form === null) {
         Logger::debug('Failed to find custom navigation item form %s for item %s. Using form NavigationItemForm now', $className, $type);
         $form = new NavigationItemForm();
     } elseif (!$form instanceof NavigationItemForm) {
         throw new ProgrammingError('Class %s must inherit from NavigationItemForm', $classPath);
     }
     return $form;
 }
Beispiel #5
0
 /**
  * Create and return a new navigation item for the given configuration
  *
  * @param   string              $name
  * @param   array|ConfigObject  $properties
  *
  * @return  NavigationItem
  *
  * @throws  InvalidArgumentException    If the $properties argument is neither an array nor a ConfigObject
  */
 public function createItem($name, $properties)
 {
     if ($properties instanceof ConfigObject) {
         $properties = $properties->toArray();
     } elseif (!is_array($properties)) {
         throw new InvalidArgumentException('Argument $properties must be of type array or ConfigObject');
     }
     $itemType = isset($properties['type']) ? StringHelper::cname($properties['type'], '-') : 'NavigationItem';
     if (!empty(static::$types) && isset(static::$types[$itemType])) {
         return new static::$types[$itemType]($name, $properties);
     }
     $item = null;
     foreach (Icinga::app()->getModuleManager()->getLoadedModules() as $module) {
         $classPath = 'Icinga\\Module\\' . ucfirst($module->getName()) . '\\' . static::NAVIGATION_NS . '\\' . $itemType;
         if (class_exists($classPath)) {
             $item = new $classPath($name, $properties);
             break;
         }
     }
     if ($item === null) {
         $classPath = 'Icinga\\' . static::NAVIGATION_NS . '\\' . $itemType;
         if (class_exists($classPath)) {
             $item = new $classPath($name, $properties);
         }
     }
     if ($item === null) {
         Logger::debug('Failed to find custom navigation item class %s for item %s. Using base class NavigationItem now', $itemType, $name);
         $item = new NavigationItem($name, $properties);
         static::$types[$itemType] = 'Icinga\\Web\\Navigation\\NavigationItem';
     } elseif (!$item instanceof NavigationItem) {
         throw new ProgrammingError('Class %s must inherit from NavigationItem', $classPath);
     } else {
         static::$types[$itemType] = $classPath;
     }
     return $item;
 }
 /**
  * Set the properties of the acknowledgement
  *
  * @param   array|object|Traversable $properties
  *
  * @return  $this
  * @throws  InvalidArgumentException If the type of the given properties is invalid
  */
 public function setProperties($properties)
 {
     if (!is_array($properties) && !is_object($properties) && !$properties instanceof Traversable) {
         throw new InvalidArgumentException('Properties must be either an array or an instance of Traversable');
     }
     foreach ($properties as $name => $value) {
         $setter = 'set' . ucfirst(StringHelper::cname($name));
         if (method_exists($this, $setter)) {
             $this->{$setter}($value);
         }
     }
     return $this;
 }