sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
public function get($customCollectionId, array $fields = array()) { $params = array(); if (!empty($fields)) { $params['fields'] = $fields; } $endpoint = '/admin/custom_collections/'.$customCollectionId.'.json'; $response = $this->request($endpoint, 'GET', $params); return $this->createObject(CustomCollection::class, $response['custom_collection']); }
Receive a single custom collection @link https://help.shopify.com/api/reference/customcollection#show @param integer $customCollectionId @param array $fields @return CustomCollection
entailment
public function create(CustomCollection &$customCollection) { $data = $customCollection->exportData(); $endpoint = '/admin/custom_collections.json'; $response = $this->request( $endpoint, 'POST', array( 'custom_collection' => $data ) ); $customCollection->setData($response['custom_collection']); }
Create a new collection @link https://help.shopify.com/api/reference/customcollection#create @param CustomCollection $customCollection @return void
entailment
public function update(CustomCollection &$customCollection) { $data = $customCollection->exportData(); $endpoint = '/admin/custom_collections/'.$customCollection->id.'.json'; $response = $this->request( $endpoint, 'PUT', array( 'custom_collection' => $data ) ); $customCollection->setData($response['custom_collection']); }
Update a custom collection @link https://help.shopify.com/api/reference/customcollection#update @param CustomCollection $customCollection @return void
entailment
public function delete(CustomCollection &$customCollection) { $endpoint = '/admin/custom_collections/'.$customCollection->getId().'.json'; $request = $this->createRequest($endpoint, static::REQUEST_METHOD_DELETE); $response = $this->send($request); return; }
Delete a custom collection @link https://help.shopify.com/api/reference/customcollection#destroy @param CustomCollection $customCollection @return void
entailment
public function count($productId, array $params = array()) { $endpoint = '/admin/products/'.$productId.'/images/count.json'; $response = $this->request($endpoint, 'GET', $params); return $response['count']; }
Receive a count of all Product Images @link https://help.shopify.com/api/reference/product_image#count @param integer $productId @param array $params @return integer
entailment
public function get($productId, $productImageId) { $endpoint = '/admin/products/'.$productId.'/images/'.$productImageId.'.json'; $response = $this->request($endpoint, 'GET'); return $this->createObject(ProductImage::class, $response['image']); }
Get a single product image @link https://help.shopify.com/api/reference/product_image#show @param integer $productId @param integer $productImageId @return ProductImage
entailment
public function create($productId, ProductImage &$productImage) { $data = $productImage->exportData(); $endpoint = '/admin/products/'.$productId.'/images.json'; $response = $this->request( $endpoint, 'POST', array( 'image' => $data ) ); $productImage->setData($response['image']); }
Create a new product Image @link https://help.shopify.com/api/reference/product_image#create @param integer $productId @param ProductImage $productImage @return void
entailment
public function update($productId, ProductImage &$productImage) { $data = $productImage->exportData(); $endpoint = '/admin/products/'.$productId.'/images/'.$productImage->id.'.json'; $response = $this->request( $endpoint, 'PUT', array( 'image' => $data ) ); $productImage->setData($response['image']); }
Modify an existing product image @link https://help.shopify.com/api/reference/product_image#update @param integer $productId @param ProductImage $productImage @return void
entailment
public function delete($productId, ProductImage $productImage) { $endpoint = '/admin/products/'.$productId.'/images/'.$productImage->id.'.json'; return $this->request($endpoint, 'DELETE'); }
Delete a product image @link https://help.shopify.com/api/reference/product_image#destroy @param integer $productId @param ProductImage $productImage @return void
entailment
public function setChildren(array $children) { foreach ($children as $child) { $this->checkType(ObjectInFolderContainerInterface::class, $child); } $this->children = $children; }
checks input array for ObjectInFolderContainerInterface and sets objects @param ObjectInFolderContainerInterface[] $children
entailment
public function compile($value) { // Only continue is shortcodes have been registered if(!$this->enabled || !$this->hasShortcodes()) return $value; // Set empty result $result = ''; // Here we will loop through all of the tokens returned by the Zend lexer and // parse each one into the corresponding valid PHP. We will then have this // template as the correctly rendered PHP that can be rendered natively. foreach (token_get_all($value) as $token) { $result .= is_array($token) ? $this->parseToken($token) : $token; } return $result; }
Compile the contents @param string $value @return string
entailment
public function getCallback($name) { // Get the callback from the shortcodes array $callback = $this->registered[$name]; // if is a string if(is_string($callback)) { // Parse the callback list($class, $method) = Str::parseCallback($callback, 'register'); // If the class exist if(class_exists($class)) { // return class and method return array( app($class), $method ); } } return $callback; }
Get the callback for the current shortcode (class or callback) @param string $name @return callable|array
entailment
public function all(array $params = array()) { $data = $this->request('/admin/checkouts.json', 'GET', $params); return $this->createCollection(AbandonedCheckout::class, $data['checkouts']); }
List all abandonded checkouts @link https://help.shopify.com/api/reference/abandoned_checkouts#index @param array $params @return AbandonedCheckout[]
entailment
public static function match($entry) { return (bool) (!IPV4::match(trim($entry)) && AbstractIP::match(trim($entry))); }
{@inheritdoc}
entailment
public function check($entry) { if (!IPV6::matchIp($entry)) { return false; } $entryLong = $this->ip2long($entry); $templateLong = $this->ip2long($this->template); return (bool) $this->IPLongCompare($entryLong, $templateLong, '='); }
{@inheritdoc}
entailment
public function all(array $params = array()) { $endpoint = '/admin/comments.json'; $response = $this->request($endpoint, 'GET', $params); return $this->createCollection(Comment::class, $response['comments']); }
Receive a list of all comments @link https://help.shopify.com/api/reference/comment#index @param array $params @return Comment[]
entailment
public function get($commentId, array $params = array()) { $endpoint = '/admin/comments/'.$commentId.'.json'; $response = $this->request($endpoint); return $this->createObject(Comment::class, $response['comment']); }
Receive a single comment @link https://help.shopify.com/api/reference/comment#show @param integer $commentId @param array $params @return Comment
entailment
public function create(Comment &$comment) { $data = $comment->exportData(); $endpoint = '/admin/comments.json'; $respoinse = $this->request( $endpoint, 'POST', array( 'comment' => $data ) ); $comment->setData($response['comment']); }
Create a new comment @link https://help.shopify.com/api/reference/comment#create @param Comment $comment @return void
entailment
public function update(Comment &$comment) { $data = $comment->exportData(); $endpoint = '/admin/comments/'.$comment->id.'.json'; $response = $this->request( $endpoint, 'PUT', array( 'comment' => $data ) ); $comment->setData($response['comment']); }
Modify an existing comment @link https://help.shopify.com/api/reference/comment#update @param Comment $comment @return void
entailment
public function spam(Comment &$comment) { $endpoint = '/admin/comments/'.$comment->id.'/spam.json'; $response = $this->request($endpoint, 'POST'); $comment->setData($response['comment']); }
Mark comment as spam @link https://help.shopify.com/api/reference/comment#spam @param Comment $comment @return void
entailment
public function all(array $params = array()) { $endpoint = '/admin/pages.json'; $response = $this->request($endpoint, 'GET', $params); return $this->createCollection(Page::class, $response['pages']); }
Receive a list of all pages @link https://help.shopify.com/api/reference/page#index @param array $params @return Page[]
entailment
public function get($pageId, array $params = array()) { $endpoint = '/admin/pages/'.$pageId.'.json'; $response = $this->request($endpoint, 'GET', $params); return $this->createObject(Page::class, $response['page']); }
Receive a single @link https://help.shopify.com/api/reference/page#show @param integer $pageId @param array $params @return Page
entailment
public function create(Page &$page) { $data = $page->exportData(); $endpoint= '/admin/pages.json'; $response = $this->request( $endpoint, 'POST', array( 'page' => $data ) ); $page->setData($response['page']); }
Create a new page @link https://help.shopify.com/api/reference/page#create @param Page $page @return void
entailment
public function update(Page &$page) { $data = $page->exportData(); $endpoint= '/admin/pages/'.$page->id.'.json'; $response = $this->request( $endpoint, 'PUT', array( 'page' => $data ) ); $page->setData($response['page']); }
Modify an existing page @link https://help.shopify.com/api/reference/page#update @param Page $page @return void
entailment
public function delete(Page $page) { $endpoint = '/admin/pages/'.$page->id.'.json'; $response = $this->request($endpoint, 'DELETE'); return; }
Delete an existing page @link https://help.shopify.com/api/reference/page#destroy @param Page $page @return void
entailment
public function getUnitSymbolsForFamily($family) { $familyConfig = $this->getFamilyConfig($family); $unitsConfig = $familyConfig['units']; return array_map( function ($unit) { return $unit['symbol']; }, $unitsConfig ); }
Get unit symbols for a measure family @param string $family the measure family @return array the measure symbols
entailment
protected function getFamilyConfig($family) { if (!isset($this->config[$family])) { throw new \InvalidArgumentException( sprintf('Undefined measure family "%s"', $family) ); } return $this->config[$family]; }
Get the family config @param string $family @throws \InvalidArgumentException @return array
entailment
public function all(array $params = array()) { $endpoint = '/admin/customers.json'; $response = $this->request($endpoint, 'GET', $params); return $this->createCollection(Customer::class, $response['customers']); }
Get all customers @link https://help.shopify.com/api/reference/customer#index @param array $params @return Customer[]
entailment
public function search(array $params = array()) { $endpoint = '/admin/customers/search.json'; $response = $this->request($endpoint, 'GET', $params); return $this->createCollection(Customer::class, $response['customers']); }
Search for customers matching suppliied query @link https://help.shopify.com/api/reference/customer#search @param array $params @return Customer[]
entailment
public function get($customerId, array $params = array()) { $endpoint = '/admin/customers/'.$customerId.'.json';; $response = $this->request($endpoint, 'GET', $params); return $this->createObject(Customer::class, $response['customer']); }
Receive a single customer @link https://help.shopify.com/api/reference/customer#show @param integer $customerId @param array $params @return Customer
entailment
public function create(Customer &$customer) { $data = $customer->exportData(); $endpoint = '/admin/customers.json'; $response = $this->request( $endpoint, "POST", array( 'customer' => $data ) ); $customer->setData($response['customer']); }
Create a customer @link https://help.shopify.com/api/reference/customer#create @param Customer $customer @return void
entailment
public function update(Customer &$customer) { $data = $customer->exportData(); $endpoint = '/admin/customers/'.$customer->id.'.json'; $response = $this->request( $endpoint, 'PUT', array( 'customer' => $data ) ); $customer->setData($response['customer']); }
Update a customer @link https://help.shopify.com/api/reference/customer#update @param Customer $customer @return void
entailment
public function delete(Customer $customer) { $endpoint = '/admin/customers/'.$customer->id.'.json'; $response = $this->request($endpoint, 'DELETE'); return; }
Delete a customer @link https://help.shopify.com/api/reference/customer#destroy @param Customer $customer @return void
entailment
public function sendInvite($customerId, CustomerInvite $invite = null) { $data = is_null($invite) ? array() : $invite->exportData(); $endpoint = '/admin/customers/'.$customerId.'/send_invite.json'; $response = $this->request( $endpoint, 'POST', array( 'custom_invite' => $data ) ); return $response['customer_invite']; }
Send an invite @todo Return CustomInvite, instead of raw object @link https://help.shopify.com/api/reference/customer#send_invite @param integer $customerId @return CustomerInvite
entailment
protected function getCheckRegex() { $regex = $this->template; $patterns = array( '.', '*', ); $replaces = array( '\.', parent::$digitRegex, ); return sprintf('/^%s$/', str_replace($patterns, $replaces, $regex)); }
{@inheritdoc}
entailment
public static function match($entry) { if (!strpos($entry, '*')) { return false; } $entry = str_replace('*', 12, $entry); return IPV4::match(trim($entry)); }
{@inheritdoc}
entailment
public function all($blogId, array $params = array()) { $endpoint = '/admin/blogs/'.$blogId.'/articles.json'; $data = $this->request($endpoint, 'GET', $params); return $this->createCollection(Article::class, $data['articles']); }
Receive a list of Articles @link https://help.shopify.com/api/reference/article#index @param integer $blogId @param array $params @return Article[]
entailment
public function count($blogId, array $params = array()) { $endpoint = '/admin/blogs/'.$blogId.'/articles/count.json'; $response = $this->request($endpoint, 'GET', $params); return $response['count']; }
Receive acount of all Articles @link https://help.shopify.com/api/reference/article#count @param integer $blogId @param array $params @return integer
entailment
public function get($blogId, $articleId, array $fields = array()) { $params = array(); if (!empty($fields)) { $params['fields'] = implode(',', $fields); } $endpoint = '/admin/blogs/'.$blogId.'/articles/'.$articleId.'.json'; $response = $this->request($endpoint, 'GET', $params); return $this->createObject(Article::class, $response['article']); }
Receive a single article @link https://help.shopify.com/api/reference/article#show @param integer $blogId @param integer $articleId @param array $fields @return Article
entailment
public function create($blogId, Article &$article) { $data = $article->exportData(); $endpoint = '/admin/blogs/'.$blogId.'/articles.json'; $response = $this->request( $endpoint, 'POST', array( 'article' => $data ) ); $article->setData($response['article']); }
Create a new Article @link https://help.shopify.com/api/reference/article#create @param integer $blogId @param Article $article @return void
entailment
public function update($blogId, Article &$article) { $data = $article->exportData(); $endpoint = '/admin/blogs/'.$blogId.'/articles/'.$article->id.'.json'; $response = $this->request( $endpoint, 'POST', array( 'article' => $data ) ); $article->setData($response['article']); }
Modify an existing article @link https://help.shopify.com/api/reference/article#update @param integer $blogId @param Article $article @return void
entailment
public function delete($blogId, Article &$article) { $articleId = $article->getId(); $endpoint = '/admin/blogs/'.$blogId.'/articles/'.$articleId.'.json'; $this->request($endpoint, 'DELETE'); }
Remove an article from the database @link https://help.shopify.com/api/reference/article#destroy @param integer $blogId @param Article $article @return void
entailment
public function all($orderId, array $params = array()) { $endpoint = '/admin/orders/'.$orderId.'/refunds.json'; $response = $this->request($endpoint, 'GET', $params); return $this->createCollection(Refund::class, $response['refunds']); }
Receive a list of all Refunds @link https://help.shopify.com/api/reference/refund#index @param integer $orderId @param array $params @return Refund[]
entailment
public function get($orderId, $refundId, array $params = array()) { $endpoint = '/admin/orders/'.$orderId.'/refunds/'.$refundId.'.json'; $response = $this->request($endpoint, 'GET', $params); return $this->createObject(Refund::class, $response['refund']); }
Receive a single Refund @link https://help.shopify.com/api/reference/refund#show @param integer $orderId @param integer $refundId @param array $params @return Refund
entailment
public function create($orderId, Refund &$refund) { $data = $refund->exportData(); $endpoint = '/admin/orders/'.$orderId.'/refunds.json'; $response = $this->request( $endpoint, 'POST', array( 'refund' => $data ) ); $refund->setData($response['refund']); }
Create a new refund @link https://help.shopify.com/api/reference/refund#create @param integer $orderId @param Refund $refund @return void
entailment
protected function getCheckRegex() { $digit = IPV6::getFreeDigit($this->template); $templateFull = str_replace( $digit, '*', $this->long2ip( $this->ip2long( str_replace('*', $digit, $this->template) ), false ) ); $regex = '/^'. str_replace('*', IPV6::$digitRegex, $templateFull) .'$/'; return $regex; }
{@inheritdoc}
entailment
public static function match($entry) { if (!strpos($entry, '*')) { return false; } $rpDigit = IPV6::getFreeDigit($entry); $entry = str_replace('*', $rpDigit, $entry); return IPV6::match(trim($entry)); }
{@inheritdoc}
entailment
public function all() { $endpoint = '/admin/policies.json'; $response = $this->request($endpoint); return $this->createCollection(Policy::class, $response['policies']); }
Receive a list of all Policies @link https://help.shopify.com/api/reference/policy#index @return Policy[]
entailment
public function setFamily($family) { if (!isset($this->config[$family])) { throw new UnknownFamilyMeasureException(); } $this->family = $family; return $this; }
Set a family for the converter @param string $family @throws UnknownFamilyMeasureException @return MeasureConverter
entailment
public function convert($baseUnit, $finalUnit, $value) { $standardValue = $this->convertBaseToStandard($baseUnit, $value); $result = $this->convertStandardToResult($finalUnit, $standardValue); return $result; }
Convert a value from a base measure to a final measure @param string $baseUnit Base unit for value @param string $finalUnit Result unit for value @param double $value Value to convert @return double
entailment
public function convertBaseToStandard($baseUnit, $value) { if (!isset($this->config[$this->family]['units'][$baseUnit])) { throw new UnknownMeasureException( sprintf( 'Could not find metric unit "%s" in family "%s"', $baseUnit, $this->family ) ); } $conversionConfig = $this->config[$this->family]['units'][$baseUnit]['convert']; $convertedValue = $value; foreach ($conversionConfig as $operation) { foreach ($operation as $operator => $operand) { $convertedValue = $this->applyOperation($convertedValue, $operator, $operand); } } return $convertedValue; }
Convert a value in a base unit to the standard unit @param string $baseUnit Base unit for value @param double $value Value to convert @throws UnknownOperatorException @throws UnknownMeasureException @return double
entailment
protected function applyOperation($value, $operator, $operand) { $processedValue = $value; switch ($operator) { case "div": if ($operand !== 0) { $processedValue = $processedValue / $operand; } break; case "mul": $processedValue = $processedValue * $operand; break; case "add": $processedValue = $processedValue + $operand; break; case "sub": $processedValue = $processedValue - $operand; break; default: throw new UnknownOperatorException(); } return $processedValue; }
Apply operation between value and operand by using operator @param double $value Value to convert @param string $operator Operator to apply @param double $operand Operand to use @return double
entailment
public function convertStandardToResult($finalUnit, $value) { if (!isset($this->config[$this->family]['units'][$finalUnit])) { throw new UnknownMeasureException( sprintf( 'Could not find metric unit "%s" in family "%s"', $finalUnit, $this->family ) ); } $conversionConfig = $this->config[$this->family]['units'][$finalUnit]['convert']; $convertedValue = $value; // calculate result with conversion config (calculs must be reversed and operation inversed) foreach (array_reverse($conversionConfig) as $operation) { foreach ($operation as $operator => $operand) { $convertedValue = $this->applyReversedOperation($convertedValue, $operator, $operand); } } return $convertedValue; }
Convert a value in a standard unit to a final unit @param string $finalUnit Final unit for value @param double $value Value to convert @throws UnknownOperatorException @throws UnknownMeasureException @return double
entailment
protected function applyReversedOperation($value, $operator, $operand) { $processedValue = $value; switch ($operator) { case "div": $processedValue = $processedValue * $operand; break; case "mul": if ($operand !== 0) { $processedValue = $processedValue / $operand; } break; case "add": $processedValue = $processedValue - $operand; break; case "sub": $processedValue = $processedValue + $operand; break; default: throw new UnknownOperatorException(); } return $processedValue; }
Apply reversed operation between value and operand by using operator @param double $value Value to convert @param string $operator Operator to apply @param double $operand Operand to use @return double
entailment
public function init() { $args = array(); if (!is_null($this->myshopify_domain)) { $args['base_uri'] = sprintf("https://%s", $this->myshopify_domain); } if (!is_null($this->access_token)) { $args['headers']['X-Shopify-Access-Token'] = $this->access_token; } $this->http_handler = new Client($args); }
{@inheritDoc}
entailment
public function all(array $params = array()) { $data = $this->request('/admin/script_tags.json', 'GET', $params); return $this->createCollection(ScriptTag::class, $data['script_tags']); }
Get a list of all ScriptTags @link https://help.shopify.com/api/reference/scripttag#index @param array $params @return ScriptTag[]
entailment
public function get($scriptTagId, array $fields = array()) { $params = array(); if (!empty($fields)) { $params['fields'] = implode(',', $fields); } $data = $this->request('/admin/script_tags/'.$scriptTagId.'.json', 'GET', $params); return $this->createObject(ScriptTag::class, $data['script_tag']); }
Receive a single Script Tag @link https://help.shopify.com/api/reference/scripttag#show @param integer $scriptTagId @param array $fields @return ScriptTag
entailment
public function create(ScriptTag &$scriptTag) { $data = $scriptTag->exportData(); $response = $this->request( '/admin/script_tags.json', 'POST', array( 'script_tag' => $data ) ); $scriptTag->setData($response['script_tag']); }
Create a new script tag @link https://help.shopify.com/api/reference/scripttag#create @param ScriptTag $scriptTag @return void
entailment
public function update(ScriptTag $scriptTag) { $data = $scriptTag->exportData(); $response = $this->request( '/admin/script_tags/'.$scriptTag->id.'.json', 'PUT', array( 'script_tag' => $data ) ); $scriptTag->setData($response['script_tag']); }
Update a script tag @link https://help.shopify.com/api/reference/scripttag#update @param ScriptTag $scriptTag @return void
entailment
public function setPolicyIds(array $policyIds) { foreach ($policyIds as $key => $policyId) { $policyIds[$key] = $this->castValueToSimpleType('string', $policyId); } $this->policyIds = $policyIds; }
Sets list of policy ids @param string[] list of policy ids
entailment
public function all(array $params = array()) { $endpoint = '/admin/locations.json'; $response = $this->request($endpoint, 'GET', $params); return $this->createCollection(Location::class, $response['locations']); }
Get all locations @link https://help.shopify.com/api/reference/location#index @param array $params @return Location[]
entailment
public function get($locationId, array $params = array()) { $endpoint = '/admin/locations/'.$locationId.'.json'; $response = $this->request($endpoint, 'GET', $params); return $this->createObject(Location::class, $response['location']); }
Get a single location @link https://help.shopify.com/api/reference/location#show @param integer $locationId @param array $params @return Location
entailment
public static function match($entry) { $matchRegex = sprintf(self::$regexModel, self::$digitRegex); return (bool) ( preg_match($matchRegex, trim($entry)) && parent::match(trim($entry))); }
{@inheritdoc}
entailment
public function all(array $params = array()) { $endpoint = '/admin/events.json'; $response = $this->request($endpoint, 'GET', $params); return $this->createCollection(Event::class, $response['events']); }
Get a list of all events @link https://help.shopify.com/api/reference/event#index @param array $params @return Event[]
entailment
public function get($eventId, array $params = array()) { $endpoint = '/admin/events/'.$eventId.'.json'; $response = $this->request($endpoint, 'GET', $params); return $this->createObject(Event::class, $response['event']); }
Receive a single event @link https://help.shopify.com/api/reference/event#show @param integer $eventId @param array $params @return Event
entailment
private function getReplacementValue() { $value = $this->getValue(); return (is_array($value) || is_object($value)) ? array($value) : $value; }
Returns the replacement value. @return mixed
entailment
public function perform($targetDocument) { $pointer = new Pointer($targetDocument); $rootGet = array(); $value = $this->getValue(); try { $get = $pointer->get($this->getPath()); } catch (NonexistentValueReferencedException $e) { $get = null; } $pointerParts = $this->getPointerParts(); $rootPointer = $pointerParts[0]; if (count($pointerParts) >= 2) { try { $rootGet = $pointer->get(Pointer::POINTER_CHAR . implode('/', array_slice($pointerParts, 0, -1))); } catch (NonexistentValueReferencedException $e) { return $targetDocument; } } $targetDocument = json_decode($targetDocument); $lastPointerPart = $pointerParts[count($pointerParts) - 1]; $replacementValue = $this->getReplacementValue(); if ($get === null && $lastPointerPart !== Pointer::LAST_ARRAY_ELEMENT_CHAR) { if (ctype_digit($lastPointerPart) && $lastPointerPart > count($rootGet)) { if ($rootPointer == $lastPointerPart && is_array($targetDocument)) { if ((int) $lastPointerPart <= count($targetDocument) + 1) { array_splice($targetDocument, $lastPointerPart, 0, $replacementValue); } } return json_encode($targetDocument, JSON_UNESCAPED_UNICODE); } if (count($pointerParts) === 1) { if (is_array($targetDocument)) { $targetDocument[$pointerParts[0]] = $value; } else { $targetDocument->{$pointerParts[0]} = $value; } } elseif (count($pointerParts) > 1) { $augmentedDocument = &$targetDocument; foreach ($pointerParts as $pointerPart) { if (is_array($augmentedDocument)) { $augmentedDocument = &$augmentedDocument[$pointerPart]; } else { $augmentedDocument = &$augmentedDocument->{$pointerPart}; } } $augmentedDocument = $value; } } else { $additionIndex = array_pop($pointerParts); $arrayEntryPath = '/' . implode('/', $pointerParts); try { $targetArray = $pointer->get($arrayEntryPath); } catch (NonexistentValueReferencedException $e) { $targetArray = null; } if (is_array($targetArray)) { if ($lastPointerPart === Pointer::LAST_ARRAY_ELEMENT_CHAR) { $targetArray[] = $value; } else { if (is_numeric($additionIndex)) { array_splice($targetArray, $additionIndex, 0, $replacementValue); } else { $targetArray[$additionIndex] = $value; } } } if (is_object($targetArray)) { $targetArray->{$additionIndex} = $value; } if (is_array($targetArray) || is_object($targetArray)) { $augmentedDocument = &$targetDocument; foreach ($pointerParts as $pointerPart) { if (is_array($augmentedDocument)) { $augmentedDocument = &$augmentedDocument[$pointerPart]; } else { $augmentedDocument = &$augmentedDocument->{$pointerPart}; } } $augmentedDocument = $targetArray; } if ($targetArray === null) { if (is_numeric($additionIndex) && count($targetDocument) > 0) { array_splice($targetDocument, $additionIndex, 0, $replacementValue); } else { $targetDocument->{$additionIndex} = $value; } } } return json_encode($targetDocument, JSON_UNESCAPED_UNICODE); }
@param string $targetDocument @throws \Rs\Json\Pointer\InvalidJsonException @throws \Rs\Json\Pointer\InvalidPointerException @throws \Rs\Json\Pointer\NonWalkableJsonException @return string
entailment
public function all(array $params = array()) { $endpoint = '/admin/marketing_events.json'; $response = $this->request($endpoint, 'GET', $params); return $this->createCollection(MarketingEvent::class, $response['marketing_events']); }
Receieve a list of all Marketing Events @link https://help.shopify.com/api/reference/marketing_event#index @param array $params @return MarketingEvent[]
entailment
public function get($marketingEventId) { $endpoint = '/admin/marketing_events/'.$marketingEventId.'.json'; $response = $this->request($endpoint); return $this->createObject(MarketingEvent::class, $response['marketing_event']); }
Receive a single Marketing events @link https://help.shopify.com/api/reference/marketing_event#shows @param integer $marketingEventId @return MarketingEvent
entailment
public function create(MarketingEvent &$marketingEvent) { $data = $marketingEvent->exportData(); $endpoint = '/admin/marketing_events.json'; $response = $this->request( $endpoint, 'POST', array( 'marketing_event' => $data ) ); $marketingEvent->setData($response['marketing_event']); }
Create a marketing event @link https://help.shopify.com/api/reference/marketing_event#create @param MarketingEvent $marketingEvent @return void
entailment
public function update(MarketingEvent &$marketingEvent) { $data = $marketingEvent->exportData(); $endpoint = '/admin/marketing_events/'.$marketingEvent->id.'.json'; $response = $this->request( $endpoint, 'PUT', array( 'marketing_event' => $data ) ); $marketingEvent->setData($response['marketing_event']); }
Modify a marketing events @link https://help.shopify.com/api/reference/marketing_event#update @param MarketingEvent $marketingEvent @return void
entailment
public function delete(MarketingEvent &$marketingEvent) { $endpoint = '/admin/marketing_events/'.$marketingEvent->id.'.json'; $response = $this->request($endpoint, 'DELETE'); return; }
Remove a marketing event @link https://help.shopify.com/api/reference/marketing_event#destroy @param MarketingEvent $marketingEvent @return void
entailment
public function requireDefaultRecords() { parent::requireDefaultRecords(); foreach ($this->getDefaultSetNames() as $name) { $existingRecord = MenuSet::get() ->filter('Name', $name) ->first(); if (!$existingRecord) { $set = new MenuSet(); $set->Name = $name; $set->write(); DB::alteration_message("MenuSet '$name' created", 'created'); } } }
Set up default records based on the yaml config
entailment
protected function checkType($expectedType, $value, $nullAllowed = false) { $invalidType = null; $valueType = gettype($value); $nullAllowed = (boolean) $nullAllowed; if ($valueType === 'object') { if (!is_a($value, $expectedType)) { $invalidType = get_class($value); } } elseif ($expectedType !== $valueType) { $invalidType = $valueType; } if ($invalidType !== null && ($nullAllowed === false || ($nullAllowed === true && $value !== null))) { throw new CmisInvalidArgumentException( sprintf( 'Argument of type "%s" given but argument of type "%s" was expected.', $invalidType, $expectedType ), 1413440336 ); } return true; }
Check if the given value is the expected object type @param string $expectedType the expected object type (class name) @param mixed $value The value that has to be checked @param boolean $nullAllowed Is <code>null</code> allowed as value? @return boolean returns <code>true</code> if the given value is instance of expected type @throws CmisInvalidArgumentException Exception is thrown if the given value does not match to the expected type
entailment
protected function castValueToSimpleType($expectedType, $value, $nullIsValidValue = false) { try { $this->checkType($expectedType, $value, $nullIsValidValue); } catch (CmisInvalidArgumentException $exception) { if (PHP_INT_SIZE == 4 && $expectedType == 'integer' && is_double($value)) { //TODO: 32bit - handle this specially? settype($value, $expectedType); } else { trigger_error( sprintf( 'Given value is of type "%s" but a value of type "%s" was expected.' . ' Value has been casted to the expected type.', gettype($value), $expectedType ), E_USER_NOTICE ); settype($value, $expectedType); } } return $value; }
Ensure that a value is an instance of the expected type. If not the value is casted to the expected type and a log message is triggered. @param string $expectedType the expected object type (class name) @param mixed $value The value that has to be checked @param boolean $nullIsValidValue defines if <code>null</code> is also a valid value @return mixed
entailment
public function get() { $request = $this->createRequest('/admin/shop.json'); $response = $this->send($request); return $this->createObject(Shop::class, $response['shop']); }
Receive a single shop @link https://help.shopify.com/api/reference/shop#show @return Shop
entailment
public function getPropertyDefinition($id) { return (isset($this->propertyDefinitions[$id]) ? $this->propertyDefinitions[$id] : null); }
Returns the property definitions for the given id of this type. @param string $id id of the property @return PropertyDefinitionInterface|null the property definition
entailment
protected function ip2long6($ipv6) { $ipN = inet_pton($ipv6); $byte = 0; $ipv6Long = 0; while ($byte < 16) { $ipv6Long = bcadd(bcmul($ipv6Long, 256), ord($ipN[$byte])); $byte++; } return $ipv6Long; }
Convert IP notation to long notation (IPV6) @param string $ipv6 IPV6 @return string IPV6 Long
entailment
protected function long2ip($long, $abbr = true) { switch(static::NB_BITS) { case 128: return $this->long2ip6($long, $abbr); default: return strval(long2ip($long)); } }
Convert a Long to IP Notation @param string $long Long @param boolean $abbr Whether or not use short notation @return string IP
entailment
protected function long2ip6($ipv6long, $abbr = true) { $ipv6Arr = array(); for ($part = 0; $part <= 7; $part++) { $hexPart = dechex(bcmod($ipv6long, 65536)); $ipv6long = bcdiv($ipv6long, 65536, 0); $hexFullPart = str_pad($hexPart, 4, "0", STR_PAD_LEFT); $ipv6Arr[] = $hexFullPart; } $ipv6 = implode(':', array_reverse($ipv6Arr)); if ($abbr) { $ipv6 = inet_ntop(inet_pton($ipv6)); } return $ipv6; }
Convert a Long to IP notation (IPV6) @param string $ipv6long Long @param boolean $abbr Whether or not use short notation @return string IPV6
entailment
protected function IPLongCompare($long1, $long2, $operator = '=') { $operators = preg_split('//', $operator); $diff = bccomp($long1, $long2); foreach ($operators as $operator) { switch(true) { case ( ( $operator === '=' ) && ( $diff == 0 ) ): case ( ( $operator === '<' ) && ( $diff < 0 ) ): case ( ( $operator === '>' ) && ( $diff > 0 ) ): return true; } } return false; }
Compare 2 IP Long @param mixed $long1 IP Long @param mixed $long2 IP Long @param string $operator Operator @return boolean
entailment
protected function IPLongAnd($long1, $long2) { $result = 0; for ($bit = 0; $bit < static::NB_BITS; $bit++) { $div = bcpow(2, $bit); $and = bcmod(bcdiv($long1, $div, 0), 2) && bcmod(bcdiv($long2, $div, 0), 2); $result = bcadd($result, bcmul($and, $div)); } return $result; }
Logic AND between two IP Longs @param mixed $long1 IP Long @param mixed $long2 IP Long @return string
entailment
protected function IPLongBaseConvert($long, $fromBase=10, $toBase=36) { $str = trim($long); if (intval($fromBase) != 10) { $len = strlen($str); $q = 0; for ($i=0; $i<$len; $i++) { $r = base_convert($str[$i], $fromBase, 10); $q = bcadd(bcmul($q, $fromBase), $r); } } else { $q = $str; } if (intval($toBase) != 10) { $s = ''; while (bccomp($q, '0', 0) > 0) { $r = intval(bcmod($q, $toBase)); $s = base_convert($r, 10, $toBase) . $s; $q = bcdiv($q, $toBase, 0); } } else { $s = $q; } return $s; }
Convert Long base @param mixed $long IP Long @param integer $fromBase Input base @param integer $toBase Output base @return string
entailment
private function extractPatchOperations($patchDocument) { $patchDocument = json_decode($patchDocument); if ($this->isEmptyPatchDocument($patchDocument)) { $exceptionMessage = sprintf( "Unable to extract patch operations from '%s'", json_encode($patchDocument) ); throw new InvalidOperationException($exceptionMessage); } $patchOperations = array(); foreach ($patchDocument as $index => $possiblePatchOperation) { $operation = $this->patchOperationFactory($possiblePatchOperation); if ($operation instanceof Operation) { $patchOperations[] = $operation; } } return $patchOperations; }
@param string $patchDocument The patch document containing the patch operations. @throws \Rs\Json\Patch\InvalidOperationException @return Operation[]
entailment
private function patchOperationFactory(\stdClass $possiblePatchOperation) { if (!isset($possiblePatchOperation->op)) { $exceptionMessage = sprintf( "No operation set for patch operation '%s'", json_encode($possiblePatchOperation) ); throw new InvalidOperationException($exceptionMessage); } switch ($possiblePatchOperation->op) { case 'add': if (!(($this->allowedPatchOperations & Add::APPLY) == Add::APPLY)) { return null; } return new Add($possiblePatchOperation); break; case 'copy': if (!(($this->allowedPatchOperations & Copy::APPLY) == Copy::APPLY)) { return null; } return new Copy($possiblePatchOperation); break; case 'move': if (!(($this->allowedPatchOperations & Move::APPLY) == Move::APPLY)) { return null; } return new Move($possiblePatchOperation); break; case 'replace': if (!(($this->allowedPatchOperations & Replace::APPLY) == Replace::APPLY)) { return null; } return new Replace($possiblePatchOperation); break; case 'remove': if (!(($this->allowedPatchOperations & Remove::APPLY) == Remove::APPLY)) { return null; } return new Remove($possiblePatchOperation); break; case 'test': if (!(($this->allowedPatchOperations & Test::APPLY) == Test::APPLY)) { return null; } return new Test($possiblePatchOperation); break; default: return null; } }
@param \stdClass $possiblePatchOperation @throws \Rs\Json\Patch\InvalidOperationException @return \Rs\Json\Patch\Operation or null on unsupported patch operation
entailment
public function getParents(OperationContextInterface $context = null) { $context = $this->ensureContext($context); // get object ids of the parent folders $bindingParents = $this->getBinding()->getNavigationService()->getObjectParents( $this->getRepositoryId(), $this->getId(), $this->getPropertyQueryName(PropertyIds::OBJECT_ID), false, IncludeRelationships::cast(IncludeRelationships::NONE), Constants::RENDITION_NONE, false, null ); $parents = []; foreach ($bindingParents as $parent) { if ($parent->getObject()->getProperties() === null) { // that should never happen throw new CmisRuntimeException('Repository sent invalid data!'); } $parentProperties = $parent->getObject()->getProperties()->getProperties(); // get id property $idProperty = null; if (isset($parentProperties[PropertyIds::OBJECT_ID])) { $idProperty = $parentProperties[PropertyIds::OBJECT_ID]; } if (!$idProperty instanceof PropertyIdInterface && !$idProperty instanceof PropertyStringInterface) { // the repository sent an object without a valid object id... throw new CmisRuntimeException('Repository sent invalid data! No object id!'); } // fetch the object and make sure it is a folder $parentFolder = $this->getSession()->getObject( $this->session->createObjectId((String) $idProperty->getFirstValue()), $context ); if (!$parentFolder instanceof FolderInterface) { // the repository sent an object that is not a folder... throw new CmisRuntimeException('Repository sent invalid data! Object is not a folder!'); } $parents[] = $parentFolder; } return $parents; }
Returns the parents of this object. @param OperationContextInterface|null $context the OperationContext to use to fetch the parent folder objects @return FolderInterface[] the list of parent folders of this object or an empty list if this object is unfiled or if this object is the root folder @throws CmisRuntimeException Throws exception if invalid data is returned by the repository
entailment
public function getPaths() { $folderType = $this->getSession()->getTypeDefinition((string) BaseTypeId::cast(BaseTypeId::CMIS_FOLDER)); $propertyDefinition = $folderType->getPropertyDefinition(PropertyIds::PATH); $pathQueryName = ($propertyDefinition === null) ? null : $propertyDefinition->getQueryName(); // get object paths of the parent folders $bindingParents = $this->getBinding()->getNavigationService()->getObjectParents( $this->getRepositoryId(), $this->getId(), $pathQueryName, false, IncludeRelationships::cast(IncludeRelationships::NONE), Constants::RENDITION_NONE, true, null ); $paths = []; foreach ($bindingParents as $parent) { if ($parent->getObject()->getProperties() === null) { // that should never happen but could in case of an faulty repository implementation throw new CmisRuntimeException('Repository sent invalid data! No properties given.'); } $parentProperties = $parent->getObject()->getProperties()->getProperties(); $pathProperty = null; if (isset($parentProperties[PropertyIds::PATH])) { $pathProperty = $parentProperties[PropertyIds::PATH]; } if (!$pathProperty instanceof PropertyStringInterface) { // the repository sent an object without a valid path... throw new CmisRuntimeException('Repository sent invalid data! Path is not set!'); } if ($parent->getRelativePathSegment() === null) { throw new CmisRuntimeException('Repository sent invalid data! No relative path segement!'); } $folderPath = rtrim((string) $pathProperty->getFirstValue(), '/') . '/'; $paths[] = $folderPath . $parent->getRelativePathSegment(); } return $paths; }
Returns the paths of this object. @return string[] the list of paths of this object or an empty list if this object is unfiled or if this object is the root folder @throws CmisRuntimeException Throws exception if repository sends invalid data
entailment
public function move( ObjectIdInterface $sourceFolderId, ObjectIdInterface $targetFolderId, OperationContextInterface $context = null ) { $context = $this->ensureContext($context); $originalId = $this->getId(); $newObjectId = $this->getId(); $this->getBinding()->getObjectService()->moveObject( $this->getRepositoryId(), $newObjectId, $targetFolderId->getId(), $sourceFolderId->getId(), null ); // invalidate path cache $this->getSession()->removeObjectFromCache($this->getSession()->createObjectId($originalId)); if (empty($newObjectId)) { return null; } $movedObject = $this->getSession()->getObject( $this->getSession()->createObjectId((string) $newObjectId), $context ); if (!$movedObject instanceof FileableCmisObjectInterface) { throw new CmisRuntimeException( 'Moved object is invalid because it must be of type FileableCmisObjectInterface but is not.' ); } return $movedObject; }
Moves this object. @param ObjectIdInterface $sourceFolderId the object ID of the source folder @param ObjectIdInterface $targetFolderId the object ID of the target folder @param OperationContextInterface|null $context the OperationContext to use to fetch the moved object @return FileableCmisObjectInterface the moved object @throws CmisRuntimeException Throws exception if the repository returns an invalid object after the object has been moved
entailment
public function addToFolder(ObjectIdInterface $folderId, $allVersions = true) { $objectId = $this->getId(); $this->getBinding()->getMultiFilingService()->addObjectToFolder( $this->getRepositoryId(), $objectId, $folderId->getId(), $allVersions ); // remove object form cache $this->getSession()->removeObjectFromCache($this->getSession()->createObjectId($objectId)); }
Adds this object to a folder. @param ObjectIdInterface $folderId The folder into which the object is to be filed. @param boolean $allVersions Add all versions of the object to the folder if the repository supports version-specific filing. Defaults to <code>true</code>.
entailment
public function removeFromFolder(ObjectIdInterface $folderId) { $objectId = $this->getId(); $this->getBinding()->getMultiFilingService()->removeObjectFromFolder( $this->getRepositoryId(), $objectId, $folderId->getId(), null ); // remove object form cache $this->getSession()->removeObjectFromCache($this->getSession()->createObjectId($objectId)); }
Removes this object from a folder. @param ObjectIdInterface $folderId the object ID of the folder from which this object should be removed
entailment
protected function ensureContext(OperationContextInterface $context = null) { if ($context === null) { $context = $this->getSession()->getDefaultContext(); } return $context; }
Ensures that the context is set. If the given context is <code>null</code> the session default context will be returned. @param OperationContextInterface|null $context @return OperationContextInterface
entailment
public function getPropertyById($id) { return isset($this->propertiesById[$id]) ? $this->propertiesById[$id] : null; }
Returns a property by ID. Because repositories are not obligated to add property IDs to their query result properties, this method might not always work as expected with some repositories. Use getPropertyByQueryName(String) instead. @param string $id @return PropertyDataInterface|null the property or <code>null</code> if the property doesn't exist or hasn't been requested
entailment
public function getPropertyByQueryName($queryName) { return isset($this->propertiesByQueryName[$queryName]) ? $this->propertiesByQueryName[$queryName] : null; }
Returns a property by query name or alias. @param string $queryName the property query name or alias @return PropertyDataInterface|null the property or <code>null</code> if the property doesn't exist or hasn't been requested
entailment
public function getPropertyMultivalueById($id) { $property = $this->getPropertyById($id); return $property !== null ? $property->getValues() : null; }
Returns a property multi-value by ID. @param string $id the property ID @return array|null the property value or <code>null</code> if the property doesn't exist, hasn't been requested, or the property value isn't set
entailment
public function getPropertyMultivalueByQueryName($queryName) { $property = $this->getPropertyByQueryName($queryName); return $property !== null ? $property->getValues() : null; }
Returns a property multi-value by query name or alias. @param string $queryName the property query name or alias @return array|null the property value or <code>null</code> if the property doesn't exist, hasn't been requested, or the property value isn't set
entailment
public function getPropertyValueById($id) { $property = $this->getPropertyById($id); return $property !== null ? $property->getFirstValue() : null; }
Returns a property (single) value by ID. @param string $id the property ID @return mixed
entailment
public function getPropertyValueByQueryName($queryName) { $property = $this->getPropertyByQueryName($queryName); return $property !== null ? $property->getFirstValue() : null; }
Returns a property (single) value by query name or alias. @param string $queryName the property query name or alias @return mixed the property value or <code>null</code> if the property doesn't exist, hasn't been requested, or the property value isn't set
entailment
public function appendContentStream(StreamInterface $contentStream, $isLastChunk, $refresh = true) { if ($this->getSession()->getRepositoryInfo()->getCmisVersion()->equals(CmisVersion::CMIS_1_0)) { throw new CmisNotSupportedException('This method is not supported for CMIS 1.0 repositories.'); } $newObjectId = $this->getId(); $changeToken = $this->getPropertyValue(PropertyIds::CHANGE_TOKEN); $this->getBinding()->getObjectService()->appendContentStream( $this->getRepositoryId(), $newObjectId, $this->getObjectFactory()->convertContentStream($contentStream), $isLastChunk, $changeToken ); if ($refresh) { $this->refresh(); } if ($newObjectId === null) { return null; } return $this->getSession()->createObjectId($newObjectId); }
Appends a content stream to the content stream of the document and refreshes this object afterwards. If the repository created a new version, this new document is returned. Otherwise the current document is returned. The stream in contentStream is consumed but not closed by this method. @param StreamInterface $contentStream the content stream @param boolean $isLastChunk indicates if this stream is the last chunk of the content @param boolean $refresh if this parameter is set to <code>true</code>, this object will be refreshed after the content stream has been appended @return ObjectIdInterface|null the updated object ID, or <code>null</code> if the repository did not return an object ID @throws CmisNotSupportedException
entailment
public function cancelCheckOut() { $this->getBinding()->getVersioningService()->cancelCheckOut($this->getRepositoryId(), $this->getId()); $this->getSession()->removeObjectFromCache($this); }
If this is a PWC (private working copy) the check out will be reversed.
entailment
public function checkIn( $major, array $properties, StreamInterface $contentStream, $checkinComment, array $policies = [], array $addAces = [], array $removeAces = [] ) { $newObjectId = $this->getId(); $objectFactory = $this->getObjectFactory(); $updatability = [ Updatability::cast(Updatability::READWRITE), Updatability::cast(Updatability::WHENCHECKEDOUT) ]; $this->getBinding()->getVersioningService()->checkIn( $this->getRepositoryId(), $newObjectId, $major, $objectFactory->convertProperties( $properties, $this->getObjectType(), (array) $this->getSecondaryTypes(), $updatability ), $objectFactory->convertContentStream($contentStream), $checkinComment, $objectFactory->convertPolicies($policies), $objectFactory->convertAces($addAces), $objectFactory->convertAces($removeAces) ); // remove PWC from cache, it doesn't exist anymore $this->getSession()->removeObjectFromCache($this); if ($newObjectId === null) { return null; } return $this->getSession()->createObjectId($newObjectId); }
If this is a PWC (private working copy) it performs a check in. If this is not a PWC an exception will be thrown. The stream in contentStream is consumed but not closed by this method. @param boolean $major <code>true</code> if the checked-in document object MUST be a major version. <code>false</code> if the checked-in document object MUST NOT be a major version but a minor version. @param array $properties The property values that MUST be applied to the checked-in document object. @param StreamInterface $contentStream The content stream that MUST be stored for the checked-in document object. The method of passing the contentStream to the server and the encoding mechanism will be specified by each specific binding. MUST be required if the type requires it. @param string $checkinComment Textual comment associated with the given version. MAY be "not set". @param PolicyInterface[] $policies A list of policy ids that MUST be applied to the newly-created document object @param AceInterface[] $addAces A list of ACEs that MUST be added to the newly-created document object. @param AceInterface[] $removeAces A list of ACEs that MUST be removed from the newly-created document object. @return ObjectIdInterface|null The id of the checked-in document. <code>null</code> if repository has not returned the new object id which could happen in case of a repository error
entailment