function main() { $b = new b(); $b->f($b); t::f($b); $b->set($b, 'new value'); t::set($b, 'newer value'); $a = new a(); $a->f($a); t::f($a); }
public function view($file, $vars = [], $paths = []) { // loop through vars and // print our params foreach ($this->_parameters as $key => $value) { if (!array_key_exists($key, $vars)) { $vars[$key] = $value; } } if (!is_array($paths)) { $paths = []; } // paths to find $paths += $this->parent('bolt\\browser')->path('views'); // find this template $find = new Finder(); $base = pathinfo($file)['dirname']; $name = pathinfo($file)['basename']; // loop through each path foreach ($paths as $path) { $files = $find->files()->in(b::path($path, $base))->name($name); if (iterator_count($files)) { $it = iterator_to_array($files); $first = array_shift($it); return new view(['file' => $first->getRealPath(), 'vars' => $vars, 'context' => $this, 'helpers' => []]); } } // nope return false; }
public static function setEngine($ext, $ref) { if (is_string($ref)) { $ref = b::getReflectionClass($ref); } self::$engines[$ext] = $ref; }
public function __construct($dom, $node = false) { $this->_dom = $dom; $this->_node = $node; $this->_guid = b::guid("domref"); $this->attr('data-domref', $this->_guid); }
public function isInterfaceOf($obj, $class) { if (!is_object($obj)) { return false; } return in_array(b::normalizeClassName($class), class_implements($obj)); }
public function get($key, $default = null) { if (!is_numeric($key)) { $key = '[' . trim(str_replace('.', '][', $key), '[]') . ']'; } $value = $this->_access->getValue($this->_value, $key); return b::bucket('create', $value ?: $default); }
function ab() { $this->aprotectedButReally = $this->apublic + $this->aprivate; $a->aprotectedButReally = 1; self::$asprotectedButSBPrivateSelf = 1; static::$asprotectedButSBPrivateStatic = 2; \a::$asprotectedButSBPrivateFull = 3; \b::$asprotectedButSBPrivateChildren = 3; }
function f() { self::nonStaticButSelfClass(); static::nonStaticButSelfClass(); parent::nonStaticButSelfClass(); P::nonStaticAClass(); P::staticAClass(); A1::nonStaticButSelfClass(); \a1::nonStaticButSelfClass(); b::nonStaticButSelfClass(); }
public final function matchRoute(\bolt\browser\route $route, \bolt\browser\request $req) { $collection = b::browser('route\\collection\\create', [$route]); $match = new UrlMatcher($collection, $req->getContext()); // we're going to try and match our request // if not we fall back to error try { return $match->matchRequest($req); } catch (ResourceNotFoundException $e) { return false; } }
public static function fromControllers(\bolt\browser\route\collection $collection) { $routes = []; // get all loaded classes if (($classes = b::getClassImplements('\\bolt\\browser\\route\\face')) != false) { foreach ($classes as $class) { if ($class->name === 'bolt\\browser\\controller' or !$class->hasProperty('routes') and !$class->hasMethod('getRoutes')) { continue; } // skip our controller class and make sure we have at least $routes || getRoutes() $_ = ['ref' => $class, 'collection' => $class->hasProperty('routeCollection') ? $class->getStaticPropertyValue('routeCollection') : ['prefix' => ''], 'routes' => []]; if ($class->hasProperty('routes')) { $_['routes'] = array_merge($_['routes'], $class->getStaticPropertyValue('routes')); } if ($class->hasMethod('getRoutes')) { $name = $class->name; $_['routes'] = array_merge($_['routes'], $name::getRoutes()); } $routes[] = $_; } } foreach ($routes as $class) { $c = new collection(); // loop through routes foreach ($class['routes'] as $key => $route) { $name = b::param('name', false, $route); if (!$name and !is_string($key)) { $name = "route" . rand(9, 999); } else { if (!$name) { $name = $key; } } // no name unset($route['name']); // add our two default things $route['controller'] = $class['ref']->name; $route['action'] = b::param('action', false, $route); // loop through each part and set it $c->add($name, b::browser_route('create', $route)); } // get our prefix vars extract(array_merge(['prefix' => '', 'requirements' => [], 'options' => [], 'host' => false, 'schemes' => []], $class['collection']), EXTR_OVERWRITE); // set prefix $c->addPrefix($prefix, $requirements, $options, $host, $schemes); // add this collection $collection->addCollection($c); } return null; }
function __construct() { a::y(); b::y(); c::y(); d::y(); a::$x; b::$x; c::$x; d::$x; a::$xpr; b::$xpr; c::$xpr; d::$xpr; }
public static function collect() { // collect all engines if (($engines = b::getClassImplements('\\bolt\\render\\engine\\face')) != false) { foreach ($engines as $class) { if ($class->name === 'bolt\\render\\engine\\base') { continue; } $ext = $class->getConstant('EXT'); if (!b::render('hasEngine', $ext)) { b::render('setEngine', $ext, $class); } } } }
public function test_devModeFilter() { if (!class_exists('lessc')) { $this->markTestSkipped('LessPHP is not installed'); } b::env('dev'); // we need out less filter $this->a->filter('less', 'Lessphp'); $this->a->filter('*', 'CssMin', false); $file = b::path($this->dir, 'less/file.less'); $exp = "footer {\n background: green;\n}\n" . "body header {\n background: red;\n}"; $this->assertEquals($exp, $this->a->processFile($file)); b::env('prod'); $exp = "footer{background:green}" . "body header{background:red}"; $this->assertEquals($exp, $this->a->processFile($file)); }
public function __construct($config) { // set our source $this->_source = $config['source']; // handle $handle = $this->_source->getHandle(); // configure $cfg = new Configuration(); // set $cfg->setMetadataDriverImpl(new driver($this)); $cfg->setProxyDir($config['tmp']); $cfg->setProxyNamespace('bolt\\model\\proxy'); // create our entity manager $this->_em = EntityManager::create($handle, $cfg, $handle->getEventManager()); // find all of our defined entities foreach (b::getClassExtends('\\bolt\\model\\entity') as $class) { $this->add($class->getConstant('NAME'), $class->name); } }
public function handle($req, $res) { $route = b::browser('route\\create', ['path' => $this->config->value('route', '/a/{path}'), 'require' => ['path' => '.*']]); // match a route if (($params = $this->matchRoute($route, $req)) === false) { return false; } // content $content = ""; // paths $paths = $req->assets->getDirs(); // explode out the path foreach (explode('&', $params['path']) as $path) { $info = pathinfo($path); // get our path $dir = $info['dirname']; $file = $info['basename']; $ext = $info['extension']; // find this template $find = new Finder(); // loop through each path foreach ($paths as $path) { // find the files $files = $find->files()->in(b::path($path, $dir))->name($file); if (iterator_count($files)) { $it = iterator_to_array($files); $first = array_shift($it); $real = $first->getRealPath(); // rel $rel = str_replace($path, '', $real); // process a file and append it's content $content .= \bolt\browser\assets::instance()->processFile($real, ['rel' => $rel, 'url' => 'http://localhost/' . str_replace('{path}', '', $route->getPath()), 'filterOnly' => $req->query->get('filterOnly')]); } } } // figureo ut $res->headers->set('Content-Type', $this->_mapContentTypeFromExt($ext)); // set our content $res->setContent($content); return $res; }
public function build($params = []) { // what method $method = $this->request->getMethod(); // is there an action $action = b::param('_action', false, $params); // lets figure out what function we're going to call $try = ['dispatch', "{$method}{$action}", $action, $method]; foreach ($try as $func) { if (method_exists($this, $func)) { break; } } // reflect the controller and method // and figure out what params we need $ref = b::getReflectionClass(get_called_class()); // get $args = $this->getArgsFromMethodRef($ref->getMethod($func), $params); // wonderfull, lets call the function and figure out what // they respond with return call_user_func_array([$this, $func], $args); }
<?php spl_autoload_register(function ($classname) { if (in_array($classname, array('a', 'b', 'c'))) { require_once __DIR__ . "/{$classname}.php"; } }); set_error_handler(function ($errno, $errstr, $errfile, $errline) { }, error_reporting()); a::staticTest(); $b = new b(); $b->test();
public function render() { // render $str = b::render('file', $this->_file, ['context' => $this->_context, 'vars' => $this->_vars]); return $str; }
function b() { return b::instance(); }
function C() { b::b(); }
<?php $a = b::c() * 2; $a = b::c() + 2; $a = b::c() / 2; $a = b::c() % 2;
<?php class a { public static $var; public function a($var) { self::$var = $var; } public function ret() { return self::$var; } } class b extends a { public static $var; } class c extends a { } $a = new a('-a-'); $a2 = new a('-a2-'); $b = new b('-b-'); $c = new c('-c-'); b::$var = 'b'; echo 'A: ' . a::$var; echo 'A2: ' . $a2::$var; echo ', B: ' . b::$var; echo ', C: ' . c::$var;
<?php function fiz($a) { var_dump($a); } class a { static function __callStatic($n, $a) { return $a[0]; } } class b extends a { static function bar() { fiz(parent::foo(42)); } } b::bar();
function __construct() { b::b(); }
<?php $a = -b::c();
<?php b::a(); b::d(); b::e(); E::a(); E::d(); E::e(); \E::a(); \E::d(); \E::e(); class b { public function a() { } public static function d() { } public function e() { } } class E { public static function a() { } public static function d() { }
public function b($a) { self::$a = $a; }
<?php trait a { protected $listeners; public function on() { $this->listeners = [123]; return $this->listeners; } } class b { use a; } $b = new b(); var_dump($b->on()); class event { use \Evenement\EventEmitterTrait; } $event = new event(); var_dump($event); $event->on('key1', function ($msg) { echo "key1 event: \n"; var_dump($msg); }); $event->on('key2', function ($val) { return $val + 1; }); class env
{ public $x = 2; function y() { SELF::definedInParent(); SELF::definedInParentParent(); SELF::undefined(); SELF::definedinStatic(); SELF::$pdefinedInParent; SELF::$pdefinedInParentParent; SELF::$pundefined; SELF::$pdefinedinStatic; } function definedinStatic() { print __METHOD__ . "\n"; } private $pdefinedinStatic; } class c { private $x = 1; function definedInParentParent() { print __METHOD__ . "\n"; } private $pdefinedInParentParent; } $b = new b(); //print a::$x print $b->y();
public function processDirTree($path, $ext) { $files = b::getRegexFiles($path, "^.+\\.{$ext}\$"); $tree = []; foreach ($files as $file) { $tree[$file] = $this->processFileTree($this->getFile($file), $ext); } return $tree; }