schranz-templating / templating

A template abstraction prototype for php template engines.
MIT License
24 stars 0 forks source link

Spiral framework integration #56

Closed butschster closed 1 year ago

butschster commented 1 year ago

Hi @alexander-schranz

I've tried to refactor some of Bootloaders for Spiral Framework. I tried to show you how it could be if I did it.

First of all, I don't understand the reason of using string nameslike 'schranz_templating.renderer.smarty' for container aliases. Why don't you use class names or interfaces?

$container->bindSingleton('schranz_templating.renderer.smarty', function (Container $container) {
      return new SmartyRenderer($container->get('smarty'));
});

When you bind closures into container you can request dependencies as function arguments. You don't need request container and then get dependencies from them.

$binder->bindSingleton(
    ViewFinderInterface::class,
    static function (BladeConfig $config, Filesystem $filesystem): ViewFinderInterface {
        return new FileViewFinder(
            $filesystem,
            $config->getPaths()
        );
    }
);

Spiral framework Bootloader can automatically load depended bootloaders before loading current.

final class SpiralViewBootloader extends Bootloader
{
    protected const DEPENDENCIES = [
        \Spiral\Views\Bootloader\ViewsBootloader::class
    ];
butschster commented 1 year ago

You don't need to merge the PR, it's just an example

alexander-schranz commented 1 year ago

@butschster

First of all, I don't understand the reason of using string nameslike 'schranz_templating.renderer.smarty' for container aliases.

I'm coming from a Symfony background where this is best practice for modules. The background there is that usage of a specific name avoids that a project accidentally overwrites a modules/bundle service, and defines more Interface more defines the public API.

But if you say that is not common in spiral I will definitely go the Spiral way here and avoid naming the services specific to the module.

When you bind closures into container you can request dependencies as function arguments. You don't need request container and then get dependencies from them.

Spiral framework Bootloader can automatically load depended bootloaders before loading current.

Thats are two really nice feature 👍

alexander-schranz commented 1 year ago

I could not push in your branch so I continued the changes here: https://github.com/schranz-templating/templating/pull/59

Thank you for this PR!