<commit_before><?php

/**
 * Plugin BaseController
 *
 * Extend or directly-use this plugin controller for any Rcm plugin.
 * This controller does the following for you:
 * 1) Save plugin instance configs in Json format using the Doctrine DB Conn
 * 2) Injects instance configs into the view model for plugins under name "$instanceConfig"
 *
 * PHP version 5.3
 *
 * LICENSE: No License yet
 *
 * @category  Reliv
 * @author    <NAME> <<EMAIL>>
 * @copyright 2012 Reliv International
 * @license   License.txt New BSD License
 * @version   GIT: <git_id>
 */
namespace Rcm\Plugin;

use RcmInstanceConfig\Service\PluginStorageMgrInterface;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\Stdlib\RequestInterface;
use Zend\View\Model\JsonModel;
use Zend\View\Model\ViewModel;

/**
 * Plugin Controller
 *
 * This is the main controller for this plugin
 *
 * @category  Reliv
 * @author    <NAME> <<EMAIL>>
 * @copyright 2012 Reliv International
 * @license   License.txt New BSD License
 * @version   Release: 1.0
 *
 */
class BaseController extends AbstractActionController implements PluginInterface
{
    /**
     * @var string Tells public function renderInstance() which template to use.
     */
    protected $template;

    protected $pluginName;

    protected $nameLowerDashed;

    protected $config;

    protected $pluginStorageMgr;

    public function __construct(
        $config,
        $pluginName = null
    ) {
        if ($pluginName === null) {
            /**
             * Automatically detect the plugin name for controllers that extend
             * this class by looking at the first part of the child's namespace
             */
            $classParts = explode('\\', get_class($this));
            $pluginName = $classParts[0];
        } elseif (substr($pluginName, 0, 1) == '/') {
            /**
             * @TODO REMOVE THIS AFTER REMOVING ALL USES OF IT
             * Support the deprecated method of passing the plugin path rather
             * than its name as the third argument
             */
            $pluginName = basename(realpath($pluginName));
        } else {
            /**
             * When this class is instantiated directly instead of being
             * extended, the plugin name must be passed in as the third argument
             */
            $pluginName = $pluginName;
        }

        $nameLowerDashed = $this->camelToHyphens(
            $pluginName
        );

        $this->template = $nameLowerDashed . '/plugin';

        $this->config = $config;

    }

    /**
     * Reads a plugin instance from persistent storage returns a view model for
     * it
     *
     * @param int   $instanceId
     * @param array $instanceConfig
     *
     * @return ViewModel
     */
    public function renderInstance($instanceId, $instanceConfig)
    {
        $view = new ViewModel(
            array(
                'instanceId' => $instanceId,
                'instanceConfig' => $instanceConfig,
                'config' => $this->config,
            )
        );

        $view->setTemplate($this->template);
        return $view;
    }

    /**
     * Get entity content as JSON. This is called by the editor javascript of
     * some plugins. Urls look like
     * '/rcm-plugin-admin-proxy/rcm-plugin-name/11824/instance-config'
     *
     *
     * @param integer $instanceId instance id
     *
     * @return null
     */
    public function instanceConfigAdminAjaxAction($instanceId)
    {
//        return new JsonModel(
//            array(
//                'instanceConfig' => $this->getInstanceConfig($instanceId),
//                'defaultInstanceConfig' => $this->getDefaultInstanceConfig()
//            )
//        );
    }

    public function postIsForThisPlugin()
    {
        return
            $this->getRequest()->getPost('rcmPluginName') == $this->pluginName;
    }


    /**
     * Converts camelCase to lower-case-hyphens
     *
     * @param string $value the value to convert
     *
     * @return string
     */
    public function camelToHyphens($value)
    {
        return strtolower(preg_replace('/([a-zA-Z])(?=[A-Z])/', '$1-', $value));
    }

    /**
     * @param string $pluginName
     */
    public function setPluginName($pluginName)
    {
        $this->pluginName = $pluginName;
    }

