37 lines
		
	
	
		
			844 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			844 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| namespace nur\sery\wip\php\access;
 | |
| 
 | |
| use nur\sery\cl;
 | |
| 
 | |
| abstract class AbstractAccess implements IAccess {
 | |
|   function available($src): bool {
 | |
|     return $this->exists($src) && $this->get($src) !== false;
 | |
|   }
 | |
| 
 | |
|   function inc(&$dest): int {
 | |
|     $value = (int)$this->get($dest);
 | |
|     $this->set(++$value, $dest);
 | |
|     return $value;
 | |
|   }
 | |
| 
 | |
|   function dec(&$dest, bool $allowNegative=false): int {
 | |
|     $value = (int)$this->get($dest);
 | |
|     if ($allowNegative || $value > 0) {
 | |
|       $this->set(--$value, $dest);
 | |
|     }
 | |
|     return $value;
 | |
|   }
 | |
| 
 | |
|   function merge($values, &$dest): void {
 | |
|     $array = $this->get($dest);
 | |
|     $array = cl::merge($array, $values);
 | |
|     $this->set($array, $dest);
 | |
|   }
 | |
| 
 | |
|   function append($value, &$dest, $key=null): void {
 | |
|     $array = $this->get($dest);
 | |
|     cl::set($array, $key, $value);
 | |
|     $this->set($array, $dest);
 | |
|   }
 | |
| }
 |