mirror of
				https://github.com/kevinveenbirkenbach/coding-challenge-online-shop.git
				synced 2025-11-03 18:47:57 +00:00 
			
		
		
		
	Implemented Navigation
This commit is contained in:
		@@ -1,52 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace router;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A link containes out of get parameters
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 *        
 | 
			
		||||
 */
 | 
			
		||||
final class Link
 | 
			
		||||
{
 | 
			
		||||
    /** 
 | 
			
		||||
     * ArrayCollection would be nicer but I have to save time ;)
 | 
			
		||||
     * @var array
 | 
			
		||||
     */
 | 
			
		||||
    private $parameters;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 
 | 
			
		||||
     * @var string
 | 
			
		||||
     */
 | 
			
		||||
    private $name;
 | 
			
		||||
    
 | 
			
		||||
    public function __construct(array $parameters=[],string $name = ''){
 | 
			
		||||
        $this->setParameters($parameters);
 | 
			
		||||
        $this->setName($name);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public function setParameters(array $parameters):void{
 | 
			
		||||
        $this->parameters = $parameters;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public function setName(string $name):void{
 | 
			
		||||
        $this->name = $name;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public function getName():string{
 | 
			
		||||
        return $this->name;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public function getUrl():string{
 | 
			
		||||
        return "index.php".$this->getParameters(); 
 | 
			
		||||
    }
 | 
			
		||||
        
 | 
			
		||||
    private function getParameters():string{
 | 
			
		||||
        $parameters = '?';
 | 
			
		||||
        foreach ($this->parameters as $key=>$value){
 | 
			
		||||
            $parameters .= $key.'='.$value.'&';
 | 
			
		||||
        }
 | 
			
		||||
        return $parameters;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -14,7 +14,10 @@ use controller\order\Order;
 | 
			
		||||
 */
 | 
			
		||||
final class Router implements RouterInterface
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    const CONTROLLER='controller';
 | 
			
		||||
    
 | 
			
		||||
    const ACTION = 'action';
 | 
			
		||||
    
 | 
			
		||||
    /**
 | 
			
		||||
     *
 | 
			
		||||
     * @var CoreInterface
 | 
			
		||||
@@ -38,10 +41,10 @@ final class Router implements RouterInterface
 | 
			
		||||
    public function route()
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->get) {
 | 
			
		||||
            switch ($this->get['controller']) {
 | 
			
		||||
            switch ($this->get[self::CONTROLLER]) {
 | 
			
		||||
                case 'user':
 | 
			
		||||
                    $userController = new User();
 | 
			
		||||
                    switch ($this->get['action']) {
 | 
			
		||||
                    switch ($this->get[self::ACTION]) {
 | 
			
		||||
                        case 'login':
 | 
			
		||||
                            return $userController->login();
 | 
			
		||||
                        case 'logout':
 | 
			
		||||
@@ -51,13 +54,13 @@ final class Router implements RouterInterface
 | 
			
		||||
                    }
 | 
			
		||||
                case 'product':
 | 
			
		||||
                    $productController = new Product($this->core);
 | 
			
		||||
                    switch ($this->get['action']) {
 | 
			
		||||
                    switch ($this->get[self::ACTION]) {
 | 
			
		||||
                        case 'list':
 | 
			
		||||
                            return $productController->list(($this->get['color'])?$this->get['color']:null);
 | 
			
		||||
                    }
 | 
			
		||||
                case 'order':
 | 
			
		||||
                    $orderController = new Order($this->core);
 | 
			
		||||
                    switch ($this->get['action']){
 | 
			
		||||
                    switch ($this->get[self::ACTION]){
 | 
			
		||||
                        case 'store':
 | 
			
		||||
                            return $orderController->store();
 | 
			
		||||
                        case 'basket':
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace router;
 | 
			
		||||
namespace router\link;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A button containes out of a link and post parameters
 | 
			
		||||
							
								
								
									
										71
									
								
								src/router/link/Link.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								src/router/link/Link.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,71 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace router\link;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A link containes out of get parameters
 | 
			
		||||
 *
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 *        
 | 
			
		||||
 */
 | 
			
		||||
final class Link implements LinkInterface
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * ArrayCollection would be nicer but I have to save time ;)
 | 
			
		||||
     *
 | 
			
		||||
     * @var array
 | 
			
		||||
     */
 | 
			
		||||
    private $parameters;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     *
 | 
			
		||||
     * @var string
 | 
			
		||||
     */
 | 
			
		||||
    private $name;
 | 
			
		||||
 | 
			
		||||
    public function __construct(array $parameters = [], string $name = '')
 | 
			
		||||
    {
 | 
			
		||||
        $this->setParameters($parameters);
 | 
			
		||||
        $this->setName($name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function setParameters(array $parameters): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->parameters = $parameters;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function setName(string $name): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->name = $name;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getName(): string
 | 
			
		||||
    {
 | 
			
		||||
        return $this->name;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getUrl(): string
 | 
			
		||||
    {
 | 
			
		||||
        return "index.php" . $this->getParameters();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function getParameters(): string
 | 
			
		||||
    {
 | 
			
		||||
        $parameters = '?';
 | 
			
		||||
        foreach ($this->parameters as $key => $value) {
 | 
			
		||||
            $parameters .= $key . '=' . $value . '&';
 | 
			
		||||
        }
 | 
			
		||||
        return $parameters;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function isActive(): bool
 | 
			
		||||
    {
 | 
			
		||||
        foreach ($this->parameters as $key => $parameter) {
 | 
			
		||||
            if (! array_key_exists($key, $_GET) || (array_key_exists($key, $_GET) && $_GET[$key]!==$parameter)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										17
									
								
								src/router/link/LinkInterface.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/router/link/LinkInterface.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace router\link;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 *
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 *        
 | 
			
		||||
 */
 | 
			
		||||
interface LinkInterface
 | 
			
		||||
{
 | 
			
		||||
    public function getName():string;
 | 
			
		||||
    
 | 
			
		||||
    public function getUrl():string;
 | 
			
		||||
    
 | 
			
		||||
    public function isActive():bool;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user