Skip to content

Commit

Permalink
[#6] Fix assets directly call using Url::assert
Browse files Browse the repository at this point in the history
  • Loading branch information
cydrickn committed Apr 12, 2020
1 parent d92c647 commit b1c84e8
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Backend\Classes\WidgetBase;
use Config;
use Cyd293\BackendSkin\Listener\PluginEventSubscriber;
use Cyd293\BackendSkin\Router\UrlGenerator;
use Cyd293\BackendSkin\Skin\BackendSkin;
use Event;
use System\Classes\PluginBase;
Expand All @@ -17,7 +18,6 @@ class Plugin extends PluginBase
public function boot()
{
Config::set('cms.backendSkin', BackendSkin::class);

Event::subscribe(new PluginEventSubscriber());
WidgetBase::extendableExtendCallback(function (WidgetBase $widget) {
$origViewPath = $widget->guessViewPath();
Expand All @@ -29,7 +29,6 @@ public function boot()

public function registerComponents()
{

}

public function registerSettings()
Expand All @@ -38,6 +37,7 @@ public function registerSettings()

public function register()
{
$this->app->register(RoutingServiceProvider::class);
$this->registerConsoleCommand('cyd293.backendskin', Console\SetSkinCommand::class);
}

Expand Down
48 changes: 48 additions & 0 deletions RoutingServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Cyd293\BackendSkin;

use Cyd293\BackendSkin\Router\UrlGenerator;
use Illuminate\Support\ServiceProvider;

class RoutingServiceProvider extends ServiceProvider
{
public function register()
{
$this->registerUrlGenerator();
}

protected function registerUrlGenerator()
{
$this->app->singleton('url', function ($app) {
$routes = $app['router']->getRoutes();
$app->instance('routes', $routes);

$url = new UrlGenerator(
$routes,
$app->rebinding(
'request',
$this->requestRebinder()
)
);

$url->setSessionResolver(function () {
return $this->app['session'];
});

$app->rebinding('routes', function ($app, $routes) {
$app['url']->setRoutes($routes);
});

return $url;
});
}

protected function requestRebinder()
{
return function ($app, $request) {
$app['url']->setRequest($request);
};
}

}
30 changes: 30 additions & 0 deletions router/UrlGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Cyd293\BackendSkin\Router;

use Backend\Classes\Skin as AbstractSkin;
use October\Rain\Router\UrlGenerator as Base;
use Cyd293\BackendSkin\Classes\Skin;

class UrlGenerator extends Base
{
public function asset($path, $secure = null)
{
if (!starts_with($path, '/themes') && !starts_with($path, '/backendskins')) {
$publicSkinAssetPath = $this->getActiveSkin()->publicSkinPath . '/views/' . ltrim($path, '/');
$skinAssetPath = $this->getActiveSkin()->skinPath . '/views/' . ltrim($path, '/');
if (file_exists($skinAssetPath)) {
$path = $publicSkinAssetPath;
}
}
return parent::asset($path, $secure);
}

/**
* @return \Cyd293\BackendSkin\Skin\BackendSkin
*/
private function getActiveSkin()
{
return AbstractSkin::getActive();
}
}
2 changes: 2 additions & 0 deletions updates/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
1.1.0:
- Add separation of backendskin and theme
- Add new method on defining skin code
1.1.1:
- Fix Aseet Maker

0 comments on commit b1c84e8

Please sign in to comment.