A PHP library for simplifying the use of accessors.

Related tags

Laravel lib-accessor
Overview

Accessor

Build Status Coverage Status Latest Stable Version Total Downloads

A PHP library for simplifying the use of accessors.

Usage

use Doctrine\ORM\Mapping as ORM;
use Phine\Accessor\AccessorTrait;
use Phine\Accessor\Type\InstanceType;

/**
 * This is an example Doctrine entity class.
 *
 * @ORM\Entity()
 * @ORM\Table()
 */
class Address
{
    use AccessorTrait;

    /**
     * The country the address resides in.
     *
     * @var Country
     *
     * @ORM\JoinColumn(name="country")
     * @ORM\ManyToOne(targetEntity="Country")
     */
    private $country;

    /**
     * The unique identifier for this address.
     *
     * @var integer
     *
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Id()
     */
    private $id;

    /**
     * The state the address resides in.
     *
     * @var State
     *
     * @ORM\JoinColumn(name="state")
     * @ORM\ManyToOne(targetEntity="State")
     */
    private $state;

    /**
     * Configures the accessors.
     */
    public function __construct()
    {
        $this->makePropertyAccessible('country');
        $this->makePropertyAccessible('id');
        $this->makePropertyAccessible('state');

        $this->makePropertyMutable('country', new InstanceType('Country'));
        $this->makePropertyMutable('state', new InstanceType('State'));
    }
}

Now we make use of that example class:

// this all works just fine
$address = new Address();
$address->country = new Country();
$address->state = new State();

// these throw exceptions
$address->country = new State();
$address->id = 123;
$address->state = null;

Requirement

  • PHP >= 5.4

Installation

Via Composer:

$ composer require "phine/accessor=~1.0"

Documentation

You can find the documentation in the docs/ directory.

License

This library is available under the MIT license.

You might also like...
Laravel package to use the notion API

Package to work with Notion API from Laravel This package helps you to use the notion API from Laravel. Installation You can install the package via c

A package to easily make use of Iconic icons in your Laravel Blade views.
A package to easily make use of Iconic icons in your Laravel Blade views.

Blade Iconic A package to easily make use of Iconic icons in your Laravel Blade views. For a full list of available icons see the SVG directory. Iconi

A package to easily make use of Simple Icons in your Laravel Blade views.
A package to easily make use of Simple Icons in your Laravel Blade views.

Blade Simple Icons A package to easily make use of Simple Icons in your Laravel Blade views. For a full list of available icons see the SVG directory.

These projects are free for public use. Be a lesson for those who violate the rights of others!! ✌️

Faraz Kish Projects These projects are free for public use. Be a lesson for those who violate the rights of others!! ✌️ Brands Farazkish Uinvest MFina

Your users do not always report errors, LaraBug does. LaraBug is a simple to use and implement error tracker built for the Laravel framework.
Your users do not always report errors, LaraBug does. LaraBug is a simple to use and implement error tracker built for the Laravel framework.

Your users do not always report errors, LaraBug does. LaraBug is a simple to use and implement error tracker built for the Laravel framework. This rep

A simple to use opinionated ERP package to work with Laravel

Laravel ERP A simple to use opinionated ERP package to work with Laravel Installation You can install the package via composer: composer require justs

A collection of helper functions that I use across my projects.

A collection of helper functions that I use across my projects. This package includes some of the helper functions that I tend to use in all of my pro

Use auto generated UUID slugs to identify and retrieve your Eloquent models.

Laravel Eloquent UUID slug Summary About Features Requirements Installation Examples Compatibility table Alternatives Tests About By default, when get

Zarinpal is a laravel package to easily use zarinpal.com payment services in your applications
Zarinpal is a laravel package to easily use zarinpal.com payment services in your applications

پکیج اتصال به درگاه پرداخت زرین پال zarinpal.com برای اتصال به درگاه پرداخت اینترنتی زرین پال و استفاده از api های آن می توانید از این پکیج استفاده کن

Owner
KHerGe - Archived Projects
A collection of projects archived by kherge, but not deleted. Create a clone to continue a project.
KHerGe - Archived Projects
A package for simplifying the integration of a maker-checker approval process to your Laravel application.

prismaticoder/maker-checker-laravel The prismaticoder/maker-checker-laravel package is a comprehensive Laravel package that provides a flexible and cu

Jesutomiwa Salam 12 Jun 16, 2023
A super simple package allowing for use MySQL 'USE INDEX' and 'FORCE INDEX' statements.

Laravel MySQL Use Index Scope A super simple package allowing for use MySQL USE INDEX and FORCE INDEX statements. Requirements PHP ^7.4 | ^8.0 Laravel

Vasyl 29 Dec 27, 2022
A simple to use query builder for the jQuery QueryBuilder plugin for use with Laravel.

QueryBuilderParser Status Label Status Value Build Insights Code Climate Test Coverage QueryBuilderParser is designed mainly to be used inside Laravel

Tim Groeneveld 149 Nov 11, 2022
A Laravel package that allows you to use multiple ".env" files in a precedent manner. Use ".env" files per domain (multi-tentant)!

Laravel Multi ENVs Use multiple .envs files and have a chain of precedence for the environment variables in these different .envs files. Use the .env

Allyson Silva 48 Dec 29, 2022
Library that offers Input Filtering based on Annotations for use with Objects. Check out 2.dev for 2.0 pre-release.

DMS Filter Component This library provides a service that can be used to filter object values based on annotations Install Use composer to add DMS\Fil

Rafael Dohms 89 Nov 28, 2022
Stop duplicating your Eloquent query scopes and constraints in PHP. This package lets you re-use your query scopes and constraints by adding them as a subquery.

Laravel Eloquent Scope as Select Stop duplicating your Eloquent query scopes and constraints in PHP. This package lets you re-use your query scopes an

Protone Media 75 Dec 7, 2022
Barcode generator in PHP that is easy to use, non-bloated and framework independent.

PHP Barcode Generator This is an easy to use, non-bloated, framework independent, barcode generator in PHP. It creates SVG, PNG, JPG and HTML images,

Picqer 1.4k Jan 6, 2023
Collection of agnostic PHP Functions and helpers with zero dependencies to use as foundation in packages and other project

Collection of agnostic PHP Functions and helpers This package provides a lot of very usefull agnostic helpers to use as foundation in packages and oth

padosoft 54 Sep 21, 2022
Register for multiple Livestorm sessions from an external form. Practical use of Livestorm API with PHP/Javascript.

Livestorm Multi Session Registration Register for multiple Livestorm sessions from an external form. Practical use of Livestorm API with PHP/Javascrip

Nathan CHEVALIER 0 Dec 24, 2021
Laravel wrapper to use Lightship PHP

lightship-laravel Laravel wrapper to use Lightship PHP. Summary About Features Installation Examples Tests About Lightship is a way to get web page au

Lightship 3 Dec 11, 2022