Exemple #1
0
<?php

use rock\base\Alias;
use rock\db\BatchQueryResult;
use rock\rbac\Permission;
use rock\rbac\Role;
use rock\Rock;
use rock\security\Security;
use rock\template\Template;
return array_merge(['route' => ['class' => \rock\route\Route::className()], 'access' => ['class' => \rock\access\Access::className()], 'behavior' => ['class' => \rock\components\Behavior::className()], 'db' => ['class' => \rock\db\Connection::className(), 'username' => 'root', 'password' => 'root', 'charset' => 'utf8', 'dsn' => 'mysql:host=localhost;dbname=rockdemo;charset=utf8', 'tablePrefix' => 'spt_', 'aliasSeparator' => '__'], 'BatchQueryResult' => ['class' => BatchQueryResult::className()], 'template' => ['class' => Template::className(), 'locale' => [\rock\LocaleProperties::className(), 'locale'], 'autoEscape' => Template::ESCAPE | Template::TO_TYPE, 'handlerLink' => function ($link, Template $template, array $params = []) {
    if (!($link = Alias::getAlias("@{$link}", [], false))) {
        return '#';
    }
    return $template->autoEscape(\rock\template\filters\BaseFilter::modifyUrl($link, $params));
}, 'extensions' => ['cfg' => function (array $keys) {
    return \rock\helpers\ArrayHelper::getValue(Rock::$config, $keys);
}, 'user' => function (array $keys) {
    if (current($keys) === 'isGuest') {
        return Rock::$app->user->isGuest();
    } elseif (in_array(current($keys), ['isLogged', 'isAuthenticated'], true)) {
        return !Rock::$app->user->isGuest();
    }
    return \rock\helpers\ArrayHelper::getValue(Rock::$app->user->getAll(), $keys);
}, 'call' => function (array $call, array $params = [], Template $template) {
    if (!isset($call[1])) {
        $call[1] = null;
    }
    list($class, $method) = $call;
    if ($class === 'context') {
        $object = $template->context;
        $function = [$object, $method];
Exemple #2
0
 /**
  * Starts a batch query and retrieves data row by row.
  * This method is similar to {@see \rock\db\Query::batch()} except that in each iteration of the result,
  * only one row of data is returned. For example,
  *
  * ```php
  * $query = (new Query)->from('user');
  * foreach ($query->each() as $row) {
  * }
  * ```
  *
  * @param integer $batchSize the number of records to be fetched in each batch.
  * @param ConnectionInterface $connection the database connection. If not set, the "db" application component will be used.
  * @return BatchQueryResult the batch query result. It implements the `Iterator` interface
  * and can be traversed to retrieve the data in batches.
  */
 public function each($batchSize = 100, ConnectionInterface $connection = null)
 {
     return Instance::ensure(['class' => BatchQueryResult::className(), 'query' => $this, 'batchSize' => $batchSize, 'connection' => isset($connection) ? $connection : $this->getConnection(), 'each' => true]);
 }