From dd6cb2f6cefa25a6c818c3bd406edb7d2570f5cb Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Wed, 26 Aug 2015 17:13:18 +0930 Subject: [PATCH] Clean up, add header comments --- LICENSE.txt => LICENSE | 0 Vagrantfile | 3 +- admin.php | 35 +++++++++----- api.php | 35 +++++++++----- flarum/bootstrap.php | 51 +++++++++++--------- flarum/composer.json | 36 +++++++------- flarum/flarum | 22 +++++++-- flarum/storage/framework/sessions/.gitignore | 2 - flarum/vagrant/environment.sh | 16 +++--- index.php | 42 ++++++++++------ 10 files changed, 146 insertions(+), 96 deletions(-) rename LICENSE.txt => LICENSE (100%) delete mode 100644 flarum/storage/framework/sessions/.gitignore diff --git a/LICENSE.txt b/LICENSE similarity index 100% rename from LICENSE.txt rename to LICENSE diff --git a/Vagrantfile b/Vagrantfile index 24fa3ca..756f879 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -8,7 +8,6 @@ github_branch = "1.3.0" github_url = "https://raw.githubusercontent.com/#{github_username}/#{github_repo}/#{github_branch}" # Server Configuration - hostname = "flarum.dev" # Set a local private network IP address. @@ -296,7 +295,7 @@ Vagrant.configure("2") do |config| config.vm.provision "shell", path: "#{github_url}/scripts/composer.sh", privileged: false, args: composer_packages.join(" ") # Provision Laravel - #config.vm.provision "shell", path: "#{github_url}/scripts/laravel.sh", privileged: false, args: [server_ip, laravel_root_folder, public_folder, laravel_version] + # config.vm.provision "shell", path: "#{github_url}/scripts/laravel.sh", privileged: false, args: [server_ip, laravel_root_folder, public_folder, laravel_version] # Provision Symfony # config.vm.provision "shell", path: "#{github_url}/scripts/symfony.sh", privileged: false, args: [server_ip, symfony_root_folder, public_folder] diff --git a/admin.php b/admin.php index 8cc23df..97b1078 100644 --- a/admin.php +++ b/admin.php @@ -1,37 +1,46 @@ <?php +/* + * This file is part of Flarum. + * + * (c) Toby Zerner <toby.zerner@gmail.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + use Flarum\Core; +use Flarum\Forum\Middleware\HandleErrors; +use Franzl\Middleware\Whoops\Middleware as WhoopsMiddleware; use Zend\Diactoros\Server; use Zend\Stratigility\MiddlewarePipe; -// Instantiate the application, register providers etc. $app = require __DIR__.'/flarum/bootstrap.php'; -// Set up everything we need for the frontend $app->register('Flarum\Admin\AdminServiceProvider'); -// Build a middleware pipeline for Flarum $admin = new MiddlewarePipe(); $admin->pipe($app->make('Flarum\Api\Middleware\ReadJsonParameters')); $admin->pipe($app->make('Flarum\Admin\Middleware\LoginWithCookieAndCheckAdmin')); $adminPath = parse_url(Core::config('admin_url'), PHP_URL_PATH); -$admin->pipe($adminPath, $app->make('Flarum\Http\RouterMiddleware', ['routes' => $app->make('flarum.admin.routes')])); +$router = $app->make('Flarum\Http\RouterMiddleware', ['routes' => $app->make('flarum.admin.routes')]); + +$admin->pipe($adminPath, $router); -// Handle errors if (Core::inDebugMode()) { - $admin->pipe(new \Franzl\Middleware\Whoops\Middleware()); + $admin->pipe(new WhoopsMiddleware()); } else { - $admin->pipe(new \Flarum\Forum\Middleware\HandleErrors(base_path('error'))); + $admin->pipe(new HandleErrors(base_path('error'))); } $server = Server::createServer( - $admin, - $_SERVER, - $_GET, - $_POST, - $_COOKIE, - $_FILES + $admin, + $_SERVER, + $_GET, + $_POST, + $_COOKIE, + $_FILES ); $server->listen(); diff --git a/api.php b/api.php index df00402..533900c 100644 --- a/api.php +++ b/api.php @@ -1,37 +1,46 @@ <?php +/* + * This file is part of Flarum. + * + * (c) Toby Zerner <toby.zerner@gmail.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Flarum\Api\Middleware\JsonApiErrors; use Flarum\Core; +use Franzl\Middleware\Whoops\Middleware as WhoopsMiddleware; use Zend\Diactoros\Server; use Zend\Stratigility\MiddlewarePipe; -// Instantiate the application, register providers etc. $app = require __DIR__.'/flarum/bootstrap.php'; -// Set up everything we need for the API $app->register('Flarum\Api\ApiServiceProvider'); -// Build a middleware pipeline for the API $api = new MiddlewarePipe(); $api->pipe($app->make('Flarum\Api\Middleware\ReadJsonParameters')); $api->pipe($app->make('Flarum\Api\Middleware\LoginWithHeader')); $apiPath = parse_url(Core::config('api_url'), PHP_URL_PATH); -$api->pipe($apiPath, $app->make('Flarum\Http\RouterMiddleware', ['routes' => $app->make('flarum.api.routes')])); +$router = $app->make('Flarum\Http\RouterMiddleware', ['routes' => $app->make('flarum.api.routes')]); + +$api->pipe($apiPath, $router); -// Handle errors if (Core::inDebugMode()) { - $api->pipe(new \Franzl\Middleware\Whoops\Middleware()); + $api->pipe(new WhoopsMiddleware()); } else { - $api->pipe(new \Flarum\Api\Middleware\JsonApiErrors()); + $api->pipe(new JsonApiErrors()); } $server = Server::createServer( - $api, - $_SERVER, - $_GET, - $_POST, - $_COOKIE, - $_FILES + $api, + $_SERVER, + $_GET, + $_POST, + $_COOKIE, + $_FILES ); $server->listen(); diff --git a/flarum/bootstrap.php b/flarum/bootstrap.php index 6f98dd6..698724c 100644 --- a/flarum/bootstrap.php +++ b/flarum/bootstrap.php @@ -1,27 +1,43 @@ <?php -define('LARAVEL_START', microtime(true)); -require __DIR__.'/vendor/autoload.php'; +/* + * This file is part of Flarum. + * + * (c) Toby Zerner <toby.zerner@gmail.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ -// Temp while franzliedke/studio doesn't autoload files -if (file_exists(__DIR__.'/core')) { - require __DIR__.'/core/src/helpers.php'; - require __DIR__.'/core/vendor/swiftmailer/swiftmailer/lib/swift_required.php'; +use Flarum\Core; +use Flarum\Core\Application; +use Illuminate\Cache\FileStore; +use Illuminate\Cache\Repository; +use Illuminate\Config\Repository as ConfigRepository; +use Illuminate\Filesystem\Filesystem; + +define('FLARUM_START', microtime(true)); + +require __DIR__ . '/vendor/autoload.php'; + +// franzliedke/studio currently doesn't autoload files (see issue below), so we +// will need to load them manually if we're using studio. +// https://github.com/franzliedke/studio/issues/29 +if (file_exists(__DIR__ . '/core')) { + require __DIR__ . '/core/src/helpers.php'; + require __DIR__ . '/core/vendor/swiftmailer/swiftmailer/lib/swift_required.php'; } -$app = new Flarum\Core\Application( - realpath(__DIR__) -); +$app = new Application(realpath(__DIR__)); $app->instance('path.public', __DIR__.'/..'); Illuminate\Container\Container::setInstance($app); -// LoadConfiguration if (file_exists($configFile = __DIR__.'/../config.php')) { $app->instance('flarum.config', include $configFile); } -$app->instance('config', $config = new \Illuminate\Config\Repository([ +$app->instance('config', $config = new ConfigRepository([ 'view' => [ 'paths' => [ realpath(base_path('resources/views')) @@ -53,9 +69,8 @@ $app->instance('config', $config = new \Illuminate\Config\Repository([ ], ])); -// ConfigureLogging $logger = new Monolog\Logger($app->environment()); -$logPath = $app->storagePath().'/logs/flarum.log'; +$logPath = $app->storagePath() . '/logs/flarum.log'; $handler = new \Monolog\Handler\StreamHandler($logPath, Monolog\Logger::DEBUG); $handler->setFormatter(new \Monolog\Formatter\LineFormatter(null, null, true, true)); $logger->pushHandler($handler); @@ -63,13 +78,7 @@ $logger->pushHandler($handler); $app->instance('log', $logger); $app->alias('log', 'Psr\Log\LoggerInterface'); -// Register some services -use Flarum\Core; -use Illuminate\Cache\FileStore; -use Illuminate\Cache\Repository; -use Illuminate\Filesystem\Filesystem; - -$app->singleton('cache', function($app) { +$app->singleton('cache', function ($app) { $store = new FileStore(new Filesystem(), storage_path('framework/cache')); $repository = new Repository($store); $repository->setEventDispatcher($app->make('events')); @@ -77,7 +86,6 @@ $app->singleton('cache', function($app) { }); $app->alias('cache', 'Illuminate\Contracts\Cache\Repository'); -// RegisterProviders $serviceProviders = [ 'Flarum\Core\DatabaseServiceProvider', 'Flarum\Core\Settings\SettingsServiceProvider', @@ -114,7 +122,6 @@ if (Core::isInstalled()) { $app->register(new \Flarum\Support\ExtensionsServiceProvider($app)); } -// BootProviders $app->boot(); return $app; diff --git a/flarum/composer.json b/flarum/composer.json index 8bf5322..d7be33a 100644 --- a/flarum/composer.json +++ b/flarum/composer.json @@ -1,20 +1,20 @@ { - "name": "flarum/flarum", - "description": "The Flarum forum skeleton.", - "keywords": ["forum", "flarum"], - "license": "MIT", - "type": "project", - "require": { - "illuminate/container": "5.1.*", - "monolog/monolog": "^1.16.0", - "zendframework/zend-stratigility": "^1.1", - "franzl/whoops-middleware": "dev-master", - "flarum/core": "0.1.x@dev" - }, - "require-dev": { - "franzl/studio": "1.0.x@dev" - }, - "config": { - "preferred-install": "dist" - } + "name": "flarum/flarum", + "description": "The Flarum forum skeleton.", + "keywords": ["forum", "flarum"], + "license": "MIT", + "type": "project", + "require": { + "illuminate/container": "5.1.*", + "monolog/monolog": "^1.16.0", + "zendframework/zend-stratigility": "^1.1", + "franzl/whoops-middleware": "dev-master", + "flarum/core": "0.1.x@dev" + }, + "require-dev": { + "franzl/studio": "1.0.x@dev" + }, + "config": { + "preferred-install": "dist" + } } diff --git a/flarum/flarum b/flarum/flarum index 0b6f3b9..9914cf0 100644 --- a/flarum/flarum +++ b/flarum/flarum @@ -1,12 +1,26 @@ #!/usr/bin/env php <?php +/* + * This file is part of Flarum. + * + * (c) Toby Zerner <toby.zerner@gmail.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Flarum\Console\GenerateExtensionCommand; +use Flarum\Console\UpgradeCommand; +use Flarum\Install\Console\InstallCommand; +use Symfony\Component\Console\Application; + $app = require_once __DIR__.'/bootstrap.php'; -$console = new \Symfony\Component\Console\Application('Flarum', '0.1.0-beta'); +$console = new Application('Flarum', $app::VERSION); -$console->add(new \Flarum\Install\Console\InstallCommand($app)); -$console->add(new \Flarum\Console\UpgradeCommand($app)); -$console->add(new \Flarum\Console\GenerateExtensionCommand($app)); +$console->add(new InstallCommand($app)); +$console->add(new UpgradeCommand($app)); +$console->add(new GenerateExtensionCommand($app)); exit($console->run()); diff --git a/flarum/storage/framework/sessions/.gitignore b/flarum/storage/framework/sessions/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/flarum/storage/framework/sessions/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/flarum/vagrant/environment.sh b/flarum/vagrant/environment.sh index 43d1219..dc8f8c0 100644 --- a/flarum/vagrant/environment.sh +++ b/flarum/vagrant/environment.sh @@ -70,26 +70,26 @@ else echo "source ~/.aliases" >> ~/.bashrc fi -### Set up environment files and database ### -cp /vagrant/system/.env.example /vagrant/system/.env mysql -u root -proot -e 'create database flarum' ### Setup flarum/core and install dependencies ### -cd /vagrant/system/core +cd /vagrant/flarum/core composer install --prefer-dist -cd /vagrant/system + +cd /vagrant/flarum composer install --prefer-dist composer dump-autoload -cd /vagrant/system/core/js +cd /vagrant/flarum/core/js bower install -cd /vagrant/system/core/js/forum + +cd /vagrant/flarum/core/js/forum npm install gulp -cd /vagrant/system/core/js/admin + +cd /vagrant/flarum/core/js/admin npm install gulp cd /vagrant/system -#php flarum vendor:publish php flarum install --defaults diff --git a/index.php b/index.php index 23ab209..e1dbbcc 100644 --- a/index.php +++ b/index.php @@ -1,28 +1,41 @@ <?php +/* + * This file is part of Flarum. + * + * (c) Toby Zerner <toby.zerner@gmail.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + use Flarum\Core; +use Flarum\Forum\Middleware\HandleErrors; +use Franzl\Middleware\Whoops\Middleware as WhoopsMiddleware; use Zend\Diactoros\Server; use Zend\Stratigility\MiddlewarePipe; -// Instantiate the application, register providers etc. $app = require __DIR__.'/flarum/bootstrap.php'; +// If Flarum's configuration exists, then we can assume that installation has +// been completed. We will set up a middleware pipe to route the request through +// to one of the main forum actions. if ($app->bound('flarum.config')) { $app->register('Flarum\Forum\ForumServiceProvider'); - // Build a middleware pipeline for Flarum $flarum = new MiddlewarePipe(); $flarum->pipe($app->make('Flarum\Forum\Middleware\LoginWithCookie')); $flarum->pipe($app->make('Flarum\Api\Middleware\ReadJsonParameters')); $basePath = parse_url(Core::config('base_url'), PHP_URL_PATH); - $flarum->pipe($basePath, $app->make('Flarum\Http\RouterMiddleware', ['routes' => $app->make('flarum.forum.routes')])); + $router = $app->make('Flarum\Http\RouterMiddleware', ['routes' => $app->make('flarum.forum.routes')]); + + $flarum->pipe($basePath, $router); - // Handle errors if (Core::inDebugMode()) { - $flarum->pipe(new \Franzl\Middleware\Whoops\Middleware()); + $flarum->pipe(new WhoopsMiddleware()); } else { - $flarum->pipe(new \Flarum\Forum\Middleware\HandleErrors(base_path('error'))); + $flarum->pipe(new HandleErrors(base_path('error'))); } } else { $app->register('Flarum\Install\InstallServiceProvider'); @@ -30,17 +43,18 @@ if ($app->bound('flarum.config')) { $flarum = new MiddlewarePipe(); $basePath = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); - $flarum->pipe($basePath, $app->make('Flarum\Http\RouterMiddleware', ['routes' => $app->make('flarum.install.routes')])); - $flarum->pipe(new \Franzl\Middleware\Whoops\Middleware()); + $router = $app->make('Flarum\Http\RouterMiddleware', ['routes' => $app->make('flarum.install.routes')]); + $flarum->pipe($basePath, $router); + $flarum->pipe(new WhoopsMiddleware()); } $server = Server::createServer( - $flarum, - $_SERVER, - $_GET, - $_POST, - $_COOKIE, - $_FILES + $flarum, + $_SERVER, + $_GET, + $_POST, + $_COOKIE, + $_FILES ); $server->listen();