Skip to content

Commit

Permalink
Merge pull request #351 from spira/feature/lumen-5.2-upgrade
Browse files Browse the repository at this point in the history
Updated to support lumen 5.2
  • Loading branch information
zakhenry committed Jan 20, 2016
2 parents 8144516 + c3c47d8 commit ac24cf2
Show file tree
Hide file tree
Showing 41 changed files with 1,432 additions and 1,126 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ before_script:
- psql -c 'create database spira;' -U postgres
- gulp build
- php ./api/artisan migrate --seed
- php ./api/artisan serve --port 8000 --host 127.0.0.1 --quiet 2>&1 >/dev/null & # start api server
- php -S 127.0.0.1:8000 ./api/server.php 2>&1 >/dev/null & # start api server
- http-server ./app/build/ -p 8001 2>&1 >/dev/null & # start webserver
- mailcatcher # start mailcatcher server
- beanstalkd -d -l 127.0.0.1 -p 11300 # start queue listener
Expand Down
1 change: 1 addition & 0 deletions api/.travis.env
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ WEBSERVER_PORT=8000

AUTH_MODEL=App\Models\User
AUTH_DRIVER=jwt
AUTH_GUARD=jwt

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
Expand Down
2 changes: 1 addition & 1 deletion api/app/Extensions/Socialite/SocialiteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function boot()
*/
public function register()
{
$this->app->bindShared('Laravel\Socialite\Contracts\Factory', function ($app) {
$this->app->singleton('Laravel\Socialite\Contracts\Factory', function ($app) {
return new SocialiteManager($app);
});
}
Expand Down
16 changes: 3 additions & 13 deletions api/app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@

class AuthController extends ApiController
{
/**
* The application instance.
*
* @var Application
*/
protected $app;

/**
* @var SpiraGuard
*/
Expand All @@ -59,13 +52,10 @@ class AuthController extends ApiController
* @param AuthTokenTransformer $transformer
* @param Application $app
*/
public function __construct(
Guard $auth,
AuthTokenTransformer $transformer,
Application $app)
public function __construct(Guard $auth, AuthTokenTransformer $transformer)
{
$this->auth = $auth;
$this->app = $app;

parent::__construct($transformer);
}

Expand Down Expand Up @@ -255,7 +245,7 @@ public function singleSignOn($requester, Request $request)
*/
protected function validateProvider($provider)
{
if (! in_array($provider, array_keys($this->app['config']['services']))) {
if (! in_array($provider, array_keys(app()['config']['services']))) {
throw new NotImplementedException('Provider '.$provider.' is not supported.');
}
}
Expand Down
3 changes: 0 additions & 3 deletions api/app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use App\Jobs\SendPasswordResetEmail;
use Illuminate\Contracts\Auth\Guard;
use App\Jobs\SendEmailConfirmationEmail;
use Laravel\Lumen\Routing\DispatchesJobs;
use Spira\Auth\Driver\Guard as SpiraGuard;
use Spira\Core\Controllers\EntityController;
use Spira\Core\Responder\Response\ApiResponse;
Expand All @@ -29,8 +28,6 @@

class UserController extends EntityController
{
use DispatchesJobs;

/**
* @var SpiraGuard
*/
Expand Down
2 changes: 1 addition & 1 deletion api/app/Http/Transformers/AuthTokenTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function transformItem($token, array $options = [])
$result = ['token' => (string) $token];

if (env('APP_DEBUG', false)) {
$result['decodedTokenBody'] = \App::make('auth')->getTokenizer()->decode($token);
$result['decodedTokenBody'] = app('auth')->getTokenizer()->decode($token);
}

return $result;
Expand Down
5 changes: 2 additions & 3 deletions api/app/Jobs/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@

namespace App\Jobs;

use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldBeQueued;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

abstract class Job implements SelfHandling, ShouldBeQueued
abstract class Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
}
23 changes: 11 additions & 12 deletions api/app/Jobs/SendEmailConfirmationEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
namespace App\Jobs;

use App\Models\User;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Message;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Config;
use Illuminate\Contracts\Queue\ShouldQueue;

class SendEmailConfirmationEmail extends Job implements SelfHandling, ShouldQueue
class SendEmailConfirmationEmail extends Job implements ShouldQueue
{
/**
* User to email.
Expand Down Expand Up @@ -49,10 +49,10 @@ class SendEmailConfirmationEmail extends Job implements SelfHandling, ShouldQueu
/**
* Create a new job instance.
*
* @param User $user
* @param string $email
* @param string $token
* @return void
* @param User $user
* @param string $email
* @param $emailConfirmToken
* @param $loginToken
*/
public function __construct(User $user, $email, $emailConfirmToken, $loginToken)
{
Expand All @@ -65,16 +65,15 @@ public function __construct(User $user, $email, $emailConfirmToken, $loginToken)
/**
* Execute the job.
*
* @param Mailer $mailer
* @return void
*/
public function handle(Mailer $mailer)
public function handle()
{
$mailer->send('emails.emailConfirmation', [
Mail::send('emails.emailConfirmation', [
'user' => $this->user,
'email' => $this->email,
'emailConfirmationRedirectionUrl' => Config::get('hosts.app').'/profile?emailConfirmationToken='.$this->emailConfirmToken.'&loginToken='.$this->loginToken,
], function ($m) {
], function (Message $m) {

$m->to($this->email, $this->user->full_name)
->subject('Confirm Your Email');
Expand Down
12 changes: 5 additions & 7 deletions api/app/Jobs/SendPasswordResetEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@

use App\Models\User;
use Illuminate\Mail\Message;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Config;
use Illuminate\Contracts\Queue\ShouldQueue;

class SendPasswordResetEmail extends Job implements SelfHandling, ShouldQueue
class SendPasswordResetEmail extends Job implements ShouldQueue
{
/**
* User to email.
Expand Down Expand Up @@ -49,12 +48,11 @@ public function __construct(User $user, $loginToken)
/**
* Execute the job.
*
* @param Mailer $mailer
* @return void
*/
public function handle(Mailer $mailer)
public function handle()
{
$mailer->send('emails.resetPassword', [
Mail::send('emails.resetPassword', [
'user' => $this->user,
'passwordResetRedirectionUrl' => Config::get('hosts.app').'/profile?loginToken='.$this->loginToken,
], function (Message $m) {
Expand Down
2 changes: 1 addition & 1 deletion api/app/Models/PostDiscussion.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public function setPost($post)
protected function getClient()
{
if (! $this->client) {
$this->client = App::make(VanillaClient::class);
$this->client = app(VanillaClient::class);
}

return $this->client;
Expand Down
3 changes: 2 additions & 1 deletion api/app/Models/UserCredential.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace App\Models;

use Illuminate\Support\Facades\Hash;
use Spira\Core\Model\Model\BaseModel;

class UserCredential extends BaseModel
Expand Down Expand Up @@ -59,6 +60,6 @@ class UserCredential extends BaseModel
*/
public function setPasswordAttribute($value)
{
$this->attributes['password'] = \Hash::make($value);
$this->attributes['password'] = Hash::make($value);
}
}
2 changes: 2 additions & 0 deletions api/app/Providers/ApplicationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public function boot()
'rbac_role_exists' => 'The :attribute must be an existing Rbac role',
];

$this->app->bind('url', \Laravel\Lumen\Routing\UrlGenerator::class);

$this->app->extend('validator', function (Factory $validator) use ($spiraMessages) {
$validator->resolver(function ($translator, $data, $rules, $messages, $customAttributes) use ($spiraMessages) {
return new Validator($translator, $data, $rules, array_merge($messages, $spiraMessages), $customAttributes);
Expand Down
2 changes: 1 addition & 1 deletion api/app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function registerAuthenticator()
});

$this->app->singleton('auth.driver', function ($app) {
return $app['auth']->driver();
return $app['auth']->guard();
});
}

Expand Down
30 changes: 30 additions & 0 deletions api/app/Services/Redirector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
* This file is part of the Spira framework.
*
* @link https://github.com/spira/spira
*
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

namespace App\Services;

use Illuminate\Http\RedirectResponse;

/**
* This class is temporary fixing session requirement while making redirect response because of Lumen 5.2 doesn't support sessions.
*
* It should override redirect() method dependency, but there is call of new \Laravel\Lumen\Http\Redirector
*/
class Redirector extends \Laravel\Lumen\Http\Redirector
{
/** @inherit */
protected function createRedirect($path, $status, $headers)
{
$redirect = new RedirectResponse($path, $status, $headers);
$redirect->setRequest($this->app->make('request'));

return $redirect;
}
}
2 changes: 1 addition & 1 deletion api/app/Services/SingleSignOn/VanillaSingleSignOn.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ protected function getMappedRoles()
*/
protected function getGate()
{
return \App::make(GateContract::class);
return app(GateContract::class);
}

/**
Expand Down
12 changes: 8 additions & 4 deletions api/bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
$app->configure('regions');
$app->configure('jwt');
$app->configure('cors');
$app->configure('mail');

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -92,13 +93,16 @@
*/

$app->register(App\Providers\ApplicationProvider::class);
$app->register(App\Providers\ElasticServiceProvider::class);
$app->register(App\Providers\AuthServiceProvider::class);
$app->register(App\Providers\AuthDriverServiceProvider::class);
$app->register(App\Providers\ElasticServiceProvider::class);
$app->register(App\Providers\AccessServiceProvider::class);
$app->register(Bosnadev\Database\DatabaseServiceProvider::class);
$app->register(App\Providers\AuthDriverServiceProvider::class);
$app->register(\Illuminate\Mail\MailServiceProvider::class);
$app->register(\Illuminate\Redis\RedisServiceProvider::class);

$app->register(App\Extensions\Socialite\SocialiteServiceProvider::class);
$app->register(Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);

$app->register(Bosnadev\Database\DatabaseServiceProvider::class);
$app->register(Barryvdh\Cors\LumenServiceProvider::class);

/*
Expand Down
20 changes: 6 additions & 14 deletions api/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,30 @@
"repositories": [
{
"type": "vcs",
"url": "https://github.com/spira/Elasticquent"
},
{
"type": "vcs",
"url": "https://github.com/spira/api-core"
"url": "https://github.com/spira/revisionable"
},
{
"type": "vcs",
"url": "https://github.com/spira/revisionable"
"url": "http://github.com/spira/database"
}
],
"require": {
"jeremeamia/superclosure": "^2.1",
"pda/pheanstalk": "^3.0",
"predis/predis": "^1.0",
"illuminate/redis": "5.1.*",
"guzzlehttp/guzzle": "5.3.*",
"illuminate/redis": "5.2.*",
"league/flysystem": "^1.0",
"laravel/socialite": "^2.0",
"cloudinary/cloudinary_php": "^1.1",
"venturecraft/revisionable": "^2.0",
"spira/core": "1.5.*",
"namshi/jose": "^6.0"
"namshi/jose": "^6.0",
"spira/core": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "~5.1",
"mockery/mockery": "^0.9.4",
"fzaninotto/faker": "^1.4",
"barryvdh/laravel-ide-helper": "dev-master"
"symfony/var-dumper": "^3.0"
},
"autoload": {
"psr-4": {
Expand All @@ -63,9 +58,6 @@
"post-install-cmd": [
"npm install",
"php artisan auth:generate-keys"
],
"post-update-cmd": [
"php artisan ide-helper:generate"
]
}
}

0 comments on commit ac24cf2

Please sign in to comment.