Download the PHP package arc/prototype without Composer
On this page you can find all versions of the php package arc/prototype. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download arc/prototype
More information about arc/prototype
Files in arc/prototype
Download arc/prototype
More information about arc/prototype
Files in arc/prototype
Vendor arc
Package prototype
Short Description ARC: prototypical inheritance component
License MIT
Homepage https://github.com/Ariadne-CMS/arc/wiki
Package prototype
Short Description ARC: prototypical inheritance component
License MIT
Homepage https://github.com/Ariadne-CMS/arc/wiki
Please rate this library. Is it a good library?
Informations about the package prototype
ARC: Ariadne Component Library
arc/prototype
This component adds prototypes to PHP, with all the javascript features like Object.extend, Object.assign, Object.freeze and Object.observe. It also has support for setters and getters, defined per property.
Create a prototype object
Adding properties
Adding methods
Extending objects
Quick create
Quick extend
Setters and Getters
If you only have a 'set' function, getting the value will always return 'null'. If you only have a 'get' function, setting the value will do nothing.
Finalizing objects
This will throw a \BadMethodCallException.
Sealing objects
This will throw a \LogicException
$isExtensible = \arc\prototype::isExtensible($object); // returns false
$isSealed = \arc\prototype::isSealed($object); // returns true
$isExtensible = \arc\prototype::isExtensible($object); // returns false
$isSealed = \arc\prototype::isSealed($object); // returns true
$isFrozen = \arc\prototype::isFrozen($object); // returns true
## Observing changes
Or limit the observer to specific types of changes:
If not set, the full list of change types will be observed: 'add','update','delete','reconfigure'.
## Setters, Getters and Superprivates
By using a variable that is not a property of the prototype object, but is in the scope of a number of the objects methods, you
can create something like a private property. But it is even more private than a normal private property, even other methods in this
object cannot access this variable. This is called a 'SuperPrivate' in javascript.
## Using arc\prototype as a Dependency Injection Container
Note: PHP has a limitation in that you can never bind a static function to an object. This will result in an uncatchable fatal error. To work around this, you must tell the prototype that a Closure is static, by prefixing the name with a ":". In that case the first argument to that method will always be the current object:
Static closure are all closures defined within a static function, or explicitly defined as static. Closures defined outside of a class scope can be bound and don't need this workaround.
## methods
### \arc\prototype::create
(object) \arc\prototype::create( (array) $properties )
Returns a new \arc\prototype\Prototype object with the given properties. The properties array may contain closures, these will be available as methods on the new Prototype object.
### \arc\prototype::extend
(object) \arc\prototype::extend( (object) $prototype, (array) $properties )
This returns a new Prototype object with the given properties, just like \arc\prototype::create(). But in addition the new object has a prototype property linking it to the original object from which it was extended.
Any methods or properties on the original object will also be accessible in the new object through its prototype chain.
You can check an objects prototype by getting the prototype property of a \arc\prototype\Prototype object. You cannot change this property - it is readonly. You can only set the prototype property by using the extend method.
### \arc\prototype::assign
(object) \arc\prototype::extend( (object) $prototype, (object) ...$objects )
This returns a new Prototype object with the given prototype set. In addition all properties on the extra objects passed to this method, will be copied to the new Prototype object. For any property that is set on multiple objects, the value of the property in the later object overwrites values from other objects.
### \arc\prototype::freeze
(void) \arc\prototype::freeze( (object) $prototype )
This makes changes to the given Prototype object impossible. The object
becomes immutable. Any attempt to change the
object will silently fail. The object is also sealed and no longer
extensible. The only way to unfreeze it is to clone the object. The clone
will be unfrozen, unsealed and open to extension.
### \arc\prototype::isFrozen
(bool) \arc\prototype::isFrozen( (object) $prototype )
Returns true if this object is frozen and thus immutable.
### \arc\prototype::seal
(void) \arc\prototype::seal( (object) $prototype )
This makes the object incapable of adding or removing properties, or
reconfiguring them. The object is no longer open to extensions as well.
The only way to unseal it is to clone it. The clone will be unsealed and
open to extension.
### \arc\prototype::isSealed
(bool) \arc\prototype::isSealed( (object) $prototype )
Returns true if this object is sealed and properties can no longer be
reconfigured, added or deleted.
### \arc\prototype::preventExtensions
(void) \arc\prototype::preventExtensions( (object) $prototype )
This makes the object incapable of adding properties or extending it.
### \arc\prototype::isExtensible
(bool) \arc\prototype::isExtensible( (object) $prototype )
Returns true if this object is open to extensions.
### \arc\prototype::observe
(void) \arc\prototype::observe( (object) $prototype, (Closure) $f )
This calls the Closure $f each time a property of $prototype is changed. The Closure is called with the prototype object, the name of the property and the new value.
If the closure returns false exactly (no other 'falsy' values will work), the change will be cancelled.
### \arc\prototype::unobserve
(void) \arc\prototype::unobserve( (object) $prototype, (Closure) $f )
This removes a specific observer function from a Prototype object. You must pass the exact same closure for this to work.
### \arc\prototype::getObservers
### \arc\prototype::hasProperty
(bool) \arc\prototype::hasProperty( (string) $propertyName )
Returns true if the requested property is available on the current Prototype object itself or any of its prototypes.
### \arc\prototype::keys
(array) \arc\prototype::keys( (object) $prototype )
### \arc\prototype::values
(array) \arc\prototype::values( (object) $prototype )
### \arc\prototype::entries
(array) \arc\prototype::entries( (object) $prototype )
### \arc\prototype::ownKeys
(array) \arc\prototype::ownKeys( (object) $prototype )
### \arc\prototype::ownValues
(array) \arc\prototype::ownValues( (object) $prototype )
### \arc\prototype::ownEntries
(array) \arc\prototype::ownEntries( (object) $prototype )
### \arc\prototype::hasOwnProperty
(bool) \arc\prototype::hasOwnProperty( (string) $propertyName )
Returns true if the requested property is available on the current Prototype object itself without checking its prototype chain.
### \arc\prototype::hasPrototype
(bool) \arc\prototype::hasPrototype( (string) $prototypeObject )
Returns true if the given object is part of the prototype chain of the current Prototype object.
### \arc\prototype::getDescendants
(array) \arc\prototype::getDescendants( (object) $prototype )
### \arc\prototype::getInstances
(array) \arc\prototype::getInstances( (object) $prototype )
### \arc\prototype::getPrototypes
(array) \arc\prototype::getPrototypes( (object) $prototype )
### \arc\prototype::memoize
(Closure) \arc\prototype::memoize( (callable) $f )
Returns a function that will only be run once. After the first run it will then return the value that run returned, unless that value is null. This makes it possible to create lazy loading functions that only run when used. You can also create shared objects in a dependency injection container.
This method doesn't guarantee that the given function is never run more than once - unless you only ever call it indirectly through the resulting closure.
All versions of prototype with dependencies
PHP Build Version
Package Version
Requires
php Version
>=7.1
The package arc/prototype contains the following files
Loading the files please wait ....