Monday, May 12, 2014

PHP Design Patterns - The Observer Pattern

In this case class NoticeBoard is publisher and classes Student and Teacher are subscribers

<?php
class NoticeBoard{
  private $_observers = array();

  public function addNote( $name )  {
    foreach( $this->_observers as $obs )
      $obs->onChanged( $this, $name );
  }

  public function addObserver( $observer )  {
    $this->_observers []= $observer;
  }
}

class Student{
  public function onChanged( $sender, $args )  {
    echo("The ".__CLASS__." is informed '$args' \n" );
  }
}

class Teacher{
  public function onChanged( $sender, $args )  {
    echo( "The ".__CLASS__." is informed '$args' \n" );
  }
}

$s = new Student(); 
$t = new Teacher();

$nb = new NoticeBoard(); 
$nb -> addObserver($s); 
$nb -> addObserver($t);

$nb->addNote('Due storm exams are postponed.');
?>

Result is
The Student is informed 'Due storm exams are postponed.'
The Teacher is informed 'Due storm exams are postponed.'

Thursday, March 27, 2014

Consuming SOAP services

Full web service description is at http://www.webservicex.net/ws/WSDetails.aspx?CATID=12&WSID=64
Yellow highlighted portion is SOAP Web Service URI
Green Highlighted portion is the method name.

Monday, March 24, 2014

Post installation tasks on CentOS regarding Apache web server

This is a short troubleshooting guide for system administrators. Almost all tasks described in this post should be done as root. You need to be familiar with basic Linux commands / editors such as cat, vi, chmod and chown.

Wednesday, March 19, 2014

One Way Encryption with Crypt Function and Salt

This tutorial shows how to hash passwords with random string as salt using Blowfish algo and PHP's function Crypt.

Wednesday, March 12, 2014

Most Useful PHP Snippets

Dumping arrays or objects with HTML markup text as member. This prevents creating iFrame and similar tags in your debug output.

Monday, March 10, 2014

Git Workflow for Local and Remote Repository

Typical workflow for two developer that clone/fetch/push to a remote git repo. Each developer use one tracking branch. Once changes are pushed to remote repo we use rebase twice to merge the local branches into the master branch.

Tuesday, March 4, 2014

Git resolving conflict on remote machine

Git conflict resolution on remote server after two branches merging into master branch
Branches are master, armand and ralph.