获取新实例

@param string $funcKey
标识
@return object
@throws \Exception
351782
private function getNewInstance(string $funcKey)
    {
        if (! isset($this->classMap[$funcKey])) {
            throw new \UnexpectedValueException('找不到类' . $funcKey . '的实例规则');
        }
        return call_user_func($this->classMap[$funcKey], $this);
    }
437293
public function restore($key = null)
    {
        if (is_null($key)) {
            $mergedData         = array_merge($this->_DATA, $this->_originalDATA);
            $this->_DATA        = $this->_removeNewKeys($mergedData);
            $this->_dataChanged = false;
            $this->_newKeys     = [];
        } else {
            if (array_key_exists($key, $this->_originalDATA)) {
                $this->_DATA[$key] = $this->_originalDATA[$key];
            }
        }

        return $this;
    }
317293
public function commit($args = array()) {
        foreach ($args as $item) {
            $res = mysql_query($item, $this->driver);
            if (!$res) {
                throw new \Exception('事务执行失败！');
            }
        }
        $arg = mysql_query('COMMIT');
        $result = empty($arg);
        mysql_query('END', $this->driver);
        return $result;
    }
1280864
public function remove($key)
    {
        if ($this->getReadOnly()) {
            throw new Exception('只读map，不允许执行删除操作', 100100604);
        }
        if (isset($this->_data[$key])) {
            $value = $this->_data[$key];
            unset($this->_data[$key]);
        } else {
            $value = null;
        }
        return $value;
    }
873835
public function chunk($num = 100, callable $func)
    {
        $this->paramsAutoReset();
        $start = 0;
        $backComdition = $this->sql;//sql组装
        $backTable = $this->table;//操作的表
        $backJoin = $this->join;//是否内联
        $backleftJoin = $this->leftJoin;//是否左联结
        $backrightJoin = $this->rightJoin;//是否右联
        $backBindParams = $this->bindParams;

        while ($result = $this->select($start, $num)) {
            if ($func($result) === false) {
                break;
            }
            $start += count($result);

            $this->sql = $backComdition;//sql组装
            $this->table = $backTable;//操作的表
            $this->join = $backJoin;//是否内联
            $this->leftJoin = $backleftJoin;//是否左联结
            $this->rightJoin = $backrightJoin;//是否右联
            $this->bindParams = $backBindParams;
        }
        $this->paramsAutoReset();
        $this->reset();
        $this->clearBindParams();
    }
155303
public function update($f = false)
    {
        $_where      = '';
        $_table_name = $this->_get_table_name();

        $_set_string = ' SET ';
        $tmp         = array();

        if (is_array($this->data)) {
            foreach ($this->data as $k => $v) {
                $tmp[] = $k . '=' . $v;
            }
            $_set_string .= implode(',', $tmp);
        } elseif (is_string($this->data)) {
            $_set_string .= $this->data;
        }

        if ($this->where) {
            $_where = ' WHERE ' . $this->where;
        } elseif ($this->where == '' && $f == false) {
            throw_error('警告：您似乎漏掉了where条件。如果确认不使用where条件，请使用update(true)');
        }

        // 清理使用过的变量
        $this->data  = array();
        $this->where = '';

        $this->sql = 'UPDATE ' . $_table_name . $_set_string . $_where;
        return $this->conn()->query($this->sql);
    }
1278747
final public function rollBack()
    {
        if (!$this->pdo) {
            throw  new Exception('您还没有连接数据库', Exception::CODE_DATABASE_ERROR);
        }
        if ($this->_begintransaction) {
            $this->pdo->rollBack();
            $this->_begintransaction = false;
        }
        return $this;
    }
971851
public function updateIndexOne(array $data)
    {
        if (!is_array($data)) {
            throw new \Exception('你的索引参数不是一个数组');
        }

        if (count($data) == count($data, 1)) {
            // 一维数组
            $this->getIndex()->update(new \XSDocument($data));
        }

        //索引是否立即生效
        if ($this->flush_index) {
            $this->getIndex()->flushIndex();
        }

        return $this->getIndex();
    }
75183
public function newFromKey($key)
    {
        $scope = $this->get($key);
        if ($this->checkRefs && is_array($scope)) {
            $this->replaceRefs($key, $scope);
        }
        $result = new static($scope);

        return $result;
    }
961557
private function replaceCurrentVersionbyNewVersion()
    {
        $this->fs->copy($this->newInstallerFile, $this->currentInstallerFile, true);

        return $this;
    }
