2017 © Pedro Peláez
 

library commons

Util Library

image

phramz/commons

Util Library

  • Saturday, January 25, 2014
  • by Maximilian Reichel
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2,370 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 1 % Grown

The README.md

Phramz/Commons Build Status

Commons is a php-library that comes with some handy utilities to ease your daily coding-business., (*1)

Install

It's easy if you use composer!, (*2)

edit your composer.json, (*3)

``` json "require": { "phramz/commons": "*" }, (*4)


or via command line

php composer.phar require phramz/commons, (*5)



Examples ------ Picture this .... ``` php <?php use Phramz\Commons\Property\PropertyUtils; class Contact { private $email = 'info@phramz.com'; private $phone = '123' public function getEmail() { return $this->email; } public function setEmail($email) { $this->email = $email; } public function getPhone() { return $this->phone; } public function setPhone($phone) { $this->phone = $phone; } } class User { private $name = 'foo'; private $contact = null; public function __construct() { $this->contact = new Contact(); } public function getName() { return $this->name; } public function setName($name) { $this->name = $name; } public function getContact() { return $this->contact; } public function setContact(Contact $contact) { $this->contact = $contact; } } // get an instance of our User class $example = new User();

Now, maybe you want to access the private member name ``` php // get an instance of PropertyUtils $propertyUtils = new PropertyUtils();, (*6)

$propertyUtils->getProperty('name', $example); // will return 'foo', (*7)


Wow! Not very exciting, as long as you could call `getName()` directly, right!? But what if you have an abritary object and you do not know exactly if there is a public method `getName()` or maybe `name` is just a public member and therefore no need for getter? The object may not even have a member by the name of `name` and implements `ArrayAccess`? The `getProperty()` - method can deal with all of these usecases. Well, by the same way you can also set `name` to another value: ``` php // get an instance of PropertyUtils $propertyUtils = new PropertyUtils(); $propertyUtils->setProperty('name', 'bar', $example); $propertyUtils->getProperty('name', $example); // will now return 'bar' ... as well as $example->getName(); // ... will also return 'bar'

If you need to you can also access nested members like email at any depth by using the path seperator . ``` php // get an instance of PropertyUtils $propertyUtils = new PropertyUtils();, (*8)

$propertyUtils->getProperty('contact.email', $example); // will return 'info@phramz.com', (*9)


Do you need to deal with arrays? No problem at all: ``` php // if our User-object were an array it would look like this $example = array( 'name' => 'foo', 'contact' => array( 'email' => 'info@phramz.com', 'phone' => '123' ) ); // get an instance of PropertyUtils $propertyUtils = new PropertyUtils(); $propertyUtils->getProperty('name', $example); // will still return 'foo' $propertyUtils->getProperty('contact.email', $example); // will still return 'info@phramz.com'

There is one difference if you're working with arrays due these values are no references like objects. So if we want to set a new value to a member we need to save the manipulated array. ``` php // get an instance of PropertyUtils $propertyUtils = new PropertyUtils();, (*10)

// setProperty() will return the manipulated array, so we write it back to $example $example = $propertyUtils->setProperty('name', 'bar', $example);, (*11)

$propertyUtils->getProperty('name', $example); // will return 'bar' ... as well as $example->getName(); // ... will also return 'bar' ```, (*12)

That's it! I hope this peace of software will be helpful! Have fun!, (*13)

The Versions

25/01 2014

dev-master

9999999-dev https://github.com/phramz/commons

Util Library

  Sources   Download

LGPL v3

The Requires

  • php >=5.3

 

by Avatar Maximilian Reichel

stream util commons propertyutils propertywriter propertyreader

25/01 2014

v1.0.3

1.0.3.0 https://github.com/phramz/commons

Util Library

  Sources   Download

LGPL v3

The Requires

  • php >=5.3

 

by Avatar Maximilian Reichel

stream util commons propertyutils propertywriter propertyreader

25/01 2014

v1.0.2

1.0.2.0 https://github.com/phramz/commons

Util Library

  Sources   Download

LGPL v3

The Requires

  • php >=5.3

 

by Avatar Maximilian Reichel

stream util commons propertyutils propertywriter propertyreader

08/06 2013

v1.0.0

1.0.0.0 https://github.com/phramz/commons

Util Library

  Sources   Download

LGPL v3

The Requires

  • php >=5.3

 

by Avatar Maximilian Reichel

stream util commons propertyutils propertywriter propertyreader

08/06 2013

v1.0.1

1.0.1.0 https://github.com/phramz/commons

Util Library

  Sources   Download

LGPL v3

The Requires

  • php >=5.3

 

by Avatar Maximilian Reichel

stream util commons propertyutils propertywriter propertyreader