Skip to content

Commit

Permalink
chore: upgrade to laravel 5.8 and release to version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bl4ckbon3 committed Mar 6, 2019
1 parent e3fccac commit 9fe14ba
Show file tree
Hide file tree
Showing 15 changed files with 2,029 additions and 712 deletions.
File renamed without changes.
33 changes: 33 additions & 0 deletions app/acme/Api/Presenter/PingPresenter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);

namespace Acme\Api\Presenter;

use Illuminate\Contracts\Support\Responsable;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
use Pandawa\Component\Presenter\NameablePresenterInterface;
use Pandawa\Component\Presenter\NameablePresenterTrait;
use Pandawa\Component\Presenter\PresenterInterface;
use Pandawa\Module\Api\Http\Controller\InteractsWithRendererTrait;

/**
* @author Iqbal Maulana <iq.bluejack@gmail.com>
*/
final class PingPresenter implements PresenterInterface, NameablePresenterInterface
{
use NameablePresenterTrait;
use InteractsWithRendererTrait {
InteractsWithRendererTrait::render as response;
}

/**
* @param Request $request
*
* @return View|Responsable
*/
public function render(Request $request)
{
return $this->response($request, ['status' => 'pong']);
}
}
5 changes: 5 additions & 0 deletions app/acme/Api/Resources/routes/routes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ping:
type: presenter
methods: [get]
path: ping
presenter: ping
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

use Pandawa\Component\Module\AbstractModule;
use Pandawa\Component\Module\Provider\RouteProviderTrait;
use Pandawa\Component\Module\Provider\ViewProviderTrait;

