Skip to content

Commit

Permalink
Merge pull request #444 from modmore/new-package-model-structure
Browse files Browse the repository at this point in the history
Accept packages with new structure using xpdo3
  • Loading branch information
muzzwood authored Dec 11, 2023
2 parents b0451a6 + 2b687a9 commit 8954d7f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 44 deletions.
32 changes: 32 additions & 0 deletions src/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,36 @@ public function getPartitionCriteria($partition)

return null;
}

/**
* Loads a package (xPDO Model) by its name
*
* @param $package
* @param array $options
*/
public function getPackage($package, array $options = []): void
{
// Check if this package is specified to use the newer xPDO v3 namespaced model structure
$xpdo3 = !empty($options['namespace']);

$path = (isset($options['package_path'])) ? $options['package_path'] : false;
if (!$path) {
$path = $this->modx->getOption($package . '.core_path', null, $this->modx->getOption('core_path') . 'components/' . $package . '/', true);
$path .= $xpdo3 ? 'src/' : 'model/';
}

// If the package uses the xPDO v3 namespaced model structure, add package with namespace and model options.
if ($xpdo3) {
$this->modx->addPackage($options['model'], $path, null, $options['namespace'] . '\\');
return;
}

// Load packages using the older model structure
if (isset($options['service'])) {
$path .= $package . '/';
$this->modx->getService($package, $options['service'], $path);
} else {
$this->modx->addPackage($package, $path);
}
}
}
22 changes: 0 additions & 22 deletions src/Command/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,28 +196,6 @@ public function buildContent($folder, $type)
$this->resolveConflicts($folder, $type, true);
}

/**
* Loads a package (xPDO Model) by its name
*
* @param $package
* @param array $options
*/
public function getPackage($package, array $options = array())
{
$path = (isset($options['package_path'])) ? $options['package_path'] : false;
if (!$path) {
$path = $this->modx->getOption($package . '.core_path', null, $this->modx->getOption('core_path') . 'components/' . $package . '/', true);
$path .= 'model/';
}

if (isset($options['service'])) {
$path .= $package . '/';
$this->modx->getService($package, $options['service'], $path);
} else {
$this->modx->addPackage($package, $path);
}
}

/**
* Loops over resource files to create the resources.
*
Expand Down
22 changes: 0 additions & 22 deletions src/Command/ExtractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,28 +379,6 @@ public function generate($object, array $options = array())
return $out;
}

/**
* Loads a package (xPDO Model) by its name
*
* @param $package
* @param array $options
*/
public function getPackage($package, array $options = array())
{
$path = (isset($options['package_path'])) ? $options['package_path'] : false;
if (!$path) {
$path = $this->modx->getOption($package . '.core_path', null, $this->modx->getOption('core_path') . 'components/' . $package . '/', true);
$path .= 'model/';
}

if (isset($options['service'])) {
$path .= $package . '/';
$this->modx->getService($package, $options['service'], $path);
} else {
$this->modx->addPackage($package, $path);
}
}

/**
* Loops over a folder to get all the files in it. Uses for cleaning up old files.
*
Expand Down

0 comments on commit 8954d7f

Please sign in to comment.