protected function parseTemplateTag(array $match)
    {
        $keys = explode('->', $match[1]);

        $context = 'title';
        if ($keys[0][0] === '$') {
            $context = substr(array_shift($keys), 1);
        }

        $previous = null;
        $model = $this->{$context};

        foreach ($keys as $key) {
            $previous = $model;
            $model = (is_object($model))
                ? $model->{$key}
                : $model[$key];
        }

        if ($context === 'dictionary') {
            $model = utf8_encode($model);
        }

        if ($model instanceof Medools\Model) {
            return implode('-', $model->getPrimaryKey());
        }

        switch ($key) {
            case 'billet_tax':
            case 'discount1_value':
            case 'discount2_value':
            case 'discount3_value':
            case 'fine_value':
            case 'interest_value':
            case 'ioc_iof':
            case 'rebate':
            case 'tax_value':
            case 'value_paid':
            case 'value':
                $model = $this->formatMoney($model);
                break;

            case 'discount1_date':
            case 'discount2_date':
            case 'discount3_type_date':
            case 'due':
            case 'emission':
            case 'fine_date':
            case 'interest_date':
                $model = $this->formatDate($model);
                break;

            case 'document':
                $model = $previous->getFormattedDocument();
                break;

            case 'stamp':
            case 'update':
                $model = date('H:i:s d/m/Y', strtotime($model));
                break;

            case 'zipcode':
                $model = Utils\Validation::cep($model);
                break;
        }

        return $model;
    }
protected function parseTemplateTag(array $match)
    {
        $keys = explode('->', $match[1]);

        $context = 'title';
        if ($keys[0][0] === '$') {
            $context = substr(array_shift($keys), 1);
        }

        $previous = null;
        $model = $this->{$context};

        foreach ($keys as $key) {
            $previous = $model;
            $model = (is_object($model))
                ? $model->{$key}
                : $model[$key];
        }

        if ($context === 'dictionary') {
            $model = utf8_encode($model);
        }

        if ($model instanceof Medools\Model) {
            return implode('-', $model->getPrimaryKey());
        }

        switch ($key) {
            case 'billet_tax':
            case 'discount1_value':
            case 'discount2_value':
            case 'discount3_value':
            case 'fine_value':
            case 'interest_value':
            case 'ioc_iof':
            case 'rebate':
            case 'tax_value':
            case 'value_paid':
            case 'value':
                $model = $this->formatMoney($model);
                break;

            case 'discount1_date':
            case 'discount2_date':
            case 'discount3_type_date':
            case 'due':
            case 'emission':
            case 'fine_date':
            case 'interest_date':
                $model = $this->formatDate($model);
                break;

            case 'document':
                $model = $previous->getFormattedDocument();
                break;

            case 'stamp':
            case 'update':
                $model = date('H:i:s d/m/Y', strtotime($model));
                break;

            case 'zipcode':
                $model = Utils\Validation::cep($model);
                break;
        }

        return $model;
    }
protected function parseTemplateTag ( array $ match ) { $ keys = explode ( '->' , $ match [ 1 ] ) ; $ context = 'title' ; if ( $ keys [ 0 ] [ 0 ] === '$' ) { $ context = substr ( array_shift ( $ keys ) , 1 ) ; } $ previous = null ; $ model = $ this -> { $ context } ; foreach ( $ keys as $ key ) { $ previous = $ model ; $ model = ( is_object ( $ model ) ) ? $ model -> { $ key } : $ model [ $ key ] ; } if ( $ context === 'dictionary' ) { $ model = utf8_encode ( $ model ) ; } if ( $ model instanceof Medools \ Model ) { return implode ( '-' , $ model -> getPrimaryKey ( ) ) ; } switch ( $ key ) { case 'billet_tax' : case 'discount1_value' : case 'discount2_value' : case 'discount3_value' : case 'fine_value' : case 'interest_value' : case 'ioc_iof' : case 'rebate' : case 'tax_value' : case 'value_paid' : case 'value' : $ model = $ this -> formatMoney ( $ model ) ; break ; case 'discount1_date' : case 'discount2_date' : case 'discount3_type_date' : case 'due' : case 'emission' : case 'fine_date' : case 'interest_date' : $ model = $ this -> formatDate ( $ model ) ; break ; case 'document' : $ model = $ previous -> getFormattedDocument ( ) ; break ; case 'stamp' : case 'update' : $ model = date ( 'H:i:s d/m/Y' , strtotime ( $ model ) ) ; break ; case 'zipcode' : $ model = Utils \ Validation :: cep ( $ model ) ; break ; } return $ model ; }
Expands a template tag

NOTE:
- Some tags have specific formatting that is applied automatically
- If the tag points to a Medools\Model, its primary key is returned

@param string[] $match Match from preg_replace_callback()

@return string
Expands a template tag