Class to create Assets in PHP. ### Examples: $asset = $this->objectManager->get('FluidTYPO3\\Vhs\\Asset'); OR you can use the static factory method which works anywhere including outside of Extbase. $asset = \FluidTYPO3\Vhs\Asset::getInstance(); $asset->setPath('fileadmin/test.js')->setStandalone(TRUE)->finalize(); Or simply: $this->objectManager->get('FluidTYPO3\\Vhs\\Asset')->setPath('...')->finalize(); And you can create clean instances: Depending on how you need to access the Asset afterwards, you will want wo switch between these methods. Or if you have all settings in an array (with members named according to the properties on this class: \FluidTYPO3\Vhs\Asset::createFromSettings($settings)->finalize(); Finally, if your Asset is file based, VHS can perform a few detections to set initial attributes like standalone, external (if file contains protocol), type (based on extension) and name (base name of file). \FluidTYPO3\Vhs\Asset::createFromFile($filePathAndFilename); \FluidTYPO3\Vhs\Asset::createFromUrl($urlToExternalFile); You can chain all setters on the class before finally calling finalize() to register the Asset (you can still modify the Asset afterwards, but an Asset that has not been finalize()'ed will never show up or be processed - which is a lot friendlier than requiring you to use remove() on unwanted Assets). > Note: the "createFrom..." suite of methods automatically calls finalize() > on your Asset just before returning it. You can of course keep modifying > the instance after it is returned - but when using a "createFrom"... method > VHS assumes you always want your Asset included in the output.
Inheritance: implements FluidTYPO3\Vhs\ViewHelpers\Asset\AssetInterface
 /**
  * @param array $asset
  * @return void
  */
 protected function loadByVhs(array $asset)
 {
     if (GeneralUtility::getApplicationContext()->isDevelopment()) {
         $developmentFile = $this->getDevelopmentFile($asset);
         if ($developmentFile) {
             $asset['path'] = str_replace('.min.', '.', $asset['path']);
         }
     }
     Asset::createFromSettings($asset);
 }
Example #2
0
 /**
  * @param array $parameters
  * @param object $caller
  * @param boolean $cached If TRUE, treats this inclusion as happening in a cached context
  * @return void
  */
 public function buildAll(array $parameters, $caller, $cached = TRUE)
 {
     if (FALSE === $this->objectManager instanceof \TYPO3\CMS\Extbase\Object\ObjectManager) {
         $this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
         $this->configurationManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
     }
     $settings = $this->getSettings();
     $cached = (bool) $cached;
     if (FALSE === self::$typoScriptAssetsBuilt && TRUE === isset($settings['asset']) && TRUE === is_array($settings['asset'])) {
         foreach ($settings['asset'] as $name => $typoScriptAsset) {
             if (FALSE === isset($GLOBALS['VhsAssets'][$name]) && TRUE === is_array($typoScriptAsset)) {
                 if (FALSE === isset($typoScriptAsset['name'])) {
                     $typoScriptAsset['name'] = $name;
                 }
                 Asset::createFromSettings($typoScriptAsset);
             }
         }
         self::$typoScriptAssetsBuilt = TRUE;
     }
     if (FALSE === isset($GLOBALS['VhsAssets']) || FALSE === is_array($GLOBALS['VhsAssets'])) {
         return;
     }
     $assets = $GLOBALS['VhsAssets'];
     $assets = $this->sortAssetsByDependency($assets);
     $assets = $this->manipulateAssetsByTypoScriptSettings($assets);
     $buildDebugRequested = isset($settings['asset']['debugBuild']) && $settings['asset']['debugBuild'] > 0;
     $assetDebugRequested = isset($settings['asset']['debug']) && $settings['asset']['debug'] > 0;
     $useDebugUtility = isset($settings['asset']['useDebugUtility']) && $settings['asset']['useDebugUtility'] > 0 || FALSE === isset($settings['asset']['useDebugUtility']);
     if (TRUE === ($buildDebugRequested || $assetDebugRequested)) {
         if (TRUE === $useDebugUtility) {
             DebuggerUtility::var_dump($assets);
         } else {
             echo var_export($assets, TRUE);
         }
     }
     $this->placeAssetsInHeaderAndFooter($assets, $cached);
 }
Example #3
0
 /**
  * @test
  */
 public function assertSupportsRawContent()
 {
     $file = $this->getAbsoluteAssetFixturePath();
     $content = file_get_contents($file);
     $asset = Asset::createFromContent($content);
     $this->assertSame($content, $asset->getContent());
 }
Example #4
0
 /**
  * @param array $parameters
  * @param object $caller
  * @param boolean $cached If TRUE, treats this inclusion as happening in a cached context
  * @return void
  */
 public function buildAll(array $parameters, $caller, $cached = true)
 {
     if (false === $this->objectManager instanceof ObjectManager) {
         $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
         $this->configurationManager = $this->objectManager->get(ConfigurationManagerInterface::class);
     }
     $settings = $this->getSettings();
     $cached = (bool) $cached;
     $buildTypoScriptAssets = !static::$typoScriptAssetsBuilt && ($cached || $GLOBALS['TSFE']->no_cache);
     if ($buildTypoScriptAssets && isset($settings['asset']) && is_array($settings['asset'])) {
         foreach ($settings['asset'] as $name => $typoScriptAsset) {
             if (!isset($GLOBALS['VhsAssets'][$name]) && is_array($typoScriptAsset)) {
                 if (!isset($typoScriptAsset['name'])) {
                     $typoScriptAsset['name'] = $name;
                 }
                 Asset::createFromSettings($typoScriptAsset);
             }
         }
         static::$typoScriptAssetsBuilt = true;
     }
     if (!isset($GLOBALS['VhsAssets']) || !is_array($GLOBALS['VhsAssets'])) {
         return;
     }
     $assets = $GLOBALS['VhsAssets'];
     $assets = $this->sortAssetsByDependency($assets);
     $assets = $this->manipulateAssetsByTypoScriptSettings($assets);
     $buildDebugRequested = isset($settings['asset']['debugBuild']) && $settings['asset']['debugBuild'] > 0;
     $assetDebugRequested = isset($settings['asset']['debug']) && $settings['asset']['debug'] > 0;
     $useDebugUtility = isset($settings['asset']['useDebugUtility']) && $settings['asset']['useDebugUtility'] > 0 || false === isset($settings['asset']['useDebugUtility']);
     if (true === ($buildDebugRequested || $assetDebugRequested)) {
         if (true === $useDebugUtility) {
             DebuggerUtility::var_dump($assets);
         } else {
             echo var_export($assets, true);
         }
     }
     $this->placeAssetsInHeaderAndFooter($assets, $cached);
 }