/**
  * Returns an associative array of classes known to extend Node.
  * Pulls this array from cache if available - if not, generates
  * and caches it.
  *
  * Class names are keyed on their machine name.
  * 
  * @access private
  * @static
  * @return array
  */
 private static function init_registry()
 {
     $cache = cache_get(self::DOODAL_CACHE_ID);
     ##
     ## Attempt to get registry from cache
     if ($cache && !empty($cache->data)) {
         return $cache->data;
     } else {
         ##
         ## Load all classes registered for autoloading not in an ignored (i.e. system) module
         $results = db_query("SELECT name FROM {registry} WHERE type = 'class' AND module != '' AND module NOT IN (:modules) ORDER BY name", array(':modules' => self::get_ignored_modules()))->fetchAll();
         ##
         ## Get subset of classes marked as "node"
         $registry = array();
         foreach ($results as $result) {
             $reflectedClass = new ReflectionAnnotatedClass($result->name);
             if ($reflectedClass->hasAnnotation('MachineName')) {
                 $registry[$reflectedClass->getAnnotation('MachineName')->value] = $result->name;
             }
         }
         ##
         ## Cache results and return
         cache_set(self::DOODAL_CACHE_ID, $registry, 'cache', CACHE_PERMANENT);
         return $registry;
     }
 }
示例#2
0
 private function checkTargetConstraints($target)
 {
     $reflection = new ReflectionAnnotatedClass($this);
     if ($reflection->hasAnnotation('Target')) {
         $value = $reflection->getAnnotation('Target')->value;
         $values = is_array($value) ? $value : array($value);
         foreach ($values as $value) {
             if ($value == 'class' && $target instanceof ReflectionClass) {
                 return;
             }
             if ($value == 'method' && $target instanceof ReflectionMethod) {
                 return;
             }
             if ($value == 'property' && $target instanceof ReflectionProperty) {
                 return;
             }
             if ($value == 'nested' && $target === false) {
                 return;
             }
         }
         if ($target === false) {
             trigger_error("Annotation '" . get_class($this) . "' nesting not allowed", E_USER_ERROR);
         } else {
             trigger_error("Annotation '" . get_class($this) . "' not allowed on " . $this->createName($target), E_USER_ERROR);
         }
     }
 }
示例#3
0
 function process($webscript, $method)
 {
     $this->deleteInvalidTickets();
     try {
         $reflectedWebscript = new ReflectionAnnotatedClass(ucfirst($webscript) . "Webscript");
         if ($reflectedWebscript->hasMethod($method)) {
             $methodInstance = $reflectedWebscript->getMethod($method);
             if ($methodInstance->isPublic()) {
                 $args = "";
                 $ticket = "";
                 if ($methodInstance->hasAnnotation("Get")) {
                     $args = $_GET['data'];
                     $ticket = $_GET['ticket'];
                 }
                 if ($methodInstance->hasAnnotation("Post")) {
                     $args = $_POST['data'];
                     $ticket = $_POST['ticket'];
                 }
                 if ($methodInstance->hasAnnotation("RequiresAuthentication")) {
                     if ($this->checkAuthentication($ticket, $methodInstance->getAnnotation("RequiresAuthentication"))) {
                         $this->extendAuthentication($ticket);
                     } else {
                         return $this->authenticationFailed();
                     }
                 }
                 return $methodInstance->invoke($reflectedWebscript->newInstance(), $args, $ticket);
             }
         } else {
             return $this->notFound();
         }
     } catch (ReflectionException $e) {
         return $this->notFound();
     }
 }
示例#4
0
 public function __construct(RootEventDispatcher $EventDispatcher)
 {
     $reflection = new \ReflectionAnnotatedClass(get_class($this));
     foreach ($reflection->getMethods() as $method) {
         if ($method->hasAnnotation('CEP_EventHandler')) {
             $annotation = $method->getAnnotation('CEP_EventHandler');
             $EventDispatcher->addListener($annotation->event, array($method->class, $method->name), $annotation->priority);
         }
     }
 }
