You are here

class Pattern in Patterns 6.2

Hierarchy

Expanded class hierarchy of Pattern

File

./pattern.class.php, line 2

View source
class Pattern {
  private $info = array(
    'title' => "",
    'description' => "",
    'author' => "",
    'author_email' => "",
    'category' => "",
    'version' => "0.1",
  );
  private $modules = array();
  private $actions = array();
  function __construct($title, $author, $author_email) {
    $this
      ->info('title', $title);
    $this
      ->info('author', $author);
    $this
      ->info('author_email', $author_email);
  }
  public function info($key = null, $value = null) {
    if ($key == null) {
      return $this->info;
    }
    $this->info[$key] = $value;
  }
  public function modules($modules_list) {
    $modules = self::list_to_array($modules_list);
    $this->modules = array_merge($this->modules, $modules);
  }

  // Actions
  private function action($tag, $data) {
    $this->actions[] = array_merge($data, array(
      'tag' => $tag,
    ));
  }
  public function variable($name, $value) {
    $this
      ->action('variable', array(
      'name' => $name,
      'value' => $value,
    ));
  }
  public function view($name, $description, $tag, $base = "node") {
    $view = new PatternView($name, $description, $tag, $base);
    $this
      ->action('view', array(
      'patterns_object' => $view,
    ));
    return $view;
  }

  // Utility
  public function export() {
    foreach ($this->actions as &$action) {
      if (array_key_exists('patterns_object', $action)) {
        $data = $action['patterns_object']
          ->export();

        // TODO: export shouldn't be destructive
        unset($action['patterns_object']);
        $action = array_merge($action, $data);
      }
    }
    return array(
      'info' => $this->info,
      'modules' => $this->modules,
      'actions' => $this->actions,
    );
  }
  private static function list_to_array($list) {
    return explode(",", preg_replace("/[,\\s]+/", ",", $list));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Pattern::$actions private property
Pattern::$info private property
Pattern::$modules private property
Pattern::action private function
Pattern::export public function
Pattern::info public function
Pattern::list_to_array private static function
Pattern::modules public function
Pattern::variable public function
Pattern::view public function
Pattern::__construct function