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