Archive for the ‘php’ Category

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 […]

PHP PSR-1 Explained

Class names MUST be declared in StudlyCaps. Class constants MUST be declared in all UPPER_CASE with underscore separators. Method names MUST be declared in camelCase.

Swiftmailer sending email via gmail.com

  <?php   $transport = \Swift_SmtpTransport::newInstance(’smtp.gmail.com’,465) ->setUsername(’yourusername@yourdomain.com’) ->setPassword(’yourpassword’) ->setEncryption(’ssl’) ->setAuthMode(’login’);   $mailer = \Swift_Mailer::newInstance($transport);   $message = \Swift_Message::newInstance() ->setSubject(’Welcome’) ->setFrom(array(’yourusername@yourdomain.com’)) ->setTo(array(’to@to.com’)) ->setBody(’hello world’) ->setContentType("text/plain");   $mailer->send($message);

Silex Microframework structure points

1. A bootstrap (app/bootstrap.php) and application file (app/app.php) which could be used by my frontend controller, as well as by PHPUnit/Codeception 2. A web directory that is accessible for the world, containing only index.php and possibly some resources web/index.php

PSR-2 Conding standard checker

vendor/bin/php-cs-fixer fix path/to/folder –level="psr2" -v The –dry-run option displays the files that need to be fixed but without actually modifying them vendor/bin/php-cs-fixer fix path/to/file –level="psr2" –dry-run –diff -v

Php increase memory limit

<?php   ini_set(’memory_limit’,’2048M’);

Yii2 print ActiveRecord query sql output

<?php   echo $query->createCommand()->sql;

Php curl verbose

<?php   curl_setopt($f1, CURLOPT_VERBOSE, true);

Yii 2 Download a File

<?php   return Yii::$app->response->sendFile($fileName);

PHP sending email via gmail

apt-get install msmtp add gmail account to /etc/msmtp vi php.ini   sendmail_path = "/usr/bin/msmtp –logfile /var/log/msmtp_php/msmtp-php-cli.log -a gmail -t"