<commit_before><?php

namespace AssetsCompiler\Minifier\View\Helper;

/**
 * Helper for getting bundle scripts path
 *
 * @author    <NAME>
 */
class BundlePath extends \Zend\View\Helper\AbstractHelper
{
    protected $mode;
    protected $persistentPath;
    protected $persistentData;
    protected $developmentMode = null;

    private function persistentData()
    {
        if($this->persistentData == null) {
            $path = $this->getPersistentPath();

            if( file_exists($path) ) {
                $reader = new \Zend\Config\Reader\Xml();
                $this->persistentData = $reader->fromFile($path);
            }
        }

        return $this->persistentData;
    }

    /**
     * getting development mode flag - if it isn't setted to now,
     * trying get it from 'minifier'->'development_mode' configuration
     *
     * @return boolean
     */
    public function getDevelopmentMode() {
        if( $this->developmentMode == null ) {
            $sl = $this->getView()->getHelperPluginManager()->getServiceLocator();

            $config = $sl->get('config');

            $this->developmentMode = isset( $config['minifier']['development_mode'] )
                ? $config['minifier']['development_mode'] : null;
        }
        return $this->developmentMode;
    }

    /**
     * setting development mode flag.
     *
     * @param string $newdevelopmentMode
     */
    public function setDevelopmentMode($developmentMode) {
        $this->developmentMode = $developmentMode;

        return $this;
    }


    /**
     * xml file path where persistent data are stored
     *
     * @return string
     */
    public function getPersistentPath() {
        if( $this->persistentPath == null ) {
            $sl = $this->getView()->getHelperPluginManager()->getServiceLocator();

            $config = $sl->get('config');
            $this->persistentPath = $config['minifier']['persistent_file'];
        }
        return $this->persistentPath;
    }

    /**
     * setting xml file path where persistent data are stored
     *
     * @param string $newpersistentPath
     */
    public function setPersistentPath($persistentPath) {
        $this->persistentPath = $persistentPath;

        return $this;
    }

    public function getMode()
    {
        return $this->mode;
    }

    public function setMode($mode)
    {
        $this->mode = $mode;
        return $this;
    }

    public function pathes( $bundle_name )
    {
        $sl = $this->getView()->getHelperPluginManager()->getServiceLocator();

        $data = $this->persistentData();
        $mode = $this->mode;

        if( !isset( $data[$mode][$bundle_name] ) ) {
            throw new \DomainException( sprintf(
                '%s: Bundle "%s" not exists.',
                __METHOD__,
                $bundle_name
            ));
        }

        $base_path = $this->getView()->basePath();
        if( $this->getDevelopmentMode() ) {
            $sources = $data[$mode][$bundle_name]['sources']['file'];
            $sources = is_scalar($sources) ? array( $sources ) : $sources;
            return array_map( function( $file ) use( $base_path ) {
                return $base_path . $file;
            }, $sources );
        }
        else {
            $file = $data[$mode][$bundle_name]['filepath'];
            return array( $base_path . $file );
        }
    }


    public function __invoke( $bundle_name = null, $action = 'prepend' )
    {
        if( $bundle_name == null ) return $this;

        $files = $this->pathes( $bundle_name );

        foreach( $files as $file ) {
            switch( $this->getMode() ) {
                case 'js':
                    $this->getView()->headScript()->{$action . 'File'}( $file );
                    break;
                case 'css':
                    $this->getView()->headLink()->{$action . 'Stylesheet'}( $file );
                    break;
            }<commit_msg>make bundles view helper working without minifier compile called before. it wasn't needed.<commit_after><?php

namespace AssetsCompiler\Minifier\View\Helper;

/**
 * Helper for getting bundle scripts path
 *
 * @author    <NAME>
 */
class BundlePath extends \Zend\View\Helper\AbstractHelper
{
    protected $mode;
    protected $persistentPath;
    protected $persistentData;
    protected $developmentMode = null;

    private function persistentData()
    {
        if($this->persistentData == null) {
            $path = $this->getPersistentPath();

            if( file_exists($path) ) {
                $reader = new \Zend\Config\Reader\Xml();
                $this->persistentData = $reader->fromFile($path);
            }
        }

        return $this->persistentData;
    }

    private function devConfigData()
    {
        $sl = $this->getView()->getHelperPluginManager()->getServiceLocator();
        $config = $sl->get('config')['minifier'];
        return $config['bundles'][$this->mode]['list'];
    }

    /**
     * getting development mode flag - if it isn't setted to now,
     * trying get it from 'minifier'->'development_mode' configuration
     *
     * @return boolean
     */
    public function getDevelopmentMode() {
        if( $this->developmentMode == null ) {
            $sl = $this->getView()->getHelperPluginManager()->getServiceLocator();

            $config = $sl->get('config');

            $this->developmentMode = isset( $config['minifier']['development_mode'] )
                ? $config['minifier']['development_mode'] : null;
        }
        return $this->developmentMode;
    }

    /**
     * setting development mode flag.
     *
     * @param string $newdevelopmentMode
     */
    public function setDevelopmentMode($developmentMode) {
        $this->developmentMode = $developmentMode;

        return $this;
    }


    /**
     * xml file path where persistent data are stored
     *
     * @return string
     */
    public function getPersistentPath() {
        if( $this->persistentPath == null ) {
            $sl = $this->getView()->getHelperPluginManager()->getServiceLocator();

            $config = $sl->get('config');
            $this->persistentPath = $config['minifier']['persistent_file'];
        }
        return $this->persistentPath;
    }

    /**
     * setting xml file path where persistent data are stored
     *
     * @param string $newpersistentPath
     */
    public function setPersistentPath($persistentPath) {
        $this->persistentPath = $persistentPath;

        return $this;
    }

    public function getMode()
    {
        return $this->mode;
    }

    public function setMode($mode)
    {
        $this->mode = $mode;
        return $this;
    }

    public function pathes( $bundle_name )
    {
        $sl = $this->getView()->getHelperPluginManager()->getServiceLocator();

        $base_path = $this->getView()->basePath();
        if( $this->getDevelopmentMode() ) {
            $data = $this->devConfigData();

            $sources = $data[$bundle_name]['sources'];
            $sources = is_scalar($sources) ? array( $sources ) : $sources;
            return array_map( function( $file ) use( $base_path ) {
                return $base_path . $file;
            }, $sources );
        }
        else {
            $data = $this->persistentData()[$this->mode];
            if( !isset( $data[$bundle_name] ) ) {
                throw new \DomainException( sprintf(
                    '%s: Bundle "%s" not exists.',
                    __METHOD__,
                    $bundle_name
                ));
            }

            $file = $data[$bundle_name]['filepath'];
            return array( $base_path . $file );
        }
    }


    public function __invoke( $bundle_name = null, $action = 'prepend' )
    {
        if( $bundle_name == null ) return $this;

        $files = $this->pathes( $bundle_name );

        foreach( $files as $file ) {
            switch( $this->getMode() ) {
                case 'js':
                    $this->getView()->headScript()->{$action . 'File'}( $file );
                    break;
                case 'css':
                    $this->getView()->headLink()->{$action . 'Stylesheet'}( $file );
                    break;
            }
{'fraction_non_alphanumeric': 0.14058129636385747, 'fraction_numerical': 0.0, 'mean_word_length': 1.9550844412504491, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2976958', 'n_tokens_mistral': 2329, 'n_tokens_neox': 2211, 'n_words': 479}