Seasar DI Container with AOP

PHP Expression

PHP expression implies PHP source code written in Seasar2 dicon file. Besides <property> element in a dicon file, PHP expression may be written in <component> element, <initMethod> element, <destroyMethod> element, <arg> element, <meta> element, and <aspect> element.
dicon file used in this sample is included in s2container.php5/src/examples/expression.

arg, property, aspect, meta Tag

Return to PHP expression arguments to Constructor and value assigned to a property.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN"
"http://www.seasar.org/dtd/components21.dtd">
<components>
    <component name="sample1" class="ArgExp">
        <arg>10</arg>
        <property name="message">
            file_get_contents(EXAMPLE_DIR . '/dicon/expression/ArgSample.txt')
        </property>
    </component>
    <component name="sample2" class="ArgExp">
        <arg>2+3</arg>
        <property name="message">
            $msg1 = "Hello ";
            $msg2 = "World";
            return $msg1 . $msg2;
        </property>
    </component>
</components>
When PHP expression does not include a return, return is automatically inserted. In component sample1,
arugment to a constructor
 return 10; 
and message property
 return file_get_contents(EXAMPLE_DIR . '/dicon/expression/ArgSample.txt');
are processed by a eval function.

PHP expression may also be included in aspect tags and meta tags.

component tag

PHP expression returning an object.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN"
"http://www.seasar.org/dtd/components21.dtd">
<components>
    <component name="hello">
       new ComponentExp("Hello")
        <property name="messageB">"World"</property>
    </component>
    <component name="hello2" class="ComponentExp">
        hello3
    </component>
    <component name="hello3" class="ComponentExp"/>
</components>
When there is a class attribute to a component tag, object returned by PHP expression and ReflectionClass#isSubclassOf are compared.

initMethod, destroyMethod tags

Component initialization and exiting processes written in PHP expression. $component variable is used to reference itself.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN"
"http://www.seasar.org/dtd/components21.dtd">
<components>
    <component name="method" class="MethodExp">
        <initMethod>
            $component->init(10)
        </initMethod>
    </component>
</components>