sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
public function checkOut() { $newObjectId = $this->getId(); $this->getBinding()->getVersioningService()->checkOut($this->getRepositoryId(), $newObjectId); if ($newObjectId === null) { return null; } return $this->getSession()->createObjectId($newObjectId); ...
Checks out the document and returns the object ID of the PWC (private working copy). @return ObjectIdInterface|null PWC object ID
entailment
public function copy( ObjectIdInterface $targetFolderId = null, array $properties = [], VersioningState $versioningState = null, array $policies = [], array $addAces = [], array $removeAces = [], OperationContextInterface $context = null ) { try { ...
Creates a copy of this document, including content. @param ObjectIdInterface|null $targetFolderId the ID of the target folder, <code>null</code> to create an unfiled document @param array $properties The property values that MUST be applied to the object. This list of properties SHOULD only contain properties whose va...
entailment
protected function copyViaClient( ObjectIdInterface $targetFolderId = null, array $properties = [], VersioningState $versioningState = null, array $policies = [], array $addAces = [], array $removeAces = [] ) { $newProperties = []; $allPropertiesConte...
Copies the document manually. The content is streamed from the repository and back. @param ObjectIdInterface|null $targetFolderId the ID of the target folder, <code>null</code> to create an unfiled document @param array $properties The property values that MUST be applied to the object. This list of properties SHOULD ...
entailment
public function deleteContentStream($refresh = true) { $newObjectId = $this->getId(); $changeToken = $this->getPropertyValue(PropertyIds::CHANGE_TOKEN); $this->getBinding()->getObjectService()->deleteContentStream( $this->getRepositoryId(), $newObjectId, ...
Removes the current content stream from the document and refreshes this object afterwards. @param boolean $refresh if this parameter is set to <code>true</code>, this object will be refreshed after the content stream has been deleted @return DocumentInterface|null the updated document, or <code>null</code> if the repo...
entailment
public function getAllVersions(OperationContextInterface $context = null) { $context = $this->ensureContext($context); $versions = $this->getBinding()->getVersioningService()->getAllVersions( $this->getRepositoryId(), $this->getId(), $this->getVersionSeriesId(), ...
Fetches all versions of this document using the given OperationContext. The behavior of this method is undefined if the document is not versionable and can be different for each repository. @param OperationContextInterface|null $context @return DocumentInterface[]
entailment
public function getContentUrl($streamId = null) { $objectService = $this->getBinding()->getObjectService(); if ($objectService instanceof LinkAccessInterface) { if ($streamId === null) { return $objectService->loadContentLink($this->getRepositoryId(), $this->getId()); ...
Returns the content URL of the document or a rendition if the binding supports content URLs. Depending on the repository and the binding, the server might not return the content but an error message. Authentication data is not attached. That is, a user may have to re-authenticate to get the content. @param string|nul...
entailment
public function getContentStream($streamId = null, $offset = null, $length = null) { return $this->getSession()->getContentStream($this, $streamId, $offset, $length); }
Retrieves the content stream that is associated with the given stream ID. This is usually a rendition of the document. @param string|null $streamId the stream ID @param integer|null $offset the offset of the stream or <code>null</code> to read the stream from the beginning @param integer|null $length the maximum lengt...
entailment
public function setContentStream(StreamInterface $contentStream, $overwrite, $refresh = true) { $newObjectId = $this->getId(); $changeToken = $this->getPropertyValue(PropertyIds::CHANGE_TOKEN); $this->getBinding()->getObjectService()->setContentStream( $this->getRepositoryId(), ...
Sets a new content stream for the document. If the repository created a new version, the object ID of this new version is returned. Otherwise the object ID of the current document is returned. The stream in contentStream is consumed but not closed by this method. @param StreamInterface $contentStream the content strea...
entailment
public function isAllowed($entry, $defaultState) { $whited = false; $blacked = false; if (is_array($this->lists)) { foreach ($this->lists as $list) { $allowed = $list->isAllowed($entry); if ($allowed !== null) { if ($allowed) ...
Check if a string is allowed @param string $entry String to compare @param boolean $defaultState Default value @return boolean
entailment
public function all(array $params = array()) { $endpoint = '/admin/smart_collections.json'; $response = $this->request($endpoint, 'GET', $params); return $this->createCollection(SmartCollection::class, $response['smart_collections']); }
Receive a list of all SmartCollection @link https://help.shopify.com/api/reference/smartcollection#index @param array $params @return SmartCollection[]
entailment
public function get($smartCollectionId, array $params = array()) { $endpoint = '/admin/smart_collections/'.$smartCollectionId.'.json'; $response = $this->request($endpoint, 'GET', $params); return $this->createObject(SmartCollection::class, $response['smart_collection']); }
Receive a single smart collection @link https://help.shopify.com/api/reference/smartcollection#show @param integer $smartCollectionId @param array $params @return SmartCollection
entailment
public function create(SmartCollection &$smartCollection) { $data = $smartCollection->exportData(); $endpoint = '/admin/smart_collections.json'; $response = $this->request( $endpoint, 'POST', array( 'smart_collection' => $data ) ); $smartCo...
Create a new smart collection @link https://help.shopify.com/api/reference/smartcollection#create @param SmartCollection $smartCollection @return void
entailment
public function update(SmartCollection &$smartCollection) { $data = $smartCollection->exportData(); $endpoint = '/admin/smart_collections/'.$smart_collection->id.'.json'; $response = $this->request( $endpoint, 'PUT', array( 'smart_collection' => $data ) ...
Modify an existing smart collection @link https://help.shopify.com/api/reference/smartcollection#update @param SmartCollection $smartCollection @return void
entailment
public function delete(SmartCollection $smartCollection) { $request = $this->createRequest('/admin/smart_collections/'.$smartCollection->getId().'.json', static::REQUEST_METHOD_DELETE); $this->send($request); }
Delete an existing smart_collection @link https://help.shopify.com/api/reference/smartcollection#destroy @param SmartCollection $smartCollection @return void
entailment
public function applyAcl( $repositoryId, $objectId, AclInterface $addAces = null, AclInterface $removeAces = null, AclPropagation $aclPropagation = null, ExtensionDataInterface $extension = null ) { // TODO: Implement applyAcl() method. }
Adds or removes the given ACEs to or from the ACL of the object. @param string $repositoryId The identifier for the repository. @param string $objectId The identifier of the object. @param AclInterface|null $addAces The ACEs to be added. @param AclInterface|null $removeAces The ACEs to be removed. @param AclPropagatio...
entailment
public function convertNewTypeSettableAttributes(array $data = null) { if (empty($data)) { return null; } $object = new NewTypeSettableAttributes(); $object->populate( $data, array_combine( JSONConstants::getCapabilityNewTypeSettab...
Create NewTypeSettableAttributes object and populate given data to it @param string[]|null $data @return NewTypeSettableAttributes|null Returns object or <code>null</code> if given data is empty
entailment
public function convertCreatablePropertyTypes(array $data = null) { if (empty($data)) { return null; } $object = new CreatablePropertyTypes(); $canCreate = []; foreach ($data[JSONConstants::JSON_CAP_CREATABLE_PROPERTY_TYPES_CANCREATE] ?? [] as $canCreateItem) { ...
Create CreatablePropertyTypes object and populate given data to it @param array|null $data The data that should be populated to the CreatablePropertyTypes object @return CreatablePropertyTypes|null Returns a CreatablePropertyTypes object or <code>null</code> if empty data is given.
entailment
public function convertTypeDefinition(array $data = null) { if (empty($data)) { return null; } if (empty($data[JSONConstants::JSON_TYPE_ID])) { throw new CmisInvalidArgumentException('Id of type definition is empty but must not be empty!'); } $typeDef...
Convert an array to a type definition object @param array|null $data @return AbstractTypeDefinition|null @throws CmisInvalidArgumentException
entailment
private function convertTypeDefinitionSpecificData(array $data, MutableTypeDefinitionInterface $typeDefinition) { if ($typeDefinition instanceof MutableDocumentTypeDefinitionInterface) { if (!empty($data[JSONConstants::JSON_TYPE_CONTENTSTREAM_ALLOWED])) { $data[JSONConstants::JSO...
Convert specific type definition data so it can be populated to the type definition @param MutableTypeDefinitionInterface $typeDefinition The type definition to set the data to @param array $data The data that contains the values that should be applied to the object @return MutableTypeDefinitionInterface The type defi...
entailment
public function convertTypeMutability(array $data = null) { if (empty($data)) { return null; } $typeMutability = new TypeMutability(); $typeMutability->populate( $data, array_combine( JSONConstants::getTypeTypeMutabilityKeys(), ...
Convert an array to a type mutability object @param array|null $data The data that should be populated to the object @return TypeMutability|null Returns the type mutability object or <code>null</code> if empty array is given
entailment
protected function preparePropertyDefinitionData(array $data) { $data[JSONConstants::JSON_PROPERTY_TYPE_PROPERTY_TYPE] = PropertyType::cast( $data[JSONConstants::JSON_PROPERTY_TYPE_PROPERTY_TYPE] ); if (isset($data[JSONConstants::JSON_PROPERTY_TYPE_DEAULT_VALUE])) { ...
Cast data values to the expected type @param array $data @return array
entailment
public function convertObject(array $data = null) { if (empty($data)) { return null; } $object = new ObjectData(); $acl = $this->convertAcl( $data[JSONConstants::JSON_OBJECT_ACL] ?? [], (boolean) ($data[JSONConstants::JSON_OBJECT_EXACT_ACL] ?? fal...
Converts an object. @param array|null $data @return null|ObjectData
entailment
public function convertRendition(array $data = null) { if (empty($data)) { return null; } $rendition = new RenditionData(); if (isset($data[JSONConstants::JSON_RENDITION_HEIGHT])) { $rendition->setHeight((integer) $data[JSONConstants::JSON_RENDITION_HEIGHT]);...
Convert given input data to a RenditionData object @param array|null $data @return null|RenditionData
entailment
public function convertRenditions(array $data = null) { return array_filter( array_map( [$this, 'convertRendition'], array_filter( $data, 'is_array' ) ), function ($item) { ...
Convert given input data to a list of RenditionData objects @param array|null $data @return RenditionData[]
entailment
public function convertExtension(array $data = null, array $cmisKeys = []) { $extensions = []; foreach (array_diff_key((array) $data, array_flip($cmisKeys)) as $key => $value) { if (!is_array($value)) { $value = (empty($value)) ? null : (string) $value; ...
Convert given input data to an Extension object @param array|null $data @param string[] $cmisKeys @return CmisExtensionElement[]
entailment
public function convertExtensionFeatures(array $data = null) { $features = []; $extendedFeatures = array_filter(array_filter((array) $data, 'is_array'), function ($item) { return !empty($item); }); foreach ($extendedFeatures as $extendedFeature) { $feature = new ExtensionFeatur...
Convert given input data to an ExtensionFeature object @param array|null $data @return ExtensionFeature[]
entailment
public function convertPolicyIdList(array $data = null) { $policyIdsList = new PolicyIdList(); $policyIdsList->setPolicyIds( array_filter( array_filter( $data[JSONConstants::JSON_OBJECT_POLICY_IDS_IDS] ?? [], 'is_string' ...
Converts a list of policy ids. @param array|null $data @return PolicyIdList List of policy ids
entailment
public function convertFromTypeDefinition(TypeDefinitionInterface $typeDefinition) { $propertyList = [ 'baseTypeId' => JSONConstants::JSON_TYPE_BASE_ID, 'parentTypeId' => JSONConstants::JSON_TYPE_PARENT_ID ]; if ($typeDefinition instanceof RelationshipTypeDefinitionI...
Convert a type definition object to a custom format @param TypeDefinitionInterface $typeDefinition @return string JSON representation of the type definition
entailment
protected function castArrayValuesToSimpleTypes(array $data) { foreach ($data as $key => $item) { if (is_array($item)) { $data[$key] = $this->castArrayValuesToSimpleTypes($item); } elseif (is_object($item)) { $data[$key] = $this->convertObjectToSimpleT...
Cast values of an array to simple types @param array $data @return array
entailment
protected function convertObjectToSimpleType($data) { /** @var null|TypeConverterInterface $converterClassName */ $converterClassName = null; if (class_exists($this->buildConverterClassName(get_class($data)))) { $converterClassName = $this->buildConverterClassName(get_class($data...
Convert an object to a simple type representation @param mixed $data @return mixed @throws CmisRuntimeException Exception is thrown if no type converter could be found to convert the given data to a simple type
entailment
public function convertTypeChildren(array $data = null) { if (empty($data)) { return null; } $result = new TypeDefinitionList(); $types = []; $typesList = $data[JSONConstants::JSON_TYPESLIST_TYPES] ?? []; foreach (array_filter($typesList, 'is_array') as...
Convert given input data to a TypeChildren object @param array|null $data @return TypeDefinitionListInterface|null Returns a TypeDefinitionListInterface object or <code>null</code> if empty data is given.
entailment
public function convertTypeDescendants(array $data = null) { $result = []; if (empty($data)) { return $result; } foreach (array_filter($data, 'is_array') as $itemData) { $container = new TypeDefinitionContainer(); $typeDefinition = $this->conve...
Convert given input data to a TypeDescendants object @param array|null $data @return TypeDefinitionContainerInterface[] Returns an array of TypeDefinitionContainerInterface objects
entailment
public function convertObjectInFolderList(array $data = null) { if (empty($data)) { return null; } $objects = array_filter( array_map( [$this, 'convertObjectInFolder'], $data[JSONConstants::JSON_OBJECTINFOLDERLIST_OBJECTS] ?? [] ...
Convert given input data to a ObjectInFolderList object @param array|null $data @return null|ObjectInFolderList
entailment
public function convertObjectInFolder(array $data = null) { if (empty($data)) { return null; } $objectInFolderData = new ObjectInFolderData(); $object = $this->convertObject($data[JSONConstants::JSON_OBJECTINFOLDER_OBJECT] ?? []); if ($object !== null) { ...
Convert given input data to a ObjectInFolderData object @param array|null $data @return ObjectInFolderData|null
entailment
public function convertObjectParents(array $data = null) { return array_filter( array_map( [$this, 'convertObjectParentData'], (array) ($data ?? []) ), function ($item) { return !empty($item); // @TODO once a...
Convert given input data to a list of ObjectParentData objects @param array|null $data @return ObjectParentData[]
entailment
public function convertObjectParentData(array $data = null) { if (empty($data)) { return null; } $parent = new ObjectParentData(); $object = $this->convertObject($data[JSONConstants::JSON_OBJECTPARENTS_OBJECT] ?? null); if ($object !== null) { $parent...
Convert given input data to a ObjectParentData object @param array|null $data @return null|ObjectParentData
entailment
public function convertObjectList(array $data = null) { if (empty($data)) { return null; } $objectList = new ObjectList(); $objects = []; foreach ((array) ($data[JSONConstants::JSON_OBJECTLIST_OBJECTS] ?? []) as $objectData) { $object = $this->conver...
Convert given input data array to a ObjectList object @param array|null $data @return null|ObjectList
entailment
public function convertQueryResultList(array $data = null) { if (empty($data)) { return null; } $objectList = new ObjectList(); $objects = []; foreach ((array) ($data[JSONConstants::JSON_QUERYRESULTLIST_RESULTS] ?? []) as $objectData) { $object = $th...
Convert given input data array from query result to a ObjectList object @param array|null $data @return null|ObjectList
entailment
public function convertDescendants(array $data = null) { return array_filter( array_map( [$this, 'convertDescendant'], $data ?? [] ), function ($item) { return !empty($item); } ); }
Convert given input data array to a ObjectList object @param array|null $data @return ObjectInFolderContainer[]
entailment
public function convertDescendant(array $data = null) { if (empty($data)) { return null; } $object = $this->convertObjectInFolder($data[JSONConstants::JSON_OBJECTINFOLDERCONTAINER_OBJECT] ?? null); if ($object === null) { throw new CmisRuntimeException('Give...
Convert given input data array to a ObjectInFolderContainer object @param array|null $data @return null|ObjectInFolderContainer @throws CmisRuntimeException
entailment
public function convertFailedToDelete(array $data = null) { $result = new FailedToDeleteData(); if (empty($data)) { return $result; } $result->setIds(array_map('strval', $data[JSONConstants::JSON_FAILEDTODELETE_ID] ?? [])); $result->setExtensions($this->convertE...
Converts FailedToDelete ids. @param array|null $data @return FailedToDeleteData
entailment
public static function getMatchRegex() { $pRegex = IPRange::getMatchRegex(); $regex = substr($pRegex, 2, ( strlen($pRegex) - 4 )); $separator = static::$separatorRegex; $maskRegex = static::getMaskRegex(); return sprintf("/^%s%s%s$/", $regex, $separator, $maskReg...
{@inheritdoc}
entailment
public function getRange($long = true) { $parts = $this->getParts(); $ret = array(); $ipLong = $this->ip2long($parts['ip']); $maskLong = $this->ip2long($parts['mask']); $ret['begin'] = $this->IPLongAnd( $ipLong, $maskLong ); $ret...
{@inheritdoc}
entailment
public function get($orderId, $transactionId, array $params = array()) { $endpoint = '/admin/orders/'.$orderId.'/transactions/'.$transactionId.'.json'; $response = $this->request($endpoint, 'GET', $params); return $this->createObject(Transaction::class, $response['transaction']); }
Get a single Transaction @link https://help.shopify.com/api/reference/transaction#show @param integer $orderId @param integer $transactionId @param array $params @return Transaction
entailment
public function create(Transaction &$transaction) { $data = $transaction->exportData(); $endpoint = '/admin/transactions.json'; $response = $this->request( $endpoint, 'POST', array( 'transaction' => $data ) ); $transaction->setData($respons...
Create a new transaction @link https://help.shopify.com/api/reference/transaction#create @param Transaction $transaction @return void
entailment
public function get($themeId, array $params = array()) { $endpoint = '/admin/themes/'.$themeId.'.json'; $response = $this->request($endpoint, 'GET', $params); return $this->createObject(Theme::class, $response['theme']); }
Receive a single theme @link https://help.shopify.com/api/reference/theme#show @param integer $themeId @param array $params @return Theme
entailment
public function all(array $params = array()) { $endpoint = '/admin/themes.json'; $response = $this->request($endpoint, 'GET', $params); return $this->createCollection(Theme::class, $response['themes']); }
Receive a list of all themes @link https://help.shopify.com/api/reference/theme#index @param array $params @return Theme[]
entailment
public function create(Theme &$theme) { $data = $theme->exportData(); $endpoint = '/admin/themes.json'; $response = $this->request( $endpoint, 'POST', array( 'theme' => $data ) ); $theme->setData($response['theme']); }
Create a new theme @link https://help.shopify.com/api/reference/theme#create @param Theme $theme @return void
entailment
public function update(Theme &$theme) { $data = $theme->exportData(); $endpoint = '/admin/themes/'.$theme->id.'.json'; $response = $this->request( $endpoint, 'PUT', array( 'theme' => $data ) ); $theme->setData($response['theme']); }
Update a theme @link https://help.shopify.com/api/reference/theme#update @param Theme $theme @return void
entailment
public function getBindingType() { $bindingType = $this->session->get(SessionParameter::BINDING_TYPE); if (!is_string($bindingType)) { return BindingType::cast(BindingType::CUSTOM); } try { return BindingType::cast($bindingType); } catch (InvalidEnum...
Returns the binding type. @return BindingType
entailment
private function search(string $parameter, string $value): SeriesData { $options = [ 'query' => [ $parameter => $value, ], 'http_errors' => false ]; $json = $this->client->performApiCallWithJsonResponse('get', '/search/series', $options); ...
Search for a series based on parameter and value. @param string $parameter @param string $value @return SeriesData @throws RequestFailedException @throws UnauthorizedException @throws InvalidArgumentException @throws InvalidJsonInResponseException
entailment
public function isImage() { $mime = $this->getMimeType(); // The $image_mimes property contains an array of file extensions and // their associated MIME types. We will loop through them and look for // the MIME type of the current UploadedFile. foreach ($this->image_mimes as...
Utility method for detecing whether a given file upload is an image. @return bool
entailment
public function getErrorMessage($code = null) { $code = $code ?: $this->$code; static $errors = [ UPLOAD_ERR_INI_SIZE => 'The file "%s" exceeds your upload_max_filesize ini directive (limit is %d kb).', UPLOAD_ERR_FORM_SIZE => 'The file "%s" exceeds the upload limit defined ...
Returns an informative upload error message. @param int $code @return string
entailment
protected function getName($name) { $name = parent::getName($name); // This fixes any URL encoded filename and sanitize it $name = strtolower(urldecode($name)); // Replace spaces with a dash $name = preg_replace('!\s+!', '-', $name); // Remove odd characters ...
Returns locale independent base name of the given path. @param string $name The new file name @return string containing
entailment
public function resize(UploadedFile $file, $style) { $quality = $this->option('quality', 90); $this->imagine = new $this->image_processor; $file_path = @tempnam(sys_get_temp_dir(), 'STP') . '.' . $file->getClientOriginalName(); list($width, $height, $option, $enlarge) = $this->pars...
Resize an image using the computed settings. @param UploadedFile $file @param string $style @return string
entailment
protected function parseStyleDimensions($style) { if (is_callable($style) === true) { return [null, null, 'custom', false]; } $enlarge = true; // Don't allow the package to enlarge an image if (strpos($style, '?') !== false) { $style = str_replace('?...
parseStyleDimensions method Parse the given style dimensions to extract out the file processing options, perform any necessary image resizing for a given style. @param string $style @return array
entailment
protected function resizeLandscape(ImageInterface $image, $width, $height, $enlarge = true) { // Don't enlarge a small image $box = $image->getSize(); $ratio = $box->getHeight() / $box->getWidth(); if ($enlarge === false && $box->getWidth() < $width) { $width = $box->get...
Resize an image as a landscape (width only) @param ImageInterface $image @param string $width @param string $height @param bool $enlarge @return ManipulatorInterface
entailment
protected function resizePortrait(ImageInterface $image, $width, $height, $enlarge = true) { // Don't enlarge a small image $box = $image->getSize(); $ratio = $box->getWidth() / $box->getHeight(); if ($enlarge === false && $box->getHeight() < $height) { $height = $box->g...
Resize an image as a portrait (height only) @param ImageInterface $image @param string $width @param string $height @param bool $enlarge @return ManipulatorInterface
entailment
protected function resizeCrop(ImageInterface $image, $width, $height, $enlarge = true) { $size = $image->getSize(); if ($enlarge === false && $size->getWidth() < $width) { $width = $size->getWidth(); } if ($enlarge === false && $size->getHeight() < $height) { ...
Resize an image and then center crop it. @param ImageInterface $image @param string $width @param string $height @param bool $enlarge @return ManipulatorInterface
entailment
protected function resizeExact(ImageInterface $image, $width, $height, $enlarge = true) { return $image->resize(new Box($width, $height)); }
Resize an image to an exact width and height. @param ImageInterface $image @param string $width @param string $height @param bool $enlarge @return ImageInterface
entailment
protected function resizeAuto(ImageInterface $image, $width, $height, $enlarge = true) { $size = $image->getSize(); $original_width = $size->getWidth(); $original_height = $size->getHeight(); if ($original_height < $original_width) { return $this->resizeLandscape($image,...
Resize an image as closely as possible to a given width and height while still maintaining aspect ratio. This method is really just a proxy to other resize methods: If the current image is wider than it is tall, we'll resize landscape. If the current image is taller than it is wide, we'll resize portrait. If the imag...
entailment
protected function resizeCustom(UploadedFile $file, $callable, $enlarge = true) { return call_user_func_array($callable, [$file, $this->imagine, $enlarge]); }
Resize an image using a user defined callback. @param UploadedFile $file @param $callable @param bool $enlarge @return \stdClass
entailment
protected function getOptimalCrop(BoxInterface $size, $width, $height, $enlarge = true) { $height_ratio = $size->getHeight() / $height; $width_ratio = $size->getWidth() / $width; if ($height_ratio < $width_ratio) { $optimal_ratio = $height_ratio; } else { ...
Attempts to find the best way to crop. Takes into account the image being a portrait or landscape. @param BoxInterface $size @param string $width @param string $height @param bool $enlarge @return array
entailment
protected function autoOrient($path, ImageInterface $image) { if (function_exists('exif_read_data')) { $exif = exif_read_data($path); if (isset($exif['Orientation'])) { switch ($exif['Orientation']) { case 2: $image->flipHo...
Re-orient an image using its embedded Exif profile orientation: 1. Attempt to read the embedded exif data inside the image to determine it's orientation. if there is no exif data (i.e an exeption is thrown when trying to read it) then we'll just return the image as is. 2. If there is exif data, we'll rotate and flip t...
entailment
public function get(): UserData { $json = $this->client->performApiCallWithJsonResponse('get', '/user'); return ResponseHandler::create($json, ResponseHandler::METHOD_USER)->handle(); }
Get basic information about the currently authenticated user. @return UserData @throws RequestFailedException @throws UnauthorizedException @throws InvalidArgumentException @throws InvalidJsonInResponseException
entailment
public function getFavorites(): UserFavoritesData { $json = $this->client->performApiCallWithJsonResponse('get', '/user/favorites'); return ResponseHandler::create($json, ResponseHandler::METHOD_USER_FAVORITES)->handle(); }
Get user favorites. @return UserFavoritesData @throws RequestFailedException @throws UnauthorizedException @throws InvalidArgumentException @throws InvalidJsonInResponseException
entailment
public function removeFavorite(int $identifier): bool { $response = $this->client->performApiCall( 'delete', sprintf('user/favorites/%d', (int) $identifier), [ 'http_errors' => false ] ); return $response->getStatusCode() === 2...
Remove series with $identifier from favorites. @param int $identifier @return bool @throws UnauthorizedException
entailment
public function addFavorite(int $identifier): UserFavoritesData { $identifier = (int) $identifier; try { $json = $this->client->performApiCallWithJsonResponse( 'put', sprintf('user/favorites/%d', $identifier), [ 'http_e...
Add series with $identifier to favorites. @param int $identifier @return UserFavoritesData @throws RequestFailedException @throws UnauthorizedException @throws InvalidArgumentException @throws InvalidJsonInResponseException @throws CouldNotAddFavoriteException
entailment
public function getRatings(string $type = null): UserRatingsData { if ($type !== null && !in_array($type, self::$ratingTypes, true)) { throw new InvalidArgumentException( 'Invalid rating type, use one of these instead: ' . implode(self::$ratingTypes, ', ') ); ...
Get user ratings. @param string|null $type Use class constants UsersExtension::RATING_TYPE_* @return UserRatingsData @throws RequestFailedException @throws UnauthorizedException @throws InvalidArgumentException @throws InvalidJsonInResponseException
entailment
public function addRating(int $type, int $itemId, int $rating): UserRatingsDataNoLinks { if (!in_array($type, self::$ratingTypes, true)) { throw new InvalidArgumentException( 'Invalid rating type, use one of these instead: ' . implode(self::$ratingTypes, ', ') ); ...
Add user rating. @param int $type Use class constants UsersExtension::RATING_TYPE_* @param int $itemId @param int $rating Value between 1 and 10 @return UserRatingsDataNoLinks @throws RequestFailedException @throws UnauthorizedException @throws InvalidArgumentException @throws InvalidJsonInResponseException
entailment
public function updateRating(int $type, int $itemId, int $rating): UserRatingsDataNoLinks { return $this->addRating($type, $itemId, $rating); }
Update user rating. @param int $type Use class constants UsersExtension::RATING_TYPE_* @param int $itemId @param int $rating Value between 1 and 10 @return UserRatingsDataNoLinks @throws RequestFailedException @throws UnauthorizedException @throws InvalidArgumentException @throws InvalidJsonInResponseException
entailment
public function removeRating(int $type, int $itemId): bool { $response = $this->client->performApiCall( 'delete', sprintf('user/ratings/%d/%d', (int) $type, (int) $itemId), [ 'http_errors' => false ] ); return $response->getSta...
Remove user rating. @param int $type @param int $itemId @return bool @throws UnauthorizedException
entailment
private function getApiErrorMessage(ResponseInterface $response): string { try { $body = $response->getBody()->getContents(); } catch (\RuntimeException $re) { return ''; } if (strpos($body, '"Error"') !== false && ($body = json_decode($body, true...
Extract error message from response body. @param ResponseInterface $response @return string
entailment
public function login(string $apiKey, string $username = null, string $accountIdentifier = null): string { $this->client->setToken(null); $data = [ 'apikey' => $apiKey ]; if ($username !== null) { $data['username'] = $username; } if ($accoun...
Returns a session token to be included in the rest of the requests. Example of usage: $token = $client->authentication()->login('apikey', 'username', 'accountIdentifier'); $client->setToken($token); @param string $apiKey @param string $username @param string $accountIdentifier @return string @throws CouldNotLoginExce...
entailment
public function refreshToken(): string { $data = $this->client->performApiCallWithJsonResponse('get', '/refresh_token'); $data = (array) json_decode($data); if (array_key_exists('token', $data)) { return $data['token']; } throw new TokenNotFoundInResponseExcepti...
Refreshes your current, valid JWT token and returns a new token. @return string @throws TokenNotFoundInResponseException @throws RequestFailedException @throws UnauthorizedException
entailment
public function interpolate($string, $style = '') { return preg_replace_callback("/{(([[:alnum:]]|_|\.|-)+)?}/", function ($match) use ($style) { $key = $match[1]; // Create local method call. $method = 'get' . studly_case($key); // Check for a custom interp...
Interpolate a string. @param string $string @param string $style @return string
entailment
protected function getId() { if ($key = $this->manager->config('model_primary_key')) { return $this->manager->getInstance()->{$key}; } return $this->manager->getInstance()->getKey(); }
Returns the id of the current object instance. @return string
entailment
public function handle() { $data = [ 'table' => $this->argument('table'), 'attachment' => $this->argument('attachment'), 'queueable' => $this->option('queueable'), ]; // Create filename $file = base_path("database/migrations/" . date('Y_m_d_His') ...
Execute the console command. @return void
entailment
public function changeConfig($config) { if (!is_array($config)) { return false; } $this->config = array_merge($this->config, $config); return true; }
Change the configuration values. @param array $configArray @return bool
entailment
public function set($key, $content, $expiry = 0) { $cacheObj = new \stdClass(); if (!is_string($content)) { $content = serialize($content); } $cacheObj->content = $content; if (!$expiry) { // If no expiry specified, set to 'Never' expire timestamp (...
Sets an item in the cache. @param mixed $key @param mixed $content @param int $expiry @return bool
entailment
public function get($key) { $filePath = $this->getFilePathFromKey($key); if (!file_exists($filePath)) { return false; } if (!is_readable($filePath)) { return false; } $cacheFileData = file_get_contents($filePath); if ($this->config[...
Returns a value from the cache. @param string $key @return mixed
entailment
public function delete($key) { $filePath = $this->getFilePathFromKey($key); if (!file_exists($filePath)) { return false; } return unlink($filePath); }
Remove a value from the cache. @param string $key @return bool
entailment
private function deleteDirectoryTree($directory) { $filePaths = scandir($directory); foreach ($filePaths as $filePath) { if ($filePath == '.' || $filePath == '..') { continue; } $fullFilePath = $directory.'/'.$filePath; if (is_dir($fu...
Removes cache files from a given directory. @param string $directory @return bool
entailment
public function increment($key, $offset = 1) { $filePath = $this->getFilePathFromKey($key); if (!file_exists($filePath)) { return false; } if (!is_readable($filePath)) { return false; } $cacheFileData = file_get_contents($filePath); ...
Increments a value within the cache. @param string $key @param int $offset @return bool
entailment
public function replace($key, $content, $expiry = 0) { if (!$this->get($key)) { return false; } return $this->set($key, $content, $expiry); }
Replaces a value within the cache. @param string $key @param mixed $content @param int $expiry @return bool
entailment
protected function getFilePathFromKey($key) { $key = basename($key); $badChars = ['-', '.', '_', '\\', '*', '\"', '?', '[', ']', ':', ';', '|', '=', ',']; $key = str_replace($badChars, '/', $key); while (strpos($key, '//') !== false) { $key = str_replace('//', '/', $key);...
Returns the file path from a given cache key, creating the relevant directory structure if necessary. @param string $key @return string
entailment
public function make($file) { if ($file instanceof SymfonyUploadedFile) { return $this->createFromObject($file); } if (is_array($file)) { if (isset($file['base64']) && isset($file['name'])) { return $this->createFromBase64($file['name'], $file['base64...
Build an UploadedFile object using various file input types. @param mixed $file @return \Torann\MediaSort\File\UploadedFile
entailment
protected function createFromObject(SymfonyUploadedFile $file) { $path = $file->getPathname(); $original_name = $file->getClientOriginalName(); $mime_type = $file->getClientMimeType(); $size = $file->getSize(); $error = $file->getError(); $upload_file = new UploadedF...
Build a \Torann\MediaSort\File\UploadedFile object from a Symfony\Component\HttpFoundation\File\UploadedFile object. @param \Symfony\Component\HttpFoundation\File\UploadedFile $file @return \Torann\MediaSort\File\UploadedFile @throws \Torann\MediaSort\Exceptions\FileException
entailment
protected function createFromBase64($filename, $data) { // Get temporary destination $destination = sys_get_temp_dir() . '/' . str_random(4) . '-' . $filename; // Create destination if not already there if (is_dir(dirname($destination)) === false) { mkdir(dirname($destin...
Build a Torann\MediaSort\File\UploadedFile object from a base64 encoded image array. Usually from an API request. @param array $filename @param array $data @return \Torann\MediaSort\File\UploadedFile
entailment
protected function createFromUrl($file) { $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $file, CURLOPT_RETURNTRANSFER => 1, CURLOPT_USERAGENT => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578....
Fetch a remote file using a string URL and convert it into an instance of Torann\MediaSort\File\UploadedFile. @param string $file @return \Torann\MediaSort\File\UploadedFile
entailment
protected function setPathPrefix() { if ($this->media->local_root) { // Interpolate path $root = $this->media->getInterpolator() ->interpolate($this->media->local_root); // Set path $this->filesystem->getDriver() ->getAdapter()...
Set local path prefix from settings. @return void
entailment
public function register() { $this->registerMediaSort(); if ($this->app->runningInConsole()) { $this->registerResources(); $this->registerCommands(); } $this->mergeConfigFrom( __DIR__ . '/../config/mediasort.php', 'mediasort' ); }
Register the service provider. @return void
entailment
protected function registerMediaSort() { $this->media_sort_null = sha1(time()); if (defined('MEDIASORT_NULL') === false) { define('MEDIASORT_NULL', $this->media_sort_null); } }
Register \Torann\MediaSort\MediaSort with the container. @return void
entailment
public function registerCommands() { $this->app->bind('mediasort.fasten', function ($app) { return new Commands\FastenCommand( $app['view'], $app['files'] ); }); // TODO: Get this working //$this->app->bind('mediasort.refresh', function ($app)...
Register commands. @return void
entailment
public function handle(): ValueObject { $data = $this->getData(); $class = self::$mapping[$this->method]; return new $class($data); }
{@inheritdoc} @throws InvalidJsonInResponseException
entailment
public function all(): LanguageData { $json = $this->client->performApiCallWithJsonResponse('get', '/languages'); return ResponseHandler::create($json, ResponseHandler::METHOD_LANGUAGES)->handle(); }
Get all available languages. @return LanguageData @throws RequestFailedException @throws UnauthorizedException @throws InvalidJsonInResponseException @throws InvalidArgumentException
entailment
public function get($identifier): Language { $json = $this->client->performApiCallWithJsonResponse('get', sprintf('/languages/%d', (int) $identifier)); return ResponseHandler::create($json, ResponseHandler::METHOD_LANGUAGE)->handle(); }
Get information about a particular language, given the language ID. @param int $identifier @return Language @throws RequestFailedException @throws UnauthorizedException @throws InvalidJsonInResponseException @throws InvalidArgumentException
entailment
public function getById($id, array $options = []) { $query = $this->createBaseBuilder($options); return $query->find($id); }
Get a resource by its primary key @param mixed $id @param array $options @return Collection
entailment
public function getRecent(array $options = []) { $query = $this->createBaseBuilder($options); $query->orderBy($this->getCreatedAtColumn(), 'DESC'); return $query->get(); }
Get all resources ordered by recentness @param array $options @return Collection
entailment
public function getRecentWhere($column, $value, array $options = []) { $query = $this->createBaseBuilder($options); $query->where($column, $value); $query->orderBy($this->getCreatedAtColumn(), 'DESC'); return $query->get(); }
Get all resources by a where clause ordered by recentness @param string $column @param mixed $value @param array $options @return Collection
entailment