コード例 #1
0
 protected function inlineFiles($inlines, $setVar = 'customCSS', $unsetVar = 'css', $replaceString = '%s', $id = 'Inline-CSS')
 {
     if (count($inlines)) {
         $this->removeIfFound($id, $setVar);
         $items = [];
         $isDev = Director::isDev();
         foreach ($inlines as $file => $data) {
             if (!Director::is_absolute_url($file)) {
                 $file = Director::getAbsFile($file);
             }
             $key = Utilities::clean_cache_key($file);
             $content = singleton('require')->cache()->load($key);
             if ($content === false) {
                 $content = @file_get_contents($file);
                 if ($content && !$isDev) {
                     $content = singleton('require')->minify_contents_according_to_type($content, $file);
                 }
                 if (!$isDev) {
                     singleton('require')->cache()->save($content, $key);
                 }
             }
             if ($content) {
                 $items[$file] = $content;
                 $this->removeIfFound($id, $unsetVar);
             }
         }
         if (count($items)) {
             if ($setVar == 'customHeadTags') {
                 $this->insertHeadTags(sprintf($replaceString, implode("\n\n", $items)), $id);
             } elseif ($setVar == 'customScript') {
                 $this->customScript(sprintf($replaceString, implode("\n\n", $items)), $id);
             } elseif ($setVar == 'customCSS') {
                 $this->customCSS(sprintf($replaceString, implode("\n\n", $items)), $id);
             }
         }
     }
 }
コード例 #2
0
 public function testCleanCacheKey()
 {
     $this->assertEquals('Test_', Utilities::clean_cache_key('Test#&^%$'));
     $this->assertEquals('Test_isawesome', Utilities::clean_cache_key('Test#&^%$', ['is' => 'awesome']));
     $this->assertEquals('Test_isawesome_andmore', Utilities::clean_cache_key('Test#&^%$', ['is' => 'awesome', 'and' => 'more']));
 }