/** * @param string $className * * @return array */ public function processClass($className, $path) { $reflection = new \ReflectionClass($className); if (null === $this->reader->getClassAnnotation($reflection, $this->annotationClass)) { return array(); } $mappings = array(); $this->output->writeln("Found class: {$className}"); foreach ($reflection->getMethods() as $method) { /** @var Method[] $annotations */ $annotations = $this->reader->getMethodAnnotations($method); if (0 == count($annotations)) { continue; } $this->output->writeln(sprintf("Found annotations for method %s::%s.", $method->class, $method->getName())); foreach ($annotations as $annotation) { if (!$annotation instanceof Method) { continue; } $this->output->writeln(sprintf("Found mapping: %s::%s --> %s::%s", $method->class, $method->getName(), $annotation->getClass(), $annotation->getMethod())); $mapping = new Mapping(); $moduleFile = $reflection->getFileName(); $moduleFile = substr($moduleFile, strpos($moduleFile, $path)); $mapping->setOxidClass($annotation->getClass())->setOxidMethod($annotation->getMethod())->setModuleClass($className)->setModuleMethod($method->getName())->setReturn($annotation->hasReturnValue())->setParentExecution($annotation->getParentExecution())->setModuleFile($moduleFile); $mappings[] = $mapping; } } return $mappings; }
/** * @param Mapping $mapping * * @return $this */ public function addMapping(Mapping $mapping) { $oxidClass = $mapping->getOxidClass(); $oxidMethod = $mapping->getOxidMethod(); $moduleClass = $mapping->getModuleClass(); $moduleFile = $mapping->getModuleFile(); if (!isset($this->mappings[$oxidClass])) { $this->mappings[$oxidClass] = array(); } $needNewProxy = true; foreach ($this->mappings[$oxidClass] as $proxyClass => $classMethods) { if (!isset($classMethods[$oxidMethod])) { $this->setMapping($oxidClass, $proxyClass, $oxidMethod, $moduleFile, $moduleClass, $mapping); $needNewProxy = false; break; } } if ($needNewProxy) { $proxyClass = count($this->mappings[$oxidClass]) + 1; $this->setMapping($oxidClass, $proxyClass, $oxidMethod, $moduleFile, $moduleClass, $mapping); } return $this; }