    /**
     * @return string<commit_msg>Updated plugin interface and merged instance configs into core<commit_after><?php

/**
 * Plugin BaseController
 *
 * Extend or directly-use this plugin controller for any Rcm plugin.
 * This controller does the following for you:
 * 1) Save plugin instance configs in Json format using the Doctrine DB Conn
 * 2) Injects instance configs into the view model for plugins under name "$instanceConfig"
 *
 * PHP version 5.3
 *
 * LICENSE: No License yet
 *
 * @category  Reliv
 * @author    <NAME> <<EMAIL>>
 * @copyright 2012 Reliv International
 * @license   License.txt New BSD License
 * @version   GIT: <git_id>
 */
namespace Rcm\Plugin;

use RcmInstanceConfig\Service\PluginStorageMgrInterface;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\Stdlib\RequestInterface;
use Zend\View\Model\JsonModel;
use Zend\View\Model\ViewModel;

/**
 * Plugin Controller
 *
 * This is the main controller for this plugin
 *
 * @category  Reliv
 * @author    <NAME> <<EMAIL>>
 * @copyright 2012 Reliv International
 * @license   License.txt New BSD License
 * @version   Release: 1.0
 *
 */
class BaseController extends AbstractActionController implements PluginInterface
{
    /**
     * @var string Tells public function renderInstance() which template to use.
     */
    protected $template;

    protected $pluginName;

    protected $nameLowerDashed;

    protected $config;

    protected $pluginStorageMgr;

    public function __construct(
        $config,
        $pluginName = null
    ) {
        if ($pluginName === null) {
            /**
             * Automatically detect the plugin name for controllers that extend
             * this class by looking at the first part of the child's namespace
             */
            $classParts = explode('\\', get_class($this));
            $this->pluginName = $classParts[0];
        } elseif (substr($pluginName, 0, 1) == '/') {
            /**
             * @TODO REMOVE THIS AFTER REMOVING ALL USES OF IT
             * Support the deprecated method of passing the plugin path rather
             * than its name as the third argument
             */
            $this->pluginName = basename(realpath($pluginName));
        } else {
            /**
             * When this class is instantiated directly instead of being
             * extended, the plugin name must be passed in as the third argument
             */
            $this->pluginName = $pluginName;
        }

        $this->nameLowerDashed = $this->camelToHyphens(
            $this->pluginName
        );

        $this->template = $this->nameLowerDashed . '/plugin';

        $this->config = $config;

    }

    /**
     * Reads a plugin instance from persistent storage returns a view model for
     * it
     *
     * @param int   $instanceId
     * @param array $instanceConfig
     *
     * @return ViewModel
     */
    public function renderInstance($instanceId, $instanceConfig)
    {
        $view = new ViewModel(
            array(
                'instanceId' => $instanceId,
                'instanceConfig' => $instanceConfig,
                'config' => $this->config,
            )
        );

        $view->setTemplate($this->template);
        return $view;
    }

    /**
     * Get entity content as JSON. This is called by the editor javascript of
     * some plugins. Urls look like
     * '/rcm-plugin-admin-proxy/rcm-plugin-name/11824/instance-config'
     *
     *
     * @param integer $instanceId instance id
     *
     * @return null
     */
    public function instanceConfigAdminAjaxAction($instanceId)
    {
//        return new JsonModel(
//            array(
//                'instanceConfig' => $this->getInstanceConfig($instanceId),
//                'defaultInstanceConfig' => $this->getDefaultInstanceConfig()
//            )
//        );
    }

    public function postIsForThisPlugin()
    {
        if (!$this->getRequest()->isPost()){
            return false;
        }

        return
            $this->getRequest()->getPost('rcmPluginName') == $this->pluginName;
    }


    /**
     * Converts camelCase to lower-case-hyphens
     *
     * @param string $value the value to convert
     *
     * @return string
     */
    public function camelToHyphens($value)
    {
        return strtolower(preg_replace('/([a-zA-Z])(?=[A-Z])/', '$1-', $value));
    }

    /**
     * @param string $pluginName
     */
    public function setPluginName($pluginName)
    {
        $this->pluginName = $pluginName;
    }

    /**
     * @return string
{'fraction_non_alphanumeric': 0.10730001128286133, 'fraction_numerical': 0.005190116213471737, 'mean_word_length': 2.115641476274165, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 59, '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': '7200591', 'n_tokens_mistral': 2474, 'n_tokens_neox': 2365, 'n_words': 701}