読者です 読者をやめる 読者になる 読者になる

PHPのstaticメソッドのメモ。

<?php

interface mailOrderState_Interface
{
    const STATE_RESERVED = 10;
    const STATE_ONSALE   = 20;
    const STATE_ARRIVAL  = 30;
    const STATE_DISPLAY  = 40;

    const STATE_RESERVED_NOPAY  = 10;
    const STATE_RESERVED_PAYED  = 20;
    const STATE_RESERVED_LOCKED = 30;

    const STATE_ONSALE_NOSECURE = 10;
    const STATE_ONSALE_SECURE   = 20;
    const STATE_ONSALE_SEND     = 30;
    
    const STATE_ARRIVAL_INBOX   = 10;
    const STATE_ARRIVAL_OPENBOX = 20;
    const STATE_ARRIVAL_ONCASE  = 30;

    public static getLargeStateCode();

    public static getMiddleStateCode();

    public static getStateSerialKey();

    public getActionList();

}


class StateManager
{
    private $_stateList = array(
        'stReservedNopay',
        'stReservedPayed',
        'stOnsaleSecure',
        'stDisplayOutercase',
        'stDisplayInnercase',
    };

    public getState($option)
    {
        if (is_a($option, 'Zend_DB_Row')) {
            return $this->getStateByRow($option);
        }

        if (is_integer($option)) {
            return $this->getStateBySerialKey($option);
        }

        if (is_array($option)) {
            if((is_integer($option[0])) && (is_integer($option[1])) {
                return $this->getStateByKeySet($option[0], $option[1]);
            }

            if((is_integer($option['large'])) && (is_integer($option['middle'])) {
                return $this->getStateByKeySet($option['large'], $option['middle']);
            }
        }
        return null;
    }
}


abstract class mailOrderState implements mailOrderState_Interface
{
    public static getStateSerialKey()
    {
        return self::getLargeState() * 1000 + self::getMiddleState();
    }

    public getActionList()
    {
        return array(
            'pay'      => false,
            'cancel'   => false,
            'sendback' => false,
            'open'     => false,
            'display'  => false,
            'photo'    => false,
            'peropero' => false,
        );
    }

}


class stReservedNopay implements mailOrderState
{
    public static getLargeStateCode()
    {
        return self::STATE_RESERVED;
    }

    public static getMiddleStateCode()
    {
        return self::STATE_RESERVED_NOPAY;
    }

    public getActionList()
    {
        $result = parent::getActionList();
        $result['pay'] = true;
        $result['cancel'] = true;
        return $result;
    }
}


class stArraival implements mailOrderState
{
    public static getLargeStateCode()
    {
        return self::STATE_ARRIVAL;
    }

    public static getMiddleStateCode()
    {
        return self::STATE_ARRIVAL_INBOX;
    }


    public getActionList()
    {
        $result = parent::getActionList();
        $result['sendback'] = true;
        $result['open'] = true;
        return $result;
    }
}


class stDisplayOutercase implements mailOrderState
{
    public static getLargeStateCode()
    {
        return self::STATE_DISPLAY;
    }

    public static getMiddleStateCode()
    {
        return self::STATE_ARRIVAL_OPENBOX;
    }


    public getActionList()
    {
        $result = parent::getActionList();
        $result['photo'] = true;
        $result['peropero'] = true;
        return $result;
    }
}

で、この状態で

<?php
$largecode = stArraival::getLargeStateCode();

は30が返ってくるけど、

<?php
$serialkey = stArraival::getStateSerialKey();

を実行すると「mailOrderStateでabstractメソッドが実装されてない」エラーが出る、と。