Build from a live endpoint

@param string Swagger compliant JSON endpoint for resource listing

@throws \Exception
@return Swizzle
544282
public function build($baseUri)
    {
        $this->serviceDescription = null;
        $client = SwaggerClient::factory(['base_uri' => $baseUri]);
        $this->debug('Fetching resource listing from %s', $baseUri);
        $listing = $client->getResources();

        // check this looks like a resource listing
        if (!$listing->isSwagger()) {
            throw new \RuntimeException("This doesn't look like a Swagger spec");
        }
        if (!$listing->getApis()) {
            $this->logger->addAlert("Resource listing doesn't define any APIs");
        }
        // check swagger version
        if (self::SWAGGER_VERSION !== $listing->getSwaggerVersion()) {
            throw new \RuntimeException('Unsupported Swagger version, Swizzle expects '.self::SWAGGER_VERSION);
        }
        // Declared version overrides anything we've set
        if ($version = $listing->getApiVersion()) {
            $this->debug('+ set apiVersion %s', $version);
            $this->setApiVersion($version);
        }
        // Set description if missing from constructor
        if (empty($this->init['description'])) {
            $info = $listing->getInfo();
            $this->init['description'] = $info['description'] ?: $this->init['title'];
        }
        // set base path from docs location if not provided
        if (empty($this->init['baseUri'])) {
            $this->init['baseUri'] = self::mergeUrl('/', $baseUri);
        }
        // no more configs allowed now, Guzzle service gets constructed
        $service = $this->getServiceDescription();
        // ready to pull each api declaration
        foreach ($listing->getApiPaths() as $path) {
            if ($this->delay) {
                usleep($this->delay);
            }
            // @todo do proper path resolution here, allowing a cross-domain spec.
            $path = rtrim(parse_url($baseUri)['path'], '/').'/'.ltrim($path, '/');
            $this->debug('pulling %s ...', $path);
            $apiDeclaration = $client->getDeclaration(compact('path'));
            foreach ($apiDeclaration->getModels() as $model) {
                $this->addModel($model);
            }
            // Ensure a fully qualified base url for this api
            $baseUrl = self::mergeUrl($apiDeclaration->getBasePath(), $service->getBaseUri());
            // add each api against required base url
            foreach ($apiDeclaration->getApis() as $api) {
                $this->addApi($api, $baseUrl);
            }
        }
        $this->debug('finished');
        return $this;
    }
1302769
public static function buildAsync(
        $host,
        $port,
        $user,
        $pass,
        $exchangeName,
        $escapeMode = self::ESCAPE_MODE_SERIALIZE,
        $timeout = 0
    ) {
        return self::build($host, $port, $user, $pass, $exchangeName, false, $escapeMode, $timeout);
    }
797824
public function build($json)
    {
        $contract = \GuzzleHttp\json_decode($json, true);
        if (!isset($contract['protocol'])) {
            throw new \InvalidArgumentException('Invalid contract; Protocol is not specified');
        }

        return $this->getBuilder($contract['protocol'])->build($contract);
    }
143576
public function build(): HighlightNodeRequest
	{
		$instance = new HighlightNodeRequest();
		if ($this->highlightConfig === null) {
			throw new BuilderException('Property [highlightConfig] is required.');
		}
		$instance->highlightConfig = $this->highlightConfig;
		$instance->nodeId = $this->nodeId;
		$instance->backendNodeId = $this->backendNodeId;
		$instance->objectId = $this->objectId;
		$instance->selector = $this->selector;
		return $instance;
	}
836542
public function build(): FailRequestRequest
	{
		$instance = new FailRequestRequest();
		if ($this->requestId === null) {
			throw new BuilderException('Property [requestId] is required.');
		}
		$instance->requestId = $this->requestId;
		if ($this->errorReason === null) {
			throw new BuilderException('Property [errorReason] is required.');
		}
		$instance->errorReason = $this->errorReason;
		return $instance;
	}
