Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(php): Add remaining php clients #106

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,6 @@

namespace Algolia\AlgoliaSearch\Configuration;

class AbTestingConfig extends Configuration
class AbTestingConfig extends ConfigWithRegion
{
public static function create($appId = null, $apiKey = null, $region = null)
{
$config = [
'appId' => null !== $appId ? $appId : getenv('ALGOLIA_APP_ID'),
'apiKey' => null !== $apiKey ? $apiKey : getenv('ALGOLIA_API_KEY'),
'region' => null !== $region ? $region : 'us',
];

return new static($config);
}

public function setRegion($region)
{
$this->config['region'] = $region;

return $this;
}

public function getRegion()
{
return $this->config['region'];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,6 @@

namespace Algolia\AlgoliaSearch\Configuration;

class AnalyticsConfig extends Configuration
class AnalyticsConfig extends ConfigWithRegion
{
public static function create($appId = null, $apiKey = null, $region = null)
{
$config = [
'appId' => null !== $appId ? $appId : getenv('ALGOLIA_APP_ID'),
'apiKey' => null !== $apiKey ? $apiKey : getenv('ALGOLIA_API_KEY'),
'region' => null !== $region ? $region : 'us',
];

return new static($config);
}

public function setRegion($region)
{
$this->config['region'] = $region;

return $this;
}

public function getRegion()
{
return $this->config['region'];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Algolia\AlgoliaSearch\Configuration;

use Algolia\AlgoliaSearch\Exceptions\AlgoliaException;

abstract class ConfigWithRegion extends Configuration
{
protected static $allowedRegions = [
'us',
damcou marked this conversation as resolved.
Show resolved Hide resolved
'de',
];

public static function create($appId = null, $apiKey = null, $region = null)
{
if ($region !== null && !in_array($region, self::$allowedRegions, true)) {
throw new AlgoliaException('Specified region is not allowed.');
}

$config = [
'appId' => null !== $appId ? $appId : getenv('ALGOLIA_APP_ID'),
'apiKey' => null !== $apiKey ? $apiKey : getenv('ALGOLIA_API_KEY'),
'region' => null !== $region ? $region : 'us',
];

return new static($config);
}

public function setRegion($region)
{
if (!in_array($region, self::$allowedRegions, true)) {
throw new AlgoliaException('Specified region is not allowed.');
}

$this->config['region'] = $region;

return $this;
}

public function getRegion()
{
return $this->config['region'];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,6 @@

namespace Algolia\AlgoliaSearch\Configuration;

class InsightsConfig extends Configuration
class InsightsConfig extends ConfigWithRegion
{
public static function create($appId = null, $apiKey = null, $region = null)
{
$config = [
'appId' => null !== $appId ? $appId : getenv('ALGOLIA_APP_ID'),
'apiKey' => null !== $apiKey ? $apiKey : getenv('ALGOLIA_API_KEY'),
'region' => null !== $region ? $region : 'us',
];

return new static($config);
}

public function setRegion($region)
{
$this->config['region'] = $region;

return $this;
}

public function getRegion()
{
return $this->config['region'];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,6 @@

namespace Algolia\AlgoliaSearch\Configuration;

class PersonalizationConfig extends Configuration
class PersonalizationConfig extends ConfigWithRegion
{
public static function create($appId = null, $apiKey = null, $region = null)
{
$config = [
'appId' => null !== $appId ? $appId : getenv('ALGOLIA_APP_ID'),
'apiKey' => null !== $apiKey ? $apiKey : getenv('ALGOLIA_API_KEY'),
'region' => null !== $region ? $region : 'us',
];

return new static($config);
}

public function setRegion($region)
{
$this->config['region'] = $region;

return $this;
}

public function getRegion()
{
return $this->config['region'];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,6 @@

namespace Algolia\AlgoliaSearch\Configuration;

class QuerySuggestionsConfig extends Configuration
class QuerySuggestionsConfig extends ConfigWithRegion
{
public static function create($appId = null, $apiKey = null, $region = null)
{
$config = [
'appId' => null !== $appId ? $appId : getenv('ALGOLIA_APP_ID'),
'apiKey' => null !== $apiKey ? $apiKey : getenv('ALGOLIA_API_KEY'),
'region' => null !== $region ? $region : 'us',
];

return new static($config);
}

public function setRegion($region)
{
$this->config['region'] = $region;

return $this;
}

public function getRegion()
{
return $this->config['region'];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,6 @@

namespace Algolia\AlgoliaSearch\Configuration;

class RecommendConfig extends Configuration
class RecommendConfig extends ConfigWithRegion
{
public static function create($appId = null, $apiKey = null, $region = null)
{
$config = [
'appId' => null !== $appId ? $appId : getenv('ALGOLIA_APP_ID'),
'apiKey' => null !== $apiKey ? $apiKey : getenv('ALGOLIA_API_KEY'),
'region' => null !== $region ? $region : 'us',
];

return new static($config);
}

public function setRegion($region)
{
$this->config['region'] = $region;

return $this;
}

public function getRegion()
{
return $this->config['region'];
}
}