<?php
/*
 *
 * @package		ARI Framework
 * @author		ARI Soft
 * @copyright	Copyright (c) 2011 www.ari-soft.com. All rights reserved
 * @license		GNU/GPL (http://www.gnu.org/copyleft/gpl.html)
 *
 */

(defined('_JEXEC') && defined('ARI_FRAMEWORK_LOADED')) or die('Direct Access to this location is not allowed.');

AriKernel::import('SimpleTemplate.Filters.FilterBase');

class AriSimpleTemplateJsonDecodeFilter extends AriSimpleTemplateFilterBase
{
    function getFilterName()
    {
        return 'json_decode';
    }

    function parse($string, $assoc = false)
    {
        $assoc = boolval($assoc);
        $retVal = null;

        if (strlen($string) > 0) {
            $retVal = json_decode($string, $assoc);

            if (json_last_error() !== JSON_ERROR_NONE) {
                $retVal = null;
            }
        }

        return $retVal;
    }
}

new AriSimpleTemplateJsonDecodeFilter();