A super easy PHP Framework for web development!
				https://github.com/exacti/phacil-framework
			
			
		
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					124 lines
				
				2.6 KiB
			
		
		
			
		
	
	
					124 lines
				
				2.6 KiB
			| 
								 
											2 years ago
										 
									 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * Copyright © 2023 ExacTI Technology Solutions. All rights reserved.
							 | 
						||
| 
								 | 
							
								 * GPLv3 General License.
							 | 
						||
| 
								 | 
							
								 * https://exacti.com.br
							 | 
						||
| 
								 | 
							
								 * Phacil PHP Framework - https://github.com/exacti/phacil-framework
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								namespace Phacil\Framework\Databases\Object;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								use Phacil\Framework\Databases\Object\ItemInterface as ObjectInterface;
							 | 
						||
| 
								 | 
							
								use Traversable;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
								if (version_compare(phpversion(), "7.1.0", ">=")) {
							 | 
						||
| 
								 | 
							
									class ComplementItem extends \Phacil\Framework\Databases\Object\Aux\ComplementItem
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								} else {
							 | 
						||
| 
								 | 
							
									class ComplementItem extends \Phacil\Framework\Databases\Object\Aux\ComplementItemLegacy
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * {@inheritdoc}
							 | 
						||
| 
								 | 
							
								 * @method mixed getValue(string $field) 
							 | 
						||
| 
								 | 
							
								 * @method mixed getValues(string field, ...) 
							 | 
						||
| 
								 | 
							
								 * @package Phacil\Framework\Databases\Object
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
								class Item extends ComplementItem implements ObjectInterface {
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
									/**
							 | 
						||
| 
								 | 
							
									 * 
							 | 
						||
| 
								 | 
							
									 * @param mixed $data 
							 | 
						||
| 
								 | 
							
									 * @return $this 
							 | 
						||
| 
								 | 
							
									 */
							 | 
						||
| 
								 | 
							
									function __construct($data = null) {
							 | 
						||
| 
								 | 
							
										$this->__data = $data;
							 | 
						||
| 
								 | 
							
										return $this;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									/**
							 | 
						||
| 
								 | 
							
									 * 
							 | 
						||
| 
								 | 
							
									 * @param array $data 
							 | 
						||
| 
								 | 
							
									 * @return $this 
							 | 
						||
| 
								 | 
							
									 */
							 | 
						||
| 
								 | 
							
									public function setData(array $data) {
							 | 
						||
| 
								 | 
							
										$this->__data = $data;
							 | 
						||
| 
								 | 
							
										//$this->__data = new SplObjectStorage();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										/* foreach($data as $key => $val) {
							 | 
						||
| 
								 | 
							
											$keyForA = new self([$key => $val]);
							 | 
						||
| 
								 | 
							
											$this->__data[$keyForA] = [$key => $val];
							 | 
						||
| 
								 | 
							
										} */
							 | 
						||
| 
								 | 
							
										
							 | 
						||
| 
								 | 
							
										//$this->__data->attach(new self($data));
							 | 
						||
| 
								 | 
							
										//$this->__data->attach(json_decode(json_encode($data)));
							 | 
						||
| 
								 | 
							
										return $this;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									/**
							 | 
						||
| 
								 | 
							
									 * @param string $key 
							 | 
						||
| 
								 | 
							
									 * @return mixed 
							 | 
						||
| 
								 | 
							
									 */
							 | 
						||
| 
								 | 
							
									private function _getValue($key){
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
										return isset($this->__data[$key]) ? $this->__data[$key] : null;
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
									}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									public function __get($key){
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
										return isset($this->__data[$key]) ? $this->__data[$key] : null;
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
									}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									/**
							 | 
						||
| 
								 | 
							
									 * 
							 | 
						||
| 
								 | 
							
									 * @param string $key 
							 | 
						||
| 
								 | 
							
									 * @param mixed $value 
							 | 
						||
| 
								 | 
							
									 * @return $this 
							 | 
						||
| 
								 | 
							
									 */
							 | 
						||
| 
								 | 
							
									public function setValue($key, $value){
							 | 
						||
| 
								 | 
							
										$this->__data[$key] = $value;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										return $this;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									/**
							 | 
						||
| 
								 | 
							
									 * 
							 | 
						||
| 
								 | 
							
									 * @param string $method 
							 | 
						||
| 
								 | 
							
									 * @param string[] $args 
							 | 
						||
| 
								 | 
							
									 * @return mixed 
							 | 
						||
| 
								 | 
							
									 */
							 | 
						||
| 
								 | 
							
									public function __call($method, $args) {
							 | 
						||
| 
								 | 
							
										if(($p = strpos($method, 'get')) !== false && $p === 0){
							 | 
						||
| 
								 | 
							
											$fieldname = (str_replace('get', '', $method)); 
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
											if(!empty($args)){
							 | 
						||
| 
								 | 
							
												switch ($fieldname) {
							 | 
						||
| 
								 | 
							
													case 'Values':
							 | 
						||
| 
								 | 
							
													case 'Value':
							 | 
						||
| 
								 | 
							
														if(count($args) === 1)
							 | 
						||
| 
								 | 
							
															return $this->_getValue($args[0]);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
														$values = [];
							 | 
						||
| 
								 | 
							
														foreach($args as $arg){
							 | 
						||
| 
								 | 
							
															$values[$arg] = $this->_getValue($arg);
							 | 
						||
| 
								 | 
							
														}
							 | 
						||
| 
								 | 
							
														return $values;
							 | 
						||
| 
								 | 
							
														break;
							 | 
						||
| 
								 | 
							
													
							 | 
						||
| 
								 | 
							
													default:
							 | 
						||
| 
								 | 
							
														# code...
							 | 
						||
| 
								 | 
							
														break;
							 | 
						||
| 
								 | 
							
												}
							 | 
						||
| 
								 | 
							
												
							 | 
						||
| 
								 | 
							
											}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
											//Convert data to insensitive case
							 | 
						||
| 
								 | 
							
											$lower_array_object = new \Phacil\Framework\ArrayClass\CaseInsensitiveArray(
							 | 
						||
| 
								 | 
							
												$this->__data
							 | 
						||
| 
								 | 
							
											);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
											return $lower_array_object[$fieldname];
							 | 
						||
| 
								 | 
							
										}
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								}
							 |