Archive for January 2017

PHP Recursive function

  <?php   function recursive(&$myarray, $dir, $recursiveDir = null) {   $items = scandir($dir);   foreach ($items as $item) {   if ($item != "." && $item != "..") {   $file = $dir. DIRECTORY_SEPARATOR. $item;   if (is_dir($file)) { definitions($routes, $file, $file); } else { // get name of api $expl = explode(".", $item); […]

PHP Functional Programming, helper function, annonymous function, closure

  <?php $url = function($folder) use ($hostname) { return $hostname . DIRECTORY_SEPARATOR . $folder; };   $hostname = "https://" . $_SERVER[’SERVER_NAME’];   $myurl = $url(’pictures’); echo $myurl;   // output // https://www.aghayev.com/pictures

Stateless – when the application doesn’t save anything to the disk or to the RAM that is required to process future workloads. The benefit of stateless application is that it is possible to run multiple instances of an application in order to distribute workload and increase availability.

Sample transactional stored procedure

  CREATE DEFINER=`root`@`localhost` PROCEDURE `Sample`(IN inParameterID VARCHAR(10)) Sample:BEGIN   DECLARE httpStatus INT DEFAULT 500; DECLARE errorCode INT DEFAULT NULL; DECLARE errorDetails TEXT DEFAULT NULL;   DECLARE EXIT HANDLER FOR SQLEXCEPTION, SQLWARNING BEGIN ROLLBACK; SELECT 500 AS statusCode, ‘Failed’ AS statusMessage; END;   SET @variableID = 0;   SELECT TableA.ID INTO @variableID FROM TableA WHERE TableA.ParameterID […]

PHP PSR-4 and Namespaces

How-to add namespaces to old php project https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md Simple project with namespaces https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md

Bitbucket is good for free private repos Github is good for free public repos, for demonstration of your work

Difference between Strategy and Factory design patterns

A Strategy pattern is an operational pattern. Strategy pattern allows you to polymorphically change behavior of a class. Strategy pattern is to avoid conditionals switching in favor of polymorphism. So, Strategy pattern = polymorphism. A Factory pattern is a creational pattern. Factory pattern allows you to encapsulate object creation. Factory pattern = encapsulation. A difference […]