首页 > php教程 > PHP源码 > 静态变量、成员、方法

静态变量、成员、方法

PHP中文网
发布: 2016-05-25 17:06:32
原创
1054 人浏览过

php代码

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

<?php

  interface IImage{

    

    function getHeight();

     

    function getWidth();

     

    function getData();

  }

   

  class Image_PNG implements IImage{

    private $_width,$_height,$_data;

    public function __construct($file){

      $this->_file=$file;

      $this->_parse();

    }

    private function _parse(){

      //完成PNG格式的解析工作

      //并填充$_width、$_height和$_data

    }

    public function getWidth(){

    return $this->_width;

    }

    public function getHeight(){

    return $this->_height;

    }

    public function getData(){

    return $this->_data;

    }

  }

 class Image_JPEG implements IImage{

  private $_width ,$_height,$_data;

  public function __construct($file){

    $this->_file=$file;

    $this->_parse();

  }

  private function _parse(){

  }

  public function getWidth(){

    return $this->_width;

  }

  public function getHeight(){

    return $this->_height;

  }

  public function getData(){

    return $this->_data;

  }

 }

 class ImageFactory{

  public static function factory($file){

    $pathParts=pathinfo($file);

    switch(strtolower($pathParts[&#39;extension&#39;])){

      case &#39;jpg&#39;;

        $ret=new Image_JPEG($file);

        break;

      case &#39;png&#39;;

        $ret=new Image_PNG($file);

        break;

        default;

    }

    if($ret instanceof IImage){

      return $ret;

      }

      else{

      }

  }

 }

  $image=ImageFactory::factory(&#39;/path/to/b/bei.jpg&#39;);

  echo $image->getWidth();

?>

登录后复制
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板