/**
* @author Iqbal Maulana <iq.bluejack@gmail.com>
*/
final class AcmeWebModule extends AbstractModule
{
use RouteProviderTrait;
use RouteProviderTrait, ViewProviderTrait;

protected function routes(): array
{
Expand Down
29 changes: 29 additions & 0 deletions app/acme/Web/Presenter/LandingPresenter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);

namespace Acme\Web\Presenter;

use Illuminate\Contracts\Support\Responsable;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
use Pandawa\Component\Presenter\NameablePresenterInterface;
use Pandawa\Component\Presenter\NameablePresenterTrait;
use Pandawa\Component\Presenter\PresenterInterface;

/**
* @author Iqbal Maulana <iq.bluejack@gmail.com>
*/
final class LandingPresenter implements PresenterInterface, NameablePresenterInterface
{
use NameablePresenterTrait;

/**
* @param Request $request
*
* @return View|Responsable
*/
public function render(Request $request)
{
return view('acme-web::pages.landing');
}
}
5 changes: 5 additions & 0 deletions app/acme/Web/Resources/routes/routes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
homepage:
type: presenter
methods: [get]
path: /
presenter: landing
87 changes: 87 additions & 0 deletions app/acme/Web/Resources/views/pages/landing.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>Pandawa</title>

<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">

<!-- Styles -->
<style>
html, body {
background-color: #fff;
color: #636b6f;
font-family: 'Raleway', sans-serif;
font-weight: 100;
height: 100vh;
margin: 0;
}
.full-height {
height: 100vh;
}
.flex-center {
align-items: center;
display: flex;
justify-content: center;
}
.position-ref {
position: relative;
}
.top-right {
position: absolute;
right: 10px;
top: 18px;
}
.content {
text-align: center;
}
.title {
font-size: 84px;
}
.links > a {
color: #636b6f;
padding: 0 25px;
font-size: 12px;
font-weight: 600;
letter-spacing: .1rem;
text-decoration: none;
text-transform: uppercase;
}
.m-b-md {
margin-bottom: 30px;
}
</style>
</head>
<body>
<div class="flex-center position-ref full-height">
@if (Route::has('login'))
<div class="top-right links">
@auth
<a href="{{ url('/home') }}">Home</a>
@else
<a href="{{ route('login') }}">Login</a>
<a href="{{ route('register') }}">Register</a>
@endauth
</div>
@endif

<div class="content">
<div class="title m-b-md">
Pandawa
</div>
</div>
</div>
</body>
</html>
21 changes: 0 additions & 21 deletions app/api/Acme/Http/Controller/PingController.php

This file was deleted.

4 changes: 0 additions & 4 deletions app/api/Acme/Resources/routes/routes.yaml

This file was deleted.

69 changes: 65 additions & 4 deletions app/laravel/Http/Middleware/Authorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,88 @@
namespace App\Http\Middleware;

use Illuminate\Auth\Middleware\Authorize as LaravelAuthorize;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Http\Request;
use Illuminate\Contracts\Auth\Factory as Auth;
use Illuminate\Contracts\Auth\Access\Gate;
use Pandawa\Component\Message\MessageRegistryInterface;
use Pandawa\Component\Resource\ResourceRegistryInterface;
use RuntimeException;

/**
* @author Iqbal Maulana <iq.bluejack@gmail.com>
*/
class Authorize extends LaravelAuthorize
{
use DispatchesJobs;

/**
* @var ResourceRegistryInterface
*/
private $registry;

/**
* @var null|MessageRegistryInterface
*/
private $messageRegistry;

/**
* Constructor.
*
* @param Auth $auth
* @param Gate $gate
* @param ResourceRegistryInterface $registry
* @param MessageRegistryInterface|null $messageRegistry
*/
public function __construct(Auth $auth, Gate $gate, ResourceRegistryInterface $registry, MessageRegistryInterface $messageRegistry = null)
{
parent::__construct($auth, $gate);
$this->registry = $registry;
$this->auth = $auth;
$this->messageRegistry = $messageRegistry;
}

protected function getModel($request, $model)
{
return $this->isClassName($model) ? $model : $this->getRouteModel($request, $model);
}

private function getRouteModel(Request $request, string $model)
{
$bindings = $request->route('bindings') ? $request->route('bindings') : [];
$bindings = collect($bindings);
$route = $request->route();

if (null !== $this->messageRegistry
&& null !== $options = array_get($route->defaults, sprintf('bindings.%s', $model))) {

$message = $this->getMessageClass(array_get($options, 'message'));
$arguments = array_only(
array_merge($request->all(), $route->parameters()),
array_get($options, 'arguments', [])
);

if ($bindings->has($model)) {
return $bindings->get($model)::{'findOrFail'}($request->route($model));
return $this->dispatch(new $message($arguments));
}

if ($this->registry->has($model)) {
$modelClass = $this->registry->get($model)->getModelClass();

return $modelClass::{'findOrFail'}($request->route($model));
}

return $request->route($model);
}

/**
* @param string $message
*
* @return string
*/
private function getMessageClass(string $message): string
{
if (!$this->messageRegistry->has($message)) {
throw new RuntimeException(sprintf('Message "%s" not found.', $message));
}

return $this->messageRegistry->get($message)->getMessageClass();
}
}
17 changes: 0 additions & 17 deletions app/web/Acme/Http/Controller/HomeController.php

This file was deleted.

4 changes: 0 additions & 4 deletions app/web/Acme/Resources/routes/routes.yaml

This file was deleted.

11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"license": "MIT",
"type": "project",
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=7.2",
"fideloper/proxy": "~4.0",
"laravel/framework": "5.6.*",
"laravel/tinker": "~1.0",
"pandawa/pandawa": "~0.1"
"pandawa/pandawa": "^1.0"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^2.4",
Expand All @@ -27,8 +27,8 @@
],
"psr-4": {
"App\\": "app/laravel",
"Acme\\Api\\": "app/api/Acme",
"Acme\\Web\\": "app/web/Acme",
"Acme\\Api\\": "app/acme/Api",
"Acme\\Web\\": "app/acme/Web",
"": "src/"
}
},
Expand All @@ -38,6 +38,9 @@
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
},
"laravel": {
"dont-discover": [
]
Expand Down
Loading

0 comments on commit 9fe14ba

Please sign in to comment.