Laravel

Magent 2 – Install via composer

This installation assumes that you have PHP, apache2, MySql, composer installed already. 1. Install via composer: composer create-project –repository=https://repo.magento.com/ magento/project-community-edition <install-directory-name> 2. Set file permissions cd <install-directory-name> sudo find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + sudo find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws […]

0 comments

PHP JSON_ENCODE – avoid backslash – hexadecimal – print pretty

Spent sometime to figure it out: json_encode($urlData, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);

0 comments

Chain pattern

require “vendor/autoload.php”; use Chain\HomeStatus; use Chain\Lock; use Chain\Lights; use Chain\Alarm; $lock = new Lock(); $lights = new Lights(); $alarm = new Alarm(); $lock->setSuccessor($lights); $lights->setSuccessor($alarm); $homeStatus = new HomeStatus(); $lock->check($homeStatus); echo PHP_EOL;

0 comments

Template pattern

use Temp\B; use Temp\C; require “vendor/autoload.php”; $b = new B(2,3); $b->compute(); $c = new C(2, 3); $c->compute();

0 comments

Strategy pattern

namespace Stra; use Stra\Logger; use Stra\DatabaseLogger; use Stra\FileLogger; class Strategy { public function log($msg, Logger $logger = null) { if(is_null($logger)) { $logger = new DatabaseLogger(); } $logger->log($msg); } } Test Drive require ‘vendor/autoload.php’; use Stra\Strategy; use Stra\FileLogger; use Stra\DatabaseLogger; $app = new Strategy(); $app->log(‘Some action happened.’, new FileLogger());

0 comments

Factory pattern

Code namespace Patterns; /** * Design pattern – Factory * * @author: Hazrat Ali * @mail: iloveyii@yahoo.com * Date: 2016-07-30 */ class ShapeFactory { private static $types = [‘Rectangle’, ‘Square’]; public static function create($type) { if( ! in_array($type, self::$types)) { die(‘Invalid type ‘ . $type . ‘, valid types are ‘ . implode(‘,’, self::$types) . […]

0 comments

SingletonX

Git repo namespace Patterns; /** * Design pattern – Singleton extended * The extended version contains an array of instances * * @author: Hazrat Ali * @mail: iloveyii@yahoo.com * Date: 2016-07-30 */ class SingletonX { private static $instances = []; private $dir = ‘tr’; private $language; private $translations; public function __construct($language) { $this->language = $language; […]

0 comments

Singleton pattern

Code The singleton pattern is used to restrict the creation of only object of a class. This is useful when it is expensive (in terms of resources) to initiate new objects every time the same object is needed. This pattern specifically put this logic of maintaining only one instance inside the class itself. This pattern […]

0 comments

PHP Startup: Unable to load dynamic library /usr/lib/php/20151012/mcrypt.so

You need to do the following steps to fix it. You need to change php version and library file name in the following command.   Find the files which is trying to load this library ( or any other ) grep -Hrv “;” /etc/php/7.0 | grep -E “extension(\s+)?=” | grep mcrypt Then comment out the […]

0 comments

Ubuntu PHP 7 install soap

sudo apt-get install php7.0-soap sudo systemctl restart apache2.service

0 comments

Ubuntu install PHP mail function

It is not installed by default so you have to install it and then a little configuration is required. sudo apt install sendmail The run the following command and choose Y for all the options. sudo sendmailconfig Now edit the host file: sudo nano /etc/hosts And add or edit as: 127.0.0.1    localhost localhost.localdomain your_machine_name To […]

0 comments

Ubuntu 16.04 – PhpStorm – configure xdebug with PHP 7.0

Today I spent a couple of hours to figure out that ONLY the following configuration works. It is not covered in any video/tutorial. This is the settings that MUST be added to all the files: [xDebug] zend_extension=/usr/lib/php/20160303/xdebug.so xdebug.default_enable=1 xdebug.idekey=PHPSTORM xdebug.remote_port=9000 xdebug.remote_enable=1 xdebug.remote_handler=dbgp xdebug.remote_autostart = on xdebug.remote_start = on xdebug.profiler_enable=1 xdebug.profiler_output_dir=/dev/null xdebug.remote_host=localhost     The files […]

1 comment

Web developement in 2016/17

The learning tree for web development. These tools, packages and techniques will be highly useful to any web developer in the future.

0 comments

perl: warning: Setting locale failed

Install the language pack by using the following command: sudo apt-get install language-pack-en-base Log off and login again.

0 comments