<commit_before><?php
/**
 * Zym
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 *
 * @author     <NAME>
 * @category   Zym
 * @package    Paginate
 * @copyright Copyright (c) 2008 Zym. (http://www.assembla.com/wiki/show/zym)
 * @license http://www.assembla.com/wiki/show/dpEKouT5Gr3jP5abIlDkbG/License    New BSD License
 */

/**
 * @author     <NAME>
 * @category   Zym
 * @package    Paginate
 * @copyright Copyright (c) 2008 Zym. (http://www.assembla.com/wiki/show/zym)
 * @license http://www.assembla.com/wiki/show/dpEKouT5Gr3jP5abIlDkbG/License    New BSD License
 */
class Zym_Paginate
{
    /**
     * Constants
     *
     */
    const ITEMS = 'items';
    const PAGES = 'pages';
    const COUNT = 'count';
    const DEFAULT_ITEMS_PER_PAGE = 10;

    /**
     * Instance
     *
     * @var Zym_Paginate
     */
    protected static $_instance = null;

    /**
     * Get the paginate instance
     */
    protected function _getInstance()
    {
        if (!self::$_instance) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }

    /**
     * Paginate a collection.
     *
     * @param array $data
     * @param int $itemsPerPage
     * @return array
     */
    public static function paginate($data, $itemsPerPage = self::DEFAULT_ITEMS_PER_PAGE)
    {
        $paginator = self::_getInstance();

        if ($data instanceof Zend_Db_Table_Rowset_Abstract) {
            $data = $paginator->paginateRowset($data, $itemsPerPage);
        } elseif (is_array($data)) {
        	if ($paginator->isAssocArray($data)) {
                $data = $paginator->paginateAssoc($data, $itemsPerPage);
        	} else {
        		$data = $paginator->paginateNumeric($data, $itemsPerPage);
        	}
        } else {
            $data = array(self::ITEMS => $data,
                          self::PAGES => 1,
                          self::COUNT => count($data));
        }

        return $data;
    }

    /**
     * Check if the array is associative
     *
     * @param array $data<commit_msg>Make getInstance static and public<commit_after><?php
/**
 * Zym
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 *
 * @author     <NAME>
 * @category   Zym
 * @package    Paginate
 * @copyright Copyright (c) 2008 Zym. (http://www.assembla.com/wiki/show/zym)
 * @license http://www.assembla.com/wiki/show/dpEKouT5Gr3jP5abIlDkbG/License    New BSD License
 */

/**
 * @author     <NAME>
 * @category   Zym
 * @package    Paginate
 * @copyright Copyright (c) 2008 Zym. (http://www.assembla.com/wiki/show/zym)
 * @license http://www.assembla.com/wiki/show/dpEKouT5Gr3jP5abIlDkbG/License    New BSD License
 */
class Zym_Paginate
{
    /**
     * Constants
     *
     */
    const ITEMS = 'items';
    const PAGES = 'pages';
    const COUNT = 'count';
    const DEFAULT_ITEMS_PER_PAGE = 10;

    /**
     * Instance
     *
     * @var Zym_Paginate
     */
    protected static $_instance = null;

    /**
     * Get the paginate instance
     */
    public static function getInstance()
    {
        if (!self::$_instance) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }

    /**
     * Paginate a collection.
     *
     * @param array $data
     * @param int $itemsPerPage
     * @return array
     */
    public static function paginate($data, $itemsPerPage = self::DEFAULT_ITEMS_PER_PAGE)
    {
        $paginator = self::getInstance();

        if ($data instanceof Zend_Db_Table_Rowset_Abstract) {
            $data = $paginator->paginateRowset($data, $itemsPerPage);
        } elseif (is_array($data)) {
        	if ($paginator->isAssocArray($data)) {
                $data = $paginator->paginateAssoc($data, $itemsPerPage);
        	} else {
        		$data = $paginator->paginateNumeric($data, $itemsPerPage);
        	}
        } else {
            $data = array(self::ITEMS => $data,
                          self::PAGES => 1,
                          self::COUNT => count($data));
        }

        return $data;
    }

    /**
     * Check if the array is associative
     *
     * @param array $data
{'fraction_non_alphanumeric': 0.13117826188802997, 'fraction_numerical': 0.007964394471773249, 'mean_word_length': 2.0631276901004303, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '345670', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1363, 'n_words': 302}