-
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 #13 from benrowe/releases/build-3
Releases/build 3
- Loading branch information
Showing
16 changed files
with
1,869 additions
and
35 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace App\Exceptions; | ||
|
||
use Exception; | ||
|
||
class HttpException extends Exception | ||
{ | ||
} |
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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use RuntimeException; | ||
|
||
/** | ||
* Class AbstractController | ||
* | ||
* @package App\Http\Controllers | ||
*/ | ||
abstract class AbstractController | ||
{ | ||
private $request; | ||
private $response; | ||
|
||
/** | ||
* AbstractController constructor. | ||
* | ||
* @param ServerRequestInterface $request | ||
* @param ResponseInterface $response | ||
*/ | ||
public function __construct(ServerRequestInterface $request, ResponseInterface $response) | ||
{ | ||
$this->request = $request; | ||
$this->response = $response; | ||
} | ||
|
||
/** | ||
* Get the request (get/post) param from the request handler | ||
* | ||
* @param string $key | ||
* @param mixed $default | ||
* @return mixed | ||
*/ | ||
protected function getRequestParam($key, $default = null) | ||
{ | ||
$params = $this->request->getQueryParams(); | ||
if (array_key_exists($key, $params)) { | ||
return $params[$key]; | ||
} | ||
|
||
return $default; | ||
} | ||
|
||
/** | ||
* Verify the existence of a request param | ||
* | ||
* @param string $key | ||
* @return bool | ||
*/ | ||
protected function hasRequestParam($key) | ||
{ | ||
$params = $this->request->getQueryParams(); | ||
|
||
return array_key_exists($key, $params); | ||
} | ||
|
||
/** | ||
* Allow a controllers actions to be called statically be invoking a new instance of the controller | ||
* | ||
* @param string $method | ||
* @param array $params | ||
* @return string|array|ResponseInterface | ||
*/ | ||
public static function __callStatic($method, $params) | ||
{ | ||
$methodName = 'action'.ucfirst($method); | ||
|
||
if (method_exists(static::class, $methodName)) { | ||
$callback = [new static(array_shift($params), array_shift($params)), $methodName]; | ||
|
||
return call_user_func_array($callback, $params[0] ?: []); | ||
} | ||
throw new RuntimeException(sprintf("Unknown static method %s::%s()", static::class, $method)); | ||
} | ||
|
||
/** | ||
* Load the requested view add write it to the body | ||
* | ||
* @param string $path | ||
* @param array $params | ||
* @return \Psr\Http\Message\StreamInterface | ||
*/ | ||
protected function view($path, array $params = []) | ||
{ | ||
$view = \App\app()->get('view')->view(); | ||
$rendered = $view->make($path, $params)->render(); | ||
$this->response->getBody()->write($rendered); | ||
return $this->response; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
/** | ||
* Class DefaultController | ||
* | ||
* @package App\Http\Controllers | ||
*/ | ||
class DefaultController extends AbstractController | ||
{ | ||
/** | ||
* Load the application homepage | ||
*/ | ||
public function actionIndex() | ||
{ | ||
|
||
} | ||
} |
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 |
---|---|---|
@@ -1,12 +1,9 @@ | ||
<?php | ||
|
||
use App\Http\Controllers\ArtistController; | ||
use App\Http\Controllers\DefaultController; | ||
|
||
/** | ||
* @var \League\Route\RouteCollection $routes | ||
* @var \League\Route\RouteCollection $route | ||
*/ | ||
$route->addRoute('GET', '/', function() { | ||
return 'asdf'; | ||
}); | ||
|
||
$route->addRoute('GET', '/ajax', function() { | ||
return ['foo' => 'bar']; | ||
}); | ||
$route->addRoute('GET', '/', DefaultController::class.'::index'); |
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
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
Oops, something went wrong.