News Feed
Jobs Feed
Sections




News Archive
feed this:

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

Kevin Schroeder:
Creating a module in Magento 2
December 12, 2013 @ 09:15:40

Kevin Schroeder has posted a step-by-step guide to his site today about creating a module for Magento in the first of a series of posts about Magento.

I believe that one of the best ways to learn something is to write out what it is you are learning. This forces you to think through the concepts and determine how to explain them to others. In doing so you are forced to use terms that are familiar to describe this new thing. This helps to solidify the concepts in your own mind, making it easier to remember. But still, there are three caveats: Magento 2 is not out yet, I'm learning as I write and what I share is what I see (my interpretation).

He talks about some of the differences between Magento 1 and 2 including:

  • The lack of code pools
  • Discovery XML files are in a different location
  • A different parser for these XML files

With all of this configuration and location information covered, he gets into the actual module building. He makes a simple "Hello World" module with a module.xml, event.xml and an Observer that handles sending the text back to the waiting application.

0 comments voice your opinion now!
tutorial module magento2 module event observer

Link: http://www.eschrade.com/page/creating-a-module-in-magento-2/

PHPMaster.com:
Inversion of Control - The Hollywood Principle
December 10, 2012 @ 09:43:50

In this new tutorial on PHPMaster.com, Alejandro Gervasio looks at the Inversion of Control methodology and how it's more than just an abstract reference to dependency injection.

Traditionally, application components have been designed to operate on and control the execution environment, an approach that delivers well to some extent. [...] Instead of making the module completely responsible for logging data to multiple endpoints, we can transfer the responsibility straight to the external environment. [...] Not surprisingly, the process of inverting these responsibilities between components and the environment is formally known as Inversion of Control (or in a more relaxed jargon, The Hollywood Principle), and its implementation can be a real boost when it comes to developing extensible, highly-decoupled program modules.

He uses a set of domain objects (Posts and Comments in a typical blog structure) and the Observer pattern to show how mixed up things might get if the application isn't carefully coded. He takes this and updates it to include a "comment notification service" that implements the SplObserver and is attached to the post to be executed on an event (in this case, the setting of a new comment).

0 comments voice your opinion now!
inversionofcontrol hollywood principle introduction listener observer tutorial


Zumba Fitness Engineering:
Using Application Events to Hook in Plugins
August 09, 2012 @ 09:23:37

In this recent post on the Zubma Fitness Engineering site, Chris Saylor looks at using events in your applications to hook in plugins to easily (and dynamically) enhance functionality.

In many instances, having a plugin system (even for closed-source applications) is a convenient and safe approach to adding functionality to a product. It minimizes risk by not having to modify the core of the source. In this article, I'll be discussing how we implemented a plugin system for our cart software to allow for plugins.

Its implemented a bit like the Observer design pattern - you "register" the listening event which can then be activated by a "trigger" method with the event's name. These events are stored in a registry (static) so they can be accessed across the application.

0 comments voice your opinion now!
events plugin trigger register tutorial observer


PHP-Tip-a-Day:
PHP Tutorial King Floyd and the Seventeen Princes - A Tale of the Observer Pattern
June 22, 2012 @ 09:20:39

On the PHP-Tip-a-Day site today there's an new "fable" posted in the Design Pattern Fables series. This time it's about the Observer pattern (and kings and princes).

The first place I recall encountering the observer pattern was not in PHP, but in JavaScript. If you've ever set a listener to fire when an event happened, you've used the observer pattern. Functions or methods are registered with an object so that when it experiences a specific event, it "notifies" the registered functions or methods by calling them.

His story tells about a royal family, a pregnancy and magic mirrors that allows for instant communication between the family and outlying locations. He relates it to the objects and "watchers" that make up the Observer pattern and gives a brief code example (in Javascript) of a HTML button and a jQuery event observer that fires when it's clicked.

0 comments voice your opinion now!
designpattern fable story observer event watcher


Anthony Ferrara's Blog:
Handling Plugins In PHP
March 09, 2012 @ 13:34:38

Anthony Ferrara has a new post today looking at plugin handling and a few of the more common design patterns that can be used to implement them in your applications.

A common problem that developers face when building applications is how to allow the application to be "plug-able" at runtime. Meaning, to allow non-core code to modify the way an application is processed at runtime. There are a lot of different ways that this can be done, and lots of examples of it in real life. Over a year ago, I wrote a StackOverflow Answer on this topic. However, I think it deserves another look. So let's look at some patterns and common implementations.

The patterns he covers are:

  • Observer
  • Mediator
  • Strategy
  • Decorator
  • Chain of Responsibility

For each there's both a bit of sample code showing it in use and links to some examples from various frameworks and other projects.

