]> dev.renevier.net Git - syj.git/blob - application/views/helpers/HeadBase.php
version 0.1
[syj.git] / application / views / helpers / HeadBase.php
1 <?php
2 /*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
3     and is published under the AGPL license. */
4
5 class Syj_View_Helper_HeadBase extends Zend_View_Helper_Placeholder_Container_Standalone
6 {
7
8     /* base uri */
9     protected $href;
10
11     /* string to use as an indent of output */
12     protected $_indent = '';
13
14     public function headBase($href = null) {
15         $href = (string) $href;
16         if ($href == '') {
17             $serverUrl = rtrim($this->view->serverUrl(), '/');
18             $baseUrl = trim($this->view->baseUrl(), '/');
19             $href = $serverUrl . '/' . ($baseUrl ? ($baseUrl . '/'): '');
20         }
21         $this->href = $href;
22         return $this;
23     }
24
25     public function toString($indent = null) {
26         $indent = (null !== $indent)
27                 ? $this->getWhitespace($indent)
28                 : $this->getIndent();
29
30         return $indent . '<base href="' . $this->href . '">';
31     }
32
33     /* following part of the file is copied from Zend_View_Helper_Placeholder_Container_Abstract */
34
35     /**
36      * Retrieve whitespace representation of $indent
37      *
38      * @param  int|string $indent
39      * @return string
40      */
41     public function getWhitespace($indent)
42     {
43         if (is_int($indent)) {
44             $indent = str_repeat(' ', $indent);
45         }
46
47         return (string) $indent;
48     }
49
50     /**
51      * Set the indentation string for __toString() serialization,
52      * optionally, if a number is passed, it will be the number of spaces
53      *
54      * @param  string|int $indent
55      * @return Zend_View_Helper_Placeholder_Container_Abstract
56      */
57     public function setIndent($indent)
58     {
59         $this->_indent = $this->getWhitespace($indent);
60         return $this;
61     }
62
63     /**
64      * Retrieve indentation
65      *
66      * @return string
67      */
68     public function getIndent()
69     {
70         return $this->_indent;
71     }
72
73 }