@param $records
@param null $adapter
@param array $config
@return RecordSet

Make and paginator object
346567
public function make($records, $adapter = null, $config = array())
    {
        $config = array_merge($this->getConfig(), $config);
        $this->setConfig($config);
        $configHelper = new ConfigHelper($this->getConfig());

        if ($adapter) {
            $this->setAdapter($adapter);
        }

        $recordSet = $this->generate($records,$configHelper);
        $infiniteScroll = new InfiniteScroll(new ViewLoader(), $configHelper);

        $linkCreator = new LinkCreator($configHelper, $infiniteScroll);
        $links = $linkCreator->createLinks($recordSet->total());
        $recordSet->setLinks($links);
        return $recordSet;
    }
406330
public function settings(Array $config = []) : Paginator
    {
        foreach( $config as $key => $value )
        {
            $this->$key = $value;
        }        

        $this->class = array_merge($this->config['class'], $this->class ?? []);
        $this->style = array_merge($this->config['style'], $this->style ?? []);

        if( isset($config['url']) && $this->type !== 'ajax' )
        {
            $this->url = Base::suffix(URL::site($config['url']));
        }
        elseif( $this->type === 'ajax' )
        {
            $this->url = 'javascript:;';
        }
        else
        {
            $this->url = CURRENT_CFURL;
        }

        return $this;
    }
796871
protected function getPager(AdapterInterface $adapter, $currentPage)
    {
        $currentPage = (int) $currentPage;
        $pager = new Pagerfanta($adapter);
        $pager->setNormalizeOutOfRangePages(true);
        $pager->setMaxPerPage(
            $this->configResolver->getParameter('admin.max_per_page', 'netgen_information_collection')
        );
        $pager->setCurrentPage($currentPage > 0 ? $currentPage : 1);

        return $pager;
    }
1209739
public function getRecord($recordId, $dataDimensions = null)
    {

        if ($dataDimensions == null) {
            $dataDimensions = $this->getCurrentDataDimensions();
        }

        if ($this->isSingleContentRecordCaching()) {
            $cacheKey = $this->createCacheKey('record', [$this->getCurrentContentTypeName(), $recordId],
                                              $dataDimensions);

            $data = $this->getCacheProvider()->fetch($cacheKey);

            if ($data) {

                $data = json_decode($data, true);
                $recordFactory = $this->getRecordFactory();
                $record        = $recordFactory->createRecordFromJSON($this->getCurrentContentTypeDefinition(), $data);

                $record->setLanguage($dataDimensions->getLanguage());
                $record->setWorkspace($dataDimensions->getWorkspace());
                $record->setViewName($dataDimensions->getViewName());

                $record->setRepository($this);

                return $record;
            }

            $record = parent::getRecord($recordId, $dataDimensions);

            if ($record) {
                $data = json_encode($record);

                $this->getCacheProvider()->save($cacheKey, $data, $this->singleContentRecordCaching);
            }

            return $record;
        }

        return parent::getRecord($recordId, $dataDimensions);
    }
324170
protected function _createConnection( $name, $adapter )
	{
		$host = $this->_config->get( 'resource/' . $name . '/host' );
		$port = $this->_config->get( 'resource/' . $name . '/port' );
		$user = $this->_config->get( 'resource/' . $name . '/username' );
		$pass = $this->_config->get( 'resource/' . $name . '/password' );
		$sock = $this->_config->get( 'resource/' . $name . '/socket' );
		$dbase = $this->_config->get( 'resource/' . $name . '/database' );

		$dsn = $adapter . ':dbname=' . $dbase;
		if( $sock == null )
		{
			$dsn .= isset( $host ) ? ';host=' . $host : '';
			$dsn .= isset( $port ) ? ';port=' . $port : '';
		}
		else
		{
			$dsn .= ';unix_socket=' . $sock;
		}

		$attr = array(
			PDO::ATTR_PERSISTENT => $this->_config->get( 'resource/' . $name . '/opt-persistent', false ),
		);

		$pdo = new PDO( $dsn, $user, $pass, $attr );
		$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
		$dbc = new MW_DB_Connection_PDO( $pdo );

		foreach( $this->_config->get( 'resource/' . $name . '/stmt', array() ) as $stmt ) {
			$dbc->create( $stmt )->execute()->finish();
		}

		return $dbc;
	}
327878
public function getRecord($recordId, $dataDimensions = null)
    {
        if ($dataDimensions == null) {
            $dataDimensions = $this->getCurrentDataDimensions();
        }

        $record = $this->readConnection->getRecord($recordId, $this->getCurrentContentTypeName(), $dataDimensions);

        if ($record) {
            $record->setRepository($this);
        }

        return $record;
    }
104763
public function createOssAdapter(array $config)
    {
        $root = $config['root'] ?? null;
        $oss = new OssClient($config['access_id'], $config['access_secret'], $config['endpoint'],
            $config['isCName'] ?? false,
            $config['securityToken'] ?? null,
            $config['proxy'] ?? null
        );
        $oss->setTimeout($config['timeout'] ?? 3600);
        $oss->setConnectTimeout($config['connectTimeout'] ?? 10);
        $oss->setUseSSL($config['useSSL'] ?? false);
        return $this->adapt($this->createFlysystem(
            new OssAdapter($oss, $config['bucket'], $root), $config
        ));
    }
451402
protected function fillArrayWithRecords( array &$results, array $records, $limit, $offset )
    {
        $length = min( count( $records ), $limit );

        $index = 0;

        foreach ($records as $record) {
            $offset += $this->fillArrayWithSingleRecord( $results, $record, $offset );

            $index++;

            if ($index >= $length) {
                break;
            }
        }
    }
500317
protected function getStatements($records, $config)
    {
        $statements = [];
        foreach ($records as $record) {
            $duration = null;
            $memory   = null;

            $isSuccess = (LogLevel::INFO === strtolower($record['level_name']));

            $detailsCount = count($config['details']);
            $parameters   = explode($config['outerGlue'], $record['message'], $detailsCount + 1);
            if (count($parameters) === ($detailsCount + 1)) {
                $parameters = array_map('trim', $parameters);
                $_details   = [];
                foreach (array_splice($parameters, 0, $detailsCount) as $string) {
                    list($key, $value) = array_map('trim', explode($config['innerGlue'], $string, 2));
                    $_details[$key] = $value;
                }

                $details = [];
                foreach ($config['details'] as $key => $detail) {
                    if (isset($_details[$detail['name']])) {
                        $value = $_details[$detail['name']];
                        if ('time' === $key) {
                            if (substr_count($value, 'ms')) {
                                $value = (float) $value / 1000;
                            } else {
                                $value = (float) $value;
                            }
                        } else {
                            $suffixes = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
                            $suffix   = substr($value, -2);
                            $i        = array_search($suffix, $suffixes, true);
                            $i        = (false === $i) ? 0 : $i;

                            $value = ((float) $value) * pow(1024, $i);
                        }
                        $details[$key] = $value;
                    }
                }

                if (isset($details['time'])) {
                    $duration = $details['time'];
                }
                if (isset($details['memDelta'])) {
                    $memory = $details['memDelta'];
                }

                $message = end($parameters);

                if ($isSuccess) {
                    $this->queryCount++;
                }
            } else {
                $message = $record['message'];
            }

            $statement = [
                'sql'          => $message,
                'is_success'   => $isSuccess,
                'duration'     => $duration,
                'duration_str' => $this->getDataFormatter()->formatDuration($duration),
                'memory'       => $memory,
                'memory_str'   => $this->getDataFormatter()->formatBytes($memory),
            ];

            if (false === $isSuccess) {
                $statement['sql']           = '';
                $statement['error_code']    = $record['level'];
                $statement['error_message'] = $message;
            }

            $statements[] = $statement;
        }
        return $statements;
    }
824745
protected function createFilesystem(AdapterInterface $adapter, array $config)
    {
        $cache = Arr::pull($config, 'cache');

        $config = Arr::only($config, ['visibility', 'disable_asserts', 'url']);

        if ($cache) {
            $adapter = new CachedAdapter($adapter, $this->createCacheStore($cache));
        }

        return new Filesystem($adapter, count($config) > 0 ? $config : null);
    }
240106
public function paginate($listRows = null, $simple = false, $config = [])
    {
        $result = $this->buildQuery()->paginate($listRows, $simple, $config);
        $this->hydratePivot($result);

        return $result;
    }