1284468
public static function build($apiKey)
    {
        self::$apiKey          = $apiKey;
        static::$cachedFactory = new ServiceBuilderLoader();

        return parent::factory(__DIR__.'/Resources/clients.json');
    }
530125
private function build(string $name)
    {
        $instance = null;
        $map = $this->map[$name];

        if (is_array($map)) {
            $params = $this->getParamsFromMap($map);
            $instance = new $name(...$params);
        } elseif ($map instanceof \Closure) {
            $instance = $map($this);
        } elseif (is_object($map)) {
            $instance = $map;
        } elseif (is_string($map)) {
            $instance = $this->get($map);
        } else {
            throw new \Exception('Invalid map');
        }

        return $instance;
    }
715290
private function buildUpdateAction() {
        $api = new Swagger\Api();
        $api->setPath('/' . $this->getClassName() . '/{id}');
        $operation = new Swagger\Operation();
        $operation->setMethod('PUT');
        $operation->setSummary('Update ' . $this->singularModelA_Or_An() . '.');
        $operation->setNotes('Update ' . $this->singularModelA_Or_An() . '.');

        $operation->addParameter($this->buildIdParameter());
        $operation->addParameter($this->buildFieldsParameter());

        $parameter = new Swagger\Parameter();
        $parameter->setName('body');
        $parameter->setDescription($this->getPutPostBodyDescription(false));
        $parameter->setParamType('body');
        $parameter->setType($this->getClassName());
        $operation->addParameter($parameter);

        $responseMessage = new Swagger\ResponseMessage();
        $responseMessage->setCode(200);
        $responseMessage->setMessage(ucfirst($this->getModel()->getSource()) . ' was updated.');
        $responseMessage->setResponseModel($this->getClassName());
        $operation->addResponseMessage($responseMessage);

        $responseMessage = new Swagger\ResponseMessage();
        $responseMessage->setCode(304);
        $responseMessage->setMessage(ucfirst($this->getModel()->getSource()) . ' was not changed.');
        $operation->addResponseMessage($responseMessage);

        $responseMessage = $this->invalidFieldSpecifiedError();
        $operation->addResponseMessage($responseMessage);

        $responseMessage = $this->notAuthorizedResponse();
        $operation->addResponseMessage($responseMessage);

        $responseMessage = $this->notFoundResponse();
        $operation->addResponseMessage($responseMessage);

        $responseMessage = $this->invalidValuePassed();
        $operation->addResponseMessage($responseMessage);

        $api->addOperation($operation);
        $method = new Object\Method();
        $method->setDescription($api->__toString());
        $method->setReturnType('void');
        $method->setAccess('public');
        $method->setName('updateAction');
        $method->setContent('parent::updateAction();');
        $this->getObject()->addMethod($method);
    }
1224584
public function build(): DispatchSyncEventRequest
	{
		$instance = new DispatchSyncEventRequest();
		if ($this->origin === null) {
			throw new BuilderException('Property [origin] is required.');
		}
		$instance->origin = $this->origin;
		if ($this->registrationId === null) {
			throw new BuilderException('Property [registrationId] is required.');
		}
		$instance->registrationId = $this->registrationId;
		if ($this->tag === null) {
			throw new BuilderException('Property [tag] is required.');
		}
		$instance->tag = $this->tag;
		if ($this->lastChance === null) {
			throw new BuilderException('Property [lastChance] is required.');
		}
		$instance->lastChance = $this->lastChance;
		return $instance;
	}
384166
public function build(): ReleaseAnimationsRequest
	{
		$instance = new ReleaseAnimationsRequest();
		if ($this->animations === null) {
			throw new BuilderException('Property [animations] is required.');
		}
		$instance->animations = $this->animations;
		return $instance;
	}
