2017 © Pedro Peláez
 

library common

Phpf Common package

image

phpf/common

Phpf Common package

  • Saturday, January 31, 2015
  • by wells5609
  • Repository
  • 1 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Common

Common class library, including a flexible autoloader and various containers., (*1)

Namespace: Phpf\Common, (*2)

Dependencies: None, (*3)

Classes

Containers
  • Container
  • DataContainer
  • EnhancedContainer
  • EnhancedDataContainer
  • SerializableContainer
  • SerializableDataContainer
Registries
  • Registry
  • StaticRegistry
Other
  • Autoloader
  • ClassAliaser

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., (*4)

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() - Implements Countable * getIterator() - Implements IteratorAggregate., (*5)

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., (*6)

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., (*7)

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., (*8)

EnhancedContainer

The "enhanced" containers (EnhancedContainer and EnhancedDataContainer) simply allow callable properties to be added and then called as object methods, much like JavaScript., (*9)

For example:, (*10)

$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"

The Versions

31/01 2015

dev-master

9999999-dev https://github.com/phpf/Common

Phpf Common package

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by The PHPf Developer

alias container common autoloader