code
stringlengths 52
7.75k
| docs
stringlengths 1
5.85k
|
---|---|
public function afterSpec(Spec $spec)
{
if ($spec->isFailed()) {
$this->failures[] = $spec;
$title = $this->formatter->red($spec);
} elseif ($spec->isIncomplete()) {
$this->incompleteSpecs[] = $spec;
$title = $this->formatter->cyan($spec);
} elseif ($spec->isPending()) {
$this->pendingSpecs[] = $spec;
$title = $this->formatter->yellow($spec);
} else {
$title = $this->formatter->grey($spec);
}
$this->console->writeLn($title);
}
|
Ran after an individual spec. May be used to display the results of that
particular spec.
@param Spec $spec The spec after which to run this method
|
protected function handleHookFailure(Hook $hook)
{
$this->failures[] = $hook;
$title = $this->formatter->red($hook);
$this->console->writeLn($title);
}
|
If a given hook failed, adds it to list of failures and prints the
result.
@param Hook $hook The failed hook
|
public function match($subject)
{
$this->subject = $subject;
$suffixLength = strlen($this->suffix);
if (!$suffixLength) {
return true;
}
return (substr($subject, -$suffixLength) === $this->suffix);
}
|
Returns true if the subject ends with the given suffix, false otherwise.
@param mixed $subject The string to test
@return boolean Whether or not the string contains the suffix
|
public function write($name, $eventObjectTable, $actionTiming, $event, $path)
{
$this->ensureMigrationDoesntAlreadyExist($name);
$stub = $this->files->get($this->stubPath().'/create.stub');
$this->files->put(
$path = $this->getPath($name, $path),
$this->populate($name, $eventObjectTable, $actionTiming, $event, $stub)
);
return $path;
}
|
Create a new migration at the given path.
@param string $name
@param string $eventObjectTable
@param string $actionTiming
@param string $event
@param string|null $path
@return string
|
protected function populate($name, $eventObjectTable, $actionTiming, $event, $stub)
{
$stub = str_replace('DummyClass', $this->getClassName($name), $stub);
$stub = str_replace('DummyName', $name, $stub);
$stub = str_replace('DummyEventObjectTable', $eventObjectTable, $stub);
$stub = str_replace('DummyActionTiming', $actionTiming, $stub);
$stub = str_replace('DummyEvent', $event, $stub);
return $stub;
}
|
Populate migration stub.
@param string $name
@param string $eventObjectTable
@param string $actionTiming
@param string $event
@param string $stub
@return string;
|
public function getConsoleOption($name)
{
if (isset($this->options[$name])) {
return $this->options[$name];
}
foreach ($this->options as $option) {
$longName = $option->getLongName();
$shortName = $option->getShortName();
if ($name == $longName || $name == $shortName) {
return $option;
}
}
}
|
Returns the ConsoleOption object either found at the key with the supplied
name, or whose short name or long name matches.
@param string $name The name, shortName, or longName of the option
@return ConsoleOption The option matching the supplied name, if it exists
|
public function getOptions()
{
$options = [];
foreach ($this->options as $name => $option) {
$options[$name] = $option->getValue();
}
return $options;
}
|
Returns an associative array consisting of the names of the ConsoleOptions
added to the parser, and their values.
@return array The names of the options and their values
|
public function addOption($name, $longName, $shortName, $description,
$argumentName = null)
{
$this->options[$name] = new ConsoleOption($longName, $shortName,
$description, $argumentName);
}
|
Adds a new option to be parsed by the ConsoleOptionParser by creating
a new ConsoleOption with the supplied longName, shortName, description
and optional argumentName. The object is stored in an associative array,
using $name as the key.
@param string $name The name of the option, to be used as a key
@param string $longName Long name of the option, including the two
preceding dashes.
@param string $shortName Short name of the option: a single
alphabetical character preceded by a dash.
@param string $description Brief description of the option.
@param string $argumentName Human readable name for the argument
|
public function getOptionNames()
{
$names = [];
foreach ($this->options as $option) {
$names[] = $option->getLongName();
$names[] = $option->getShortName();
}
return $names;
}
|
Returns an array containing the long and short names of all options.
@return array The short and long names of the options
|
public function parseArguments($args)
{
// Loop over options
for ($i = 0; $i < count($args); $i++) {
if (!in_array($args[$i], $this->getOptionNames())) {
// The option isn't defined
if (strpos($args[$i], '-') === 0) {
$this->invalidArguments[] = $args[$i];
}
break;
}
// It's a valid option and accepts arguments, add the next argument
// as its value. Otherwise, just set the option to true
$option = $this->getConsoleOption($args[$i]);
if ($option->acceptsArguments()) {
if (isset($args[$i+1])) {
$option->setValue($args[$i + 1]);
$i++;
}
} else {
$option->setValue(true);
}
}
// The rest of the arguments are assumed to be paths
if (!$this->invalidArguments && $i < count($args)) {
$this->paths = array_slice($args, $i);
}
}
|
Parses the supplied arguments, assigning their values to the stored
ConsoleOptions. If an option accepts arguments, then any following
argument is assigned as its value. Otherwise, the option is merely
a flag, and its value is set to true. Any arguments containing a dash as
their first character are assumed to be an option, and if invalid,
are stored in the $invalidOptions array.
@param array An array of strings corresponding to the console arguments
|
public function match($callable)
{
try {
$callable();
} catch(\Exception $exception) {
$this->thrown = $exception;
}
return ($this->thrown instanceof $this->expected);
}
|
Compares the exception thrown by the callable, if any, to the expected
exception. Returns true if an exception of the expected class is thrown,
false otherwise.
@param callable $callable The function to invoke
@return boolean Whether or not the function threw the expected exception
|
public function getFailureMessage($negated = false)
{
$explanation = 'none thrown';
if ($this->thrown) {
$class = get_class($this->thrown);
$explanation = "got $class";
}
if (!$negated) {
return "Expected {$this->expected} to be thrown, {$explanation}";
} else {
return "Expected {$this->expected} not to be thrown";
}
}
|
Returns an error message indicating why the match failed, and the
negation of the message if $negated is true.
@param boolean $negated Whether or not to print the negated message
@return string The error message
|
public function syncStripeFromLocal(ApiResource $stripeResource, StripeLocalResourceInterface $localResource)
{
/** @var Charge $stripeResource */
if ( ! $stripeResource instanceof Charge) {
throw new \InvalidArgumentException('ChargeSyncer::hydrateStripe() accepts only Stripe\Charge objects as first parameter.');
}
/** @var StripeLocalCharge $localResource */
if ( ! $localResource instanceof StripeLocalCharge) {
throw new \InvalidArgumentException('ChargeSyncer::hydrateStripe() accepts only StripeLocalCharge objects as second parameter.');
}
throw new \RuntimeException('Method not yet implemented');
}
|
{@inheritdoc}
|
public function getFailureMessage($negated = false)
{
$actual = $this->getStringValue($this->actual);
$expected = $this->getStringValue($this->expected);
if (!$negated) {
return "Expected $actual to equal $expected";
} else {
return "Expected $actual not to equal $expected";
}
}
|
Returns an error message indicating why the match failed, and the
negation of the message if $negated is true.
@param boolean $negated Whether or not to print the negated message
@return string The error message
|
public static function getJsonApiHandler($login, $transaction_key, $server = self::USE_AKAMAI_SERVER)
{
$login = trim($login);
$transaction_key = trim($transaction_key);
$api_url = static::getWebServiceURL($server);
if (empty($login) || empty($transaction_key)) {
throw new AuthnetInvalidCredentialsException('You have not configured your login credentials properly.');
}
$curl = new Curl();
$curl->setOpt(CURLOPT_RETURNTRANSFER, true);
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
$curl->setOpt(CURLOPT_HEADER, false);
$curl->setHeader('Content-Type', 'text/json');
$object = new AuthnetJsonRequest($login, $transaction_key, $api_url);
$object->setProcessHandler($curl);
return $object;
}
|
Validates the Authorize.Net credentials and returns a Request object to be used to make an API call
@param string $login Authorize.Net API Login ID
@param string $transaction_key Authorize.Net API Transaction Key
@param integer $server ID of which server to use (optional)
@return \JohnConde\Authnet\AuthnetJsonRequest
@throws \ErrorException
@throws \JohnConde\Authnet\AuthnetInvalidCredentialsException
@throws \JohnConde\Authnet\AuthnetInvalidServerException
|
protected static function getWebServiceURL($server)
{
$urls = [
static::USE_PRODUCTION_SERVER => 'https://api.authorize.net/xml/v1/request.api',
static::USE_DEVELOPMENT_SERVER => 'https://apitest.authorize.net/xml/v1/request.api',
static::USE_AKAMAI_SERVER => 'https://api2.authorize.net/xml/v1/request.api'
];
if (array_key_exists($server, $urls)) {
return $urls[$server];
}
throw new AuthnetInvalidServerException('You did not provide a valid server.');
}
|
Gets the API endpoint to be used for a JSON API call
@param integer $server ID of which server to use
@return string The URL endpoint the request is to be sent to
@throws \JohnConde\Authnet\AuthnetInvalidServerException
|
public static function getSimHandler($login, $transaction_key, $server = self::USE_PRODUCTION_SERVER)
{
$login = trim($login);
$transaction_key = trim($transaction_key);
$api_url = static::getSimURL($server);
if (empty($login) || empty($transaction_key)) {
throw new AuthnetInvalidCredentialsException('You have not configured your login credentials properly.');
}
return new AuthnetSim($login, $transaction_key, $api_url);
}
|
Validates the Authorize.Net credentials and returns a SIM object to be used to make a SIM API call
@param string $login Authorize.Net API Login ID
@param string $transaction_key Authorize.Net API Transaction Key
@param integer $server ID of which server to use (optional)
@return \JohnConde\Authnet\AuthnetSim
@throws \JohnConde\Authnet\AuthnetInvalidCredentialsException
@throws \JohnConde\Authnet\AuthnetInvalidServerException
|
protected static function getSimURL($server)
{
if ($server === static::USE_PRODUCTION_SERVER) {
$url = 'https://secure2.authorize.net/gateway/transact.dll';
} else if ($server === static::USE_DEVELOPMENT_SERVER) {
$url = 'https://test.authorize.net/gateway/transact.dll';
} else {
throw new AuthnetInvalidServerException('You did not provide a valid server.');
}
return $url;
}
|
Gets the API endpoint to be used for a SIM API call
@param integer $server ID of which server to use
@return string The URL endpoint the request is to be sent to
@throws \JohnConde\Authnet\AuthnetInvalidServerException
|
public static function getWebhooksHandler($login, $transaction_key, $server = self::USE_PRODUCTION_SERVER)
{
$login = trim($login);
$transaction_key = trim($transaction_key);
$api_url = static::getWebhooksURL($server);
if (empty($login) || empty($transaction_key)) {
throw new AuthnetInvalidCredentialsException('You have not configured your login credentials properly.');
}
$base64credentials = base64_encode(sprintf('%s:%s', $login, $transaction_key));
$curl = new Curl();
$curl->setOpt(CURLOPT_RETURNTRANSFER, true);
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
$curl->setOpt(CURLOPT_HEADER, false);
$curl->setHeader('Content-Type', 'application/json');
$curl->setHeader('Authorization', sprintf('Basic %s', $base64credentials));
$object = new AuthnetWebhooksRequest($api_url);
$object->setProcessHandler($curl);
return $object;
}
|
Validates the Authorize.Net credentials and returns a Webhooks Request object to be used to make an Webhook call
@param string $login Authorize.Net API Login ID
@param string $transaction_key Authorize.Net API Transaction Key
@param integer $server ID of which server to use (optional)
@throws \ErrorException
@return \JohnConde\Authnet\AuthnetWebhooksRequest
@throws \JohnConde\Authnet\AuthnetInvalidCredentialsException
@throws \JohnConde\Authnet\AuthnetInvalidServerException
|
protected static function getWebhooksURL($server)
{
if ($server === static::USE_PRODUCTION_SERVER) {
$url = 'https://api.authorize.net/rest/v1/';
} else if ($server === static::USE_DEVELOPMENT_SERVER) {
$url = 'https://apitest.authorize.net/rest/v1/';
} else {
throw new AuthnetInvalidServerException('You did not provide a valid server.');
}
return $url;
}
|
Gets the API endpoint to be used for a SIM API call
@param integer $server ID of which server to use
@return string The URL endpoint the request is to be sent to
@throws \JohnConde\Authnet\AuthnetInvalidServerException
|
public function syncStripeFromLocal(ApiResource $stripeResource, StripeLocalResourceInterface $localResource)
{
/** @var Subscription $stripeResource */
if ( ! $stripeResource instanceof Subscription) {
throw new \InvalidArgumentException('SubscriptionSyncer::hydrateStripe() accepts only Stripe\Subscription objects as first parameter.');
}
/** @var StripeLocalSubscription $localResource */
if ( ! $localResource instanceof StripeLocalSubscription) {
throw new \InvalidArgumentException('SubscriptionSyncer::hydrateStripe() accepts only StripeLocalSubscription objects as second parameter.');
}
throw new \RuntimeException('Method not yet implemented');
}
|
{@inheritdoc}
|
public function removeLocal(StripeLocalResourceInterface $localResource)
{
$this->getEntityManager()->remove($localResource);
$this->getEntityManager()->flush();
}
|
{@inheritdoc}
|
private function validateEvent(Blueprint $blueprint)
{
if (! in_array(strtolower($blueprint->event), $this->events)) {
throw new InvalidArgumentException("Cannot use {$blueprint->event} as trigger event.");
}
return $blueprint->event;
}
|
Validate event.
@param string $event
@return string
|
private function validateActionTiming(Blueprint $blueprint)
{
if (! in_array(strtolower($blueprint->actionTiming), $this->actionTimes)) {
throw new InvalidArgumentException("Cannot use {$blueprint->actionTiming} as trigger action timing.");
}
return $blueprint->actionTiming;
}
|
Validate action time.
@param string $actionTime
@return string
|
public static function create(base $db = null)
{
if ($db === null) {
$db = GnfConnectionProvider::getConnection(PlatformConnectionGroup::PLATFORM_WRITE);
}
return new static($db);
}
|
@param base $db
@return static
|
public static function xml2array($xmlstring)
{
$result = [];
self::normalizeSimpleXML(simplexml_load_string($xmlstring, null, LIBXML_NOCDATA), $result);
return $result;
}
|
TODO ArrayUtil ๋ง๋ค์ด์ ์ด๋ && method ์ค๋ช
์ถ๊ฐํ ๊ฒ
@see http://php.net/manual/en/class.simplexmlelement.php
@param $xmlstring string
@return array
|
private static function normalizeSimpleXML($obj, &$result)
{
$data = $obj;
if (is_object($data)) {
$data = get_object_vars($data);
}
if (is_array($data)) {
foreach ($data as $key => $value) {
$res = null;
self::normalizeSimpleXML($value, $res);
if (($key == '@attributes') && ($key)) {
$result = $res;
} else {
$result[$key] = $res;
}
}
} else {
$result = $data;
}
}
|
TODO ArrayUtil ๋ง๋ค์ด์ ์ด๋ && method ์ค๋ช
์ถ๊ฐํ ๊ฒ
@param $obj
@param $result
|
public static function implodeByChunk($glue_in_chunk, $glue_between_chunks, $chunk_size, array $pieces)
{
if (count($pieces) % $chunk_size !== 0) {
throw new \Exception('chunk size error');
}
$result = '';
// ๊ตฌ๋ถ์ ํผ๋๋ฐฉ์ง๋ฅผ ์ํ replace
foreach ($pieces as &$str) {
$str = str_replace($glue_in_chunk, '', $str);
$str = str_replace($glue_between_chunks, '', $str);
}
$rows = array_chunk($pieces, $chunk_size);
foreach ($rows as $row) {
if (!array_filter($row)) {
continue;
}
$result .= trim(implode($glue_in_chunk, $row)) . $glue_between_chunks;
}
return trim($result);
}
|
๋ฐฐ์ด์ chunk๋ก ๋๋์ด implode ์ํจ๋ค.
ex) ['A1', 'A2', 'A3', 'B1', 'B2', 'B3']์ ๋ฐฐ์ด์์
(';', "\n", 3, $pieces) => "A1;A2;A3\nB1;B2;B3"
@param string $glue_in_chunk chunk ๋ด๋ถ์์์ ๊ตฌ๋ถ์
@param string $glue_between_chunks chunk ๋ผ๋ฆฌ์ ๊ตฌ๋ถ์
@param int $chunk_size chunk ๋ด๋ถ ์ฌ์ด์ฆ
@param array $pieces
@return string
@throws \Exception
|
public static function swapTwoSubStrings($string, $sub_string1, $sub_string2)
{
$length = strlen($string);
for ($i = 0; $i <= $length; $i++) {
if (substr($string, $i, strlen($sub_string1)) == $sub_string1) {
$string = substr_replace($string, $sub_string2, $i, strlen($sub_string1));
$length -= strlen($sub_string1);
$length += strlen($sub_string2);
$i += strlen($sub_string2) - 1; // for๋ฌธ๋ด์์ $i++์ด๊ธฐ์
} elseif (substr($string, $i, strlen($sub_string2)) == $sub_string2) {
$string = substr_replace($string, $sub_string1, $i, strlen($sub_string2));
$length -= strlen($sub_string2);
$length += strlen($sub_string1);
$i += strlen($sub_string1) - 1; // for๋ฌธ๋ด์์ $i++์ด๊ธฐ์
}
}
return $string;
}
|
๋ ๋ฌธ์์ด์ ์๋ก ์นํํ๋ค.
ex) <b><b> => <b><b>
@param string $string
@param string $sub_string1
@param string $sub_string2
@return string
|
public function importFromRequest($request)
{
$reflect = new ReflectionClass(get_called_class());
$properties = $reflect->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED);
foreach ($properties as $property) {
$property->setValue($this, $request->get($property->getName()));
}
}
|
Request class๋ฅผ ์ด์ฉํ์ฌ ํด๋์ค๋ฅผ ์ด๊ธฐํํ๋ค.
@param Request $request
@internal public ์ด ์๋ protected ๋ก ๋ณ๊ฒฝํ์
|
public function importFromStdClass($stdClass)
{
$reflect = new ReflectionClass(get_called_class());
$properties = $reflect->getDefaultProperties();
foreach ($properties as $key => $value) {
$this->{$key} = $stdClass->{$key};
}
}
|
stdClass ์ผ ๊ฒฝ์ฐ ํด๋์ค ์ด๊ธฐํ
@param \stdClass $stdClass
@internal public ์ด ์๋ protected ๋ก ๋ณ๊ฒฝํ์
|
public function importFromInterface($reader)
{
$reflect = new ReflectionClass(get_called_class());
$default_properties = $reflect->getDefaultProperties();
foreach ($default_properties as $key => $value) {
if (method_exists($reader, $key)) {
$this->{$key} = $reader->$key();
}
}
}
|
interface์ function์ ๊ฐ์ ธ์ ํด๋์ค๋ฅผ ์ด๊ธฐํ ํ๋ค.
@param $reader
@deprecated UniversalBookReader ๋ฅผ ์์๋ฐ์ ๊ตฌํํ ๊ฒ
|
public function importFromArray($array)
{
if (!is_array($array)) {
throw new \Exception('invalid array');
}
$reflect = new ReflectionClass(get_called_class());
$properties = $reflect->getDefaultProperties();
foreach ($properties as $key => $value) {
if (array_key_exists($key, $array)) {
$this->{$key} = $array[$key];
}
}
}
|
๋ฐฐ์ด์ ์ด์ฉํ์ฌ ํด๋์ค๋ฅผ ์ด๊ธฐํํ๋ค
@param array $array
@throws \Exception
@internal public ์ด ์๋ protected ๋ก ๋ณ๊ฒฝํ์
|
public function exportAsArray()
{
$reflect = new ReflectionClass(get_called_class());
$reflect_parent = $reflect->getParentClass();
$default_properties = $reflect->getDefaultProperties();
$columns = [];
foreach ($default_properties as $key => $value) {
if ($reflect_parent->hasProperty($key)) {
// ๋ถ๋ชจ ํด๋์ค์ properties๋ ๋ฌด์ํ๋ค.
continue;
}
$columns = array_merge($columns, [$key => $this->{$key}]);
}
return $columns;
}
|
ํจ์๋ฅผ ํธ์ถํ ํด๋์ค์ ๊ธฐ๋ณธ ๋ฉค๋ฒ๋ณ์๋ง์(๋์ , ๋ถ๋ชจ ๋ฉค๋ฒ๋ณ์ ์ ์ธ) ๋ฆฌํดํ๋ค.
@return array
@internal public ์ด ์๋ protected ๋ก ๋ณ๊ฒฝํ์
|
public function exportAsArrayExceptNull()
{
$columns = $this->exportAsArray();
foreach ($columns as $key => $value) {
if ($value === null) {
unset($columns[$key]);
}
}
return $columns;
}
|
ํจ์๋ฅผ ํธ์ถํ ํด๋์ค์ ๊ธฐ๋ณธ ๋ฉค๋ฒ๋ณ์๋งํผ(๋์ , ๋ถ๋ชจ ๋ฉค๋ฒ๋ณ์ ์ ์ธ) ๋ฆฌํดํ๋ค.
๋จ, Null๊ฐ์ ๊ฐ์ง column์ ์ ์ธํ๋ค.
@return array
@internal public ์ด ์๋ protected ๋ก ๋ณ๊ฒฝํ์
@deprecated use exportAsArray
|
private static function getProperty()
{
$class = get_called_class();
if (!isset(self::$property_cache[$class])) {
$reflect = new ReflectionClass($class);
self::$property_cache[$class] = $reflect->getProperty($reflect->getShortName());
}
return self::$property_cache[$class];
}
|
Array ์ด๋ฆ์ด ํด๋์ค ์ด๋ฆ๊ณผ ๊ฐ์์ผ ํ๋ค.
@return \ReflectionProperty
|
public static function checkNumberField($field, $msg)
{
if ((StringUtils::isEmpty($field) === false) && !is_numeric($field)) {
throw new MsgException($msg);
}
}
|
์
๋ ฅ๋ ํ๋๊ฐ ์ซ์๊ฐ ์๋ ๊ฒฝ์ฐ exception
@param $field
@param string $msg
@throws \Ridibooks\Exception\MsgException
|
public static function checkMinLength($field, $minLength, $msg)
{
if ((StringUtils::isEmpty($field) === false) && mb_strlen($field) < $minLength) {
throw new MsgException($msg);
}
}
|
์
๋ ฅ๋ ํ๋์ ์ต์ ๊ธธ์ด๋ณด๋ค ์์ ๊ฒฝ์ฐ exception
@param object $field
@param int $minLength
@param string $msg
@throws \Ridibooks\Exception\MsgException
|
public static function checkLength($field, $length, $msg)
{
if ((StringUtils::isEmpty($field) === false) && mb_strlen($field) != $length) {
throw new MsgException($msg);
}
}
|
์
๋ ฅ๋ ํ๋์ ๊ธธ์ด๊ฐ ์ ํด์ง ๊ธธ์ด์ ๋ค๋ฅผ ๊ฒฝ์ฐ exception
@param object $field
@param int $length
@param string $msg
@throws \Ridibooks\Exception\MsgException
|
public static function checkDatetimeFormat($field, $format, $msg)
{
$date = date($format, strtotime($field));
if ($field !== $date) {
throw new MsgException($msg);
}
}
|
์
๋ ฅ๋ ํ๋์ ๊ฐ์ด ์ ํฉํ datetime ํ์์ด ์๋ ๊ฒฝ์ฐ exception
@param string $field
@param string $format
@param string $msg
@throws MsgException
|
public static function checkIsbn10Number($isbn)
{
$isbn = trim($isbn);
if (mb_strlen($isbn) !== 10 || preg_match('/0{10}/', $isbn)) {
throw new MsgException("ISBN10 ํ์์ ๋ง์ง ์์ต๋๋ค.");
}
$total = 0;
for ($i = 0; $i < 9; $i++) {
$digit = intval(substr($isbn, $i, 1));
$total += ((10 - $i) * $digit);
}
$check_sum = (11 - ($total % 11)) % 11;
if ($check_sum === 10) {
$check_sum = 'X';
}
if ($check_sum != substr($isbn, 9)) {
throw new MsgException("ISBN10 ํ์์ ๋ง์ง ์์ต๋๋ค.");
}
}
|
ISBN10 ๊ฐ ์ ํจ์ฑ ์ฒดํฌํ๋ค.
https://en.wikipedia.org/wiki/International_Standard_Book_Number#ISBN-10_check_digit_calculation
@param $isbn
@throws MsgException
|
public static function checkIsbn13Number($isbn)
{
$isbn = trim($isbn);
if (mb_strlen($isbn) !== 13 || preg_match('/0{13}/', $isbn)) {
throw new MsgException("ISBN13 ํ์์ ๋ง์ง ์์ต๋๋ค.");
}
if (!is_numeric($isbn)) {
throw new MsgException('ISBN13 ํ์์ ๋ง์ง ์์ต๋๋ค.');
}
$total = 0;
for ($i = 0; $i < 12; $i++) {
$digit = intval(substr($isbn, $i, 1));
$total += ($i % 2 === 0) ? $digit : $digit * 3;
}
$check_sum = 10 - ($total % 10);
if ($check_sum === 10) {
$check_sum = 0;
}
if ($check_sum !== intval(substr($isbn, -1))) {
throw new MsgException("ISBN13 ํ์์ ๋ง์ง ์์ต๋๋ค.");
}
}
|
ISBN13 ๊ฐ ์ ํจ์ฑ ์ฒดํฌํ๋ค.
http://en.wikipedia.org/wiki/International_Standard_Book_Number#ISBN-13_check_digit_calculation
@param string $isbn
@throws MsgException
|
public static function checkEcn($ecn)
{
$ecn = trim(StringUtils::removeHyphen($ecn));
/*
* ECN์ ๋์ด์ ์ฌ์ฉํ์ง ์๊ณ , ๊ทธ ๋์์ผ๋ก UCI๋ฅผ ์ฌ์ฉํ๋๋ก ํ์๋ค.
* ๊ธฐ์กด์ ECN์ ๋ฐ๊ธ๋ฐ์ ๋์๋ค์ ๊ฒฝ์ฐ
* UCI๋ฅผ ๋ฐ๊ธ๋ฐ์ง ์๊ณ ,
* ECN ๋ฒํธ ์์ I410์ ๋ถ์ฌ UCI ๋ฒํธ๋ก ํ๊ธฐ๋ก ํ์๋ค.
*/
$ecn = str_replace('I410', '', $ecn);
if (mb_strlen($ecn) !== 23 || preg_match('/0{23}/', $ecn)) {
throw new MsgException('ECN ํ์์ ๋ง์ง ์์ต๋๋ค.');
}
}
|
ECN ๊ฐ ์ ํจ์ฑ ์ฒดํฌํ๋ค.
ex) ecn sample
ECN-0102-2008-000-123456789
I410-ECN-0199-2009-657-010848674
@param $ecn
@throws MsgException
|
public static function checkIssn($issn)
{
$issn = trim(StringUtils::removeHyphen($issn));
if (mb_strlen($issn) !== 8 || preg_match('/0{8}/', $issn)) {
throw new MsgException('ISSN ํ์์ ๋ง์ง ์์ต๋๋ค.');
}
$total = 0;
for ($i = 0; $i < 7; $i++) {
$digit = intval(substr($issn, $i, 1));
$total += ((8 - $i) * $digit);
}
$check_sum = 11 - ($total % 11);
if ($check_sum === 10) {
$check_sum = 'X';
}
if ($check_sum != substr($issn, -1)) {
throw new MsgException("ISSN ํ์์ ๋ง์ง ์์ต๋๋ค.");
}
}
|
ISSN ๊ฐ ์ ํจ์ฑ ์ฒดํฌํ๋ค.
https://en.wikipedia.org/wiki/International_Standard_Serial_Number#Code_format
@param $issn
@throws MsgException
|
public static function getWeekNumberOfMonth($datetime)
{
$first_day_of_month = clone $datetime;
$first_day_of_month->modify('first day of this month');
return ceil($datetime->format('W') - $first_day_of_month->format('W')) + 1;
}
|
@param \DateTime $datetime
@return int
|
public static function getFormattedDate($date, $format)
{
if (StringUtils::isEmpty($date) || StringUtils::isEmpty($format)) {
return null;
}
return date($format, strtotime($date));
}
|
์
๋ ฅ๋ฐ์ ์์์ ๋ง์ถ ๋ ์๋ฅผ ๋ฐํํ๋ค.
@param $date
@param $format
@return bool|string
|
public static function convertToStartDateTime(string $date_or_date_time): \DateTime
{
if (strlen($date_or_date_time) <= 10) {
return (new \DateTime($date_or_date_time))->setTime(0, 0);
} else {
return (new \DateTime($date_or_date_time));
}
}
|
@param string $date_or_date_time Y-m-d or Y-m-d H:i:s
@return \DateTime
|
public static function convertToEndDateTime(string $date_or_date_time): \DateTime
{
if (strlen($date_or_date_time) <= 10) {
return (new \DateTime($date_or_date_time))->setTime(23, 59, 59);
} else {
return (new \DateTime($date_or_date_time));
}
}
|
@param string $date_or_date_time Y-m-d or Y-m-d H:i:s
@return \DateTime
|
public static function isExecutionTimeInTimeTable(\DateTime $last_executed_datetime, array $time_table): bool
{
$now = self::createNowExceptMicroseconds();
$execution_time = '';
foreach ($time_table as $time) {
if ($last_executed_datetime < $time) {
$execution_time = $time;
break;
}
}
if (empty($execution_time) || $now < $execution_time) {
return false;
}
return true;
}
|
@param \DateTime $last_executed_datetime
@param array $time_table
@return bool
|
public function setException($exception, $msg = null)
{
if ($exception instanceof MsgException) {
$this->setMsgException($exception);
} else {
SentryHelper::triggerSentryException($exception);
if (StringUtils::isEmpty($msg)) {
$msg = "์ค๋ฅ๊ฐ ๋ฐ์ํ์์ต๋๋ค. ๋ค์ ์๋ํ์ฌ ์ฃผ์ธ์. ๋ฌธ์ ๊ฐ ๋ค์ ๋ฐ์ํ ๊ฒฝ์ฐ ๊ฐ๋ฐ๊ทธ๋ฃน์ ๋ฌธ์ํ์ฌ์ฃผ์ธ์.";
}
$this->success = false;
$this->setMsg($msg);
}
}
|
Exception ๋ฐ์ ์ set<br/>
MsgException์ผ ๊ฒฝ์ฐ exception msg๋ง ๋ณด์ฌ์ค๋ค.
์ผ๋ฐ Exception์ผ ๊ฒฝ์ฐ exception์ ์ธ๋ถ์ ๋
ธ์ถ์ํค์ง ์๊ณ trigger_error์ ํตํ์ฌ sentry์ exception ์๋ฆฐ๋ค.
@param \Exception $exception
@param string $msg ๊ธฐ๋ณธ์ ์ผ๋ก ๋ณด์ฌ์ค ๋ฌธ๊ตฌ
|
public static function getArrayDiffRecursively($array1, $array2)
{
$diff_array = [];
// value ๋น๊ต
if (!is_array($array1)) {
if ($array1 != $array2) {
return $array1;
} else {
return [];
}
}
// array ๋น๊ต
foreach ($array1 as $key => $value) {
if (is_array($value)) {
if (!is_array($array2[$key])) {
$diff_array[$key] = $value;
} else {
$sub_diff_array = ArrayUtils::getArrayDiffRecursively($value, $array2[$key]);
if (count($sub_diff_array)) {
// $diff_array[$key] = $sub_diff_array;
$diff_array[$key] = $value;
}
}
} elseif ($array2[$key] != $value) {
$diff_array[$key] = $value;
}
}
return $diff_array;
}
|
$array1์ ๊ธฐ์ค์ผ๋ก $array2์ ๋น๊ตํ์ ๋, $array1์ด ๋ฐ๋ ๊ฐ๋ค์ ๋ฆฌํดํ๋ค.
@param array $array1
@param array $array2
@return array
|
public static function shortenSequential(array $values, $glue = '~')
{
$result = [];
$sequential_values = [];
sort($values);
foreach ($values as $index => $value) {
$previous_value = $values[$index - 1];
if (!in_array(($value - 1), $values)) {
if (count($sequential_values) > 0) {
$result[] = self::implodeSequential($glue, $sequential_values);
}
$sequential_values = [$value];
} else {
if ($previous_value + 1 === $value) {
$sequential_values[] = $value;
}
}
if ($value === end($values)) {
$result[] = self::implodeSequential($glue, $sequential_values);
}
}
return $result;
}
|
์์ฐจ์ ์ธ array item ์ ์๋ตํด์ฃผ๋ ๋ฉ์๋์
๋๋ค.
@example [1, 2, 3, 5, 6, 8] -> ['1~3', '5~6', '8']
@param array $values
@param string $glue
@return \string[]
|
private static function implodeSequential(string $glue, array $values)
{
$first_value = reset($values);
$last_value = end($values);
if ($first_value !== $last_value) {
return $first_value . $glue . $last_value;
}
return $first_value;
}
|
@param string $glue
@param array $values
@return string
|
public static function stripNonAllowableTags($string, $allowable_tags)
{
$string = self::filterNonAllowableTags($string, $allowable_tags);
$string = StringUtils::swapTwoSubStrings($string, '<', '<');
$string = StringUtils::swapTwoSubStrings($string, '>', '>');
$string = strip_tags($string);
$string = StringUtils::swapTwoSubStrings($string, '<', '<');
$string = StringUtils::swapTwoSubStrings($string, '>', '>');
return $string;
}
|
ํ์ฉํ์ง ์๋ ํ๊ทธ์ฉ ๋ฌธ์๋ฅผ ์ ๊ฑฐํด์ค๋ค.
@param $string
@param array $allowable_tags
$allowable_tags ๋ฐฐ์ด ํ์:
$allowable_tags = [
'tag' => ['attr1', 'attr2']
]
@return string
|
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$serializer = new ToggleSerializer(new OperatorConditionSerializer(new OperatorSerializer()));
$toggleData = array_map(function (Toggle $toggle) use ($serializer) {
return $serializer->serialize($toggle);
}, $this->toggleManager->all());
$this->data['toggleDetails'] = $toggleData;
$this->data['context'] = $this->contextFactory->createContext();
}
|
Collects data for the given Request and Response.
@param Request $request A Request instance
@param Response $response A Response instance
@param \Exception $exception An Exception instance
|
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('qandidate_toggle');
$rootNode = \method_exists($treeBuilder, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('qandidate_toggle');
$rootNode
->children()
->enumNode('persistence')
->values(array('in_memory', 'redis', 'factory', 'config'))
->defaultValue('in_memory')
->end()
->arrayNode('collection_factory')
->children()
->scalarNode('service_id')
->isRequired()
->cannotBeEmpty()
->end()
->scalarNode('method')
->isRequired()
->cannotBeEmpty()
->end()
->end()
->end()
->scalarNode('context_factory')
->defaultNull()
->end()
->scalarNode('redis_namespace')
->defaultValue('toggle_%kernel.environment%')
->end()
->scalarNode('redis_client')
->defaultNull()
->end()
->arrayNode('toggles')
->prototype('array')
->children()
->scalarNode('name')->end()
->scalarNode('status')->end()
->arrayNode('conditions')
->prototype('array')
->children()
->scalarNode('name')->end()
->scalarNode('key')->end()
->arrayNode('operator')
->prototype('variable')
->end()
->end()
->end()
->end()
->end()
->end()
->end()
->end()
->end()
->validate()
->ifTrue(function ($v) {
if (isset($v['persistence']) && $v['persistence'] === 'factory') {
return ! isset($v['collection_factory']['service_id'], $v['collection_factory']['method']);
}
return false;
})
->thenInvalid(
'When choosing "factory" persistence make sure you set "collection_factory.service_id" and "collection_factory.method"')
->end();
return $treeBuilder;
}
|
{@inheritDoc}
|
public function createContext()
{
$context = new Context();
$token = $this->tokenStorage->getToken();
if (null !== $token) {
$context->set('username', $this->tokenStorage->getToken()->getUsername());
}
return $context;
}
|
{@inheritDoc}
|
public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/'));
$loader->load('services.xml');
$config = $this->processConfiguration(new Configuration(), $configs);
$collection = 'in_memory';
switch (true) {
case 'redis' === $config['persistence']:
$loader->load('redis.xml');
$collection = 'predis';
$container->setParameter('qandidate.toggle.redis.namespace', $config['redis_namespace']);
$container->setAlias('qandidate.toggle.redis.client', $config['redis_client']);
break;
case 'factory' === $config['persistence']:
$collection = 'factory';
$definition = new Definition(InMemoryCollection::class);
$definition->setFactory(array(
new Reference($config['collection_factory']['service_id']),
$config['collection_factory']['method']
));
$container->setDefinition('qandidate.toggle.collection.factory', $definition);
break;
case 'config' === $config['persistence']:
$collection = 'factory';
$definition = $container->getDefinition('qandidate.toggle.collection.in_memory');
$definition->setFactory(array(
new Reference('qandidate.toggle.collection.serializer.in_memory'),
'deserialize'
));
$definition->addArgument($config['toggles']);
$container->setDefinition('qandidate.toggle.collection.factory', $definition);
break;
}
$container->setAlias('qandidate.toggle.collection', new Alias('qandidate.toggle.collection.' . $collection, true));
$contextFactoryService = 'qandidate.toggle.user_context_factory';
if (null !== $config['context_factory']) {
$contextFactoryService = $config['context_factory'];
}
$container->setAlias('qandidate.toggle.context_factory', $contextFactoryService);
}
|
{@inheritDoc}
|
public function make(array $config)
{
$client = new Client($this->getBuilder($config), array_get($config, 'version'), array_get($config, 'enterprise'));
if (!array_key_exists('method', $config)) {
throw new InvalidArgumentException('The github factory requires an auth method.');
}
if ($config['method'] === 'none') {
return $client;
}
return $this->auth->make($config['method'])->with($client)->authenticate($config);
}
|
Make a new github client.
@param string[] $config
@throws \InvalidArgumentException
@return \Github\Client
|
protected function getBuilder(array $config)
{
$builder = new ClientBuilder();
if ($backoff = array_get($config, 'backoff')) {
$builder->addPlugin(new RetryPlugin(['retries' => $backoff === true ? 2 : $backoff]));
}
if ($this->cache && class_exists(CacheItemPool::class) && $cache = array_get($config, 'cache')) {
$builder->addCache(new CacheItemPool($this->cache->store($cache === true ? null : $cache)));
}
return $builder;
}
|
Get the http client builder.
@param string[] $config
@return \GrahamCampbell\GitHub\Http\ClientBuilder
|
public function authenticate(array $config)
{
if (!$this->client) {
throw new InvalidArgumentException('The client instance was not given to the application authenticator.');
}
if (!array_key_exists('clientId', $config) || !array_key_exists('clientSecret', $config)) {
throw new InvalidArgumentException('The application authenticator requires a client id and secret.');
}
$this->client->authenticate($config['clientId'], $config['clientSecret'], Client::AUTH_URL_CLIENT_ID);
return $this->client;
}
|
Authenticate the client, and return it.
@param string[] $config
@throws \InvalidArgumentException
@return \Github\Client
|
public function authenticate(array $config)
{
if (!$this->client) {
throw new InvalidArgumentException('The client instance was not given to the token authenticator.');
}
if (!array_key_exists('token', $config)) {
throw new InvalidArgumentException('The token authenticator requires a token.');
}
$this->client->authenticate($config['token'], Client::AUTH_HTTP_TOKEN);
return $this->client;
}
|
Authenticate the client, and return it.
@param string[] $config
@throws \InvalidArgumentException
@return \Github\Client
|
protected function registerGitHubFactory()
{
$this->app->singleton('github.factory', function (Container $app) {
$auth = $app['github.authfactory'];
$cache = $app['cache'];
return new GitHubFactory($auth, $cache);
});
$this->app->alias('github.factory', GitHubFactory::class);
}
|
Register the github factory class.
@return void
|
public function authenticate(array $config)
{
if (!$this->client) {
throw new InvalidArgumentException('The client instance was not given to the jwt authenticator.');
}
if (!array_key_exists('token', $config)) {
throw new InvalidArgumentException('The jwt authenticator requires a token.');
}
$this->client->authenticate($config['token'], Client::AUTH_JWT);
return $this->client;
}
|
Authenticate the client, and return it.
@param string[] $config
@throws \InvalidArgumentException
@return \Github\Client
|
public function addCache(CacheItemPoolInterface $cachePool, array $config = [])
{
$this->setCachePlugin($cachePool, $config['generator'] ?? null, $config['lifetime'] ?? null);
$this->setPropertyValue('httpClientModified', true);
}
|
Add a cache plugin to cache responses locally.
@param \Psr\Cache\CacheItemPoolInterface $cachePool
@param array $config
@return void
|
protected function setCachePlugin(CacheItemPoolInterface $cachePool, CacheKeyGenerator $generator = null, int $lifetime = null)
{
$stream = $this->getPropertyValue('streamFactory');
$this->setPropertyValue('cachePlugin', new CachePlugin($cachePool, $stream, $generator, $lifetime));
}
|
Add a cache plugin to cache responses locally.
@param \Psr\Cache\CacheItemPoolInterface $cachePool
@param \Http\Client\Common\Plugin\Cache\Generator\CacheKeyGenerator|null $generator
@param int|null $lifetime
@return void
|
protected static function getProperty(string $name)
{
$prop = (new ReflectionClass(Builder::class))->getProperty($name);
$prop->setAccessible(true);
return $prop;
}
|
Get the builder reflection property for the given name.
@param string $name
@return \ReflectionProperty
|
protected function normalizePHPOS($name)
{
//Cygwin
if (stripos($name, 'CYGWIN') !== false) {
return 'CYGWIN';
}
//MinGW
if (stripos($name, 'MSYS') !== false || stripos($name, 'MINGW') !== false) {
return 'MINGW';
}
return $name;
}
|
This method normalizes some names for future compliance
@param $name
@return string
|
public function getNoncer()
{
if (!isset($this->noncer)) {
$this->noncer = new self::$defaultNoncerClass($this->noncerLength);
if (!$this->noncer instanceof NoncerInterface) {
throw new \UnexpectedValueException('Noncer must implement Acquia\Rest\NoncerInterface');
}
}
return $this->noncer;
}
|
Returns a noncer, instantiates it if it doesn't exist.
@return \Acquia\Rest\NoncerInterface
@throws \UnexpectedValueException
|
protected function getBundleProducts( \Aimeos\MShop\Product\Item\Iface $product, $quantity, $stocktype, $supplier )
{
$orderProducts = [];
$orderProductManager = \Aimeos\MShop::create( $this->getContext(), 'order/base/product' );
foreach( $product->getRefItems( 'product', null, 'default' ) as $item )
{
$orderProduct = $orderProductManager->createItem()->copyFrom( $item );
$prices = $item->getRefItems( 'price', 'default', 'default' );
$orderProducts[] = $orderProduct->setStockType( $stocktype )->setSupplierCode( $supplier )
->setPrice( $this->calcPrice( $orderProduct, $prices, $quantity ) );
}
return $orderProducts;
}
|
Adds the bundled products to the order product item.
@param \Aimeos\MShop\Product\Item\Iface $product Bundle product item
@param integer $quantity Amount of products that should by added
@param string $stocktype Unique code of the stock type to deliver the products from
@param string|null $supplier Unique supplier code the product is from
@return \Aimeos\MShop\Order\Item\Base\Product\Iface[] List of order product item from bundle
|
public function renderMenu(string $menuClass = '', $options = []): string
{
// Merge Options
$options = array_merge($this->defaultOptions, $options);
// Get Menu
$menu = $this->container->has($menuClass) ? $this->container->get($menuClass) : new $menuClass();
// Render
if ($menu instanceof MenuInterface) {
// Process Menu
$menu = $this->itemProcess->processMenu($menu->createMenu($options), $options);
return $this->engine->render($menu, $options);
}
return false;
}
|
Render Menu.
@param string $menuClass
@param array $options
@return string
|
public function getMenu(string $menuClass, $options = []): ItemInterface
{
// Merge Options
$options = array_merge($this->defaultOptions, $options);
// Get Menu
$menu = $this->container->has($menuClass) ? $this->container->get($menuClass) : new $menuClass();
// Render
if ($menu instanceof MenuInterface) {
return $this->itemProcess->processMenu($menu->createMenu($options), $options);
}
return false;
}
|
Get Menu Array.
@param string $menuClass
@param array $options
@return ItemInterface|bool
|
public function arrayToAttr(array $array = [], array $append = [], array $options = [])
{
$array = array_merge_recursive($array, $append);
$attr = '';
foreach ($array as $key => $value) {
if (\is_array($value)) {
$value = implode(' ', $value);
}
if ('title' === mb_strtolower($key)) {
if (!isset($array['title_translate'])) {
$value = $this->translator->trans($value, [], $options['trans_domain'] ?? null);
}
}
$attr .= sprintf('%s="%s"', $key, $value);
}
return $attr;
}
|
Array to Html Attr Convert.
@param array $array
@param array $append
@return string
|
public function addAddressItem( \Aimeos\MShop\Common\Item\Address\Iface $item, $position = null )
{
$this->controller->addAddressItem( $item, $position );
return $this;
}
|
Adds the given address item to the customer object (not yet stored)
@param \Aimeos\MShop\Common\Item\Address\Iface $item Address item to add
@param integer|null $pos Position (key) in the list of address items or null to add the item at the end
@return \Aimeos\Controller\Frontend\Customer\Iface Customer controller for fluent interface
@since 2019.04
|
public function deleteAddressItem( \Aimeos\MShop\Common\Item\Address\Iface $item )
{
$this->controller->deleteAddressItem( $item );
return $this;
}
|
Removes the given address item from the customer object (not yet stored)
@param \Aimeos\MShop\Common\Item\Address\Iface $item Address item to remove
@return \Aimeos\Controller\Frontend\Customer\Iface Customer controller for fluent interface
|
public function deleteListItem( $domain, \Aimeos\MShop\Common\Item\Lists\Iface $listItem, \Aimeos\MShop\Common\Item\Iface $refItem = null )
{
$this->controller->deleteListItem( $domain, $listItem, $refItem );
return $this;
}
|
Removes the given list item from the customer object (not yet stored)
@param string $domain Domain name the referenced item belongs to
@param \Aimeos\MShop\Common\Item\Lists\Iface $item List item to remove
@param \Aimeos\MShop\Common\Item\Iface|null $refItem Referenced item to remove or null if only list item should be removed
@return \Aimeos\Controller\Frontend\Customer\Iface Customer controller for fluent interface
|
public function setObject( \Aimeos\Controller\Frontend\Iface $object )
{
parent::setObject( $object );
$this->controller->setObject( $object );
return $this;
}
|
Injects the reference of the outmost object
@param \Aimeos\Controller\Frontend\Iface $object Reference to the outmost controller or decorator
@return \Aimeos\Controller\Frontend\Iface Controller object for chaining method calls
|
public static function factory($config = array())
{
$required = array(
'base_url',
'username',
'password',
);
$defaults = array(
'base_url' => self::BASE_URL,
'base_path' => self::BASE_PATH,
);
// Instantiate the Acquia Search plugin.
$config = Collection::fromConfig($config, $defaults, $required);
$client = new static($config->get('base_url'), $config);
$client->setDefaultHeaders(array(
'Content-Type' => 'application/json; charset=utf-8',
));
// Attach the Acquia Search plugin to the client.
$plugin = new CloudApiAuthPlugin($config->get('username'), $config->get('password'));
$client->addSubscriber($plugin);
return $client;
}
|
{@inheritdoc}
@return \Acquia\Cloud\Api\CloudApiClient
|
public function site($site)
{
$variables = array('site' => $site);
$request = $this->get(array('{+base_path}/sites/{site}.json', $variables));
return new Response\Site($request);
}
|
@param string $site
@return \Acquia\Cloud\Api\Response\Site
@throws \Guzzle\Http\Exception\ClientErrorResponseException
@see http://cloudapi.acquia.com/#GET__sites__site-instance_route
|
public function environments($site)
{
$variables = array('site' => $site);
$request = $this->get(array('{+base_path}/sites/{site}/envs.json', $variables));
return new Response\Environments($request);
}
|
@param string $site
@return \Acquia\Cloud\Api\Response\Environments
@throws \Guzzle\Http\Exception\ClientErrorResponseException
@see http://cloudapi.acquia.com/#GET__sites__site_envs-instance_route
|
public function environment($site, $env)
{
$variables = array(
'site' => $site,
'env' => $env,
);
$request = $this->get(array('{+base_path}/sites/{site}/envs/{env}.json', $variables));
return new Response\Environment($request);
}
|
@param string $site
@param string $env
@return \Acquia\Cloud\Api\Response\Environment
@throws \Guzzle\Http\Exception\ClientErrorResponseException
@see http://cloudapi.acquia.com/#GET__sites__site_envs__env-instance_route
|
public function installDistro($site, $env, $type, $source)
{
$variables = array(
'site' => $site,
'env' => $env,
'type' => $type,
'source' => $source,
);
$request = $this->post(array('{+base_path}/sites/{site}/envs/{env}/install/{type}.json?source={source}', $variables));
return new Response\Task($request);
}
|
@param string $site
@param string $env
@param string $type
@param string $source
@return \Acquia\Cloud\Api\Response\Task
@throws \Guzzle\Http\Exception\ClientErrorResponseException
@see http://cloudapi.acquia.com/#POST__sites__site_envs__env_install__type-instance_route
|
public function installDistroByProject($site, $env, $projectName, $version)
{
$source = 'http://ftp.drupal.org/files/projects/' . $projectName . '-' . $version . '-core.tar.gz';
return $this->installDistro($site, $env, self::INSTALL_PROJECT, $source);
}
|
Install any publicly accessible, standard Drupal distribution.
@param string $site
@param string $env
@param string $projectName
@param string $version
@return \Acquia\Cloud\Api\Response\Task
@throws \Guzzle\Http\Exception\ClientErrorResponseException
|
public function installDistroByMakefile($site, $env, $makefileUrl)
{
return $this->installDistro($site, $env, self::INSTALL_MAKEFILE, $makefileUrl);
}
|
Install a distro by passing a URL to a Drush makefile.
@param string $site
@param string $env
@param string $makefileUrl
@return \Acquia\Cloud\Api\Response\Task
@throws \Guzzle\Http\Exception\ClientErrorResponseException
|
public function servers($site, $env)
{
$variables = array(
'site' => $site,
'env' => $env,
);
$request = $this->get(array('{+base_path}/sites/{site}/envs/{env}/servers.json', $variables));
return new Response\Servers($request);
}
|
@param string $site
@param string $env
@return \Acquia\Cloud\Api\Response\Servers
@throws \Guzzle\Http\Exception\ClientErrorResponseException
@see http://cloudapi.acquia.com/#GET__sites__site_envs__env_servers-instance_route
|
public function server($site, $env, $server)
{
$variables = array(
'site' => $site,
'env' => $env,
'server' => $server,
);
$request = $this->get(array('{+base_path}/sites/{site}/envs/{env}/servers/{server}.json', $variables));
return new Response\Server($request);
}
|
@param string $site
@param string $env
@param string $server
@return \Acquia\Cloud\Api\Response\Server
@throws \Guzzle\Http\Exception\ClientErrorResponseException
@see http://cloudapi.acquia.com/#GET__sites__site_envs__env_servers__server-instance_route
|
public function sshKeys($site)
{
$variables = array('site' => $site);
$request = $this->get(array('{+base_path}/sites/{site}/sshkeys.json', $variables));
return new Response\SshKeys($request);
}
|
@param string $site
@return \Acquia\Cloud\Api\Response\SshKeys
@throws \Guzzle\Http\Exception\ClientErrorResponseException
@see http://cloudapi.acquia.com/#GET__sites__site_sshkeys-instance_route
|
public function sshKey($site, $keyId)
{
$variables = array(
'site' => $site,
'id' => $keyId,
);
$request = $this->get(array('{+base_path}/sites/{site}/sshkeys/{id}.json', $variables));
return new Response\SshKey($request);
}
|
@param string $site
@param int $keyId
@return \Acquia\Cloud\Api\Response\SshKey
@throws \Guzzle\Http\Exception\ClientErrorResponseException
@see http://cloudapi.acquia.com/#GET__sites__site_sshkeys__sshkeyid-instance_route
|
public function addSshKey($site, $publicKey, $nickname, $shellAccess = true, $vcsAccess = true, $blacklist = array())
{
$path = '{+base_path}/sites/{site}/sshkeys.json?nickname={nickname}';
$variables = array(
'site' => $site,
'nickname' => $nickname,
);
$body = Json::encode(array(
'ssh_pub_key' => $publicKey,
'shell_access' => $shellAccess,
'vcs_access' => $vcsAccess,
'blacklist' => $blacklist,
));
$request = $this->post(array($path, $variables), null, $body);
return new Response\Task($request);
}
|
@param string $site
@param string $publicKey
@param string $nickname
@param bool $shellAccess
@param bool $vcsAccess
@param array $blacklist
@return \Acquia\Cloud\Api\Response\Task
@throws \Guzzle\Http\Exception\ClientErrorResponseException
@see http://cloudapi.acquia.com/#POST__sites__site_sshkeys-instance_route
|
public function deleteSshKey($site, $keyId)
{
if (!is_string($site)) {
throw new \InvalidArgumentException('The site parameter must be a string.');
}
if (!is_int($keyId)) {
throw new \InvalidArgumentException('The keyId parameter must be an integer.');
}
$variables = array(
'site' => $site,
'id' => $keyId,
);
$request = $this->delete(array('{+base_path}/sites/{site}/sshkeys/{id}.json', $variables));
return new Response\Task($request);
}
|
@param string $site
@param int $keyId
@return \Acquia\Cloud\Api\Response\Task
@throws \Guzzle\Http\Exception\ClientErrorResponseException|\InvalidArgumentException
@see http://cloudapi.acquia.com/#DELETE__sites__site_sshkeys__sshkeyid-instance_route
|
public function svnUsers($site)
{
$variables = array('site' => $site);
$request = $this->get(array('{+base_path}/sites/{site}/svnusers.json', $variables));
return new Response\SvnUsers($request);
}
|
@param string $site
@return \Acquia\Cloud\Api\Response\SvnUsers
@throws \Guzzle\Http\Exception\ClientErrorResponseException
@see http://cloudapi.acquia.com/#GET__sites__site_svnusers-instance_route
|
public function svnUser($site, $userId)
{
$variables = array(
'site' => $site,
'id' => $userId,
);
$request = $this->get(array('{+base_path}/sites/{site}/svnusers/{id}.json', $variables));
return new Response\SvnUser($request);
}
|
@param string $site
@param int $userId
@return \Acquia\Cloud\Api\Response\SvnUser
@throws \Guzzle\Http\Exception\ClientErrorResponseException
@see http://cloudapi.acquia.com/#GET__sites__site_svnusers__svnuserid-instance_route
|
public function addSvnUser($site, $username, $password)
{
$path = '{+base_path}/sites/{site}/svnusers/{username}.json';
$variables = array(
'site' => $site,
'username' => $username,
);
$body = Json::encode(array('password' => $password));
$request = $this->post(array($path, $variables), null, $body);
return new Response\Task($request);
}
|
@param string $site
@param string $username
@param string $password
@return \Acquia\Cloud\Api\Response\Task
@throws \Guzzle\Http\Exception\ClientErrorResponseException
@see http://cloudapi.acquia.com/#POST__sites__site_svnusers__username-instance_route
@todo Testing returned a 400 response.
|
public function deleteSvnUser($site, $userId)
{
$variables = array(
'site' => $site,
'id' => $userId,
);
$request = $this->delete(array('{+base_path}/sites/{site}/svnusers/{id}.json', $variables));
return new Response\Task($request);
}
|
@param string $site
@param int $userId
@return \Acquia\Cloud\Api\Response\Task
@throws \Guzzle\Http\Exception\ClientErrorResponseException
@see http://cloudapi.acquia.com/#DELETE__sites__site_svnusers__svnuserid-instance_route
@todo Testing returned a 400 response.
|
public function databases($site)
{
$variables = array('site' => $site);
$request = $this->get(array('{+base_path}/sites/{site}/dbs.json', $variables));
return new Response\DatabaseNames($request);
}
|
@param string $site
@return \Acquia\Cloud\Api\Response\DatabaseNames
@throws \Guzzle\Http\Exception\ClientErrorResponseException
@see http://cloudapi.acquia.com/#GET__sites__site_dbs-instance_route
|
public function database($site, $db)
{
$variables = array(
'site' => $site,
'db' => $db,
);
$request = $this->get(array('{+base_path}/sites/{site}/dbs/{db}.json', $variables));
return new Response\DatabaseName($request);
}
|
@param string $site
@param string $db
@return \Acquia\Cloud\Api\Response\DatabaseName
@throws \Guzzle\Http\Exception\ClientErrorResponseException
@see http://cloudapi.acquia.com/#GET__sites__site_dbs__db-instance_route
|
public function addDatabase($site, $db, $cluster_map = NULL)
{
$variables = array('site' => $site);
$options = array();
if (is_array($cluster_map) && !empty($cluster_map)) {
foreach ($cluster_map as $env => $db_cluster) {
if (is_string($env) && !empty($env) &&
intval($db_cluster) > 0) {
$options[$env] = array('db_cluster' => (string) $db_cluster);
}
}
}
$body = array('db' => $db);
if (count($options) > 0) {
$body['options'] = $options;
}
$body = Json::encode($body);
$request = $this->post(array('{+base_path}/sites/{site}/dbs.json', $variables), null, $body);
return new Response\Task($request);
}
|
@param string $site
@param string $db
@param array $cluster_map
Optional. A mapping containing all environments and the cluster to which
the associated database should be created. Each entry consists of the
environment name as the key and the database cluster ID as the value.
Note that if more than one cluster is associated with a site group,
this map is required.
@return \Acquia\Cloud\Api\Response\Task
@throws \Guzzle\Http\Exception\ClientErrorResponseException
@see http://cloudapi.acquia.com/#POST__sites__site_dbs-instance_route
|
public function deleteDatabase($site, $db, $backup = TRUE)
{
$variables = array(
'site' => $site,
'db' => $db,
'backup' => $backup ? 1 : 0,
);
$request = $this->delete(array('{+base_path}/sites/{site}/dbs/{db}.json?backup={backup}', $variables));
return new Response\Task($request);
}
|
@param string $site
@param string $db
@param bool $backup
Optional. If TRUE, a final backup of the database instance in each
environment is made before deletion.
@return \Acquia\Cloud\Api\Response\Task
@throws \Guzzle\Http\Exception\ClientErrorResponseException
@see http://cloudapi.acquia.com/#DELETE__sites__site_dbs__db-instance_route
|
public function environmentDatabases($site, $env)
{
$variables = array(
'site' => $site,
'env' => $env,
);
$request = $this->get(array('{+base_path}/sites/{site}/envs/{env}/dbs.json', $variables));
return new Response\Databases($request);
}
|
@param string $site
@param string $env
@return \Acquia\Cloud\Api\Response\Databases
@throws \Guzzle\Http\Exception\ClientErrorResponseException
@see http://cloudapi.acquia.com/#GET__sites__site_envs__env_dbs-instance_route
|
public function environmentDatabase($site, $env, $db)
{
$variables = array(
'site' => $site,
'env' => $env,
'db' => $db,
);
$request = $this->get(array('{+base_path}/sites/{site}/envs/{env}/dbs/{db}.json', $variables));
return new Response\Database($request);
}
|
@param string $site
@param string $env
@param string $db
@return \Acquia\Cloud\Api\Response\Database
@throws \Guzzle\Http\Exception\ClientErrorResponseException
@see http://cloudapi.acquia.com/#GET__sites__site_envs__env_dbs__db-instance_route
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.