示例#5
0
 private static function prepareForSerize(\ReflectionAnnotatedClass $reflection, $object, $parent = false)
 {
     $hash = spl_object_hash($object);
     if (in_array($hash, self::$prepared) && $parent == false) {
         return;
     }
     array_push(self::$prepared, $hash);
     $globalAltered = false;
     $defaults = null;
     foreach ($reflection->getProperties() as $property) {
         $altered = false;
         $property->setAccessible(true);
         $value = $property->getValue($object);
         if (self::isTransient($property)) {
             $defaults = $defaults == null ? $reflection->getDefaultProperties() : $defaults;
             $name = $property->getName();
             $property->setValue($object, array_key_exists($name, $defaults) ? $defaults[$name] : null);
             $altered = true;
         } else {
             if (is_object($value) && $value instanceof \Closure) {
                 $property->setValue($object, new SerializableClosure($value));
                 $altered = true;
             } else {
                 if (is_object($value) && !$value instanceof SerializableClosure && spl_object_hash($value) != $hash) {
                     $valueReflection = new \ReflectionAnnotatedClass($value);
                     $altered = self::prepareForSerize($valueReflection, $value);
                 } else {
                     if (is_array($value)) {
                         $newValue = self::prepareArrayForSerialize($value);
                         if (is_array($newValue)) {
                             $property->setValue($object, $newValue);
                             $altered = true;
                         }
                     }
                 }
             }
         }
         if ($altered) {
             self::addRestore($property, $object, $value);
             $globalAltered = true;
         }
     }
     $parent = $reflection->getParentClass();
     if ($parent != null) {
         self::prepareForSerize($parent, $object, true);
     }
     if (!$parent) {
         if ($object instanceof Detachable) {
             $object->detach();
         }
     }
     return $globalAltered;
 }
示例#6
0
  private function reflectClass ( $class_name )
  {
    require_once $this->file_name;

    // reflect class
    $class = new ReflectionAnnotatedClass( $class_name );
    // reflect @DefinitionObject
    if ( $class_annotation = $class->getAnnotation( 'DefinitionObject' ) ) {
      // set table
      $table = new DefinitionObject;
      $table->table = $class_annotation->table;
      $this->setTable( $class->getName(), $table );
      unset( $table );

      if ( isset( $class_annotation->build ) && $class_annotation->build ) {
        $this->build = $class_annotation->build;
      }

      // iterate properties
      foreach ( $class->getProperties() as $property ) {

        $ref_col = $property->getAnnotation( 'DefinitionObject' );
        // create column
        $column = new DefinitionObject;
        $column->column = $ref_col->column;
        $column->type = $ref_col->type;
        $column->size = $ref_col->size;
        $column->scale = $ref_col->scale;
        $column->default = $ref_col->default;
        $column->required = $ref_col->required;
        $column->autoIncrement = $ref_col->autoIncrement;
        $column->primaryKey = $ref_col->primaryKey;
        $column->index = $ref_col->index;
        $column->unique = $ref_col->unique;

        // reflect @ReferenceDef
        if ( $ref_ref = $property->getAnnotation( 'ReferenceDef' ) ) {
          // create reference
          $ref = new ReferenceDef();
          $ref->table = $ref_ref->table;
          $ref->column = $ref_ref->column;
          $ref->onUpdate = $ref_ref->onUpdate;
          $ref->onDelete = $ref_ref->onDelete;
        }

        // set column string
        $this->setColumn( $property->getName(), $column, isset( $ref )
                                                         ? $ref : false );
        unset( $ref );
        unset( $column );
      }
    }
  }
 /**
  * Gets the ckAbstractPropertyStrategy implementation for a given class from the PropertyStrategy annotation,
  * if no annotation is found ckDefaultPropertyStrategy is returned.
  *
  * @param ReflectionAnnotatedClass $class A ReflectionAnnotatedClass object
  *
  * @return ckAbstractPropertyStrategy The ckAbstractPropertyStrategy implementation
  */
 public static function getPropertyStrategy(ReflectionAnnotatedClass $class)
 {
     $strategy = null;
     if ($class->hasAnnotation('PropertyStrategy')) {
         $strategy = $class->getAnnotation('PropertyStrategy')->value;
         $strategy = new $strategy($class);
     }
     if (is_null($strategy) || !$strategy instanceof ckAbstractPropertyStrategy) {
         $strategy = new ckDefaultPropertyStrategy($class);
     }
     return $strategy;
 }
