<repo_name>zuniphp/uri<file_sep>/README.md
# uri
Zuni Uri
<file_sep>/src/Zuni/Uri/ControllerToNamespaces.php
<?php 

/*
 * @package     ZuniPHP
 * @author      <NAME> <<EMAIL>>
 * @link        http://zuniphp.github.io
 * @copyright   2016
 * 
 */



namespace Zuni\Uri;


use Zuni\Contract\Uri\GetSegment as IGetSegment;
use Zuni\Contract\GetArr as IGetArr;
use Zuni\Filter\Preserve\AlnumUnderscoreHyphen;
use Zuni\Uri;


class ControllerToNamespaces implements IGetSegment
{

    private $controller;


    public function __construct()
    {
        self::_prepare();
    }

    public function getSegment()
    {
        return $this->controller;
    } 

    private function _prepare()
    {

        $position = new Uri\Position(0);
        $controller = $position->getSegment();

        $this->controller = self::_getCapitalize($controller);

        return $this;


    } 


    private function _getCapitalize($controller)
    {

        $explodeFile = explode('_', $controller);

        $prepareFile = array();

        foreach ($explodeFile as $f)
        {
            $prepareFile[] = ucfirst($f);
        }

        $controller = implode('\\', $prepareFile);

        return $controller;


    } 




}


<file_sep>/src/Zuni/Uri/Factory/Spt.php
<?php 

namespace Zuni\Uri\Factory;

use Zuni\Contract\Create;
use Zuni\Uri\Full as UriFull;
use Zuni\Uri\Spt as UriSpt;

class Spt implements Create
{
    public static function create()
    {
        return new UriSpt(new UriFull());
    } 
    
}    


<file_sep>/src/Zuni/Uri/Full.php
<?php 

/*
 * @package     ZuniPHP
 * @author      <NAME> <<EMAIL>>
 * @link        http://zuniphp.github.io
 * @copyright   2016
 * 
 */



namespace Zuni\Uri;


use Zuni\Contract\Uri\GetSegment as IGetSegment;



class Full implements IGetSegment
{

    private $_param = 'uri';
    

    public function getSegment()
    {
        return self::_getUri();
    } 


    private function _isUri()
    {
       return (array_key_exists($this->_param, $_GET));
    } 

    private function _getUri()
    {
        if(!self::_isUri())
        {
            return NULL;
        }

            return $_GET[$this->_param];

    } 
    
    
    

}    


<file_sep>/src/Zuni/Uri/Position.php
<?php 

/*
 * @package     ZuniPHP
 * @author      <NAME> <<EMAIL>>
 * @link        http://zuniphp.github.io
 * @copyright   2016
 * 
 */



namespace Zuni\Uri;

use Zuni\Contract\Uri\GetSegment as IGetSegment;
use Zuni\Contract\GetArr as IGetArr;
use Zuni\Filter\Preserve\AlnumUnderscoreHyphen;
use Zuni\Uri;

class Position implements IGetSegment
{

    private $num;
    private $filter;
    private $explode;


    public function __construct($num)
    {

        if(!is_int($num))
        {
            throw new \Exception("'argument requires number'\n");
        }

        $this->num     = $num;
        $this->filter  = new AlnumUnderscoreHyphen();
        $this->explode = new Uri\Spt(new Uri\Full());

    }



    public function getSegment()
    { 

        $e         = $this->explode->getArr();
        $a         = array_merge($e, array('index'));
        $isAction  = (array_key_exists(1, $e));

        $e = ($isAction)? $e: $a;

        if(!array_key_exists($this->num, $e))
        {
            return NULL;
        }

        $search    = array('-');
        $segment   = $this->filter->filter($e[$this->num]);

        return str_replace( $search, '_', $segment);

    } 

}


<file_sep>/src/Zuni/Uri/Spt.php
<?php 

/*
 * @package     ZuniPHP
 * @author      <NAME> <<EMAIL>>
 * @link        http://zuniphp.github.io
 * @copyright   2016
 * 
 */



namespace Zuni\Uri;


use Zuni\Contract\GetArr as IGetArr;
use Zuni\Contract\Uri\GetSegment as IGetSegment;
use Zuni\Registry\Container;

class Spt implements IGetArr
{


    private $uri;


    public function __construct(IGetSegment $uri)
    {
        $this->uri = $uri; 
    }

    public function getArr()
    {

        if(!$this->uri->getSegment())
        {
            $container = Container::getInstance();
            $index = strtolower($container->get('startController'));

            return array( $index, 'index');
        }

        return explode('/', rtrim($this->uri->getSegment(), '/'));

    } 





}    


