@@ -58,6 +58,9 @@ |
||
| 58 | 58 | protected $pattern = ""; |
| 59 | 59 | protected $callable; |
| 60 | 60 | |
| 61 | + /** |
|
| 62 | + * @param string $pattern |
|
| 63 | + */ |
|
| 61 | 64 | public function __construct($pattern, $callable) { |
| 62 | 65 | $this->setPattern($pattern); |
| 63 | 66 | $this->setCallable($callable); |
@@ -89,14 +89,14 @@ |
||
| 89 | 89 | <body> |
| 90 | 90 | <h1>Tight Framework Exception</h1> |
| 91 | 91 | EXC; |
| 92 | - $output .= "<p><strong>" . get_class($ex) . ": </strong>" . $ex->getMessage() . "</p>"; |
|
| 93 | - $output .= "<p class='padding-left'>in <strong>" . $lastTrace['file'] . "</strong> at line <strong>" . $lastTrace['line'] . "</strong></p>"; |
|
| 92 | + $output .= "<p><strong>".get_class($ex).": </strong>".$ex->getMessage()."</p>"; |
|
| 93 | + $output .= "<p class='padding-left'>in <strong>".$lastTrace['file']."</strong> at line <strong>".$lastTrace['line']."</strong></p>"; |
|
| 94 | 94 | $output .= "<br/>"; |
| 95 | 95 | $output .= "<p>Stack Trace:</p>"; |
| 96 | 96 | $trace = $ex->getTrace(); |
| 97 | 97 | for ($index = 0; $index < count($trace); $index++) { |
| 98 | 98 | $el = $trace[$index]; |
| 99 | - $output .= "<p>#" . ($index + 1) . ": " . $el['class'] . $el['type'] . $el['function'] . "() at <strong>" . $el['file'] . "</strong> at line <strong>" . $el['line'] . "</strong></p>"; |
|
| 99 | + $output .= "<p>#".($index + 1).": ".$el['class'].$el['type'].$el['function']."() at <strong>".$el['file']."</strong> at line <strong>".$el['line']."</strong></p>"; |
|
| 100 | 100 | } |
| 101 | 101 | echo $output; |
| 102 | 102 | } |
@@ -48,10 +48,12 @@ |
||
| 48 | 48 | */ |
| 49 | 49 | public function __construct($config = []) { |
| 50 | 50 | set_exception_handler([$this, "exceptionHandler"]); |
| 51 | - if (is_array($config)) |
|
| 52 | - $config = new \Tight\TightConfig($config); |
|
| 53 | - if (!$config instanceof \Tight\TightConfig) |
|
| 54 | - throw new \InvalidArgumentException("Argument passed to Tight::__constructor must be array or <b>\Tight\TightConfig</b> object"); |
|
| 51 | + if (is_array($config)) { |
|
| 52 | + $config = new \Tight\TightConfig($config); |
|
| 53 | + } |
|
| 54 | + if (!$config instanceof \Tight\TightConfig) { |
|
| 55 | + throw new \InvalidArgumentException("Argument passed to Tight::__constructor must be array or <b>\Tight\TightConfig</b> object"); |
|
| 56 | + } |
|
| 55 | 57 | $this->config = $config; |
| 56 | 58 | $this->router = new Router($config->basePath); |
| 57 | 59 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | // Get the substring after $substrToRemove |
| 54 | 54 | $post = substr($string, $lastIndex); |
| 55 | 55 | // Return $pre and $post |
| 56 | - return $pre . $post; |
|
| 56 | + return $pre.$post; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | public static function addTrailingSlash($path) { |
| 78 | 78 | if (null !== $path && is_string($path) && !empty($path)) { |
| 79 | 79 | if (substr($path, -1) !== "/") { |
| 80 | - $path .="/"; |
|
| 80 | + $path .= "/"; |
|
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | return $path; |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * @return string |
| 102 | 102 | */ |
| 103 | 103 | public static function removeDouble($string, $substring) { |
| 104 | - return str_replace($substring . $substring, $substring, $string); |
|
| 104 | + return str_replace($substring.$substring, $substring, $string); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | } |
@@ -33,18 +33,18 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class TightConfig |
| 35 | 35 | { |
| 36 | - private $config=[ |
|
| 36 | + private $config = [ |
|
| 37 | 37 | "basePath"=>null, |
| 38 | 38 | |
| 39 | 39 | ]; |
| 40 | 40 | |
| 41 | - public function __construct(array $config = []){ |
|
| 41 | + public function __construct(array $config = []) { |
|
| 42 | 42 | foreach ($config as $key => $value) { |
| 43 | 43 | $this->$key = $value; |
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | public function __get($name) { |
| 47 | - if(isset($this->config[$name])) |
|
| 47 | + if (isset($this->config[$name])) |
|
| 48 | 48 | return $this->config[$name]; |
| 49 | 49 | else |
| 50 | 50 | return null; |
@@ -44,10 +44,11 @@ |
||
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | public function __get($name) { |
| 47 | - if(isset($this->config[$name])) |
|
| 48 | - return $this->config[$name]; |
|
| 49 | - else |
|
| 50 | - return null; |
|
| 47 | + if(isset($this->config[$name])) { |
|
| 48 | + return $this->config[$name]; |
|
| 49 | + } else { |
|
| 50 | + return null; |
|
| 51 | + } |
|
| 51 | 52 | } |
| 52 | 53 | public function __set($name, $value) { |
| 53 | 54 | $this->config[$name] = $value; |
@@ -87,7 +87,7 @@ |
||
| 87 | 87 | } |
| 88 | 88 | $pattern = array_shift($args); // 2nd-> Pattern |
| 89 | 89 | $callable = array_pop($args); // Last -> callable |
| 90 | - $route = new Route(Utils::removeDouble($this->basePath . $pattern, "/"), $callable); |
|
| 90 | + $route = new Route(Utils::removeDouble($this->basePath.$pattern, "/"), $callable); |
|
| 91 | 91 | $route->setHttpMethods($methods); |
| 92 | 92 | if (count($args) > 0) { |
| 93 | 93 | $route->setMiddleware($args); |
@@ -72,25 +72,25 @@ |
||
| 72 | 72 | */ |
| 73 | 73 | public function testUtilsAddTrailingSlash() { |
| 74 | 74 | $path = "/etc/php5"; |
| 75 | - $this->assertEquals("/etc/php5/",Utils::addTrailingSlash($path)); |
|
| 76 | - $this->assertEquals("/etc/php5/",Utils::addTrailingSlash($path."/")); |
|
| 75 | + $this->assertEquals("/etc/php5/", Utils::addTrailingSlash($path)); |
|
| 76 | + $this->assertEquals("/etc/php5/", Utils::addTrailingSlash($path."/")); |
|
| 77 | 77 | } |
| 78 | 78 | /** |
| 79 | 79 | * @test |
| 80 | 80 | */ |
| 81 | - public function testUtilsFilterPath(){ |
|
| 81 | + public function testUtilsFilterPath() { |
|
| 82 | 82 | $pathWin = "C:\\php\\ext"; |
| 83 | 83 | $pathUnx = "/var/htdocs"; |
| 84 | - $this->assertEquals("C:/php/ext/",Utils::filterPath($pathWin)); |
|
| 85 | - $this->assertEquals("/var/htdocs/",Utils::filterPath($pathUnx)); |
|
| 86 | - $this->assertEquals("/var/htdocs/",Utils::filterPath($pathUnx."/")); |
|
| 84 | + $this->assertEquals("C:/php/ext/", Utils::filterPath($pathWin)); |
|
| 85 | + $this->assertEquals("/var/htdocs/", Utils::filterPath($pathUnx)); |
|
| 86 | + $this->assertEquals("/var/htdocs/", Utils::filterPath($pathUnx."/")); |
|
| 87 | 87 | } |
| 88 | 88 | /** |
| 89 | 89 | * @test |
| 90 | 90 | */ |
| 91 | - public function testUtilsRemoveDouble(){ |
|
| 92 | - $this->assertEquals("String",Utils::removeDouble("Stringg", "g")); |
|
| 93 | - $this->assertEquals("/etc/php",Utils::removeDouble("/etc//php", "/")); |
|
| 94 | - $this->assertEquals("Testing",Utils::removeDouble("Testing", "u")); |
|
| 91 | + public function testUtilsRemoveDouble() { |
|
| 92 | + $this->assertEquals("String", Utils::removeDouble("Stringg", "g")); |
|
| 93 | + $this->assertEquals("/etc/php", Utils::removeDouble("/etc//php", "/")); |
|
| 94 | + $this->assertEquals("Testing", Utils::removeDouble("Testing", "u")); |
|
| 95 | 95 | } |
| 96 | 96 | } |