public function testMetadataManual()
 {
     $di = new Phalcon\DI();
     $di->set('modelsManager', function () {
         return new Phalcon\Mvc\Model\Manager();
     });
     $di->set('modelsMetadata', function () {
         return new Phalcon\Mvc\Model\Metadata\Memory();
     });
     $di->set('modelsQuery', 'Phalcon\\Mvc\\Model\\Query');
     $di->set('modelsQueryBuilder', 'Phalcon\\Mvc\\Model\\Query\\Builder');
     $di->set('modelsCriteria', 'Phalcon\\Mvc\\Model\\Criteria');
     $metaData = $di->getShared('modelsMetadata');
     $robotto = new Robotto($di);
     //Robots
     $pAttributes = array(0 => 'id', 1 => 'name', 2 => 'type', 3 => 'year');
     $attributes = $metaData->getAttributes($robotto);
     $this->assertEquals($attributes, $pAttributes);
     $ppkAttributes = array(0 => 'id');
     $pkAttributes = $metaData->getPrimaryKeyAttributes($robotto);
     $this->assertEquals($ppkAttributes, $pkAttributes);
     $pnpkAttributes = array(0 => 'name', 1 => 'type', 2 => 'year');
     $npkAttributes = $metaData->getNonPrimaryKeyAttributes($robotto);
     $this->assertEquals($pnpkAttributes, $npkAttributes);
     $this->assertEquals($metaData->getIdentityField($robotto), 'id');
 }
<?php

$di = new Phalcon\DI();
$di->set('A', function () {
    return new A();
});
$di->set('B', function () use($di) {
    return new B($di->getShared('A'));
});
//trigger autoload
$b = $di->get('B');
unset($b);
$t1 = microtime(true);
for ($i = 0; $i < 10000; $i++) {
    $b = $di->get('B');
}
$t2 = microtime(true);
$results = ['time' => $t2 - $t1, 'files' => count(get_included_files()), 'memory' => memory_get_peak_usage() / 1024 / 1024];
echo json_encode($results);
<?php

$di = new Phalcon\DI();
$di->set('A', function () {
    return new A();
});
//trigger autoload
$a = $di->getShared('A');
unset($a);
$t1 = microtime(true);
for ($i = 0; $i < 10000; $i++) {
    $a = $di->getShared('A');
}
$t2 = microtime(true);
$results = ['time' => $t2 - $t1, 'files' => count(get_included_files()), 'memory' => memory_get_peak_usage() / 1024 / 1024];
echo json_encode($results);
Esempio n. 4
0
$di->set('response', 'Phalcon\\Http\\Response');
//Registering the view component
$di->set('view', function () {
    $view = new \Phalcon\Mvc\View();
    $view->setViewsDir('../apps/views/');
    return $view;
});
$di->set('db', function () {
    return new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => "localhost", "username" => "root", "password" => "", "dbname" => "invo"));
});
//Registering the Models-Metadata
$di->set('modelsMetadata', 'Phalcon\\Mvc\\Model\\Metadata\\Memory');
//Registering the Models Manager
$di->set('modelsManager', 'Phalcon\\Mvc\\Model\\Manager');
try {
    $router = $di->getShared('router');
    $router->handle();
    $view = $di->getShared('view');
    $dispatcher = $di->getShared('dispatcher');
    $dispatcher->setControllerName($router->getControllerName());
    $dispatcher->setActionName($router->getActionName());
    $dispatcher->setParams($router->getParams());
    //Start the view
    $view->start();
    //Dispatch the request
    $dispatcher->dispatch();
    $view->render($dispatcher->getControllerName(), $dispatcher->getActionName(), $dispatcher->getParams());
    $view->finish();
    $response = $di->getShared('response');
    //Pass the output of the view to the response
    $response->setContent($view->getContent());