示例#8
0
 public function handle($inteceptor)
 {
     $re = new ReflectionAnnotatedClass(get_class($this->CI));
     $method = $re->getMethod($inteceptor->call_method);
     if ($method->hasAnnotation('RunRule')) {
         $run = $method->getAnnotations('RunRule');
         $run = $run[0];
         // Clear the clips context if needed
         if ($run->clear) {
             $this->clips->clear();
         }
         if ($run->templates) {
             if (is_string($run->templates)) {
                 $run->templates = array($run->templates);
             }
             foreach ($run->templates as $t) {
                 $this->clips->template($t);
             }
         }
         // Let the call method to add the facts
         $ret = $inteceptor->process();
         // Load the rules
         if ($run->rules) {
             if (is_string($run->rules)) {
                 $run->value = array($run->rules);
             }
             if (is_array($run->rules)) {
                 $run->value = $run->rules;
             }
         }
         if (isset($run->value)) {
             if (is_string($run->value)) {
                 $run->value = array($run->value);
             }
             foreach ($run->value as $v) {
                 $this->clips->load('ci://config/rules/' . $v);
             }
         }
         // Run the clips context
         $this->clips->run();
         // Return the original return
         return $ret;
     }
     return $inteceptor->process();
 }
示例#9
0
 public function Service()
 {
     $className = get_class($this);
     parent::__construct($className);
     $this->route = $className;
     $this->serviceMethods = array();
     $this->subroutes = array();
     // Annotations
     if ($this->hasAnnotation('Route')) {
         $annotation = $this->getAnnotation('Route');
         if ($annotation->value) {
             $this->route = $annotation->value;
         }
     }
     // Service methods
     foreach ($this->getMethods() as $reflectionMethod) {
         $methodName = strtolower($reflectionMethod->name);
         $httpMethods = array();
         if ($methodName == 'get' || $methodName == 'post' || $methodName == 'put' || $methodName == 'delete' || $methodName == 'any') {
             $httpMethods[] = $methodName;
         }
         // Check for http method annotations
         if ($reflectionMethod->hasAnnotation('Get')) {
             $httpMethods[] = 'get';
         }
         if ($reflectionMethod->hasAnnotation('Post')) {
             $httpMethods[] = 'post';
         }
         if ($reflectionMethod->hasAnnotation('Put')) {
             $httpMethods[] = 'put';
         }
         if ($reflectionMethod->hasAnnotation('Delete')) {
             $httpMethods[] = 'delete';
         }
         if ($reflectionMethod->hasAnnotation('Any')) {
             $httpMethods[] = 'any';
         }
         $httpMethods = array_unique($httpMethods);
         $subroute = NULL;
         if ($reflectionMethod->hasAnnotation('Subroute')) {
             $subrouteAnnotation = $reflectionMethod->getAnnotation('Subroute');
             if ($subrouteAnnotation->value) {
                 $subroute = preg_replace('/{[^}]*}/', '{}', $subrouteAnnotation->value);
             }
         }
         if (count($httpMethods) > 0) {
             if ($subroute) {
                 if (!isset($this->subroutes[$subroute])) {
                     $this->subroutes[$subroute] = array();
                 }
                 $this->subroutes[$subroute][] = new ServiceMethod($this, $reflectionMethod, $httpMethods);
             } else {
                 $this->serviceMethods[] = new ServiceMethod($this, $reflectionMethod, $httpMethods);
             }
         }
     }
 }
 public function generate($entity)
 {
     $classe = get_class($entity);
     $reflectionClass = new ReflectionAnnotatedClass($classe);
     $tabela = $reflectionClass->getAnnotation('Table')->value;
     $propriedades = $reflectionClass->getProperties();
     foreach ($propriedades as $propriedade) {
         if ($propriedade->hasAnnotation('Column')) {
             $getter = $propriedade->name;
             $key = $propriedade->getAnnotation('Column')->name;
             $params = (array) $propriedade->getAnnotation('Column');
             foreach ($params as $chave => $valor) {
                 $fields[$key][$chave] = $valor;
             }
         }
         if ($propriedade->hasAnnotation('Join')) {
             $params = (array) $propriedade->getAnnotation('Join');
             foreach ($params as $chave => $valor) {
                 $fields[$key][$chave] = $valor;
             }
         }
     }
     $script = "DROP TABLE IF EXISTS " . SCHEMA . $tabela . "; \n" . "CREATE TABLE " . SCHEMA . $tabela . " ( \n";
     $uid;
     foreach ($fields as $key => $value) {
         $fk;
         if (isset($value['joinTable'])) {
             $fk = "\tCONSTRAINT " . $tabela . "_" . $value['joinTable'] . "_fk FOREIGN KEY({$key})\n";
             $fk .= "\t\tREFERENCES " . SCHEMA . $value['joinTable'] . "({$value['joinColumn']}) MATCH SIMPLE\n";
             $fk .= "\t\tON UPDATE NO ACTION ON DELETE NO ACTION,\n";
             $script .= "\t" . $key . " integer, \n";
         } else {
             if ($key == 'id') {
                 $script .= "\t" . $key . " serial NOT NULL, \n";
                 $uid = $key;
             } else {
                 $script .= "\t" . $key . " " . ($value['type'] == 'integer' ? 'integer' : ($value['type'] == 'timestamp' ? 'timestamp' : 'character varying')) . ", \n";
             }
         }
     }
     $script .= @$fk;
     $script .= "\tCONSTRAINT " . $tabela . "_pk PRIMARY KEY (" . $uid . ") \n";
     return $script . " );\n\n -- \n";
 }
示例#11
0
/**
 * Loads current action according TlalokesRequest or default configuration
 *
 * @author Basilio Briceno <*****@*****.**>
 * @param array $conf
 * @param TlalokesRequest $request
 */
function tlalokes_core_conf_get_action(&$conf, TlalokesRequest &$request)
{
    require_once 'ReflectionAnnotatedClass.php';
    require_once 'ControllerDefinition.php';
    require_once 'ActionDefinition.php';
    // reflect Annotations from current controller class
    $rc = new ReflectionAnnotatedClass($conf['current']['controller']);
    // try to find the @ControllerDefinition
    if (!$rc->hasAnnotation('ControllerDefinition')) {
        tlalokes_error_msg('Define annotation @ControllerDefinition in ' . $conf['current']['controller']);
    }
    // try to find the default action property in @ControllerDefinition
    if (!($default = $rc->getAnnotation('ControllerDefinition')->default)) {
        tlalokes_error_msg('Define a default action in @ControllerDefinition in ' . $conf['current']['controller']);
    }
    // set the current action from TlalokesRequest or default if not found
    $conf['current']['action'] = !$rc->hasMethod($request->_action) ? $default : $request->_action;
    return $conf;
}
示例#12
0
 public function findPks($className)
 {
     $reflection = new ReflectionAnnotatedClass($className);
     // by class name
     $properties = $reflection->getProperties();
     $atributes_column = array();
     if (count($properties) > 0) {
         foreach ($properties as $key => $property) {
             $reflectionAnotatedProperty = new ReflectionAnnotatedProperty($className, $property->getName());
             $Key = $reflectionAnotatedProperty->getAnnotation('Column')->Key;
             if (strlen($Key) > 0 && $Key == "PRI") {
                 $atributes_column[] = (string) $reflectionAnotatedProperty->getAnnotation('Column')->Field;
             }
         }
     }
     if (count($atributes_column) > 0) {
         return $atributes_column;
     }
     throw new Exception('La clase ' . $className . " no tiene definidas llaves");
 }
示例#13
0
 /**
  * @param type $object 
  */
 public function inject(&$object, $reflection = null)
 {
     if ($reflection == null) {
         $reflection = new \ReflectionAnnotatedClass($object);
     }
     $properties = $reflection->getProperties();
     foreach ($properties as $property) {
         if ($property->hasAnnotation("Resource")) {
             $annotation = $property->getAnnotation("Resource");
             $resource = $property->getName();
             if (!empty($annotation->name)) {
                 $resource = $annotation->name;
             }
             $property->setAccessible(true);
             $property->setValue($object, $this->context->getResource($resource));
         }
     }
     $parent = $reflection->getParentClass();
     if ($parent != null) {
         $this->inject($object, $parent);
     }
 }
 /**
  * 
  * @param String $filename réal path of the php file to scan ex: /home/project/src/org/foo/bar.php
  * @param String $namespace the name space of this file ex: org\foo
  * @return void
  * @throws IocException
  */
 protected function scanFile($filename, $namespace)
 {
     if (!is_file($filename)) {
         \org\equinox\utils\Logger::error("({$filename}) is not a file!");
         throw new IocException("({$filename}) is not a file!");
     }
     include_once $filename;
     $name = basename($filename);
     $className = $namespace . '\\' . substr($name, 0, strpos($name, '.'));
     if (class_exists($className)) {
         $ref = new \ReflectionAnnotatedClass($className);
         $listAnnotation = $ref->getAllAnnotations();
         if (empty($listAnnotation)) {
             return;
             // this class is not a Component !
         }
         $bean = new BeanDefinition();
         $bean->setClassName($className);
         foreach ($listAnnotation as $annotation) {
             if ($annotation instanceof annotations\ClassAnnotation) {
                 $annotation->doBean($bean, $className);
             }
         }
         if ($bean->getId() == null) {
             throw new IocException("Equinox annotation found but no @Component annotation found (mandatory) in {$className}");
         }
         $listProperties = $ref->getProperties();
         foreach ($listProperties as $property) {
             $this->doProperty($bean, $property);
         }
         $listMethod = $ref->getMethods();
         foreach ($listMethod as $method) {
             $this->doMethod($bean, $method);
         }
         $this->context->addBeanDefinition($bean);
     }
 }
示例#15
0
 public function loadResourceMap($classes)
 {
     $resources = array();
     foreach ($classes as $class) {
         $reflection = new \ReflectionAnnotatedClass($class);
         $name = "";
         if ($reflection->hasAnnotation("Service")) {
             $annotation = $reflection->getAnnotation('Service');
             $resources[$this->getResourceName($annotation, $class)] = $reflection->getName();
         }
         if ($reflection->hasAnnotation("Repository")) {
             $annotation = $reflection->getAnnotation('Repository');
             $resources[$this->getResourceName($annotation, $class)] = $reflection->getName();
         }
     }
     return $resources;
 }
示例#16
0
 /**
  * {@inheritdoc}
  */
 public function matches($className, \ReflectionAnnotatedClass $reflection)
 {
     return preg_match('/' . $this->expression . '/', $reflection->getName());
 }
 public function testMultiTargetAnnotationThrowsNoErrorWhenOnRightPlace()
 {
     $reflection = new ReflectionAnnotatedClass('SuccesfullyAnnotatedClass');
     $method = $reflection->getProperty('property2');
     $this->assertNoErrors();
 }
示例#18
0
 /**
  * {@inheritdoc}
  */
 public function matches($className, \ReflectionAnnotatedClass $reflection)
 {
     return $reflection->isSubclassOf($this->superClass);
 }
