PHP code example of zeptech / annotations

1. Go to this page and download the library: Download zeptech/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/ */

    

zeptech / annotations example snippets



use \zpt\anno\Annotations;

$classReflector = new ReflectionClass('MyClass');
$classAnnotations = new Annotations($classReflector);

$methodAnnotations = array();
foreach ($classReflector->getMethods() as $methodReflector) {
    $methodAnnotations[$methodReflector->getName()] = new Annotations($methodReflector);
}


use \zpt\anno\AnnotationFactory;

$factory = new AnnotationFactory;
$annos = $factory->get('stdclass');


/**
 * @Characteristic
 */
class MyClass {
}

$annotations = new Annotations(new ReflectionClass('MyClass'));
$annotations['Characteristic'] === true;

$annotations['AnotherCharacteristic'] === null;
isset($annotations['AnotherCharacteristic']) === false;


/**
 * @Characteristic false
 */

$annotations['Characteristic'] === false;
isset($annotations['Characteristic']) === true;


$annotations->hasAnnotation('Characteristic') === true;
$annotations->hasAnnotation('AnotherCharacteristic') === false;


/**
 * @LikesToEat cheese
 */
class MyClass {
    // ...
}

$annotations['LikesToEat'] === 'cheese';


/**
 * @LikesToEat [ cheese, kraft dinner, hot dogs ]
 */
// ...

$annotations['LikesToEat'] == array('cheese', 'kraft dinner', 'hot dogs');


is_array($annotations['LikesToEat']) === true

/**
 * @LikesToDrink water
 * @LikesToDrink beer
 */
// ...

$annotations['LikesToDrink'] == array('water', 'beer');


/**
 * @LikesToEat weekend = [ chips, dip ], anytime = [ cheese, kraft dinner, hot dogs ]
 */
// ...

$annotations['likesToEat']['weekend'] == array('chips', 'dip');
$annotations['likesToEat']['anytime'] == array('cheese', 'kraft dinner', 'hot dogs');

/**
 * This is a comment which contains an annotation value with a nested list.
 *
 * @ListNest [ [0], [1], [2] ]
 * @MapNest oneZero = [0], oneOne = [1], oneTwo = [2]
 */
// ...

$annotation['listnest'] = array( array(0), array(1), array(2) );
$annotation['mapnest'] = array( 'oneZero' => array(0), 'oneOne' => array(1), 'oneTwo' => array(2) );

/**
 * @MenuData {"root":{"child":{"arraychild":[0,1,2,3]}},"arraysroot":[1,2,3]}
 */


/**
 * @LikesToEat([ cheese, kraft dinner, hot dogs ])
 * @DoesNotLikeToEat( morning = salad, night = [ toast, fruit ])
 */

/**
 * @Yolo [ sounds, like, a, good, time ]
 * @Yolo [ but, is, it? ]
 * @Yolo yolo!
 */