_id
stringlengths 2
7
| title
stringlengths 3
151
| partition
stringclasses 3
values | text
stringlengths 83
13k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q258400 | AbstractSubject.getRootCategory | test | public function getRootCategory()
{
// load the actual store view code
$storeViewCode = $this->getStoreViewCode($this->getDefaultStoreViewCode());
// query weather or not we've a root category or not
if (isset($this->rootCategories[$storeViewCode])) {
return $this->rootCategories[$storeViewCode];
}
// throw an exception if the root category is NOT available
throw new \Exception(sprintf('Root category for %s is not available', $storeViewCode));
} | php | {
"resource": ""
} |
q258401 | AbstractSubject.resolveOriginalColumnName | test | public function resolveOriginalColumnName($columnName)
{
// try to load the original data
$originalData = $this->getOriginalData();
// query whether or not original data is available
if (isset($originalData[ColumnKeys::ORIGINAL_COLUMN_NAMES])) {
// query whether or not the original column name is available
if (isset($originalData[ColumnKeys::ORIGINAL_COLUMN_NAMES][$columnName])) {
return $originalData[ColumnKeys::ORIGINAL_COLUMN_NAMES][$columnName];
}
// query whether or a wildcard column name is available
if (isset($originalData[ColumnKeys::ORIGINAL_COLUMN_NAMES]['*'])) {
return $originalData[ColumnKeys::ORIGINAL_COLUMN_NAMES]['*'];
}
}
// return the original column name
return $columnName;
} | php | {
"resource": ""
} |
q258402 | AbstractSubject.getOriginalData | test | public function getOriginalData()
{
// initialize the array for the original data
$originalData = array();
// query whether or not the column contains original data
if ($this->hasOriginalData()) {
// unerialize the original data from the column
$originalData = unserialize($this->row[$this->headers[ColumnKeys::ORIGINAL_DATA]]);
}
// return an empty array, if not
return $originalData;
} | php | {
"resource": ""
} |
q258403 | AbstractSubject.hasOriginalData | test | public function hasOriginalData()
{
return isset($this->headers[ColumnKeys::ORIGINAL_DATA]) && isset($this->row[$this->headers[ColumnKeys::ORIGINAL_DATA]]);
} | php | {
"resource": ""
} |
q258404 | AbstractSubject.wrapException | test | public function wrapException(
array $columnNames = array(),
\Exception $parent = null,
$className = '\TechDivision\Import\Exceptions\WrappedColumnException'
) {
// initialize the message
$message = $parent->getMessage();
// query whether or not has been a result of invalid data of a previous column of a CSV file
if ($this->hasOriginalData()) {
// load the original data
$originalData = $this->getOriginalData();
// replace old filename and line number of the original message
$message = $this->appendExceptionSuffix(
$this->stripExceptionSuffix($message),
$originalData[ColumnKeys::ORIGINAL_FILENAME],
$originalData[ColumnKeys::ORIGINAL_LINE_NUMBER]
);
} else {
// append filename and line number to the original message
$message = $this->appendExceptionSuffix(
$this->stripExceptionSuffix($message),
$this->filename,
$this->lineNumber
);
}
// query whether or not, column names has been passed
if (sizeof($columnNames) > 0) {
// prepare the original column names
$originalColumnNames = array();
foreach ($columnNames as $columnName) {
$originalColumnNames[] = $this->resolveOriginalColumnName($columnName);
}
// append the column information
$message = sprintf('%s in column(s) %s', $message, implode(', ', $originalColumnNames));
}
// create a new exception and wrap the parent one
return new $className($message, null, $parent);
} | php | {
"resource": ""
} |
q258405 | AbstractSubject.appendExceptionSuffix | test | public function appendExceptionSuffix($message = null, $filename = null, $lineNumber = null)
{
// query whether or not a filename has been passed
if ($filename === null) {
$filename = $this->getFilename();
}
// query whether or not a line number has been passed
if ($lineNumber === null) {
$lineNumber = $this->getLineNumber();
}
// if no message has been passed, only return the suffix
if ($message === null) {
return sprintf(' in file %s on line %d', $filename, $lineNumber);
}
// concatenate the message with the suffix and return it
return sprintf('%s in file %s on line %d', $message, $filename, $lineNumber);
} | php | {
"resource": ""
} |
q258406 | FileUploadTrait.getNewFileName | test | public function getNewFileName($targetFilename)
{
// load the file information
$fileInfo = pathinfo($targetFilename);
// query whether or not, the file exists
if ($this->getFilesystemAdapter()->isFile($targetFilename)) {
// initialize the incex and the basename
$index = 1;
$baseName = $fileInfo['filename'] . '.' . $fileInfo['extension'];
// prepare the new filename by raising the index
while ($this->getFilesystemAdapter()->isFile($fileInfo['dirname'] . '/' . $baseName)) {
$baseName = $fileInfo['filename'] . '_' . $index . '.' . $fileInfo['extension'];
$index++;
}
// set the new filename
$targetFilename = $baseName;
} else {
// if not, simply return the filename
return $fileInfo['basename'];
}
// return the new filename
return $targetFilename;
} | php | {
"resource": ""
} |
q258407 | FileUploadTrait.uploadFile | test | public function uploadFile($filename)
{
// trim the leading /, if available
$trimmedFilename = ltrim($filename, '/');
$mediaDir = ltrim($this->getMediaDir(), '/');
$imagesFileDir = ltrim($this->getImagesFileDir(), '/');
// prepare source/target filename
$sourceFilename = sprintf('%s/%s', $imagesFileDir, $trimmedFilename);
$targetFilename = sprintf('%s/%s', $mediaDir, $trimmedFilename);
// query whether or not the image file to be imported is available
if (!$this->getFilesystemAdapter()->isFile($sourceFilename)) {
throw new \Exception(sprintf('Media file %s not available', $sourceFilename));
}
// prepare the target filename, if necessary
$newTargetFilename = $this->getNewFileName($targetFilename);
$targetFilename = str_replace(basename($targetFilename), $newTargetFilename, $targetFilename);
// make sure, the target directory exists
if (!$this->getFilesystemAdapter()->isDir($targetDirectory = dirname($targetFilename))) {
$this->getFilesystemAdapter()->mkdir($targetDirectory, 0755);
}
// copy the image to the target directory
$this->getFilesystemAdapter()->copy($sourceFilename, $targetFilename);
// return the new target filename
return str_replace($mediaDir, '', $targetFilename);
} | php | {
"resource": ""
} |
q258408 | FileUploadTrait.deleteFile | test | public function deleteFile($filename)
{
// trim the leading /, if available
$trimmedFilename = ltrim($filename, '/');
$mediaDir = ltrim($this->getMediaDir(), '/');
// prepare source/target filename
$targetFilename = sprintf('%s/%s', $mediaDir, $trimmedFilename);
// query whether or not the image file to be deleted is available
if (!$this->getFilesystemAdapter()->isFile($targetFilename)) {
throw new \Exception(sprintf('Media file %s not available', $targetFilename));
}
// delte the image from the target directory
$this->getFilesystemAdapter()->delete($targetFilename);
} | php | {
"resource": ""
} |
q258409 | EavEntityTypeRepository.findAll | test | public function findAll()
{
// initialize the array for the EAV entity types
$eavEntityTypes = array();
// try to load the EAV entity types
$this->eavEntityTypeStmt->execute();
// load the available EAV entity types
$availableEntityTypes = $this->eavEntityTypeStmt->fetchAll(\PDO::FETCH_ASSOC);
// prepare the EAV entity types => we need the entity type code as key
foreach ($availableEntityTypes as $eavEntityType) {
$eavEntityTypes[$eavEntityType[MemberNames::ENTITY_TYPE_CODE]] = $eavEntityType;
}
// return the array with the EAV entity types
return $eavEntityTypes;
} | php | {
"resource": ""
} |
q258410 | EavEntityTypeRepository.findOneByEntityTypeCode | test | public function findOneByEntityTypeCode($entityTypeCode)
{
// load and return the EAV attribute with the passed params
$this->eavEntityTypeByEntityTypeACodeStmt->execute(array(MemberNames::ENTITY_TYPE_CODE => $entityTypeCode));
return $this->eavEntityTypeByEntityTypeACodeStmt->fetch(\PDO::FETCH_ASSOC);
} | php | {
"resource": ""
} |
q258411 | ValueCsvSerializer.serialize | test | public function serialize(array $unserialized = null)
{
// do nothing, if the passed value is empty or NULL
if ($unserialized === null || $unserialized === '') {
return;
}
// load the global configuration
$configuration = $this->getConfiguration();
// initializet delimiter, enclosure and escape char
$delimiter = $this->getDelimiter() ? $this->getDelimiter() : $configuration->getDelimiter();
$enclosure = $configuration->getEnclosure();
$escape = $configuration->getEscape();
// create hte callback method to enclose/escape the values
$callback = function ($value) use ($enclosure, $escape) {
return $enclosure . str_replace($escape, $escape . $escape, $value) . $enclosure;
};
// implode and return the enclosed/escaped values
return implode($delimiter, array_map($callback, $unserialized));
} | php | {
"resource": ""
} |
q258412 | ValueCsvSerializer.unserialize | test | public function unserialize($serialized = null)
{
// do nothing, if the passed value is empty or NULL
if ($serialized === null || $serialized === '') {
return;
}
// load the global configuration
$configuration = $this->getConfiguration();
// initializet delimiter, enclosure and escape char
$delimiter = $this->getDelimiter() ? $this->getDelimiter() : $configuration->getDelimiter();
$enclosure = $configuration->getEnclosure();
$escape = $configuration->getEscape();
// parse and return the found data as array
return str_getcsv($serialized, $delimiter, $enclosure, $escape);
} | php | {
"resource": ""
} |
q258413 | MissingOptionValuesPlugin.getTargetDir | test | protected function getTargetDir()
{
// load the actual status
$status = $this->getRegistryProcessor()->getAttribute($this->getSerial());
// query whether or not the configured source directory is available
if (!is_dir($sourceDir = $status[RegistryKeys::SOURCE_DIRECTORY])) {
throw new \Exception(sprintf('Configured source directory %s is not available!', $sourceDir));
}
// return the source directory where we want to export to
return $sourceDir;
} | php | {
"resource": ""
} |
q258414 | ExportConfigFactory.createExportConfig | test | public function createExportConfig()
{
// initialize the lexer configuration
$config = new ExporterConfig();
// query whether or not a delimiter character has been configured
if ($delimiter = $this->configuration->getDelimiter()) {
$config->setDelimiter($delimiter);
}
// query whether or not a custom escape character has been configured
if ($escape = $this->configuration->getEscape()) {
$config->setEscape($escape);
}
// query whether or not a custom enclosure character has been configured
if ($enclosure = $this->configuration->getEnclosure()) {
$config->setEnclosure($enclosure);
}
// query whether or not a custom source charset has been configured
if ($fromCharset = $this->configuration->getFromCharset()) {
$config->setFromCharset($fromCharset);
}
// query whether or not a custom target charset has been configured
if ($toCharset = $this->configuration->getToCharset()) {
$config->setToCharset($toCharset);
}
// query whether or not a custom file mode has been configured
if ($fileMode = $this->configuration->getFileMode()) {
$config->setFileMode($fileMode);
}
// return the lexer configuration
return $config;
} | php | {
"resource": ""
} |
q258415 | AdditionalAttributeCsvSerializer.init | test | public function init(CsvConfigurationInterface $configuration)
{
// pass the configuration to the parent instance
parent::init($configuration);
// create the CSV value serializer instance
$this->setValueCsvSerializer($this->getValueCsvSerializerFactory()->createSerializer($configuration));
} | php | {
"resource": ""
} |
q258416 | AdditionalAttributeCsvSerializer.unserialize | test | public function unserialize($serialized = null)
{
// initialize the array for the unserialized additional attributes
$attributes = array();
// explode the additional attributes
if ($additionalAttributes = $this->explode($serialized)) {
// iterate over the attributes and append them to the row
foreach ($additionalAttributes as $additionalAttribute) {
// explode attribute code/option value from the attribute
list ($attributeCode, $optionValue) = explode('=', $additionalAttribute);
// extract the key/value pairs into an array
$attributes[$attributeCode] = $optionValue;
}
}
// return the array with the unserialized additional attributes
return $attributes;
} | php | {
"resource": ""
} |
q258417 | AdditionalAttributeCsvSerializer.serialize | test | public function serialize(array $unserialized = null)
{
// initialize the array
$attributes = array();
if (is_array($unserialized)) {
// serialize the key/value pairs into the array
foreach ($unserialized as $attributeCode => $attributeValue) {
$attributes[] = implode('=', array($attributeCode, $attributeValue));
}
}
// serialize the array itself
return $this->implode($attributes);
} | php | {
"resource": ""
} |
q258418 | AbstractBaseProcessor.getPreparedStatement | test | protected function getPreparedStatement($name = null)
{
// try to load the prepared statement, or use the default one
if (isset($this->preparedStatements[$name])) {
return $this->preparedStatements[$name];
}
// return the first (default) prepared statement
return reset($this->preparedStatements);
} | php | {
"resource": ""
} |
q258419 | AbstractBaseProcessor.init | test | public function init()
{
// load the statements
$statements = $this->getStatements();
foreach ($statements as $name => $statement) {
$this->addPreparedStatement($name, $this->getConnection()->prepare($statement));
}
} | php | {
"resource": ""
} |
q258420 | AdditionalAttributeObserver.parseAdditionaAttributes | test | protected function parseAdditionaAttributes($additionalAttributes)
{
// load the global configuration
$configuration = $this->getSubject()->getConfiguration()->getConfiguration();
// initializet delimiter, enclosure and escape char
$delimiter = $configuration->getDelimiter();
$enclosure = $configuration->getEnclosure();
$escape = $configuration->getEscape();
// parse and return the found data as array
return str_getcsv($additionalAttributes, $delimiter, $enclosure, $escape);
} | php | {
"resource": ""
} |
q258421 | CoreConfigDataUidGenerator.generate | test | public function generate(array $entity)
{
// load the data to generate the entity with
$path = $entity[MemberNames::PATH];
$scope = $entity[MemberNames::SCOPE];
$scopeId = $entity[MemberNames::SCOPE_ID];
// generate and return the entity
return sprintf('%s/%s/%s', $scope, $scopeId, $path);
} | php | {
"resource": ""
} |
q258422 | AbstractCachedRepository.resolveReference | test | protected function resolveReference($from)
{
// query whether or not a reference exists
if (isset($this->references[$from])) {
return $this->references[$from];
}
// return the passed reference
return $from;
} | php | {
"resource": ""
} |
q258423 | AbstractCachedRepository.toCache | test | public function toCache($cacheKey, $value, array $references = array())
{
// add the value to the cache
$this->cache[$cacheKey] = $value;
// also register the references if given
foreach ($references as $from => $to) {
$this->references[$from] = $to;
}
} | php | {
"resource": ""
} |
q258424 | AbstractCachedRepository.fromCache | test | public function fromCache($cacheKey)
{
// query whether or not a value for the cache key is available
if (isset($this->cache[$resolvedCacheKey = $this->resolveReference($cacheKey)])) {
return $this->cache[$resolvedCacheKey];
}
// throw an exception if not
throw new \Exception(sprintf('Can\'t find cached value for key "%s"', $cacheKey));
} | php | {
"resource": ""
} |
q258425 | AbstractCachedRepository.flushCache | test | public function flushCache($cacheKey = null)
{
// flush the complete cache, if NO cache key has been passed
if ($cacheKey === null) {
$this->references = $this->cache = array();
return;
}
// only flush the value with the passed cache key
if (isset($this->cache[$resolvedCacheKey = $this->resolveReference($cacheKey)])) {
unset($this->cache[$resolvedCacheKey]);
}
} | php | {
"resource": ""
} |
q258426 | EavAttributeSetRepository.load | test | public function load($id)
{
// execute the prepared statement and return the EAV attribute set with the passed ID
$this->eavAttributeSetStmt->execute(array($id));
return $this->eavAttributeSetStmt->fetch(\PDO::FETCH_ASSOC);
} | php | {
"resource": ""
} |
q258427 | EavAttributeSetRepository.findAllByEntityTypeId | test | public function findAllByEntityTypeId($entityTypeId)
{
// initialize the array for the attribute sets
$eavAttributeSets = array();
// load the attributes
$this->eavAttributeSetsByEntityTypeIdStmt->execute(array($entityTypeId));
// load the available EAV attribute sets
$availableEavAttributeSets = $this->eavAttributeSetsByEntityTypeIdStmt->fetchAll(\PDO::FETCH_ASSOC);
// prepare the array with the attribute set names as keys
foreach ($availableEavAttributeSets as $eavAttributeSet) {
$eavAttributeSets[$eavAttributeSet[MemberNames::ATTRIBUTE_SET_NAME]] = $eavAttributeSet;
}
// return the array with the attribute sets
return $eavAttributeSets;
} | php | {
"resource": ""
} |
q258428 | EavAttributeSetRepository.findOneByEntityTypeIdAndAttributeSetName | test | public function findOneByEntityTypeIdAndAttributeSetName($entityTypeId, $attributeSetName)
{
// initialize the params
$params = array(
MemberNames::ENTITY_TYPE_ID => $entityTypeId,
MemberNames::ATTRIBUTE_SET_NAME => $attributeSetName
);
// load and return the attribute set
$this->eavAttributeSetByEntityTypeIdAndAttributeSetNameStmt->execute($params);
return $this->eavAttributeSetByEntityTypeIdAndAttributeSetNameStmt->fetch(\PDO::FETCH_ASSOC);
} | php | {
"resource": ""
} |
q258429 | EavAttributeSetRepository.findOneByEntityTypeCodeAndAttributeSetName | test | public function findOneByEntityTypeCodeAndAttributeSetName($entityTypeCode, $attributeSetName)
{
// initialize the params
$params = array(
MemberNames::ENTITY_TYPE_CODE => $entityTypeCode,
MemberNames::ATTRIBUTE_SET_NAME => $attributeSetName
);
// load and return the attribute set
$this->eavAttributeSetByEntityTypeCodeAndAttributeSetNameStmt->execute($params);
return $this->eavAttributeSetByEntityTypeCodeAndAttributeSetNameStmt->fetch(\PDO::FETCH_ASSOC);
} | php | {
"resource": ""
} |
q258430 | CsvExportAdapterFactory.createExportAdapter | test | public function createExportAdapter(SubjectConfigurationInterface $subjectConfiguration)
{
// load the export adapter configuration
$exportAdapterConfiguration = $subjectConfiguration->getExportAdapter();
// load the serializer factory instance
$serializerFactory = $this->container->get($exportAdapterConfiguration->getSerializer()->getId());
// create the instance and pass the export adapter configuration instance
$exportAdapter = $this->container->get(DependencyInjectionKeys::IMPORT_ADAPTER_EXPORT_CSV);
$exportAdapter->init($exportAdapterConfiguration, $serializerFactory);
// return the initialized export adapter instance
return $exportAdapter;
} | php | {
"resource": ""
} |
q258431 | PDOConnectionWrapper.quote | test | public function quote($string, $parameterType = \PDO::PARAM_STR)
{
return $this->connection->quote($string, $parameterType);
} | php | {
"resource": ""
} |
q258432 | UrlRewriteRepository.findAllByEntityTypeAndEntityId | test | public function findAllByEntityTypeAndEntityId($entityType, $entityId)
{
// initialize the params
$params = array(
MemberNames::ENTITY_TYPE => $entityType,
MemberNames::ENTITY_ID => $entityId
);
// load and return the URL rewrites
$this->urlRewritesByEntityTypeAndEntityIdStmt->execute($params);
return $this->urlRewritesByEntityTypeAndEntityIdStmt->fetchAll(\PDO::FETCH_ASSOC);
} | php | {
"resource": ""
} |
q258433 | UrlRewriteRepository.findAllByEntityTypeAndEntityIdAndStoreId | test | public function findAllByEntityTypeAndEntityIdAndStoreId($entityType, $entityId, $storeId)
{
// initialize the params
$params = array(
MemberNames::ENTITY_TYPE => $entityType,
MemberNames::ENTITY_ID => $entityId,
MemberNames::STORE_ID => $storeId
);
// load and return the URL rewrites
$this->urlRewritesByEntityTypeAndEntityIdAndStoreIdStmt->execute($params);
return $this->urlRewritesByEntityTypeAndEntityIdAndStoreIdStmt->fetchAll(\PDO::FETCH_ASSOC);
} | php | {
"resource": ""
} |
q258434 | Interpreter.notify | test | private function notify(array $row)
{
// make the observers local
$observers = $this->observers;
// invoke the observers on the passed line
foreach ($observers as $observer) {
$this->delegate($observer, $row);
}
} | php | {
"resource": ""
} |
q258435 | Interpreter.checkRowConsistency | test | private function checkRowConsistency(array $row)
{
// query whether or not strict mode is enabled
if ($this->isNotStrict()) {
return;
}
// count the number of columns
$current = count($row);
// if the row consistency has not been set, set it
if ($this->rowConsistency === null) {
$this->rowConsistency = $current;
}
// check row consistency
if ($current !== $this->rowConsistency) {
throw new StrictViolationException(sprintf('Column size should be %u, but %u columns given', $this->rowConsistency, $current));
}
// set the new row consistency
$this->rowConsistency = $current;
} | php | {
"resource": ""
} |
q258436 | RowTrait.hasValue | test | public function hasValue($name)
{
// query whether or not the header is available
if ($this->hasHeader($name)) {
// load the key for the row
$headerValue = $this->getHeader($name);
// query whether the rows column has a vaild value
return (isset($this->row[$headerValue]) && $this->row[$headerValue] !== '');
}
// return FALSE if not
return false;
} | php | {
"resource": ""
} |
q258437 | SubjectFactory.createSubject | test | public function createSubject(SubjectConfigurationInterface $subjectConfiguration)
{
// load the subject instance from the DI container and set the subject configuration
$subjectInstance = $this->container->get($subjectConfiguration->getId());
$subjectInstance->setConfiguration($subjectConfiguration);
// load the import adapter instance from the DI container and set it on the subject instance
$importAdapter = $this->container->get($subjectConfiguration->getImportAdapter()->getId());
// query whether or not we've found a factory or the instance itself
if ($importAdapter instanceof ImportAdapterInterface) {
$subjectInstance->setImportAdapter($importAdapter);
// log a warning, that this is deprecated
$this->getSystemLogger()->warning(
sprintf(
'Direct injection of import adapter with DI ID "%s" is deprecated since version 3.0.0, please use factory instead',
$subjectConfiguration->getImportAdapter()->getId()
)
);
} elseif ($importAdapter instanceof ImportAdapterFactoryInterface) {
$subjectInstance->setImportAdapter($importAdapter->createImportAdapter($subjectConfiguration));
} else {
throw new \Exception(
sprintf(
'Expected either an instance of ImportAdapterInterface or ImportAdapterFactoryInterface for DI ID "%s"',
$subjectConfiguration->getImportAdapter()->getId()
)
);
}
// query whether or not we've a subject instance that implements the exportable subject interface
if ($subjectInstance instanceof ExportableSubjectInterface) {
// load the export adapter instance from the DI container and set it on the subject instance
$exportAdapter = $this->container->get($subjectConfiguration->getExportAdapter()->getId());
// query whether or not we've found a factory or the instance itself
if ($exportAdapter instanceof ExportAdapterInterface) {
// inject the export adapter into the subject
$subjectInstance->setExportAdapter($exportAdapter);
// log a warning, that this is deprecated
$this->getSystemLogger()->warning(
sprintf(
'Direct injection of export adapter with DI ID "%s" is deprecated since version 3.0.0, please use factory instead',
$subjectConfiguration->getExportAdapter()->getId()
)
);
} elseif ($exportAdapter instanceof ExportAdapterFactoryInterface) {
$subjectInstance->setExportAdapter($exportAdapter->createExportAdapter($subjectConfiguration));
} else {
throw new \Exception(
sprintf(
'Expected either an instance of ExportAdapterInterface or ExportAdapterFactoryInterface for DI ID "%s"',
$subjectConfiguration->getExportAdapter()->getId()
)
);
}
}
// load te number converter instance from the DI container and set it on the subject instance
if ($subjectInstance instanceof NumberConverterSubjectInterface) {
$subjectInstance->setNumberConverter($this->numberConverterFactory->createNumberConverter($subjectConfiguration));
}
// load te date converter instance from the DI container and set it on the subject instance
if ($subjectInstance instanceof DateConverterSubjectInterface) {
$subjectInstance->setDateConverter($this->dateConverterFactory->createDateConverter($subjectConfiguration));
}
// load the filesystem adapter instance from the DI container and set it on the subject instance
if ($subjectInstance instanceof FilesystemSubjectInterface) {
$filesystemAdapterFactory = $this->container->get($subjectConfiguration->getFilesystemAdapter()->getId());
$subjectInstance->setFilesystemAdapter($filesystemAdapterFactory->createFilesystemAdapter($subjectConfiguration));
}
// return the initialized subject instance
return $subjectInstance;
} | php | {
"resource": ""
} |
q258438 | AdditionalAttributeCsvSerializerFactory.createSerializer | test | public function createSerializer(CsvConfigurationInterface $configuration)
{
// load the serializer instance from the container and pass the configuration
/** @var \TechDivision\Import\Serializers\ConfigurationAwareSerializerInterface $serializer */
$serializer = $this->container->get(DependencyInjectionKeys::IMPORT_SERIALIZER_CSV_ADDITIONAL_ATTRIBUTE);
$serializer->init($configuration);
// return the serializer instance
return $serializer;
} | php | {
"resource": ""
} |
q258439 | EavAttributeRepository.findAllByEntityTypeIdAndAttributeSetName | test | public function findAllByEntityTypeIdAndAttributeSetName($entityTypeId, $attributeSetName)
{
// initialize the params
$params = array(
MemberNames::ENTITY_TYPE_ID => $entityTypeId,
MemberNames::ATTRIBUTE_SET_NAME => $attributeSetName
);
// initialize the array for the EAV attributes
$eavAttributes = array();
// execute the prepared statement and return the array with the EAV attributes
$this->eavAttributesByEntityTypeIdAndAttributeSetNameStmt->execute($params);
// load the available EAV attributes
$availableEavAttributes = $this->eavAttributesByEntityTypeIdAndAttributeSetNameStmt->fetchAll(\PDO::FETCH_ASSOC);
foreach ($availableEavAttributes as $eavAttribute) {
$eavAttributes[$eavAttribute[MemberNames::ATTRIBUTE_CODE]] = $eavAttribute;
}
// return the array with the EAV attributes
return $eavAttributes;
} | php | {
"resource": ""
} |
q258440 | EavAttributeRepository.findAllByOptionValueAndStoreId | test | public function findAllByOptionValueAndStoreId($optionValue, $storeId)
{
// initialize the params
$params = array(
MemberNames::VALUE => $optionValue,
MemberNames::STORE_ID => $storeId
);
// execute the prepared statement and return the array with the EAV attributes
$this->eavAttributesByOptionValueAndStoreIdStmt->execute($params);
return $this->eavAttributesByOptionValueAndStoreIdStmt->fetchAll(\PDO::FETCH_ASSOC);
} | php | {
"resource": ""
} |
q258441 | EavAttributeRepository.findAllByIsUserDefined | test | public function findAllByIsUserDefined($isUserDefined = 1)
{
// initialize the array for the EAV attributes
$eavAttributes = array();
// initialize the params
$params = array(MemberNames::ID_USER_DEFINED => $isUserDefined);
// execute the prepared statement and return the array with the EAV attributes
$this->eavAttributesByUserDefinedStmt->execute($params);
// load the available EAV attributes
$availableEavAttributes = $this->eavAttributesByUserDefinedStmt->fetchAll(\PDO::FETCH_ASSOC);
foreach ($availableEavAttributes as $eavAttribute) {
$eavAttributes[$eavAttribute[MemberNames::ATTRIBUTE_CODE]] = $eavAttribute;
}
// return the array with the EAV attributes
return $eavAttributes;
} | php | {
"resource": ""
} |
q258442 | EavAttributeRepository.findAllByEntityTypeIdAndIsUserDefined | test | public function findAllByEntityTypeIdAndIsUserDefined($entityTypeId, $isUserDefined = 1)
{
// initialize the array for the EAV attributes
$eavAttributes = array();
// initialize the params
$params = array(
MemberNames::ENTITY_TYPE_ID => $entityTypeId,
MemberNames::ID_USER_DEFINED => $isUserDefined
);
// execute the prepared statement and return the array with the EAV attributes
$this->eavAttributesByEntityTypeIdAndUserDefinedStmt->execute($params);
// load the available EAV attributes
$availableEavAttributes = $this->eavAttributesByEntityTypeIdAndUserDefinedStmt->fetchAll(\PDO::FETCH_ASSOC);
foreach ($availableEavAttributes as $eavAttribute) {
$eavAttributes[$eavAttribute[MemberNames::ATTRIBUTE_CODE]] = $eavAttribute;
}
// return the array with the EAV attributes
return $eavAttributes;
} | php | {
"resource": ""
} |
q258443 | EavAttributeRepository.findAllByEntityTypeId | test | public function findAllByEntityTypeId($entityTypeId)
{
// initialize the array for the EAV attributes
$eavAttributes = array();
// execute the prepared statement and return the array with the EAV attributes
$this->eavAttributesByEntityTypeIdAndUserDefinedStmt->execute(array(MemberNames::ENTITY_TYPE_ID => $entityTypeId));
// load the available EAV attributes
$availableEavAttributes = $this->eavAttributesByEntityTypeIdAndUserDefinedStmt->fetchAll(\PDO::FETCH_ASSOC);
foreach ($availableEavAttributes as $eavAttribute) {
$eavAttributes[$eavAttribute[MemberNames::ATTRIBUTE_CODE]] = $eavAttribute;
}
// return the array with the EAV attributes
return $eavAttributes;
} | php | {
"resource": ""
} |
q258444 | EavAttributeRepository.findOneByOptionValueAndStoreId | test | public function findOneByOptionValueAndStoreId($optionValue, $storeId)
{
// execute the prepared statement and return the array with the fail EAV attributes
if (sizeof($eavAttributes = $this->findAllByOptionValueAndStoreId($optionValue, $storeId)) > 0) {
return reset($eavAttributes);
}
} | php | {
"resource": ""
} |
q258445 | ObserverVisitor.prepareObservers | test | protected function prepareObservers(SubjectInterface $subject, array $observers, $type = null)
{
// iterate over the array with observers and prepare them
foreach ($observers as $key => $observer) {
// we have to initialize the type only on the first level
if ($type == null) {
$type = $key;
}
// query whether or not we've an subarry or not
if (is_array($observer)) {
$this->prepareObservers($subject, $observer, $type);
} else {
$subject->registerObserver($this->container->get($observer), $type);
}
}
} | php | {
"resource": ""
} |
q258446 | FilesystemTrait.resolvePath | test | public function resolvePath($path)
{
// if we've an absolute path, return it immediately
if ($this->getFilesystemAdapter()->isDir($path)) {
return $path;
}
// temporarily save the path
$originalPath = $path;
// try to prepend the actual working directory, assuming we've a relative path
if ($this->getFilesystemAdapter()->isDir($path = getcwd() . DIRECTORY_SEPARATOR . ltrim($path, '/'))) {
return $path;
}
// throw an exception if the passed directory doesn't exists
throw new \InvalidArgumentException(
sprintf('Directory %s doesn\'t exist', $originalPath)
);
} | php | {
"resource": ""
} |
q258447 | FilesystemTrait.mkdir | test | public function mkdir($pathname, $mode = 0700, $recursive = false)
{
return $this->getFilesystemAdapter()->mkdir($pathname, $mode, $recursive);
} | php | {
"resource": ""
} |
q258448 | RegistryProcessor.setAttribute | test | public function setAttribute($key, $value)
{
// query whether or not the key has already been used
if (isset($this->attributes[$key])) {
throw new \Exception(sprintf('Try to override data with key %s', $key));
}
// set the attribute in the registry
$this->attributes[$key] = $value;
} | php | {
"resource": ""
} |
q258449 | RegistryProcessor.raiseCounter | test | public function raiseCounter($key, $counterName)
{
// raise/initialize the value
if (isset($this->attributes[$key][$counterName])) {
$this->attributes[$key][$counterName]++;
} else {
$this->attributes[$key][$counterName] = 1;
}
// return the new value
return $this->attributes[$key][$counterName];
} | php | {
"resource": ""
} |
q258450 | RegistryProcessor.mergeAttributesRecursive | test | public function mergeAttributesRecursive($key, array $attributes)
{
// if the key not exists, simply add the new attributes
if (!isset($this->attributes[$key])) {
$this->attributes[$key] = $attributes;
return;
}
// if the key exists and the value is an array, merge it with the passed array
if (isset($this->attributes[$key]) && is_array($this->attributes[$key])) {
$this->attributes[$key] = array_replace_recursive($this->attributes[$key], $attributes);
return;
}
// throw an exception if the key exists, but the found value is not of type array
throw new \Exception(sprintf('Can\'t merge attributes, because value for key %s already exists, but is not of type array', $key));
} | php | {
"resource": ""
} |
q258451 | LeagueFilesystemAdapterFactory.createFilesystemAdapter | test | public function createFilesystemAdapter(SubjectConfigurationInterface $subjectConfiguration)
{
// the filesystem adapter configuration
$filesystemAdapterConfiguration = $subjectConfiguration->getFilesystemAdapter();
// load the filesystem adapter's adapter configuration (FS specific)
$adapterConfiguration = $filesystemAdapterConfiguration->getAdapter();
// load the adapter parameters
$adapterParams = $adapterConfiguration->getParams();
// initialize the root directory, if not specified in the adapter parameters
if (!isset($adapterParams[ConfigurationKeys::ROOT])) {
$adapterParams[ConfigurationKeys::ROOT] = getcwd();
}
// load the adapter to use
$reflectionClass = new \ReflectionClass($adapterConfiguration->getType());
$adapter = $reflectionClass->newInstanceArgs(ConfigurationUtil::prepareConstructorArgs($reflectionClass, $adapterParams));
// create a new filesystem instance
return new LeagueFilesystemAdapter(new Filesystem($adapter));
} | php | {
"resource": ""
} |
q258452 | CategoryRepository.findAllByStoreView | test | public function findAllByStoreView($storeViewId)
{
// try to load the categories and return them
$this->categoriesByStoreViewStmt->execute(array(MemberNames::STORE_ID => $storeViewId));
return $this->categoriesByStoreViewStmt->fetchAll(\PDO::FETCH_ASSOC);
} | php | {
"resource": ""
} |
q258453 | CategoryRepository.findAllRootCategories | test | public function findAllRootCategories()
{
// try to load the categories
$this->rootCategoriesStmt->execute();
// initialize the array with the store code as key
$rootCategories = array();
// load the available root categories
$availableRootCategories = $this->rootCategoriesStmt->fetchAll(\PDO::FETCH_ASSOC);
// prepare the array with the root categories
foreach ($availableRootCategories as $category) {
$rootCategories[$category[MemberNames::CODE]] = $category;
}
// append the root categories to the cache
return $rootCategories;
} | php | {
"resource": ""
} |
q258454 | EmitterFactory.createEmitter | test | public function createEmitter()
{
// initialize the event emitter
$emitter = new Emitter();
// load the listener configuration from the configuration
$availableListeners = $this->configuration->getListeners();
// load, initialize and add the configured listeners to the emitter
foreach ($availableListeners as $listeners) {
$this->prepareListeners($emitter, $listeners);
}
// load the available operations from the configuration
$availableOperations = $this->configuration->getOperations();
// load, initialize and add the configured listeners for the actual operation
/** @var \TechDivision\Import\Configuration\OperationConfigurationInterface $operation */
foreach ($availableOperations as $operation) {
if ($operation->equals($this->configuration->getOperation())) {
// load the operation's listeners
$operationListeners = $operation->getListeners();
// prepare the operation's listeners
foreach ($operationListeners as $listeners) {
$this->prepareListeners($emitter, $listeners);
}
}
}
// return the initialized emitter instance
return $emitter;
} | php | {
"resource": ""
} |
q258455 | EmitterFactory.prepareListeners | test | protected function prepareListeners(EmitterInterface $emitter, array $listeners, $eventName = null)
{
// iterate over the array with listeners and prepare them
foreach ($listeners as $key => $listener) {
// we have to initialize the event name only on the first level
if ($eventName == null) {
$eventName = $key;
}
// query whether or not we've an subarray or not
if (is_array($listener)) {
$this->prepareListeners($emitter, $listener, $eventName);
} else {
$emitter->addListener($eventName, $this->container->get($listener));
}
}
} | php | {
"resource": ""
} |
q258456 | AbstractPlugin.removeDir | test | protected function removeDir($src)
{
// open the directory
$dir = opendir($src);
// remove files/folders recursively
while (false !== ($file = readdir($dir))) {
if (($file != '.') && ($file != '..')) {
$full = $src . '/' . $file;
if (is_dir($full)) {
$this->removeDir($full);
} else {
if (!unlink($full)) {
throw new \Exception(sprintf('Can\'t remove file %s', $full));
}
}
}
}
// close handle and remove directory itself
closedir($dir);
if (!rmdir($src)) {
throw new \Exception(sprintf('Can\'t remove directory %s', $src));
}
} | php | {
"resource": ""
} |
q258457 | AbstractPlugin.getSwiftMailer | test | protected function getSwiftMailer()
{
// the swift mailer configuration
if ($swiftMailerConfiguration = $this->getPluginConfiguration()->getSwiftMailer()) {
// load the factory that creates the swift mailer instance
$factory = $swiftMailerConfiguration->getFactory();
// create the swift mailer instance
return $factory::factory($swiftMailerConfiguration);
}
} | php | {
"resource": ""
} |
q258458 | AbstractFileResolver.initialize | test | protected function initialize($serial)
{
// load the actual status
$status = $this->getRegistryProcessor()->getAttribute($serial);
// query whether or not the configured source directory is available
if (!is_dir($sourceDir = $status[RegistryKeys::SOURCE_DIRECTORY])) {
throw new \Exception(sprintf('Configured source directory "%s" is not available!', $sourceDir));
}
// set the source directory
$this->setSourceDir($sourceDir);
} | php | {
"resource": ""
} |
q258459 | AbstractFileResolver.loadFiles | test | public function loadFiles($serial)
{
// clear the filecache
clearstatcache();
// initialize the resolver
$this->initialize($serial);
// initialize the array with the files matching the suffix found in the source directory
$files = glob(sprintf('%s/*.%s', $this->getSourceDir(), $this->getSuffix()));
// sort the files for the apropriate order
usort($files, function ($a, $b) {
return strcmp($a, $b);
});
// return the sorted files
return $files;
} | php | {
"resource": ""
} |
q258460 | UrlRewriteDeleteProcessor.getStatements | test | protected function getStatements()
{
return array(
SqlStatementKeys::DELETE_URL_REWRITE => $this->loadStatement(SqlStatementKeys::DELETE_URL_REWRITE),
SqlStatementKeys::DELETE_URL_REWRITE_BY_SKU => $this->loadStatement(SqlStatementKeys::DELETE_URL_REWRITE_BY_SKU),
SqlStatementKeys::DELETE_URL_REWRITE_BY_PATH => $this->loadStatement(SqlStatementKeys::DELETE_URL_REWRITE_BY_PATH),
SqlStatementKeys::DELETE_URL_REWRITE_BY_CATEGORY_ID => $this->loadStatement(SqlStatementKeys::DELETE_URL_REWRITE_BY_CATEGORY_ID)
);
} | php | {
"resource": ""
} |
q258461 | CsvImportAdapterFactory.createImportAdapter | test | public function createImportAdapter(SubjectConfigurationInterface $subjectConfiguration)
{
// load the import adapter configuration
$importAdapterConfiguration = $subjectConfiguration->getImportAdapter();
// load the serializer factory instance
$serializerFactory = $this->container->get($importAdapterConfiguration->getSerializer()->getId());
// create the instance and pass the import adapter configuration instance
$importAdapter = $this->container->get(DependencyInjectionKeys::IMPORT_ADAPTER_IMPORT_CSV);
$importAdapter->init($importAdapterConfiguration, $serializerFactory);
// return the initialized import adapter instance
return $importAdapter;
} | php | {
"resource": ""
} |
q258462 | CallbackVisitor.prepareCallbacks | test | protected function prepareCallbacks(SubjectInterface $subject, array $callbacks, $type = null)
{
// iterate over the array with callbacks and prepare them
foreach ($callbacks as $key => $callback) {
// we have to initialize the type only on the first level
if ($type == null) {
$type = $key;
}
// query whether or not we've an subarry or not
if (is_array($callback)) {
$this->prepareCallbacks($subject, $callback, $type);
} else {
$subject->registerCallback($this->container->get($callback), $type);
}
}
} | php | {
"resource": ""
} |
q258463 | ImportProcessor.getGlobalData | test | public function getGlobalData()
{
// initialize the array for the global data
$globalData = array();
// initialize the global data
$globalData[RegistryKeys::STORES] = $this->getStores();
$globalData[RegistryKeys::LINK_TYPES] = $this->getLinkTypes();
$globalData[RegistryKeys::TAX_CLASSES] = $this->getTaxClasses();
$globalData[RegistryKeys::IMAGE_TYPES] = $this->getImageTypes();
$globalData[RegistryKeys::DEFAULT_STORE] = $this->getDefaultStore();
$globalData[RegistryKeys::STORE_WEBSITES] = $this->getStoreWebsites();
$globalData[RegistryKeys::LINK_ATTRIBUTES] = $this->getLinkAttributes();
$globalData[RegistryKeys::ROOT_CATEGORIES] = $this->getRootCategories();
$globalData[RegistryKeys::CUSTOMER_GROUPS] = $this->getCustomerGroups();
$globalData[RegistryKeys::CORE_CONFIG_DATA] = $this->getCoreConfigData();
$globalData[RegistryKeys::ENTITY_TYPES] = $eavEntityTypes = $this->getEavEntityTypes();
// prepare the attribute sets
$eavAttributes = array();
$eavAttributeSets = array();
$eavAttributeGroups = array();
foreach ($eavEntityTypes as $eavEntityTypeCode => $eavEntityType) {
// load the attribute sets for the entity type
$attributeSets = $this->getEavAttributeSetsByEntityTypeId($entityTypeId = $eavEntityType[MemberNames::ENTITY_TYPE_ID]);
// append the attribute sets to the array
$eavAttributeSets[$eavEntityTypeCode] = $attributeSets;
// iterate over the attribute sets and initialize the attributes
foreach ($attributeSets as $attributeSet) {
// load the attribute set name
$eavAttributeSetName = $attributeSet[MemberNames::ATTRIBUTE_SET_NAME];
// load the attributes for the attribute set
$eavAttributes[$eavEntityTypeCode][$eavAttributeSetName] = $this->getEavAttributesByEntityTypeIdAndAttributeSetName(
$entityTypeId,
$eavAttributeSetName
);
// load the attribute group for the attribute set
$eavAttributeGroups[$eavEntityTypeCode][$eavAttributeSetName] = $this->getEavAttributeGroupsByAttributeSetId(
$attributeSet[MemberNames::ATTRIBUTE_SET_ID]
);
}
}
// prepare the user defined attributes
$eavUserDefinedAttributes = array();
foreach ($eavEntityTypes as $eavEntityTypeCode => $eavEntityType) {
// load the user defined attributes for the entity type
$eavUserDefinedAttributes[$eavEntityTypeCode] = $this->getEavAttributesByEntityTypeIdAndIsUserDefined(
$eavEntityType[MemberNames::ENTITY_TYPE_ID]
);
}
// initialize the arrays with the EAV attributes, EAV user defined attributes and attribute sets/groups
$globalData[RegistryKeys::EAV_ATTRIBUTES] = $eavAttributes;
$globalData[RegistryKeys::ATTRIBUTE_SETS] = $eavAttributeSets;
$globalData[RegistryKeys::ATTRIBUTE_GROUPS] = $eavAttributeGroups;
$globalData[RegistryKeys::EAV_USER_DEFINED_ATTRIBUTES] = $eavUserDefinedAttributes;
// initialize categories per store view
$globalData[RegistryKeys::CATEGORIES] = array();
foreach ($globalData[RegistryKeys::STORES] as $storeView) {
$storeViewCode = $storeView[MemberNames::CODE];
$storeViewId = $storeView[MemberNames::STORE_ID];
$globalData[RegistryKeys::CATEGORIES][$storeViewCode] = $this->categoryAssembler->getCategoriesWithResolvedPathByStoreView($storeViewId);
}
// return the array
return $globalData;
} | php | {
"resource": ""
} |
q258464 | AbstractSqlStatementRepository.load | test | public function load($id)
{
// try to find the SQL statement with the passed key
if (isset($this->preparedStatements[$id])) {
return $this->preparedStatements[$id];
}
// throw an exception if NOT available
throw new \Exception(sprintf('Can\'t find SQL statement with ID %s', $id));
} | php | {
"resource": ""
} |
q258465 | DateConverterFactory.createDateConverter | test | public function createDateConverter(SubjectConfigurationInterface $subject)
{
// create a new date converter instance for the subject with the passed configuration
$dateConverter = $this->container->get($subject->getDateConverter()->getId());
$dateConverter->setSubjectConfiguration($subject);
// return the date converter instance
return $dateConverter;
} | php | {
"resource": ""
} |
q258466 | ExportableTrait.overrideArtefacts | test | protected function overrideArtefacts($type, array $artefacts)
{
foreach ($artefacts as $key => $artefact) {
$this->artefacs[$type][$this->getLastEntityId()][$key] = $artefact;
}
} | php | {
"resource": ""
} |
q258467 | ExportableTrait.appendArtefacts | test | protected function appendArtefacts($type, array $artefacts)
{
foreach ($artefacts as $artefact) {
$this->artefacs[$type][$this->getLastEntityId()][] = $artefact;
}
} | php | {
"resource": ""
} |
q258468 | ExportableTrait.getArtefactsByTypeAndEntityId | test | public function getArtefactsByTypeAndEntityId($type, $entityId)
{
// query whether or not, artefacts for the passed params are available
if (isset($this->artefacs[$type][$entityId])) {
// load the artefacts
$artefacts = $this->artefacs[$type][$entityId];
// unserialize the original data
array_walk($artefacts, function (&$artefact) {
if (isset($artefact[ColumnKeys::ORIGINAL_DATA])) {
$artefact[ColumnKeys::ORIGINAL_DATA] = unserialize($artefact[ColumnKeys::ORIGINAL_DATA]);
}
});
// return the artefacts
return $artefacts;
}
// throw an exception if not
throw new \Exception(
sprintf(
'Cant\'t load artefacts for type %s and entity ID %d',
$type,
$entityId
)
);
} | php | {
"resource": ""
} |
q258469 | ExportableTrait.newArtefact | test | public function newArtefact(array $columns, array $originalColumnNames = array())
{
// initialize the original data and the artefact
$artefact = array();
$originalData = array();
// query whether or not, we've original columns
if (sizeof($originalColumnNames) > 0) {
// prepare the original column data
$originalData[ColumnKeys::ORIGINAL_FILENAME] = $this->getFilename();
$originalData[ColumnKeys::ORIGINAL_LINE_NUMBER] = $this->getLineNumber();
$originalData[ColumnKeys::ORIGINAL_COLUMN_NAMES] = $originalColumnNames;
// add the original column data to the new artefact
$artefact = array(ColumnKeys::ORIGINAL_DATA => $originalData);
}
// merge the columns into the artefact entity and return it
return array_merge($artefact, $columns);
} | php | {
"resource": ""
} |
q258470 | ExportableTrait.export | test | public function export($timestamp, $counter)
{
$this->getExportAdapter()->export($this->getArtefacts(), $this->getTargetDir(), $timestamp, $counter);
} | php | {
"resource": ""
} |
q258471 | LinkTypeRepository.findAll | test | public function findAll()
{
// query whether or not we've already loaded the value
if (!isset($this->cache[__METHOD__])) {
// try to load the link types
$this->linkTypeStmt->execute();
// initialize the array for the link types
$linkTypes = array();
// load the available link types
$availableLinkTypes = $this->linkTypeStmt->fetchAll(\PDO::FETCH_ASSOC);
// prepare the link types => we need the code as key
foreach ($availableLinkTypes as $linkType) {
$linkTypes[$linkType[MemberNames::CODE]] = $linkType;
}
// append the link types to the cache
$this->cache[__METHOD__] = $linkTypes;
}
// return the link types from the cache
return $this->cache[__METHOD__];
} | php | {
"resource": ""
} |
q258472 | ImageTypeRepository.findAll | test | public function findAll()
{
// initialize the result array
$result = array();
// load and the image types from the EAV attribute table
$this->imageTypesByEntityTypeCodeAndFrontendInputStmt->execute();
// fetch the image types with the passed parameters
if ($imageTypes = $this->imageTypesByEntityTypeCodeAndFrontendInputStmt->fetchAll(\PDO::FETCH_ASSOC)) {
// iterate over the image types found
foreach ($imageTypes as $imageType) {
$attributeCode = $imageType[MemberNames::ATTRIBUTE_CODE];
// map the default image types
if (isset($this->defaultMappings[$attributeCode])) {
$attributeCode = $this->defaultMappings[$attributeCode];
}
// add the (mapped) image type
$result[$attributeCode] = sprintf('%s_label', $attributeCode);
}
}
// return the result
return $result;
} | php | {
"resource": ""
} |
q258473 | SimpleDateConverter.convert | test | public function convert($date)
{
// create a DateTime instance from the passed value
if ($dateTime = \DateTime::createFromFormat($this->getDateConverterConfiguration()->getSourceDateFormat(), $date)) {
return $dateTime->format('Y-m-d H:i:s');
}
// return NULL, if the passed value is NOT a valid date
return null;
} | php | {
"resource": ""
} |
q258474 | SimpleNumberConverter.convert | test | public function convert($number)
{
// initialize the formatter instance with the source locale
$formatter = \NumberFormatter::create($this->getNumberConverterConfiguration()->getLocale(), \NumberFormatter::DECIMAL);
// parse, format and return the value
return $this->getFormatter()->format($formatter->parse($number));
} | php | {
"resource": ""
} |
q258475 | SubjectExecutor.execute | test | public function execute(SubjectConfigurationInterface $subject, array $matches, $serial, $pathname)
{
// initialize the subject and import the bunch
$subjectInstance = $this->subjectFactory->createSubject($subject);
try {
// setup the subject instance
$subjectInstance->setUp($serial);
// initialize the callbacks/observers
$this->callbackVisitor->visit($subjectInstance);
$this->observerVisitor->visit($subjectInstance);
// finally import the CSV file
$subjectInstance->import($serial, $pathname);
// query whether or not, we've to export artefacts
if ($subjectInstance instanceof ExportableSubjectInterface) {
$subjectInstance->export(
$matches[BunchKeys::FILENAME],
$matches[BunchKeys::COUNTER]
);
}
// tear down the subject instance
$subjectInstance->tearDown($serial);
} catch (\Exception $e) {
// query whether or not, we've to export artefacts
if ($subjectInstance instanceof ExportableSubjectInterface) {
// tear down the subject instance
$subjectInstance->tearDown($serial);
}
// re-throw the exception
throw $e;
}
} | php | {
"resource": ""
} |
q258476 | SimpleFileResolver.getPatternKeys | test | protected function getPatternKeys()
{
// load the pattern keys from the configuration
$patternKeys = $this->getPatternElements();
// make sure that they are all lowercase
array_walk($patternKeys, function (&$value) {
$value = strtolower($value);
});
// return the pattern keys
return $patternKeys;
} | php | {
"resource": ""
} |
q258477 | SimpleFileResolver.resolvePatternValues | test | protected function resolvePatternValues()
{
// initialize the array
$elements = array();
// load the pattern keys
$patternKeys = $this->getPatternKeys();
// prepare the pattern values
foreach ($patternKeys as $element) {
$elements[] = sprintf('(?<%s>%s)', $element, $this->resolvePatternValue($element));
}
// return the pattern values
return $elements;
} | php | {
"resource": ""
} |
q258478 | SimpleFileResolver.resolvePatternValue | test | protected function resolvePatternValue($element)
{
// query whether or not matches has been found OR the counter element has been passed
if ($this->countMatches() === 0 || BunchKeys::COUNTER === $element) {
// prepare the method name for the callback to load the pattern value with
$methodName = sprintf('get%s', ucfirst($element));
// load the pattern value
if (in_array($methodName, get_class_methods($this->getFileResolverConfiguration()))) {
return call_user_func(array($this->getFileResolverConfiguration(), $methodName));
}
// stop processing
return;
}
// try to load the pattern value from the matches
return $this->getMatch($element);
} | php | {
"resource": ""
} |
q258479 | SimpleFileResolver.preparePattern | test | protected function preparePattern()
{
return sprintf($this->getRegex(), implode($this->getElementSeparator(), $this->resolvePatternValues()), $this->getSuffix());
} | php | {
"resource": ""
} |
q258480 | SimpleFileResolver.prepareOkFilename | test | protected function prepareOkFilename(array $parts)
{
return sprintf('%s/%s.%s', $this->getSourceDir(), implode($this->getElementSeparator(), $parts), $this->getOkFileSuffix());
} | php | {
"resource": ""
} |
q258481 | SimpleFileResolver.isEqualFilename | test | protected function isEqualFilename($filename1, $filename2)
{
return $this->stripSuffix($filename1, $this->getSuffix()) === $this->stripSuffix($filename2, $this->getOkFileSuffix());
} | php | {
"resource": ""
} |
q258482 | SimpleFileResolver.getOkFilenames | test | protected function getOkFilenames()
{
// initialize the array for the available okFilenames
$okFilenames = array();
// prepare the OK filenames based on the found CSV file information
for ($i = 1; $i <= sizeof($patternKeys = $this->getPatternKeys()); $i++) {
// intialize the array for the parts of the names (prefix, filename + counter)
$parts = array();
// load the parts from the matches
for ($z = 0; $z < $i; $z++) {
// append the part
$parts[] = $this->getMatch($patternKeys[$z]);
}
// query whether or not, the OK file exists, if yes append it
if (file_exists($okFilename = $this->prepareOkFilename($parts))) {
$okFilenames[] = $okFilename;
}
}
// prepare and return the pattern for the OK file
return $okFilenames;
} | php | {
"resource": ""
} |
q258483 | SimpleFileResolver.shouldBeHandled | test | public function shouldBeHandled($filename)
{
// initialize the array with the matches
$matches = array();
// update the matches, if the pattern matches
if ($result = preg_match($this->preparePattern(), $filename, $matches)) {
foreach ($matches as $name => $match) {
$this->addMatch($name, $match);
}
}
// stop processing, if the filename doesn't match
return (boolean) $result;
} | php | {
"resource": ""
} |
q258484 | SimpleFileResolver.cleanUpOkFile | test | public function cleanUpOkFile($filename)
{
// query whether or not the subject needs an OK file, if yes remove the filename from the file
if ($this->getSubjectConfiguration()->isOkFileNeeded() === false) {
return;
}
try {
// try to load the expected OK filenames
if (sizeof($okFilenames = $this->getOkFilenames()) === 0) {
throw new MissingOkFileException(sprintf('Can\'t find a OK filename for file %s', $filename));
}
// iterate over the found OK filenames (should usually be only one, but could be more)
foreach ($okFilenames as $okFilename) {
// if the OK filename matches the CSV filename AND the OK file is empty
if ($this->isEqualFilename($filename, $okFilename) && filesize($okFilename) === 0) {
unlink($okFilename);
return;
}
// else, remove the CSV filename from the OK file
$this->removeLineFromFile(basename($filename), $fh = fopen($okFilename, 'r+'));
fclose($fh);
// if the OK file is empty, delete the file
if (filesize($okFilename) === 0) {
unlink($okFilename);
}
// return immediately
return;
}
// throw an exception if either no OK file has been found,
// or the CSV file is not in one of the OK files
throw new \Exception(
sprintf(
'Can\'t found filename %s in one of the expected OK files: %s',
$filename,
implode(', ', $okFilenames)
)
);
} catch (LineNotFoundException $lne) {
// wrap and re-throw the exception
throw new \Exception(
sprintf(
'Can\'t remove filename %s from OK file: %s',
$filename,
$okFilename
),
null,
$lne
);
}
} | php | {
"resource": ""
} |
q258485 | TaxClassRepository.findAll | test | public function findAll()
{
// initialize the array with the available tax classes
$taxClasses = array();
// execute the prepared statement
$this->taxClassesStmt->execute();
// load the available tax classes
$availableTaxClasses = $this->taxClassesStmt->fetchAll();
// fetch the tax classes and assemble them as array with the class name as key
foreach ($availableTaxClasses as $taxClass) {
$taxClasses[$taxClass[MemberNames::CLASS_NAME]] = $taxClass;
}
// return the array with the tax classes
return $taxClasses;
} | php | {
"resource": ""
} |
q258486 | EavAttributeOptionValueCacheWarmer.warm | test | public function warm()
{
// load the available EAV attribute option values
$eavAttributeOptionValues = $this->repository->findAll();
// prepare the caches for the statements
foreach ($eavAttributeOptionValues as $eavAttributeOptionValue) {
// prepare the cache key and add the option value to the cache
$cacheKey1 = $this->repository->cacheKey(
SqlStatementKeys::EAV_ATTRIBUTE_OPTION_VALUE_BY_OPTION_ID_AND_STORE_ID,
array(
MemberNames::STORE_ID => $eavAttributeOptionValue[MemberNames::STORE_ID],
MemberNames::OPTION_ID => $eavAttributeOptionValue[MemberNames::OPTION_ID]
)
);
// prepare the cache key and add the option value to the cache
$cacheKey2 = $this->repository->cacheKey(
SqlStatementKeys::EAV_ATTRIBUTE_OPTION_VALUE_BY_ATTRIBUTE_CODE_AND_STORE_ID_AND_VALUE,
array(
MemberNames::ATTRIBUTE_CODE => $eavAttributeOptionValue[MemberNames::ATTRIBUTE_CODE],
MemberNames::STORE_ID => $eavAttributeOptionValue[MemberNames::STORE_ID],
MemberNames::VALUE => $eavAttributeOptionValue[MemberNames::VALUE]
)
);
// add the EAV attribute option value to the cache
$this->repository->toCache(
$eavAttributeOptionValue[MemberNames::VALUE_ID],
$eavAttributeOptionValue,
array(
$cacheKey1 => $eavAttributeOptionValue[MemberNames::VALUE_ID],
$cacheKey2 => $eavAttributeOptionValue[MemberNames::VALUE_ID]
)
);
}
} | php | {
"resource": ""
} |
q258487 | StoreWebsiteRepository.findAll | test | public function findAll()
{
// initialize the array with the available store websites
$storeWebsites = array();
// execute the prepared statement
$this->storeWebsitesStmt->execute();
// load the available store websites
$availableStoreWebsites = $this->storeWebsitesStmt->fetchAll();
// fetch the store websites and assemble them as array with the codes as key
foreach ($availableStoreWebsites as $storeWebsite) {
$storeWebsites[$storeWebsite[MemberNames::CODE]] = $storeWebsite;
}
// return the array with the store websites
return $storeWebsites;
} | php | {
"resource": ""
} |
q258488 | StoreRepository.findAll | test | public function findAll()
{
// initialize the array with the available stores
$stores = array();
// execute the prepared statement
$this->storesStmt->execute();
// load the available stores
$availableStores = $this->storesStmt->fetchAll();
// fetch the stores and assemble them as array with the store code as key
foreach ($availableStores as $store) {
$stores[$store[MemberNames::CODE]] = $store;
}
// return the array with the stores
return $stores;
} | php | {
"resource": ""
} |
q258489 | CategoryVarcharRepository.findAllByEntityIds | test | public function findAllByEntityIds(array $entityIds)
{
// prepare the cache key
$vals = implode(',', $entityIds);
$sql = str_replace('?', $vals, $this->loadStatement(SqlStatementKeys::CATEGORY_VARCHARS_BY_ENTITY_IDS));
// load the categories with the passed values and return them
if ($stmt = $this->getConnection()->query($sql)) {
return $stmt->fetchAll();
}
} | php | {
"resource": ""
} |
q258490 | CategoryVarcharRepository.findByEntityId | test | public function findByEntityId($entityId)
{
// prepare the cache key
$sql = str_replace('?', $entityId, $this->loadStatement(SqlStatementKeys::CATEGORY_VARCHARS_BY_ENTITY_IDS));
// load the categories with the passed values and return them
if ($stmt = $this->getConnection()->query($sql)) {
return $stmt->fetch();
}
} | php | {
"resource": ""
} |
q258491 | CustomerGroupRepository.findAll | test | public function findAll()
{
// initialize the array for the customer groups
$customerGroups = [];
// execute the prepared statement
$this->customerGroupsStmt->execute();
// load the available customer groups
$availableCustomerGroups = $this->customerGroupsStmt->fetchAll();
// fetch the customer groups and assemble them as array with the codes as key
foreach ($availableCustomerGroups as $customerGroup) {
$customerGroups[$customerGroup[MemberNames::CUSTOMER_GROUP_CODE]] = $customerGroup;
}
// return the customer groups
return $customerGroups;
} | php | {
"resource": ""
} |
q258492 | PrimaryKeyUtil.getPrimaryKeyMemberName | test | public function getPrimaryKeyMemberName()
{
// make sure the edition name is in upper cases
$editionName = strtoupper($this->configuration->getMagentoEdition());
// return the primary key member name for the actual edition
if (isset($this->editionPrimaryKeyMemberNameMappings[$editionName])) {
return $this->editionPrimaryKeyMemberNameMappings[$editionName];
}
// throw an exception if the edition is NOT supported/available
throw new \Exception(sprintf('Found not supported/available Magento edition name "%s"', $editionName));
} | php | {
"resource": ""
} |
q258493 | AttributeObserverTrait.clearRow | test | protected function clearRow()
{
// query whether or not the column keys has been initialized
if ($this->cleanUpEmptyColumnKeys === null) {
// initialize the array with the column keys that has to be cleaned-up
$this->cleanUpEmptyColumnKeys = array();
// query whether or not column names that has to be cleaned up have been configured
if ($this->getSubject()->getConfiguration()->hasParam(ConfigurationKeys::CLEAN_UP_EMPTY_COLUMNS)) {
// if yes, load the column names
$cleanUpEmptyColumns = $this->getSubject()->getCleanUpColumns();
// translate the column names into column keys
foreach ($cleanUpEmptyColumns as $cleanUpEmptyColumn) {
if ($this->hasHeader($cleanUpEmptyColumn)) {
$this->cleanUpEmptyColumnKeys[] = $this->getHeader($cleanUpEmptyColumn);
}
}
}
}
// remove all the empty values from the row, expected the columns has to be cleaned-up
return array_filter(
$this->row,
function ($value, $key) {
return ($value !== null && $value !== '') || in_array($key, $this->cleanUpEmptyColumnKeys);
},
ARRAY_FILTER_USE_BOTH
);
} | php | {
"resource": ""
} |
q258494 | RenderBlade.blade | test | public static function blade($view, $data = array(), $viewPath = EVENTMANAGERINTEGRATION_VIEW_PATH)
{
if (!file_exists(EVENTMANAGERINTEGRATION_CACHE_DIR)) {
mkdir(EVENTMANAGERINTEGRATION_CACHE_DIR, 0777, true);
}
$blade = new Blade($viewPath, EVENTMANAGERINTEGRATION_CACHE_DIR);
return $blade->view()->make($view, $data)->render();
} | php | {
"resource": ""
} |
q258495 | Events.registerRestRoutes | test | public function registerRestRoutes()
{
register_rest_route(
'wp/v2',
'/'.$this->postType.'/'.'module',
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'getEvents'),
'args' => $this->getCollectionParams(),
'permission_callback' => array($this, 'validateNonce'),
)
);
} | php | {
"resource": ""
} |
q258496 | Events.getCollectionParams | test | public function getCollectionParams()
{
return array(
'page' => array(
'description' => 'Current page of the collection.',
'type' => 'integer',
'default' => 1,
'sanitize_callback' => 'absint',
),
'per_page' => array(
'description' => 'Maximum number of items to be returned in result collection.',
'type' => 'integer',
'default' => 10,
'sanitize_callback' => array($this, 'sanitizePerPage'),
),
'start_date' => array(
'description' => 'Get events from this date',
'type' => 'string',
'default' => date('Y-m-d H:i:s', strtotime("today midnight")),
'sanitize_callback' => array($this, 'sanitizeDate'),
),
'end_date' => array(
'description' => 'Get events to this date',
'type' => 'string',
'default' => date('Y-m-d H:i:s', strtotime("today midnight")),
'sanitize_callback' => array($this, 'sanitizeEndDate'),
),
'categories' => array(
'description' => 'Filter by categories',
'type' => 'object',
'default' => null,
),
'tags' => array(
'description' => 'Filter by tags',
'type' => 'object',
'default' => null,
),
'groups' => array(
'description' => 'Filter by groups',
'type' => 'object',
'default' => null,
),
'lat' => array(
'description' => 'Filter by coordinates',
'type' => 'string',
'default' => null,
),
'lng' => array(
'description' => 'Filter by coordinates',
'type' => 'string',
'default' => null,
),
'distance' => array(
'description' => 'Distance (km) radius from coordinates',
'type' => 'float',
'default' => null,
),
'module_id' => array(
'description' => 'The module ID',
'type' => 'integer',
'default' => 0,
'sanitize_callback' => 'absint',
),
'search_string' => array(
'description' => 'Filter by search string',
'type' => 'string',
'default' => '',
'sanitize_callback' => 'sanitize_text_field',
),
'age_group' => array(
'description' => 'Filter by age group.',
'type' => 'object',
'default' => null,
),
'lang' => array(
'description' => 'Filter by language.',
'type' => 'string',
'default' => null,
),
);
} | php | {
"resource": ""
} |
q258497 | Events.sanitizeEndDate | test | public function sanitizeEndDate($data)
{
$data = strtotime($data);
if ($data == false) {
$data = strtotime('today midnight');
}
$data = strtotime('+1 day', $data) - 1;
return date('Y-m-d H:i:s', $data);
} | php | {
"resource": ""
} |
q258498 | Events.getEvents | test | public function getEvents($request)
{
// Get params
$params = $request->get_params();
// Set display limit to -1 to get all events
$params['display_limit'] = -1;
// Save coordinates to location array
if (!empty($params['lat']) && !empty($params['lng'])) {
$params['location'] = array(
'lat' => $params['lat'],
'lng' => $params['lng'],
);
}
// Get events
$events = \EventManagerIntegration\Helper\QueryEvents::getEventsByInterval($params, 1);
// Return error if result is empty
if (empty($events)) {
return new \WP_REST_Response(
array(
'message' => __('No events could be found.', 'event-integration'),
'state' => 'empty_result',
),
404
);
}
// Set total items & pages count
$total = count($events);
$totalPages = 1;
// If per page param is not unlimited, get chunk of paged items
if ($params['per_page'] !== -1) {
// Calculate total pages
$totalPages = ceil($total / $params['per_page']);
$offset = ($params['page'] - 1) * $params['per_page'];
$offset = $offset > 0 ? $offset : 0;
$events = array_slice($events, $offset, $params['per_page']);
}
// Sanitize and add meta data to items list
$events = $this->mapEventModuleData($params['module_id'], $events);
$response = rest_ensure_response($events);
// Set headers with total counts
$response->header('X-WP-Total', $total);
$response->header('X-WP-TotalPages', $totalPages);
return $response;
} | php | {
"resource": ""
} |
q258499 | Events.mapEventModuleData | test | public function mapEventModuleData($moduleId, $events)
{
$data = get_fields($moduleId);
$template = $data['mod_event_display'] ?? 'list';
$class = '\EventManagerIntegration\Module\Event\TemplateController\\'.ucwords($template).'Template';
if (class_exists($class)) {
$controller = new $class(array(), array(), $data);
if (is_array($data) && isset($controller->data) && is_array($controller->data)) {
$data = array_merge($data, $controller->data);
}
}
foreach ($events as &$event) {
// Set permalink url with date parameter
$event->permalink = esc_url(
add_query_arg('date', preg_replace('/\D/', '', $event->start_date), get_permalink($event->ID))
);
// Format occasion date
$event->occasion = \EventManagerIntegration\App::formatEventDate($event->start_date, $event->end_date);
// Set location
$location = get_post_meta($event->ID, 'location', true);
$event->location = !empty($location['title']) ? $location['title'] : null;
// Get image url
switch ($template) {
case 'index':
if (function_exists('municipio_get_thumbnail_source') && municipio_get_thumbnail_source(
$event->ID,
array($data['imageDimensions']['width'], $data['imageDimensions']['height']),
$data['imageRatio']
)) {
$event->image_url = municipio_get_thumbnail_source(
$event->ID,
array($data['imageDimensions']['width'], $data['imageDimensions']['height']),
$data['imageRatio']
);
} elseif (!empty($data['mod_event_def_image'])) {
$src = wp_get_attachment_image_src(
$data['mod_event_def_image']['ID'],
municipio_to_aspect_ratio(
$data['imageRatio'],
array($data['imageDimensions']['width'], $data['imageDimensions']['height'])
)
);
$event->image_url = $src[0] ?? null;
}
break;
default:
if (function_exists('municipio_get_thumbnail_source') && municipio_get_thumbnail_source(
$event->ID
)) {
$event->image_url = municipio_get_thumbnail_source($event->ID);
} elseif (!empty($data['mod_event_def_image'])) {
$src = wp_get_attachment_image_src(
$data['mod_event_def_image']['ID']
);
$event->image_url = $src[0] ?? null;
}
}
}
return $events;
} | php | {
"resource": ""
} |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.