Beispiel #1
0
 /**
  * Create a new Annotations instance.
  *
  * @param mixed $reflector Either a Reflector instance, the name of a class, 
  * a doc comment or an array to use to directly populate the instance. An 
  * value that evaluates to `false` will result in an empty Annotations 
  * instance.
  * @throws ReflectorNotCommentedException If the given object is a Reflector 
  * instance but does not contain a getDocComment() method.
  * @throws InvalidArgumentException If the given parameter is an object but 
  * not a Reflector instance.
  */
 public function __construct($reflector = null)
 {
     if (!$reflector) {
         $reflector = array();
     }
     if (is_array($reflector)) {
         $this->_annotations = $reflector;
     } else {
         $docComment = self::parseDocComment($reflector);
         $this->_annotations = AnnotationParser::getAnnotations($docComment);
     }
 }
Beispiel #2
0
 /**
  * Internal helper to generate a JOIN statement.
  *
  * @param array $fields Array of fields to extend.
  * @return string The JOIN statement to append to the query string.
  */
 protected function generateJoin(array &$fields)
 {
     $annotations = $this->annotations['class'];
     $props = $this->annotations['properties'];
     $table = '';
     foreach (['Require' => '', 'Include' => 'LEFT '] as $type => $join) {
         if (isset($annotations[$type])) {
             foreach ($annotations[$type] as $local => $joinCond) {
                 if (is_numeric($local)) {
                     foreach ($joinCond as $local => $joinCond) {
                     }
                 }
                 // Hack to make the annotationParser recurse.
                 $joinCond = AnnotationParser::getAnnotations('/** @joinCond ' . implode(', ', $joinCond) . ' */')['joincond'];
                 $table .= sprintf(' %1$sJOIN %2$s ON ', $join, $local);
                 $conds = [];
                 foreach ($joinCond as $ref => $me) {
                     if ($me == '?') {
                         $conds[] = sprintf("%s.%s = {$me}", $local, $ref);
                     } else {
                         $conds[] = sprintf("%s.%s = %s.%s", $local, $ref, $this->identifier, $me);
                     }
                 }
                 $table .= implode(" AND ", $conds);
             }
         }
     }
     foreach ($fields as &$field) {
         $name = str_replace("{$this->identifier}.", '', $field);
         if (isset($props[$name]['From'])) {
             $field = sprintf('%s %s', $props[$name]['From'], $name);
         }
     }
     return $table;
 }