Created
January 21, 2024 15:22
-
-
Save korenevskiy/915e994f79ffe4ab075471b2794e3f34 to your computer and use it in GitHub Desktop.
Class Reg heir Registry (Joomla CMS framework). This class has magic methods for use simple properties
This file contains hidden or 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
<?php | |
if(class_exists('Reg') == false){ | |
/** | |
* Class Reg heir Registry | |
* This class has magic methods for simple use properties | |
* Example: $reg->prop1; $reg->prop2 = 123; | |
*/ | |
class Reg extends \Joomla\Registry\Registry{ | |
function __get($nameProperty) { | |
return $this->get($nameProperty, ''); | |
} | |
function __set($nameProperty, $value = null) { | |
$this->set($nameProperty, $value); | |
} | |
function __isset($nameProperty) { | |
return $this->exists($nameProperty); | |
} | |
/** | |
* Get or Set value in array in property object Registry | |
* how get item: $o->ArrayItem('propArray',$index); | |
* how set item: $o->ArrayItem('propArray',$index, $value); | |
* how add item: $o->ArrayItem('propArray', null, $value); | |
* @param string $nameProperty name property Array | |
* @param int|string $index index in property Array | |
* @param mixed $value new value in property Array | |
* @return mixed | |
*/ | |
function ArrayItem($nameProperty, $index = null, $value = null){ | |
if(!isset($this->data->$nameProperty)) | |
$this->data->$nameProperty = []; | |
if($index === null && $value === null) | |
return $this->data->$nameProperty; | |
$old = $this->data->$nameProperty[$index] ?? null; | |
if($value === null) | |
return $old; | |
if($index === '' || $index === null) | |
$this->data->$nameProperty[] = $value; | |
else | |
$this->data->$nameProperty[$index] = $value; | |
return $old; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment