News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

NetTuts.com:
Design Patterns The Decorator Pattern
January 23, 2015 @ 12:08:21

The NetTuts.com site has continued their series looking at design patterns and how they can be used in PHP. In this new post they focus in on the Decorator pattern, most commonly used to add functionality to a existing class (to "decorate" it).

Earlier in this series we explored both the facade and adapter design patterns in this series. Using facade, we can simplify large systems, and by implementing adapter we can stay safe while working with external API and classes. Now we are going to cover the decorator design pattern, which also falls under the category of structural patterns. We can use the decorator pattern when we just want to give some added responsibility to our base class. This design pattern is a great alternative to a sub‑classing feature for extending functionality with some added advantages.

They start with a problem that needs solving - sending an email with additional content not defined in the parent class. They show how to do something similar with child classes, but quickly find a limitation. Instead, they show how to use decorator classes and a simple interface to provide interchangeable classes that augment the contents of the email body as passed in via constructor injection.

0 comments voice your opinion now!
designpattern decorator tutorial series email body content

Link: http://code.tutsplus.com/tutorials/design-patterns-the-decorator-pattern--cms-22641

Hari KT:
Conduit The Middleware for PHP
January 22, 2015 @ 10:22:16

In his latest post Hari KT looks at Conduit, a middleware system that lets you build PHP applications out of various pieces (the middleware) according to the PSR-7 specification (for HTTP messaging).

Long back, I happened to talk with Beau Simensen about stackphp on #auraphp channel. It was hard for me to digest when I noticed it need symfony/http-kernel and its dependencies. After a few months, I started to like the middleware approach of slim framework and wanted to push it to aura. But nothing happened there. Conduit is a Middleware for PHP built by Matthew Weier O'Phinney lead of Zend framework. Conduit supports the current PSR-7 proposal. I believe like the many PSR's, PSR-7 will be a revolution in the PHP world. Conduit is really a micro framework and can grow with your project.

Hari walks you through getting the tool installed and includes an example route that just echoes "Hello conduit!"back to the user. With that in place, he shows how to add in some middlewares, chosing the Aura router and dispatcher for more complex route handling, and integrating them into a simple controller/action microframework structure.

0 comments voice your opinion now!
conduit middleware psr7 proposal mwop tutorial auraframework

Link: http://harikt.com/blog/2015/01/21/conduit-middleware-for-php/

NetTuts.com:
Create a Custom Payment Method in OpenCart Part 3
January 21, 2015 @ 10:20:44

NetTuts.com has continued their series showing how to integrate a custom payment method into your OpenCart instance with part three of the series. In this tutorial they focus more on the frontend aspects, creating controller and model handling for the new method.

If you've been following along with this series, you should be familiar with the kind of file structure we set up for our custom payment method in the back-end. [...] We'll use a similar kind of file setup for the front-end section as well.

He starts with the controller, building a handler for the Custom method, doing some data filtering and getting the order information. He walks you through what each of the lines are doing and shows how to output the result back to a view. He also includes the model code needed for the custom payment method as well as language/template files to display the form needed to gather the necessary data.

0 comments voice your opinion now!
opencart part3 series custom payment method tutorial

Link: http://code.tutsplus.com/tutorials/create-a-custom-payment-method-in-opencart-part-3--cms-22464

SitePoint PHP Blog:
How to Encrypt Large Messages with Asymmetric Keys and phpseclib
January 20, 2015 @ 11:40:51

On the SitePoint PHP blog today David Brumbaugh shows you how to encrypt large messages with phpseclib and asymmetric keys. phpseclib is a PHP library specifically designed to handle encryption and decryption in an easy-to-use way.

Most of us understand the need to encrypt sensitive data before transmitting it. Encryption is the process of translating plaintext (i.e. normal data) into ciphertext (i.e. secret data). During encryption, plaintext information is translated to ciphertext using a key and an algorithm. To read the data, the ciphertext must be decrypted (i.e. translated back to plaintext) using a key and an algorithm. [...] A core problem to be solved with any encryption algorithm is key distribution. How do you transmit keys to those who need them in order to establish secure communication? The solution to the problem depends on the nature of the keys and algorithms.

