mirror of
https://github.com/flarum/framework.git
synced 2024-11-28 20:16:08 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
ea29bd42d8
|
@ -14,6 +14,7 @@ before_script:
|
|||
|
||||
script:
|
||||
- vendor/bin/phpcs --standard=PSR2 -np src
|
||||
- vendor/bin/phpspec run
|
||||
|
||||
notifications:
|
||||
email:
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
"codeception/codeception": "~2.0.0",
|
||||
"codeception/mockery-module": "*",
|
||||
"laracasts/testdummy": "~2.0",
|
||||
"squizlabs/php_codesniffer": "2.*"
|
||||
"squizlabs/php_codesniffer": "2.*",
|
||||
"phpspec/phpspec": "^2.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
|
165
composer.lock
generated
165
composer.lock
generated
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "09afef66b65df77878c1bdd8d51b1eab",
|
||||
"hash": "6f47932716cfbd88646a021ea58c18b5",
|
||||
"packages": [
|
||||
{
|
||||
"name": "danielstjules/stringy",
|
||||
|
@ -856,7 +856,7 @@
|
|||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/tobscure/json-api/zipball/fe013caafe9ed0797b1b6abb116d514b301fbf1c",
|
||||
"url": "https://api.github.com/repos/tobscure/json-api/zipball/2629b6f48eb380973848c7e5fc36d41f33b305b3",
|
||||
"reference": "fe013caafe9ed0797b1b6abb116d514b301fbf1c",
|
||||
"shasum": ""
|
||||
},
|
||||
|
@ -1600,6 +1600,118 @@
|
|||
],
|
||||
"time": "2015-02-03 12:10:50"
|
||||
},
|
||||
{
|
||||
"name": "phpspec/php-diff",
|
||||
"version": "v1.0.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpspec/php-diff.git",
|
||||
"reference": "30e103d19519fe678ae64a60d77884ef3d71b28a"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpspec/php-diff/zipball/30e103d19519fe678ae64a60d77884ef3d71b28a",
|
||||
"reference": "30e103d19519fe678ae64a60d77884ef3d71b28a",
|
||||
"shasum": ""
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Diff": "lib/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Chris Boulton",
|
||||
"homepage": "http://github.com/chrisboulton",
|
||||
"role": "Original developer"
|
||||
}
|
||||
],
|
||||
"description": "A comprehensive library for generating differences between two hashable objects (strings or arrays).",
|
||||
"time": "2013-11-01 13:02:21"
|
||||
},
|
||||
{
|
||||
"name": "phpspec/phpspec",
|
||||
"version": "2.2.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpspec/phpspec.git",
|
||||
"reference": "e9a40577323e67f1de2e214abf32976a0352d8f8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpspec/phpspec/zipball/e9a40577323e67f1de2e214abf32976a0352d8f8",
|
||||
"reference": "e9a40577323e67f1de2e214abf32976a0352d8f8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"doctrine/instantiator": "^1.0.1",
|
||||
"php": ">=5.3.3",
|
||||
"phpspec/php-diff": "~1.0.0",
|
||||
"phpspec/prophecy": "~1.4",
|
||||
"sebastian/exporter": "~1.0",
|
||||
"symfony/console": "~2.3",
|
||||
"symfony/event-dispatcher": "~2.1",
|
||||
"symfony/finder": "~2.1",
|
||||
"symfony/process": "~2.1",
|
||||
"symfony/yaml": "~2.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"behat/behat": "^3.0.11",
|
||||
"bossa/phpspec2-expect": "~1.0",
|
||||
"phpunit/phpunit": "~4.4",
|
||||
"symfony/filesystem": "~2.1",
|
||||
"symfony/process": "~2.1"
|
||||
},
|
||||
"suggest": {
|
||||
"phpspec/nyan-formatters": "~1.0 – Adds Nyan formatters"
|
||||
},
|
||||
"bin": [
|
||||
"bin/phpspec"
|
||||
],
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.2.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"PhpSpec": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Konstantin Kudryashov",
|
||||
"email": "ever.zet@gmail.com",
|
||||
"homepage": "http://everzet.com"
|
||||
},
|
||||
{
|
||||
"name": "Marcello Duarte",
|
||||
"homepage": "http://marcelloduarte.net/"
|
||||
}
|
||||
],
|
||||
"description": "Specification-oriented BDD framework for PHP 5.3+",
|
||||
"homepage": "http://phpspec.net/",
|
||||
"keywords": [
|
||||
"BDD",
|
||||
"SpecBDD",
|
||||
"TDD",
|
||||
"spec",
|
||||
"specification",
|
||||
"testing",
|
||||
"tests"
|
||||
],
|
||||
"time": "2015-05-30 15:21:40"
|
||||
},
|
||||
{
|
||||
"name": "phpspec/prophecy",
|
||||
"version": "v1.4.1",
|
||||
|
@ -2841,6 +2953,55 @@
|
|||
"homepage": "https://symfony.com",
|
||||
"time": "2015-06-04 20:11:48"
|
||||
},
|
||||
{
|
||||
"name": "symfony/process",
|
||||
"version": "v2.7.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/Process.git",
|
||||
"reference": "48aeb0e48600321c272955132d7606ab0a49adb3"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/Process/zipball/48aeb0e48600321c272955132d7606ab0a49adb3",
|
||||
"reference": "48aeb0e48600321c272955132d7606ab0a49adb3",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.9"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/phpunit-bridge": "~2.7"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.7-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Component\\Process\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony Process Component",
|
||||
"homepage": "https://symfony.com",
|
||||
"time": "2015-07-01 11:25:50"
|
||||
},
|
||||
{
|
||||
"name": "symfony/yaml",
|
||||
"version": "v2.7.1",
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace spec\Flarum\Core\Settings;
|
||||
|
||||
use Flarum\Core\Settings\SettingsRepository;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MemoryCacheSettingsRepositorySpec extends ObjectBehavior
|
||||
{
|
||||
function let(SettingsRepository $inner)
|
||||
{
|
||||
$this->beConstructedWith($inner);
|
||||
}
|
||||
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('Flarum\Core\Settings\MemoryCacheSettingsRepository');
|
||||
}
|
||||
|
||||
function it_retrieves_data_from_inner(SettingsRepository $inner)
|
||||
{
|
||||
$settings = ['a' => 1, 'b' => 2];
|
||||
$inner->all()->willReturn($settings);
|
||||
$inner->all()->shouldBeCalled();
|
||||
|
||||
// Test fetching all settings
|
||||
$this->all()->shouldReturn($settings);
|
||||
|
||||
// Test fetching single settings
|
||||
$this->get('a')->shouldReturn(1);
|
||||
$this->get('b')->shouldReturn(2);
|
||||
|
||||
// Test invalid key
|
||||
$this->get('c')->shouldReturn(null);
|
||||
|
||||
// Test invalid key with custom default
|
||||
$this->get('d', 'foobar')->shouldReturn('foobar');
|
||||
}
|
||||
|
||||
function it_passes_new_data_to_inner(SettingsRepository $inner)
|
||||
{
|
||||
$this->set('a', 1);
|
||||
$inner->set('a', 1)->shouldHaveBeenCalled();
|
||||
}
|
||||
|
||||
function it_caches_new_data(SettingsRepository $inner)
|
||||
{
|
||||
$this->set('b', 2);
|
||||
$this->get('b')->shouldReturn(2);
|
||||
$inner->all()->shouldNotHaveBeenCalled();
|
||||
$inner->get('b')->shouldNotHaveBeenCalled();
|
||||
}
|
||||
}
|
|
@ -4,15 +4,12 @@ use Illuminate\Console\Command;
|
|||
use Illuminate\Foundation\Application;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Flarum\Core\Exceptions\ValidationFailureException;
|
||||
use Flarum\Core\Models\User;
|
||||
use Flarum\Core\Models\Discussion;
|
||||
use Flarum\Core\Models\DiscussionState;
|
||||
use Flarum\Core\Models\CommentPost;
|
||||
use Flarum\Core\Users\User;
|
||||
use Flarum\Core\Discussions\Discussion;
|
||||
use Flarum\Core\Discussions\DiscussionState;
|
||||
use Flarum\Core\Posts\CommentPost;
|
||||
use Flarum\Tags\Tag;
|
||||
use Flarum\Core\Events\PostWasPosted;
|
||||
use Flarum\Core\Events\UserWasRegistered;
|
||||
use Flarum\Core\Activity\JoinedActivity;
|
||||
use Flarum\Core\Posts\Events\PostWasPosted;
|
||||
use Symfony\Component\Console\Helper\ProgressBar;
|
||||
|
||||
class ImportCommand extends Command
|
||||
|
@ -23,7 +20,7 @@ class ImportCommand extends Command
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'flarum:import';
|
||||
protected $name = 'import';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
|
|
|
@ -18,10 +18,6 @@ class Core
|
|||
return $default;
|
||||
}
|
||||
|
||||
if (is_null($value = app('flarum.db')->table('config')->where('key', $key)->pluck('value'))) {
|
||||
$value = $default;
|
||||
}
|
||||
|
||||
return $value;
|
||||
return app('Flarum\Core\Settings\SettingsRepository')->get($key, $default);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php namespace Flarum\Core;
|
||||
|
||||
use Flarum\Core\Settings\MemoryCacheSettingsRepository;
|
||||
use Flarum\Core\Settings\DatabaseSettingsRepository;
|
||||
use Flarum\Core\Users\User;
|
||||
use Flarum\Support\ServiceProvider;
|
||||
use Flarum\Extend;
|
||||
|
@ -31,6 +33,14 @@ class CoreServiceProvider extends ServiceProvider
|
|||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->singleton('Flarum\Core\Settings\SettingsRepository', function() {
|
||||
return new MemoryCacheSettingsRepository(
|
||||
new DatabaseSettingsRepository(
|
||||
$this->app->make('Illuminate\Database\ConnectionInterface')
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
$this->app->singleton('flarum.forum', 'Flarum\Core\Forum');
|
||||
|
||||
// TODO: probably use Illuminate's AggregateServiceProvider
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
use Illuminate\Contracts\Validation\Factory;
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Flarum\Core\Exceptions\ValidationFailureException;
|
||||
use LogicException;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Flarum\Core;
|
||||
namespace Flarum\Core\Settings;
|
||||
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
|
||||
class DatabaseSettingsRepository implements SettingsRepositoryInterface
|
||||
class DatabaseSettingsRepository implements SettingsRepository
|
||||
{
|
||||
protected $database;
|
||||
|
||||
|
@ -13,6 +13,11 @@ class DatabaseSettingsRepository implements SettingsRepositoryInterface
|
|||
$this->database = $connection;
|
||||
}
|
||||
|
||||
public function all()
|
||||
{
|
||||
return $this->database->table('config')->lists('value', 'key');
|
||||
}
|
||||
|
||||
public function get($key, $default = null)
|
||||
{
|
||||
if (is_null($value = $this->database->table('config')->where('key', $key)->pluck('value'))) {
|
45
src/Core/Settings/MemoryCacheSettingsRepository.php
Normal file
45
src/Core/Settings/MemoryCacheSettingsRepository.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace Flarum\Core\Settings;
|
||||
|
||||
class MemoryCacheSettingsRepository implements SettingsRepository
|
||||
{
|
||||
protected $inner;
|
||||
|
||||
protected $isCached;
|
||||
|
||||
protected $cache = [];
|
||||
|
||||
public function __construct(SettingsRepository $inner)
|
||||
{
|
||||
$this->inner = $inner;
|
||||
}
|
||||
|
||||
public function all()
|
||||
{
|
||||
if (!$this->isCached) {
|
||||
$this->cache = $this->inner->all();
|
||||
$this->isCached = true;
|
||||
}
|
||||
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
public function get($key, $default = null)
|
||||
{
|
||||
if (array_key_exists($key, $this->cache)) {
|
||||
return $this->cache[$key];
|
||||
} else if (!$this->isCached) {
|
||||
return array_get($this->all(), $key, $default);
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
public function set($key, $value)
|
||||
{
|
||||
$this->cache[$key] = $value;
|
||||
|
||||
$this->inner->set($key, $value);
|
||||
}
|
||||
}
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Flarum\Core;
|
||||
namespace Flarum\Core\Settings;
|
||||
|
||||
interface SettingsRepositoryInterface
|
||||
interface SettingsRepository
|
||||
{
|
||||
public function all();
|
||||
|
||||
public function get($key, $default = null);
|
||||
|
||||
public function set($key, $value);
|
|
@ -1,5 +1,6 @@
|
|||
<?php namespace Flarum\Core\Users\Commands;
|
||||
|
||||
use Flarum\Core\Settings\SettingsRepository;
|
||||
use Flarum\Core\Users\PasswordToken;
|
||||
use Flarum\Core\Users\UserRepository;
|
||||
use Illuminate\Contracts\Mail\Mailer;
|
||||
|
@ -15,19 +16,31 @@ class RequestPasswordResetHandler
|
|||
*/
|
||||
protected $users;
|
||||
|
||||
/**
|
||||
* @var SettingsRepository
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* @var Mailer
|
||||
*/
|
||||
protected $mailer;
|
||||
|
||||
/**
|
||||
* @var UrlGeneratorInterface
|
||||
*/
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* @param UserRepository $users
|
||||
* @param SettingsRepository $settings
|
||||
* @param Mailer $mailer
|
||||
* @param UrlGeneratorInterface $url
|
||||
*/
|
||||
public function __construct(UserRepository $users, Mailer $mailer, UrlGeneratorInterface $url)
|
||||
public function __construct(UserRepository $users, SettingsRepository $settings, Mailer $mailer, UrlGeneratorInterface $url)
|
||||
{
|
||||
$this->users = $users;
|
||||
$this->settings = $settings;
|
||||
$this->mailer = $mailer;
|
||||
$this->url = $url;
|
||||
}
|
||||
|
@ -53,8 +66,8 @@ class RequestPasswordResetHandler
|
|||
// password route be part of core??
|
||||
$data = [
|
||||
'username' => $user->username,
|
||||
'url' => Core::config('base_url').'/reset/'.$token->id,
|
||||
'forumTitle' => Core::config('forum_title')
|
||||
'url' => $this->settings->get('base_url').'/reset/'.$token->id,
|
||||
'forumTitle' => $this->settings->get('forum_title'),
|
||||
];
|
||||
|
||||
$this->mailer->send(['text' => 'flarum::emails.resetPassword'], $data, function (Message $message) use ($user) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php namespace Flarum\Core\Users\Listeners;
|
||||
|
||||
use Flarum\Core\Settings\SettingsRepository;
|
||||
use Flarum\Core\Users\Events\UserWasRegistered;
|
||||
use Flarum\Core\Users\Events\UserEmailChangeWasRequested;
|
||||
use Flarum\Core;
|
||||
|
@ -11,16 +12,23 @@ use Illuminate\Mail\Message;
|
|||
|
||||
class EmailConfirmationMailer
|
||||
{
|
||||
/**
|
||||
* @var SettingsRepository
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* @var Mailer
|
||||
*/
|
||||
protected $mailer;
|
||||
|
||||
/**
|
||||
* @param SettingsRepository $settings
|
||||
* @param Mailer $mailer
|
||||
*/
|
||||
public function __construct(Mailer $mailer)
|
||||
public function __construct(SettingsRepository $settings, Mailer $mailer)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
$this->mailer = $mailer;
|
||||
}
|
||||
|
||||
|
@ -90,8 +98,8 @@ class EmailConfirmationMailer
|
|||
// email route be part of core??
|
||||
return [
|
||||
'username' => $user->username,
|
||||
'url' => Core::config('base_url').'/confirm/'.$token->id,
|
||||
'forumTitle' => Core::config('forum_title')
|
||||
'url' => $this->settings->get('base_url').'/confirm/'.$token->id,
|
||||
'forumTitle' => $this->settings->get('forum_title')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ use Flarum\Assets\AssetManager;
|
|||
use Flarum\Assets\JsCompiler;
|
||||
use Flarum\Assets\LessCompiler;
|
||||
use Flarum\Core;
|
||||
use Flarum\Core\Settings\SettingsRepository;
|
||||
use Flarum\Core\Users\User;
|
||||
use Flarum\Locale\JsCompiler as LocaleJsCompiler;
|
||||
use Flarum\Locale\LocaleManager;
|
||||
|
@ -61,14 +62,20 @@ abstract class ClientAction extends HtmlAction
|
|||
*/
|
||||
protected $locales;
|
||||
|
||||
/**
|
||||
* @var SettingsRepository
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* @param Client $apiClient
|
||||
* @param LocaleManager $locales
|
||||
*/
|
||||
public function __construct(Client $apiClient, LocaleManager $locales)
|
||||
public function __construct(Client $apiClient, LocaleManager $locales, SettingsRepository $settings)
|
||||
{
|
||||
$this->apiClient = $apiClient;
|
||||
$this->locales = $locales;
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -156,7 +163,7 @@ abstract class ClientAction extends HtmlAction
|
|||
$assets->addLess("@$name: $value;");
|
||||
}
|
||||
|
||||
$assets->addLess(Core::config('custom_less'));
|
||||
$assets->addLess($this->settings->get('custom_less'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -168,10 +175,10 @@ abstract class ClientAction extends HtmlAction
|
|||
protected function getLessVariables()
|
||||
{
|
||||
return [
|
||||
'fl-primary-color' => Core::config('theme_primary_color', '#000'),
|
||||
'fl-secondary-color' => Core::config('theme_secondary_color', '#000'),
|
||||
'fl-dark-mode' => Core::config('theme_dark_mode') ? 'true' : 'false',
|
||||
'fl-colored-header' => Core::config('theme_colored_header') ? 'true' : 'false'
|
||||
'fl-primary-color' => $this->settings->get('theme_primary_color', '#000'),
|
||||
'fl-secondary-color' => $this->settings->get('theme_secondary_color', '#000'),
|
||||
'fl-dark-mode' => $this->settings->get('theme_dark_mode') ? 'true' : 'false',
|
||||
'fl-colored-header' => $this->settings->get('theme_colored_header') ? 'true' : 'false'
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -11,13 +11,23 @@ class ExtensionsServiceProvider extends ServiceProvider
|
|||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Boot the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
// Extensions will not be registered if Flarum is not installed yet
|
||||
if (!Core::isInstalled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$extensions = json_decode(Core::config('extensions_enabled'), true);
|
||||
$config = $this->app->make('Flarum\Core\Settings\SettingsRepository')->get('extensions_enabled');
|
||||
$extensions = json_decode($config, true);
|
||||
$providers = [];
|
||||
|
||||
foreach ($extensions as $extension) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user