Skip to content

Instantly share code, notes, and snippets.

View ezimuel's full-sized avatar
🇮🇹
Working remotely, since 2008

Enrico Zimuel ezimuel

🇮🇹
Working remotely, since 2008
View GitHub Profile
@ezimuel
ezimuel / CatalogEntity.php
Created December 9, 2014 14:53
Example of Entity for Apigility
namespace Ecommerce\V1\Rest\Catalog;
class CatalogEntity
{
public $id;
public $name;
public $description;
public $picture;
public $price;
public $quantity;
@ezimuel
ezimuel / gist:f34b22f347d4a0c985a1
Created June 25, 2015 07:38
New stratigility example, updated with PR zendframework/zend-stratigility#12
<?php
use Zend\Stratigility\MiddlewarePipe;
use Zend\Diactoros\Server;
require 'vendor/autoload.php';
$app = new MiddlewarePipe();
$server = Server::createServer($app, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
// Injected for all the URL
@ezimuel
ezimuel / test.php
Created August 10, 2015 13:29
Unit test for RouteMiddlewareTest issue #40 zend-expressive
<?php
/**
* Get the router adapters installed
*/
public function getRouterAdapters()
{
$adapters = [];
if (class_exists('Aura\Router\Router')) {
$adapters[] = [ 'Zend\Expressive\Router\Aura' ];
}
@ezimuel
ezimuel / pluginmanager.php
Last active November 7, 2015 16:54
Experimental plugin manager compliant with ContainerInterface
<?php
/**
* Experimantal plugin manager complaint with ContainerInterface with options support
* using the optional Interface rule of PHP
*/
use Interop\Container\ContainerInterface;
class PluginManager implements ContainerInterface
{
@ezimuel
ezimuel / sign.sh
Created March 14, 2016 15:50
Sign and verify a file using OpenSSL command line tool. It exports the digital signature in Base64 format.
#!/bin/bash
# Sign a file with a private key using OpenSSL
# Encode the signature in Base64 format
#
# Usage: sign <file> <private_key>
#
# NOTE: to generate a public/private key use the following commands:
#
# openssl genrsa -aes128 -passout pass:<passphrase> -out private.pem 2048
# openssl rsa -in private.pem -passin pass:<passphrase> -pubout -out public.pem
@ezimuel
ezimuel / install.sh
Created April 19, 2016 11:59
Verify and install composer from bash command line
#!/bin/bash
# Verify and install composer from https://getcomposer.org/installer
me=`basename "$0"`
if [[ $# -eq 0 ]] ; then
echo "Usage: $me <hash>"
echo 'where <hash> is the hash value of the installer to verify'
exit 1
fi
@ezimuel
ezimuel / test_bench.php
Created March 8, 2017 12:15
MD5 vs. preg_replace_callback for PDOStament::bindParam() usage in zend-db
<?php
// Testing md5 vs. preg_replace_callback()
$execPreg = 0;
$execMd5 = 0;
for ($i=0; $i<100000; $i++) {
$name = randomName(10);
$start = microtime(true);
$result = preg_replace_callback(
@ezimuel
ezimuel / .htaccess
Created March 14, 2017 16:15
Create a PHP deploy package .zpk for Zend Server
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
@ezimuel
ezimuel / decrypt.php
Created April 26, 2018 13:07
Decrypt a file in PHP form an encrypted file with OpenSSL CLI
<?php
/**
* Decrypt a file generated with the command line:
* openssl enc -aes-256-cbc -in file-to-encrypt -out encrypted-file -k password
*
* To decrypt:
* php decrypt.php encrypted-file password decrypted-file
*
* NOTE: this script has been tested with OpenSSL v.1.1, for old version
* please check if you need to use MD5 instead of SHA256 in EVP_BytesToKey()
@ezimuel
ezimuel / server.php
Created May 31, 2018 14:11
Simple Hello World! HTTP server in PHP with Swoole
<?php
$http = new swoole_http_server("127.0.0.1", 9501);
$http->on("start", function ($server) {
var_dump($server);
echo "Swoole http server is started at http://127.0.0.1:9501\n";
});
$http->on("request", function ($request, $response) {
var_dump($request);