Flyweight Pattern

同じものは一度しか作らない。

■コード

Item.php

class Item {
    private $code;
    private $name;
    private $price;
    public function __construct($code, $name, $price) {
        $this->code = $code;
        $this->name = $name;
        $this->price = $price;
    }
}

ItemFactory.php

class ItemFactory {
    private $pool;
    private static $instance = null;
    private function __construct($filename) {
        $this->buildPool($filename);
    }
    public static function getInstance($filename) {
        if(!is_null(self::$instance)) {
            self::$instance = new ItemFactory($filename);
        }
        return self::$instance;
    }
    public function getItem($code) {
        if(array_key_exists($code, $this->pool)) {
            return $this->pool($code);
        }
        else {
            return null;
        }
    }
    public function buildPool($filename) {
        $this->pool = array();
        $fh = fopen($filename, 'r');
        while($buffer = fgets($fp, 4096)) {
            list($itemCode, $itemName, $price) = split("\t", $buffer);
            $this->pool[$itemCode] = new Item($itemCode, $itemName, $price);
        }
        fclose($fh);
    }
    public final __clone() {
        throw new RuntimeException();
    }
}

■クライアントコード

$factory = ItemFactory::getInstance('list.dat');
$factory->getItem(123);// 何度コールしても同じインスタンスが返るはず
$factory->getItem(456);//
$factory->getItem(789);//

Singletonをまとめた感じだ。

xamppにXDebugとPHPUnitとMaple4_DocTestを入れる

■Xdebug

というかXdebugは最初から入ってるのでphp.iniの記述を変更する。

;zend_extension = "C:\xampp\php\ext\php_xdebug.dll"

以下のように記述する。

zend_extension="C:\xampp\php\ext\php_xdebug.dll";eclipseで変数が適切に表示されなかった為追記
zend_extension_ts="C:\xampp\php\ext\php_xdebug.dll"
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.profiler_enable=1
xdebug.profiler_output_dir = "C:\xampp\tmp"
xdebug.profiler_output_name = cachegrind.out.%s

但し、上述は既に記述されている項目もあるので重複しないように記述すること。また、出力されたファイルはWinCacheGrindなどを用いて参照するとベンチマーク結果が分かりやすく参照できる。

zend_extension_tsについて

phpinfo()のThread SafetyとDebug Buildの値を確認し、zend_extension_tsは以下のように書き換える必要があるとのこと。

Debug Build ON Debug Build OFF
Thread Safety ON zend_extension_debug_ts zend_extension_ts
Thread Safety OFF zend_extension_debug zend_extension

注意

以下の部分は変更しないので注意。

;extension=php_xdebug.dll

pear自体のアップグレードをしておく。

pear channel-update pear.php.net
pear upgrade PEAR

XAMPP for Mac

sudo /Applications/XAMPP/xamppfiles/bin/pear channel-update pear.php.net
sudo /Applications/XAMPP/xamppfiles/bin/pear upgrade pear

■PHPUnit

以下のコマンドでPHPUnitをインストールする。

pear channel-discover pear.phpunit.de
pear channel-discover pear.symfony-project.com
pear channel-discover components.ez.no
pear install phpunit/PHPUnit

Mac

sudo pear channel-discover pear.phpunit.de
sudo pear install phpunit/PHPUnit
; UNIX: "/path1:/path2"
include_path = ".:/php/includes:/usr/lib/php/pear"

XAMPP for Mac

sudo /Applications/XAMPP/xamppfiles/bin/pear channel-discover pear.phpunit.de
sudo /Applications/XAMPP/xamppfiles/bin/pear channel-discover pear.symfony-project.com
sudo /Applications/XAMPP/xamppfiles/bin/pear channel-discover components.ez.no
sudo /Applications/XAMPP/xamppfiles/bin/pear install phpunit/PHPUnit

■Maple4_DocTest

以下のコマンドでMaple4_DocTestをインストールする。

