From 126e0b72cc3d49947f3e7b3660d1fc840452cbd8 Mon Sep 17 00:00:00 2001 From: woxxy Date: Wed, 26 Dec 2012 01:03:05 +0100 Subject: [PATCH] Fixes from real use cases --- classes/Foolz/Theme/Builder.php | 18 +++++ classes/Foolz/Theme/ParamManager.php | 4 +- classes/Foolz/Theme/Props.php | 114 +++++++++++++++++++++++++++ classes/Foolz/Theme/View.php | 12 ++- 4 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 classes/Foolz/Theme/Props.php diff --git a/classes/Foolz/Theme/Builder.php b/classes/Foolz/Theme/Builder.php index 2fce728..7ef3b4c 100644 --- a/classes/Foolz/Theme/Builder.php +++ b/classes/Foolz/Theme/Builder.php @@ -32,6 +32,13 @@ class Builder */ protected $param_manager; + /** + * Instance of a props object + * + * @var \Foolz\Theme\Props + */ + protected $props = null; + /** * We need at least a theme * @@ -41,6 +48,7 @@ public function __construct(\Foolz\Theme\Theme $theme) { $this->theme = $theme; $this->param_manager = new ParamManager(); + $this->props = new Props(); } /** @@ -63,6 +71,16 @@ public function getParamManager() return $this->param_manager; } + /** + * Returns the props object to manage title, meta etc. + * + * @return \Foolz\Theme\Props The props object + */ + public function getProps() + { + return $this->props; + } + /** * Set a layout that is going to wrap all the partials * diff --git a/classes/Foolz/Theme/ParamManager.php b/classes/Foolz/Theme/ParamManager.php index b74fb2d..b7bdb0f 100644 --- a/classes/Foolz/Theme/ParamManager.php +++ b/classes/Foolz/Theme/ParamManager.php @@ -42,7 +42,7 @@ public function getParams() */ public function getParam($key) { - if ( ! isset($this->params[$key])) + if ( ! array_key_exists($key, $this->params)) { throw new \OutOfBoundsException('Undefined parameter.'); } @@ -77,7 +77,7 @@ public function setParams($array) { $this->params[$key] = $item; } - + return $this; } } \ No newline at end of file diff --git a/classes/Foolz/Theme/Props.php b/classes/Foolz/Theme/Props.php new file mode 100644 index 0000000..9eb1dac --- /dev/null +++ b/classes/Foolz/Theme/Props.php @@ -0,0 +1,114 @@ +. The content of the internal array are tag => value + * + * @var array + */ + /* + protected $meta_tags = [ + ['charset' => 'utf8'], + ]; + + public function getHeader() + { + $string = "" + ."\n" + ." \n" + ." \n"; + + foreach ($this->meta_tags as $meta) + { + $string .= " $value) + { + $string .= ' '.$tag.'="'.htmlspecialchars($value).'"'; + } + $string .= ">\n"; + } + + $string .= " ".htmlspecialchars($this->getTitle()).""; + + foreach () + + return $string; + } + + public function getFooter() + { + + } + */ + + /** + * Set the entire array of the title. Empties the title if no parameter is given + * + * @param array $title The array of elements of which the title is composed + * + * @return \Foolz\Theme\Props The current object + */ + public function setTitle(array $title = []) + { + $this->title = $title; + + return $this; + } + + /** + * Adds an element to the title + * + * @param string $title The element to add to the title + * + * @return \Foolz\Theme\Props The current object + */ + public function addTitle($title) + { + $this->title[] = $title; + + return $this; + } + + /** + * Sets a string to use as separator between the elements of the title. It must contain eventual spaces around it + * + * @param string $separator The separator string + * + * @return \Foolz\Theme\Props The current object + */ + public function setTitleSeparator($separator) + { + $this->title_separator = $separator; + + return $this; + } + + /** + * Returns the compiled title, NOT ESCAPED + * + * @return string The compiled title + */ + public function getTitle() + { + return implode($this->title_separator, $this->title); + } + + +} diff --git a/classes/Foolz/Theme/View.php b/classes/Foolz/Theme/View.php index 3e594f6..a2d27cb 100644 --- a/classes/Foolz/Theme/View.php +++ b/classes/Foolz/Theme/View.php @@ -11,6 +11,13 @@ class View */ protected $builder; + /** + * Instance of a props object + * + * @var \Foolz\Theme\Props + */ + protected $props = null; + /** * The type of view, if partial or layout * @@ -43,6 +50,7 @@ public static function forge(\Foolz\Theme\Builder $builder, $type, $view) { // get the View object in case it can be found $class = $builder->getTheme()->getNamespace().'\\'. ucfirst($type).'\\'.Util::lowercaseToClassName($view); + if (class_exists($class)) { $new = new $class(); @@ -173,7 +181,9 @@ public function build() */ public function doBuild() { - $this->built = $this->toString(); + ob_start(); + $this->toString(); + $this->built = ob_get_clean(); return $this; }