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

4
5
/*
 * This file is part of the TYPO3 CMS project.
flyguide's avatar
flyguide committed
6
 *
7
8
9
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
flyguide's avatar
flyguide committed
10
 *
11
12
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
flyguide's avatar
flyguide committed
13
 *
14
15
 * The TYPO3 project - inspiring people to share!
 */
flyguide's avatar
flyguide committed
16
17
18
19

/**
 * Abstract extension provider
 */
20
abstract class AbstractProvider implements \T3o\TerFe2\Provider\ProviderInterface
21
22
23
{

    /**
24
     * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
25
26
27
28
     */
    protected $objectManager;

    /**
29
     * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory
30
31
32
33
     */
    protected $dataMapFactory;

    /**
34
     * @var \TYPO3\CMS\Extbase\Reflection\ReflectionService
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
     */
    protected $reflectionService;

    /**
     * @var array Configuration array
     */
    protected $configuration;

    /**
     * @var string
     */
    protected $imageCachePath = 'typo3temp/tx_terfe2/images/';


    /**
     * Get or create absolute path to image cache directory
     */
    public function __construct()
    {
54
        $this->imageCachePath = \T3o\TerFe2\Utility\FileUtility::getAbsoluteDirectory($this->imageCachePath);
55
56
57
    }


58
59
    /**
     * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
60
61
     * @return void
     */
62
    public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
63
64
65
66
67
68
    {
        $this->objectManager = $objectManager;
    }


    /**
69
     * @param \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory $dataMapFactory
70
71
     * @return void
     */
72
    public function injectDataMapFactory(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory $dataMapFactory)
73
74
75
76
77
78
    {
        $this->dataMapFactory = $dataMapFactory;
    }


    /**
79
     * @param \TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService
80
81
     * @return void
     */
82
    public function injectReflectionService(\TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService)
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
    {
        $this->reflectionService = $reflectionService;
    }


    /**
     * Set configuration for the DataProvider
     *
     * @param array $configuration TypoScript configuration
     * @return void
     */
    public function setConfiguration(array $configuration)
    {
        $this->configuration = $configuration;
    }


    /**
     * Returns the url to an extension related icon
     *
103
     * @param \T3o\TerFe2\Domain\Model\Version $version Version object
104
105
106
     * @param string $fileType File type
     * @return string Url to icon file
     */
107
    public function getIconUrl(\T3o\TerFe2\Domain\Model\Version $version, $fileType)
108
109
110
111
112
    {
        $filename = $this->getFileName($version, $fileType);
        $localName = $this->imageCachePath . basename($filename);

        // Check local cache first
113
114
        if (\T3o\TerFe2\Utility\FileUtility::fileExists($localName)) {
            return \T3o\TerFe2\Utility\FileUtility::getUrlFromAbsolutePath($localName);
115
116
117
118
119
120
121
        }

        // Get icon from concrete extension provider
        $iconUrl = $this->getFileUrl($version, $fileType);

        // Copy icon to local cache
        if (!empty($iconUrl)) {
122
            \T3o\TerFe2\Utility\FileUtility::copyFile($iconUrl, $localName);
123
124
        }

125
        return \T3o\TerFe2\Utility\FileUtility::getUrlFromAbsolutePath($localName);
126
127
128
129
130
131
132
133
134
135
136
    }


    /**
     * Returns an array with minimum and maximum version number from range
     *
     * @param string $version Range of versions
     * @return array Minumum and maximum version number
     */
    protected function getVersionByRange($version)
    {
137
        $version = \TYPO3\CMS\Extbase\Utility\ArrayUtility::trimExplode('-', $version);
138
139
        $minimum = (!empty($version[0]) ? \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger($version[0]) : 0);
        $maximum = (!empty($version[1]) ? \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger($version[1]) : 0);
140
141
142

        return array($minimum, $maximum);
    }
flyguide's avatar
flyguide committed
143
}