Merge pull request #198 from cachethq/refactoring

Refactoring
This commit is contained in:
Graham Campbell
2015-01-01 16:21:06 +00:00
32 changed files with 165 additions and 181 deletions

1
.gitignore vendored
View File

@@ -1,7 +1,6 @@
# Laravel
/bootstrap/compiled.php
/vendor
/workbench
# Configuration
.env.*.php

View File

@@ -113,22 +113,20 @@ return [
'Illuminate\Pagination\PaginationServiceProvider',
'Illuminate\Queue\QueueServiceProvider',
'Illuminate\Redis\RedisServiceProvider',
'Illuminate\Remote\RemoteServiceProvider',
'Illuminate\Auth\Reminders\ReminderServiceProvider',
'Illuminate\Database\SeedServiceProvider',
'Illuminate\Session\SessionServiceProvider',
'Illuminate\Translation\TranslationServiceProvider',
'Illuminate\Validation\ValidationServiceProvider',
'Illuminate\View\ViewServiceProvider',
'Illuminate\Workbench\WorkbenchServiceProvider',
'Dingo\Api\Provider\ApiServiceProvider',
'GrahamCampbell\Throttle\ThrottleServiceProvider',
'GrahamCampbell\Markdown\MarkdownServiceProvider',
'Thujohn\Rss\RssServiceProvider',
'CachetHQ\Cachet\Support\ServiceProviders\RepositoryServiceProvider',
'CachetHQ\Cachet\Support\ServiceProviders\RoutingServiceProvider',
'CachetHQ\Cachet\Providers\RepositoryServiceProvider',
'CachetHQ\Cachet\Providers\RoutingServiceProvider',
],
@@ -158,19 +156,16 @@ return [
'aliases' => [
'API' => 'Dingo\Api\Facade\API',
'App' => 'Illuminate\Support\Facades\App',
'Artisan' => 'Illuminate\Support\Facades\Artisan',
'Auth' => 'Illuminate\Support\Facades\Auth',
'Blade' => 'Illuminate\Support\Facades\Blade',
'Cache' => 'Illuminate\Support\Facades\Cache',
'Carbon' => 'Carbon\Carbon',
'ClassLoader' => 'Illuminate\Support\ClassLoader',
'Config' => 'Illuminate\Support\Facades\Config',
'Controller' => 'Illuminate\Routing\Controller',
'Cookie' => 'Illuminate\Support\Facades\Cookie',
'Crypt' => 'Illuminate\Support\Facades\Crypt',
'DB' => 'Illuminate\Support\Facades\DB',
'Eloquent' => 'Illuminate\Database\Eloquent\Model',
'Event' => 'Illuminate\Support\Facades\Event',
'File' => 'Illuminate\Support\Facades\File',
'Form' => 'Illuminate\Support\Facades\Form',
@@ -189,20 +184,12 @@ return [
'Response' => 'Illuminate\Support\Facades\Response',
'Route' => 'Illuminate\Support\Facades\Route',
'Schema' => 'Illuminate\Support\Facades\Schema',
'Seeder' => 'Illuminate\Database\Seeder',
'Session' => 'Illuminate\Support\Facades\Session',
'SoftDeletingTrait' => 'Illuminate\Database\Eloquent\SoftDeletingTrait',
'SSH' => 'Illuminate\Support\Facades\SSH',
'Str' => 'Illuminate\Support\Str',
'URL' => 'Illuminate\Support\Facades\URL',
'Validator' => 'Illuminate\Support\Facades\Validator',
'View' => 'Illuminate\Support\Facades\View',
'API' => 'Dingo\Api\Facade\API',
'Throttle' => 'GrahamCampbell\Throttle\Facades\Throttle',
'Markdown' => 'GrahamCampbell\Markdown\Facades\Markdown',
'RSS' => 'Thujohn\Rss\RssFacade',
],
];

View File

@@ -1,31 +0,0 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Workbench Author Name
|--------------------------------------------------------------------------
|
| When you create new packages via the Artisan "workbench" command your
| name is needed to generate the composer.json file for your package.
| You may specify it now so it is used for all of your workbenches.
|
*/
'name' => '',
/*
|--------------------------------------------------------------------------
| Workbench Author E-Mail Address
|--------------------------------------------------------------------------
|
| Like the option above, your e-mail address is used when generating new
| workbench packages. The e-mail is placed in your composer.json file
| automatically after the package is created by the workbench tool.
|
*/
'email' => '',
];

View File

