davidantonyan1981
Новичок
class Request
{
private $request_url;
private $segments = array();
private $controller;
private $action;
private $args;
public function __construct()
{
$this->request_url = $_SERVER['REQUEST_URI'];
$this->request_url = parse_url($this->request_url, PHP_URL_PATH);
}
public function getRequest()
{
return $this->request_url;
}
public function getSegments()
{
if(!empty($this->request_url))
{
$this->segments = ($this->request_url === '/') ? 'home' : $this->request_url;
$this->segments = explode('/', trim($this->segments,'/'));
}
return $this->segments;
}
public function getController()
{
if(isset($this->segments[0]))
{
$this->controller = $this->segments[0];
}
return $this->controller;
}
public function getAction()
{
$this->action = (!isset($this->segments[1])) ? 'index' : $this->segments[1];
return $this->action;
}
public function getArgs()
{
$this->args = (count($this->segments) >2) ? array_slice($this->segments,2) : null;
return $this->args;
}
}
{
private $request_url;
private $segments = array();
private $controller;
private $action;
private $args;
public function __construct()
{
$this->request_url = $_SERVER['REQUEST_URI'];
$this->request_url = parse_url($this->request_url, PHP_URL_PATH);
}
public function getRequest()
{
return $this->request_url;
}
public function getSegments()
{
if(!empty($this->request_url))
{
$this->segments = ($this->request_url === '/') ? 'home' : $this->request_url;
$this->segments = explode('/', trim($this->segments,'/'));
}
return $this->segments;
}
public function getController()
{
if(isset($this->segments[0]))
{
$this->controller = $this->segments[0];
}
return $this->controller;
}
public function getAction()
{
$this->action = (!isset($this->segments[1])) ? 'index' : $this->segments[1];
return $this->action;
}
public function getArgs()
{
$this->args = (count($this->segments) >2) ? array_slice($this->segments,2) : null;
return $this->args;
}
}