pear install http://kunit.jp/maple4/Maple4_DocTest-0.2.0.tgz

こっちは全く使わなくなってしまったな。。。

swfmillのインストール

■gcc-c++

yum install gcc-c++

■patch

patchコマンドが使えなかった。

yum install patch

■swfmill

wget http://swfmill.org/releases/swfmill-0.3.0.tar.gz
tar xzf swfmill-0.3.0.tar.gz
cd swfmill-0.3.0

FlashLite1.1に対応するためのパッチをあてる。

wget http://lab.klab.org/files/flash/encoding.patch
patch -p1 < encoding.patch

このバージョンに対するパッチではないようだ。エラーが出る。

wget http://swfmill.org/releases/swfmill-0.2.12.tar.gz
tar xzf swfmill-0.2.12.tar.gz
cd swfmill-0.2.12
wget http://lab.klab.org/files/flash/encoding.patch
patch -p1 < encoding.patch
./configure
make
make install

試してみる。

wget http://ai.yimg.jp/bdv/43559/820056/20091207/odbpq8l0gqpysnz_3t2o-b.swf
swfmill swf2xml odbpq8l0gqpysnz_3t2o-b.swf banner.xml
vi banner.xml

以下のように表示される。(画像などを読み込んだ)バイナリ部分はBase64でエンコードされている。

<?xml version="1.0" encoding="UTF-8"?>
<swf version="6" compressed="0">
  <Header framerate="24" frames="215">
    <size>
      <Rectangle left="0" right="7000" top="0" bottom="3200"/>
    </size>
    <tags>
      <SetBackgroundColor>
        <color>
          <Color red="255" green="255" blue="255"/>
        </color>
      </SetBackgroundColor>
      <DefineBitsJPEG2 objectID="1">
        <data>
          <data>/9n/2P/Y/+AAEEpGSUYAAQIAAGQAZAAA   [省略]   JREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoi//9k=</data>
        </data>
      </DefineBitsJPEG2>
      <DefineShape objectID="2">
        <bounds>
          <Rectangle left="-3500" right="3500" top="-1600" bottom="1600"/>
        </bounds>
        <styles>
          <StyleList>
            <fillStyles>
              <ClippedBitmap objectID="65535">
                <matrix>
                  <Transform scaleX="20.00000000000000" scaleY="20.00000000000000" transX="0" transY="0"/>
                </matrix>
              </ClippedBitmap>
              <ClippedBitmap objectID="1">
                <matrix>
                  <Transform scaleX="20.00000000000000" scaleY="20.00000000000000" transX="-3500" transY="-1600"/>
                </matrix>
              </ClippedBitmap>
            </fillStyles>
            <lineStyles/>
          </StyleList>
        </styles>
        <shapes>
          <Shape>
            <edges>
              <ShapeSetup x="3500" y="1600" fillStyle1="2"/>
              <LineTo x="-7000" y="0"/>
              <LineTo x="0" y="-3200"/>
              <LineTo x="7000" y="0"/>
              <LineTo x="0" y="3200"/>
              <ShapeSetup/>
            </edges>
          </Shape>
        </shapes>
      </DefineShape>
      <PlaceObject2 replace="0" depth="1" objectID="2">
        <transform>
          <Transform transX="3500" transY="1600"/>
        </transform>
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="0"/>
        </colorTransform>
      </PlaceObject2>
      <DefineShape objectID="3">
        <bounds>
          <Rectangle left="-10" right="7010" top="-10" bottom="3210"/>
        </bounds>
        <styles>
          <StyleList>
            <fillStyles>
              <Solid>
                <color>
                  <Color red="129" green="216" blue="208"/>
                </color>
              </Solid>
            </fillStyles>
            <lineStyles>
              <LineStyle width="20">
                <color>
                  <Color red="153" green="153" blue="153"/>
                </color>
              </LineStyle>
            </lineStyles>
          </StyleList>
        </styles>
        <shapes>
          <Shape>
            <edges>
              <ShapeSetup x="7000" y="3200" fillStyle1="1" lineStyle="1"/>
              <LineTo x="-7000" y="0"/>
              <LineTo x="0" y="-3200"/>
              <LineTo x="7000" y="0"/>
              <LineTo x="0" y="3200"/>
              <ShapeSetup/>
            </edges>
          </Shape>
        </shapes>
      </DefineShape>
      <DefineButton2 objectID="4" menu="0" buttonsSize="10">
        <buttons>
          <Button hitTest="1" down="0" over="0" up="0" objectID="3" depth="1">
            <transform>
              <Transform transX="0" transY="0"/>
            </transform>
            <colorTransform>
              <ColorTransform2/>
            </colorTransform>
          </Button>
          <Button hitTest="0" down="0" over="0" up="0"/>
        </buttons>
        <conditions>
          <Condition next="0" menuEnter="0" pointerReleaseOutside="0" pointerDragEnter="0" pointerDragLeave="0" pointerReleaseInside="1" pointerPush="0" pointerLeave="0" pointerEnter="0" key="0" menuLeave="0">
            <actions>
              <Dictionary>
                <strings>
                  <String value="clickTAG"/>
                  <String value="substr"/>
                  <String value="http:"/>
                  <String value="https:"/>
                  <String value="targetTAG"/>
                </strings>
              </Dictionary>
              <PushData>
                <items>
                  <StackInteger value="5"/>
                  <StackDouble value="0.000000000000000"/>
                  <StackInteger value="2"/>
                  <StackDictionaryLookup index="0"/>
                </items>
              </PushData>
              <GetVariable/>
              <PushData>
                <items>
                  <StackDictionaryLookup index="1"/>
                </items>
              </PushData>
              <CallMethod/>
              <PushData>
                <items>
                  <StackDictionaryLookup index="2"/>
                </items>
              </PushData>
              <EqualTyped/>
              <PushData>
                <items>
                  <StackInteger value="6"/>
                  <StackDouble value="0.000000000000000"/>
                  <StackInteger value="2"/>
                  <StackDictionaryLookup index="0"/>
                </items>
              </PushData>
              <GetVariable/>
              <PushData>
                <items>
                  <StackDictionaryLookup index="1"/>
                </items>
              </PushData>
              <CallMethod/>
              <PushData>
                <items>
                  <StackDictionaryLookup index="3"/>
                </items>
              </PushData>
              <EqualTyped/>
              <LogicalOR/>
              <LogicalNOT/>
              <BranchIfTrue byteOffset="16"/>
              <PushData>
                <items>
                  <StackDictionaryLookup index="0"/>
                </items>
              </PushData>
              <GetVariable/>
              <PushData>
                <items>
                  <StackDictionaryLookup index="4"/>
                </items>
              </PushData>
              <GetVariable/>
              <GetURL2 method="0"/>
              <EndAction/>
            </actions>
          </Condition>
        </conditions>
      </DefineButton2>
      <PlaceObject2 replace="0" depth="2" objectID="4">
        <transform>
          <Transform transX="0" transY="0"/>
        </transform>
      </PlaceObject2>
      <ShowFrame/>
      <DoAction>
        <actions>
          <Dictionary>
            <strings>
              <String value="Stage"/>
              <String value="showMenu"/>
              <String value="l"/>
              <String value=""/>
              <String value="ar"/>
              <String value="Array"/>
              <String value="i"/>
              <String value="length"/>
              <String value="charAt"/>
              <String value="/"/>
              <String value="push"/>
              <String value="str"/>
              <String value="substr"/>
              <String value="yimg.jp"/>
              <String value="indexOf"/>
              <String value="admission.jp"/>
              <String value="snd"/>
              <String value="Sound"/>
              <String value="setVolume"/>
            </strings>
          </Dictionary>
          <PushData>
            <items>
              <StackDictionaryLookup index="0"/>
            </items>
          </PushData>
          <GetVariable/>
          <PushData>
            <items>
              <StackDictionaryLookup index="1"/>
              <StackBoolean value="0"/>
            </items>
          </PushData>
          <SetMember/>
          <PushData>
            <items>
              <StackDictionaryLookup index="2"/>
              <StackDictionaryLookup index="3"/>
              <StackInteger value="15"/>
            </items>
          </PushData>
          <GetProperty/>
          <SetLocalVariable/>
          <PushData>
            <items>
              <StackDictionaryLookup index="4"/>
              <StackDouble value="0.000000000000000"/>
              <StackDictionaryLookup index="5"/>
            </items>
          </PushData>
          <New/>
          <SetLocalVariable/>
          <PushData>
            <items>
              <StackDictionaryLookup index="6"/>
              <StackDouble value="0.000000000000000"/>
            </items>
          </PushData>
          <SetLocalVariable/>
          <PushData>
            <items>
              <StackDictionaryLookup index="6"/>
            </items>
          </PushData>
          <GetVariable/>
          <PushData>
            <items>
              <StackDictionaryLookup index="2"/>
            </items>
          </PushData>
          <GetVariable/>
          <PushData>
            <items>
              <StackDictionaryLookup index="7"/>
            </items>
          </PushData>
          <GetMember/>
          <LessThanTyped/>
          <LogicalNOT/>
          <BranchIfTrue byteOffset="74"/>
          <PushData>
            <items>
              <StackDictionaryLookup index="6"/>
            </items>
          </PushData>
          <GetVariable/>
          <PushData>
            <items>
              <StackInteger value="1"/>
              <StackDictionaryLookup index="2"/>
            </items>
          </PushData>
          <GetVariable/>
          <PushData>
            <items>
              <StackDictionaryLookup index="8"/>
            </items>
          </PushData>
          <CallMethod/>
          <PushData>
            <items>
              <StackDictionaryLookup index="9"/>
            </items>
          </PushData>
          <EqualTyped/>
          <LogicalNOT/>
          <BranchIfTrue byteOffset="24"/>
          <PushData>
            <items>
              <StackDictionaryLookup index="6"/>
            </items>
          </PushData>
          <GetVariable/>
          <PushData>
            <items>
              <StackInteger value="1"/>
              <StackDictionaryLookup index="4"/>
            </items>
          </PushData>
          <GetVariable/>
          <PushData>
            <items>
              <StackDictionaryLookup index="10"/>
            </items>
          </PushData>
          <CallMethod/>
          <Pop/>
          <PushData>
            <items>
              <StackDictionaryLookup index="6"/>
              <StackDictionaryLookup index="6"/>
            </items>
          </PushData>
          <GetVariable/>
          <Increment/>
          <SetVariable/>
          <BranchAlways byteOffset="65437"/>
          <PushData>
            <items>
              <StackDictionaryLookup index="11"/>
              <StackDictionaryLookup index="4"/>
            </items>
          </PushData>
          <GetVariable/>
          <PushData>
            <items>
              <StackInteger value="2"/>
            </items>
          </PushData>
          <GetMember/>
          <PushData>
            <items>
              <StackDictionaryLookup index="4"/>
            </items>
          </PushData>
          <GetVariable/>
          <PushData>
            <items>
              <StackInteger value="1"/>
            </items>
          </PushData>
          <GetMember/>
          <Substract/>
          <PushData>
            <items>
              <StackInteger value="1"/>
            </items>
          </PushData>
          <Substract/>
          <PushData>
            <items>
              <StackDictionaryLookup index="4"/>
            </items>
          </PushData>
          <GetVariable/>
          <PushData>
            <items>
              <StackInteger value="1"/>
            </items>
          </PushData>
          <GetMember/>
          <PushData>
            <items>
              <StackInteger value="1"/>
            </items>
          </PushData>
          <AddTyped/>
          <PushData>
            <items>
              <StackInteger value="2"/>
              <StackDictionaryLookup index="2"/>
            </items>
          </PushData>
          <GetVariable/>
          <PushData>
            <items>
              <StackDictionaryLookup index="12"/>
            </items>
          </PushData>
          <CallMethod/>
          <SetVariable/>
          <PushData>
            <items>
              <StackDictionaryLookup index="13"/>
              <StackInteger value="1"/>
              <StackDictionaryLookup index="11"/>
            </items>
          </PushData>
          <GetVariable/>
          <PushData>
            <items>
              <StackDictionaryLookup index="14"/>
            </items>
          </PushData>
          <CallMethod/>
          <PushData>
            <items>
              <StackInteger value="-1"/>
            </items>
          </PushData>
          <EqualTyped/>
          <LogicalNOT/>
          <Duplicate/>
          <BranchIfTrue byteOffset="30"/>
          <Pop/>
          <PushData>
            <items>
              <StackDictionaryLookup index="15"/>
              <StackInteger value="1"/>
              <StackDictionaryLookup index="11"/>
            </items>
          </PushData>
          <GetVariable/>
          <PushData>
            <items>
              <StackDictionaryLookup index="14"/>
            </items>
          </PushData>
          <CallMethod/>
          <PushData>
            <items>
              <StackInteger value="-1"/>
            </items>
          </PushData>
          <EqualTyped/>
          <LogicalNOT/>
          <LogicalNOT/>
          <BranchIfTrue byteOffset="6"/>
          <Play/>
          <BranchAlways byteOffset="46"/>
          <PushData>
            <items>
              <StackDictionaryLookup index="16"/>
              <StackDouble value="0.000000000000000"/>
              <StackDictionaryLookup index="17"/>
            </items>
          </PushData>
          <New/>
          <SetLocalVariable/>
          <PushData>
            <items>
              <StackDouble value="0.000000000000000"/>
              <StackInteger value="1"/>
              <StackDictionaryLookup index="16"/>
            </items>
          </PushData>
          <GetVariable/>
          <PushData>
            <items>
              <StackDictionaryLookup index="18"/>
            </items>
          </PushData>
          <CallMethod/>
          <Pop/>
          <Stop/>
          <EndAction/>
        </actions>
      </DoAction>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="5"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="11"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="16"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="22"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="27"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="33"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="38"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="44"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="49"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="54"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="60"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="65"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="71"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="76"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="82"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="87"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="93"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="98"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="103"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="109"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="114"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="120"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="125"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="131"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="136"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="142"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="147"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="153"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="158"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="163"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="169"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="174"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="180"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="185"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="191"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="196"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="202"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="207"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="212"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="218"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="223"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="229"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="234"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="240"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="245"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="251"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="251"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="245"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="240"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="234"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="229"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="223"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="218"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="212"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="207"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="202"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="196"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="191"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="185"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="180"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="174"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="169"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="163"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="158"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="153"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="147"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="142"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="136"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="131"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="125"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="120"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="114"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="109"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="103"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="98"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="93"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="87"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="82"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="76"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="71"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="65"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="60"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="54"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="49"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="44"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="38"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="33"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="27"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="22"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="16"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="11"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="5"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="0"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <DefineBitsJPEG2 objectID="5">
        <data>
          <data>/9n/2P/Y/+AAEEpGSUYAAQIAAGQAZAAA/+wAEUR1Y2t5AAEABAAAAGQAAP/   [省略]   /8Av3xpqRoWF4vAQfop4iqPXRPiUkl6/iqyCc7XjTWRMx48cfFhhlgf4Cy020Kf9BbEU401+y9/+P8AnxprG7iDYzBUGnXPqL4UGXEa/wAu/wBe1+ONNYZ/25aV785S/wBwP7gFTJXe1+CVHfLyEvH/AD+eNNf/2Q==</data>
        </data>
      </DefineBitsJPEG2>
      <DefineShape objectID="6">
        <bounds>
          <Rectangle left="-3500" right="3500" top="-1600" bottom="1600"/>
        </bounds>
        <styles>
          <StyleList>
            <fillStyles>
              <ClippedBitmap objectID="65535">
                <matrix>
                  <Transform scaleX="20.00000000000000" scaleY="20.00000000000000" transX="0" transY="0"/>
                </matrix>
              </ClippedBitmap>
              <ClippedBitmap objectID="5">
                <matrix>
                  <Transform scaleX="20.00000000000000" scaleY="20.00000000000000" transX="-3500" transY="-1600"/>
                </matrix>
              </ClippedBitmap>
            </fillStyles>
            <lineStyles/>
          </StyleList>
        </styles>
        <shapes>
          <Shape>
            <edges>
              <ShapeSetup x="3500" y="1600" fillStyle1="2"/>
              <LineTo x="-7000" y="0"/>
              <LineTo x="0" y="-3200"/>
              <LineTo x="7000" y="0"/>
              <LineTo x="0" y="3200"/>
              <ShapeSetup/>
            </edges>
          </Shape>
        </shapes>
      </DefineShape>
      <PlaceObject2 replace="1" depth="1" objectID="6"/>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="5"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="11"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="16"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="22"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="27"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="33"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="38"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="44"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="49"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="54"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="60"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="65"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="71"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="76"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="82"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="87"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="93"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="98"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="103"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="109"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="114"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="120"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="125"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="131"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="136"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="142"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="147"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="153"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="158"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="163"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="169"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="174"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="180"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="185"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="191"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="196"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="202"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="207"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="212"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="218"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="223"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="229"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="234"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="240"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="245"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2 factorRed="256" factorGreen="256" factorBlue="256" factorAlpha="251"/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <DoAction>
        <actions>
          <Stop/>
          <EndAction/>
        </actions>
      </DoAction>
      <PlaceObject2 replace="1" depth="1">
        <colorTransform>
          <ColorTransform2/>
        </colorTransform>
      </PlaceObject2>
      <ShowFrame/>
      <End/>
    </tags>
  </Header>
