This repository has been archived by the owner on Oct 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
ServiceOptions.php
805 lines (726 loc) · 25.5 KB
/
ServiceOptions.php
1
2
3
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
<?php
namespace AssetsBundle\Service;
class ServiceOptions extends \Zend\Stdlib\AbstractOptions
{
const NO_MODULE = 'no_module';
const NO_ACTION = 'no_action';
const NO_CONTROLLER = 'no_controller';
/**
* Application environment (Developpement => false)
* @var boolean
*/
protected $production;
/**
* Arbitrary last modified time in production
* @var scalable|null
*/
protected $lastModifiedTime;
/**
* Cache directory absolute path
* @var string
*/
protected $cachePath;
/**
* Assets directory absolute path (allows you to define relative path for assets config)
* @var string
*/
protected $assetsPath;
/**
* Temp directory absolute path
* @var string
*/
protected $tmpDirPath;
/**
* Processed files directory absolute path
* @var string
*/
protected $processedDirPath;
/**
* Base URL of the application
* @var string
*/
protected $baseUrl = '';
/**
* Cache directory base url
* @var string
*/
protected $cacheUrl;
/**
* Media extensions to be cached
* @var array
*/
protected $mediaExt;
/**
* Allows search for matching assets in required folder and its subfolders
* @var boolean
*/
protected $recursiveSearch;
/**
* Permissions for created files
* @var integer
*/
protected $filesPermissions;
/**
* Permissions for created directories
* @var integer
*/
protected $directoriesPermissions;
/**
* Required assets
* @var array
*/
protected $assets = array();
/**
* Assets renderer
* @var \Zend\View\Renderer\RendererInterface
*/
protected $renderer;
/**
* Current module name
* @var string
*/
protected $moduleName = self::NO_MODULE;
/**
* Current controller name
* @var string
*/
protected $controllerName = self::NO_CONTROLLER;
/**
* Current action name
* @var string
*/
protected $actionName = self::NO_ACTION;
/**
* Disabled contexts
* @var array
*/
protected $disabledContexts = array();
/**
* View helper plugins by asset file types
* @var array
*/
protected $view_helper_plugins = array();
/**
* Store resolved real paths
* @var array
*/
protected $resolvedPaths = array();
/**
* @param boolean $bProduction
* @throws \InvalidArgumentException
* @return \AssetsBundle\Service\ServiceOptions
*/
public function setProduction($bProduction)
{
if (is_bool($bProduction)) {
$this->production = $bProduction;
return $this;
}
throw new \InvalidArgumentException('"Production" option expects a boolean, "' . gettype($bProduction) . '" given');
}
/**
* @throws \LogicException
* @return boolean
*/
public function isProduction()
{
if (is_bool($this->production)) {
return $this->production;
}
throw new \LogicException('"Production" option is undefined');
}
/**
* @param scalable|null $sLastModifiedTime
* @throws \InvalidArgumentException
* @return \AssetsBundle\Service\ServiceOptions
*/
public function setLastModifiedTime($sLastModifiedTime = null)
{
if (is_scalar($sLastModifiedTime) || is_null($sLastModifiedTime)) {
$this->lastModifiedTime = $sLastModifiedTime;
return $this;
}
throw new \InvalidArgumentException('"Last modified time" option expects a scalable value, "' . gettype($sLastModifiedTime) . '" given');
}
/**
* @throws \LogicException
* @return scalable|null
*/
public function getLastModifiedTime()
{
if (is_scalar($this->lastModifiedTime) || is_null($this->lastModifiedTime)) {
return $this->lastModifiedTime;
}
throw new \LogicException('"Last modified time" option is undefined');
}
/**
* @param string $sCachePath
* @throws \InvalidArgumentException
* @return \AssetsBundle\Service\ServiceOptions
*/
public function setCachePath($sCachePath)
{
if (is_string($sCachePath)) {
if (is_dir($sRealCachePath = $this->getRealPath($sCachePath))) {
if (is_writable($sRealCachePath)) {
$this->cachePath = $sRealCachePath;
return $this;
}
throw new \InvalidArgumentException('Cache path directory "' . $sRealCachePath . '" is not writable');
}
throw new \InvalidArgumentException('Cache path option expects a valid directory path, "' . $sCachePath . '" given');
}
throw new \InvalidArgumentException('"Cache path" option expects a string, "' . gettype($sCachePath) . '" given');
}
/**
* @throws \LogicException
* @return string
*/
public function getCachePath()
{
if (is_string($this->cachePath)) {
return $this->cachePath;
}
throw new \LogicException('"Cache path" option is undefined');
}
/**
* @param string|null $sAssetsPath
* @throws \InvalidArgumentException
* @return \AssetsBundle\Service\ServiceOptions
*/
public function setAssetsPath($sAssetsPath = null)
{
if (!is_string($sAssetsPath) && !is_null($sAssetsPath)) {
throw new \InvalidArgumentException('"Assets path" option expects a string or null, "' . gettype($sAssetsPath) . '" given');
}
if (is_null($sAssetsPath)) {
$this->assetsPath = null;
} elseif (is_dir($sAssetsRealPath = $this->getRealPath($sAssetsPath))) {
$this->assetsPath = $sAssetsRealPath;
} else {
throw new \InvalidArgumentException('"assetsPath" config expects a valid directory path, "' . $sAssetsRealPath . '" given');
}
return $this;
}
/**
* @return boolean
*/
public function hasAssetsPath()
{
return is_string($this->assetsPath);
}
/**
* @throws \LogicException
* @return string
*/
public function getAssetsPath()
{
if ($this->hasAssetsPath()) {
return $this->assetsPath;
}
throw new \LogicException('"Assets path" option is undefined');
}
/**
* @param string $sTmpDirPath
* @return \AssetsBundle\Service\ServiceOptions
* @throws \InvalidArgumentException
*/
public function setTmpDirPath($sTmpDirPath)
{
if (!is_string($sTmpDirPath)) {
throw new \InvalidArgumentException('"Temp dir path" option expects a string, "' . gettype($sTmpDirPath) . '" given');
}
if (($sTmpDirRealPath = $this->getRealPath($sTmpDirPath)) && is_dir($sTmpDirRealPath) && is_writable($sTmpDirRealPath)) {
$this->tmpDirPath = $sTmpDirRealPath;
return $this;
}
throw new \InvalidArgumentException('"Temp dir path" option "' . $sTmpDirPath . '" is not writable directory path');
}
/**
* @return string
* @throws \LogicException
*/
public function getTmpDirPath()
{
if (is_dir($this->tmpDirPath) && is_writable($this->tmpDirPath)) {
return $this->tmpDirPath;
}
throw new \LogicException('"Temp dir path" option is undefined');
}
/**
* @param string $sProcessedDirPath
* @return \AssetsBundle\Service\ServiceOptions
* @throws \InvalidArgumentException
*/
public function setProcessedDirPath($sProcessedDirPath)
{
if (!is_string($sProcessedDirPath)) {
throw new \InvalidArgumentException('"Processed dir path" option expects a string, "' . gettype($sProcessedDirPath) . '" given');
}
if (($sProcessedDirRealPath = $this->getRealPath($sProcessedDirPath)) && is_dir($sProcessedDirRealPath) && is_writable($sProcessedDirRealPath)) {
$this->processedDirPath = $sProcessedDirRealPath;
return $this;
}
throw new \InvalidArgumentException('"Processed dir path" option "' . $sProcessedDirPath . '" is not writable directory path');
}
/**
* @return string
* @throws \LogicException
*/
public function getProcessedDirPath()
{
if (is_dir($this->processedDirPath) && is_writable($this->processedDirPath)) {
return $this->processedDirPath;
}
throw new \LogicException('"Processed dir path" option is undefined');
}
/**
* @param string $sBaseUrl
* @throws \InvalidArgumentException
* @return \AssetsBundle\Service\ServiceOptions
*/
public function setBaseUrl($sBaseUrl)
{
if (is_string($sBaseUrl)) {
$this->baseUrl = rtrim($sBaseUrl, '/');
return $this;
}
throw new \InvalidArgumentException('"Base url" option expects a string, "' . gettype($sBaseUrl) . '" given');
}
/**
* @throws \LogicException
* @return string
*/
public function getBaseUrl()
{
if (is_string($this->baseUrl)) {
return $this->baseUrl;
}
throw new \LogicException('"Base url" option is undefined');
}
/**
* @param string $sCacheUrl
* @throws \InvalidArgumentException
* @return \AssetsBundle\Service\ServiceOptions
*/
public function setCacheUrl($sCacheUrl)
{
if (is_string($sCacheUrl)) {
if (strpos($sCacheUrl, '@zfBaseUrl') !== false) {
$sCacheUrl = $this->getBaseUrl() . '/' . ltrim(str_ireplace('@zfBaseUrl', '', $sCacheUrl), '/');
}
$this->cacheUrl = $sCacheUrl;
return $this;
}
throw new \InvalidArgumentException('"Cache url" option expects a string, "' . gettype($sCacheUrl) . '" given');
}
/**
* @throws \LogicException
* @return string
*/
public function getCacheUrl()
{
if (is_string($this->cacheUrl)) {
return $this->cacheUrl;
}
throw new \LogicException('"Cache url" option is undefined');
}
/**
* @param array $aMediaExt
* @throws \InvalidArgumentException
* @return \AssetsBundle\Service\ServiceOptions
*/
public function setMediaExt(array $aMediaExt)
{
$this->mediaExt = array();
foreach (array_unique($aMediaExt) as $sMediaExt) {
if (empty($sMediaExt)) {
throw new \InvalidArgumentException('Media extension is empty');
}
if (is_string($sMediaExt)) {
$this->mediaExt[] = $sMediaExt;
} else {
throw new \InvalidArgumentException('"Media extension" expects a string, "' . gettype($sMediaExt) . '" given');
}
}
return $this;
}
/**
* @throws \LogicException
* @return array
*/
public function getMediaExt()
{
if (is_array($this->mediaExt)) {
return $this->mediaExt;
}
throw new \LogicException('"Media extensions" option is undefined');
}
/**
* @param boolean $bRecursiveSearch
* @throws \InvalidArgumentException
* @return \AssetsBundle\Service\ServiceOptions
*/
public function setRecursiveSearch($bRecursiveSearch)
{
if (is_bool($bRecursiveSearch)) {
$this->recursiveSearch = $bRecursiveSearch;
return $this;
}
throw new \InvalidArgumentException('"Recursive search" option expects a boolean, "' . gettype($bRecursiveSearch) . '" given');
}
/**
* @throws \LogicException
* @return boolean
*/
public function allowsRecursiveSearch()
{
if (is_bool($this->recursiveSearch)) {
return $this->recursiveSearch;
}
throw new \LogicException('"Recursive search" option is undefined');
}
/**
* @return integer
* @throws \LogicException
*/
public function getFilesPermissions()
{
if (is_integer($this->filesPermissions)) {
return $this->filesPermissions;
}
throw new \LogicException('Property "filesPermissions" expects an integer, "' . (is_object($this->filesPermissions) ? get_class($this->filesPermissions) : gettype($this->filesPermissions)) . '" defined');
}
/**
* @param integer $iFilesPermissions
* @return \AssetsBundle\Service\ServiceOptions
* @throws \InvalidArgumentException
*/
public function setFilesPermissions($iFilesPermissions)
{
if (is_integer($iFilesPermissions)) {
$this->filesPermissions = $iFilesPermissions;
return $this;
}
throw new \InvalidArgumentException('Argument "$iFilesPermissions" expects an integer, "' . (is_object($iFilesPermissions) ? get_class($iFilesPermissions) : gettype($iFilesPermissions)) . '" given');
}
/**
* @return integer
* @throws \LogicException
*/
public function getDirectoriesPermissions()
{
if (is_integer($this->directoriesPermissions)) {
return $this->directoriesPermissions;
}
throw new \LogicException('Property "directoriesPermissions" expects an integer, "' . (is_object($this->directoriesPermissions) ? get_class($this->directoriesPermissions) : gettype($this->directoriesPermissions)) . '" defined');
}
/**
* @param integer $iDirectoriesPermissions
* @return \AssetsBundle\Service\ServiceOptions
* @throws \InvalidArgumentException
*/
public function setDirectoriesPermissions($iDirectoriesPermissions)
{
if (is_integer($iDirectoriesPermissions)) {
$this->directoriesPermissions = $iDirectoriesPermissions;
return $this;
}
throw new \InvalidArgumentException('Argument "$iDirectoriesPermissions" expects an integer, "' . (is_object($iDirectoriesPermissions) ? get_class($iDirectoriesPermissions) : gettype($iDirectoriesPermissions)) . '" given');
}
/**
* @param array $aAssets
* @return \AssetsBundle\Service\ServiceOptions
*/
public function setAssets(array $aAssets)
{
$this->assets = $aAssets;
return $this;
}
/**
* @throws \LogicException
* @return array
*/
public function getAssets()
{
if (is_array($this->assets)) {
return $this->assets;
}
throw new \LogicException('"Assets" option is undefined');
}
/**
* @param \Zend\View\Renderer\RendererInterface $oRenderer
* @return \AssetsBundle\Service\ServiceOptions
*/
public function setRenderer(\Zend\View\Renderer\RendererInterface $oRenderer)
{
$this->renderer = $oRenderer;
return $this;
}
/**
* @throws \LogicException
* @return \Zend\View\Renderer\RendererInterface
*/
public function getRenderer()
{
if ($this->renderer instanceof \Zend\View\Renderer\RendererInterface) {
return $this->renderer;
}
throw new \LogicException('"Renderer" option is undefined');
}
/**
* @param string $sModuleName
* @throws \InvalidArgumentException
* @return \AssetsBundle\Service\ServiceOptions
*/
public function setModuleName($sModuleName)
{
if (empty($sModuleName)) {
throw new \InvalidArgumentException('"Module name" option is empty');
}
if (!is_string($sModuleName)) {
throw new \InvalidArgumentException('"Module name" option expects a string, "' . gettype($sModuleName) . '" given');
}
$this->moduleName = $sModuleName;
return $this;
}
/**
* @throws \LogicException
* @return string
*/
public function getModuleName()
{
if (is_string($this->moduleName)) {
return $this->moduleName;
}
throw new \LogicException('"Module name" option is undefined');
}
/**
* @param string $sControllerName
* @throws \InvalidArgumentException
* @return \AssetsBundle\Service\ServiceOptions
*/
public function setControllerName($sControllerName)
{
if (empty($sControllerName)) {
throw new \InvalidArgumentException('"Controller name" option is empty');
}
if (!is_string($sControllerName)) {
throw new \InvalidArgumentException('"Controller name" option expects a string, "' . gettype($sControllerName) . '" given');
}
$this->controllerName = $sControllerName;
return $this;
}
/**
* @throws \LogicException
* @return string
*/
public function getControllerName()
{
if (is_string($this->controllerName)) {
return $this->controllerName;
}
throw new \LogicException('"Controller name" option is undefined');
}
/**
* @param string $sActionName
* @throws \InvalidArgumentException
* @return \AssetsBundle\Service\ServiceOptions
*/
public function setActionName($sActionName)
{
if (empty($sActionName)) {
throw new \InvalidArgumentException('"Action name" option is empty');
}
if (!is_string($sActionName)) {
throw new \InvalidArgumentException('"Action name" option expects a string, "' . gettype($sActionName) . '" given');
}
$this->actionName = $sActionName;
return $this;
}
/**
* @throws \LogicException
* @return string
*/
public function getActionName()
{
if (is_string($this->actionName)) {
return $this->actionName;
}
throw new \LogicException('"Action name" option is undefined');
}
/**
* @param array $aDisabledContexts
* @return \AssetsBundle\Service\ServiceOptions
*/
public function setDisabledContexts(array $aDisabledContexts)
{
$this->disabledContexts = $aDisabledContexts;
return $this;
}
/**
* @return boolean
*/
public function isAssetsBundleDisabled()
{
if (isset($this->disabledContexts[$sModuleName = $this->getModuleName()])) {
if (is_bool($this->disabledContexts[$sModuleName])) {
return $this->disabledContexts[$sModuleName];
}
if (isset($this->disabledContexts[$sModuleName][$sControllerName = $this->getControllerName()])) {
if (is_bool($this->disabledContexts[$sModuleName][$sControllerName])) {
return $this->disabledContexts[$sModuleName][$sControllerName];
}
if (isset($this->disabledContexts[$sModuleName][$sControllerName][$sActionName = $this->getActionName()])) {
if (is_bool($this->disabledContexts[$sModuleName][$sControllerName][$sActionName])) {
return $this->disabledContexts[$sModuleName][$sControllerName][$sActionName];
}
}
}
}
return false;
}
/**
* @param array $aViewHelperPlugins
* @return \AssetsBundle\Service\ServiceOptions
*/
public function setViewHelperPlugins(array $aViewHelperPlugins)
{
$this->view_helper_plugins = $aViewHelperPlugins;
return $this;
}
/**
* @return array
* @throws \LogicException
*/
public function getViewHelperPlugins()
{
if (is_array($this->view_helper_plugins)) {
return $this->view_helper_plugins;
}
throw new \LogicException('View helper plugins are undefined');
}
/**
* @param string $sAssetFileType
* @return \Zend\View\Helper\HelperInterface
* @throws \LogicException
* @throws \InvalidArgumentException
*/
public function getViewHelperPluginForAssetFileType($sAssetFileType)
{
if (\AssetsBundle\AssetFile\AssetFile::assetFileTypeExists($sAssetFileType)) {
if (!is_array($this->view_helper_plugins)) {
throw new \LogicException('View helper plugins are undefined');
}
if (isset($this->view_helper_plugins[$sAssetFileType]) && $this->view_helper_plugins[$sAssetFileType] instanceof \Zend\View\Helper\HelperInterface) {
return $this->view_helper_plugins[$sAssetFileType];
}
throw new \InvalidArgumentException('View helper plugin for asset file type "' . $sAssetFileType . '" is undefined');
}
}
/**
* Try to retrieve realpath for a given path (manage @zfRootPath)
* @param string $sPathToResolve
* @return string|boolean
* @throws \InvalidArgumentException
*/
public function getRealPath($sPathToResolve, \AssetsBundle\AssetFile\AssetFile $oAssetFile = null)
{
if (!is_string($sPathToResolve)) {
throw new \InvalidArgumentException('Argument "$sPathToResolve" expects a string, "' . (is_object($sPathToResolve) ? get_class($sPathToResolve) : gettype($sPathToResolve)) . '" given');
}
if (!$sPathToResolve) {
throw new \InvalidArgumentException('Argument "$sPathToResolve" is empty');
}
// Define resolved paths key
$sResolvedPathsKey = ($oAssetFile ? $oAssetFile->getAssetFilePath() . '_' : '') . $sPathToResolve;
if (isset($this->resolvedPaths[$sResolvedPathsKey])) {
return $this->resolvedPaths[$sResolvedPathsKey];
}
// If path is "/", assets path is prefered
if ($sPathToResolve === DIRECTORY_SEPARATOR && $this->hasAssetsPath()) {
return $this->resolvedPaths[$sResolvedPathsKey] = $this->getAssetsPath();
}
// Path is absolute
if (file_exists($sPathToResolve)) {
return $this->resolvedPaths[$sResolvedPathsKey] = realpath($sPathToResolve);
}
if (strpos($sPathToResolve, '@zfRootPath') !== false) {
$sPathToResolve = str_ireplace('@zfRootPath', getcwd(), $sPathToResolve);
}
if (strpos($sPathToResolve, '@zfAssetsPath') !== false) {
$sPathToResolve = str_ireplace('@zfAssetsPath', $this->getAssetsPath(), $sPathToResolve);
}
if (($sRealPath = realpath($sPathToResolve)) !== false) {
return $this->resolvedPaths[$sResolvedPathsKey] = $sRealPath;
}
// Try to guess real path with root path or asset path (if defined)
if (file_exists($sRealPath = getcwd() . DIRECTORY_SEPARATOR . $sPathToResolve)) {
return $this->resolvedPaths[$sResolvedPathsKey] = realpath($sRealPath);
}
if ($this->hasAssetsPath() && file_exists($sRealPath = $this->getAssetsPath() . DIRECTORY_SEPARATOR . $sPathToResolve)) {
return $this->resolvedPaths[$sResolvedPathsKey] = realpath($sRealPath);
}
// Try to define real path with given asset file path
if ($oAssetFile && file_exists($sRealPath = dirname($oAssetFile->getAssetFilePath()) . DIRECTORY_SEPARATOR . $sPathToResolve)) {
return $this->resolvedPaths[$sResolvedPathsKey] = realpath($sRealPath);
}
return false;
}
/**
* Retrieve cache file name for given module name, controller name and action name
* @return string
*/
public function getCacheFileName()
{
$aAssets = $this->getAssets();
$sCacheFileName = isset($aAssets[$sModuleName = $this->getModuleName()]) ? $sModuleName : \AssetsBundle\Service\ServiceOptions::NO_MODULE;
$aUnwantedKeys = array(
\AssetsBundle\AssetFile\AssetFile::ASSET_CSS => true,
\AssetsBundle\AssetFile\AssetFile::ASSET_LESS => true,
\AssetsBundle\AssetFile\AssetFile::ASSET_JS => true,
\AssetsBundle\AssetFile\AssetFile::ASSET_MEDIA => true
);
$aAvailableModuleAssets = array_diff_key($aAssets, $aUnwantedKeys);
$bControllerNameFound = false;
$sControllerName = $this->getControllerName();
foreach ($aAvailableModuleAssets as $aModuleConfig) {
if (isset($aModuleConfig[$sControllerName])) {
$bControllerNameFound = true;
break;
}
}
$sCacheFileName .= '_' . ($bControllerNameFound ? $sControllerName : \AssetsBundle\Service\ServiceOptions::NO_CONTROLLER);
$bActionNameFound = false;
$sActionName = $this->getActionName();
reset($aAvailableModuleAssets);
foreach ($aAvailableModuleAssets as $aModuleConfig) {
foreach (array_diff_key($aModuleConfig, $aUnwantedKeys) as $aControllerConfig) {
if (isset($aControllerConfig[$sActionName])) {
$bActionNameFound = true;
}
}
}
$sCacheFileName .= '_' . ($bActionNameFound ? $sActionName : \AssetsBundle\Service\ServiceOptions::NO_ACTION);
return md5($sCacheFileName);
}
/**
* @param \AssetsBundle\AssetFile\AssetFile $oAssetFile
* @param scalar $iLastModifiedTime
* @return string
*/
public function getAssetFileBaseUrl(\AssetsBundle\AssetFile\AssetFile $oAssetFile, $iLastModifiedTime = null)
{
if ($oAssetFile->isAssetFilePathUrl()) {
return $oAssetFile->getAssetFilePath();
}
$sAssetPath = str_replace(array($this->getCachePath(), DIRECTORY_SEPARATOR), array('', '/'), $oAssetFile->getAssetFilePath());
if ($oAssetFile->getAssetFileType() === \AssetsBundle\AssetFile\AssetFile::ASSET_MEDIA) {
return $this->getCacheUrl() . ltrim($sAssetPath, '/');
}
if ($iLastModifiedTime === null) {
$iLastModifiedTime = $oAssetFile->getAssetFileLastModified();
}
return $this->getCacheUrl() . ltrim($sAssetPath, '/') . ($iLastModifiedTime ? (strpos($sAssetPath, '?') === false ? '?' : '&' ) . $iLastModifiedTime : '');
}
}