Skip to content

Instantly share code, notes, and snippets.

@ilya-dev
ilya-dev / x0_taste.php
Created April 28, 2014 16:33
What x0 might look like
<?php
/**
* @name facade:resolve
* @desc Show underlying classes and the corresponding IoC bindings
* @sign {query:optional:"The query string":"*"}
*/
class SomeCommand {
public function go($input, $output)
@ilya-dev
ilya-dev / project_x0.php
Last active August 29, 2015 14:00
Something I am working on...
<?php
// command-name {name:required} {age:optional:"Jack"}
// command-name {--name} {--age:required} {--country:optional:USA}
// facade:resolve "Show underlying classes and the corresponding IoC bindings" {query:optional:"Query string":"*"}
listen("say-hello")->act(function($input, $output) {
$output("Hello, world!");
});
@ilya-dev
ilya-dev / runner.php
Last active August 29, 2015 13:59
Laravel Task Runner - how that might look like
<?php
// in app/tasks.php
// the second argument contains the array of "dependencies"
task("default", ["minify_css", "minify_js", "concatenate"]);
// smart enough to analyze the arguments
// and "inject" required components
task("minify_css", function($minifyCss)
@ilya-dev
ilya-dev / app_self_update.php
Last active March 1, 2016 23:18
Raw prototype of an application updater
<?php namespace Acme;
use Illuminate\Filesystem\Filesystem;
class Updater {
/**
* The Filesystem instance
*
* @var Illuminate\Filesystem\Filesystem
@ilya-dev
ilya-dev / tips1.php
Created April 2, 2014 15:58
To prevent an accidental assignment when comparing two variables, wrap the first one within parentheses.
<?php
$foo = 10; $bar = 9;
var_dump($foo = $bar); // whoops, accidental assignment! but no message will be displayed
var_dump(($foo) = $bar); // again, but this is a syntax error b/c an expression can't have a value assigned to it!
@ilya-dev
ilya-dev / aliases.sh
Created March 29, 2014 16:53
Some very useful Laravel aliases to have in your .bashrc or .zshrc file
alias art="php artisan"
alias art_set_env="sed -i 's/your-machine-name/`hostname`/g' bootstrap/start.php"
@ilya-dev
ilya-dev / declared_classes.php
Last active August 29, 2015 13:57
Getting all classes declared in a PHP file - various solutions.
<?php
function get_declared_class($file)
{
require_once $file;
$classes = get_declared_classes();
return end($classes);
}
<?php
class Bar extends \Exception {}
namespace Foo {
try
{
// do something
@ilya-dev
ilya-dev / laravel_artisan_call.php
Last active August 29, 2015 13:57
[Laravel specific] Works perfectly if you need to execute an Artisan command AND get the output as a string.
<?php
if ( ! \function_exists('artisan_call'))
{
function artisan_call($command, array $parameters = array())
{
$buffer = new \Symfony\Component\Console\Output\BufferedOutput();
\Artisan::call($command, $parameters, $buffer);