Hardcore Simple Events Dispatcher for PHP

Events is simple pure functional event dispatching library for PHP 5.5+ and have nice and clear interface with function on(), one(), off(), trigger(), filter(), ensure(), listeners(), events() - that's all!

With sphido/events can:

  • listeners prioritization
  • add/remove listeners
  • filter values by functions
  • stop propagation in function chain
  • and have event default handler

Trigger event

on('event', function () {
  echo "wow it's works yeah!";

trigger('event'); // print wow it's works yeah!

Hardcore simple events for PHP with filter, prioritizing, removing handlers and stop propagation. It's even simpler then my previous version https://github.com/OzzyCzech/events.


Getting GitHub latest release URL

Do you need Download Latest Version button? Try follow PHP code:

function getLatestTagUrl($repository, $default = 'master') {
    $file = @json_decode(@file_get_contents("https://api.github.com/repos/$repository/tags", false,
        stream_context_create(['http' => ['header' => "User-Agent: Vestibulum\r\n"]])
    return sprintf("https://github.com/$repository/archive/%s.zip", $file ? reset($file)->name : $default);

echo getLatestTagUrl('sphido/sphido');
// will return https://github.com/sphido/sphido/archive/v0.2.1.zip


AngularJS $http not sending X-Requested-With header

Angular $http isn’t appending the header X-Requested-With = XMLHttpRequest since Angular 1.3.0.

X-Requested-With header is rarely used in practice and by using it all the time we are riggering preflight checks for crossdomain requests. See commit message

That can cause some problems on PHP side. If you need somehow differentiate XHR and common requests. For example Zend Framework and lot of others PHP frameworks use follow code:

function isXmlHttpRequest() {
 return !empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&

You can easily add on Angular side by following code:

myAppModule.config(['$httpProvider', function($httpProvider) {
    $httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest';


How to add all custom post type to main Wordpress archive.php

Default archive shows only post type if you need show all post types just add follow code to function.php

'pre_get_posts', function ($query) {
        if (
            $query->is_main_query() &&
            !is_admin() &&
            (is_category() || is_tag())
            && empty($query->query_vars['suppress_filters'])
        ) {
            $posts = array_diff(
                get_post_types(['public' => true]), ['page', 'attachment', 'revision', 'forum', 'reply', 'topic'] /* array of ignored types*/
                'post_type', $posts
            return $query;


How to protect your emails with PHP and Javascript

Working with or without javascript it's combine two technique for email protection ROT13 and CSS

function mail($email, $text = null) {
 return '<script type="text/javascript">document.write("' .
   '<a href="mailto:' . $email . '" rel="nofollow">' . ($text ? : $email) . '</a>'
 ) . '".replace(/[a-zA-Z]/g,function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);}));</script>' .
 '<noscript><span style="unicode-bidi: bidi-override; direction: rtl;">' . strrev($email) . '</span></noscript>';