Created
September 8, 2018 00:51
-
-
Save ojulianos/2d98abd96bb79392dd59ec1571865fcf to your computer and use it in GitHub Desktop.
app.php
This file contains hidden or 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
<?php | |
/** | |
* Created by PhpStorm. | |
* User: juliano | |
* Date: 07/09/18 | |
* Time: 16:01 | |
*/ | |
namespace App\Controllers\Auth; | |
use App\Models\Aluno; | |
use App\Controllers\Controller; | |
use Respect\Validation\Validator as v; | |
class AuthController extends Controller | |
{ | |
public function getSignUp($request, $response) | |
{ | |
return $this->view->render($response, 'auth/signup.twig'); | |
} | |
public function postSignUp($request, $response) | |
{ | |
$validation = $this->validator->validate($request, [ | |
'email' => v::noWhitespace()->noEmpty(), | |
'name' => v::noWhitespace()->noEmpty()->alpha(), | |
'password' => v::noWhitespace()->noEmpty(), | |
]); | |
$aluno = Aluno::create([ | |
'email' => $request->getparam('email'), | |
'nome' => $request->getparam('name'), | |
'senha' => password_hash($request->getparam('password'), PASSWORD_DEFAULT, ['cost' => 10]), | |
]); | |
return $response->withRedirect($this->router->pathFor('home')); | |
} | |
} |
This file contains hidden or 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
<?php | |
session_start(); | |
require __DIR__ . '/../vendor/autoload.php'; | |
$app = new \Slim\App([ | |
'settings' => [ | |
'displayErrorDetails' => true, | |
//Eloquent Configuration | |
'db' => [ | |
'driver' => 'mysql', | |
'host' => 'localhost', | |
'database' => 'mybelt', | |
'username' => 'root', | |
'password' => 'root', | |
'charset' => 'utf8', | |
'collation' => 'utf8_unicode_ci', | |
'prefix' => '' | |
] | |
] | |
]); | |
$container = $app->getContainer(); | |
/* | |
* Capsule Eloquent Configuration From Settings | |
* */ | |
$capsule = new \Illuminate\Database\Capsule\Manager(); | |
$capsule->addConnection($container['settings']['db']); | |
$capsule->setAsGlobal(); | |
$capsule->bootEloquent(); | |
/* | |
* Create de reference $this->db to Models | |
* */ | |
$container['db'] = function ($container) use ($capsule) { | |
return $capsule; | |
}; | |
/* | |
* TWIG Configuration | |
* */ | |
$container['view'] = function($container){ | |
$view = new \Slim\Views\Twig(__DIR__ . '/../resources/views', [ | |
'cache' => false, | |
]); | |
$view->addExtension(new \Slim\Views\TwigExtension( | |
$container->router, | |
$container->request->getUri() | |
)); | |
return $view; | |
}; | |
/* | |
* Validator | |
* */ | |
$container['validator'] = function($container) { | |
return new \App\Validation\Validator; | |
}; | |
/* | |
* Return Controller Instance | |
* */ | |
$container['HomeController'] = function($container) { | |
return new \App\Controllers\HomeController($container); | |
}; | |
$container['AuthController'] = function($container) { | |
return new \App\Controllers\Auth\AuthController($container); | |
}; | |
require __DIR__ . '/../app/routes.php'; |
This file contains hidden or 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
<?php | |
/** | |
* Created by PhpStorm. | |
* User: juliano | |
* Date: 07/09/18 | |
* Time: 21:01 | |
*/ | |
namespace App\Validation\Validator; | |
use Respect\Validation\Validator as Respect; | |
class Validator | |
{ | |
public function validate($request, array $rules) | |
{ | |
var_dump($rules); | |
die(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment