paulhenri-l/php-abstract-decorator

1.0.0 2021-10-02 17:25 UTC

This package is auto-updated.

Last update: 2024-10-29 06:13:00 UTC


README

PHP Tests PHP Code Style License: MIT

This abstract class helps you in creating decorators for your classes.

Installation

composer require paulhenri-l/php-abstract-decorator

Usage

<?php

class Person {
    public function talk()
    {
        return "hello";
    }

    public function name()
    {
        return "none";
    }
}

class LoudPerson extends \PaulhenriL\PhpAbstractDecorator\AbstractDecorator {
    public function talk(){
        return mb_strtoupper(
            $this->decoratedInstance->talk()
        );
    }
}

$person = new Person;
$loudPerson = new LoudPerson($person);

$loudPerson->talk(); // HELLO
$loudPerson->name(); // none