He talks some about the difference between symmetric and asymmetric algorithms and some advice about the selection of the right one (or ones) to use in your app. He also talks briefly about the problem with RSA keys, mostly that it has limits on the amount of text it can encrypt. His solution is to "encrypt the message with a symmetric key, then asymmetrically encrypt the key and attach it to the message". He explains the encryption/decryption process step by step and starts in showing the code to make phpseclib do the work. He shows how to generate the keys, build the encrypt function and the decrypt function with about 30 lines of code each.

0 comments voice your opinion now!
encrypt decrypt large message asymetric key phpseclib tutorial

Link: http://www.sitepoint.com/encrypt-large-messages-asymmetric-keys-phpseclib/

NetTuts.com:
Building With the Twitter API Repeating Tweets From a Group
January 19, 2015 @ 11:18:45

NetTuts.com has continued their series about constructing a Twitter application as a Yii framework-based application. In this latest tutorial they expand on the previous post's "tweet storm" functionality and instead posts random updates based on pre-defined content. If you need to catch up, you can find the other parts of the series here.

The nature of the Twitter stream makes repetition useful, within reason; overdoing it is spammy and annoying.[...] This automates the task of repeating and creating variation over time to increase the likelihood that your Twitter followers will engage with your content. Keep in mind that the Twitter API has limits on repetitive content. You'll be more successful if you offer a wide variety of variations and run the service on an account that you also use manually to share other content.

They start with a short list of features the application needs to support including the main goal of posting the randomized, recurring tweets. They start by creating the Group model and table to allow for the grouping of tweets. Then they use Yii's scaffolding to create a form for creating new groups. Next up is the controller code to handle the group submission and an update to link a tweet to a group. Finally they include the code to push the tweets out to Twitter and mark the tweets as sent. The post ends with an example of a timeline with the resulting posts.

0 comments voice your opinion now!
tutorial series twitter api repeat tweets group random

Link: http://code.tutsplus.com/tutorials/building-with-the-twitter-api-repeating-tweets-from-a-group--cms-22490

VG Tech Blog:
How I Set Up My Local PHP Dev Environment on Mac OSX Yosemite in Three Easy Steps
January 16, 2015 @ 11:43:51

On the VG Tech blog today Erland Wiencke has posted a quick guide to the "three easy steps" he uses to set up a PHP development environment on OSX.

When I first started writing this post, I considered giving it a title such as "How to set up local PHP development with dynamically configured mass virtual hosting on Apache 2.4″, "Quick and easy prototyping using Liip PHP, Dnsmasq or Proxy Auto Configuration" or even "The Ultimate Guide to Rapid Development on OSX 10.10″. I did not.

In my daily job as a Development Manager, I don't get to code very much, but when I do, I want to have a setup that allows me to quickly create development projects and prototypes in the ~/Sites folder and have them show up as vhosts automagically, without having to edit any configuration file(s).

His three steps do require a few prerequisites including Homebrew, but that's easy enough to set up. Here's his process:

  • Step 1 - installing (my preferred version of) PHP
  • Step 2 - enable hosting under ~/Sites
  • Step 3 - add a local DNS server

He also includes a "Step 3a" that shows how to test the installation via a simple response from each of the domains.

0 comments voice your opinion now!
development environment osx yosemite local tutorial setup configure

Link: http://tech.vg.no/2015/01/15/how-i-set-up-my-local-php-development-environment-on-mac-osx-yosemite-in-three-easy-steps/

Edd Mann:
Implementing Streams in PHP
January 16, 2015 @ 10:09:22

Edd Mann has a new post today looking at implementing streams in your PHP applications. In this case we're not talking about the streams built into PHP but the concept of a source of information that only produces the next item when requested (aka "lazy loading").

Typically, when we think about a list of elements we assume there is both a start and finite end. In this example the list has been precomputed and stored for subsequent traversal and transformation. If instead, we replaced the finite ending with a promise to return the next element in the sequence, we would have the architecture to provide infinite lists. Not only would these lists be capable of generating infinite elements, but they would also be lazy, only producing the next element in the sequence when absolutely required. This concept is called a Stream, commonly also referred to as a lazy list, and is a foundational concept in languages such as Haskell.

