1 | <?php |
||
11 | abstract class AbstractOembedProvider extends AbstractProvider implements OembedProviderInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var array |
||
15 | */ |
||
16 | protected $oembedDataCache; |
||
17 | |||
18 | /** |
||
19 | * @param AbstractMedia $media |
||
20 | * @param bool $providerReferenceUpdated |
||
21 | * @throws \Exception |
||
22 | */ |
||
23 | public function update(AbstractMedia $media, $providerReferenceUpdated) |
||
48 | |||
49 | /** |
||
50 | * @param FormMapper $formMapper |
||
51 | */ |
||
52 | public function buildProviderCreateForm(FormMapper $formMapper) |
||
60 | |||
61 | /** |
||
62 | * @param FormMapper $formMapper |
||
63 | */ |
||
64 | public function buildProviderEditFormBefore(FormMapper $formMapper) |
||
72 | |||
73 | /** |
||
74 | * @param ErrorElement $errorElement |
||
75 | * @param AbstractMedia $media |
||
76 | */ |
||
77 | public function validate(ErrorElement $errorElement, AbstractMedia $media) |
||
86 | |||
87 | /** |
||
88 | * @param \MediaMonks\SonataMediaBundle\Model\AbstractMedia $media |
||
89 | */ |
||
90 | public function refreshImage(AbstractMedia $media) |
||
99 | |||
100 | /** |
||
101 | * @param string $id |
||
102 | * @return string |
||
103 | */ |
||
104 | public function getImageUrl($id) |
||
108 | |||
109 | /** |
||
110 | * @param $id |
||
111 | * @return mixed |
||
112 | * @throws \Exception |
||
113 | */ |
||
114 | protected function getOembedDataCache($id) |
||
115 | { |
||
116 | if (empty($this->oembedDataCache[$id])) { |
||
117 | |||
118 | $this->disableErrorHandler(); |
||
119 | $data = json_decode($this->getUrlData($this->getOembedUrl($id)), true); |
||
120 | $this->restoreErrorHandler(); |
||
121 | |||
122 | if (empty($data['title'])) { |
||
123 | throw new \Exception($this->getTranslator()->trans('error.provider_reference', [ |
||
124 | '%provider%' => $this->getName(), |
||
125 | '%reference%' => $id |
||
126 | ])); |
||
127 | } |
||
128 | |||
129 | $this->oembedDataCache[$id] = $data; |
||
130 | } |
||
131 | |||
132 | return $this->oembedDataCache[$id]; |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * @return string |
||
137 | */ |
||
138 | public function getReferenceLabel() |
||
142 | |||
143 | /** |
||
144 | * @return bool |
||
145 | */ |
||
146 | public function supportsDownload() |
||
150 | |||
151 | /** |
||
152 | * @return bool |
||
153 | */ |
||
154 | public function supportsEmbed() |
||
158 | |||
159 | /** |
||
160 | * @return bool |
||
161 | */ |
||
162 | public function supportsImage() |
||
166 | |||
167 | /** |
||
168 | * @param $url |
||
169 | * @return mixed |
||
170 | */ |
||
171 | protected function getUrlData($url) |
||
184 | |||
185 | /** |
||
186 | * @param string $url |
||
187 | * @return bool |
||
188 | */ |
||
189 | protected function urlExists($url) |
||
205 | } |
||
206 |