Skip to content

Instantly share code, notes, and snippets.

@MontealegreLuis
MontealegreLuis / example.php
Created July 25, 2014 05:02
More examples of Interface, Trait and Abstract Class
<?php
abstract class Animal
{
/** @type string */
protected $name;
/**
* @param string $name
*/
public function __construct($name)
@MontealegreLuis
MontealegreLuis / Autoloader.php
Created July 24, 2014 03:44
Abstract class, interface, and trait example.
<?php
class Autoloader
{
/**
* @param string $className
*/
public function autoload($className)
{
require str_replace('\\', '/', $className) . '.php';
}
@MontealegreLuis
MontealegreLuis / Autoloader.php
Created July 24, 2014 03:22
OOP visibility and type hinting examples
<?php
class Autoloader
{
/**
* @param string $className
*/
public function autoload($className)
{
require str_replace('\\', '/', $className) . '.php';
}
@MontealegreLuis
MontealegreLuis / MoneySpec.php
Created April 23, 2014 23:51
PHPUnit and phpspec examples
<?php
namespace spec\Money;
use PhpSpec\ObjectBehavior;
use Money\Currency;
use Money\Money;
class MoneySpec extends ObjectBehavior
{
public function it_should_be_initializable(Currency $currency)
@MontealegreLuis
MontealegreLuis / DoctrineTable.php
Last active August 5, 2021 12:44
Pagination and DDD
<?php
namespace Doctrine1\TableGateway;
use \Doctrine_Record as Record;
use \Doctrine_Query as Query;
use \Doctrine1\QuerySpecifications\Specification;
abstract class DoctrineTable
{
protected $record;
@MontealegreLuis
MontealegreLuis / composer.json
Created November 24, 2013 03:52
composer.json for Drupal 8 + DrupalAppConsole
{
"name": "drupal/drupal",
"description": "Drupal is an open source content management platform powering millions of websites and applications.",
"type": "drupal-core",
"license": "GPL-2.0+",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/MontealegreLuis/DrupalAppConsole.git"
}
@MontealegreLuis
MontealegreLuis / ajax.js
Created September 12, 2013 19:11
Ajax function
function CreateAjax() {
var objetoAjax = false;
try {
/* Para navegadores distintos a Internet Explorer */
objetoAjax = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
/* Para explorer */
objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
@MontealegreLuis
MontealegreLuis / date-diff.php
Created June 20, 2013 20:20
Difference in hours between two dates.
<?php
$now = new DateTime('now', new DateTimeZone('America/Mexico_City'));
$twoHoursAgo = clone $now;
$twoHoursAgo = $twoHoursAgo->sub(new DateInterval('PT2H'));
$diff = $now->diff($twoHoursAgo);
echo $diff->format("%H hours\n");
@MontealegreLuis
MontealegreLuis / VenueTypeFixture.php
Last active December 14, 2015 23:19
Slim application functional test (Very simplified version of a RESTful Web Service)
<?php
// /tests/functional/Application/DataFixture/VenueTypeFixture.php
namespace Application\DataFixture;
use \Doctrine\DBAL\Connection;
class VenueTypeFixture
{
protected $connection;
@MontealegreLuis
MontealegreLuis / find-dups-array.php
Created March 8, 2013 18:24
Finding duplicates in an array
<?php
$array = array('pedro', 'juan', 'paco', 'pedro');
$repeated = array_filter(array_count_values($array), function($count) {
return $count > 1;
});
foreach ($repeated as $key => $value) {
echo "Key '$key' is repeated $value times <br />";
}