Skip to content

Instantly share code, notes, and snippets.

@raphaeldealmeida
raphaeldealmeida / operador_ternario.php
Created February 20, 2012 18:02
Operador Ternário PHP 5.3
<?php
$input = 'Raphael';
if(!empty($input)){
echo $input;
}else{
echo 'Vazio' . "\n\r";
}
@raphaeldealmeida
raphaeldealmeida / operador_ternario.php
Created February 20, 2012 18:02
Operador Ternário PHP 5.3
<?php
$input = 'Raphael';
if(!empty($input)){
echo $input;
}else{
echo 'Vazio' . "\n\r";
}
@raphaeldealmeida
raphaeldealmeida / gist:1839268
Created February 15, 2012 21:57
transação com closure
<?php
$em->transactional(function($em){
//...
$em->persist($user);
}
@raphaeldealmeida
raphaeldealmeida / gist:1839261
Created February 15, 2012 21:55
transação sem closure
<?php
$em->getConnection()->beginTransaction();
try{
//...
$em->persist($user);
$em->flush();
$em->getConnection()->commit();
}catch(Exception $e){
$em->getConnection()->rollback();
@raphaeldealmeida
raphaeldealmeida / gist:1839226
Created February 15, 2012 21:50
utilização clojure
<?php
$cores = array(
array('cor' => 'verde'),
array('cor' => 'vermelho'),
array('cor' => 'amarelo')
);
usort($cores, function($a, $b){
return strcmp($a['cor'], $b['cor']);
}
@raphaeldealmeida
raphaeldealmeida / gist:1839171
Created February 15, 2012 21:39
Funções Anonimas
<?php
function(){
echo 'Olá';
}
$saudacao = function(){
echo 'Olá';
};
@raphaeldealmeida
raphaeldealmeida / gist:1839085
Created February 15, 2012 21:24
Composição horizontal PHP 5.4
<?php
trait SomeClass{
public function add($x, $y) { return $x + $y; }
}
class TestComponent {
use SomeClass;
}
@raphaeldealmeida
raphaeldealmeida / gist:1839077
Created February 15, 2012 21:22
Composição horizontal PHP 5.3
<?php
class TestComponent { }
class SomeClass extends CBehavior{
public function add($x, $y) { return $x + $y; }
}
$test_comp = new TestComponent();
$test_comp->attachbehavior('blah', new SomeClass);
@raphaeldealmeida
raphaeldealmeida / gist:1838964
Created February 15, 2012 20:57
Arrays 5.4
<?php
class Service\User{
public function getUser(){
return ['id' => 1,
'name' => 'Raphael Almeida',
'publisher' => true];
}
}
@raphaeldealmeida
raphaeldealmeida / gist:1838903
Created February 15, 2012 20:49
Arrays 5.4
<?php
//array vazio
$lista = [];
//array
$lista = ['Raphael', 'Gabriela', 'Eduarda'];
//array multi-dimensional