mcpField
L
laravel:template-method-and-plugins

laravel:template-method-and-plugins

github.com/jpcaparasDevelopment157111 installsUpdated 19w ago
Repository

About laravel:template-method-and-plugins

A Laravel development skill for structuring stable core flows with extension points. It covers Template Method and pluggable strategies, including registering implementations and selecting them by key or configuration.

Key features

  1. 01Template Method algorithm skeletons
  2. 02Subclass hook methods
  3. 03Interface-based strategies
  4. 04Registry-based implementation selection
  5. 05Isolated implementation testing

Use cases

  1. 01Keeping an import flow stable while varying steps
  2. 02Adding payment gateway implementations
  3. 03Replacing switch statements with registered classes

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/jpcaparas/superpowers-laravel --skill laravel:template-method-and-plugins

After installing, type/laravel:template-method-and-pluginsin Claude Code to confirm it loaded.

Details

From the project README

Template Method and Pluggable Strategies

Keep core flows stable; enable extension via small classes.

Template Method

Use a base class that defines the algorithm skeleton; subclasses override hooks.

abstract class Importer {
    final public function handle(string $path): void {
        $rows = $this->load($path);
        $data = $this->normalize($rows);
        $this->validate($data);
        $this->save($data);
    }
    abstract protected function load(string $path): array;
    protected function normalize(array $rows): array { return $rows; }
    protected function validate(array $data): void {}
    abstract protected function save(array $data): void;
}

Strategy/Plugin

Define an interface; register implementations; select by key/config.

interface PaymentGateway { public function charge(int $cents, string $currency): string; }

final class StripeGateway implements PaymentGateway { /* ... */ }
final class BraintreeGateway implements PaymentGateway { /* ... */ }

final class PaymentsRegistry {
    /** @param array<string,PaymentGateway> $drivers */
    public function __construct(private array $drivers) {}
    public function for(string $key): PaymentGateway { return $this->drivers[$key]; }
}

Prefer adding a class over editing switch statements. Test implementations in isolation.

Comments

Markdown supported