Skip to content

[NFR]: Assets which respect the base static URI from \Phalcon\Mvc\Url #16570

@mustafa519

Description

@mustafa519

Hello,

I am just migrating from 4.2 to 5.6. I see there are a lot of fixes, features that I wanted to congrat your hard work.

Is your feature request related to a problem? Please describe.

I was using assets manager efficiently. But now I have to use it something like that. Removing universal prefix support was really necessary? We were already able to define external targets that we could add our own prefixes by calling url service or something like that. That felt me weird and wanted to know if there is a decent reason behind.

# Common Assets
# -------------------------------------------- #
$this->assets
  ->collection('header')
  // ->setPrefix($this->url->getStatic())
  ->addCss($this->url->getStatic('css/bootstrap.min.css'))
  ->addCss($this->url->getStatic('css/style.css'))
  ->addCss($this->url->getStatic('css/module-'. $moduleName .'.css'))
  ->addJs($this->url->getStatic('js/livequery.js'));

In Phalcon 4.2, the only requirement was defining the assets manager like below:

$this->DI->setShared('assets', ['className' => 'Phalcon\Assets\Manager']);

But now I have to define all the services in the outer scope of the service definition, which is not efficient because they'll create another instance even if I might not use them in the request.

$ESCAPER = new \Phalcon\Html\Escaper();
$TAG_FACTORY = new \Phalcon\Html\TagFactory($ESCAPER);
$ASSETS = new Phalcon\Assets\Manager($TAG_FACTORY);

$this->DI->setShared('escaper', $ESCAPER);
$this->DI->setShared('assets', $ASSETS);

Describe the solution you'd like

  • I'd like to use assets manager in 5.6 like 4.2.
  • Assets are certainly related to TagFactory however, it requires strictly an argument which is not efficient if there are no any alternatives.
  • TagFactory also requires escaper instance which was annoyed that I might not need escaper at all.

I've ended up by doing below way that it works:

$this->DI->setShared('escaper', function ()
{
  return new \Phalcon\Html\Escaper();
});

$this->DI->setShared('tag', function ()
{
  return new \Phalcon\Html\TagFactory($this->getShared('escaper'));
});

$this->DI->setShared('assets', function ()
{
  return new \Phalcon\Assets\Manager($this->getShared('tag'));
});

That is not antipattern or something like that, right?

Mustafa,
Thanks.

Metadata

Metadata

Assignees

Labels

5.0The issues we want to solve in the 5.0 releasenew feature requestPlanned Feature or New Feature Request

Type

No type
No fields configured for issues without a type.

Projects

Status
Implemented

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions