public function load()
{
if ($this->loaded) {
return $this;
}
if (static::$sorter === null || !static::$sorter instanceof Sorter) {
static::$sorter = new Sorter();
}
$prev = null;
foreach ((array) $this->files as $file) {
// add file to output list
static::$fileList = array_add(static::$fileList, $this->location, []);
list($element, $position) = explode('.', $this->location);
static::$fileList[$element][$position][$file] = $this;
$added = false;
// add before
if (!empty($this->befores)) {
$added = true;
static::$sorter->add($file, Sorter::BEFORE, $this->befores);
}
if ($prev !== null) {
static::$sorter->add($file, Sorter::BEFORE, $prev);
}
// remember prev file
$prev = $file;
// add after
if (!empty($this->afters)) {
$added = true;
static::$sorter->add($file, Sorter::AFTER, $this->afters);
}
// add file to sorter
if (!$added) {
static::$sorter->add($file);
}
}
// remove files from 'unloaded' list
static::$unloaded = array_diff(static::$unloaded, (array) $this->files);
// set loaded flag
$this->loaded = true;
return $this;
}