You are here

abstract class Application in Module Object Oriented Programming API 7.2

Same name and namespace in other branches
  1. 6.2 component/moopapi.component.inc \Application
  2. 6 component/moopapi.component.inc \Application
  3. 7 component/moopapi.component.inc \Application

@todo Desc for Application.

Hierarchy

Expanded class hierarchy of Application

File

component/moopapi.component.inc, line 112

View source
abstract class Application extends Component implements IApplication {

  // The base path for all configurations.
  const ADMIN_PATH = 'admin';
  protected $type = 'Application';

  // A list of controller names to be initialize at the first launch.
  protected $ctrls = array();

  // Controllers to manipulate the parts of the application as a whole.
  protected $controllers = array();
  public function __construct($decorators_applied = array()) {
    parent::__construct($decorators_applied);
    $this
      ->getControllers();
  }
  public function getControllers() {
    if (empty($this->controllers)) {
      foreach ($this->ctrls as $ctrl_name) {
        $this->controllers[$ctrl_name] = $this
          ->getController($ctrl_name);
      }
    }
    return $this->controllers;
  }
  protected function getController($ctrl_name) {
    if (empty($this->controllers[$ctrl_name])) {
      $controller = ComponentFactory::get($this->app_name, 'Controller', $ctrl_name, $this->decorators_applied, $this->relations);
      $this->controllers[$ctrl_name] = $controller;
    }
    return $this->controllers[$ctrl_name];
  }
  public function getAdminForm($form, &$form_state, $form_name) {
    $app_name = strtolower($this->app_name);

    // @todo Refactor this switch stuff with classes since they are similar a lot.
    switch ($form_name) {
      case 'general':

        // Development fieldset.
        $form['development'] = array(
          '#type' => 'fieldset',
          '#title' => t('Development'),
          '#description' => t('In fact you should change the state of these settings only for development purposes.'),
        );

        // Decorator fieldset.
        $form['development']['decorators'] = array(
          '#type' => 'fieldset',
          '#title' => t('Decorators'),
          '#description' => t('Features that extend usual behavior of the module. For more details see <a href="@decorator_link">Decorator pattern</a> article.', array(
            '@decorator_link' => url("http://en.wikipedia.org/wiki/Decorator_pattern"),
          )),
        );

        // Logger decorator.
        $form['development']['decorators']['logger'] = array(
          '#type' => 'checkbox',
          '#title' => t('Logger'),
          '#description' => t('Enable to get full log of all application method calls as a file.'),
          '#default_value' => in_array('Logger', (array) unserialize(variable_get("{$app_name}_decorators", serialize(array())))),
        );

        // Cacher decorator.
        $form['development']['decorators']['cacher'] = array(
          '#disabled' => TRUE,
          '#type' => 'checkbox',
          '#title' => t('Cacher'),
          '#description' => t('Speeds up each method call by using multi-level caching.') . ' ' . $this
            ->getStubText(1870060, 'moopapi'),
          '#default_value' => in_array('Cacher', (array) unserialize(variable_get("{$app_name}_decorators", serialize(array())))),
        );
        break;
    }
    return $form;
  }
  public function submitAdminForm($form, &$form_state) {
    $form_name = $form['#form_name']['#value'];

    // Decorators handling.
    switch ($form_name) {
      case 'general':

        // @todo Refactor it.
        $decs = array(
          'logger' => 'Logger',
          'cacher' => 'Cacher',
        );
        $app_name = strtolower($this->app_name);
        $decorators = array();
        foreach ($decs as $field_name => $decorator_id) {
          if ($form_state['values'][$field_name]) {
            $decorators[$field_name] = $decorator_id;
          }
        }
        variable_set("{$app_name}_decorators", serialize($decorators));
    }
  }
  protected function getStubText($drupal_nid, $app_name = NULL) {
    $app_name = !empty($app_name) ? $app_name : strtolower($this->app_name);
    return t('This functionality is currently in development. See <a href="@issue_link">related issue</a>. Please consider participating in <a href="@patchranger_link">patch crowd funding of this issue</a>. Read more about patch crowd funding on <a href="@project_link">the module\'s project page</a>.', array(
      '@issue_link' => url("http://drupal.org/node/{$drupal_nid}"),
      '@patchranger_link' => url("http://www.patchranger.com/?do_nid={$drupal_nid}"),
      '@project_link' => url("http://drupal.org/project/{$app_name}#how-much-does-it-cost"),
    ));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Application::$controllers protected property
Application::$ctrls protected property
Application::$type protected property Overrides Component::$type
Application::ADMIN_PATH constant
Application::getAdminForm public function
Application::getController protected function
Application::getControllers public function Overrides IApplication::getControllers
Application::getStubText protected function
Application::submitAdminForm public function
Application::__construct public function Overrides Component::__construct
Component::$app_name protected property
Component::$decorators_applied protected property
Component::$id protected property
Component::$relations protected property
Component::$rltns protected property
Component::ID_APPLICATION constant
Component::TYPE_CONTROLLER constant
Component::TYPE_MODEL constant