<commit_before><?php

/**
 * Plugin Controller
 *
 * This is the main controller for this plugin
 *
 * PHP version 5.3
 *
 * LICENSE: No License yet
 *
 * @category  Reliv
 * @package   RcmSimpleConfigStorages\RcmSimpleConfigStorage
 * @author    <NAME> <<EMAIL>>
 * @copyright 2012 Reliv International
 * @license   License.txt New BSD License
 * @version   GIT: <git_id>
 * @link      http://ci.reliv.com/confluence
 */
namespace RcmSimpleConfigStorage\Controller;
use Doctrine\ORM\EntityManager;
use \RcmSimpleConfigStorage\StorageEngine\NewInstanceRepo,
    \RcmSimpleConfigStorage\StorageEngine\DoctrineSerializedRepo;
/**
 * Plugin Controller
 *
 * This is the main controller for this plugin
 *
 * @category  Reliv
 * @package   RcmSimpleConfigStorages\RcmSimpleConfigStorage
 * @author    <NAME> <<EMAIL>>
 * @copyright 2012 Reliv International
 * @license   License.txt New BSD License
 * @version   Release: 1.0
 * @link      http://ci.reliv.com/confluence
 *
 */
class SimpleConfigStorageController
    extends \Zend\Mvc\Controller\AbstractActionController
    implements \Rcm\Plugin\PluginInterface
{
    /**
     * @var string Tells function renderInstance() which template to use.
     */
    protected $template;

    /**
     * Stores configs for active instances
     * Now there is only one type of repo but this may become swap-able later
     * @var \RcmSimpleConfigStorage\StorageEngine\DoctrineSerializedRepo
     */
    protected $configRepo;

    protected $defaultInstanceConfig;

    protected $pluginName;

    protected $pluginNameLowerCaseDash;

    protected $pluginDirectory;

    /**
     * @var \Doctrine\ORM\EntityManager entity manager
     */
    protected $entityMgr;

    /**
     * Caches instance configs to speed up multiple calls to getInstanceConfig()
     * @var array
     */
    private $instanceConfigs=array();

    function __construct(
        EntityManager $entityMgr,
        $config,
        $pluginDirectory = null
    ) {
        $this->entityMgr = $entityMgr;
        $this->configRepo = new DoctrineSerializedRepo($entityMgr);

        if(!$pluginDirectory){
            //Allow auto path detection for controllers that extend this class
            $reflection = new \ReflectionClass(get_class($this));
            $pluginDirectory =
                realpath(dirname($reflection->getFileName()) . '/../../../');
        }

        $this->pluginDirectory=$pluginDirectory;
        $this->pluginName=basename($pluginDirectory);
        $this->pluginNameLowerCaseDash=$this->camelToHyphens($this->pluginName);
        $this->template = $this->pluginNameLowerCaseDash.'/plugin';

        $this->defaultInstanceConfig=$config['rcmPlugin'][$this->pluginName]
        ['defaultInstanceConfig'];

    }

    /**
     * Allows core to properly pass the request to this plugin controller
     * @param $request
     */
    function setRequest($request){
        $this->request = $request;
    }

    /**
     * Reads a plugin instance from persistent storage returns a view model for
     * it
     *
     * @param int $instanceId plugin instance id
     *
     * @return \Zend\View\Model\ViewModel
     */
    function renderInstance($instanceId, $extraViewVariables = array()){
        $view = new \Zend\View\Model\ViewModel(
            array_merge(
                array(
                    'instanceId' => $instanceId,
                    'ic' => $this->getInstanceConfig($instanceId)
                ),
                $extraViewVariables
            )
        );
        $view->setTemplate($this->template);
        return $view;
    }

    public function getNewInstanceConfig(){
        return $this->defaultInstanceConfig;
    }

    /**
     * Returns a view model filled with content for a brand new instance. This
     * usually comes out of a config file rather than writable persistent
     * storage like a database.
     *
     * @return \Zend\View\Model\ViewModel
     */
    function renderDefaultInstance($instanceId, $extraViewVariables = array()){
        $view = new \Zend\View\Model\ViewModel(
            array_merge(
                array(
                    'instanceId' => $instanceId,
                    'ic' => $this->getNewInstanceConfig($instanceId)
                ),
                $extraViewVariables
            )
        );
        $view->setTemplate($this->template);<commit_msg>Moved cart enabled to config file.<commit_after><?php

/**
 * Plugin Controller
 *
 * This is the main controller for this plugin
 *
 * PHP version 5.3
 *
 * LICENSE: No License yet
 *
 * @category  Reliv
 * @package   RcmSimpleConfigStorages\RcmSimpleConfigStorage
 * @author    <NAME> <<EMAIL>>
 * @copyright 2012 Reliv International
 * @license   License.txt New BSD License
 * @version   GIT: <git_id>
 * @link      http://ci.reliv.com/confluence
 */
namespace RcmSimpleConfigStorage\Controller;
use Doctrine\ORM\EntityManager;
use \RcmSimpleConfigStorage\StorageEngine\NewInstanceRepo,
    \RcmSimpleConfigStorage\StorageEngine\DoctrineSerializedRepo;
/**
 * Plugin Controller
 *
 * This is the main controller for this plugin
 *
 * @category  Reliv
 * @package   RcmSimpleConfigStorages\RcmSimpleConfigStorage
 * @author    <NAME> <<EMAIL>>
 * @copyright 2012 Reliv International
 * @license   License.txt New BSD License
 * @version   Release: 1.0
 * @link      http://ci.reliv.com/confluence
 *
 */
class SimpleConfigStorageController
    extends \Zend\Mvc\Controller\AbstractActionController
    implements \Rcm\Plugin\PluginInterface
{
    /**
     * @var string Tells function renderInstance() which template to use.
     */
    protected $template;

    /**
     * Stores configs for active instances
     * Now there is only one type of repo but this may become swap-able later
     * @var \RcmSimpleConfigStorage\StorageEngine\DoctrineSerializedRepo
     */
    protected $configRepo;

    protected $defaultInstanceConfig;

    protected $pluginName;

    protected $pluginNameLowerCaseDash;

    protected $pluginDirectory;

    protected $config;

    /**
     * @var \Doctrine\ORM\EntityManager entity manager
     */
    protected $entityMgr;

    /**
     * Caches instance configs to speed up multiple calls to getInstanceConfig()
     * @var array
     */
    private $instanceConfigs=array();

    function __construct(
        EntityManager $entityMgr,
        $config,
        $pluginDirectory = null
    ) {
        $this->entityMgr = $entityMgr;
        $this->configRepo = new DoctrineSerializedRepo($entityMgr);

        if(!$pluginDirectory){
            //Allow auto path detection for controllers that extend this class
            $reflection = new \ReflectionClass(get_class($this));
            $pluginDirectory =
                realpath(dirname($reflection->getFileName()) . '/../../../');
        }

        $this->pluginDirectory=$pluginDirectory;
        $this->pluginName=basename($pluginDirectory);
        $this->pluginNameLowerCaseDash=$this->camelToHyphens($this->pluginName);
        $this->template = $this->pluginNameLowerCaseDash.'/plugin';

        $this->defaultInstanceConfig=$config['rcmPlugin'][$this->pluginName]
        ['defaultInstanceConfig'];

        $this->config = $config;

    }

    /**
     * Allows core to properly pass the request to this plugin controller
     * @param $request
     */
    function setRequest($request){
        $this->request = $request;
    }

    /**
     * Reads a plugin instance from persistent storage returns a view model for
     * it
     *
     * @param int $instanceId plugin instance id
     *
     * @return \Zend\View\Model\ViewModel
     */
    function renderInstance($instanceId, $extraViewVariables = array()){
        $view = new \Zend\View\Model\ViewModel(
            array_merge(
                array(
                    'instanceId' => $instanceId,
                    'ic' => $this->getInstanceConfig($instanceId),
                    'config' => $this->config,
                ),
                $extraViewVariables
            )
        );
        $view->setTemplate($this->template);
        return $view;
    }

    public function getNewInstanceConfig(){
        return $this->defaultInstanceConfig;
    }

    /**
     * Returns a view model filled with content for a brand new instance. This
     * usually comes out of a config file rather than writable persistent
     * storage like a database.
     *
     * @return \Zend\View\Model\ViewModel
     */
    function renderDefaultInstance($instanceId, $extraViewVariables = array()){
        $view = new \Zend\View\Model\ViewModel(
            array_merge(
                array(
                    'instanceId' => $instanceId,
                    'ic' => $this->getNewInstanceConfig($instanceId)
                ),
                $extraViewVariables
            )
        );
        $view->setTemplate($this->template);
{'fraction_non_alphanumeric': 0.10626057529610829, 'fraction_numerical': 0.0027072758037225042, 'mean_word_length': 2.429787234042553, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1798500', 'n_tokens_mistral': 2409, 'n_tokens_neox': 2345, 'n_words': 580}