222422
private function build() {
        $this->getObject()->addUse('Bullhorn\FastRest\Api\Models\ApiInterface as ModelInterface');
        $this->getObject()->setName(ucfirst(strtolower($this->getClassName())) . 'Controller');
        $this->getObject()->setNamespace($this->getConfiguration()->getRootNamespace() . '\Controllers');
        $this->getObject()->setExtends('ControllerBase');
        $this->buildFactory();
        $this->buildIndexAction();
        $this->buildShowAction();
        $this->buildCreateAction();
        $this->buildUpdateAction();
        $this->buildDeleteAction();
        $this->buildDocumentation();
    }
358976
public function build(): TakeResponseBodyAsStreamRequest
	{
		$instance = new TakeResponseBodyAsStreamRequest();
		if ($this->requestId === null) {
			throw new BuilderException('Property [requestId] is required.');
		}
		$instance->requestId = $this->requestId;
		return $instance;
	}
674405
public function build(): DeliverPushMessageRequest
	{
		$instance = new DeliverPushMessageRequest();
		if ($this->origin === null) {
			throw new BuilderException('Property [origin] is required.');
		}
		$instance->origin = $this->origin;
		if ($this->registrationId === null) {
			throw new BuilderException('Property [registrationId] is required.');
		}
		$instance->registrationId = $this->registrationId;
		if ($this->data === null) {
			throw new BuilderException('Property [data] is required.');
		}
		$instance->data = $this->data;
		return $instance;
	}
271794
public function build(): RequestCachedResponseRequest
	{
		$instance = new RequestCachedResponseRequest();
		if ($this->cacheId === null) {
			throw new BuilderException('Property [cacheId] is required.');
		}
		$instance->cacheId = $this->cacheId;
		if ($this->requestURL === null) {
			throw new BuilderException('Property [requestURL] is required.');
		}
		$instance->requestURL = $this->requestURL;
		if ($this->requestHeaders === null) {
			throw new BuilderException('Property [requestHeaders] is required.');
		}
		$instance->requestHeaders = $this->requestHeaders;
		return $instance;
	}
764381
public function build(): CompileScriptRequest
	{
		$instance = new CompileScriptRequest();
		if ($this->expression === null) {
			throw new BuilderException('Property [expression] is required.');
		}
		$instance->expression = $this->expression;
		if ($this->sourceURL === null) {
			throw new BuilderException('Property [sourceURL] is required.');
		}
		$instance->sourceURL = $this->sourceURL;
		if ($this->persistScript === null) {
			throw new BuilderException('Property [persistScript] is required.');
		}
		$instance->persistScript = $this->persistScript;
		$instance->executionContextId = $this->executionContextId;
		return $instance;
	}
1223838
private static function build(
        $host,
        $port,
        $user,
        $pass,
        $exchangeName,
        $sync,
        $escapeMode,
        $timeout
    ) {
        $driver = DriverFactory::getDriver([
            'host' => $host,
            'port' => $port,
            'user' => $user,
            'pwd'  => $pass
        ]);

        $publisher = ($sync) ?
            new SyncPublisher($driver, $exchangeName, $timeout):
            new AsyncPublisher($driver, $exchangeName);

        if ($escapeMode === self::ESCAPE_MODE_NONE) {
            return $publisher;
        }

        if ($escapeMode === self::ESCAPE_MODE_JSON) {
            return new SerializingPublisher($publisher, new JsonSerializer());
        }

        if ($escapeMode === self::ESCAPE_MODE_SERIALIZE) {
            return new SerializingPublisher($publisher, new PhpSerializer());
        }

        throw new \InvalidArgumentException('Bad serializer name');
    }
880908
public function build($index, $default = null, $params = [])
    {
        $class = $this->get($index, $default);
        if (!class_exists($class)) {
            throw new \Exception('Class doesn\'t exist for the index : ' .$index);
        }

        $class = new \ReflectionClass($class);
        return $class->newInstanceArgs($params);
    }