IBM Developer Blog: Get Started With CouchDB Using PHP and Guzzle

On the IBM Developer Blog they’ve posted a new article from Lorna Mitchell helping you get started with CouchDB and Guzzle, making use of this popular HTTP client package to interface with CouchDB’s HTTP interface quickly and easily.

In today’s post, we’ll look at how we can use CouchDB in our PHP applications, using the excellent PHP HTTP library Guzzle. Guzzle is a modern, PSR-7 compliant object-oriented PHP library that handles all aspects of HTTP in a correct and — importantly, a scalable — way. So it’s a great way to add any HTTP-interfaced services into your application (PHP 5.5 and later, does support PHP 7).

She then starts off with the installation of Guzzle via Composer and some sample code to make the initial connection to the CouchDB server (either local or remote). With the connection up and working and a "welcome" banner returned, she shows some simple operations like:

  • getting a list of all databases
  • creating a new database
  • inserting and selecting data
  • updating and deleting data

Code is provided for each of these and, thankfully, Guzzle makes it a pretty simple process and handles most of the heavy lifting on the HTTP requests for you.

PHPDeveloper.org

PHP.net: PHP 5.6.24 & 5.5.38 Released

The PHP development group has posted the official release announcements for the latest versions in the PHP 5.6.x and 5.5.x series: PHP 5.6.24 and PHP 5.5.38.

The PHP development team announces the immediate availability of PHP [5.6.24 and 5.6.38]. This is a security release. Several security bugs were fixed in this release. All PHP 5.6 users are encouraged to upgrade to this version.

They also have a quick note that this release for the PHP 5.5.x series is the last in the branch as laid out by the release schedule. Future updates on this branch will only be made if there are major security issues found. Otherwise developers are encouraged to upgrade to the latest versions (5.6.x at the least but really PHP 7.x would be better). You can get these latest releases either from the main downloads page (source) or from windows.php.net for the Windows binaries.

PHPDeveloper.org

Site News: Blast from the Past – One Year Ago in PHP (07.21.2016)

