Giter Club home page Giter Club logo

yell's Introduction

#Yell Scrutinizer Code Quality Code Climate Latest Stable Version License

PHP package to make your objects strict and throw exception when you try to access or set some undefined property in your objects.

##Requirement PHP >= 5.3.0.

##Installation You can install the library using the following ways:

##Using Composer You can install this through Composer, a dependency manager for PHP. Just run the below command:

composer require zeeshanu/yell

For further details you can find the package at Packagist.

##Manual way

  • Copy src to your codebase, perhaps to the vendor directory.
  • Add the Zeeshanu\Yell\Scream class to your autoloader or require the file directly.

##Getting Started I'm going to create take an example to demonstrate the usage.

For example, you have a Person class like below:

class Person
{
    public $name;
    public $age;
}

$person = new Person();

$person->name = 'John Doe';
$person->age = 23;

// Will silently set the property `profession` on `Person` without any issue 
$person->profession = 'Teacher';

Here is how you can make your object strict i.e. not allow any other properties except $name and $age and throw exceptions for any other properties. Just use Zeeshanu\Yell\Scream trait in your class as follows

use Zeeshanu\Yell\Scream;

class Person
{
    use Scream;

    public $name;
    public $age;
}

$person = new Person();

$person->name = 'John Doe';
$person->age = 23;

// An exception will be thrown when showing message "Trying to set undefined property $profession in class Person"  
$person->profession = 'Teacher';

##Feedback If you notice that there might be some improvements in code you can create a pull request or report an issue. You can also contact me at [email protected].

License

The MIT License (MIT). Please see License File for more information.

yell's People

Contributors

adamnicholson avatar thekonz avatar ziishaned avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.