mirror of
				https://github.com/kevinveenbirkenbach/coding-challenge-online-shop.git
				synced 2025-11-03 18:47:57 +00:00 
			
		
		
		
	Optimized routing
This commit is contained in:
		@@ -35,7 +35,7 @@ final class Router implements RouterInterface
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @see \router\RouterInterface::route()
 | 
			
		||||
     */
 | 
			
		||||
    public function route(): void
 | 
			
		||||
    public function route()
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->get) {
 | 
			
		||||
            switch ($this->get['controller']) {
 | 
			
		||||
 
 | 
			
		||||
@@ -11,13 +11,7 @@ use core\CoreInterface;
 | 
			
		||||
interface RouterInterface
 | 
			
		||||
{
 | 
			
		||||
    public function setCore(CoreInterface $core):void;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Post parameters are used to save data
 | 
			
		||||
     * @param array $post
 | 
			
		||||
     */
 | 
			
		||||
    public function setPost(array $post): void;
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
    /**
 | 
			
		||||
     * Get Parameters are used to request Data
 | 
			
		||||
     * @param array $get
 | 
			
		||||
@@ -26,6 +20,7 @@ interface RouterInterface
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Opens the controller
 | 
			
		||||
     * @return mixed 
 | 
			
		||||
     */
 | 
			
		||||
    public function route():void;
 | 
			
		||||
    public function route();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										32
									
								
								src/router/Url.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								src/router/Url.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace router;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 *
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 *        
 | 
			
		||||
 */
 | 
			
		||||
class Url
 | 
			
		||||
{
 | 
			
		||||
    /** 
 | 
			
		||||
     * ArrayCollection would be nicer but I have to save time ;)
 | 
			
		||||
     * @var array
 | 
			
		||||
     */
 | 
			
		||||
    private $parameters;
 | 
			
		||||
 | 
			
		||||
    public function setParameters(array $parameters):void{
 | 
			
		||||
        $this->parameters = $parameters;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public function getUrl():string{
 | 
			
		||||
        return "index.php".$this->getParameters(); 
 | 
			
		||||
    }
 | 
			
		||||
        
 | 
			
		||||
    private function getParameters():string{
 | 
			
		||||
        $parameters = '?';
 | 
			
		||||
        foreach ($parameters as $key=>$value){
 | 
			
		||||
            $parameters .= $key.'='.$value.'&';
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user