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

James Morris:
PHPUnit Mocking and Method Chaining
July 17, 2013 @ 12:13:02

James Morris has an interesting new post about mocking and method chaining and a discovery he made about the proper use of the "at" method in what his mock objects were expecting.

I've been given the task of unit testing Symfony2's security layer, which at first seems daunting, but in reality with a clever bit of PHPUnit mocking, it's actually quite simple. Symfony2 makes heavy use of method chaining.

He illustrates one way to create the mocks for this chain (one mock returning another) but suggests an alternative - returning an instance of "self" to keep the chain alive. He also includes a bit about the "at" matcher and how, despite what the PHPUnit documentation says, it should be correctly used to handle the response of certain methods in the chained call.

0 comments voice your opinion now!
phpunit mock method chain object tutorial matcher

Link: http://blog.jmoz.co.uk/phpunit-mocking-and-method-chaining

DZone.com:
Zend_Validate for the win
December 03, 2010 @ 10:32:58

In this new post to DZone.com today Giorgio Sironi looks at what he considers one of the more valuable yet underestimated components of the Zend Framework - Zend_Validate.

Zend_Validate is a component of Zend Framework which provides validation classes which out-of-the-box enable you to check from string lengths to stranger properties like conformance to regular expressions or to a standard for barcodes. [...] Some parts of Zend_Validate are quite complex, and tie-in with the other components: there are file-related validations on size, hash and more to attach to your forms; in the domain-specific category instead, we can find validator for credit card numbers consistency, or barcodes; isbn codes; and more...

He includes a code sample to show of just some of the validators the component includes like: alpha-numeric, "between", valid email address, valid IP address, matches a regular expression and, a very handy feature of the component, setting up chains of validations.

0 comments voice your opinion now!
zendvalidate example chain zendframework


Ian Barber's Blog:
PageRank In PHP
December 16, 2009 @ 09:45:39

Ian Barber has put together a new blog post that looks at his creation of a simple PageRank-style algorithm, similar to the ideas behind Google's famous ranking technique.

The idea is that there is a random surfer, who starts on web page then browses through in a somewhat random way. [...] This random walk is a Markov chain, a traversal of a matrix that gives the probability of moving to any state from any other state, with the total probabilities for the destinations from any given page adding up to 1. PageRank attempts to find extract a vector of weights from that table, with one weight per page - they aren't related to any particularly query, so are only ever going to be a factor in a page being returned on a results page.

He includes the code to create a page rank rating for a sample set of data with the results showing the differences in ranking based on frequency of times the "page" is linked to and how that relates to the rankings of the other pages.

0 comments voice your opinion now!
pagerank tutorial markov chain


Robert Basic's Blog:
Chaining routes in Zend Framework
November 30, 2009 @ 12:04:28

Robert Basic has a quick new tutorial about chaining routes in your Zend Framework applications:

On a forum, there was a question today, about adding language "support" to the routes using Zend Framework. The guy wanted routes like /en/foo/bar or /de/baz. I wrote there an example for that using Zend_Router_Routes_Chain, so just posting that example here, too.

Custom routing allows you to define routes specific to your application without having to change the core libraries. In his example, he shows how to set up the routing objects and how to add them to the request's chain.

0 comments voice your opinion now!
chain route custom zendframework tutorial


Matt Curry's Blog:
On The Fly Model Chains With CakePHP
April 17, 2009 @ 11:13:52

Matt Curry has come back and posted yet another method you can use to help speed up your CakePHP applications that need chained methods (as he mentioned before) - only loading the parts as they're needed.

The smart readers (which is really all of you guys. you're the best) probably realized that there is a lot of overhead in building the chain, especially for apps with lots of interlinked models. Wouldn't it be awesome if Cake only created the pieces of the chain as needed?

He's created a sample model to do just that - it removes all model associations previously set (so it doesn't auto-build the chain) and then only adds in the models it needs (as defined in the __loadAssociations array) and then calls the parent constructor to autoload just those. A few benchmarks are tossed in comparing a model with no chains versus one with a varying number (one/nine).

0 comments voice your opinion now!
cakephp model chain custom load


ElectricToolBox.com:
Method chaining with PHP
December 22, 2008 @ 12:37:07

On the ElectricToolBox.com blog there's a quick post looking at method chaining in a Zend Framework application:

Having used the Zend Framework on a couple of projects and spent a lot of time reading the documentation I discovered the use of method chaining. This post looks at how to use method chaining in PHP.

His examples include a comparison between a method-chained Zend_Mail example and a non-chained method with each line augmenting the same object over and over. He also includes the simple-as-pie method that lets you use chaining in your own applications - returning the object itself.

0 comments voice your opinion now!
method chain zendframework zendmail tutorial example


PHPKitchen:
Using Wordpress
October 02, 2007 @ 15:22:00

Demian Turner has passed along an "indepth and informative" comment from the PHP London mailing list he saw about WordPress involving some of the things that suck about it.

We did http://ftalphaville.ft.com using Wordpress, and speaking as someone who's actually had to wade through pretty much the whole codebase, let me tell you it seriously sucks.

Their highlights include messing with the raw POST data to limit access, function calls chained eight long and comments like "This probably isn't needed anymore" all over the place.

0 comments voice your opinion now!
wordpress suck list comment mailinglist post function chain wordpress suck list comment mailinglist post function chain


DevShed:
Introducing the Chain of Responsibility Between PHP Objects
October 30, 2006 @ 12:18:00

DevShed is starting off a new series today with this first article talking about how to introduce the "chain of responsibility" method in how you use your objects.

In this three-part series, I'll show you how to create a chain of responsibility across different classes, which hopefully will give you a better understanding of how this schema can be implemented with PHP.

Since it's just the first part in the esries, they start with the whys and hows of the chain of command process before getting on with the actual code. For the foundation, they create some subclasses that will make the parts of the chain. Next up is combining them and, finally, making the "master class" to combine the links of the chain together. They use a "DataServer" example to work with local files.

0 comments voice your opinion now!
tutorial chain responsibility object process pattern subclass tutorial chain responsibility object process pattern subclass



Community Events





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


series framework list version artisanfiles symfony podcast conference introduction library voicesoftheelephpant opinion security composer community language laravel interview release tool

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