1. Go to this page and download the library: Download noone4rever/axessors library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
noone4rever / axessors example snippets
class Email
{
public $email;
public function __construct()
{
/* ... */
}
public function getEmailDomain()
{
/* ... */
}
}
$emailAddress->email = new \stdclass();
public function setEmail(string $val): void
{
$this->email = $val;
}
public function getEmail(): string
{
return $this->email;
}
public function setEmail(string $val): void
{
if (preg_match('/[a-z][a-z\d_\.]*@[a-z]+\.[a-z]+/i', $email)) {
$this->email = strtolower($val);
} else {
throw new ValidationException('not a valid email address given');
}
}
use NoOne4rever\Axessors\Axessors;
class WithTrait
{
use Axessors;
/* ... */
}
private $field; #: +axs mixed
nclude 'MyClassB.php';
class WithKeywords
{
use Axessors;
private $a; #: +rdb int
private $b; #: +wrt int
private $c; #: +axs int
}
$test = new WithKeywords();
$test->getA();
$test->setB(1);
$test->getC();
$test->setC(1);
class WithAccessModifiers
{
use Axessors;
private $publicAccess; #: +axs int
private $protectedAccess; #: ~axs int
private $privateAccess; #: -axs int
}
$test = new WithAccessModifiers();
$test->getPublicAccess(); // OK
$test->getPrivateAccess(); // Error
private $field = 'smth'; #: ~wrt +rdb
class WithTypeDeclarations
{
use Axessors;
private $email; #: +axs string
}
class WithMultipleTypeDeclarations
{
use Axessors;
private $bigNumber; #: +axs int|string
}
class WithDefaultFieldValue
{
use Axessors;
private $epsilon = 1e-9; #: +rdb
}
class Config
{
private static $settings; #: +axs array[int|string]
}
class WithConditionalSetter
{
private $age;
public function setAge(int $val): void
{
if ($val >= 1 && $val <= 120) {
$this->age = $val;
} else {
throw new ValidationException('given age is not possible');
}
}
}
class WithConditionalSetter
{
use Axessors;
private $age; #: +wrt int 1..120
}
class Email
{
use Axessors;
private $email; #: +axs string `preg_match('/[a-z][a-z\d_\.]*@[a-z]+\.[a-z]+/i', $var)`
}
class Email
{
use Axessors;
private $email; #: +axs string < 120 && `preg_match('/[a-z][a-z\d_\.]*@[a-z]+\.[a-z]+/i', $var)`
}
class WithGroupedConditions
{
use Axessors;
private $exactInt; #: +axs int (!= 4 && (1..10 || > 100))
}
class Email
{
use Axessors;
private $email; #: +axs string `preg_match('/[a-z][a-z\d_\.]*@[a-z]+\.[a-z]+/i', $var)` -> lower
}
class WithInjectedCallback
{
use Axessors;
private $system; #: +axs string <= 100 -> `system('explorer %APPDATA%')`
}
class WithNumber
{
use Axessors;
private $number; #: +axs int -> inc, dec
}
class WithRelativeNames
{
use Axessors;
private $field; #: +axs `:CurrentNamespaceClass::doSmth()` -> `globalNamespaceClass::doSmthElse()`
}
class WithShortThisSyntax
{
use Axessors;
private $field; #: +axs int -> `$.doSmth()`
private function doSmth() {...}
}
class WithCodeBlocks
{
use Axessors;
private $field; #: +axs int `{$a = 0; $b = 255; return $var >= $a && $var <= $b;}`
}
class WithEcho
{
use Axessors;
private $field; #: +axs int -> `{echo 'ok';}`
}
class WithLongField
{
private $thisFieldWithReallyLooooongName;
}
class ParentClass
{
use Axessors;
private $field; #: +axs int => parentField
}
class ChildClass extends ParentClass
{
use Axessors;
private $field; #: +axs int => childField
}
class WithArrayOfStrings
{
use Axessors;
private $strings; #: +axs Array[string]
}
interface Locatable
{
# public function getX(): int;
# public function getY(): int;
# public function setX(int $val): void;
# public function setY(int $val): void;
}
abstract class Shape implements Locatable
{
use Axs;
# abstract public fucntion getId(): int;
}
class Triangle extends Shape
{
use Axessors;
private $id; #: +rdb int
private $x, $y; #: +axs int
}
class Color
{
use Axessors;
private $red, $green, $blue; #: +axs int 0..255
/* ... */
}
$color = new Color(255, 255, 0);
$color->getRed();
$color->getGreen();
$color->getBlue();
/**
* Class with Axessors methods.
*
* @method int getInstanceField() getter for instace field
* @methdd static int getClassField() getter for class field
*/
class WithAxessorsMethods
{
use Axessors;
private static $classField; #: +axs int
private $instanceField; #: +axs int
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.