PHP ClassesPHP 7 Migration Guide Part 4: New Classes, Interfaces and New Global Constants (5.5.2016, 04:09 UTC)
By Atif Shahab Qureshi
In the previous part of this migration guide tutorial series it was covered new and changed functions in PHP 7.

But maybe more interesting to all developers that live and breathe Object Oriented Programming every day is what is new in terms of built-in classes and interfaces.

Read this article to learn not only about new classes and interfaces added in PHP 7 but also relevant global constants.
Link
SitePoint PHPBuilding a SparkPost Client: TDD with PhpUnit and Mockery (4.5.2016, 16:00 UTC)

In a previous post, we looked at SparkPost (as an alternative to Mandrill), and explored a bit of the official PHP client. The official client handles a decent amount of work, but I got to thinking about what it would take to build a new client.

The more I thought about it, the more it made sense. I could learn about the SparkPost API, and practice Test Driven Development at the same time. So, in this post we'll look to do just that!

Home page screenshot

You can find the code for this post on Github.

Getting Started

To begin, we're going to need Guzzle to make requests to the SparkPost API. We can install it with:

composer require guzzlehttp/guzzle

In addition, we're going to be writing tests early, so we should also install PHPUnit and Mockery:

composer require --dev phpunit/phpunit mockery/mockery

Before we can run PHPUnit, we need to create a configuration file:

<?xml version="1.0" encoding="UTF-8"?>

    
        
            tests
        
    
    
        
            src
        
    


This configuration file handles a number of things:

  1. Many of the root node attributes are sensible, intuitive defaults. The one I want to draw particular attention to is bootstrap: which tells PHPUnit to load Composer's autoload code.
  2. We tell PHPUnit to load all files ending in Test.php, in the tests folder. It will treat all files with this suffix as though they are class files with a single class each. If it can't instantiate any of the classes it finds (like abstract classes) then it will just ignore those.
  3. We tell PHPUnit to add all PHP files (from the src folder) to code coverage reporting. If you're unsure what that is, don't worry. We'll look at it in a bit...

We can now run:

vendor/bin/phpunit

... and we should see:

New phpunit screen

Continue reading %Building a SparkPost Client: TDD with PhpUnit and Mockery%

Link
PHP ClassesTurn Your WordPress Site into More Than One Blog with the Easy Content Types Plugin (4.5.2016, 04:07 UTC)
By Elma Dilaver Gheith
WordPress started as a blogging platform but thanks to many thousands of plugins, nowadays it can be practically anything else other than a blog.

The custom post types feature is very powerful because it can turn what would be a blog post page into anything, as long as you know how to take advantage of it or you can use a plugin to simplify your task.

Read this article to learn about the Easy Content Types plugin and you can use it to easily create new custom post types, taxonomies and meta boxes.
Link
Qafoo - PHPNever Use null (3.5.2016, 08:00 UTC)
When doing code reviews together with our customers we see a pattern regularly which I consider problematic in multiple regards – the usage of null as a valid property or return value. We can do better than this.
Link
PHP ClassesPHP Articles Report April 2016 Edition (3.5.2016, 05:34 UTC)
By Manuel Lemos
This is the April edition of the podcast hangout recorded by Manuel Lemos and Arturs Sosins to comment on the latest outstanding PHP Articles published recently.

They commented on articles about PHP source code protection solutions, the parallax WordPress theme, email verification solutions, PHP 7 backwards incompatible changes and new features, and fast debugging methods using PHPEd.

Listen to the podcast, or watch the hangout video to learn more about these PHP articles.
Link
PHP ClassesNotable PHP package: Scripd (3.5.2016, 04:31 UTC)
By Manuel Lemos
Every SQL database driven application needs to update the database schema once in a while to support new features.

This class can perform that process of generating SQL for database updates with elegance, as it allows developers to defined database schema additions in a JSON based file format, so it can work with different types of databases.

Since the format is based in JSON it can be used eventually by similar packages written in other languages.

Not only it supports the creation and modification of databases, tables and indexes, but it also supports triggers, views, stored procedures and functions.

Read this article to learn more details about how this notable PHP package works.
Link
Voices of the ElePHPantInterview with Rachel Baker (3.5.2016, 04:00 UTC) Link
PHP ClassesNotable PHP package: PHP Get All Words (30.4.2016, 20:34 UTC)
By Manuel Lemos
PHP provides an extensive set of functions to manipulate text strings including several ways to split a string into its words.

However, there is no built-in way to detect and exclude stop words.

This class can extract the words of a text excluding stop words. I can also consider words that may appear duplicated but with different case.

Read this article to learn more details about how this notable PHP package works.
Link
SitePoint PHPStarting a Business with Laravel Spark (29.4.2016, 16:00 UTC)

I am really excited about Laravel Spark. By the time you read this, there will probably be a multitude of posts explaining how you can set it up. That's not as interesting to me as the journey I'm about to take in creating an actual business with Spark!

The idea is simple. I have created a Pagekit module which you can use to back up and restore site data. The module makes it easy to store and download these backups, and restore them on different servers.

The trouble is, getting those backup files to the remote server takes time and a bit of hassle. I have often wanted a way to quickly and painlessly transfer this application state from one server to another, and make automated offsite backups. So I'm going to set that up for myself, and perhaps others will find it useful enough to pay for it.

Spark splash screen

Getting Started

I'm using Stripe, and intend to have a single plan with no trial. The setup for this is quite easy, but I've made a note of the plan ID. I'll need that to set the plan up in Spark...

Stripe welcome screen

Next, I reset my secret and public Stripe keys and update to the latest API (through the same screen, https://dashboard.stripe.com/account/apikeys).

I forgot that the settings in .env do not automatically reload while the Laravel development server is running, so I was getting needlessly frustrated at the keys which wouldn't seem to update.

Spark has a few expected registration/profile fields, but I want to add a few more. I would like to ask users if they would like automatic backups and I'd also like to collect their billing address, so I can show it on their invoice. First I'll have to create a migration for the new field:

php artisan make:migration add_should_backup_field

To do this, we can add the column (making sure to remove it if the migrations are rolled back):

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddShouldBackupField extends Migration
{
    public function up()
    {
        Schema::table("users", function (Blueprint $table) {
            $table->boolean("should_backup");
        });
    }

    public function down()
    {
        Schema::table("users", function (Blueprint $table) {
            $table->dropColumn("should_backup");
        });
    }
}

Continue reading %Starting a Business with Laravel Spark%

Link
Evert PotWriting SQL that works on PostgreSQL, MySQL and SQLite (28.4.2016, 08:56 UTC)

I am one of those crazy people who attempts to write SQL that works on SQlite, MySQL and PostgreSQL. First I should explain why:

This is all for my project sabre/dav. sabre/dav is a server for CalDAV, CardDAV and WebDAV. One of the big design goals is that it this project has to be a library first, and should be easily integratable into existing applications.

To do this effectively, it’s important that it’s largely agnostic to the host platform, and one of the best ways (in my opinion) to achieve that is to have as little dependencies as possible. Adding dependencies such as Doctrine is a great idea for applications or more opinionated frameworks, but for sabre/dav lightweight is key, and I need people to be able to understand the extension points fairly easily, without requiring them to familiarize them with the details of the dependency graph.

So while you are completely free to choose to add Doctrine or Propel yourself, the core adapters (wich function both as a default implementation and as samples for writing your own), all only depend on an instance of PDO.

The nice thing is that ORMs such as Doctrine and Propel, you can get access to the underlying PDO connection object and pass that, thus reusing your existing configuration.

For the longest time we only supported SQLite and MySQL, but I’m now working on adding PostgreSQL support. So I figured, I might as well write down my notes.

But how feasable is it to write SQL that works everywhere?

Well, it turns out that this is actually not super easy. There is such as thing as Standard SQL, but all of these databases have many of their own extensions and deviations.

The most important thing is that this will likely only work well for you if you have a very simple schema and simple queries.

Well, this blog post is not intended as a full guide, I’m just listing the particular things I’ve ran into. If you have your own, you can edit this blog post on github, or leave a comment.

My approach

  • I try to keep my queries as simple as possible.
  • If I can rewrite a query to work on every database, that query will have the preference.
  • I avoid stored procedures, triggers, functions, views. I’m really just dealing with tables and indexes.
  • Even if that means that it’s not the most optimal query. So I’m ok with sarcrificing some performance, if that means my queries can stay generic, within reason.
  • If there’s no possible way to do things in a generic way, I fall back on something like this:
<?php

if ($pdo->getAttribute(PDO::ATTR_DRIVER_NAME) === 'pgsql') {

    $query = "...";

} else {

    $query = "...';

}

$stmt = $pdo->prepare($query);


?>

DDL

First there is the “Data Definition Language” and “Data Manipulation Language” the former is used for queries starting with CREATE, ALTER, DROP, etc, and the latter SELECT, UPDATE, DELETE, INSERT.

There really is no sane way to generalize your CREATE TABLE queries, as the types and syntax are vastly different.

So for those we have a

Truncated by Planet PHP, read more at the original (another 16026 bytes)

Link
LinksRSS 0.92   RDF 1.
Atom Feed   100% Popoon
PHP5 powered   PEAR
ButtonsPlanet PHP   Planet PHP
Planet PHP