3.4. DICON File Tag Reference

3.4.1. DOCTYPE (required)

DOCTYPE is specified as the next of XML declaration. Please specify as follows.

<?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" class="Hello"/>
    . . .
</components>

3.4.2. components tag (required)

Components tag is a root tag of DICON file. Namespace can be specified with the namespace attribute of a components tag.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN"
"http://www.seasar.org/dtd/components21.dtd">
<components namespace="dao">
    ...
</components>

By specifying namespace with a namespace attribute, when the definition of a component is divided, the collision of a component name is avoidable. In the following example, foo.dicon and bar.dicon are included in parent.dicon. The component of a same name called service is defined in each DICON file.

  • parent.dicon
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN"
"http://www.seasar.org/dtd/components21.dtd">
<components>
    <include path="/path/to/foo.dicon"/>
    <include path="/path/to/bar.dicon"/>

    <component name="service" class="DefaultService"/>
</components>
  • foo.dicon
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN"
"http://www.seasar.org/dtd/components21.dtd">
<components namespace="foo">
    <component name="service" class="FooService"/>
</components>
  • bar.dicon
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN"
"http://www.seasar.org/dtd/components21.dtd">
<components namespace="bar">
    <component name="service" class="BarService"/>
</components>

The service component defined by parent.dicon can be referred to without specification of namespace. If the service component defined by foo.dicon and bar.dicon is referred, it is necessary to specify the name space. The name space is specified with Piriord ".". When the service component of foo.dicon is referred, it becomes the following.

<?php
require_once('S2Container/S2Container.php');

$container  = seasar:container\factory\S2ContainerFactory::create('/path/to/parent.dicon');
$service    = $container->getComponent('service');
$fooService = $container->getComponent('foo.service');
$barService = $container->getComponent('bar.service');
?>

3.4.3. include tag

include tag is used when taking in the definition of divided S2Container. The path of a DICON file is specified with a path attribute. (required) It is necessary to describe an include tag in front of a component tag. If DICON file specified with the path attribute does not exist, a path attribute value is passed to an eval function as PHP Expression. Therefore, the constant and class variable which are contained in a path are evaluated.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN"
"http://www.seasar.org/dtd/components21.dtd">
<components>
    <include path="path/to/foo.dicon" />
    <include path="DICON_DIR . '/bar.dicon'" />
</components>

The order of search of a component looks for the component first registered into itself. The case where a component is not found, the component registered into child S2Container is searched with the included turn, and the component found first is returned.

3.4.4. component tag

The component tag defines a component.

<?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="action" class="IndexAction" instance="singleton" autoBinding="auto"/>
</components>

name attribute

A component name. A default value is the class name specified with the class attribute.

class attribute (required)

The class name of a component is specified.

instance attribute

It is specified how S2Container manages the instance of a component. "singleton (default)", "prototype" can be specified. Please refer to Instance Type for details.

autoBinding attribute

It is specified how S2Container solves the dependency of a component. "auto (default)", "none" can be specified. Please refer to Binding Type for details.

3.4.5. arg tag

When an arg tag is used as a child tag of an component tag, it becomes an argument of a constructor. The arg tag is passed to a constructor in the described turn. It becomes an argument of a method when it is used as a child tag of an initMethod tag. The following item can be set to the body of a arg tag.

  • The value surrounded by the (double) quote
  • Expression which described in PHP
  • Reference to other component

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN"
"http://www.seasar.org/dtd/components21.dtd">
<components>
    <component class="Hoge">
        <arg>"seasar"</arg>
        <arg><component class="Foo"/></arg>
        <initMethod name="addService">
            <arg>new Bar</arg>
        </initMethod>
    </component>
</components>

3.4.6. property tag

A property tag is used as a child tag of component tag. The following item can be set to the body of a property tag.

  • The value surrounded by the (double) quote
  • Expression which described in PHP
  • Reference to other component

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN"
"http://www.seasar.org/dtd/components21.dtd">
<components>
    <component class="Hoge">
        <property name="project">"seasar"</property>
    </component>
</components>

name attribute (required)

A property name is specified.

3.4.7. initMethod tag

A initMethod is used as a child tag of component tag. A method argument is specified with an arg tag. When not writing a name attribute, PHP can be described on a body. In PHP expression, the instance of the component with which the initMethod tag is defined is set as $component.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN"
"http://www.seasar.org/dtd/components21.dtd">
<components>
    <component class="HashMap">
        <initMethod name="put">
            <arg>"aaa"</arg>
            <arg>111</arg>
        </initMethod>
        <initMethod>$component->put("aaa", 111);</initMethod>
        <initMethod>print "Hello";</initMethod>
    </component>
</components>

name attribute

A method name is specified.

3.4.8. aspect tag

An aspect is applied to a component. The name of Interceptor component is specified with the body of aspect tag.

<?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="trace" class="seasar\aop\interceptor\TraceInterceptor"/>
    <component class="IndexAction">
        <aspect pointcut=".*Action">trace</aspect>
    </component>
</components>

pointcut attribute

The aspect target method name is specified as pointcut attribute. A regular expression can be used for a method name. When not specifying pointcut attribute, the following target method is chosen.
  • If the class of a component implements abstract method, all the abstract method is applicable
  • If the class of a component does not implement abstract method, all the public method implemented in the class is applicable.

3.4.9. meta tag

The meta tag can specify as a child tag of components tag, component tag, arg tag, and property tag. The following item can be set to the body of a meta tag.

  • The value surrounded by the (double) quote
  • Expression which described in PHP
  • Reference to other component

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR2.1//DTD S2Container//EN"
"http://www.seasar.org/dtd/components21.dtd">
<components>
    <meta name="project">"seasar"</meta>
    <component class="Hoge">
        <meta name="service">true</meta>
    </component>
</components>

name attribute (required)

A meta name is specified.

3.4.10. description tag

The description tag can specify as a child tag of components tag, component tag, arg tag, and property tag. Explanation can be described freely.



© Copyright The Seasar Foundation and the others 2005-2010, all rights reserved.