-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from InitPHP/1.2.1
v1.2.1 Request ve Response nesnelerinin new instanceları argüman olarak kullanılabilir.
- Loading branch information
Showing
6 changed files
with
55 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,6 @@ | |
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "9.5", | ||
"initphp/http": "^1.0" | ||
"initphp/http": "^2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
* @author Muhammet ŞAFAK <[email protected]> | ||
* @copyright Copyright © 2022 Muhammet ŞAFAK | ||
* @license ./LICENSE MIT | ||
* @version 1.1.3 | ||
* @version 1.2.1 | ||
* @link https://www.muhammetsafak.com.tr | ||
*/ | ||
|
||
|
@@ -45,18 +45,21 @@ class Router | |
protected $cache_status = false; | ||
|
||
protected $configs = [ | ||
'paths' => [ | ||
'controller' => null, | ||
'middleware' => null, | ||
'paths' => [ | ||
'controller' => null, | ||
'middleware' => null, | ||
], | ||
'namespaces' => [ | ||
'controller' => null, | ||
'middleware' => null, | ||
'namespaces' => [ | ||
'controller' => null, | ||
'middleware' => null, | ||
], | ||
'base_path' => '/', | ||
'variable_method' => false, | ||
'base_path' => '/', | ||
'variable_method' => false, | ||
'argument_new_instance' => false, | ||
]; | ||
|
||
protected $argumentNewInstance = false; | ||
|
||
protected $patterns = [ | ||
'{[^/]+}' => '([^/]+)', | ||
':any[0-9]?' => '([^/]+)', | ||
|
@@ -134,6 +137,8 @@ public function __construct(RequestInterface $request, ResponseInterface $respon | |
unset($configs['cache']); | ||
} | ||
$this->configs = \array_merge($this->configs, $configs); | ||
$this->argumentNewInstance = $this->configs['argument_new_instance']; | ||
unset($this->configs['argument_new_instance']); | ||
$this->request = &$request; | ||
$this->response = &$response; | ||
$this->uri = new Uri($this->request->getUri()->__toString()); | ||
|
@@ -1016,13 +1021,15 @@ private function resolveParameters(\Reflector $reflector, array $parameters): ar | |
} | ||
continue; | ||
} | ||
if($class->isInstance($this->request)){ | ||
$arguments[] = $this->request; | ||
continue; | ||
} | ||
if($class->isInstance($this->response)){ | ||
$arguments[] = $this->response; | ||
continue; | ||
if (!$this->argumentNewInstance) { | ||
if($class->isInstance($this->request)){ | ||
$arguments[] = $this->request; | ||
continue; | ||
} | ||
if($class->isInstance($this->response)){ | ||
$arguments[] = $this->response; | ||
continue; | ||
} | ||
} | ||
if($class->isInstantiable()){ | ||
$arguments[] = $this->getClassContainer($class); | ||
|
@@ -1033,11 +1040,13 @@ private function resolveParameters(\Reflector $reflector, array $parameters): ar | |
|
||
private function getClassContainer(\ReflectionClass $class): object | ||
{ | ||
if($class->isInstance($this->request)){ | ||
return $this->request; | ||
} | ||
if($class->isInstance($this->response)){ | ||
return $this->response; | ||
if (!$this->argumentNewInstance) { | ||
if($class->isInstance($this->request)){ | ||
return $this->request; | ||
} | ||
if($class->isInstance($this->response)){ | ||
return $this->response; | ||
} | ||
} | ||
if(isset($this->container) && is_object($this->container)){ | ||
return $this->container->get($class->getName()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters