/** * Parse and transform the preset statement to a ready-to-use information * * The statement string can be constructed as (without spaces): * * position : info : src * * where `position` can be an integer or a string like `top` or `bottom`, `info` can be * a string like `pack` for packed javascript or `min` for already minified scripts and * `src` is the relative path of the file in the original package. Position is a [-1;100] * integer range where 100 is the top of the stack (first files to include). * * By default, position is 0 (the file is added to the stack), and the script is considered * not minified neither as packed. * * @return void * @throws \Exception if one of the statements is malformed */ public function parse() { if (!empty($this->transformed_data)) { return; } $data = $this->data; if (count($data) === 1 && !isset($data['src']) && isset($data[0])) { $data = array('src' => $data[0]); } $data = array_merge(self::$defaults, $data); $src = $data['src']; if (!empty($src)) { if (substr_count($src, ':')) { unset($data['src']); $substrs = explode(':', $src); if (count($substrs) > 3) { throw new \Exception(sprintf('Statement js of preset "%s" is malformed (%s)!', $this->preset->getName(), $src)); } foreach ($substrs as $substr) { switch ($substr) { case 'min': $data['minified'] = true; $data['packed'] = false; break; case 'pack': $data['minified'] = false; $data['packed'] = true; break; case 'first': $data['position'] = Preset::FILES_STACK_FIRST; break; case 'last': $data['position'] = Preset::FILES_STACK_LAST; break; default: if (is_numeric($substr)) { if (!(-1 <= $substr && 100 >= $substr)) { throw new \Exception(sprintf('A position must be in range [-1;100] for js statement of preset "%s" (got %s)!', $this->preset->getName(), $substr)); } $data['position'] = $substr; } else { if (empty($data['src'])) { $data['src'] = $substr; } else { throw new \Exception(sprintf('Misunderstood information "%s" for js statement of preset "%s"!', $substr, $this->preset->getName())); } } break; } } } } else { throw new \Exception(sprintf('No source file defined for statement js of preset "%s"!', $this->preset->getName())); } $this->transformed_data = $data; if (!\AssetsManager\Loader::isUrl($this->transformed_data['src'])) { $this->transformed_data['src'] = $this->preset->findInPackage($this->transformed_data['src']); } }
/** * @return void * @throws \Exception caught calling required preset */ public function parse() { if (!empty($this->dependencies)) { return; } $this->dependencies = array(); $data = !is_array($this->data) ? array($this->data) : $this->data; foreach ($data as $preset_requires) { try { $preset = Loader::findPreset($preset_requires); } catch (\Exception $e) { throw new \Exception(sprintf('An error occurred trying to load a dependency for preset "%s" : "%s"', $this->preset->getName(), $e->getMessage())); } $this->dependencies[$preset_requires] = $preset; } }