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

Marc Moreram:
EventListeners as Collectors in Symfony
Aug 28, 2015 @ 13:25:07

Marc Moreram has posted a guide on his site to using event listeners as collectors in Symfony 2 based applications. He shows how to hook into the eventing system and both gather events fired (matching your criteria) and view the current collection.

Some of my concerns during the last couple of years have been how to collect data from all installed bundles using available tools in Symfony packages. I say concerns because I don’t really know if is there a tool for that. Some people have told me that the EventDispatcher component can do this work greatly, but then I have the same question once and again… is this component designed for such?

He uses an example of gathering mmoreram.wake_up events from his codebase, triggered when it "wakes up". He shows how to create a simple class for the event with a "rested" value. He modifies this to set up an array of "feelings" inside the event and a method to add new instances to the internal array. Finally he shows how to dispatch an event of the mmoreram.wake_up type and access the resulting set of "feelings" directly from the event.

tagged: event listener collector symfony feelings fire wakeup tutorial

Link: http://mmoreram.com/blog/2015/08/28/eventlisteners-as-collectors-in-symfony/

DZone.com:
How to correctly work with PHP serialization
Aug 29, 2012 @ 13:19:37

In this new post to DZone.com today Giorgio Sironi takes a look at the serializing functionality in PHP and how it works with both regular variables and objects.

PHP is able to automatically serialize most of its variables to strings - letting you save them into storage like $_SESSION. However, there are some tweaks you have to know to avoid exploding .php scripts and performance problems.

He gives some code snippets showing the serialization of variables and objects and points out a few things that can't be effectively serialized (like resources and closures). The mentions the "__sleep" and "__wakeup" magic methods for automatic class serialization and mentions the Serializable interface that comes built in to PHP.

tagged: serialize variable object tutorial sleep wakeup serializable interface

Link:

Dave Gardner's Blog:
Caching dependency-injected objects
Mar 25, 2010 @ 16:49:57

Dave Gardner has posted about a method he uses to cache objects that have dependency injection needs in something like a memcached server.

The objects themselves have a number of injected dependencies. It includes using the PHP magic methods __sleep and __wakeup to manage serialisation. It also discusses mechanisms for re-injecting dependencies on wakeup via a method that maintains Inversion of Control (IoC).

He uses a user object based example that has an injection needed to load in the user's usage history. He includes the code to define the classes, create the objects via a dependency injection container and performing the sleep/wakeup actions with the dependencies coming out intact on the other side.

tagged: tutorial cache dependency injection object sleep wakeup

Link:

DevShed:
The Sleep and Wakeup Magic Functions in PHP 5
Jun 17, 2009 @ 13:49:19

DevShed has posted the next part of their series looking at the "magic functions" that PHP5+ has to offer you in your development. They've already looked at ones like __call, __clone and __isset/__unset and now, with this new tutorial they've added __sleep and __wake.

Magic functions are an important part of the numerous improvements and additions that were introduced originally in PHP 5. They can be extremely handy when it comes to simplifying the execution of complex tasks. [...] In this fourth chapter I'm going to examine closely the "__sleep()" and "__wakeup()" functions, which are called automatically when an object is serialized and unserialized respectively.

In their example code they add the __sleep and __wake functions to the class they've been developing to output a string when the object is manipulated. These methods are automatically called when a serialize/unserialize function call is made on the object.

tagged: tutorial function magic wakeup sleep

Link:

Stubbles Blog:
Some remarks to serialization without pity
Mar 22, 2007 @ 15:39:00

In response to Terry Chay's response about his previous blog post, Frank Kleine has posted a few more comments on the topic of object serialization and some of the assertions Terry made.

Terry Chay made some remarks to my last blog entry about a solution for lazy class loading without using __autoload(). Some of his statements seem like I explained my implementation not good enough leading to wrong interpretations. In this blog entry I'll use some of his statements to take a deeper look into my implementation and show that he has drawed some conclusions which I want to disprove.

He goes back and corrects some of what Terry has said in his response, including showing a more detailed version of him implementation. Be sure to check out the comments for the post, though - Terry comes back and clarifies some of the comments he'd made including the framework talk and changes of perspective having seen the new code snippet/information.

tagged: serialized pity autoload object sleep wakeup detail serialized pity autoload object sleep wakeup detail

Link:

Stubbles Blog:
Some remarks to serialization without pity
Mar 22, 2007 @ 15:39:00

In response to Terry Chay's response about his previous blog post, Frank Kleine has posted a few more comments on the topic of object serialization and some of the assertions Terry made.

Terry Chay made some remarks to my last blog entry about a solution for lazy class loading without using __autoload(). Some of his statements seem like I explained my implementation not good enough leading to wrong interpretations. In this blog entry I'll use some of his statements to take a deeper look into my implementation and show that he has drawed some conclusions which I want to disprove.

He goes back and corrects some of what Terry has said in his response, including showing a more detailed version of him implementation. Be sure to check out the comments for the post, though - Terry comes back and clarifies some of the comments he'd made including the framework talk and changes of perspective having seen the new code snippet/information.

tagged: serialized pity autoload object sleep wakeup detail serialized pity autoload object sleep wakeup detail

Link:

DevShed:
Using the Sleep and Wakeup Functions to Serialize Objects in PHP (Part 2)
Jun 13, 2006 @ 13:11:34

DevShed continues their "serializing objects" series today with part two of the series, highlighting the use of the sleep and wakeup functionality of PHP to help with the serialization.

After refreshing the concepts that I deployed in the first part of this series, it's time to focus on the topics that I'll cover in this article, so you'll know what to expect before you continue reading. In this second part, I'll explain how to use objects in conjunction with the "__sleep()" and "__wakeup() magic functions respectively, in order to get the most out of them.

They start with a look at defining self-saving objects with their ObjectSaver class developed earlier. Building on that reminder, they integrate the "__sleep()" and "__wakeup()" functionality to handle calls immediately before and immediately after the handling of the object. They then use this new functionality to create persistent objects, capable of maintaining values across page requests.

tagged: serialize object persist sleep wakeup save serialize object persist sleep wakeup save

Link:

DevShed:
Using the Sleep and Wakeup Functions to Serialize Objects in PHP (Part 2)
Jun 13, 2006 @ 13:11:34

DevShed continues their "serializing objects" series today with part two of the series, highlighting the use of the sleep and wakeup functionality of PHP to help with the serialization.

After refreshing the concepts that I deployed in the first part of this series, it's time to focus on the topics that I'll cover in this article, so you'll know what to expect before you continue reading. In this second part, I'll explain how to use objects in conjunction with the "__sleep()" and "__wakeup() magic functions respectively, in order to get the most out of them.

They start with a look at defining self-saving objects with their ObjectSaver class developed earlier. Building on that reminder, they integrate the "__sleep()" and "__wakeup()" functionality to handle calls immediately before and immediately after the handling of the object. They then use this new functionality to create persistent objects, capable of maintaining values across page requests.

tagged: serialize object persist sleep wakeup save serialize object persist sleep wakeup save

Link:


Trending Topics: