~chroot64bit/zivios/gentoo-experimental

« back to all changes in this revision

Viewing changes to application/library/Zend/Soap/Wsdl/Strategy/DefaultComplexType.php

  • Committer: Mustafa A. Hashmi
  • Date: 2008-12-04 13:32:21 UTC
  • Revision ID: mhashmi@zivios.org-20081204133221-0nd1trunwevijj38
Inclusion of new installation framework with ties to zend layout and dojo layout

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Zend Framework
 
4
 *
 
5
 * LICENSE
 
6
 *
 
7
 * This source file is subject to the new BSD license that is bundled
 
8
 * with this package in the file LICENSE.txt.
 
9
 * It is also available through the world-wide-web at this URL:
 
10
 * http://framework.zend.com/license/new-bsd
 
11
 * If you did not receive a copy of the license and are unable to
 
12
 * obtain it through the world-wide-web, please send an email
 
13
 * to license@zend.com so we can send you a copy immediately.
 
14
 *
 
15
 * @category   Zend
 
16
 * @package    Zend_Soap
 
17
 * @subpackage Wsdl
 
18
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
19
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
20
 * @version    $Id$
 
21
 */
 
22
 
 
23
class Zend_Soap_Wsdl_Strategy_DefaultComplexType extends Zend_Soap_Wsdl_Strategy_Abstract
 
24
{
 
25
    /**
 
26
     * Add a complex type by recursivly using all the class properties fetched via Reflection.
 
27
     *
 
28
     * @param  string $type Name of the class to be specified
 
29
     * @return string XSD Type for the given PHP type
 
30
     */
 
31
    public function addComplexType($type)
 
32
    {
 
33
        if(!class_exists($type)) {
 
34
            require_once "Zend/Soap/Wsdl/Exception.php";
 
35
            throw new Zend_Soap_Wsdl_Exception(sprintf(
 
36
                "Cannot add a complex type %s that is not an object or where ".
 
37
                "class could not be found in 'DefaultComplexType' strategy.", $type
 
38
            ));
 
39
        }
 
40
 
 
41
        $dom = $this->getContext()->toDomDocument();
 
42
        $class = new ReflectionClass($type);
 
43
 
 
44
        $complexType = $dom->createElement('xsd:complexType');
 
45
        $complexType->setAttribute('name', $type);
 
46
 
 
47
        $all = $dom->createElement('xsd:all');
 
48
 
 
49
        foreach ($class->getProperties() as $property) {
 
50
            if (preg_match_all('/@var\s+([^\s]+)/m', $property->getDocComment(), $matches)) {
 
51
 
 
52
                /**
 
53
                 * @todo check if 'xsd:element' must be used here (it may not be compatible with using 'complexType'
 
54
                 * node for describing other classes used as attribute types for current class
 
55
                 */
 
56
                $element = $dom->createElement('xsd:element');
 
57
                $element->setAttribute('name', $property->getName());
 
58
                $element->setAttribute('type', $this->getContext()->getType(trim($matches[1][0])));
 
59
                $all->appendChild($element);
 
60
            }
 
61
        }
 
62
 
 
63
        $complexType->appendChild($all);
 
64
        $this->getContext()->getSchema()->appendChild($complexType);
 
65
        $this->getContext()->addType($type);
 
66
 
 
67
        return "tns:$type";
 
68
    }
 
69
}