-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b99bcb6
Showing
11 changed files
with
749 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/.github export-ignore | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.releaserc export-ignore | ||
/composer.lock export-ignore |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: | ||
- master | ||
- develop | ||
- alpha | ||
- beta | ||
|
||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
token: ${{ secrets.OBLAKBOT_PAT }} | ||
- name: Import GPG key | ||
uses: crazy-max/ghaction-import-gpg@v6 | ||
id: gpg | ||
with: | ||
gpg_private_key: ${{ secrets.OBLAKBOT_GPG_KEY }} | ||
passphrase: ${{ secrets.OBLAKBOT_GPG_PASS }} | ||
git_config_global: true | ||
git_user_signingkey: true | ||
git_commit_gpgsign: true | ||
- name: Semantic Release | ||
uses: cycjimmy/semantic-release-action@v4 | ||
with: | ||
extra_plugins: | | ||
@semantic-release/github | ||
@semantic-release/exec | ||
env: | ||
GIT_AUTHOR_NAME: ${{ steps.gpg.outputs.name}} | ||
GIT_AUTHOR_EMAIL: ${{ steps.gpg.outputs.email}} | ||
GIT_COMMITTER_NAME: ${{ steps.gpg.outputs.name}} | ||
GIT_COMMITTER_EMAIL: ${{ steps.gpg.outputs.email}} | ||
GITHUB_TOKEN: ${{ secrets.OBLAKBOT_PAT }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
composer.lock | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"branches": [ | ||
"master" | ||
], | ||
"plugins": [ | ||
"@semantic-release/commit-analyzer", | ||
"@semantic-release/release-notes-generator", | ||
[ | ||
"@semantic-release/exec", | ||
{ | ||
"prepareCmd": "zip -r '/tmp/release.zip' *.php README.md" | ||
} | ||
], | ||
[ | ||
"@semantic-release/github", | ||
{ | ||
"assets": [ | ||
{ | ||
"path": "/tmp/release.zip", | ||
"name": "xwp-helper-traits-${nextRelease.version}.zip", | ||
"label": "xWP Helper Traits v${nextRelease.version}" | ||
} | ||
] | ||
} | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
<?php //phpcs:disable WordPress.NamingConventions | ||
namespace XWP\Helper\Traits; | ||
|
||
/** | ||
* Allows a class to be accessed as an array. | ||
* | ||
* @template TKey | ||
* @template TValue | ||
* @template-covariant TValue | ||
* @template-implements \ArrayAccess<TKey, TValue>, \Iterator<TKey, TValue>, \Countable, \JsonSerializable | ||
* @phpstan-require-implements \ArrayAccess<TKey, TValue>, \Iterator<TKey, TValue>, \Countable, \JsonSerializable | ||
*/ | ||
trait Array_Access { | ||
/** | ||
* Traversible data array. | ||
* | ||
* @var array<int|string, mixed> | ||
*/ | ||
protected array $arr_data = array(); | ||
|
||
/** | ||
* Array of keys for the data array. | ||
* | ||
* @var array<string|int> | ||
*/ | ||
protected array $arr_data_keys = array(); | ||
|
||
/** | ||
* Current iterator position. | ||
* | ||
* @var int | ||
*/ | ||
protected int $arr_position = 0; | ||
|
||
/** | ||
* Counts the number of items in the data array. | ||
* | ||
* Used by the Countable interface. | ||
* | ||
* @return int<0, max> | ||
*/ | ||
public function count(): int { | ||
return \count( $this->arr_data_keys ); | ||
} | ||
|
||
/** | ||
* Returns the current item in the data array. | ||
* | ||
* Used by the Iterator interface. | ||
* | ||
* @return TValue Can return any type. | ||
*/ | ||
public function current(): mixed { | ||
return $this->arr_data[ $this->arr_data_keys[ $this->arr_position ] ]; | ||
} | ||
|
||
/** | ||
* Returns the key of the current item in the data array. | ||
* | ||
* Used by the Iterator interface. | ||
* | ||
* @return TKey|null TKey on success, or null on failure. | ||
*/ | ||
public function key(): mixed { | ||
return $this->arr_data_keys[ $this->arr_position ]; | ||
} | ||
|
||
/** | ||
* Moves the iterator to the next item in the data array. | ||
* | ||
* Used by the Iterator interface. | ||
* | ||
* @return void | ||
*/ | ||
public function next(): void { | ||
++$this->arr_position; | ||
} | ||
|
||
/** | ||
* Resets the iterator to the first item in the data array. | ||
* | ||
* Used by the Iterator interface. | ||
* | ||
* @return void | ||
*/ | ||
public function rewind(): void { | ||
$this->arr_position = 0; | ||
} | ||
|
||
/** | ||
* Checks if the current iterator position is valid. | ||
* | ||
* Used by the Iterator interface. | ||
* | ||
* @return bool | ||
*/ | ||
public function valid(): bool { | ||
return isset( $this->arr_data_keys[ $this->arr_position ] ); | ||
} | ||
|
||
/** | ||
* Assigns a value to the specified offset. | ||
* | ||
* Used by the ArrayAccess interface. | ||
* | ||
* @param TKey $offset The offset to assign the value to. | ||
* @param TValue $value The value to set. | ||
* @return void | ||
*/ | ||
public function offsetSet( $offset, $value ): void { | ||
if ( \is_null( $offset ) ) { | ||
$this->arr_data[] = $value; | ||
$this->arr_data_keys[] = \array_key_last( $this->arr_data ); | ||
|
||
return; | ||
} | ||
|
||
$this->arr_data[ $offset ] = $value; | ||
|
||
if ( \in_array( $offset, $this->arr_data_keys, true ) ) { | ||
return; | ||
} | ||
|
||
$this->arr_data_keys[] = $offset; | ||
} | ||
|
||
/** | ||
* Returns the value at the specified offset. | ||
* | ||
* Used by the ArrayAccess interface. | ||
* | ||
* @param TKey $offset The offset to retrieve. | ||
* @return TValue Can return any type. | ||
*/ | ||
public function &offsetGet( $offset ): mixed { | ||
$this->arr_data[ $offset ] ??= array(); | ||
|
||
return $this->arr_data[ $offset ]; | ||
} | ||
|
||
/** | ||
* Checks if the specified offset exists. | ||
* | ||
* Used by the ArrayAccess interface. | ||
* | ||
* @param TKey $offset The offset to check. | ||
* @return bool | ||
*/ | ||
public function offsetExists( $offset ): bool { | ||
return isset( $this->arr_data[ $offset ] ); | ||
} | ||
|
||
/** | ||
* Unsets the value at the specified offset. | ||
* | ||
* Used by the ArrayAccess interface. | ||
* | ||
* @param TKey $offset The offset to unset. | ||
* @return void | ||
*/ | ||
public function offsetUnset( $offset ): void { | ||
unset( $this->arr_data[ $offset ] ); | ||
unset( $this->arr_data_keys[ \array_search( $offset, $this->arr_data_keys, true ) ] ); | ||
|
||
$this->arr_data_keys = \array_values( $this->arr_data_keys ); | ||
} | ||
|
||
/** | ||
* Returns the data array as an array. | ||
* | ||
* @return array<TKey, TValue> | ||
*/ | ||
public function __debugInfo() { | ||
return $this->arr_data; | ||
} | ||
|
||
/** | ||
* Serialize the data array. | ||
* | ||
* @return array<TKey, TValue> | ||
*/ | ||
public function __serialize() { | ||
return $this->arr_data; | ||
} | ||
|
||
/** | ||
* Unserialize the data array. | ||
* | ||
* @param array<TKey, TValue> $data The data to unserialize. | ||
* @return void | ||
*/ | ||
public function __unserialize($data) { | ||
foreach ($data as $k => $v) { | ||
$this[$k] = $v; | ||
} | ||
} | ||
|
||
/** | ||
* Json Serialize the data array. | ||
* | ||
* @return array<TKey, TValue> | ||
*/ | ||
public function jsonSerialize(): mixed { | ||
return $this->arr_data; | ||
} | ||
|
||
/** | ||
* Set the state of the object. | ||
* | ||
* @param array<TKey, TValue> $data The data to set. | ||
* @return static | ||
*/ | ||
public static function __set_state( array $data): static { | ||
$obj = new static(); | ||
|
||
foreach ($data['arr_data'] as $k => $v) { | ||
$obj[$k] = $v; | ||
} | ||
|
||
return $obj; | ||
} | ||
} |
Oops, something went wrong.