Category Archives: PHP

Introduction

Hi,

Today I decided to write about some Design Patters I’m currently studying for my future reference and I hope it’ll be helpful for you too.

Each post on this post series will be based on books, websites and my own code. I’ll show each external reference I’ll use.

To make it simple I’ll use ClassLoader from Symfony 2 Framework (in a composer dependency, installed easy as “composer install” command)

Source code will be available on github.com.

These are the patterns I’m intending to write about:

- Specification
- Strategy
- Decorator
- Chain of Responsibility
- Facade
- Abstract Factory
- Factory Method
- Template Method
- Adapter
- Bridge
- Composite
- Proxy
- Mediator
- Observer
- Visitor

Install Oracle Client on Ubuntu (PHP)

Download Instant Client on:
http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
- oracle-instantclient11.2-basic-11.2.0.3.0-1.i386.rpm
- oracle-instantclient11.2-devel-11.2.0.3.0-1.i386.rpm

Install alien to convert to rmp to deb package:

sudo apt-get install alien

Convert Packages:

sudo alien oracle-instantclient11.2-basic-11.2.0.3.0-1.i386.rpm
sudo alien oracle-instantclient11.2-devel-11.2.0.3.0-1.i386.rpm

Install client:

sudo dpkg -i oracle*.deb

Install Lib for PHP:

sudo pecl install oci8
sudo apt-get install libaio1

Refs:
https://help.ubuntu.com/community/Oracle%20Instant%20Client
http://vinteum.com/instalando-oci8-e-oracle-instant-client-no-ubuntu/
http://www.oracle.com/technetwork/topics/linuxsoft-082809.html

Add ” extension=oci8.so” to your php.ini

show full var_dump

Just update xdebug.ini file

xdebug.var_display_max_depth = -1
xdebug.var_display_max_children = -1
xdebug.var_display_max_data = -1

Refs:
http://stackoverflow.com/questions/9998490/how-to-get-xdebug-var-dump-to-show-full-object-array
http://xdebug.org/docs/all_settings#var_display_max_children

Catch SoapClient Exception

If you can’t get SoapClient exception if WSDL cant be loaded (PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn’t load from xxx)

Try this (before instantiating SoapClient):

xdebug_disable();

Found this solution up here:
https://bugs.php.net/bug.php?id=47584

Input is not proper UTF-8, indicate encoding (DOMDocument::loadXML)

Probably your XML string isn’t in UTF-8. Try this:

utf8_encode($xml);

Install composer

Composer is a dependency management for PHP and writen in PHP

curl -s https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin/
alias composer='/usr/local/bin/composer.phar'

Add PHPUnit to your Include Path (eclipse based IDE)

1 – Choose “Project” -> “Properties” or “Window” -> “Preferences” -> “PHP” (for global usage)
2 – Choose “PHP Include Path”
3 – Click on “Add External Source Folder” (typically PHPUnit is based on /usr/share/php/PHPUnit for linux distro)

Output while running (PHP)

ob_start();
for($i=0; $i<3; $i++)
{
   echo 'printing...';
   echo str_repeat(' ', 65536); // set a minimum output
 
   ob_flush();
   flush();
   usleep(300000);
}

Get only number from a string

preg_replace('/[^\d]/', '', $str);

Sum Businnes Day with PHP

function sum_business_day($date, $days) {
 
	list($year, $month, $day) = explode('-', $date);
 
	$business_day = 0;
	$add_day = 0;
 
	while ($add_day < $days) {
 
		$business_day++;
 
		$wday = gmdate('w', strtotime('+' . $business_day . ' day', mktime(0, 0, 0, $month, $day, $year)));
 
		if ($wday != 0 && $wday != 6) {
 
	            $add_day++;
		}
	}
 
	return gmdate('Y-m-d', strtotime('+ ' . $business_day . ' day', strtotime($date)));
}
Page 1 of 3123