@@ -1,15 +1,18 @@
<?php
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder;
class ComponentTableSeeder extends Seeder
{
/**
* Run the database seeds.
* Run the database seeding.
*
* @return void
*/
public function run()
{
Eloquent::unguard();
Model::unguard();
$defaultComponents = [
[

View File

@@ -1,15 +1,18 @@
<?php
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
* Run the database seeding.
*
* @return void
*/
public function run()
{
Eloquent::unguard();
Model::unguard();
$this->call('UsersTableSeeder');
$this->call('SettingsTableSeeder');

View File

@@ -1,15 +1,18 @@
<?php
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder;
class IncidentTableSeeder extends Seeder
{
/**
* Run the database seeds.
* Run the database seeding.
*
* @return void
*/
public function run()
{
Eloquent::unguard();
Model::unguard();
$defaultIncidents = [
[

View File

@@ -1,15 +1,18 @@
<?php
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder;
class SettingsTableSeeder extends Seeder
{
/**
* Run the database seeds.
* Run the database seeding.
*
* @return void
*/
public function run()
{
Eloquent::unguard();
Model::unguard();
$defaultSettings = [
[

View File

@@ -1,15 +1,18 @@
<?php
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder;
class UsersTableSeeder extends Seeder
{
/**
* Run the database seeds.
* Run the database seeding.
*
* @return void
*/
public function run()
{
Eloquent::unguard();
Model::unguard();
$users = [
[

View File

@@ -1,5 +1,7 @@
<?php
use GrahamCampbell\Throttle\Facades\Throttle;
class LoginThrottlingFilter
{
public function filter($route, $request)

View File

@@ -2,6 +2,7 @@
use CachetHQ\Cachet\Transformers\IncidentTransformer;
use Dingo\Api\Transformer\TransformableInterface;
use GrahamCampbell\Markdown\Facades\Markdown;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletingTrait;
use Watson\Validating\ValidatingTrait;

View File

@@ -1,10 +1,6 @@
<?php
Route::api([
'version' => 'v1',
'namespace' => 'CachetHQ\Cachet\Controllers\Api',
'after' => 'allowed_domains',
], function () {
Route::api(['after' => 'allowed_domains', 'namespace' => 'CachetHQ\Cachet\Controllers\Api', 'version' => 'v1'], function () {
Route::get('components', 'ComponentController@getComponents');
Route::get('components/{id}', 'ComponentController@getComponent');
Route::get('components/{id}/incidents', 'ComponentController@getComponentIncidents');

View File

@@ -1,14 +1,16 @@
<?php
// Prevent access until the app is setup.
Route::group(['before' => 'has_setting:app_name'], function () {
Route::group(['before' => 'has_setting:app_name', 'namespace' => 'CachetHQ\Cachet\Controllers'], function () {
Route::get('/', ['as' => 'status-page', 'uses' => 'HomeController@showIndex']);
Route::get('/incident/{incident}', 'HomeController@showIncident');
});
// Setup route.
Route::group(['before' => 'is_setup'], function () {
Route::group(['before' => 'is_setup', 'namespace' => 'CachetHQ\Cachet\Controllers'], function () {
Route::controller('/setup', 'SetupController');
});
Route::get('/rss', 'RSSController@feedAction');
Route::group(['namespace' => 'CachetHQ\Cachet\Controllers'], function () {
Route::get('/rss', 'RssController@feedAction');
});

View File

@@ -1,8 +1,10 @@
<?php
Route::group(['before' => 'has_setting:app_name'], function () {
Route::group(['before' => 'has_setting:app_name', 'namespace' => 'CachetHQ\Cachet\Controllers'], function () {
Route::get('/auth/login', ['before' => 'guest', 'as' => 'login', 'uses' => 'AuthController@showLogin']);
Route::post('/auth/login', ['before' => 'guest|csrf|login_throttling', 'as' => 'logout', 'uses' => 'AuthController@postLogin']);
});
Route::get('/auth/logout', ['before' => 'auth', 'as' => 'logout', 'uses' => 'AuthController@logoutAction']);
Route::group(['before' => 'auth', 'namespace' => 'CachetHQ\Cachet\Controllers'], function () {
Route::get('/auth/logout', ['as' => 'logout', 'uses' => 'AuthController@logoutAction']);
});

View File

@@ -1,6 +1,6 @@
<?php
Route::group(['before' => 'auth', 'prefix' => 'dashboard'], function () {
Route::group(['before' => 'auth', 'prefix' => 'dashboard', 'namespace' => 'CachetHQ\Cachet\Controllers'], function () {
// Dashboard
Route::get('/', ['as' => 'dashboard', 'uses' => 'DashboardController@showDashboard']);

View File

@@ -1,27 +1,5 @@
<?php
/*
|--------------------------------------------------------------------------
| Register The Laravel Class Loader
|--------------------------------------------------------------------------
|
| In addition to using Composer, you may use the Laravel class loader to
| load your controllers and models. This is useful for keeping all of
| your classes in the "global" namespace without Composer updating.
|
*/
ClassLoader::addDirectories([
app_path().'/commands',
app_path().'/controllers',
app_path().'/models',
app_path().'/transformers',
app_path().'/database/seeds',
app_path().'/filters',
]);
/*
|--------------------------------------------------------------------------
| Application Error Logger

View File

@@ -1,5 +1,5 @@
<?php
$incidentDate = Carbon::now()->subDays($i);
$incidentDate = Carbon\Carbon::now()->subDays($i);
$incidents = Incident::whereBetween('created_at', [
$incidentDate->format('Y-m-d') . ' 00:00:00',
$incidentDate->format('Y-m-d') . ' 23:59:59',

View File

@@ -43,31 +43,3 @@ if (file_exists($compiled = __DIR__.'/compiled.php')) {
*/
Patchwork\Utf8\Bootup::initMbstring();
/*
|--------------------------------------------------------------------------
| Register The Laravel Auto Loader
|--------------------------------------------------------------------------
|
| We register an auto-loader "behind" the Composer loader that can load
| model classes on the fly, even if the autoload files have not been
| regenerated for the application. We'll add it to the stack here.
|
*/
Illuminate\Support\ClassLoader::register();
/*
|--------------------------------------------------------------------------
| Register The Workbench Loaders
|--------------------------------------------------------------------------
|
| The Laravel workbench provides a convenient place to develop packages
| when working locally. However we will need to load in the Composer
| auto-load files for the packages so that these can be used here.
|
*/
if (is_dir($workbench = __DIR__.'/../workbench')) {
Illuminate\Workbench\Starter::start($workbench);
}

View File

@@ -27,17 +27,20 @@
},
"autoload": {
"classmap": [
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php",
"app/filters"
"app/filters",
"app/models"
],
"psr-4": {
"CachetHQ\\Cachet\\": "src/"
}
},
"autoload-dev": {
"classmap": [
"app/tests/TestCase.php"
]
},
"extra": {
"paas": {
"document-root": "public",

2
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "44248db4d4bba4ff38d7f3aef78acc79",
"hash": "af0ee6e5bc07e350732bc7c907e3b2ae",
"packages": [
{
"name": "classpreloader/classpreloader",

View File

@@ -20,8 +20,7 @@
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app/CachetHQ</directory>
<directory suffix=".php">./app/controllers</directory>
<directory suffix=".php">./src</directory>
<directory suffix=".php">./app/filters</directory>
<directory suffix=".php">./app/models</directory>
</whitelist>

View File

@@ -1,5 +1,15 @@
<?php
namespace CachetHQ\Cachet\Controllers;
use GrahamCampbell\Throttle\Facades\Throttle;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\View;
/**
* Logs users into their account.
*/
@@ -24,13 +34,13 @@ class AuthController extends Controller
{
if (Auth::attempt(Input::only(['email', 'password']))) {
return Redirect::intended('dashboard');
} else {
Throttle::hit(Request::instance(), 10, 10);
return Redirect::back()
->withInput(Input::except('password'))
->with('error', 'Invalid email or password');
}
Throttle::hit(Request::instance(), 10, 10);
return Redirect::back()
->withInput(Input::except('password'))
->with('error', 'Invalid email or password');
}
/**

View File

@@ -1,23 +1,30 @@
<?php
namespace CachetHQ\Cachet\Controllers;
use Component;
use Exception;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Input;
class DashAPIController extends Controller
{
/**
* Updates a component with the entered info.
*
* @param Component $component
* @param \Component $component
*
* @return array
* @throws \Exception
*
* @return \Component
*/
public function postUpdateComponent(Component $component)
{
$componentData = Input::all();
unset($componentData['_token']);
if ($component->update($componentData)) {
return $component;
} else {
App::abort(500);
if (!$component->update(Input::except(['_token']))) {
throw new Exception('Failed to update the component.');
}
return $component;
}
/**
@@ -32,9 +39,7 @@ class DashAPIController extends Controller
foreach ($componentData['component'] as $componentId => $order) {
$component = Component::find($componentId);
$component->update([
'order' => $order,
]);
$component->update(['order' => $order]);
}
return $componentData;

View File

@@ -1,5 +1,13 @@
<?php
namespace CachetHQ\Cachet\Controllers;
use Component;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View;
class DashComponentController extends Controller
{
/**

View File

@@ -1,5 +1,14 @@
<?php
namespace CachetHQ\Cachet\Controllers;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View;
use Incident;
use IncidentTemplate;
class DashIncidentController extends Controller
{
/**

View File

@@ -1,5 +1,13 @@
<?php
namespace CachetHQ\Cachet\Controllers;
use Exception;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\View;
use Setting;
class DashSettingsController extends Controller
{
protected $subMenu = [];
@@ -105,27 +113,27 @@ class DashSettingsController extends Controller
*/
public function postSettings()
{
// Fetch all of the settings we've been POSTed.
$settings = Input::all();
if ($settings['remove_banner'] == "1") {
if (Input::get('remove_banner') == "1") {
$setting = Setting::where('name', 'app_banner');
$setting->delete();
}
unset($settings['remove-banner']);
if (Input::hasFile('app_banner')) {
$file = Input::file('app_banner');
// Image Validation.
// Image size in bytes.
$maxSize = $file->getMaxFilesize();
if ($file->getSize() > $maxSize) {
return Redirect::back()->withErrorMessage('You need to upload an image that is less than '.$maxSize.'.');
} elseif (!$file->isValid() || $file->getError()) {
}
if (!$file->isValid() || $file->getError()) {
return Redirect::back()->withErrorMessage($file->getErrorMessage());
} elseif (strpos($file->getMimeType(), 'image/') !== 0) {
}
if (strpos($file->getMimeType(), 'image/') !== 0) {
return Redirect::back()->withErrorMessage('Only images may be uploaded.');
}
@@ -144,10 +152,8 @@ class DashSettingsController extends Controller
]);
}
unset($settings['app_banner']);
try {
foreach ($settings as $settingName => $settingValue) {
foreach (Input::except(['app_banner', 'remove-banner']) as $settingName => $settingValue) {
$setting = Setting::firstOrCreate([
'name' => $settingName,
])->update([

View File

@@ -1,5 +1,13 @@
<?php
namespace CachetHQ\Cachet\Controllers;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View;
class DashUserController extends Controller
{
/**

View File

@@ -1,5 +1,11 @@
<?php
namespace CachetHQ\Cachet\Controllers;
use Component;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\View;
class DashboardController extends Controller
{
/**

View File

@@ -1,26 +1,14 @@
<?php
namespace CachetHQ\Cachet\Controllers;
use Component;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\View;
use Setting;
class HomeController extends Controller
{
/**
* The component instance.
*
* @var \Component
*/
protected $component;
/**
* Create a new home controller instance.
*
* @param \Component $component
*
* @return void
*/
public function __construct(Component $component)
{
$this->component = $component;
}
/**
* Returns the rendered Blade templates.
*

View File

@@ -1,6 +1,14 @@
<?php
class RSSController extends Controller
namespace CachetHQ\Cachet\Controllers;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Response;
use Incident;
use Setting;
use Thujohn\Rss\RssFacade;
class RssController extends Controller
{
/**
* Generates an RSS feed of all incidents.
@@ -9,7 +17,7 @@ class RSSController extends Controller
*/
public function feedAction()
{
$feed = RSS::feed('2.0', 'UTF-8');
$feed = RssFacade::feed('2.0', 'UTF-8');
$feed->channel([
'title' => Setting::get('app_name'),
'description' => 'Status Feed',

View File

@@ -1,5 +1,16 @@
<?php
namespace CachetHQ\Cachet\Controllers;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\View;
use Setting;
use User;
class SetupController extends Controller
{
/**
@@ -46,7 +57,7 @@ class SetupController extends Controller
// Pull the user details out.
$userDetails = array_pull($postData, 'user');
// TODO: Do we want to just use Eloquent::unguard() here?
// TODO: Do we want to just use Model::unguard() here?
$user = User::create([
'username' => $userDetails['username'],
'email' => $userDetails['email'],
@@ -59,8 +70,8 @@ class SetupController extends Controller
$settings = array_get($postData, 'settings');
foreach ($settings as $settingName => $settingValue) {
$setting = new Setting();
$setting->name = $settingName;
$setting = new Setting();
$setting->name = $settingName;
$setting->value = $settingValue;
$setting->save();
}

View File

@@ -1,6 +1,6 @@
<?php
namespace CachetHQ\Cachet\Support\ServiceProviders;
namespace CachetHQ\Cachet\Providers;
use Illuminate\Support\ServiceProvider;

View File

@@ -1,6 +1,6 @@
<?php
namespace CachetHQ\Cachet\Support\ServiceProviders;
namespace CachetHQ\Cachet\Providers;
use Illuminate\Support\ServiceProvider;
use RecursiveDirectoryIterator;