Memcache, refactoring, View helpers, #16
git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@124 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
24
view/helpers/ViewHelper.php
Normal file
24
view/helpers/ViewHelper.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage View
|
||||
* @since 2010-03-09
|
||||
* @version SVN: $Id$
|
||||
* @filesource $URL$
|
||||
*/
|
||||
|
||||
abstract class ViewHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* @var PHPView
|
||||
*/
|
||||
protected $view = null;
|
||||
|
||||
public function __construct($view)
|
||||
{
|
||||
$this->view = $view;
|
||||
}
|
||||
}
|
57
view/helpers/ViewHelperGet.php
Normal file
57
view/helpers/ViewHelperGet.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage View
|
||||
* @since 2010-03-09
|
||||
* @version SVN: $Id$
|
||||
* @filesource $URL$
|
||||
*/
|
||||
|
||||
class ViewHelperGet extends ViewHelper
|
||||
{
|
||||
|
||||
protected $get;
|
||||
|
||||
public function get($replace)
|
||||
{
|
||||
$get = $this->getSanitizedRequest();
|
||||
if (!is_array($replace)) {
|
||||
$replace = array($replace);
|
||||
}
|
||||
foreach ($replace as $key => $value) {
|
||||
if (is_int($key)) {
|
||||
unset($get[$value]);
|
||||
} else {
|
||||
$get[$key] = $this->impl($key, $value);
|
||||
}
|
||||
}
|
||||
return '?' . $this->view->escape(implode('&', $get));
|
||||
}
|
||||
|
||||
protected function getSanitizedRequest()
|
||||
{
|
||||
if ($this->get === null) {
|
||||
$get = Env::Get();
|
||||
foreach ($get as $key => $value) {
|
||||
$this->get[$key] = $this->impl($key, $value);
|
||||
}
|
||||
}
|
||||
return $this->get;
|
||||
}
|
||||
|
||||
protected function impl($name, $value)
|
||||
{
|
||||
if (is_array($value)){
|
||||
$result = array();
|
||||
foreach ($value as $key => $val) {
|
||||
$result[] = $name . '[' . $key . ']=' . $val;
|
||||
}
|
||||
$result = implode('&', $result);
|
||||
} else {
|
||||
$result = $name . '=' . $value;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user