Skip to content

Updated Zend Framework 2 Modules because of the locator generator version 2.0.0 release

I announced already, version 2.0.0 of the "locator generator" is out.
Because of that, I am also happy to announce the release of 1.4.1 from the zend framework 2 "locator generator" module.
Furthermore, the debian 6/PHP 5.3 backport got the release of version 1.3.0.
And finally, and because of the fact that zend framework 2.5.* is dropping support for PHP 5.4, the new debian 7/PHP 5.4 got the release of version 1.7.0.
Major changes in all releases is the dependency update to the new locator generator version.

You want to have a quick look and tryout without any hassle? Try the zf demo environment available in three flavors, cutting edge, debian 7/PHP 5.4 backport and debian 6/PHP 5.3 backport.

PHP Proxy Logger Component - Put Back Some Freedom And Silence In You Logs

So what is this component all about?
Basically it is a self developed "Proxy Logger" for php. Furthermore, this projects extends the proxy logger with an buffer and again with a trigger to flush or clean this buffer.

What does a "Proxy Logger" for php mean? It means a proxy for all loggers which implements the "PSR-3 Logger Interface". The proxy forwards all log requests to all attached loggers.
By using the provided "Buffer Logger", you are able to manipulate the forwarding of the log requests to all attached loggers.
Additionally, you can manipulate the buffering itself by using the available "Buffer Manipulators". This enables the possibility to set a trigger for log level to regulate the forwarding of all log requests to all attached loggers.

By the time of this writing, the component is shipped with two manipulators, the "BypassBuffer" and the "FlushBufferTrigger".
You can use the "Bypass Buffer" to regulate which log level bypasses the buffer and are forwarded directly to all attached loggers. The "Flush Buffer Trigger" enables the way to mark a log level as trigger. If this log level is triggerd, the buffer will be flushed which means that all buffered log requests are forwarded to all attached loggers.

After writing about all the fundamental knowledge, lets move on to the "Upward Flush Buffer". The upward flush buffer extends the idea of a triggerd buffer flush by the concept of triggering this flush also if a log level of a higher priority is called. To keep it short, you can define "if at least this log level is called, flush the buffer".

The whole component is shipped with a log of examples.
Since the upward flush buffer trigger is the crown jewel of the component, i want to quote the output of the upward flush buffer trigger versus normal logger example.


----------------------------------------
First run with normal logger without log level restriction.
----------------------------------------
[1381003509] [debug] [processing id 1]
[1381003509] [info] [collection information and data id: 1]
[1381003509] [debug] [done]
[1381003509] [debug] [processing id 3]
[1381003509] [info] [collection information and data id: 3]
[1381003509] [info] [data can not handled with this process, queueing data to manual processing list]
[1381003509] [debug] [done]
[1381003509] [debug] [processing id 8]
[1381003509] [info] [collection information and data id: 8]
[1381003509] [info] [logical problem in data on key 3]
[1381003509] [notice] [trying to recalculate data]
[1381003509] [info] [setting data value of key 7 to default]
[1381003509] [debug] [finished]
[1381003509] [debug] [processing id 4]
[1381003509] [info] [collection information and data id: 4]
[1381003509] [debug] [done]
[1381003509] [debug] [processing id 5]
[1381003509] [info] [collection information and data id: 5]
[1381003509] [info] [logical problem in data on key 6]
[1381003509] [notice] [trying to recalculate data]
[1381003509] [warning] [setting data value of key 7 to default not possible]
[1381003509] [notice] [trying to revert modification]
[1381003509] [error] [runtime data and data in storage differs, can not revert modification]
[1381003509] [critical] [lost connection to storage]
[1381003509] [alert] [can not unlock and schedule processing to id 5]
[1381003509] [debug] [done]
[1381003509] [debug] [processing id 6]
[1381003509] [critical] [lost connection to storage]
[1381003509] [alert] [can not unlock and schedule processing to id 6]
[1381003509] [debug] [done]
----------------------------------------
Second run with normal logger and log level restriction to warning and above.
----------------------------------------
[1381003509] [warning] [setting data value of key 7 to default not possible]
[1381003509] [error] [runtime data and data in storage differs, can not revert modification]
[1381003509] [critical] [lost connection to storage]
[1381003509] [alert] [can not unlock and schedule processing to id 5]
[1381003509] [critical] [lost connection to storage]
[1381003509] [alert] [can not unlock and schedule processing to id 6]
----------------------------------------
Third run with manipulate buffer logger.
----------------------------------------
[1381003509] [debug] [processing id 5]
[1381003509] [info] [collection information and data id: 5]
[1381003509] [info] [logical problem in data on key 6]
[1381003509] [notice] [trying to recalculate data]
[1381003509] [warning] [setting data value of key 7 to default not possible]
[1381003509] [notice] [trying to revert modification]
[1381003509] [error] [runtime data and data in storage differs, can not revert modification]
[1381003509] [critical] [lost connection to storage]
[1381003509] [alert] [can not unlock and schedule processing to id 5]
[1381003509] [debug] [processing id 6]
[1381003509] [critical] [lost connection to storage]
[1381003509] [alert] [can not unlock and schedule processing to id 6]

What does this example show you?
The example shows typical log entries generated by a process that is dealing with a bunch of data.
"First run" is the regular massiv number of entries you have to deal with when you are running you logger without restrictions.
As you can see, it takes some time to figure out if something important happens. Even to find the place where something important happens is hard to find. The "second run" is an example when you run you logger in the restriction of "only log level of warning or above".
First of all, you notice that no debug or info messages are logged. But what is bad about that? You either miss important informations (like the process or data id) or you have to flood your logs with all informations for each log request.
Finally, the "third run" shows what i mean when i am writing about "putting back freedom and silence in your log files". The logger only logs when a critical log level is reached and provides all available informations. If nothing bad happens, nothing will be logged. Quite nice, isn't it?
If a part of the data is processed, the buffer is cleaned when nothing happens. If an important log level is triggerd, the buffer is flushed and all collected log requests are forwarded to all attached loggers.

If you find bugs, bad namings, ugly code, have ideas to improve this component, pull your code or became a participant :-).

PHP Component - Data Type

By using this component, you are able to use type hints also for basic data types.
This component includes class definitions for php basic data types like:

  • Boolean
  • Floating point
  • Integer
  • String
  • Numeric

Features

  • Enables type hints for basic php types
  • Types shipped with useful methods
  • Are comparable with native php types by using "=="
  • Provides generic type casting by implemented "toString()" methods (and so on)

Usage

Example


/**
 * Class with type hint for string
 *
 * @author stev leibelt 
 * @since 2013-08-04
 */
class MyClass
{
    /**
     * @var array
     * @author stev leibelt 
     * @since 2013-08-04
     */
    private $strings = array();

    /**
     * Super cool method with type hint for string
     *
     * @author stev leibelt 
     * @since 2013-08-04
     */
    public function addString(\Net\Bazzline\Component\DataType\String $string)
    {
        $this->strings[] = $string;

        return $this;
    }
}

$myString = new \Net\Bazzline\Component\DataType\String('super cool test string');

$myClass = new MyClass();
$myClass->addString($myString);

Hints

  • Extend provided types with classes in own namespace.
  • If you add a super cool method to your type, push it and be a part of the development team

Install

Via Git


cd path/to/my/git/respositories
mkdir -p stevleibelt/php_component_data_type
cd stevleibelt/php_component_data_type

git clone git://github.com/stevleibelt/php_component_data_type.git .

Via Composer


require: "net_bazzline/component_data_type": "dev-master"

Why?

I started developing this component because of the many casts i have to do while dealing with php's basic data types. As general, i searched the web for existing and easy to use components but could not find them. If you find one, please tell me. Last but not least SplTypes are still experimental.