Example 1:
$math = new Math;
$balance = 12.30;
$deposit = 1.70;
$total = $math->sum($balance, $deposit);
if ($total === 14)
echo 'Ok';
else
echo 'Fail';
; Configurations | |
db_host = 'localhost' | |
db_user = 'zend' | |
db_passwd = '' | |
db_name = 'test' | |
db_driver = 'mysql' | |
;db_port = 3306 | |
;db_charset = 'utf8' | |
dsn = '[db_driver]:host=[db_host];dbname=[db_name]' | |
dsn = 'sqlite::memory:' |
<?php | |
namespace MyApp; | |
class HtmlHandler implements ViewHandler | |
{ | |
public function __invoke(Response $response) | |
{ | |
foreach ($response->getHeaders() as $header) | |
header($header); |
view_path = '/app/views' | |
[options] | |
debug = false | |
charset = 'UTF-8' | |
base_template_class = 'Twig_Template' | |
strict_variables = false | |
autoescape = true | |
cache = false | |
auto_reload = null |
Example 1:
$math = new Math;
$balance = 12.30;
$deposit = 1.70;
$total = $math->sum($balance, $deposit);
if ($total === 14)
echo 'Ok';
else
echo 'Fail';
Or trying. We, as developers, love code. We read, we study, we do stare at a nice code and get amused by it. In the end of the day what we really care about is code and its functionality. Making our work useful is always the main objective and to do that, we have to - let me take a deep breath here - document it.
We have solutions today that circle around documentation blocks for classes, methods, properties and so on. We even made that documentation do something with @Annotations. So we code and (hopefully) document it using an specific markup: PHPDoc.
Don't get me wrong here. I really think PHPDoc is great, but the documentation generated by it is really usefull? Yeah, I know: IDEs do use them and so on. But how many times have an API doc been useful? Can you just give an API doc to someone and expect a lot of understanding from it?
README to the rescue
<?php | |
use FooBar\Test\Mock; | |
// In the sample below, $mock expects the method "sayHelloTo" to be called one time | |
// with the parameter $name equals "Alexandre" and return "Hello Alexandre" | |
$mock = (new Mock('NamespaceVendor\\ClassName'))([ | |
'sayHelloTo' => function($name="Alexandre") { | |
return "Hello Alexandre"; |
#!/usr/bin/env python3 | |
import argparse | |
import sys | |
def tokenize(source): | |
return list(source) | |
def parse(tokens): | |
ast = [] | |
stack = [ast] |
// ==UserScript== | |
// @name Referral: your mom | |
// @namespace yourmom | |
// @description This script changes every utm_source variable in links to 'Your mom'. | |
// @include * | |
// ==/UserScript== | |
var links = document.getElementsByTagName('a'); | |
for(var i=0; i<links.length; i++) { | |
links[i].href = links[i].href.replace(/([&|?])utm_source=(.*)([&|?|^])/,"$1utm_source=Your+mom$3"); |
<?php | |
/** | |
* Example of usage of the "Respect Framework", that is actually | |
* just using one or more Respect components together. | |
* | |
* Using components in version 0.4.* | |
*/ | |
use Respect\Validation\Validator as v; | |
use Respect\Rest\Router; |
<?php | |
/** | |
* @author: Garith | |
*/ | |
class Singleton{ | |
protected static $instance = null; | |
public static function load(){ | |
if(self::$instance === null){ |