</swf>

書き換えてswfmill xml2swfで戻せば、サーバ上で動的にswfを生成することが可能になる。

Command Pattern

■コード

File.php

class File {
    private $name;
    public function __construct($name) {
        $this->name = $name;
    }
    public function decompress() {
        // 
    }
    public function compress() {
        //
    }
    public function create() {
        //
    }
}

Command.php

interface Command {
    public function execute();
}

TouchCommand.php

class TouchCommand implements Command {
    private $file;
    public function __construct(File $file) {
        $this->file = $file;
    }
    public function execute() {
        $this->file->create();
    }
}

CompressCommand.php

class CompressCommand implements Command {
    private $file;
    public function __construct(File $file) {
        $this->file = $file;
    }
    public function execute() {
        $this->file->compress();
    }
}

CopyCommand.php

class CopyCommand implements Command {
    private $file;
    public function __construct(File $file) {
        $this->file = $file;
    }
    public function execute() {
        $file = new File('copy_' . $this->file->getName());
        $file->create();
    }
}

Queue.php

class Queue {
    private $commands;
    private $currentIndex;
    public function __construct() {
        $this->commands = array();
        $this->currenrIndex = 0;
    }
    public function addCommand(Command $command) {
        $this->commands[] = $command;
    }
    public function run() {
        while(!is_null($command = $this->next())) {
            $command->execute();
        }
    }
    private function execute() {
        if(count($this->commands) === 0 || count($this->commands) <= $this->currentIndex) {
            return null;
        }
        else {
            return $this->commands[$this->currentIndex++];
        }
    }
}

■クライアントコード

$queue = new Queue();
$file = new File('hoge.txt');
$queue->addCommand(new TouchCommand($file));
$queue->addCommand(new CompressCommand($file));
$queue->addCommand(new CopyCommand($file));
$queue->run();

Chain of Responsibility

■コード

AbstractValidationHandler

abstract class AbstractValidationHandler {
    private $nextHandler;
    public function __construct() {
        $this->nextHandler = null;
    }
    public function setHandler(ValidationHandler $handler) {
        $this->nextHandler = $handler;
        return $this;
    }
    public function getNextHandler() {
        return $this->nextHandler;
    }
    public function validate($input) {
        $result = $this->execValidation($input);
        if(!$result) {
            return $this->getErrorMessage();
        }
        else if(!is_null($this->getNextHandler())) {
            return $this->getNextHandler()->validation($input);
        }
        else {
            return true;
        }
    }
    protected abstract function execValidation($input);
    protected abstract function getErrorMessage();
}

AlphaNumericValidation.php

class AlphaNumericValidation extends AbstractValidationHandler {
    protected function execValidation($input) {
        return preg_match('/^[0-9a-zA-Z]+$/', $input);
    }
    protected function getErrorMessage() {
        return '半角英数字で!';
    }
}

NumericValidation.php

class NumericValidation extends AbstractValidationHandler {
    protected function execValidation($input) {
        return preg_match('/^[0-9]+$/', $input);
    }
    protected function getErrorMessage() {
        return '半角数字で!';
    }
}

■クライアントコード

$alphaNumericValidation = new AlphaNumericValidation();
$handler = $alphaNumericValidation->setHandler(new NumericValidation());
$result = $hander->validete($input);
if($result) {
    // ok
}
else {
    // error
}

Builder Pattern

■コード

News.php

単一のnewsのデータ構造を示す。

class News {
    private $title;
    private $url;
    private $targetDate;
    public function __construct($title, $url, $targetDate) {
        $this->title = $title;
        $this->url   = $title;
        $this->targetDate = $targetDate;
    }
}

NewsDirector.php

class NewsDirector {
    private $builder;
    private $url;
    public function __construct(NewsBuilder $builder, $url) {
        $this->builder = $builder;
        $this->url = $url;
    }
    public function getNews() {
        return $this->builder->parse($this->url);
    }
}

NewsBuilder.php

interface NewsBuilder {
    public function parse($date);
}

RssNewsBuilder.php

class RssNewsBuilder implements NewsBuilder {
    public function parse($url) {
        // RSSを取得する => Newsオブジェクトのリストを返す
    }
}

■クライアントコード

$builder = new RssNewsBuilder();
$director = new NewsDirector($builder, $url);
$news = $director->getNews();
var_dump($news);

preg_matchにおける$の注意点

preg_matchにおける$の挙動を知る。

<?php
$str = "01237";
$str = preg_replace("/37$/", '', $str);
var_dump($str);
//string(3) "012"

当然だ。次に以下を実行する。

$str = "01237\n";
$str = preg_replace("/37$/", '', $str);
var_dump($str);
//string(4) "012\n"

ん?文字列の最後尾の改行コードが$で捉えきれなかった。

$str = "01237\n";
$str = preg_replace("/37$/D", '', $str);
var_dump($str);
//string(6) "01237\n"

上述のようにDオプションを加えると期待した動作になる。

■まとめ

$
行の末尾
D
$を検索対象文字列の終わりにのみマッチ。これが無い場合、$は改行文字の前でもマッチする

従って前述のコードの様な結果となる。

HTTPヘッダインジェクションを防ぐ

PHP5.1.2以前を使っている場合は特に気をつけねばならない。以下のようにHTTPヘッダにユーザ入力の値が入るとする。

header("Location: http://sample.org/{$input}");

■攻撃

$inputに改行が入っていた場合に成立する。

$input = '\n\n<script type="text/javascript">alert("attacked");</script>';

■対策

header("Location: http://sample.org/" . strtr($input, array("\r" => '', "\n" => '')));

但し、PHP5.1.2以降ではインジェクションに対する実装として、一度に複数のヘッダを送信することができなくなり改行コードは削除されるようになった。PHP 5.2.0では脆弱性が存在したようだ。

header("Location: http://sample.org/" . trim($input));

現代でも最低限このくらいはした方がよさそうだ。

