SoapProvider.php 6.27 KB
Newer Older
1
<?php
2
3
namespace T3o\TerFe2\Provider;

flyguide's avatar
flyguide committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*******************************************************************
 *  Copyright notice
 *
 *  (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
 *
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ******************************************************************/

/**
 * Extension provider for soap requests
 */
31
class SoapProvider extends \T3o\TerFe2\Provider\AbstractProvider
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
{

    /**
     * @var string
     */
    protected $getExtensionsFunc;

    /**
     * @var string
     */
    protected $getFileUrlFunc;

    /**
     * @var string
     */
    protected $getFileNameFunc;

    /**
     * @var string
     */
    protected $getDownloadCountFunc;

    /**
55
     * @var \T3o\TerFe2\Service\Soap
56
57
58
59
60
61
62
63
64
65
66
67
     */
    protected $soapService;


    /**
     * Initialize provider
     *
     * @return void
     */
    public function initializeProvider()
    {
        if (empty($this->configuration['wsdlUrl'])) {
68
            throw new \Exception('No wsdl url configured');
69
70
71
72
        }

        $username = (empty($this->configuration['username']) ? $this->configuration['username'] : '');
        $password = (empty($this->configuration['password']) ? $this->configuration['password'] : '');
73
        $this->soapService = $this->objectManager->get(\T3o\TerFe2\Service\Soap::class);
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
        $this->soapService->connect($this->configuration['wsdlUrl'], $username, $password);

        // Set getExtensionsFunc
        if (!empty($this->configuration['getExtensionsFunc'])) {
            $this->getExtensionsFunc = $this->configuration['getExtensionsFunc'];
        }

        // Set getFileUrlFunc
        if (!empty($this->configuration['getFileUrlFunc'])) {
            $this->getFileUrlFunc = $this->configuration['getFileUrlFunc'];
        }

        // Set getFileNameFunc
        if (!empty($this->configuration['getFileNameFunc'])) {
            $this->getFileNameFunc = $this->configuration['getFileNameFunc'];
        }

        // Set getDownloadCountFunc
        if (!empty($this->configuration['getDownloadCountFunc'])) {
            $this->getDownloadCountFunc = $this->configuration['getDownloadCountFunc'];
        }
    }


    /**
     * Returns all extensions since last run
     *
     * @param integer $lastRun Timestamp of last update
     * @param integer $offset Offset to start with
     * @param integer $count Extension count to load
     * @return array Extension rows
     */
    public function getExtensions($lastRun, $offset, $count)
    {
        if (empty($this->getExtensionsFunc)) {
109
            throw new \Exception('No configuration for "getExtensionsFunc" found');
110
111
112
113
114
115
116
117
118
119
120
121
122
123
        }
        $parameters = array(
            'lastRun' => (int)$lastRun,
            'offset' => (int)$offset,
            'count' => (int)$count,
        );
        $result = $this->soapService->__call($this->getExtensionsFunc, $parameters);
        return (!empty($result['extensions']) ? $result['extensions'] : array());
    }


    /**
     * Returns the url to an extension related file
     *
124
     * @param \T3o\TerFe2\Domain\Model\Version $version Version object
125
126
127
     * @param string $fileType File type
     * @return string Url to file
     */
128
    public function getFileUrl(\T3o\TerFe2\Domain\Model\Version $version, $fileType)
129
130
    {
        if (empty($this->getFileUrlFunc)) {
131
            throw new \Exception('No configuration for "getFileUrlFunc" found');
132
133
134
135
136
137
138
139
        }
        $parameters = array(
            'extension' => (string)$version->getExtension()->getExtKey(),
            'version' => (string)$version->getVersionString(),
            'fileType' => (string)$fileType,
        );
        $result = $this->soapService->__call($this->getFileUrlFunc, $parameters);
        if (empty($result['url'])) {
140
            throw new \Exception('Could not get url to file from soap server');
141
142
143
144
145
146
147
148
        }
        return (string)$result['url'];
    }


    /**
     * Returns name of an extension related file
     *
149
     * @param \T3o\TerFe2\Domain\Model\Version $version Version object
150
151
152
     * @param string $fileType File type
     * @return string File name
     */
153
    public function getFileName(\T3o\TerFe2\Domain\Model\Version $version, $fileType)
154
155
    {
        if (empty($this->getFileNameFunc)) {
156
            throw new \Exception('No configuration for "getFileNameFunc" found');
157
158
159
160
161
162
163
164
        }
        $parameters = array(
            'extension' => (string)$version->getExtension()->getExtKey(),
            'version' => (string)$version->getVersionString(),
            'fileType' => (string)$fileType,
        );
        $result = $this->soapService->__call($this->getFileNameFunc, $parameters);
        if (empty($result['filename'])) {
165
            throw new \Exception('Could not get filename from soap server');
166
167
168
169
170
171
172
173
        }
        return (string)$result['filename'];
    }


    /**
     * Returns all information about an extension version
     *
174
     * @param \T3o\TerFe2\Domain\Model\Version $version Version object
175
176
     * @return array Version details
     */
177
    public function getVersionDetails(\T3o\TerFe2\Domain\Model\Version $version)
178
179
    {
        if (empty($this->getVersionDetailsFunc)) {
180
            throw new \Exception('No configuration for "getVersionDetailsFunc" found');
181
182
183
184
185
186
187
        }
        $parameters = array(
            'extension' => (string)$version->getExtension()->getExtKey(),
            'version' => (string)$version->getVersionString(),
        );
        $result = $this->soapService->__call($this->getVersionDetailsFunc, $parameters);
        if (empty($result) || !is_array($result)) {
188
            throw new \Exception('Could not get version details from soap server');
189
190
191
        }
        return $result;
    }
flyguide's avatar
flyguide committed
192
193

}