cwola/attribute

PHP Attribute(Cwola library).

v1.0.1 2022-07-10 04:32 UTC

This package is auto-updated.

Last update: 2024-05-12 04:33:38 UTC


README

PHP Attribute(Cwola library).

Overview

Add "ReadableAttribute" and "WritableAttribute" for PHP.

Requirement

  • PHP8.0+

Installation

composer require cwola/attribute

Usage

  • Readable
<?php

use Cwola\Attribute\Readable;

class Foo {
    use Readable;

    /**
     * @var string
     */
    #[Readable]
    protected string $protectedString = 'Protected';
}

class Bar extends Foo {
    /**
     * @var string
     */
    protected string $override = 'OVER RIDE!!';

    /**
     * {@inheritDoc}
     */
    private function __read(string $name): mixed {
        return $this->override;
    }
}

$foo = new Foo;
echo $foo->protectedString;  // Protected
$foo->protectedString = 'modify';  // Error

$custom = new Bar;
echo $custom->protectedString;  // OVER RIDE!!
echo $custom->override;  // Error

Licence

MIT