Example #1
0
 /**
  * Make sure we can un-register extensions
  */
 public function testUnRegisterExtension()
 {
     Registry::unRegister('bar');
     $checkExtensions = array('foo');
     $supportedExtensions = Registry::getSupportedExtensions('foo');
     $this->assertSame($checkExtensions, $supportedExtensions);
 }
Example #2
0
 /**
  * Parses the $rawFiles and does sanity checks
  *
  * @throws ErrorException
  * @throws Asset\NotFoundException
  */
 public function init()
 {
     if (empty($this->rawFiles)) {
         throw new ErrorException('No file specified; make sure you are using the correct .htaccess rules.');
     }
     // Handle legacy code for minifying
     if (preg_match('%^/minify/%', $this->rawFiles)) {
         $this->rawFiles = substr($this->rawFiles, 7);
         $this->setRawParam('minify', 'true');
     }
     $this->ext = strtolower(pathinfo($this->rawFiles, PATHINFO_EXTENSION));
     $supportedExtensions = Registry::getSupportedExtensions($this->ext);
     // Suppressing errors because Exceptions thrown in the callback cause Warnings.
     $webroot = $this->webroot;
     $this->files = @array_map(function ($v) use($supportedExtensions, $webroot) {
         // Make sure all the file extensions are supported
         if (!in_array(strtolower(pathinfo($v, PATHINFO_EXTENSION)), $supportedExtensions)) {
             throw new ErrorException('All requested files need to be: ' . implode(', ', $supportedExtensions));
         }
         // Strip any parent directory slugs (../) - loop through until they are all gone
         $count = 1;
         while ($count > 0) {
             $v = preg_replace('%(/\\.\\.?|\\.\\.?/)%', '', $v, -1, $count);
             // If there is no slash prefix, add it back in
             if (substr($v, 0, 1) != '/') {
                 $v = '/' . $v;
             }
         }
         // Remove sub-folder if in the path, it shouldn't be there.
         $v = str_replace(SUB_FOLDER, '', $v);
         return $webroot . $v;
     }, explode(',', $this->rawFiles));
 }