phpf / common
Phpf Common package
Installs: 32
Dependents: 4
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
pkg:composer/phpf/common
Requires
- php: >=5.3
This package is not auto-updated.
Last update: 2025-11-08 22:36:30 UTC
README
Common class library, including a flexible autoloader and various containers.
Namespace: Phpf\Common
Dependencies: None
###Classes #####Containers
ContainerDataContainerEnhancedContainerEnhancedDataContainerSerializableContainerSerializableDataContainer
#####Registries
RegistryStaticRegistry
#####Other
AutoloaderClassAliaser
###About
####Containers Containers provide a generic object interface and are based on 4 core methods:
get($var)- Retrieve an item.set($var, $val)- Set an item.exists($var)- Return whether an item exists.remove($var)- Remove an item.
Containers also have the following additional methods:
import($vars)- Sets items from an associative array or iterable object.toArray($indexed = false)- Returns items as an array, optionally indexed.count()- ImplementsCountablegetIterator()- ImplementsIteratorAggregate.
Containers implement ArrayAccess and the four magic methods __get(), __set(), __isset(), and __unset(). Both the magic and array access methods are based on the four core methods, which means that subclasses only need to overwrite the 4 core methods.
#####Container
The Container class is the simplest type of container. Each item is a property - for example, $container->set('name', 'Jim') would set the object property name to Jim.
#####DataContainer
The DataContainer class has the same methods as the basic container; however, items are stored in a single array property data. Using the same example as above, the data container would instead add an array entry to its data property with key name and value Jim.
#####EnhancedContainer
The "enhanced" containers (EnhancedContainer and EnhancedDataContainer) simply allow callable properties to be added and then called as object methods, much like JavaScript.
For example:
$container = new \Phpf\Common\EnhancedContainer; $container->set('formalize', function ($last_name, $gender) { switch($gender) { case 'doctor': $pre = 'Dr.'; break; case 'male': $pre = 'Mr.'; break; case 'female': $pre = 'Ms.'; break; } return $pre.' '.$last_name; }); echo $container->formalize('Jones', 'male'); // prints "Mr. Jones"