mirror of
https://github.com/flarum/core.git
synced 2025-08-18 06:11:23 +02:00
Merge branch 'master' into 1236-database-changes
This commit is contained in:
@@ -15,7 +15,9 @@ use Flarum\Extension\ExtensionManager;
|
||||
use Flarum\Frontend\Content\ContentInterface;
|
||||
use Flarum\Frontend\HtmlDocument;
|
||||
use Flarum\Group\Permission;
|
||||
use Flarum\Settings\Event\Deserializing;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
@@ -40,17 +42,25 @@ class AdminPayload implements ContentInterface
|
||||
* @param SettingsRepositoryInterface $settings
|
||||
* @param ExtensionManager $extensions
|
||||
* @param ConnectionInterface $db
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function __construct(SettingsRepositoryInterface $settings, ExtensionManager $extensions, ConnectionInterface $db)
|
||||
public function __construct(SettingsRepositoryInterface $settings, ExtensionManager $extensions, ConnectionInterface $db, Dispatcher $events)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
$this->extensions = $extensions;
|
||||
$this->db = $db;
|
||||
$this->events = $events;
|
||||
}
|
||||
|
||||
public function populate(HtmlDocument $document, Request $request)
|
||||
{
|
||||
$document->payload['settings'] = $this->settings->all();
|
||||
$settings = $this->settings->all();
|
||||
|
||||
$this->events->dispatch(
|
||||
new Deserializing($settings)
|
||||
);
|
||||
|
||||
$document->payload['settings'] = $settings;
|
||||
$document->payload['permissions'] = Permission::map();
|
||||
$document->payload['extensions'] = $this->extensions->getExtensions()->toArray();
|
||||
|
||||
|
@@ -1,64 +0,0 @@
|
||||
<?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\Extend;
|
||||
|
||||
use Flarum\Extension\Extension;
|
||||
use Flarum\Frontend\Asset\ExtensionAssets;
|
||||
use Flarum\Frontend\CompilerFactory;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
|
||||
class Assets implements ExtenderInterface
|
||||
{
|
||||
protected $frontend;
|
||||
|
||||
protected $css = [];
|
||||
protected $js;
|
||||
|
||||
public function __construct($frontend)
|
||||
{
|
||||
$this->frontend = $frontend;
|
||||
}
|
||||
|
||||
public function css($path)
|
||||
{
|
||||
$this->css[] = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public function asset($path)
|
||||
{
|
||||
return $this->css($path);
|
||||
}
|
||||
|
||||
public function js($path)
|
||||
{
|
||||
$this->js = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __invoke(Container $container, Extension $extension = null)
|
||||
{
|
||||
$container->resolving(
|
||||
"flarum.$this->frontend.assets",
|
||||
function (CompilerFactory $assets) use ($extension) {
|
||||
$assets->add(function () use ($extension) {
|
||||
return new ExtensionAssets($extension, $this->css, $this->js);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
94
src/Extend/Frontend.php
Normal file
94
src/Extend/Frontend.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?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\Extend;
|
||||
|
||||
use Flarum\Extension\Extension;
|
||||
use Flarum\Frontend\Asset\ExtensionAssets;
|
||||
use Flarum\Frontend\CompilerFactory;
|
||||
use Flarum\Http\RouteHandlerFactory;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
|
||||
class Frontend implements ExtenderInterface
|
||||
{
|
||||
protected $frontend;
|
||||
|
||||
protected $css = [];
|
||||
protected $js;
|
||||
protected $routes = [];
|
||||
|
||||
public function __construct($frontend)
|
||||
{
|
||||
$this->frontend = $frontend;
|
||||
}
|
||||
|
||||
public function css($path)
|
||||
{
|
||||
$this->css[] = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function js($path)
|
||||
{
|
||||
$this->js = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function route($path, $name, $content = null)
|
||||
{
|
||||
$this->routes[] = compact('path', 'name', 'content');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __invoke(Container $container, Extension $extension = null)
|
||||
{
|
||||
$this->registerAssets($container, $extension);
|
||||
$this->registerRoutes($container);
|
||||
}
|
||||
|
||||
private function registerAssets(Container $container, Extension $extension)
|
||||
{
|
||||
if (empty($this->css) && empty($this->js)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$container->resolving(
|
||||
"flarum.$this->frontend.assets",
|
||||
function (CompilerFactory $assets) use ($extension) {
|
||||
$assets->add(function () use ($extension) {
|
||||
return new ExtensionAssets(
|
||||
$extension, $this->css, $this->js
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private function registerRoutes(Container $container)
|
||||
{
|
||||
if (empty($this->routes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$routes = $container->make("flarum.$this->frontend.routes");
|
||||
$factory = $container->make(RouteHandlerFactory::class);
|
||||
|
||||
foreach ($this->routes as $route) {
|
||||
$routes->get(
|
||||
$route['path'], $route['name'],
|
||||
$factory->toForum($route['content'])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@@ -113,22 +113,8 @@ class Extension implements Arrayable
|
||||
|
||||
public function extend(Container $app)
|
||||
{
|
||||
$bootstrapper = $this->getBootstrapperPath();
|
||||
|
||||
if (! file_exists($bootstrapper)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$extenders = require $bootstrapper;
|
||||
|
||||
if (! is_array($extenders)) {
|
||||
$extenders = [$extenders];
|
||||
}
|
||||
|
||||
$extenders = array_flatten($extenders);
|
||||
|
||||
foreach ($extenders as $extender) {
|
||||
// If an extension has not yet switched to the new bootstrap.php
|
||||
foreach ($this->getExtenders() as $extender) {
|
||||
// If an extension has not yet switched to the new extend.php
|
||||
// format, it might return a function (or more of them). We wrap
|
||||
// these in a Compat extender to enjoy an unique interface.
|
||||
if ($extender instanceof \Closure || is_string($extender)) {
|
||||
@@ -274,9 +260,39 @@ class Extension implements Arrayable
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
public function getBootstrapperPath()
|
||||
private function getExtenders(): array
|
||||
{
|
||||
return "{$this->path}/bootstrap.php";
|
||||
$extenderFile = $this->getExtenderFile();
|
||||
|
||||
if (! $extenderFile) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$extenders = require $extenderFile;
|
||||
|
||||
if (! is_array($extenders)) {
|
||||
$extenders = [$extenders];
|
||||
}
|
||||
|
||||
return array_flatten($extenders);
|
||||
}
|
||||
|
||||
private function getExtenderFile(): ?string
|
||||
{
|
||||
$filename = "{$this->path}/extend.php";
|
||||
|
||||
if (file_exists($filename)) {
|
||||
return $filename;
|
||||
}
|
||||
|
||||
// To give extension authors some time to migrate to the new extension
|
||||
// format, we will also fallback to the old bootstrap.php name. Consider
|
||||
// this feature deprecated.
|
||||
$deprecatedFilename = "{$this->path}/bootstrap.php";
|
||||
|
||||
if (file_exists($deprecatedFilename)) {
|
||||
return $deprecatedFilename;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -46,10 +46,20 @@ class ExtensionAssets implements AssetInterface
|
||||
public function js(SourceCollector $sources)
|
||||
{
|
||||
if ($this->js) {
|
||||
$sources->addString(function () {
|
||||
return 'var module={}';
|
||||
});
|
||||
|
||||
if (is_callable($this->js)) {
|
||||
$sources->addString($this->js);
|
||||
} else {
|
||||
$sources->addFile($this->js);
|
||||
}
|
||||
|
||||
$sources->addString(function () {
|
||||
$name = $this->extension->getId();
|
||||
|
||||
return 'var module={};'.$this->getContent($this->js).";flarum.extensions['$name']=module.exports";
|
||||
return "flarum.extensions['$name']=module.exports";
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -65,11 +75,6 @@ class ExtensionAssets implements AssetInterface
|
||||
}
|
||||
}
|
||||
|
||||
private function getContent($asset)
|
||||
{
|
||||
return is_callable($asset) ? $asset() : file_get_contents($asset);
|
||||
}
|
||||
|
||||
public function localeJs(SourceCollector $sources, string $locale)
|
||||
{
|
||||
}
|
||||
|
@@ -40,6 +40,7 @@ class InstallServiceProvider extends AbstractServiceProvider
|
||||
'mbstring',
|
||||
'openssl',
|
||||
'pdo_mysql',
|
||||
'tokenizer',
|
||||
]),
|
||||
new WritablePaths([
|
||||
base_path(),
|
||||
@@ -53,8 +54,6 @@ class InstallServiceProvider extends AbstractServiceProvider
|
||||
$this->app->singleton('flarum.install.routes', function () {
|
||||
return new RouteCollection;
|
||||
});
|
||||
|
||||
$this->loadViewsFrom(__DIR__.'/../../views/install', 'flarum.install');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,6 +61,8 @@ class InstallServiceProvider extends AbstractServiceProvider
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->loadViewsFrom(__DIR__.'/../../views/install', 'flarum.install');
|
||||
|
||||
$this->populateRoutes($this->app->make('flarum.install.routes'));
|
||||
}
|
||||
|
||||
|
@@ -23,12 +23,37 @@ class WritablePaths extends AbstractPrerequisite
|
||||
public function check()
|
||||
{
|
||||
foreach ($this->paths as $path) {
|
||||
if (! is_writable($path)) {
|
||||
if (! file_exists($path)) {
|
||||
$this->errors[] = [
|
||||
'message' => 'The '.realpath($path).' directory is not writable.',
|
||||
'message' => 'The '.$this->getAbsolutePath($path).' directory doesn\'t exist',
|
||||
'detail' => 'This directory is necessary for the installation. Please create the folder.',
|
||||
];
|
||||
} elseif (! is_writable($path)) {
|
||||
$this->errors[] = [
|
||||
'message' => 'The '.$this->getAbsolutePath($path).' directory is not writable.',
|
||||
'detail' => 'Please chmod this directory'.($path !== public_path() ? ' and its contents' : '').' to 0775.'
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getAbsolutePath($path)
|
||||
{
|
||||
$path = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path);
|
||||
$parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
|
||||
$absolutes = [];
|
||||
|
||||
foreach ($parts as $part) {
|
||||
if ('.' == $part) {
|
||||
continue;
|
||||
}
|
||||
if ('..' == $part) {
|
||||
array_pop($absolutes);
|
||||
} else {
|
||||
$absolutes[] = $part;
|
||||
}
|
||||
}
|
||||
|
||||
return (substr($path, 0, 1) == '/' ? '/' : '').implode(DIRECTORY_SEPARATOR, $absolutes);
|
||||
}
|
||||
}
|
||||
|
@@ -277,7 +277,7 @@ class Gate implements GateContract
|
||||
|
||||
$result = call_user_func_array([$instance, 'before'], $beforeArguments);
|
||||
|
||||
// If we recieved a non-null result from the before method, we will return it
|
||||
// If we received a non-null result from the before method, we will return it
|
||||
// as the result of a check. This allows developers to override the checks
|
||||
// in the policy and return a result for all rules defined in the class.
|
||||
if (! is_null($result)) {
|
||||
|
@@ -38,7 +38,7 @@ class UserPolicy extends AbstractPolicy
|
||||
*/
|
||||
public function find(User $actor, Builder $query)
|
||||
{
|
||||
if ($actor->cannot('viewDiscussions')) {
|
||||
if ($actor->cannot('viewUserList')) {
|
||||
$query->whereRaw('FALSE');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user