Bridge Pattern

■コード

DataSourceInterface.php

interface DataSourceInterface {
    public function open();
    public function read();
    public function close();
}

FileDataSource.php

class FileDataSource implements {
    private $sourceName;
    private $handler;
    public function __construct($sourceName) {
        $this->sourceName = $sourceName;
    }
    public function open() {
        if(is_readable($this->sourceName) && $this->handler = fopen($this->sourceName)) {
            throw new Exception();
        }
    }
    public function read() {
        $buffer = array();
        while(!feof($this->handler)) {
            $buffer[] = fgets($this->handler);
        }
        return implode($buffer);
    }
}

Listing.php

class Listing {
    private $dataSource;
    public function __construct($dataSource) {
        $this->dataSource = $dataSource;
    }
    public function open() {
        $this->dataSource->open();
    }
    public function read() {
        return $this->dataSource->read();
    }
    public function close() {
        $this->dataSource->close();
    }
}

ExtendedListing.php

class ExtendedListing extends Listing {
    public function __construct($dataSource) {
        parent::__construct($dataSource);
    }
    public function readWithEncode($charset) {
        return htmlspecialchars($this->read, ENT_QUOTE, $charset);
    }
}

■クライアントコード

$list1 = new Listing(new FileDataSource('/home/hoge/fuga.txt'));
$list2 = new ExtendedListing(new FileDataSource('/home/hoge/piyo.txt'));
try {
    $list1->open();
    $list2->open();
    echo $list1->read();
    echo $list2->read();
    $list1->close();
    $list2->close();
}
catch (Exception $e) {

}

Abstract Factory Pattern

■コード

DaoFactory.php

interface DaoFactory {
    public function createItemDao();
    public function createOrderDao();
}

DbFactory.php

class DbFactory implements DaoFactory {
    public function createItemDao() {
        return new DbItemDao();
    }
    public function createOrderDao() {
        return new DbOrderDao($this->createItemDao());
    }
}

MockFactory.php

class MockFactory implements DaoFactory {
    public function createItemDao() {
        return new MockItemDao();
    }
    public function createOrderDao() {
        return new MockOrderDao();
    }
}

ItemDao.php

interface ItemDao {
    public function findById($itemId);
}

OrderDao.php

interface OrderDao {
    public function findById($orderId);
}

DbItemDao.php

class DbItemDao implements ItemDao {
    public function findById($itemId) {
        // DBから$itemIdのものを取得して返す
    }
}
MockItemDao.php
class MockItemDao implements Item Dao {
    public function findById($itemId) {
        return new Item(7, "dummy");
    }
}

DbOrderDao.php

class DbOrderDao {
    public function findById($orderId) {
        // DBから$orderIdのものを取得して返す
    }
}
MockOrderDao.php
class MockOrderDao implements OrderDao {
    public function findById($orderId) {
        $order = new Order(123);
        $order->addItem(new Item(7, "dummy1"))->addItem(new Item(11, "dummy2"))->addItem(new Item(13, "dummy3"));
        return $order;
    }
}

Item.php

class Item {
    private $id;
    private $name;
    public function __construct($id, $name) {
        $this->id   = $id;
        $this->name = $name;
    }
}

Order.php

class Order {
    private $id;
    private $items;
    public function __construct($id) {
        $this->id = $id;
    }
    public function addItem(Item $item) {
        $id = $item->getId();
        if(!array_key_exists($id, $this->items)) {
            $this->items[$id]['object'] = $item;
            $this->items[$id]['amount'] = $item;
        }
        $this->items[$id]['amount']++;
        return $this;
    }
}

■クライアントコード

define('IS_DEVELOP', true);
if(IS_DEVELOP) {
    $factory = new MockFactory();
}
else {
    $factory = new DbFactory();
}
$itemDao   = $factory->createItemDao();
$orederDao = $factory->createOrderDao();

// 処理
$itemDao->findById(23);
$orderDao->findById(29);