PHP code example of phramz / commons

1. Go to this page and download the library: Download phramz/commons library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phramz / commons example snippets


php composer.phar 
 php


use Phramz\Commons\Property\PropertyUtils;

class Contact
{
    private $email = '[email protected]';
    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();
 php
// get an instance of PropertyUtils
$propertyUtils = new PropertyUtils();

$propertyUtils->getProperty('name', $example); // will return 'foo'
 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'
 php
// get an instance of PropertyUtils
$propertyUtils = new PropertyUtils();

$propertyUtils->getProperty('contact.email', $example); // will return '[email protected]'
 php
// get an instance of PropertyUtils
$propertyUtils = new PropertyUtils();

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

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