727252
public function buildForStaff()
    {
        if (!method_exists($this, 'toStaff')) {
            throw new \Exception(__CLASS__.'未实现此方法：toStaff()');
        }

        $base = array(
                 'touser'  => $this->to,
                 'msgtype' => $this->getDefaultMessageType(),
                );
        if (!empty($this->staff)) {
            $base['customservice'] = array('kf_account' => $this->staff);
        }

        return array_merge($base, $this->toStaff());
    }
654808
public function update()
    {
        $data = $this->client->get('http://dev.maxmind.com/static/csv/codes/country_continent.csv');

        // Verify server response
        if ($this->client->getErrors() !== null) {
            throw new Exception($this->client->getErrors());
        }

        $lines = explode("\n", $data[0]);

        array_shift($lines);

        $output = [];

        foreach ($lines as $line) {
            $arr = str_getcsv($line);

            if (count($arr) < 2) {
                continue;
            }

            $output[$arr[0]] = $arr[1];
        }

        // Get path
        $path = $this->config('continent_path');

        file_put_contents($path, json_encode($output));

        return "Continent file ({$path}) updated.";
    }
773927
public function cache($key, callable $cachedCallable, $ttl, callable $onNoStaleCacheCallable = null)
    {
        $value = $this->getValue($key);

        if ($value->hasResult() && !$value->isStale()) {
            return $value->getResult();
        }

        if (!($ttl instanceof Ttl)) {
            $ttl = new Ttl($ttl);
        }

        $lock_acquired = $this->lockManager->acquire($key, $ttl->getLockTtl());

        if (!$lock_acquired) {
            if ($value->hasResult()) { // serve stale if present
                return $value->getResult();
            }

            if (!$onNoStaleCacheCallable) {
                $onNoStaleCacheCallable = $this->onNoStaleCacheCallable;
            }

            if ($onNoStaleCacheCallable !== null) {
                $event = new NoStaleCacheEvent($this, $key, $cachedCallable, $ttl);

                call_user_func($onNoStaleCacheCallable, $event);

                if ($event->hasResult()) {
                    return $event->getResult();
                }
            }
        }

        $result = call_user_func($cachedCallable);

        $this->setResult($key, $result, $ttl);

        if ($lock_acquired) {
            $this->lockManager->release($key);
        }

        return $result;
    }
891985
function refresh() {
        $this->client = new $this->clientClassName($this->accessToken, $this->spaceId, $this->cacher);
        $this->requestDecorator = new RequestDecorator();
        $this->requestDecorator->setResource($this->resourceName);
    }
357824
public function commit()
    {
        try {
            $toUpdate = array_merge($this->getFieldsToUpdate(), $this->getFieldsToDelete());

            if (! empty($toUpdate)) {
                $idField  = $this->_item->getIdField();

                $query = "
                    UPDATE
                        `" . $this->getDbPrefix() . $this->_item->getDbContainer() . "`
                    SET
                        " . $this->_getPreparedFields($toUpdate) . "
                    WHERE
                        `$idField` = ?";

                if (! array_key_exists($idField, $toUpdate)) {
                    $toUpdate[$idField] = $this->_item->getId()->getOrig();
                }

                $prepared = Agl::app()->getDb()->getConnection()->prepare($query);

                if (! $prepared->execute(array_values($toUpdate))) {
                    $error = $prepared->errorInfo();
                    throw new Exception("The update query failed (table '" . $this->getDbPrefix() . $this->_item->getDbContainer() . "') with message '" . $error[2] . "'");
                }

                if (Agl::app()->isDebugMode()) {
                    Agl::app()->getDb()->incrementCounter();
                }

                return $prepared->rowCount();
            }
        } catch (Exception $e) {
            throw new Exception($e);
        }

        return true;
    }
236877
public static function create($key, $code = 0, \Exception $prev = null)
    {
        $message = sprintf(
            'Not found server with key "%s".',
            $key
        );

        return new static($message, $code, $prev);
    }
1070766
public function get($key, callable $callback = null, $fresh = false)
    {
        if ($fresh || !$this->has($key)) {
            if (!is_null($callback)) {
                $this->set($key, $callback());
            } else {
                throw new \Exception(sprintf("Cache key '%s' not found.", $key));
            }
        } /* else {
            echo "HIT!";
        } */
        return $this->cache[$key];
    }