⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lib.php

📁 这个类可以用来生成文件的Javascript脚本。 它可以扫描的Javascript脚本文件和提取文件标签在JavaScript意见类似与JavaDoc标签。 该文件可以生成HTML中
💻 PHP
字号:
<?php
/**
 * JSPD - JavaScript PHP Documentor
 * 
 * Pacote de classes para gera玢o de documenta玢o de arquivos JavaScript
 * baseados em coment醨ios especiais.
 *
 * @package JSPD
 * @author  Rafael M. Salvioni <rafael.salvioni@gmail.com>
 */

/**
 * Nome do pacote
 *
 */
define('JSPD_NAME', 'JavaScript PHP Documentor');
/**
 * Vers鉶
 *
 */
define('JSPD_VERSION', '0.1');
/**
 * Assinatura
 *
 */
define('JSPD_SIGN', JSPD_NAME . ' ' . JSPD_VERSION);
/**
 * Identificador de coment醨ios de Arquivo
 *
 */
define('JSPD_TYPE_FILE', 'file');
/**
 * Identificador de coment醨ios de Vari醰eis
 *
 */
define('JSPD_TYPE_VAR', 'var');
/**
 * Identificador de coment醨ios de Fun玢o
 *
 */
define('JSPD_TYPE_FUNCTION', 'function');
/**
 * Identificador de coment醨ios de Classe
 *
 */
define('JSPD_TYPE_CLASS', 'class');
/**
 * Identificador de coment醨ios de M閠odo
 *
 */
define('JSPD_TYPE_METHOD', 'method');
/**
 * Identificador de coment醨ios de Propriedades
 *
 */
define('JSPD_TYPE_PROPERTY', 'property');

/**
 * Classe JSPD_Exception
 * 
 * Exce玢o padr鉶 do pacote.
 *
 * @package JSPD
 * @author  Rafael M. Salvioni <rafael.salvioni@gmail.com>
 */
class JSPD_Exception extends Exception
{
}

/**
 * Classe JSPD_Comment
 * 
 * Representa um coment醨io especial de Documenta玢o.
 *
 * @package JSPD
 * @author  Rafael M. Salvioni <rafael.salvioni@gmail.com>
 */
class JSPD_Comment
{
    /**
     * String de Coment醨io
     *
     * @var string
     */
    private $comment;
    /**
     * Tipo do Elemento
     *
     * @var string
     */
    private $type;
    /**
     * Nome do Elemento que o Coment醨io representa
     *
     * @var string
     */
    private $name;
    /**
     * Tags encontradas no Coment醨io
     *
     * @var array
     */
    private $tags;
    
    /**
     * Recupera e retorna todos os coment醨ios de documenta玢o encontrados
     * na string informada.
     *
     * @param string $jsContents String de conte鷇o
     * @return JSPD_Comment
     */
    public static function getComments($jsContents)
    {
        preg_match_all('/\/\*\#.+?\#\*\//smi', $jsContents, $matches, PREG_SET_ORDER);
        foreach ($matches as $i => $match) {
            $matches[$i] = new self($match[0]);
        }
        return $matches;
    }
    
    /**
     * CONSTRUTOR
     *
     * @param string $comment Coment醨io especial
     * @throws JSPD_Exception
     */
    public function __construct($comment)
    {
        $this->tags    = array();
        if (preg_match('/\/\*\#(.+?)\#\*\//smi', $comment, $match)) {
            $this->comment = $comment;
            $comment = $match[1];
            preg_match_all('/@(\w+)([^@]*)/smi', $comment, $matches, PREG_SET_ORDER);
            foreach ($matches as $match) {
                $tag = strtolower($match[1]);
                $val = trim($match[2]);
                switch ($tag) {
                    case JSPD_TYPE_CLASS:
                    case JSPD_TYPE_FILE:
                    case JSPD_TYPE_FUNCTION:
                    case JSPD_TYPE_METHOD:
                    case JSPD_TYPE_PROPERTY:
                    case JSPD_TYPE_VAR:
                        $this->type = $tag;
                        $this->name = $val;
                        continue 2;
                }
                if (!isset($this->tags[$tag])) {
                    $this->tags[$tag] = array();
                }
                if ($val != '') {
                    $this->tags[$tag][] = $val;
                }
            }
            if (is_null($this->type)) {
                throw new JSPD_Exception("No comment type defined in \"{$this->comment}\"");
            }
        } else {
            throw new JSPD_Exception("Invalid JSD comment string: \"$comment\"");
        }
    }
    
    /**
     * Retorna o valor de uma tag do Coment醨io.
     * 
     * As tags s鉶 armazenadas como arrays, permitindo a repeti玢o de tags no mesmo coment醨io.
     * Caso o par鈓etro $last seja true, 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -