Download the PHP package serafim/properties without Composer
On this page you can find all versions of the php package serafim/properties. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download serafim/properties
More information about serafim/properties
Files in serafim/properties
Package properties
Short Description PHP properties implementation
License MIT
Homepage http://github.io/SerafimArts/Properties
Informations about the package properties
PHP Properties
PHP Properties implementations based on getters or setters method and used PSR-5 PHPDoc information.
- Installation
- Introduction
- Properties Usage
- Readonly Properties
- Writeonly Properties
- Getters And Setters
- Autocomplete
- Type Hints
- Primitive Type Hints
- Arrays And Generics
- Conjunction And Disjunction
- Production Mode
Installation
composer require serafim/properties
Introduction
Properties provide the ability to control the behavior of setting and retrieving data from an object fields.
There are no properties at the language level, but they can be implemented with the some additional functionality.
For example:
This code example does not provide type-hint and autocomplete. Using magic without the ability to control it is always a bad option. ...well, it looks awful %)
We can fix some problems using PSR-5. In this case, we can add a docblock.
But this docblock only adds information for the IDE and does not affect the code itself. At the same time, you should always keep it up to date.
But wait! We have another problem.
This is obviously a bug. We still need to add __isset
, __unset
and __set
support.
It's damn awful!!111
Properties Usage
Now let's see what the serafim/properties
package provides.
Readonly Properties
To indicate that the type should be readonly use @property-read
annotation.
Writeonly Properties
To indicate that the type should be readonly use @property-write
annotation.
Getters And Setters
For getter or setter override just declare get[Property]
(is[Property]
for bool
values will be works too) or set[Property]
methods.
Setter:
Autocomplete
All these annotations fully work in the IDE, including autocomplete and highlighting incorrect behavior.
Type Hints
All properties with writeable behavior will be "type checkable".
Primitive Type Hints
int
(orinteger
) - property value are integerbool
(orboolean
) - value are booleanfloat
(ordouble
) - value are floatstring
- value are string or object with__toString
methodnull
(orvoid
) - value are nullableresource
- value are resourceobject
- value can be any objectmixed
- no type checkingcallable
- value can be string, instance of \Closure, array with 2 args or object with__invoke
methodscalar
- value cannot be an objectcountable
- value can be a countable (array or object providedCountable
interface).-
self
- value can be object of self class or string with name of self classself
keyword does not available yet: it will be supports in future -
static
- value can be instance of self class or string whos are sublass of selfstatic
keyword does not available yet: it will be supports in future $this
- value can be only object instance of self class$this
keyword does not available yet: it will be supports in future
Arrays And Generics
array
- value is type of arrayClass[]
- value is type of array or instance of \Traversablescalar[]
- value is type of array or instance of \TraversableCollection<>
- value is type of array or instance of "Collection" and \TraversableCollection<T>
- value is type of array or instance of "Collection" and \TraversableCollection<T,V>
- value is type of array or instance of "Collection" and \Traversable
Conjunction And Disjunction
a|b
- means that the value must be type(a or b)
.a&b
- means that the value must be type(a and b)
.a|b&c
- means that the value must be type(a or (b and c))
.
See more: https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc.md#appendix-a-types
Production Mode
The code is quite effective, but in the production mode you should use caching. The package implements support for the PSR-16 standard.
All versions of properties with dependencies
railt/parser Version 1.2.*
railt/lexer Version 1.2.*
psr/simple-cache Version ~1.0