Here’s what was popular in the PHP community one year ago today:

  • Easy Laravel Book: How Laravel 5 Prevents SQL Injection, CSRF, and XSS
  • Barry vd. Heuvel: OAuth in Javascript Apps with Angular and Lumen, using Satellizer and Laravel Soci
  • Remi Collet: New „remi-php70“ repository
  • Simon Holywell: International PHP dates with intl
  • Andrew Embler: Creating a Z-Ray Plugin for Zend Server 8.5
  • Freek Van der Herten: Speed up a Laravel app by caching the entire response
  • Lorna Mitchell: Test Your PHP Application on PHP 7
  • Sameer Borate: Cron Expression Parser in PHP
  • Paragon Initiative: Implementing Secure User Auth in PHP Applications with Long-Term Persistence
  • Simon Holywell: PHP date localisation with setlocale
  • NetTuts.com: Understand Overriding in Magento: Controllers
  • Rob Allen: Custom OAuth2 authentication in Apiiglity
  • BitExpert Blog: Think About It: PHP/PostgreSQL Bulk Performance (Part 3)
  • SitePoint PHP Blog: Defensive Programming in PHP
  • MyBuilder Tech Blog: Insertion, Removal and Inversion Operations on Binary (Search) Trees in PHP
  • Facebook HipHop Open Source Blog: Under the hood: Box’s HHVM migration
  • Tideways.io: 5 Ways to optimize Symfony Baseline Performance
  • SitePoint PHP Blog: Validating your data with Respect Validation
  • Matthew Setter: PHP South Coast 2015
  • Voices of the ElePHPant: Interview with Jacques Woodcock

    PHPDeveloper.org

  • TutsPlus.com: How to Program With Yii2: Uploading Files

    On the TutsPlus.com site there’s a new installment in their "How to Program With Yii2 Series" looking at implementing file uploads with some simple examples.

    In this How to Program With Yii2 series, I’m guiding readers in use of the Yii2 Framework for PHP. In this tutorial, I’ll guide you through the basics of uploading files and images in Yii2.

    For these examples, we’ll continue to imagine we’re building a framework for posting simple status updates, e.g. our own mini-Twitter. The image above demonstrates writing a short update while uploading a picture I took of the Taj Mahal.

    They start with a look at some of the file upload plugins that seemed like the best they found to use with Yii2: FileInput and the 2Amigos BlueImp File Uploader. They go with the first option for the rest of the tutorial, showing you how to get it installed (via Composer), updating your current database tables and changing the model to reflect these updates. Next they help you create the view with the image upload form and one to display the image result once the upload is successful (including the controller code needed).

    PHPDeveloper.org

    Loïc Faugeron: Mars Rover, Landing orientation

    Loïc Faugeron is back again with the next part of his "Mars Rover" series of tutorials. In this new article he refactors the current code even more to make it more flexible in the long run.

    In this series we’re going to build the software of a Mars Rover, according to the following specifications. It will allow us to practice the followings: Monolithic Repositories (MonoRepo), Command / Query Responsibility Segregation (CQRS), Event Sourcing (ES) and Test Driven Development (TDD). Previously we’ve created a navigation package, and in it a LandRover class that validates input parameters for our first use case.

    We’ve also started to refactor it by extracting coordinates in their own class. In this article we’re going to further refactor LandRover

    He found that the coordinates could become floats (or have additional values) and that the orientation could become an angular degree/be vertical. To help this situation, he pulls this logic out into an Orientation class. True to the TDD methods, he starts with the phpspec test and generates the skeleton class based on them. He makes some simple edits to make the tests pass and updates the main LandRover class to use the new Orientation class for these positions.

    PHPDeveloper.org

    PHP.net: PHP 7.1.0 Alpha 3 Released

    The PHP development group has officially announced the release of the latest alpha in the PHP 7.1.x series: PHP 7.1.0 Alpha 3. This is a preview release and should not be used for production applications.

    The PHP development team announces the immediate availability of PHP 7.1.0 Alpha 3. This release is the last alpha for 7.1.0. All users of PHP are encouraged to test this version carefully, and report any bugs and incompatibilities in the bug tracking system.

    This release includes new features including an Iterable type, HTTP/2 server push support, creating closures from callables and more precise float values. You can see the full list of additions and changes in the NEWS and UPGRADING files. If you’re interested in trying out this latest alpha, you can get the latest source release from here and the Windows binaries here.

    PHPDeveloper.org

    QaFoo Blog: Outside-In Testing and the Adapter and Facade Patterns

    The QaFoo blog has a post today about outside-in testing, two design patterns – Adapter and Facade – and how they relate.

    As part of our workshops on Test-Driven Development we explain to our customers how testing from the outside-in can help find the right test-mix.

    The technique puts a focus on test-driven-development, but instead of the traditional approach starts at the acceptance test level. The first test for a feature is an acceptance test and only then the feature is implemented from the outside classes first. […] Outside-In testing leads to interfaces that are written from what is useful for the client object using them, in contrast to objects that are composed of collaborators that already exist. Because at some point we have to interact with objects that exist already, we will need three techniques to link those newly created interfaces/roles to existing code in our project

    These three techniques are:

    • using the adapter pattern to interface with third party code
    • the facade pattern to "layer" your own code
    • continuous refactoring of interfaces/implementations

    In this post they focus mostly on the adapter pattern. They show how to use it in interfacing with remote systems in a Symfony application (for example) based on a remote XML file. They also include the test to verify it’s functioning correctly and the PHP code to make the mocks and interfaces you’ll need for the test.

    PHPDeveloper.org

    php[architect]: July 2016 Issue – Harnessing Magic

    php[architect] Magazine has just published their latest issue for July 2016: Harnessing Magic. This latest issue features articles like:

    • "RegEx is Your Friend" (Liam Wiltshire)
    • "Removing the Magic with Functional PHP" (David Corona)
    • "Implementing Cryptography" (Edward Barnard)
    • "Reference Counting : The PDO Case Study" (Gabriel Zerbib)

    There’s also all of the usual columns from some of the regular authors, the "Education Station", "Community Corner" and the "Security Corner". If you’re interested in the content but just want a sample, be sure to check out this month’s free article covering mailing lists and MailChimp. You can pick up either just this issue or a full year subscription directly from the php[architect] website.

    PHPDeveloper.org

    Stoimen Popov: PHP: Don’t Call the Destructor Explicitly

    In a new post to his site Stoimen Popov makes the recommendation to not call the destructor explicitly in your code and provides some alternatives.

    PHP 5 introduces a destructor concept similar to that of other object-oriented languages, such as C++” says the documentation for destructors. […] Well, as you can not call the constructor explicitly […] so we should not call the destructor explicitly. The problem is that I’ve seen this many times, but it’s a pity that this won’t destroy the object and it is still a valid PHP code.

    He talks about __destruct and it’s role in PHP’s set of "magic methods" and what they exist to do. He then gets into a few examples of what code could look like that uses a destructor and the difference between normal handling calling the destructor explicitly. The main differences is that calling it explicitly does not destroy the object, it’s basically like calling any other method. He does include an interesting method for destroying the object – setting it to null – and notes that the destructor fires then too. He also points out a few interesting things about cloning objects and how object references work when setting nulls as in the previous example.

    PHPDeveloper.org

    SitePoint PHP Blog: Using Halite for Privacy and Two-Way Encryption of Emails

    On the SitePoint PHP blog there’s a new tutorial posted showing you how to use the Halite package to encrypt the contents of emails. The Halite library sits on top of the libsodium functionality to provide tested, hardened cryptographic results.

    Cryptography is a complex matter. In fact, there is one golden rule: „Don’t implement cryptography yourself.“ The reason for this is that so many things can go wrong while implementing it, the slightest error can generate a vulnerability and if you look away, your precious data can be read by someone else.

    […] Some libraries out there implement cryptography primitives and operations, and leave a lot of decisions to the developer. […] Nevertheless, there is one library that stands out from the rest for its simplicity and takes a lot of responsibility from the developer on the best practices, in addition to using the libsodium library. In this article we are going to explore Halite.

    The tutorial then starts of helping you get the libsodium package installed on your system (assuming it’s unix-based). They then start on the sample application – a basic "email" client able to send/receive messages between users. They set up RESTful endpoints to get the messages, use the Doctrine ORM for a database interface and show the use of the Halite Crypto class to encrypt/decrypt the message contents.

    PHPDeveloper.org