Created
May 6, 2016 23:35
-
-
Save felipebastosweb/630431218b1faae82fab7b0214a28133 to your computer and use it in GitHub Desktop.
Nano Framework em PHP
This file contains hidden or 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 Fw\Nano as Nano; | |
$app = new Nano; | |
$app->db_config = [ | |
'host' => 'localhost', | |
'user' => 'nano_user', | |
'pass' => 'password', | |
'data' => 'database' | |
]; | |
$app->connect = function() use ($app) | |
{ | |
$config = $app->db_config; | |
$handle = mysqli_connect($config['host'], $config['user'], $config['pass'], $config['data']); | |
$app['db_handle'] = $handle; | |
return $handle; | |
} | |
$app->connect(); | |
$app->account = new class { | |
private $name; | |
private $balance; | |
public $incMoney = function(Money $money) | |
{ | |
return $this->balance += $money; | |
}; | |
public $decMoney = function(Money $money) | |
{ | |
return $this->balance -= $money; | |
}; | |
}; | |
//... | |
//continua ... |
This file contains hidden or 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 | |
//na época do php 5.2 não existia namespace | |
namespace Fw; | |
//na época não existiam containers | |
class Container { | |
protected $data; | |
//acesso através de métodos mágicos | |
public function __set($index, $value) | |
{ | |
$this->data[$index] = $value; | |
} | |
public function __get($index) | |
{ | |
return $this->data[$index]; | |
} | |
} | |
class Nano extends Container {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment