Update 2024-07-20 22:43:12

This commit is contained in:
Robot 2024-07-20 22:43:06 +02:00
parent 6979ada72f
commit b156152e5e
Signed by: Robot
GPG Key ID: 14DECD44E7E1BB95
14 changed files with 285 additions and 290 deletions

View File

@ -87,18 +87,35 @@ final class Grep extends ExtendingGrep implements GrepInterface
$path_guid = $path->guid ?? null; $path_guid = $path->guid ?? null;
if ($path_guid !== null) if ($path_guid !== null)
{ {
// get the Settings meta
if (($meta = $this->contents->metadata($path->organisation, $path->repository, $path->index->{$guid}->path . '/item.json', $branch)) !== null && if (($meta = $this->contents->metadata($path->organisation, $path->repository, $path->index->{$guid}->path . '/item.json', $branch)) !== null &&
isset($meta->sha)) isset($meta->sha))
{ {
if (isset($power->params) && is_object($power->params) && if (isset($power->params) && is_object($power->params) &&
isset($power->params->source) && is_array($power->params->source)) isset($power->params->source) && is_array($power->params->source))
{ {
$power->params->source[$path_guid] = $meta->sha; $power->params->source[$path_guid . '-settings'] = $meta->sha;
} }
else else
{ {
$power->params = (object) [ $power->params = (object) [
'source' => [$path_guid => $meta->sha] 'source' => [$path_guid . '-settings' => $meta->sha]
];
}
}
// get the README meta
if (($meta = $this->contents->metadata($path->organisation, $path->repository, $path->index->{$guid}->path . '/README.md', $branch)) !== null &&
isset($meta->sha))
{
if (isset($power->params) && is_object($power->params) &&
isset($power->params->source) && is_array($power->params->source))
{
$power->params->source[$path_guid . '-readme'] = $meta->sha;
}
else
{
$power->params = (object) [
'source' => [$path_guid . '-readme' => $meta->sha]
]; ];
} }
} }

View File

@ -56,18 +56,35 @@
$path_guid = $path->guid ?? null; $path_guid = $path->guid ?? null;
if ($path_guid !== null) if ($path_guid !== null)
{ {
// get the Settings meta
if (($meta = $this->contents->metadata($path->organisation, $path->repository, $path->index->{$guid}->path . '/item.json', $branch)) !== null && if (($meta = $this->contents->metadata($path->organisation, $path->repository, $path->index->{$guid}->path . '/item.json', $branch)) !== null &&
isset($meta->sha)) isset($meta->sha))
{ {
if (isset($power->params) && is_object($power->params) && if (isset($power->params) && is_object($power->params) &&
isset($power->params->source) && is_array($power->params->source)) isset($power->params->source) && is_array($power->params->source))
{ {
$power->params->source[$path_guid] = $meta->sha; $power->params->source[$path_guid . '-settings'] = $meta->sha;
} }
else else
{ {
$power->params = (object) [ $power->params = (object) [
'source' => [$path_guid => $meta->sha] 'source' => [$path_guid . '-settings' => $meta->sha]
];
}
}
// get the README meta
if (($meta = $this->contents->metadata($path->organisation, $path->repository, $path->index->{$guid}->path . '/README.md', $branch)) !== null &&
isset($meta->sha))
{
if (isset($power->params) && is_object($power->params) &&
isset($power->params->source) && is_array($power->params->source))
{
$power->params->source[$path_guid . '-readme'] = $meta->sha;
}
else
{
$power->params = (object) [
'source' => [$path_guid . '-readme' => $meta->sha]
]; ];
} }
} }

View File

@ -345,7 +345,9 @@ final class JoomlaPower implements PowerInterface
*/ */
private function setNamespaceAndType(string $guid, array $namespace): void private function setNamespaceAndType(string $guid, array $namespace): void
{ {
$this->active[$guid]->namespace = $namespace['namespace']; $this->active[$guid]->namespace = $this->placeholder->update_(
$namespace['namespace']
);
$this->active[$guid]->type = $namespace['type'] ?? 'class'; $this->active[$guid]->type = $namespace['type'] ?? 'class';
} }

View File

@ -309,7 +309,9 @@
*/ */
private function setNamespaceAndType(string $guid, array $namespace): void private function setNamespaceAndType(string $guid, array $namespace): void
{ {
$this->active[$guid]->namespace = $namespace['namespace']; $this->active[$guid]->namespace = $this->placeholder->update_(
$namespace['namespace']
);
$this->active[$guid]->type = $namespace['type'] ?? 'class'; $this->active[$guid]->type = $namespace['type'] ?? 'class';
} }

View File

@ -12,8 +12,8 @@
namespace VDM\Joomla\Componentbuilder\JoomlaPower\Remote; namespace VDM\Joomla\Componentbuilder\JoomlaPower\Remote;
use VDM\Joomla\Interfaces\Data\RemoteGetInterface; use VDM\Joomla\Interfaces\Remote\GetInterface;
use VDM\Joomla\Data\Remote\Get as ExtendingGet; use VDM\Joomla\Abstraction\Remote\Get as ExtendingGet;
/** /**
@ -21,7 +21,7 @@ use VDM\Joomla\Data\Remote\Get as ExtendingGet;
* *
* @since 3.2.0 * @since 3.2.0
*/ */
final class Get extends ExtendingGet implements RemoteGetInterface final class Get extends ExtendingGet implements GetInterface
{ {
/** /**
* Table Name * Table Name

View File

@ -12,8 +12,8 @@
namespace VDM\Joomla\Componentbuilder\Power\Remote; namespace VDM\Joomla\Componentbuilder\Power\Remote;
use VDM\Joomla\Interfaces\Data\RemoteGetInterface; use VDM\Joomla\Interfaces\Remote\GetInterface;
use VDM\Joomla\Data\Remote\Get as ExtendingGet; use VDM\Joomla\Abstraction\Remote\Get as ExtendingGet;
/** /**
@ -21,7 +21,7 @@ use VDM\Joomla\Data\Remote\Get as ExtendingGet;
* *
* @since 3.2.0 * @since 3.2.0
*/ */
final class Get extends ExtendingGet implements RemoteGetInterface final class Get extends ExtendingGet implements GetInterface
{ {
/** /**
* Table Name * Table Name

View File

@ -14,9 +14,12 @@
@startuml @startuml
class Set << (F,LightGreen) >> #RoyalBlue { class Set << (F,LightGreen) >> #RoyalBlue {
# string $table # string $table
# string $area
# array $map # array $map
# updateItem(object $item, object $existing, ...) : bool # updateItem(object $item, object $existing, ...) : bool
# createItem(object $item, object $repo) : void # createItem(object $item, object $repo) : void
# updateItemReadme(object $item, object $existing, ...) : void
# createItemReadme(object $item, object $repo) : void
} }
note right of Set::updateItem note right of Set::updateItem
@ -38,6 +41,25 @@ note right of Set::createItem
return: void return: void
end note end note
note right of Set::updateItemReadme
update an existing item readme
since: 3.2.2
return: void
arguments:
object $item
object $existing
object $repo
end note
note right of Set::createItemReadme
create a new item readme
since: 3.2.2
return: void
end note
@enduml @enduml
``` ```

View File

@ -12,8 +12,8 @@
namespace VDM\Joomla\Componentbuilder\JoomlaPower\Remote; namespace VDM\Joomla\Componentbuilder\JoomlaPower\Remote;
use VDM\Joomla\Interfaces\Data\RemoteSetInterface; use VDM\Joomla\Interfaces\Remote\SetInterface;
use VDM\Joomla\Data\Remote\Set as ExtendingSet; use VDM\Joomla\Abstraction\Remote\Set as ExtendingSet;
/** /**
@ -21,16 +21,32 @@ use VDM\Joomla\Data\Remote\Set as ExtendingSet;
* *
* @since 3.2.2 * @since 3.2.2
*/ */
final class Set extends ExtendingSet implements RemoteSetInterface final class Set extends ExtendingSet implements SetInterface
{ {
/** /**
* Table Name * Table Name
* *
* @var string * @var string
* @since 3.2.1 * @since 3.2.2
*/ */
protected string $table = 'joomla_power'; protected string $table = 'joomla_power';
/**
* Area Name
*
* @var string
* @since 3.2.2
*/
protected string $area = 'Joomla Power';
/**
* Prefix Key
*
* @var string
* @since 3.2.2
*/
protected string $prefix_key = 'Joomla---';
/** /**
* The item map * The item map
* *
@ -45,12 +61,18 @@ final class Set extends ExtendingSet implements RemoteSetInterface
]; ];
/** /**
* The settings file path * The index map
* *
* @var string * @var array
* @since 3.2.2 * @since 3.2.2
*/ */
protected string $settings_path = 'item.json'; protected array $index_map = [
'name' => 'index_map_IndexName',
'settings' => 'index_map_IndexSettingsPath',
'path' => 'index_map_IndexPath',
'jpk' => 'index_map_IndexKey',
'guid' => 'index_map_IndexGUID'
];
/** /**
* update an existing item (if changed) * update an existing item (if changed)
@ -65,7 +87,7 @@ final class Set extends ExtendingSet implements RemoteSetInterface
protected function updateItem(object $item, object $existing, object $repo): bool protected function updateItem(object $item, object $existing, object $repo): bool
{ {
// make sure there was a change // make sure there was a change
$sha = $existing->params->source[$repo->guid] ?? null; $sha = $existing->params->source[$repo->guid . '-settings'] ?? null;
$existing = $this->mapItem($existing); $existing = $this->mapItem($existing);
if ($sha === null || $this->areObjectsEqual($item, $existing)) if ($sha === null || $this->areObjectsEqual($item, $existing))
{ {
@ -105,5 +127,56 @@ final class Set extends ExtendingSet implements RemoteSetInterface
$repo->write_branch // The branch name. $repo->write_branch // The branch name.
); );
} }
/**
* update an existing item readme
*
* @param object $item
* @param object $existing
* @param object $repo
*
* @return void
* @since 3.2.2
*/
protected function updateItemReadme(object $item, object $existing, object $repo): void
{
// make sure there was a change
$sha = $existing->params->source[$repo->guid . '-readme'] ?? null;
if ($sha === null)
{
return;
}
$this->git->update(
$repo->organisation, // The owner name.
$repo->repository, // The repository name.
'src/' . $item->guid . '/README.md', // The file path.
$this->itemReadme->get($item), // The file content.
'Update ' . $item->system_name . ' readme file', // The commit message.
$sha, // The blob SHA of the old file.
$repo->write_branch // The branch name.
);
}
/**
* create a new item readme
*
* @param object $item
* @param object $repo
*
* @return void
* @since 3.2.2
*/
protected function createItemReadme(object $item, object $repo): void
{
$this->git->create(
$repo->organisation, // The owner name.
$repo->repository, // The repository name.
'src/' . $item->guid . '/README.md', // The file path.
$this->itemReadme->get($item), // The file content.
'Create ' . $item->system_name . ' readme file', // The commit message.
$repo->write_branch // The branch name.
);
}
} }

View File

@ -2,10 +2,26 @@
* Table Name * Table Name
* *
* @var string * @var string
* @since 3.2.1 * @since 3.2.2
*/ */
protected string $table = 'joomla_power'; protected string $table = 'joomla_power';
/**
* Area Name
*
* @var string
* @since 3.2.2
*/
protected string $area = 'Joomla Power';
/**
* Prefix Key
*
* @var string
* @since 3.2.2
*/
protected string $prefix_key = 'Joomla---';
/** /**
* The item map * The item map
* *
@ -20,12 +36,18 @@
]; ];
/** /**
* The settings file path * The index map
* *
* @var string * @var array
* @since 3.2.2 * @since 3.2.2
*/ */
protected string $settings_path = 'item.json'; protected array $index_map = [
'name' => 'index_map_IndexName',
'settings' => 'index_map_IndexSettingsPath',
'path' => 'index_map_IndexPath',
'jpk' => 'index_map_IndexKey',
'guid' => 'index_map_IndexGUID'
];
/** /**
* update an existing item (if changed) * update an existing item (if changed)
@ -40,7 +62,7 @@
protected function updateItem(object $item, object $existing, object $repo): bool protected function updateItem(object $item, object $existing, object $repo): bool
{ {
// make sure there was a change // make sure there was a change
$sha = $existing->params->source[$repo->guid] ?? null; $sha = $existing->params->source[$repo->guid . '-settings'] ?? null;
$existing = $this->mapItem($existing); $existing = $this->mapItem($existing);
if ($sha === null || $this->areObjectsEqual($item, $existing)) if ($sha === null || $this->areObjectsEqual($item, $existing))
{ {
@ -80,3 +102,54 @@
$repo->write_branch // The branch name. $repo->write_branch // The branch name.
); );
} }
/**
* update an existing item readme
*
* @param object $item
* @param object $existing
* @param object $repo
*
* @return void
* @since 3.2.2
*/
protected function updateItemReadme(object $item, object $existing, object $repo): void
{
// make sure there was a change
$sha = $existing->params->source[$repo->guid . '-readme'] ?? null;
if ($sha === null)
{
return;
}
$this->git->update(
$repo->organisation, // The owner name.
$repo->repository, // The repository name.
'src/' . $item->guid . '/README.md', // The file path.
$this->itemReadme->get($item), // The file content.
'Update ' . $item->system_name . ' readme file', // The commit message.
$sha, // The blob SHA of the old file.
$repo->write_branch // The branch name.
);
}
/**
* create a new item readme
*
* @param object $item
* @param object $repo
*
* @return void
* @since 3.2.2
*/
protected function createItemReadme(object $item, object $repo): void
{
$this->git->create(
$repo->organisation, // The owner name.
$repo->repository, // The repository name.
'src/' . $item->guid . '/README.md', // The file path.
$this->itemReadme->get($item), // The file content.
'Create ' . $item->system_name . ' readme file', // The commit message.
$repo->write_branch // The branch name.
);
}

View File

@ -16,16 +16,12 @@ class Main << (F,LightGreen) >> #RoyalBlue {
- readmeBuilder($items) : string - readmeBuilder($items) : string
- readmeModel(array $classes) : string - readmeModel(array $classes) : string
- generateIndex(array $classes) : string - generateIndex(array $classes) : string
- defineTypeOrder() : array - sortClasses(array $classes) : void
- sortClasses(array $classes, array $typeOrder) : void
- compareNamespace(array $a, array $b) : int
- compareType(array $a, array $b, ...) : int
- compareName(array $a, array $b) : int - compareName(array $a, array $b) : int
- indexLinkPower(array $power) : string - indexLinkPower(array $power) : string
- linkPowerRepo(array $power) : string - linkPowerRepo(array $power) : string
- linkPowerCode(array $power) : string
- linkPowerSettings(array $power) : string - linkPowerSettings(array $power) : string
- linkPowerSPK(array $power) : string - linkPowerJPK(array $power) : string
} }
note right of Main::get note right of Main::get
@ -55,67 +51,34 @@ note left of Main::generateIndex
return: string return: string
end note end note
note right of Main::defineTypeOrder note right of Main::sortClasses
Define the order of types for sorting purposes
since: 3.2.0
return: array
end note
note left of Main::sortClasses
Sort the flattened array using a single sorting function Sort the flattened array using a single sorting function
since: 3.2.0 since: 3.2.0
return: void return: void
end note end note
note right of Main::compareNamespace note left of Main::compareName
Compare the namespace of two classes
since: 3.2.0
return: int
end note
note left of Main::compareType
Compare the type of two classes
since: 3.2.0
return: int
arguments:
array $a
array $b
array $typeOrder
end note
note right of Main::compareName
Compare the name of two classes Compare the name of two classes
since: 3.2.0 since: 3.2.0
return: int return: int
end note end note
note left of Main::indexLinkPower note right of Main::indexLinkPower
Build the Link to the power in this repository Build the Link to the power in this repository
since: 3.2.0 since: 3.2.0
return: string return: string
end note end note
note right of Main::linkPowerRepo note left of Main::linkPowerRepo
Build the Link to the power in this repository Build the Link to the power in this repository
since: 3.2.0 since: 3.2.0
return: string return: string
end note end note
note left of Main::linkPowerCode
Build the Link to the power settings in this repository
since: 3.2.0
return: string
end note
note right of Main::linkPowerSettings note right of Main::linkPowerSettings
Build the Link to the power settings in this repository Build the Link to the power settings in this repository
@ -123,8 +86,8 @@ note right of Main::linkPowerSettings
return: string return: string
end note end note
note left of Main::linkPowerSPK note left of Main::linkPowerJPK
Get the SuperPowerKey (SPK) Get the JoomlaPowerKey (JPK)
since: 3.2.0 since: 3.2.0
return: string return: string

View File

@ -48,7 +48,12 @@ final class Main implements MainInterface
```"]; ```"];
// default description of super powers // default description of super powers
$readme[] = "\n### What is JCB Joomla Powers?\nThe Joomla Component Builder (JCB) Joomla Power features are designed to enhance JCB's functionality and streamline the development process. These Joomla Powers enable developers to efficiently manage and share their custom powers across multiple JCB instances through repositories hosted on [https://git.vdm.dev/[username]/[repository-name]](https://git.vdm.dev). JCB Super Powers are managed using a combination of layers, events, tasks, methods, switches, and algorithms, which work together to provide powerful customization and extensibility options. More details on JCB Super Powers can be found in the [Super Powers Documentation](https://git.vdm.dev/joomla/super-powers/wiki).\n\nIn summary, JCB Super Powers offer a flexible and efficient way to manage and share functionalities between JCB instances. By utilizing a sophisticated system of layers, events, tasks, methods, switches, and algorithms, developers can seamlessly integrate JCB core powers and their custom powers. For more information on how to work with JCB Super Powers, refer to the [Super Powers User Guide](https://git.vdm.dev/joomla/super-powers/wiki).\n\n### What can I find here?\nThis repository contains an index (see below) of all the approved powers within the JCB GUI. During the compilation of a component, these powers are automatically added to the repository, ensuring a well-organized and accessible collection of functionalities.\n"; $readme[] = "\n### What is JCB Joomla Powers?\nThe Joomla Component Builder (JCB) Joomla Power features are designed to enhance JCB's functionality and streamline the development process. The Joomla powers enable developers to effectively leverage Joomla classes in their custom code without needing to manually add the `use` statements for those classes to the file headers. JCB automatically updates these `use` statements in the necessary headers when it detects a Joomla power key in the custom code.\n
\n
By doing this, we can control the `use` statements dynamically from a central point. This is particularly beneficial when transitioning from Joomla 3 to Joomla 4, as it allows us to seamlessly switch from certain classes to their respective Joomla framework classes and vice versa. Maintaining these `use` statements in the Joomla Power area ensures that JCB handles the inclusion and updating of class names to prevent conflicts with other classes.\n
\n
This approach is convenient and allows developers to focus on the bespoke parts of their application logic without worrying about class declarations.\n
\nThis repository contains an index (see below) of all the Joomla! Powers within the JCB core GUI. These Joomla! Powers are automatically added to the repository by our maintainers, ensuring a well-organized and accessible collection of Joomla Classes are maintained.\n";
// get the readme body // get the readme body
$readme[] = $this->readmeBuilder($items); $readme[] = $this->readmeBuilder($items);
@ -93,8 +98,6 @@ final class Main implements MainInterface
{ {
// add to the sort bucket // add to the sort bucket
$classes[] = [ $classes[] = [
'namespace' => $power['namespace'],
'type' => $power['type'],
'name' => $power['name'], 'name' => $power['name'],
'link' => $this->indexLinkPower($power) 'link' => $this->indexLinkPower($power)
]; ];
@ -113,7 +116,7 @@ final class Main implements MainInterface
*/ */
private function readmeModel(array &$classes): string private function readmeModel(array &$classes): string
{ {
$this->sortClasses($classes, $this->defineTypeOrder()); $this->sortClasses($classes);
return $this->generateIndex($classes); return $this->generateIndex($classes);
} }
@ -127,108 +130,34 @@ final class Main implements MainInterface
*/ */
private function generateIndex(array &$classes): string private function generateIndex(array &$classes): string
{ {
$result = "# Index of powers\n"; $result = "# Index of Joomla! Powers\n";
$current_namespace = null;
foreach ($classes as $class) foreach ($classes as $class)
{ {
if ($class['namespace'] !== $current_namespace)
{
$current_namespace = $class['namespace'];
$result .= "\n- **Namespace**: [{$current_namespace}](#" .
strtolower(str_replace('\\', '-', $current_namespace)) . ")\n";
}
// Add the class details // Add the class details
$result .= "\n - " . $class['link']; $result .= "\n - " . $class['link'];
} }
return $result; $result .= "\n> remember to replace the `---` with `___` in the JPK to activate that Joomla! Power in your code";
}
/**
* Define the order of types for sorting purposes return $result;
*
* @return array The order of types
* @since 3.2.0
*/
private function defineTypeOrder(): array
{
return [
'interface' => 1,
'abstract' => 2,
'abstract class' => 2,
'final' => 3,
'final class' => 3,
'class' => 4,
'trait' => 5
];
} }
/** /**
* Sort the flattened array using a single sorting function * Sort the flattened array using a single sorting function
* *
* @param array $classes The classes to sort * @param array $classes The classes to sort
* @param array $typeOrder The order of types *
* @since 3.2.0 * @since 3.2.0
*/ */
private function sortClasses(array &$classes, array $typeOrder): void private function sortClasses(array &$classes): void
{ {
usort($classes, function ($a, $b) use ($typeOrder) { usort($classes, function ($a, $b) {
$namespaceDiff = $this->compareNamespace($a, $b);
if ($namespaceDiff !== 0)
{
return $namespaceDiff;
}
$typeDiff = $this->compareType($a, $b, $typeOrder);
if ($typeDiff !== 0)
{
return $typeDiff;
}
return $this->compareName($a, $b); return $this->compareName($a, $b);
}); });
} }
/**
* Compare the namespace of two classes
*
* @param array $a First class
* @param array $b Second class
*
* @return int Comparison result
* @since 3.2.0
*/
private function compareNamespace(array $a, array $b): int
{
$namespaceDepthDiff = substr_count($a['namespace'], '\\') - substr_count($b['namespace'], '\\');
if ($namespaceDepthDiff === 0)
{
return strcmp($a['namespace'], $b['namespace']);
}
return $namespaceDepthDiff;
}
/**
* Compare the type of two classes
*
* @param array $a First class
* @param array $b Second class
* @param array $typeOrder The order of types
*
* @return int Comparison result
* @since 3.2.0
*/
private function compareType(array $a, array $b, array $typeOrder): int
{
return $typeOrder[$a['type']] <=> $typeOrder[$b['type']];
}
/** /**
* Compare the name of two classes * Compare the name of two classes
* *
@ -253,13 +182,11 @@ final class Main implements MainInterface
*/ */
private function indexLinkPower(array &$power): string private function indexLinkPower(array &$power): string
{ {
$type = $power['type'] ?? 'error';
$name = $power['name'] ?? 'error'; $name = $power['name'] ?? 'error';
return '**' . $type . ' ' . $name . "** | " return '**' . $name . "** | "
. $this->linkPowerRepo($power) . ' | ' . $this->linkPowerRepo($power) . ' | '
. $this->linkPowerCode($power) . ' | ' . $this->linkPowerSettings($power) . ' | JPK: `'
. $this->linkPowerSettings($power) . ' | ' . $this->linkPowerJPK($power) .'`';
. $this->linkPowerSPK($power);
} }
/** /**
@ -276,20 +203,6 @@ final class Main implements MainInterface
return '[Details](' . $path . ')'; return '[Details](' . $path . ')';
} }
/**
* Build the Link to the power settings in this repository
*
* @param array $power The power details.
*
* @return string
* @since 3.2.0
*/
private function linkPowerCode(array &$power): string
{
$code = $power['code'] ?? 'error';
return '[Code](' . $code . ')';
}
/** /**
* Build the Link to the power settings in this repository * Build the Link to the power settings in this repository
* *
@ -305,17 +218,17 @@ final class Main implements MainInterface
} }
/** /**
* Get the SuperPowerKey (SPK) * Get the JoomlaPowerKey (JPK)
* *
* @param array $power The power details. * @param array $power The power details.
* *
* @return string * @return string
* @since 3.2.0 * @since 3.2.0
*/ */
private function linkPowerSPK(array &$power): string private function linkPowerJPK(array &$power): string
{ {
$spk = $power['spk'] ?? 'error'; $jpk = $power['jpk'] ?? 'error';
return $spk; return $jpk;
} }
} }

View File

@ -25,7 +25,12 @@
```"]; ```"];
// default description of super powers // default description of super powers
$readme[] = "\n### What is JCB Joomla Powers?\nThe Joomla Component Builder (JCB) Joomla Power features are designed to enhance JCB's functionality and streamline the development process. These Joomla Powers enable developers to efficiently manage and share their custom powers across multiple JCB instances through repositories hosted on [https://git.vdm.dev/[username]/[repository-name]](https://git.vdm.dev). JCB Super Powers are managed using a combination of layers, events, tasks, methods, switches, and algorithms, which work together to provide powerful customization and extensibility options. More details on JCB Super Powers can be found in the [Super Powers Documentation](https://git.vdm.dev/joomla/super-powers/wiki).\n\nIn summary, JCB Super Powers offer a flexible and efficient way to manage and share functionalities between JCB instances. By utilizing a sophisticated system of layers, events, tasks, methods, switches, and algorithms, developers can seamlessly integrate JCB core powers and their custom powers. For more information on how to work with JCB Super Powers, refer to the [Super Powers User Guide](https://git.vdm.dev/joomla/super-powers/wiki).\n\n### What can I find here?\nThis repository contains an index (see below) of all the approved powers within the JCB GUI. During the compilation of a component, these powers are automatically added to the repository, ensuring a well-organized and accessible collection of functionalities.\n"; $readme[] = "\n### What is JCB Joomla Powers?\nThe Joomla Component Builder (JCB) Joomla Power features are designed to enhance JCB's functionality and streamline the development process. The Joomla powers enable developers to effectively leverage Joomla classes in their custom code without needing to manually add the `use` statements for those classes to the file headers. JCB automatically updates these `use` statements in the necessary headers when it detects a Joomla power key in the custom code.\n
\n
By doing this, we can control the `use` statements dynamically from a central point. This is particularly beneficial when transitioning from Joomla 3 to Joomla 4, as it allows us to seamlessly switch from certain classes to their respective Joomla framework classes and vice versa. Maintaining these `use` statements in the Joomla Power area ensures that JCB handles the inclusion and updating of class names to prevent conflicts with other classes.\n
\n
This approach is convenient and allows developers to focus on the bespoke parts of their application logic without worrying about class declarations.\n
\nThis repository contains an index (see below) of all the Joomla! Powers within the JCB core GUI. These Joomla! Powers are automatically added to the repository by our maintainers, ensuring a well-organized and accessible collection of Joomla Classes are maintained.\n";
// get the readme body // get the readme body
$readme[] = $this->readmeBuilder($items); $readme[] = $this->readmeBuilder($items);
@ -70,8 +75,6 @@
{ {
// add to the sort bucket // add to the sort bucket
$classes[] = [ $classes[] = [
'namespace' => $power['namespace'],
'type' => $power['type'],
'name' => $power['name'], 'name' => $power['name'],
'link' => $this->indexLinkPower($power) 'link' => $this->indexLinkPower($power)
]; ];
@ -90,7 +93,7 @@
*/ */
private function readmeModel(array &$classes): string private function readmeModel(array &$classes): string
{ {
$this->sortClasses($classes, $this->defineTypeOrder()); $this->sortClasses($classes);
return $this->generateIndex($classes); return $this->generateIndex($classes);
} }
@ -104,108 +107,34 @@
*/ */
private function generateIndex(array &$classes): string private function generateIndex(array &$classes): string
{ {
$result = "# Index of powers\n"; $result = "# Index of Joomla! Powers\n";
$current_namespace = null;
foreach ($classes as $class) foreach ($classes as $class)
{ {
if ($class['namespace'] !== $current_namespace)
{
$current_namespace = $class['namespace'];
$result .= "\n- **Namespace**: [{$current_namespace}](#" .
strtolower(str_replace('\\', '-', $current_namespace)) . ")\n";
}
// Add the class details // Add the class details
$result .= "\n - " . $class['link']; $result .= "\n - " . $class['link'];
} }
return $result; $result .= "\n> remember to replace the `---` with `___` in the JPK to activate that Joomla! Power in your code";
}
/**
* Define the order of types for sorting purposes return $result;
*
* @return array The order of types
* @since 3.2.0
*/
private function defineTypeOrder(): array
{
return [
'interface' => 1,
'abstract' => 2,
'abstract class' => 2,
'final' => 3,
'final class' => 3,
'class' => 4,
'trait' => 5
];
} }
/** /**
* Sort the flattened array using a single sorting function * Sort the flattened array using a single sorting function
* *
* @param array $classes The classes to sort * @param array $classes The classes to sort
* @param array $typeOrder The order of types *
* @since 3.2.0 * @since 3.2.0
*/ */
private function sortClasses(array &$classes, array $typeOrder): void private function sortClasses(array &$classes): void
{ {
usort($classes, function ($a, $b) use ($typeOrder) { usort($classes, function ($a, $b) {
$namespaceDiff = $this->compareNamespace($a, $b);
if ($namespaceDiff !== 0)
{
return $namespaceDiff;
}
$typeDiff = $this->compareType($a, $b, $typeOrder);
if ($typeDiff !== 0)
{
return $typeDiff;
}
return $this->compareName($a, $b); return $this->compareName($a, $b);
}); });
} }
/**
* Compare the namespace of two classes
*
* @param array $a First class
* @param array $b Second class
*
* @return int Comparison result
* @since 3.2.0
*/
private function compareNamespace(array $a, array $b): int
{
$namespaceDepthDiff = substr_count($a['namespace'], '\\') - substr_count($b['namespace'], '\\');
if ($namespaceDepthDiff === 0)
{
return strcmp($a['namespace'], $b['namespace']);
}
return $namespaceDepthDiff;
}
/**
* Compare the type of two classes
*
* @param array $a First class
* @param array $b Second class
* @param array $typeOrder The order of types
*
* @return int Comparison result
* @since 3.2.0
*/
private function compareType(array $a, array $b, array $typeOrder): int
{
return $typeOrder[$a['type']] <=> $typeOrder[$b['type']];
}
/** /**
* Compare the name of two classes * Compare the name of two classes
* *
@ -230,13 +159,11 @@
*/ */
private function indexLinkPower(array &$power): string private function indexLinkPower(array &$power): string
{ {
$type = $power['type'] ?? 'error';
$name = $power['name'] ?? 'error'; $name = $power['name'] ?? 'error';
return '**' . $type . ' ' . $name . "** | " return '**' . $name . "** | "
. $this->linkPowerRepo($power) . ' | ' . $this->linkPowerRepo($power) . ' | '
. $this->linkPowerCode($power) . ' | ' . $this->linkPowerSettings($power) . ' | JPK: `'
. $this->linkPowerSettings($power) . ' | ' . $this->linkPowerJPK($power) .'`';
. $this->linkPowerSPK($power);
} }
/** /**
@ -253,20 +180,6 @@
return '[Details](' . $path . ')'; return '[Details](' . $path . ')';
} }
/**
* Build the Link to the power settings in this repository
*
* @param array $power The power details.
*
* @return string
* @since 3.2.0
*/
private function linkPowerCode(array &$power): string
{
$code = $power['code'] ?? 'error';
return '[Code](' . $code . ')';
}
/** /**
* Build the Link to the power settings in this repository * Build the Link to the power settings in this repository
* *
@ -282,15 +195,15 @@
} }
/** /**
* Get the SuperPowerKey (SPK) * Get the JoomlaPowerKey (JPK)
* *
* @param array $power The power details. * @param array $power The power details.
* *
* @return string * @return string
* @since 3.2.0 * @since 3.2.0
*/ */
private function linkPowerSPK(array &$power): string private function linkPowerJPK(array &$power): string
{ {
$spk = $power['spk'] ?? 'error'; $jpk = $power['jpk'] ?? 'error';
return $spk; return $jpk;
} }

View File

@ -346,7 +346,7 @@ class Power implements PowerInterface
if ($this->isGuidValid($guid)) if ($this->isGuidValid($guid))
{ {
// now we search for it via the super power paths // now we search for it via the super power paths
if (empty($this->retry[$guid]) && $this->superpower->load($guid, ['remote', 'local'])) if (empty($this->retry[$guid]) && $this->superpower->item($guid, ['remote', 'local']))
{ {
// we found it and it was loaded into the database // we found it and it was loaded into the database
unset($this->state[$guid]); unset($this->state[$guid]);

View File

@ -308,7 +308,7 @@
if ($this->isGuidValid($guid)) if ($this->isGuidValid($guid))
{ {
// now we search for it via the super power paths // now we search for it via the super power paths
if (empty($this->retry[$guid]) && $this->superpower->load($guid, ['remote', 'local'])) if (empty($this->retry[$guid]) && $this->superpower->item($guid, ['remote', 'local']))
{ {
// we found it and it was loaded into the database // we found it and it was loaded into the database
unset($this->state[$guid]); unset($this->state[$guid]);