0 comments voice your opinion now!
plugin designpattern observer mediator strategy decorator chainofresponsibility


PHPMaster.com:
Understanding the Observer Pattern
February 23, 2012 @ 11:39:10

PHPMaster.com has a new tutorial looking at another popular design pattern, the Observer pattern, and sharing some example code putting it to use. (Their other design pattern articles include ones on command and factory patterns).

In this article I'll show you how to implement the Observer Pattern. You'll learn how various classes in the pattern relate to one another as subject and observers, how the subject notifies observers of a change in its state, and how to identify scenarios where it would be suitable to use the Observer Pattern in your own code.

The introduce the pattern by using an abstract "Observer" and "Subject" (that defines "attach", "detach", "getState", "setState", "notify" and "getObservers" methods) observer classes to coordinate the attached classes. They extend these classes with "Auth" and "Auth_ForumHook" show how to attach the "Auth_ForumHook" classes to the main "Auth" observer manager and change the state of the observer to notify it of an update.

You can find a more detailed explanation of the Observer pattern on Wikipedia.

0 comments voice your opinion now!
observer design pattern tutorial authorization


Fabien Potencier's Blog:
Create your own framework... on top of the Symfony2 Components (part 9)
January 19, 2012 @ 08:58:11

Fabien Potencier has posted the ninth part of his "build a framework on Symfony2 components series. In this latest tutorial he takes the simple framework he's already created (complete with some unit tests) and makes it easier to extend.

Our framework is still missing a major characteristic of any good framework: extensibility. Being extensible means that the developer should be able to easily hook into the framework life cycle to modify the way the request is handled.

He chooses the Observer design pattern as a basis for his example, allowing any kind of behavior/actions to be added to the framework's execution. He includes the Symfony2 dispatcher to make this work and includes the code for a "handle" method to fire off events. It executes a "ResponseEvent" every time the framework is executed. An "addListener" method provides the hook to apply a callback to an event - in his case an anonymous function (or closure).

0 comments voice your opinion now!
symfony2 framework custom series extensible observer designpattern


Label Media Blog:
Design Patterns in PHP - Observer Pattern
February 11, 2011 @ 11:03:21

Tom Rawcliffe has posted the latest in his design patterns series covering some of the most common patterns and how they would work in PHP. In this new post he looks at the observer pattern.

So far in my series of articles on design patterns in PHP we've looked at a creational pattern, a structural pattern and a behavioral pattern. Today I'll be taking a closer look at another behavioral pattern - the observer. The observer pattern (also known as the Subscribe/Publish Pattern) is used to notify one object, the observer, about a change of state from another object, the subject.

He gives the layout of the pattern in a simple UML diagram before moving into the description and code. His sample builds a Users object that has a set of observers on it. His custom observer is a logger that, when a change is made on the Users, it writes out a value of the current object.

1 comment voice your opinion now!
observer design pattern tutorial series


Cormac' PHP Blog:
Practical example php implementation of the Observer pattern
October 14, 2010 @ 08:36:35

New from Cormac's blog there's a post looking at an implementation of the Observer design pattern in a bit more practical scenario than some other examples out there.

Observer is a pattern where an object called the subject maintains a list of dependents (observers) and notifies them of any state changes. I implemented this recently to log changes to an Account object, and to notify the account holder if their account had expire - here's the basics of the code, hopefully it'll help someone else figure out how the pattern works

The basis of the Observer pattern is that you attach these "observer" objects to a main object. These watch the object and see if something changes (like a property value) and react accordingly. For their example, they create a setup that extends the main Observer class to have some or the detection functionality built-in.

0 comments voice your opinion now!
practical example observer pattern


Eric Adams' Blog:
Implementing the Observer Pattern with SplObserver and SplSubject
June 30, 2010 @ 12:43:34

In a recent post from Eric Adams, he shows how to use the SplObserver and SplSubject components of the Standard PHP Library (SPL) to make an implementation of the observer pattern for more reusable code.

As PHP applications grow into complex object-oriented systems, developers look to create centralized components to execute repetitive tasks. These include logging, emailing, redirects, and more. The Observer pattern is a commonly used design pattern to hook such components into an application during runtime, thereby making them reusable. Since PHP 5.1, there are two interfaces built into the Standard PHP Library (SPL) that can be implemented to use the Observer pattern in your application. They are SplSubject, and SplObserver.

He shows how to use them in an example of a custom error handler class that extends the SplSubject with its attach, detach and notify methods as well as logger and mailer classes that will use it to handle their exceptions.

0 comments voice your opinion now!
splobserver splsibject tutorial observer designpattern



Community Events











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


composer hack security podcast symfony2 install component unittest opinion language application database overview release hhvm introduction facebook performance package framework

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