source

PHP는 테마 및 플러그인에 대한 주석/헤더를 구문 분석하는 데 어떻게 사용됩니까?

factcode 2023. 10. 31. 22:55
반응형

PHP는 테마 및 플러그인에 대한 주석/헤더를 구문 분석하는 데 어떻게 사용됩니까?

워드프레스 플러그인과 테마는 상단에 다음과 같은 주석이 있습니다.

/**
 * @package Akismet
 */
/*
Plugin Name: Akismet
Plugin URI: http://akismet.com/?return=true
Description: Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from comment and trackback spam</strong>. It keeps your site protected from spam even while you sleep. To get started: 1) Click the "Activate" link to the left of this description, 2) <a href="http://akismet.com/get/?return=true">Sign up for an Akismet API key</a>, and 3) Go to your <a href="admin.php?page=akismet-key-config">Akismet configuration</a> page, and save your API key.
Version: 2.5.6
Author: Automattic
Author URI: http://automattic.com/wordpress-plugins/
License: GPLv2 or later
*/

관리 인터페이스의 플러그인 페이지를 방문하면 다음과 같이 플러그인이 나열됩니다.

스크린샷- shadow.png http://img854.imageshack.us/img854/4526/screenshotwithshadow.png

그것이 문서화를 위한 표준 구문입니까?제 생각에는 그게 할 수 있는 일인 것 같아요.file_get_contents플러그인 파일에서 읽을 수 있습니다. 그러나 워드프레스는 PHP에서 사용될 조작 가능하고 표준화된 정보로 어떻게 파싱합니까?

참조wp-admin/includes/plugin.phpWordPress 파서의 경우.좀 더 구체적으로 말하면, 추출은wp-includes/functions.php:

function get_file_data( $file, $default_headers, $context = '' ) {
        // We don't need to write to the file, so just open for reading.
        $fp = fopen( $file, 'r' );

        // Pull only the first 8kiB of the file in.
        $file_data = fread( $fp, 8192 );

        // PHP will close file handle, but we are good citizens.
        fclose( $fp );

        // Make sure we catch CR-only line endings.
        $file_data = str_replace( "\r", "\n", $file_data );

        if ( $context && $extra_headers = apply_filters( "extra_{$context}_headers", array() ) ) {
                $extra_headers = array_combine( $extra_headers, $extra_headers ); // keys equal values
                $all_headers = array_merge( $extra_headers, (array) $default_headers );
        } else {
                $all_headers = $default_headers;
        }

        foreach ( $all_headers as $field => $regex ) {
                if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $ma
                        $all_headers[ $field ] = _cleanup_header_comment( $match[1] );
                else
                        $all_headers[ $field ] = '';
        }

WP 이외에도 유사한 구현이 있습니다.플러그인 시스템이 이렇게 많은 리소스를 낭비하지 않도록 설계하려면 어떻게 해야 합니까?를 참조하십시오.예를 들면

언급URL : https://stackoverflow.com/questions/13391556/how-is-php-used-to-parse-comments-headers-for-themes-and-plugins

반응형