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

Zend Framework Blog:
Validate data using zend-inputfilter
Jun 16, 2017 @ 14:22:37

Matthew Weier O'Phinney is back on the Zend Framework blog today with a spotlight on another component of the Zend Framework. This time he features zend-inputfilter, a useful component for filtering the data coming into your application from your users.

In our previous two posts, we covered zend-filter and zend-validator. With these two components, you now have the tools necessary to ensure any given user input is valid, fulfilling the first half of the "filter input, escape output" mantra.

[...] To solve [the single shot validation] problem, Zend Framework provides zend-inputfilter. An input filter aggregates one or more inputs, any one of which may also be another input filter, allowing you to validate complex, multi-set, and nested set values.

As in the other tutorials in the series, Matthew walks you through the installation of the component via Composer and briefly describes how it operates. He then includes a code example of creating a new InputFilter instance, making inputs, attaching validators to them and then ensuring everything validates in the chain with an isValid call. He then covers input specifications - configurations based on array values - to define validators on the input elements. He ends the post looking at input filters, how to manage them and defining them by specification. He also mentions a few other pieces fo functionality the component includes but he didn't cover here.

tagged: zendinputfilter component zendframework series input filter chain

Link: https://framework.zend.com/blog/2017-06-15-zend-inputfilter.html

James Morris:
PHPUnit Mocking and Method Chaining
Jul 17, 2013 @ 17: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.

tagged: 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
Dec 03, 2010 @ 16: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.

tagged: zendvalidate example chain zendframework

Link:

Ian Barber's Blog:
PageRank In PHP
Dec 16, 2009 @ 15: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.

tagged: pagerank tutorial markov chain

Link:

Robert Basic's Blog:
Chaining routes in Zend Framework
Nov 30, 2009 @ 18: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.

tagged: chain route custom zendframework tutorial

Link:

Matt Curry's Blog:
On The Fly Model Chains With CakePHP
Apr 17, 2009 @ 16: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).

tagged: cakephp model chain custom load

Link:

ElectricToolBox.com:
Method chaining with PHP
Dec 22, 2008 @ 18: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.

tagged: method chain zendframework zendmail tutorial example

Link:

PHPKitchen:
Using Wordpress
Oct 02, 2007 @ 20: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.

tagged: wordpress suck list comment mailinglist post function chain wordpress suck list comment mailinglist post function chain

Link:

PHPKitchen:
Using Wordpress
Oct 02, 2007 @ 20: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.

tagged: wordpress suck list comment mailinglist post function chain wordpress suck list comment mailinglist post function chain

Link:

DevShed:
Introducing the Chain of Responsibility Between PHP Objects
Oct 30, 2006 @ 18: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.

tagged: tutorial chain responsibility object process pattern subclass tutorial chain responsibility object process pattern subclass

Link:


Trending Topics: