mirror of
https://github.com/flarum/core.git
synced 2025-10-11 15:04:25 +02:00
Major refactor and improvements
- Reorganised all namespaces and class names for consistency and structure. Following PSR bylaws (Abstract prefix, Interface/Trait suffix). - Move models into root of Core, because writing `use Flarum\Core\Discussion` is nice. Namespace the rest by type. (Namespacing by entity was too arbitrary.) - Moved some non-domain stuff out of Core: Database, Formatter, Settings. - Renamed config table and all references to "settings" for consistency. - Remove Core class and add url()/isInstalled()/inDebugMode() as instance methods of Foundation\Application. - Cleanup, docblocking, etc. - Improvements to HTTP architecture - API and forum/admin Actions are now actually all the same thing (simple PSR-7 Request handlers), renamed to Controllers. - Upgrade to tobscure/json-api 0.2 branch. - Where possible, moved generic functionality to tobscure/json-api (e.g. pagination links). I'm quite happy with the backend balance now re: #262 - Improvements to other architecture - Use Illuminate's Auth\Access\Gate interface/implementation instead of our old Locked trait. We still use events to actually determine the permissions though. Our Policy classes are actually glorified event subscribers. - Extract model validation into Core\Validator classes. - Make post visibility permission stuff much more efficient and DRY. - Renamed Flarum\Event classes for consistency. ref #246 - `Configure` prefix for events dedicated to configuring an object. - `Get` prefix for events whose listeners should return something. - `Prepare` prefix when a variable is passed by reference so it can be modified. - `Scope` prefix when a query builder is passed. - Miscellaneous improvements/bug-fixes. I'm easily distracted! - Increase default height of post composer. - Improve post stream redraw flickering in Safari by keying loading post placeholders with their IDs. ref #451 - Use a PHP JavaScript minification library for minifying TextFormatter's JavaScript, instead of ClosureCompilerService (can't rely on external service!) - Use UrlGenerator properly in various places. closes #123 - Make Api\Client return Response object. closes #128 - Allow extensions to specify custom icon images. - Allow external API/admin URLs to be optionally specified in config.php. If the value or "url" is an array, we look for the corresponding path inside. Otherwise, we append the path to the base URL, using the corresponding value in "paths" if present. closes #244
This commit is contained in:
148
src/Database/MigrationCreator.php
Executable file
148
src/Database/MigrationCreator.php
Executable file
@@ -0,0 +1,148 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace Flarum\Database;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
|
||||
class MigrationCreator
|
||||
{
|
||||
/**
|
||||
* The filesystem instance.
|
||||
*
|
||||
* @var Filesystem
|
||||
*/
|
||||
protected $files;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $publicPath;
|
||||
|
||||
/**
|
||||
* Create a new migrator instance.
|
||||
*
|
||||
* @param Filesystem $files
|
||||
* @param string $publicPath
|
||||
*/
|
||||
public function __construct(Filesystem $files, $publicPath)
|
||||
{
|
||||
$this->files = $files;
|
||||
$this->publicPath = $publicPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new migration for the given extension.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $path
|
||||
* @param string $table
|
||||
* @param bool $create
|
||||
* @return string
|
||||
*/
|
||||
public function create($name, $extension = null, $table = null, $create = false)
|
||||
{
|
||||
$migrationPath = $this->getMigrationPath($extension);
|
||||
|
||||
$path = $this->getPath($name, $migrationPath);
|
||||
|
||||
$stub = $this->getStub($table, $create);
|
||||
|
||||
$this->files->put($path, $this->populateStub($extension, $name, $stub, $table));
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the migration stub file.
|
||||
*
|
||||
* @param string $table
|
||||
* @param bool $create
|
||||
* @return string
|
||||
*/
|
||||
protected function getStub($table, $create)
|
||||
{
|
||||
if (is_null($table)) {
|
||||
return $this->files->get($this->getStubPath().'/blank.stub');
|
||||
}
|
||||
|
||||
// We also have stubs for creating new tables and modifying existing tables
|
||||
// to save the developer some typing when they are creating a new tables
|
||||
// or modifying existing tables. We'll grab the appropriate stub here.
|
||||
$stub = $create ? 'create.stub' : 'update.stub';
|
||||
|
||||
return $this->files->get($this->getStubPath()."/{$stub}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate the place-holders in the migration stub.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $stub
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function populateStub($extension, $name, $stub, $table)
|
||||
{
|
||||
$replacements = [
|
||||
'{{namespace}}' => Str::studly($extension) ?: 'Flarum\Core',
|
||||
'{{name}}' => Str::studly($name),
|
||||
'{{table}}' => $table
|
||||
];
|
||||
|
||||
return str_replace(array_keys($replacements), array_values($replacements), $stub);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full path name to the migration directory.
|
||||
*
|
||||
* @param string $extension
|
||||
* @return string
|
||||
*/
|
||||
protected function getMigrationPath($extension)
|
||||
{
|
||||
$parent = $extension ? public_path().'/extensions/'.$extension : __DIR__.'/../..';
|
||||
|
||||
return $parent.'/migrations';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full path name to the migration.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
protected function getPath($name, $path)
|
||||
{
|
||||
return $path.'/'.$this->getDatePrefix().'_'.$name.'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date prefix for the migration.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDatePrefix()
|
||||
{
|
||||
return date('Y_m_d_His');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the stubs.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getStubPath()
|
||||
{
|
||||
return __DIR__.'/../../stubs/migrations';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user