Subversion Repositories Applications.gtt

Rev

Rev 60 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
60 jpm 1
<?php
2
/*
3
 * This work is hereby released into the Public Domain.
4
 * To view a copy of the public domain dedication,
5
 * visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
6
 * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
7
 *
8
 */
9
 
10
require_once dirname(__FILE__)."/Graph.class.php";
11
 
12
/**
13
 * All patterns must derivate from this class
14
 *
15
 * @package Artichow
16
 */
17
abstract class awPattern {
18
 
19
	/**
20
	 * Pattern arguments
21
	 *
22
	 * @var array
23
	 */
24
	protected $args = array();
25
 
26
	/**
27
	 * Load a pattern
28
	 *
29
	 * @param string $pattern Pattern name
30
	 * @return Component
31
	 */
32
	public static function get($pattern) {
33
 
34
		$file = ARTICHOW_PATTERN.DIRECTORY_SEPARATOR.$pattern.'.php';
35
 
36
		if(is_file($file)) {
37
 
38
			require_once $file;
39
 
40
			$class = $pattern.'Pattern';
41
 
42
			if(class_exists($class)) {
43
				return new $class;
44
			} else {
45
				awImage::drawError("Class Pattern: Class '".$class."' does not exist.");
46
			}
47
 
48
		} else {
49
			awImage::drawError("Class Pattern: Pattern '".$pattern."' does not exist.");
50
		}
51
 
52
	}
53
 
54
	/**
55
	 * Change pattern argument
56
	 *
57
	 * @param string $name Argument name
58
	 * @param mixed $value Argument value
59
	 */
60
	public function setArg($name, $value) {
61
		if(is_string($name)) {
62
			$this->args[$name] = $value;
63
		}
64
	}
65
 
66
	/**
67
	 * Get an argument
68
	 *
69
	 * @param string $name
70
	 * @param mixed $default Default value if the argument does not exist (default to NULL)
71
	 * @return mixed Argument value
72
	 */
73
	protected function getArg($name, $default = NULL) {
74
		if(array_key_exists($name, $this->args)) {
75
			return $this->args[$name];
76
		} else {
77
			return $default;
78
		}
79
	}
80
 
81
	/**
82
	 * Change several arguments
83
	 *
84
	 * @param array $args New arguments
85
	 */
86
	public function setArgs($args) {
87
		if(is_array($args)) {
88
			foreach($args as $name => $value) {
89
				$this->setArg($name, $value);
90
			}
91
		}
92
	}
93
 
94
}
95
 
96
registerClass('Pattern', TRUE);
97
?>