@ 2014-01-28T21:48:46Z <?php
namespace Core\Routing {
interface Router {
public function serve($uri);
}
class SimpleRouter implements Router {
public function serve($uri) {
echo 'Serving request: ', $uri, ' using ', __CLASS__;
}
}
class FancyRouter implements Router {
public function serve($uri) {
echo 'Serving request: ', $uri, ' using ', __CLASS__;
}
}
}
namespace Core\Database {
interface Connection {
public function query($sql);
}
class MySQLConnection implements Connection {
public function query($sql) {
echo 'Querying: ', $sql, ' using ', __CLASS__;
}
}
class MariaDBConnection implements Connection {
public function query($sql) {
echo 'Querying: ', $sql, ' using ', __CLASS__;
}
}
}
namespace Core {
abstract class Application {
protected static $instances = array();
private $properties = array();
public static function getInstance() {
return isset(self::$instances[$className = get_called_class()]) ? self::$instances[$className] : self::$instances[$className] = new static();
}
protected function __construct() {
}
public function __set($propertyName, $value) {
$this->properties[$propertyName] = $value;
}
public function __get($propertyName) {
return is_callable($this->properties[$propertyName]) ? $this->properties[$propertyName] = $this->properties[$propertyName]($this) : $this->properties[$propertyName];
}
}
abstract class WebApplication extends Application {
protected $routerClassName = '\\Core\\Routing\\SimpleRouter'; // TODO: why not use constants here ??? maybe code should be allowed to modify dependencies at runtime ???
protected $databaseConnectionClassName = '\\Core\\Database\\MySQLConnection';
protected function __construct() {
$this->router = function ($application) {
//$routerClassName = $application->routerClassName;
//return new $routerClassName();
return new {$application->routerClassName}();
};
$this->databaseConnection = function ($application) {
$databaseConnectionClassName = $application->databaseConnectionClassName;
return new $databaseConnectionClassName();
};
}
}
}
namespace CompanyName {
final class DiscussionsWebApplication extends \Core\WebApplication {
protected $routerClassName = '\\Core\\Routing\\FancyRouter';
protected $databaseConnectionClassName = '\\Core\\Database\\MariaDBConnection';
}
}
namespace {
CompanyName\DiscussionsWebApplication::getInstance()->router->serve('http://foo.bar/path/to/resource');
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.4.24 0.011 0.044 12.42 5.4.23 0.006 0.038 12.42 5.4.22 0.005 0.036 12.41 5.4.21 0.008 0.034 12.41 5.4.20 0.006 0.039 12.41 5.4.19 0.007 0.036 12.41 5.4.18 0.009 0.034 12.41 5.4.17 0.009 0.041 12.42 5.4.16 0.006 0.039 12.41 5.4.15 0.007 0.041 12.41 5.4.14 0.010 0.042 12.10 5.4.13 0.010 0.038 12.08 5.4.12 0.009 0.034 12.05 5.4.11 0.007 0.035 12.04 5.4.10 0.007 0.036 12.04 5.4.9 0.006 0.037 12.04 5.4.8 0.005 0.038 12.04 5.4.7 0.005 0.036 12.04 5.4.6 0.006 0.035 12.04 5.4.5 0.006 0.036 12.04 5.4.4 0.006 0.034 12.03 5.4.3 0.010 0.031 12.02 5.4.2 0.004 0.036 12.02 5.4.1 0.005 0.035 12.03 5.4.0 0.005 0.036 11.51 5.3.28 0.008 0.038 12.71 5.3.27 0.009 0.036 12.73 5.3.26 0.007 0.038 12.72 5.3.25 0.005 0.038 12.72 5.3.24 0.007 0.036 12.73 5.3.23 0.005 0.039 12.72 5.3.22 0.004 0.038 12.68 5.3.21 0.006 0.039 12.69 5.3.20 0.009 0.037 12.68 5.3.19 0.007 0.037 12.68 5.3.18 0.007 0.039 12.68 5.3.17 0.006 0.038 12.68 5.3.16 0.008 0.036 12.68 5.3.15 0.007 0.038 12.68 5.3.14 0.006 0.039 12.67 5.3.13 0.009 0.038 12.66 5.3.12 0.005 0.040 12.67 5.3.11 0.005 0.041 12.67 5.3.10 0.006 0.036 12.14 5.3.9 0.007 0.036 12.12 5.3.8 0.007 0.036 12.12 5.3.7 0.007 0.036 12.12 5.3.6 0.006 0.043 12.09 5.3.5 0.007 0.045 12.04 5.3.4 0.006 0.043 12.04 5.3.3 0.007 0.041 12.01 5.3.2 0.008 0.036 11.79 5.3.1 0.011 0.035 11.75 5.3.0 0.008 0.040 11.74
preferences:dark mode live preview
140.93 ms | 1394 KiB | 7 Q