1. Go to this page and download the library: Download objectiphy/annotations 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/ */
namespace MyNamespace;
class MyEntity
{
/** @var MyEntity $childObject A child object of the same type as the parent. */
private MyEntity $childObject;
}
namespace MyNamespace\Annotations;
class MyAnnotation
{
public string $childClassName;
protected int $value = 100;
private string $name;
public function __construct(string $name)
{
$this->name = $name;
}
public function setValue(int $value): void
{
$this->value = $value;
}
public function getValue(): int
{
return $this->value;
}
public function setName(string $name): void
{
$this->name = $name;
}
public function getName(): string
{
return $this->name;
}
}
namespace MyNamespace\Entities;
//You don't have to use an alias, this is just to demonstrate that you can:
use MyNamespace\Annotations\MyAnnotation as AnnotationAlias;
use MyNamespace\ValueObjects\OtherClass;
class MyEntity2
{
/**
* @var OtherClass
* @AnnotationAlias(name="nameValue", childClassNameName="OtherClass", value=200)
*/
public $childClassName;
}
use Objectiphy\Annotations\AnnotationReader;
use MyNamespace\Annotations\MyAnnotation;
use MyNamespace\Entities\MyEntity2;
$annotationReader = new AnnotationReader();
$annotationReader->setClassNameAttributes(['childClassName']);
$annotation = $annotationReader->getAnnotationFromProperty(MyEntity2::class, 'childClassName', MyAnnotation::class);
echo "Name: " . $annotation->getName() . "\n";
echo "Child Class Name: " . $annotation->childClassName . "\n";
echo "Value: " . $annotation->getValue();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.