zoukankan      html  css  js  c++  java
  • PHP 面向对象及Mediawiki 框架分析(二)

    mediaHandler可以理解为处理media文件的

    /includes/filerepo/file/File.php
    /**
    * Get a MediaHandler instance for this file
    *
    * @return MediaHandler|bool Registered MediaHandler for file's MIME
    type
    * or false if none found
    */
    function getHandler() {
    if ( !isset( $this->handler ) ) {
    $this->handler =
    MediaHandler::getHandler( $this->getMimeType() );
    }
    return $this->handler;
    }

    getHandler()代码:

    includes/media/MediaHandler.php
    /**
    * Get a MediaHandler for a given MIME type from the instance
    cache
    *
    * @param string $type
    * @return MediaHandler
    */
    static function getHandler( $type ) {
    global $wgMediaHandlers;
    if ( !isset( $wgMediaHandlers[$type] ) ) {
    wfDebug( __METHOD__ . ": no handler found for $type.
    " );
    return false;
    }
    $class = $wgMediaHandlers[$type];
    if ( !isset( self::$handlers[$class] ) ) {
    self::$handlers[$class] = new $class;
    if ( !self::$handlers[$class]->isEnabled() ) {
    self::$handlers[$class] = false;
    }
    }
    return self::$handlers[$class];
    }

    $class = $wgMediaHandlers[$type];
    创建一个MIME-MediaHandler 的类的临时对象。
    请看全局变量wgMediaHandlers:

    /**
    * Plugins for media file type handling.
    * Each entry in the array maps a MIME type to a class name
    */
    $wgMediaHandlers = array(
    'image/jpeg' => 'JpegHandler',
    'image/png' => 'PNGHandler',
    'image/gif' => 'GIFHandler',
    'image/tiff' => 'TiffHandler',
    'image/x-ms-bmp' => 'BmpHandler',
    'image/x-bmp' => 'BmpHandler',
    'image/x-xcf' => 'XCFHandler',
    'image/svg+xml' => 'SvgHandler', // official
    'image/svg' => 'SvgHandler', // compat
    'image/vnd.djvu' => 'DjVuHandler', // official
    'image/x.djvu' => 'DjVuHandler', // compat
    'image/x-djvu' => 'DjVuHandler', // compat
    );

    比如JpegHandler:

    includes/media/Jpeg.php
    class JpegHandler extends ExifBitmapHandler {
    function getMetadata( $image, $filename ) {
    }
    }

    请看UML 图:

    再看更详细的JpegHandler:
    关于thumb 对象的创建,handler 对象在渲染完成thumb 后,执
    行dotransform,创建一个thumb 文件对象。以下代码是生成指
    令。
    Transform()方法的部分代码:

    /includes/filerepo/file/File.php
    // Actually render the thumbnail...
    wfProfileIn( __METHOD__ . '-doTransform' );
    $thumb = $handler->doTransform( $this,
    $tmpThumbPath, $thumbUrl, $params );
    wfProfileOut( __METHOD__ . '-doTransform' );
    $tmpFile->bind( $thumb ); // keep alive with $thumb

    透过UML 图可以猜测到thumb 对象类是一个
    mediatransformoutput 的类型,相比其MIME 类型有关。我们在
    MediaHandler 的抽象类中只会看到一个抽象方法而无方法体。

    /**
    * Get a MediaTransformOutput object representing the
    transformed output. Does the
    * transform unless $flags contains self::TRANSFORM_LATER.
    *
    * @param File $image The image object
    * @param string $dstPath Filesystem destination path
    * @param string $dstUrl Destination URL to use in output
    HTML
    * @param array $params Arbitrary set of parameters
    validated by $this->validateParam()
    * Note: These parameters have *not* gone through
    $this->normaliseParams()
    * @param int $flags A bitfield, may contain
    self::TRANSFORM_LATER
    * @return MediaTransformOutput
    */
    abstract function doTransform( $image, $dstPath,
    $dstUrl, $params, $flags = 0 );

    再来看JpegHandler UML 图就一目了然。

  • 相关阅读:
    asp.net 上传文件 显示进度条
    .net 无刷新的几种模式的开发
    使用ASP.NET 2.0提供的WebResource管理资源
    sqlserver2005 递归查询
    利用触发器对某个表的操作过程(删除、修改、插入)
    Sqlserver 先分页再查询
    关于左右滚动,控制某几列不动
    几个不错的SQl语句
    怎样用.net读出Excel的多个Sheet
    将DELPHI数据库连接写进INI配置文件中
  • 原文地址:https://www.cnblogs.com/fancing/p/6393874.html
Copyright © 2011-2022 走看看