示例#19
0
 /**
  * Parse the routes of the given controller
  * 
  * @param object $controller Controller object.
  * 
  * @return Encaminar
  */
 public function parseRoutes($controller)
 {
     $reflection = new ReflectionAnnotatedClass($controller);
     foreach ($reflection->getMethods() as $method) {
         if ($method->hasAnnotation(self::ANNOTATION)) {
             $annotation = $method->getAnnotation(self::ANNOTATION)->value;
             list($httpMethod, $path) = explode(' ', $annotation);
             $this->addRoute($method, $path, $httpMethod);
         }
     }
     return $this;
 }
 /**
  * Creates a schema.xml file based in Database Definition objects
  *
  * @param TlalokesRegistry $reg
  */
 private static function buildSchemaFromDefs(TlalokesRegistry &$reg)
 {
     // static flags
     static $uniques = 0;
     static $indexes = 0;
     // build database xml dom object
     $dom = new DOMDocument('1.0', 'utf-8');
     $dom->formatOutput = true;
     $db = $dom->appendChild(new DOMElement('database'));
     $db->setAttribute('name', $reg->conf['dsn']['name']);
     // find table definitions
     foreach (glob($reg->conf['path']['app'] . $reg->conf['path']['def'] . '*Def.php') as $def) {
         // get class name
         $class_name = preg_replace('/.*\\/(\\w*Def).php$/', '$1', $def);
         // reflect annotated class
         $ref = new ReflectionAnnotatedClass($class_name);
         // check if @DefinitonObject is set
         if (!$ref->hasAnnotation('DefinitionObject')) {
             tlalokes_error_msg('PropelFactory: There is no DefinitionObject in ' . $class_name);
         }
         // check if object is marked for build
         if ($ref->getAnnotation('DefinitionObject')->build) {
             // build xml table node
             $table = $db->appendChild(new DOMElement('table'));
             // set table name attribute
             $table_name = $ref->getAnnotation('DefinitionObject')->table;
             $table->setAttribute('name', $table_name);
             unset($table_name);
             $table->setAttribute('idMethod', 'native');
             // find columns
             foreach ($ref->getProperties() as $property) {
                 // reflect column
                 $column = $property->getAnnotation('DefinitionObject');
                 // build xml column nodes
                 $col = $table->appendChild(new DOMElement('column'));
                 // name
                 $col->setAttribute('name', $column->column);
                 // phpName
                 if ($property->getName() != $column->column) {
                     $col->setAttribute('phpName', (string) $property->getName());
                 }
                 // type
                 $col->setAttribute('type', $column->type);
                 // size
                 if ($column->size) {
                     $col->setAttribute('size', $column->size);
                 }
                 // scale
                 if ($column->scale) {
                     $col->setAttribute('scale', $column->scale);
                 }
                 // required
                 if ($column->required) {
                     $col->setAttribute('required', $column->required ? 'true' : 'false');
                 }
                 // autoIncrement
                 if ($column->autoIncrement) {
                     $col->setAttribute('autoIncrement', $column->autoIncrement ? 'true' : 'false');
                     // If RBDMS is PgSQL and there is no default set the default
                     // WARNING: It needs to be tested with Oracle
                     if ($reg->conf['dsn']['type'] == 'pgsql') {
                         // build id-method-parameter
                         $imp_name = 'id-method-parameter';
                         $imp = $table->appendChild(new DOMElement($imp_name));
                         $imp->setAttribute('value', $table_name . '_seq');
                         // set default
                         if (!isset($column->default)) {
                             $col->setAttribute('default', 'nextval(\'' . $table_name . '_seq\'::regclass)');
                         }
                     }
                 }
                 // primaryKey
                 if ($column->primaryKey) {
                     $col->setAttribute('primaryKey', $column->primaryKey ? 'true' : 'false');
                 }
                 // default
                 if ($column->default || $column->default === 0) {
                     $col->setAttribute('default', tlalokes_core_get_type($column->default));
                 }
                 // find unique
                 if (isset($column->unique) && $column->unique) {
                     if (isset($uniques)) {
                         $uniques++;
                     } else {
                         $uniques = 1;
                     }
                     $unique_column_name[] = $column->column;
                 }
                 // find index
                 if (isset($column->index) && $column->index) {
                     $indexes = isset($indexes) ? $indexes + 1 : 1;
                     $index_column_name[] = $column->column;
                 }
                 // find reference
                 $reference = $property->getAnnotation('ReferenceDef');
                 if ($reference) {
                     // build foreign-key xml node
                     $fk = $table->appendChild(new DOMElement('foreign-key'));
                     $fk->setAttribute('foreignTable', $reference->table);
                     $fk->setAttribute('onDelete', strtolower($reference->onDelete));
                     $fk->setAttribute('onUpdate', strtolower($reference->onUpdate));
                     $rf = $fk->appendChild(new DOMElement('reference'));
                     $rf->setAttribute('local', $column->column);
                     $rf->setAttribute('foreign', $reference->column);
                 }
             }
             // find uniques flag
             if (isset($uniques) && $uniques >= 1) {
                 if (isset($unique_column_name)) {
                     foreach ($unique_column_name as $ucn) {
                         // build unique xml node
                         $unique = $table->appendChild(new DOMElement('unique'));
                         // build unique-column xml node
                         $uc = $unique->appendChild(new DOMElement('unique-column'));
                         $uc->setAttribute('name', $ucn);
                     }
                     unset($unique_column_name);
                 }
                 unset($uniques);
             }
             // find indexes flag
             if (isset($indexes) && $indexes >= 1) {
                 foreach ($index_column_name as $icn) {
                     // build index xml node
                     $index = $table->appendChild(new DOMElement('index'));
                     // build index-column xml node
                     $ic = $index->appendChild(new DOMElement('index-column'));
                     $ic->setAttribute('name', $icn);
                 }
                 unset($indexes);
                 unset($index_column_name);
             }
         }
         // set file path to schema.xml
         $file = $reg->conf['path']['app'] . $reg->conf['path']['tmp'] . 'generator/schema.xml';
         // write schema.xml file or return a CoreException
         if (!@file_put_contents($file, $dom->saveXML())) {
             tlalokes_error_msg('Propel: Cannot write database schema', true);
         }
     }
 }
示例#21
0
 /**
  * {@inheritdoc}
  */
 public function matches($className, \ReflectionAnnotatedClass $reflection)
 {
     return $reflection->hasAnnotation($this->annotation);
 }
 public function testSuccesfullyNestedAnnotationThrowsNoError()
 {
     $reflection = new ReflectionAnnotatedClass('SuccesfullyAnnotatedClass');
     $reflection->getMethod('method2')->getAnnotation('MethodRestrictedAnnotation');
 }
/**
 * Checks if web services are declares in the controller and loads them
 *
 * @author Basilio Briceno <*****@*****.**>
 * @param TlalokesRegistry $reg
 */
function tlalokes_receiver_webservices(&$reg)
{
    // reflect Annotations in method
    require 'ReflectionAnnotatedClass.php';
    $ref = new ReflectionAnnotatedClass($reg->conf['current']['controller']);
    //require 'ControllerDefinition.php';
    if ($ref->hasAnnotation('ControllerDefinition')) {
        // JSON
        if ($ref->getAnnotation('ControllerDefinition')->json) {
            // check request
            if ($_SERVER['REQUEST_METHOD'] == 'POST') {
                var_dump($_POST);
                $reg->webservice = true;
                $obj = new $reg->conf['current']['controller']($reg);
                unset($reg);
                echo json_encode($obj->response);
                exit;
            }
        }
        // JSON-RPC
        if ($ref->getAnnotation('ControllerDefinition')->jsonrpc) {
            require 'tlalokes_jsonrpc.php';
            // check request
            if (tlalokes_jsonrpc_server_check()) {
                $reg->json = true;
                $obj = new $reg->conf['current']['controller']($reg);
                unset($reg);
                tlalokes_jsonrpc_server_handle($obj);
            }
        }
        // SOAP
        if ($ref->getAnnotation('ControllerDefinition')->soap) {
            if ($_SERVER['REQUEST_METHOD'] == 'POST' || $_SERVER['CONTENT_TYPE'] == 'application/soap+xml') {
                // set URI for the service
                $uri = 'http://' . $_SERVER['HTTP_HOST'] . $reg->conf->path->uri . preg_replace('/^\\/(.*).php/', '$1', $_SERVER['SCRIPT_NAME']) . '/' . $reg->conf['current']['controller'];
                // set service and handle it
                $server = new SoapServer(null, array('uri' => $uri));
                $server->setClass($reg->conf['current']['controller'] . 'Ctl', $reg);
                $server->handle();
                unset($ref);
                exit;
            }
        }
    }
}
示例#24
0
 public function testReflectionAnnotatedClass()
 {
     $reflection = new ReflectionAnnotatedClass('Example');
     $this->assertTrue($reflection->hasAnnotation('FirstAnnotation'));
     $this->assertTrue($reflection->hasAnnotation('SecondAnnotation'));
     $this->assertFalse($reflection->hasAnnotation('NonExistentAnnotation'));
     $this->assertIsA($reflection->getAnnotation('FirstAnnotation'), 'FirstAnnotation');
     $this->assertIsA($reflection->getAnnotation('SecondAnnotation'), 'SecondAnnotation');
     $annotations = $reflection->getAnnotations();
     $this->assertEqual(count($annotations), 2);
     $this->assertIsA($annotations[0], 'FirstAnnotation');
     $this->assertIsA($annotations[1], 'SecondAnnotation');
     $this->assertFalse($reflection->getAnnotation('NonExistentAnnotation'));
     $this->assertIsA($reflection->getConstructor(), 'ReflectionAnnotatedMethod');
     $this->assertIsA($reflection->getMethod('exampleMethod'), 'ReflectionAnnotatedMethod');
     foreach ($reflection->getMethods() as $method) {
         $this->assertIsA($method, 'ReflectionAnnotatedMethod');
     }
     $this->assertIsA($reflection->getProperty('exampleProperty'), 'ReflectionAnnotatedProperty');
     foreach ($reflection->getProperties() as $property) {
         $this->assertIsA($property, 'ReflectionAnnotatedProperty');
     }
     foreach ($reflection->getInterfaces() as $interface) {
         $this->assertIsA($interface, 'ReflectionAnnotatedClass');
     }
     $this->assertIsA($reflection->getParentClass(), 'ReflectionAnnotatedClass');
 }
示例#25
0
 public static function getAnnotationClass($class, $annotation)
 {
     $rac = new \ReflectionAnnotatedClass($class);
     $annot = $rac->getAnnotation($annotation);
     return $annot;
 }
 public function testClassAndAnnotationInNamespaces()
 {
     $reflection = new ReflectionAnnotatedClass('Example\\Example');
     $this->assertTrue($reflection->hasAnnotation('Example\\Annotation\\ExampleAnnotation'));
 }
 public function testIgnoredAnnotationsAreNotUsed()
 {
     Addendum::ignore('FirstAnnotation', 'SecondAnnotation');
     $reflection = new ReflectionAnnotatedClass('Example');
     $this->assertFalse($reflection->hasAnnotation('FirstAnnotation'));
     $this->assertFalse($reflection->hasAnnotation('SecondAnnotation'));
 }
 public function matches($className, \ReflectionAnnotatedClass $reflection)
 {
     return $reflection->getNamespaceName() == $this->namespace;
 }
