News Feed
Sections




News Archive
feed this:

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

SitePoint PHP Blog:
Automate PHP with Phake - Real World Examples
July 10, 2014 @ 12:51:07

The SitePoint PHP blog has posted part two of their series looking at using Phake for automation in your applications. In this second part they take some of the basics they shared in part one and apply them in some more practical examples.

In part one, we covered the basics of Phake and demonstrated ways of executing tasks with it, covering groups, dependencies, and arguments. In this part, we'll look at some sample real world applications of Phake. Note that the following examples are largely based on things that I usually do manually that need some sort of automation.

He includes three different task examples, each with the code to make them happen (and descriptions of what it's doing):

  • Uploading Files to Server with a Phake task
  • Seeding the Database
  • Syncing Data

You can find out more about Phake on the project's GitHub page (including grouping, aborting and describing tasks).

0 comments voice your opinion now!
phake automate library tutorial part2 practical example

Link: http://www.sitepoint.com/automate-php-phake-real-world-examples/

Rob Allen:
Z-Ray for Zend Server 7
July 02, 2014 @ 12:56:59

In his latest post Rob Allen gives a "first look" at a new feature in the Zend Server (v7) product from Zend - Z-Ray. The z-Ray feature gives you a complete "under the covers" look at what your code is doing including resource use, database connections and processing time.

I've been running the beta for all my development work for a while now and the main reason is the new Z-Ray feature. Z-Ray is a bar that is injected into the bottom of your page showing lots of useful information.

His post shares some of the results he found with his development version of Joind.in and screenshots of the results. He shows the levels of detail available at each level, all directly in the browser. It even includes functionality to track all variables being created or used in the current execution.

0 comments voice your opinion now!
zray zendserver7 introduction joindin example screenshot

Link: http://akrabat.com/software/z-ray-for-zend-server-7/

Lorna Mitchell:
Logging to Stdout with Monolog
June 09, 2014 @ 09:08:10

Lorna Mitchell has a quick post today showing how you can use the popular Monolog logging library to log messages and data to stdout, the standard output stream of whatever is executing the script.

My worker scripts have really basic logging (as in, they echo when something happens, and I can see those in the supervisord logs). Which is kind of okay, but I wanted to at least add timestamps in to them, and maybe send emails when something REALLY bad happened. I'm a huge fan of Monolog so I grabbed that, but it wasn't immediately obvious which of the many and varied options I would need for this fairly simple addition. It turns out that the right thing to use is the ErrorLogHandler.

She includes a few lines of sample code that use the "ErrorLogger" to output the message. It includes the log level, a timestamp, the message itself and any additional contextual information you pass in.

0 comments voice your opinion now!
monolog stdout output example library logging

Link: http://www.lornajane.net/posts/2014/logging-to-stdout-with-monolog

Matthias Noback:
Inject a repository instead of an entity manager
May 19, 2014 @ 11:04:30

Matthias Noback has made a recommendation in his latest post about using a repository rather than an entity manager in your classes to inject dependencies.

It appears that I didn't make myself clear while writing about entity managers and manager registries yesterday. People were quick to reply that instead you should inject entity repositories. However, I wasn't talking about entity repositories here. I was talking about classes that get an EntityManager injected because they want to call persist() or flush(). The point of my previous post was that in those cases you should inject the manager registry, because you don't know beforehand which entity manager manages the entities you are trying to persist. By injecting a manager registry you also make your code useful in contexts where another Doctrine persistence library is used.

He suggests that more classes actually need a repository and not an entity manager to work with necessary objects. He also points out how the use of an entity manager can sometimes violate the Law of Demeter. He includes some code showing a refactoring away from an entity manager and towards a repository. He also has an example of a custom repository class based on the domain logic object types. In addition he talks about repository interfaces, resetting closed entity managers and "criteria" objects.

0 comments voice your opinion now!
repository entity manager doctrine refactor example

Link: http://php-and-symfony.matthiasnoback.nl/2014/05/inject-a-repository-instead-of-an-entity-manager/

Lorna Mitchell:
Beanstalk, Pheanstalk and Priorities
May 08, 2014 @ 09:47:08

Lorna Mitchell has a quick post showing you how to use the "priority" option that the Pheanstalk library provides when working with a Beanstalk queue.

I've got an application that uses Beanstalkd to queue up messages, and some PHP worker scripts that grab messages from the queue and process them. Messages get added by the web application, but can also be added by cron - and when I add a bunch of messages via cron, I don't want to swamp what the web application is doing! Those cron-added jobs are mostly pretty low priority, generating reports, sending weekly update emails, that kind of thing. Beanstalkd has a concept of priority, so I can create lower priority jobs.

She includes a three line example showing the use of the "LOW_PRIORITY" constant to tell Beanstalk how and when it should handle this particular job. In her situation, where there are multiple smaller jobs rather than larger ones it makes more sense to shift some of the smaller, less important tasks to be executed later.

0 comments voice your opinion now!
beanstalk pheanstalk priority tutorial example

Link: http://www.lornajane.net/posts/2014/beanstalk-pheanstalk-and-priorities

Edd Mann:
Tuples in PHP
April 18, 2014 @ 09:48:38

Edd Mann has a new post today sharing some of his exploration into implementing tuples in PHP. A tuple is a common data structure in other languages consisting of an immutable, ordered list of items.

Since exploring languages such as Scala and Python which provide the tuple data-structure, I have been keen to experiment with how to clearly map it into a PHP solution. Tuples are simply a finite, ordered sequence of elements - usually with good language support to both pack (construction) and unpack (deconstruction) of the values. I have found that many use-cases of the common place array structure in PHP could be better suited to n-tuple's. [...] I discussed briefly that what makes tuples so powerful in the highlighted languages is their good support for handling their contents, for example unpacking a user tuple into separate id and name variables. PHP supports this form of unpacking in regard to arrays using the 'list' function, which I frequently use to return multiple values from a function/method invocation.

He shares the code for his basic implementation, extended from the SplFixedArray, and shows an example of it in use. He also includes samples showing how to make typed tuples via a "type" method call.

0 comments voice your opinion now!
tuple data structure splfixedarray example tutorial

Link: http://eddmann.com/posts/tuples-in-php/

ServerGrove Blog:
Symfony2 components overview ExpressionLanguage
April 10, 2014 @ 12:09:23

The ServerGrove blog has posted the latest in their series focusing on various components in the Symfony2 framework. This latest post looks at the ExpressionLanguage component, functionality that allows you to execute "expressions" easily.

This is the 10th post in our series on Symfony2 components and we will cover the latest component added to Symfony: the ExpressionLanguage component. This component was added in version 2.4 and provides a way to have dynamic aspects in static configurations. For example, it can be used to evaluate expressions in configuration files, create a DSL ,or build a business rules engine.

The tutorial shows you how to get it installed (via Composer) and provides a simple "before" and "after" example, the first using eval and the second using ExpressionEngine to reproduce the same effect. They note that the evaluation of the expression isn't the same thing as compiling it and re-execution will always take the same amount of time. The post then talks about some of the syntax, functions and caching features of the component. It dives a little bit deeper and looks at some of the internals of the component as well.

0 comments voice your opinion now!
symfony2 component expressionengine overview example

Link: http://blog.servergrove.com/2014/04/07/symfony2-components-overview-expression-language/

PHPClasses.org:
Did You Mean Advanced Email Validation in PHP
April 09, 2014 @ 11:50:21

In this most recent post to the PHPClasses.org blog Manuel Lemos talks about invalid email addresses and shows the use of this package to evaluate them.

When you take users' email addresses, for instance in a site sign-up form, there are great chances that the addresses may be incorrect because of a typing mistake or it is not possible to deliver the message to the specified address for some reason. This e-mail validation package can detect and prevent that users enter incorrect addresses even before you accept them.

He starts the post with a list of six types of invalid email addresses including everything from simple typing mistakes out to temporary rejection from "gray listing". He shows how set up the class and briefly covers some of its methods and what they do. Also included is an example if it in use to validate the address. There's also a brief section at the end talking about using OAuth to work around users not wanting "yet another account" or to share their details with an untrusted application.

0 comments voice your opinion now!
email validation tutorial package example

Link: http://www.phpclasses.org/blog/package/13/post/2-Did-You-Mean-Advanced-Email-Validation-in-PHP.html

PHPBuilder.com:
Processing JSON in PHP
April 04, 2014 @ 10:40:39

PHPBuilder.com has posted a new tutorial today showing you how to work with JSON in PHP including serialization and database interaction.

This article explains how to use the JavaScript Object Notation (JSON) extension in PHP, going step by step through a series of essential operations. JSON is an object string notation, it is defined as a subset of JavaScript's syntax and its general-purpose is to interchange data format. As you probably know, JSON was first made to be used with JavaScript for accessing remote data, but now it is used by many other languages because JSON data is platform independent data format. JSON can be used natively in JavaScript, but you can also use it in a server-client application logic.

They start with an introduction to the JSON structure and how to both create and encode data using PHP's own json_encode and json_decode. The examples start out using arrays for the data but then move into something slightly more complex - objects. The article talks about JsonSerializable and show how to automatically hook the data into a table and store the content based on the column name/property name match.

0 comments voice your opinion now!
process json encode decode tutorial example

Link: http://www.phpbuilder.com/articles/application-architecture/object-oriented/processing-json-in-php.html

Nikita Popov:
Methods on primitive types in PHP
March 17, 2014 @ 12:11:22

In his latest post Nikita Popov highlights one of the topics from this post, primitive types as objects, and some alternative options.

A few days ago Anthony Ferrara wrote down some thoughts on the future of PHP. I concur with most of his opinions, but not all of them. In this post I'll focus on one particular aspect: Turning primitive types like strings or arrays into "pseudo-objects" by allowing to perform method calls on them. [...] Note that this isn't far off dreaming, but something that already exists right now. The scalar objects PHP extension allows you to define methods for the primitive PHP types. The introduction of method-call support for primitive types comes with a number of advantages.

Among the advantages he lists:

  • The opportunity for a cleaner API (instead of the current, sometimes oddly named functions)
  • Improved readability
  • Polymorphism through a "cleaning up" of shared methods
  • Loose Typing

He also looks at possible ways that other primitive types could be handled (like "null" or "float") and some of the problems that could come up when passing objects around. Since the values could be an object or scalar, how would you know the difference. He finishes off the post with a look at the current state of things, including that there's not much resistance just that there hasn't been a good API defined to make it work.

0 comments voice your opinion now!
method primitive type object example problems

Link: http://nikic.github.io/2014/03/14/Methods-on-primitive-types-in-PHP.html


Community Events





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


list framework testing series podcast unittest install introduction laravel interview community threedevsandamaybe language symfony2 code configure release opinion developer refactor

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