Skip to content

Instantly share code, notes, and snippets.

@hkulekci
Last active August 22, 2018 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkulekci/d809922c344f85fdfb1290e31a2393c8 to your computer and use it in GitHub Desktop.
Save hkulekci/d809922c344f85fdfb1290e31a2393c8 to your computer and use it in GitHub Desktop.
Index model for apisearch php-client
<?php
declare(strict_types=1);
namespace Apisearch\Model;
use Apisearch\Exception\InvalidFormatException;
/**
* Class Coordinate.
*/
class Index implements HttpTransportable
{
/**
* @var string
*/
private $appId;
/**
* @var string
*/
private $name;
/**
* @var integer
*/
private $docCount;
/**
* GeoPoint constructor.
*
* @param string $appId
* @param string $name
* @param int $docCount
*/
public function __construct(
string $appId,
string $name,
int $docCount = 0
) {
$this->appId = $appId;
$this->name = $name;
$this->docCount = $docCount;
}
/**
* @return string
*/
public function getAppId(): string
{
return $this->appId;
}
/**
* @param string $appId
*/
public function setAppId(string $appId): void
{
$this->appId = $appId;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name): void
{
$this->name = $name;
}
/**
* @return int
*/
public function getDocCount(): int
{
return $this->docCount;
}
/**
* @param int $docCount
*/
public function setDocCount(int $docCount = 0): void
{
$this->docCount = $docCount;
}
/**
* To array.
*
* @return array
*/
public function toArray(): array
{
return [
'appId' => $this->appId,
'name' => $this->name,
'docCount' => $this->docCount,
];
}
/**
* Create from array.
*
* @param array $array
*
* @return Coordinate
*/
public static function createFromArray(array $array): self
{
if (
!isset($array['appId']) ||
!isset($array['name'])
) {
throw InvalidFormatException::indexFormatNotValid();
}
return new self(
$array['appId'],
$array['name'],
isset($array['docCount']) ? (int)$array['docCount'] : 0
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment