cable/cable-annotations

Annotations library for cable framework

1.0.9 2017-06-27 14:08 UTC

This package is not auto-updated.

Last update: 2024-03-16 23:47:16 UTC


README

PHP Annonations library for cable framework

Requirements

PHP 5.6+

Installation

composer require cable/cable-annotations
use Cable\Annotation\Factory;


$annotation = Factory::create();

Add a Command

/**
 *
 * @Name("Test") the name of command
 *
 */
class TestCommand extends Command{


     /**
      *
      * @Annotation() // you must add this 
      *                // if you want to use that property
      *
      * @Required() // if this parameter not given by user, 
      *              //will be thrown a exception
      *
      * @Default('Default value'); // default value of property
      *                             // if you set this, required exception will be never thrown
      *                             // so there is no point of using together Default and Required
      */                            
     public $name;

}


$annotation->addCommand(new TestCommand());

Using Command

class Test{


      /**
       * 
       * @Test(name = "test name")
       *
       *
       */
      public function testing(){
      
      }

}

// execute the class instance
$class = $annotation->executeClass(new Test());

$methods = $annotation->methods();
// $annotation->get('methods') // same as above


// $methods->get('Test');
foreach($methods->Test() as $test){
    echo $test->name; // test name will be printed
}

Using Paramaters

Giving Arrays

    /**
     *
     * @Test(datas={test: "test"})
     *
     * will be given as ["test" = "test"]
     *
     */

giving annotation into data

      /**
       *
       * @Test(data= @Test(name = "data"))
       *
       *
       * // you can give @Test  into data
       */

Saving Container

You can give any psr-11 container into annotation

Annotation::setContainer($container);

``

```php

     /**
       *
       * @Test(data= aliasname{test:"test"})
       *
       *
       * // you must save aliasname into the container
       */