Beispiel #1
0
 public function assertReflFunctionEquals($expected, $name)
 {
     $refl = new \ReflectionFunction(__NAMESPACE__ . '\\' . $name);
     $this->assertEquals($expected, Reflector::parameters($refl->getParameters()));
 }
 /**
  * Build parameters with data recovered by the driver.
  *
  * @param string $className
  *
  * @return array
  */
 protected function buildParameters($className)
 {
     /** @var \Pok\PoolDBM\Mapping\ClassMetadata $metadata */
     $metadata = $this->getModelManager()->getClassMetadata($className);
     $managers = array();
     foreach ($metadata->getFieldMappings() as $model) {
         $managers[$model->getManagerName()] = array('namespace' => '\\' . $model->getName(), 'methods' => array());
         $fields = $model->getFields();
         if ($metadata->getManagerIdentifier() === $model->getManagerName()) {
             $fields[] = $metadata->getFieldIdentifier();
         }
         $pattern = self::patternDeclared($fields);
         $refl = new \ReflectionClass($model->getName());
         foreach ($refl->getMethods() as $method) {
             if (!$method->isPublic() || $method->isStatic() || $method->isConstructor() || $method->isDestructor() || $method->isAbstract()) {
                 continue;
             }
             preg_match($pattern, $method->getName(), $matches);
             if (empty($matches)) {
                 continue;
             }
             $arg = array('comment' => $method->getDocComment(), 'name' => $method->getName(), 'type' => in_array($matches[1], array('get', 'is', 'has', 'all', 'check')) ? 'getter' : 'setter', 'arguments' => Reflector::parameters($method->getParameters()), 'parameters' => $method->getParameters());
             $managers[$model->getManagerName()]['methods'][] = $arg;
         }
     }
     $associations = new Bag();
     foreach ($metadata->getAssociationDefinitions() as $definition) {
         if ($definition->isMany()) {
             $associations->many[$definition->getField()] = array('fields' => $definition->getReferences(), 'className' => $definition->getTargetMultiModel());
         } else {
             $associations->one[$definition->getField()] = array('className' => $definition->getTargetMultiModel());
         }
     }
     $occ = strrpos($metadata->getName(), '\\');
     return array('model_namespace' => substr($metadata->getName(), 0, $occ), 'model_name' => substr($metadata->getName(), $occ + 1), 'managers' => $managers, 'associations' => $associations);
 }