Add namespace.
This commit is contained in:
55
View/Helpers/GetViewHelper.php
Normal file
55
View/Helpers/GetViewHelper.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php namespace Majestic\View\Helpers;
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage View
|
||||
* @since 2010-03-09
|
||||
*/
|
||||
|
||||
class GetViewHelper 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 = \Majestic\Env\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 . ']=' . urlencode($val);
|
||||
}
|
||||
$result = implode('&', $result);
|
||||
} else {
|
||||
$result = $name . '=' . urlencode($value);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user