1 <?php
2
3 /* --------------------------------------------------------------
4 AbstractImagesApiV2Controller.inc.php 2016-01-27
5 Gambio GmbH
6 http://www.gambio.de
7 Copyright (c) 2016 Gambio GmbH
8 Released under the GNU General Public License (Version 2)
9 [http://www.gnu.org/licenses/gpl-2.0.html]
10 --------------------------------------------------------------
11 */
12
13 MainFactory::load_class('HttpApiV2Controller');
14
15 /**
16 * Class AbstractImagesApiV2Controller
17 *
18 * Provides a listing of image files.
19 *
20 * @category System
21 * @package ApiV2Controllers
22 */
23 abstract class AbstractImagesApiV2Controller extends HttpApiV2Controller
24 {
25 /**
26 * @var ProductWriteService|CategoryWriteService
27 */
28 protected $writeService;
29
30
31 /**
32 * Initializes API Controller
33 */
34 abstract protected function __initialize();
35
36
37 /**
38 * Returns the absolute path where the image files are located.
39 *
40 * @return string
41 */
42 abstract protected function _getImageFolderName();
43
44
45 /**
46 * Returns a list of all image files which exists on the server's filesystem.
47 *
48 * This function searches for image files ('gif', 'jpeg', 'jpg', 'png') in the path which is specified in the child
49 * classes _getImageFolderName method.
50 */
51 public function get()
52 {
53 $allowedFileTypes = array('gif', 'jpeg', 'jpg', 'png');
54 $response = array();
55
56 $files = glob($this->_getImageFolderName() . '*');
57 {
58 foreach($files as $file)
59 {
60 if(in_array(strtolower(pathinfo($file, PATHINFO_EXTENSION)), $allowedFileTypes))
61 {
62 $response[] = basename($file);
63 }
64 }
65 }
66
67 $this->_writeResponse($response);
68 }
69 }