sikessem / capsule

πŸ“¦οΈ Encapsulate PHP Class properties using dynamic Getter and Setter.

Home Page:https://sikessem.github.io/packages/capsule

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sikessem-logo


php-icon packagist-version-icon packagist-download-icon license-icon actions-icon pr-icon twitter-icon


An Efficient Dependency Injector and Encapsulator

Capsule is a library that uses a Container to manage dependencies and objects in an organized and centralized way, thus facilitating encapsulation.

πŸ”– Contents

πŸ“‹ Requirements

  • Requires PHP 8.1+ (at least 8.1.14 recommended to avoid potential bugs).
  • Requires Composer v2+ to manage PHP dependencies.

⚑️ Installation

Install Capsule using Composer:

  • By adding the sikessem/capsule dependency to your composer.json file:

    {
        "require" : {
            "sikessem/capsule": "^0.5"
        }
    }
  • Or by including the dependency:

    composer require sikessem/capsule --no-dev

πŸ§‘β€πŸ’» Usage

  1. Define your custom components using Capsule's interfaces and traits:

    <?php
    
    namespace Sikessem\Capsule\Sample;
    
    use Sikessem\Capsule\Core\IsEncapsulated;
    
    interface CustomInterface extends IsEncapsulated
    {
        public function getName(): string;
    
        public function setName(string $name): void;
    }
    <?php
    
    namespace Sikessem\Capsule\Sample;
    
    final class CustomClass implements CustomInterface
    {
        use CustomTrait;
    
        public function __construct(string $name = 'World')
        {
            $this->setName($name);
        }
    }
    <?php
    
    namespace Sikessem\Capsule\Sample;
    
    use Sikessem\Capsule\Core\HasEncapsulator;
    
    trait CustomTrait
    {
        use HasEncapsulator;
    
        protected string $name;
    
        public function getName(): string
        {
            return $this->name;
        }
    
        public function setName(string $name): void
        {
            $this->name = $name;
        }
    }
  2. You can use your components as below:

    <?php
    
    use Sikessem\Capsule\Sample\CustomClass;
    
    $capsule = new CustomClass('Sikessem');
    
    isset($capsule->name); // Returns true
    
    echo $capsule->name; // Prints "Sikessem"
    
    unset($capsule->name); // Does nothing
    
    isset($capsule->name); // Returns true
    
    $capsule->value = 'value'; // Throws an exception
    
    $capsule->name = 'value'; // Set name to "value"
    
    echo $capsule->name; // Prints "value"
    
    $capsule->on('hello', function (?string $name = null) {
        return 'Hello '.($name ?? 'Sikessem').'!';
    });
    
    echo $capsule->hello(); //Prints "Hello Sikessem!"

πŸ‘ Contribution

The main purpose of this repository is to continue evolving Sikessem. We want to make contributing to this project as easy and transparent as possible, and we are grateful to the community for contributing bug fixes and improvements. Read below to learn how you can take part in improving Sikessem.

Sikessem has adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.

Read our Contributing Guide to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to Sikessem.

πŸ”’οΈ Good First Issues

We have a list of good first issues that contain bugs which have a relatively limited scope. This is a great place to get started, gain experience, and get familiar with our contribution process.

πŸ’¬ Discussions

Larger discussions and proposals are discussed in sikessem/community.

πŸ” Security Reports

If you discover a security vulnerability within Sikessem, please email SIGUI KessΓ© Emmanuel at contact@sigui.ci. All security vulnerabilities will be promptly addressed.


Made with ❀︎ by Sikessem.

About

πŸ“¦οΈ Encapsulate PHP Class properties using dynamic Getter and Setter.

https://sikessem.github.io/packages/capsule

License:MIT License


Languages

Language:PHP 100.0%