1207757
protected function createPdoResolverWithHosts(array $config)
    {
        return function () use ($config) {
            foreach (Arr::shuffle($hosts = $this->parseHosts($config)) as $key => $host) {
                $config['host'] = $host;

                try {
                    return $this->createConnector($config)->connect($config);
                } catch (PDOException $e) {
                    continue;
                }
            }

            throw $e;
        };
    }
353200
protected function generateRecordMissingSubdefs(\record_adapter $record)
    {
        $wanted_subdefs = $record->get_missing_subdefs();

        if (!empty($wanted_subdefs)) {
            $this->getSubdefGenerator()->generateSubdefs($record, $wanted_subdefs);

            foreach ($wanted_subdefs as $subdef) {
                $this->container['monolog']->addInfo("generate " . $subdef . " for record " . $record->getRecordId());
            }
        }

        return count($wanted_subdefs);
    }
826542
private static function executeAdapter($adapter, Request $request, array $config = null)
    {
        if (!in_array('Embed\\Adapters\\AdapterInterface', class_implements($adapter))) {
            throw new \InvalidArgumentException("The class '$adapter' must implements 'Embed\\Adapters\\AdapterInterface'");
        }

        if (call_user_func([$adapter, 'check'], $request)) {
            return new $adapter($request, $config);
        }

        return false;
    }
931108
public function getWriteConnection(AdapterInterface $adapter = null)
    {
        if (null === $this->writeConnection) {
            $this->writeConnection = ConnectionFactory::create($this->writeConfiguration, $adapter);
            $this->writeConnection->setName($this->getName());
        }

        return $this->writeConnection;
    }
1160198
public function pagination($paginator, $config = array())
    {
        if (!$paginator) {
            return '';
        }

        $config = new AnConfig($config);

        $config->append(array(
            'url' => (string) $this->_template->getView()->getRoute(),
            'force' => false,
            'options' => array(
                'limit' => 20,
            ),
        ));

        if (is($paginator, 'AnDomainEntitysetDefault')) {
            $entityset = $paginator;
            $paginator = new AnConfigPaginator(array(
                'offset' => $entityset->getOffset(),
                'limit' => 20,
            ));

            $paginator->total = $entityset->getTotal();
        }

        if (!$paginator instanceof AnConfigPaginator) {
            $paginator = new AnConfigPaginator($paginator);
        }

        $paginator->display = 5;

        //if our total is less than the limit don't show paginator
        if ($paginator->total < $paginator->limit) {
            return;
        }

        $config->paginator = $paginator;

        //convert url to the httpurl object
        $config->url = $this->getService('anahita:http.url', array('url' => $config->url));

        $pages = array();

        foreach ($paginator->pages->offsets as $offset) {
            $page = array();
            $url = clone $config->url;
            $query = array_merge($url->getQuery(true), array('limit' => $offset->limit, 'start' => $offset->offset));

            $url->setQuery($query);

            $page['number'] = $offset->page;
            $page['current'] = $offset->current;
            $page['url'] = (string) $url;

            $pages[] = $page;
        }

        $config['pages'] = $pages;
        $config['total'] = $paginator->total;
        $pages = array('prev','next');

        foreach ($pages as $page) {
            if ($paginator->pages->$page) {
                $url = clone $config->url;
                $query = array_merge($url->getQuery(true), array('limit' => $paginator->pages->$page->limit, 'start' => $paginator->pages->$page->offset));

                $url->setQuery($query);
                $config->{$page.'_page'} = (string) $url;
            }
        }

        return $this->_render('pagination', $config);
    }
262167
public static function init($config, $collectionConfig = array())
    {
        $first = null;

        static::$collectionConfig = $collectionConfig;

        if (empty($config)) {
            return;
        }

        foreach ($config as $key => $value) {
            $value['name'] = $key;

            if (!isset($value['driver'])) {
                throw new Exception(
                    '[Norm] Cannot instantiate connection "'.$key.
                    '", Driver "'.@$value['driver'].'" not found!'
                );
            }

            $Driver = $value['driver'];

            static::$connections[$key] = new $Driver($value);

            if (!static::$connections[$key] instanceof Connection) {
                throw new Exception('Norm connection ['.$key.'] should be instance of Connection');
            }

            if (!$first) {
                $first = $key;
            }
        }

        if (!static::$defaultConnection) {
            static::$defaultConnection = $first;
        }
    }