示例#29
0
 public function registerInstance($MODULE_NAME, $name, &$obj)
 {
     $name = strtolower($name);
     $this->logger->log('DEBUG', "Registering instance name '{$name}' for module '{$MODULE_NAME}'");
     if (Registry::instanceExists($name)) {
         $this->logger->log('WARN', "Instance with name '{$name}' already registered--replaced with new instance");
     }
     $obj->moduleName = $MODULE_NAME;
     Registry::setInstance($name, $obj);
     // register settings annotated on the class
     $reflection = new ReflectionAnnotatedClass($obj);
     foreach ($reflection->getProperties() as $property) {
         if ($property->hasAnnotation('Setting')) {
             $this->settingManager->add($MODULE_NAME, $property->getAnnotation('Setting')->value, $property->getAnnotation('Description')->value, $property->getAnnotation('Visibility')->value, $property->getAnnotation('Type')->value, $obj->{$property->name}, @$property->getAnnotation('Options')->value, @$property->getAnnotation('Intoptions')->value, @$property->getAnnotation('AccessLevel')->value, @$property->getAnnotation('Help')->value);
         }
     }
     // register commands, subcommands, and events annotated on the class
     $commands = array();
     $subcommands = array();
     foreach ($reflection->getAllAnnotations() as $annotation) {
         if ($annotation instanceof DefineCommand) {
             if (!$annotation->command) {
                 $this->logger->log('WARN', "Cannot parse @DefineCommand annotation in '{$name}'.");
             }
             $command = $annotation->command;
             $definition = array('channels' => $annotation->channels, 'defaultStatus' => $annotation->defaultStatus, 'accessLevel' => $annotation->accessLevel, 'description' => $annotation->description, 'help' => $annotation->help, 'handlers' => array());
             list($parentCommand, $subCommand) = explode(" ", $command, 2);
             if ($subCommand) {
                 $definition['parentCommand'] = $parentCommand;
                 $subcommands[$command] = $definition;
             } else {
                 $commands[$command] = $definition;
             }
             // register command alias if defined
             if ($annotation->alias) {
                 $this->commandAlias->register($MODULE_NAME, $command, $annotation->alias);
             }
         }
     }
     foreach ($reflection->getMethods() as $method) {
         if ($method->hasAnnotation('Setup')) {
             $this->setupHandlers[] = array($name, $method->name);
         } else {
             if ($method->hasAnnotation('HandlesCommand')) {
                 $commandName = $method->getAnnotation('HandlesCommand')->value;
                 $methodName = $method->name;
                 $handlerName = "{$name}.{$method->name}";
                 if (isset($commands[$commandName])) {
                     $commands[$commandName]['handlers'][] = $handlerName;
                 } else {
                     if (isset($subcommands[$commandName])) {
                         $subcommands[$commandName]['handlers'][] = $handlerName;
                     } else {
                         $this->logger->log('WARN', "Cannot handle command '{$commandName}' as it is not defined with @DefineCommand in '{$name}'.");
                     }
                 }
             } else {
                 if ($method->hasAnnotation('Event')) {
                     $this->eventManager->register($MODULE_NAME, $method->getAnnotation('Event')->value, $name . '.' . $method->name, @$method->getAnnotation('Description')->value, @$method->getAnnotation('Help')->value, @$method->getAnnotation('DefaultStatus')->value);
                 }
             }
         }
     }
     foreach ($commands as $command => $definition) {
         $this->commandManager->register($MODULE_NAME, $definition['channels'], implode(',', $definition['handlers']), $command, $definition['accessLevel'], $definition['description'], $definition['help'], $definition['defaultStatus']);
     }
     foreach ($subcommands as $subCommand => $definition) {
         $this->subcommandManager->register($MODULE_NAME, $definition['channels'], implode(',', $definition['handlers']), $subCommand, $definition['accessLevel'], $definition['parentCommand'], $definition['description'], $definition['help'], $definition['defaultStatus']);
     }
 }
示例#30
0
 /**
  * Define the template according to the class
  */
 public function defineTemplate($class)
 {
     if (is_string($class) && class_exists($class)) {
         $reflection = new ReflectionAnnotatedClass($class);
         $ret = array();
         $ret[] = '(deftemplate ' . $class;
         foreach (get_class_vars($class) as $slot => $v) {
             if ($reflection->getProperty($slot)->hasAnnotation('ClipsMulti')) {
                 $ret[] = '(multislot ' . $slot . ')';
             } else {
                 $ret[] = '(slot ' . $slot . ')';
             }
         }
         return implode(' ', $ret) . ')';
     }
     return false;
 }