/** * Create proxy class * * @param string $interface * @throws InitiallyRpcException */ public function create($interface) { if (!Util::existsDirWritable($this->config->getProxyRootDir())) { throw new InitiallyRpcException("Proxy builder error: proxy class root dir not to be write"); } $this->interface = $interface; $this->reflectionInterfaceAndCheck(); $this->service = $this->config->getServiceByKey($this->interface); $info = $this->parseProxyClassInfo(); $dir = $this->getProxyClassDirAndCreate($info->getNamespace()); $file = sprintf("%s/%s.php", $dir, $info->getClassName()); $methodString = ""; foreach ($this->refectionClass->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { $methodString .= $this->buildMethod($method); } $useString = ""; $this->useList = array_unique($this->useList); foreach ($this->useList as $value) { $useString .= "use {$value};" . PHP_EOL; } $replaces = array($info->getNamespace(), $useString, $this->refectionClass->getDocComment(), $info->getClassName(), sprintf("\\%s", $this->refectionClass->getName()), str_replace("\\", "\\\\", $this->refectionClass->getName()), $methodString); $content = str_replace(self::CLASS_TPL_SEARCHES, $replaces, $this->template->getClassTemplate()); if (!@file_put_contents($file, $content)) { throw new InitiallyRpcException("Proxy builder error: proxy class code write failed"); } $this->clear(); }
/** * Build proxy or not * * @throws \Initially\Rpc\Exception\InitiallyRpcException */ public function buildProxyOrNot() { if (!Util::existsDirWritable(INITIALLY_RPC_ROOT_PATH)) { throw new InitiallyRpcException("rpc framework root dir not to be write"); } if ($this->compareConfigFile()) { $services = $this->config->getServices(); foreach ($services as $service) { $this->builder->create($service->getInterface()); } } }