Skip to content

Instantly share code, notes, and snippets.

View lisachenko's full-sized avatar

Alexander Lisachenko lisachenko

View GitHub Profile
@lisachenko
lisachenko / SplClassLoader.php
Created November 3, 2011 06:13 — forked from jwage/SplClassLoader.php
PSR-0 SplClassLoader
<?php
/**
* SplClassLoader implementation that implements the technical interoperability
* standards for PHP 5.3 namespaces and class names.
*
* http://groups.google.com/group/php-standards/web/final-proposal
*
* // Example which loads classes for the Doctrine Common package in the
* // Doctrine\Common namespace.
@lisachenko
lisachenko / chat.php
Created March 7, 2013 07:45
Stomp console chat client
<?php
$author = trim(`whoami`);
$pid = pcntl_fork();
if ($pid === 0) {
// Child process here
$stomp = new Stomp();
$stomp->subscribe('/topic/Chat');
while (true) {
$frame = $stomp->readFrame();
@lisachenko
lisachenko / test.php
Created March 13, 2013 14:24
Check your PHP knowledge
<?
data : {
a: 10;
b: {
echo 'Test';
};
logic: function() {
echo "Hello, world!";
@lisachenko
lisachenko / test.php
Created March 19, 2013 11:16
Check your PHP knowledge #1
<?php
function hello() {
echo 'Hello, magic PHP!';
}
function getCallback() {
return 'hello';
}
$result = ${'_'.!$_=getCallback()}();
@lisachenko
lisachenko / PrivilegedAspect.php
Created May 25, 2013 19:28
Preview of privileged advices in the Go! AOP PHP framework
<?php
use Go\Aop\Aspect;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Annotation\Around;
/**
* Privileged aspect shows the power of privileged advices.
*
* Privileged advice is running in the scope of target for the current joinpoint
@lisachenko
lisachenko / GetterLoggerAspect.php
Last active December 18, 2015 03:09
Zend framework getters
<?php
namespace Aspect;
use Go\Aop\Aspect;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Annotation\After;
use Go\Lang\Annotation\AfterThrowing;
use Go\Lang\Annotation\Before;
use Go\Lang\Annotation\Around;
@lisachenko
lisachenko / Hydrator.php
Created June 27, 2013 14:58
Fastest hydrator
<?php
class Test {
private $a='data';
protected $b=123;
public $c=true;
}
@lisachenko
lisachenko / Example.php
Last active December 21, 2015 18:09
Autowiring preview
<?php
use Warlock\Annotation\Autowired;
class Example
{
/**
* @Autowired("logger", required=true)
* @var LoggerInterface
@lisachenko
lisachenko / test.php
Created March 6, 2015 16:59
Method accessor as closures
class MagicMethodAccessor {
public function test()
{
echo 'Cool';
}
final public function __get($name)
{
if (method_exists($this, $name)) {
$method = (new ReflectionMethod($this, $name))->getClosure($this);
@lisachenko
lisachenko / FCGIServer.php
Created November 8, 2016 15:02
Swoole FCGI server
<?php
use Protocol\FCGI;
use Protocol\FCGI\FrameParser;
use Protocol\FCGI\Record\BeginRequest;
use Protocol\FCGI\Record\EndRequest;
use Protocol\FCGI\Record\Params;
use Protocol\FCGI\Record\Stdin;
use Protocol\FCGI\Record\Stdout;