He talks about how streams of data should be interacted with differently than a finite list of data and the promises they're based on to provide the right data. He shows two different approaches to implementing a an object to stream data from - a class-based method and one that uses generators. Sample code is provided for each with the generator approach being a bit shorter as they're designed to lazy load items as requested.

0 comments voice your opinion now!
stream data lazyload generator class iterator tutorial

Link: http://eddmann.com/posts/implementing-streams-in-php/

ThePHP.cc:
PHPUnit Migration from PEAR to PHAR
January 14, 2015 @ 13:48:34

On The PHPcc's site today Sebastian Bergmann, the creator of the popular PHPUnit unit testing framework, shows you how to move to using the tool's phar file and away from the previously used PEAR install method.

In April 2014 I announced that I would shut down pear.phpunit.de on December 31, 2014. The motivation behind this move was to simplify the release process of PHPUnit by getting rid of an outdated distribution channel. I was afraid that I would leave users of my software behind by this move. [...] I am relieved that the shutdown of pear.phpunit.de went as smooth as it did. [...] In this article I show you how to make the transition from using PHPUnit from a PEAR package to using PHPUnit from a PHP Archive or using Composer as easy and convenient as possible.

There's three main steps to the migration from PEAR to the Composer-based phar installation:

  • Uninstalling PEAR Packages
  • Using PHPUnit from a PHP Archive (PHAR)
  • Installing PHPUnit with Composer

He includes the commands and configuration files/settings you'll need to make the transition happen. He also mentions that older versions are still available if there's a need but only on GitHub/Packagist as phar packages, not via PEAR.

0 comments voice your opinion now!
phpunit migration pear phar packagist composer tutorial

Link: http://thephp.cc/news/2015/01/phpunit-migration-from-pear-to-phar

SitePoint PHP Blog:
Adding Products to Your eBay Store with the Trading API
January 13, 2015 @ 12:50:14

The SitePoint blog has posted the next part of their "using the eBay trading API" series today (part three) showing you how to add products to your store via their API.

In this third and final part of our eBay Trading API series, we'll be building the product adding functionality into our application. Now that we're done with the store settings, we can begin with writing the code for the controller that would handle the creation of products.

He walks you through the code to create the "new" action on your Slim controller, build the view to gather the product information and handle the upload of product images with the Dropzone Javascript library. Also included is the code to get the current category list (to populate a dropdown list) and the code needed to create the product, both in your database and sending it back to the eBay API for insertion. This finishes the series about using this API, but you can get more information on the API itself though its documentation. The full code for the tutorial series is available on GitHub.

0 comments voice your opinion now!
ebay trading api tutorial series part3 add product upload

Link: http://www.sitepoint.com/adding-products-ebay-store-trading-api/

Mathias Noback:
Collecting events and the event dispatching command bus
January 13, 2015 @ 11:52:33

Mathias Noback has posted the next part of his command bus in PHP series today with a few suggestions about event handling and when it's a good idea to dispatch them.

It was quite a ride so far. We have seen commands, command buses, events and event buses. We distilled some more knowledge about them while formulating answers to some interesting questions from readers.

In this new post, his focus is on collecting the events that happen as a part of the command's execution. He uses his "UserSignedUp" event his his previous example and a "send welcome email" handler to show why it may not be the best idea to execute all events simultaneously. Instead, he recommends making use of event collections (a feature his SimpleBus library supports) to define "providers" that can collect the events that need to happen and delegate the execution of them one after the other. Example code is included all through the post of events, providers and commands that make use of this idea.

0 comments voice your opinion now!
commandbus command collect event provider dispatch tutorial

Link: http://php-and-symfony.matthiasnoback.nl/2015/01/collecting-events-and-the-events-aware-command-bus/


Community Events





Don't see your event here?
Let us know!


series configure version interview symfony list unittest voicesoftheelephpant extension composer api install introduction language laravel podcast community conference release opinion

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework