mirror of
https://github.com/flarum/core.git
synced 2025-08-15 04:44:08 +02:00
Apply fixes from StyleCI
[ci skip] [skip ci]
This commit is contained in:
@@ -111,8 +111,8 @@ class ForumServiceProvider extends AbstractServiceProvider
|
|||||||
}
|
}
|
||||||
}**/
|
}**/
|
||||||
|
|
||||||
$sources->addDirectory(__DIR__ . '/../../js/dist/forum');
|
$sources->addDirectory(__DIR__.'/../../js/dist/forum');
|
||||||
$sources->addDirectory(__DIR__ . '/../../js/dist/common');
|
$sources->addDirectory(__DIR__.'/../../js/dist/common');
|
||||||
|
|
||||||
$sources->addString(function () {
|
$sources->addString(function () {
|
||||||
return $this->container->make(Formatter::class)->getJs();
|
return $this->container->make(Formatter::class)->getJs();
|
||||||
@@ -120,7 +120,7 @@ class ForumServiceProvider extends AbstractServiceProvider
|
|||||||
});
|
});
|
||||||
|
|
||||||
$assets->css(function (SourceCollector $sources) {
|
$assets->css(function (SourceCollector $sources) {
|
||||||
$sources->addFile(__DIR__ . '/../../less/forum.less');
|
$sources->addFile(__DIR__.'/../../less/forum.less');
|
||||||
$sources->addString(function () {
|
$sources->addString(function () {
|
||||||
return $this->container->make(SettingsRepositoryInterface::class)->get('custom_less', '');
|
return $this->container->make(SettingsRepositoryInterface::class)->get('custom_less', '');
|
||||||
});
|
});
|
||||||
@@ -142,7 +142,7 @@ class ForumServiceProvider extends AbstractServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
$this->loadViewsFrom(__DIR__ . '/../../views', 'flarum.forum');
|
$this->loadViewsFrom(__DIR__.'/../../views', 'flarum.forum');
|
||||||
|
|
||||||
$this->container->make('view')->share([
|
$this->container->make('view')->share([
|
||||||
'translator' => $this->container->make(TranslatorInterface::class),
|
'translator' => $this->container->make(TranslatorInterface::class),
|
||||||
@@ -202,7 +202,7 @@ class ForumServiceProvider extends AbstractServiceProvider
|
|||||||
{
|
{
|
||||||
$factory = $this->container->make(RouteHandlerFactory::class);
|
$factory = $this->container->make(RouteHandlerFactory::class);
|
||||||
|
|
||||||
$callback = include __DIR__ . '/routes.php';
|
$callback = include __DIR__.'/routes.php';
|
||||||
$callback($routes, $factory);
|
$callback($routes, $factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -12,7 +12,6 @@ namespace Flarum\Frontend\Compiler;
|
|||||||
use axy\sourcemap\SourceMap;
|
use axy\sourcemap\SourceMap;
|
||||||
use Flarum\Frontend\Compiler\Source\FileSource;
|
use Flarum\Frontend\Compiler\Source\FileSource;
|
||||||
use Flarum\Frontend\Compiler\Source\FolderSource;
|
use Flarum\Frontend\Compiler\Source\FolderSource;
|
||||||
use Illuminate\Support\Arr;
|
|
||||||
|
|
||||||
class JsCompiler extends RevisionCompiler
|
class JsCompiler extends RevisionCompiler
|
||||||
{
|
{
|
||||||
@@ -25,14 +24,14 @@ class JsCompiler extends RevisionCompiler
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$directory = $this->name . '/';
|
$directory = $this->name.'/';
|
||||||
$mapFile = $file . '.map';
|
$mapFile = $file.'.map';
|
||||||
|
|
||||||
$map = new SourceMap();
|
$map = new SourceMap();
|
||||||
$map->file = $mapFile;
|
$map->file = $mapFile;
|
||||||
$output = [];
|
$output = [];
|
||||||
|
|
||||||
if (!$this->type) {
|
if (! $this->type) {
|
||||||
$output[] = 'var module={};';
|
$output[] = 'var module={};';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,24 +44,22 @@ class JsCompiler extends RevisionCompiler
|
|||||||
|
|
||||||
if ($source instanceof FolderSource) {
|
if ($source instanceof FolderSource) {
|
||||||
foreach ($content as $file) {
|
foreach ($content as $file) {
|
||||||
$filepath = $source->getPath() . '/' . $file;
|
$filepath = $source->getPath().'/'.$file;
|
||||||
if (is_dir($filepath)) {
|
if (is_dir($filepath)) {
|
||||||
$this->levelN($filepath, $source, $file);
|
$this->levelN($filepath, $source, $file);
|
||||||
} else {
|
} else {
|
||||||
if (pathinfo($filepath, PATHINFO_EXTENSION) !== 'js') {
|
if (pathinfo($filepath, PATHINFO_EXTENSION) !== 'js') {
|
||||||
$this->assetsDir->put($source->getDirectoryName() . '/' . $file, file_get_contents($filepath));
|
$this->assetsDir->put($source->getDirectoryName().'/'.$file, file_get_contents($filepath));
|
||||||
} else {
|
} else {
|
||||||
$content = file_get_contents($filepath);
|
$content = file_get_contents($filepath);
|
||||||
$cacheDifferentiator = hash('crc32b', serialize(array_merge($source->getCacheDifferentiator(), [$content])));
|
$cacheDifferentiator = hash('crc32b', serialize(array_merge($source->getCacheDifferentiator(), [$content])));
|
||||||
$this->putFile($source->getDirectoryName() . '/' . $file, $cacheDifferentiator, $content);
|
$this->putFile($source->getDirectoryName().'/'.$file, $cacheDifferentiator, $content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if ($source instanceof FileSource) {
|
if ($source instanceof FileSource) {
|
||||||
$sourceMap = $source->getPath() . '.map';
|
$sourceMap = $source->getPath().'.map';
|
||||||
|
|
||||||
if (file_exists($sourceMap)) {
|
if (file_exists($sourceMap)) {
|
||||||
$map->concat($sourceMap, $line);
|
$map->concat($sourceMap, $line);
|
||||||
@@ -77,14 +74,14 @@ class JsCompiler extends RevisionCompiler
|
|||||||
|
|
||||||
$cacheDifferentiator = hash('crc32b', serialize($output));
|
$cacheDifferentiator = hash('crc32b', serialize($output));
|
||||||
|
|
||||||
$this->putFile($this->name . '/' . $this->name .'-' . $this->type . '.js', $cacheDifferentiator, $output);
|
$this->putFile($this->name.'/'.$this->name.'-'.$this->type.'.js', $cacheDifferentiator, $output);
|
||||||
|
|
||||||
// Add a comment to the end of our file to point to the sourcemap
|
// Add a comment to the end of our file to point to the sourcemap
|
||||||
// we just constructed. We will then store the JS file and the map
|
// we just constructed. We will then store the JS file and the map
|
||||||
// in our asset directory.
|
// in our asset directory.
|
||||||
$output[] = '//# sourceMappingURL=' . $this->assetsDir->url($mapFile);
|
$output[] = '//# sourceMappingURL='.$this->assetsDir->url($mapFile);
|
||||||
|
|
||||||
$this->assetsDir->put($directory . $mapFile, json_encode($map, JSON_UNESCAPED_SLASHES));
|
$this->assetsDir->put($directory.$mapFile, json_encode($map, JSON_UNESCAPED_SLASHES));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -93,11 +90,11 @@ class JsCompiler extends RevisionCompiler
|
|||||||
{
|
{
|
||||||
$this->assetsDir->makeDirectory($file);
|
$this->assetsDir->makeDirectory($file);
|
||||||
foreach (array_diff(scandir($filepath), ['.', '..']) as $levelNFile) {
|
foreach (array_diff(scandir($filepath), ['.', '..']) as $levelNFile) {
|
||||||
$filepath2 = $filepath . '/' . $levelNFile;
|
$filepath2 = $filepath.'/'.$levelNFile;
|
||||||
if (is_dir($filepath2)) {
|
if (is_dir($filepath2)) {
|
||||||
$this->levelN($filepath2, $source, $file . '/' . $levelNFile);
|
$this->levelN($filepath2, $source, $file.'/'.$levelNFile);
|
||||||
} else {
|
} else {
|
||||||
$this->assetsDir->put($source->getDirectoryName() . '/' . $file . '/' . $levelNFile, file_get_contents($filepath2));
|
$this->assetsDir->put($source->getDirectoryName().'/'.$file.'/'.$levelNFile, file_get_contents($filepath2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,7 +104,7 @@ class JsCompiler extends RevisionCompiler
|
|||||||
*/
|
*/
|
||||||
protected function format(string $string): string
|
protected function format(string $string): string
|
||||||
{
|
{
|
||||||
return preg_replace('~//# sourceMappingURL.*$~m', '', $string) . "\n";
|
return preg_replace('~//# sourceMappingURL.*$~m', '', $string)."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,7 +114,7 @@ class JsCompiler extends RevisionCompiler
|
|||||||
{
|
{
|
||||||
parent::delete($file);
|
parent::delete($file);
|
||||||
|
|
||||||
if ($this->assetsDir->has($mapFile = $file . '.map')) {
|
if ($this->assetsDir->has($mapFile = $file.'.map')) {
|
||||||
$this->assetsDir->delete($mapFile);
|
$this->assetsDir->delete($mapFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -111,7 +111,7 @@ class RevisionCompiler implements CompilerInterface
|
|||||||
{
|
{
|
||||||
$revision = $this->getRevision();
|
$revision = $this->getRevision();
|
||||||
|
|
||||||
if (!$revision) {
|
if (! $revision) {
|
||||||
$this->commit();
|
$this->commit();
|
||||||
|
|
||||||
$revision = $this->getRevision();
|
$revision = $this->getRevision();
|
||||||
@@ -131,10 +131,10 @@ class RevisionCompiler implements CompilerInterface
|
|||||||
|
|
||||||
$urls = [];
|
$urls = [];
|
||||||
|
|
||||||
if (!empty($appResources[$this->type])) {
|
if (! empty($appResources[$this->type])) {
|
||||||
foreach ($appResources[$this->type] as $revision => $target) {
|
foreach ($appResources[$this->type] as $revision => $target) {
|
||||||
$ext = pathinfo($target, PATHINFO_EXTENSION);
|
$ext = pathinfo($target, PATHINFO_EXTENSION);
|
||||||
$file = substr_replace($target, '-' . $revision, -strlen($ext) - 1, 0);
|
$file = substr_replace($target, '-'.$revision, -strlen($ext) - 1, 0);
|
||||||
$urls[] = $this->assetsDir->url($file);
|
$urls[] = $this->assetsDir->url($file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -203,25 +203,24 @@ class RevisionCompiler implements CompilerInterface
|
|||||||
*/
|
*/
|
||||||
protected function putFile(string $location, $cacheDifferentiator, $content)
|
protected function putFile(string $location, $cacheDifferentiator, $content)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($this->assetsDir->has(static::REV_MANIFEST)) {
|
if ($this->assetsDir->has(static::REV_MANIFEST)) {
|
||||||
$manifest = json_decode($this->assetsDir->read(static::REV_MANIFEST), true);
|
$manifest = json_decode($this->assetsDir->read(static::REV_MANIFEST), true);
|
||||||
} else {
|
} else {
|
||||||
$manifest = [];
|
$manifest = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($manifest[$this->name])) {
|
if (! isset($manifest[$this->name])) {
|
||||||
$manifest[$this->name] = [];
|
$manifest[$this->name] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($manifest[$this->name][$this->type])) {
|
if (! isset($manifest[$this->name][$this->type])) {
|
||||||
$manifest[$this->name][$this->type] = [];
|
$manifest[$this->name][$this->type] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($location) {
|
if ($location) {
|
||||||
$ext = pathinfo($location, PATHINFO_EXTENSION);
|
$ext = pathinfo($location, PATHINFO_EXTENSION);
|
||||||
|
|
||||||
$filename = substr_replace($location, '-'.$cacheDifferentiator, -strlen($ext) - 1, 0);
|
$filename = substr_replace($location, '-'.$cacheDifferentiator, -strlen($ext) - 1, 0);
|
||||||
|
|
||||||
$this->assetsDir->put($filename, $content);
|
$this->assetsDir->put($filename, $content);
|
||||||
$manifest[$this->name][$this->type][$cacheDifferentiator] = $location;
|
$manifest[$this->name][$this->type][$cacheDifferentiator] = $location;
|
||||||
@@ -262,9 +261,9 @@ class RevisionCompiler implements CompilerInterface
|
|||||||
$path = $this->assetsDir->getAdapter()->getPathPrefix();
|
$path = $this->assetsDir->getAdapter()->getPathPrefix();
|
||||||
$files = array_diff(scandir($path), ['.', '..']);
|
$files = array_diff(scandir($path), ['.', '..']);
|
||||||
|
|
||||||
foreach($files as $file) {
|
foreach ($files as $file) {
|
||||||
if (!in_array($file, $this->ignoredItems)) {
|
if (! in_array($file, $this->ignoredItems)) {
|
||||||
$filePath = $this->assetsDir->getAdapter()->getPathPrefix() . '/' . $file;
|
$filePath = $this->assetsDir->getAdapter()->getPathPrefix().'/'.$file;
|
||||||
if (is_dir($filePath)) {
|
if (is_dir($filePath)) {
|
||||||
$this->assetsDir->deleteDirectory($file);
|
$this->assetsDir->deleteDirectory($file);
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user