This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$teste = array( | |
array("foo" => "a", "bar" => "b", "timestamp" => 123456), | |
array("foo" => "a", "bar" => "b", "timestamp" => 987654), | |
array("foo" => "a", "bar" => "b", "timestamp" => 654789), | |
array("foo" => "a", "bar" => "b", "timestamp" => 456123) | |
); | |
function sortTimestamp($a, $b) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
spl_autoload_register( | |
function($className) { | |
$fileParts = explode('\\', ltrim($className, '\\')); | |
if (false !== strpos(end($fileParts), '_')) | |
array_splice($fileParts, -1, 1, explode('_', current($fileParts))); | |
$file = implode(DIRECTORY_SEPARATOR, $fileParts) . '.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function stringf($template, array $vars=array()) | |
{ | |
return preg_replace_callback( | |
'/{{(\w+)}}/', | |
function($match) use(&$vars) { return $vars[$match[1]]; }, | |
$template | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Respect\Validation\Validator as v; | |
//Enclosurer | |
function zv($name, $arguments) { | |
$name = ucfirst($name); | |
$validatorName = "Zend_Validate_$name"; | |
$validator = new $validatorName($arguments); | |
return new v::callback(function($input) use ($validator) { | |
return $validator->isValid($input); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Users; | |
use Doctrine\ORM\EntityManager as Entities; | |
use Doctrine\ORM\EntityNotFoundException; | |
use Twig_Environment as Templates; | |
use Respect\Validation\Validatable as Validator; | |
use Respect\Validation\Exceptions\ValidationException; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Infered database schema from naming conventions. | |
* Mapping works without configuration, reflection, annotation, reverse engineering, show tables | |
* or anything like that at all. All samples below generate a single SQL statement with apropriated joins. | |
* | |
* -All tables have a primary key named "id" | |
* -All foreign keys are named table_id | |
* -All association tables (N to N) are named table_table |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function formatSql($sql) | |
{ | |
return preg_replace( | |
'/(select|from|(inner|left) join|where|limit|update|set|insert|values)/i', | |
"\n$1\n ", | |
str_replace("\n", '', $sql) | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ob_start(); | |
register_shutdown_function(function(){ | |
$cacheFile = __DIR__.'/cache/'.date('Y-m-d'); | |
$cacheTime = 18000; | |
if (file_exists($cacheFile) && time() - $cacheTime < filemtime($cacheFile)) { | |
ob_end_flush(); | |
readfile($cacheFile); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//users | |
Web::serve('/users', function() { | |
return 'Hello World'; | |
}); | |
//users/alganet | |
Web::serve('/users/*', function($screenName) { | |
return "Hello $screenName"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$r = new Respect\Rest\Router; | |
$r->get('/', function() { | |
return 'Hello World'; | |
}); | |
$r->get('/users', function() use($users) { | |
return $users->list()->toHTML(); //sample model/view call |
OlderNewer