Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mustafa519 opened this issue Apr 20, 2024 · 0 comments
Open
Labels
new feature request Planned Feature or New Feature Request

Comments

@mustafa519
Copy link

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.

@mustafa519 mustafa519 added the new feature request Planned Feature or New Feature Request label Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature request Planned Feature or New Feature Request
Projects
None yet
Development

No branches or pull requests

1 participant