repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
plank/laravel-mediable | src/MediaUploader.php | MediaUploader.generateUniqueFilename | private function generateUniqueFilename(Media $model)
{
$storage = $this->filesystem->disk($model->disk);
$counter = 0;
do {
$filename = "{$model->filename}";
if ($counter > 0) {
$filename .= '-' . $counter;
}
$path = "{$model->directory}/{$filename}.{$model->extension}";
++$counter;
} while ($storage->has($path));
return $filename;
} | php | private function generateUniqueFilename(Media $model)
{
$storage = $this->filesystem->disk($model->disk);
$counter = 0;
do {
$filename = "{$model->filename}";
if ($counter > 0) {
$filename .= '-' . $counter;
}
$path = "{$model->directory}/{$filename}.{$model->extension}";
++$counter;
} while ($storage->has($path));
return $filename;
} | [
"private",
"function",
"generateUniqueFilename",
"(",
"Media",
"$",
"model",
")",
"{",
"$",
"storage",
"=",
"$",
"this",
"->",
"filesystem",
"->",
"disk",
"(",
"$",
"model",
"->",
"disk",
")",
";",
"$",
"counter",
"=",
"0",
";",
"do",
"{",
"$",
"file... | Increment model's filename until one is found that doesn't already exist.
@param \Plank\Mediable\Media $model
@return string | [
"Increment",
"model",
"s",
"filename",
"until",
"one",
"is",
"found",
"that",
"doesn",
"t",
"already",
"exist",
"."
] | 034b79452aac0e9e0a42372af21cd8dfe83a6da2 | https://github.com/plank/laravel-mediable/blob/034b79452aac0e9e0a42372af21cd8dfe83a6da2/src/MediaUploader.php#L757-L771 | train |
plank/laravel-mediable | src/MediaUploader.php | MediaUploader.generateFilename | private function generateFilename()
{
if ($this->filename) {
return $this->filename;
}
if ($this->hash_filename) {
return $this->generateHash();
}
return $this->sanitizeFileName($this->source->filename());
} | php | private function generateFilename()
{
if ($this->filename) {
return $this->filename;
}
if ($this->hash_filename) {
return $this->generateHash();
}
return $this->sanitizeFileName($this->source->filename());
} | [
"private",
"function",
"generateFilename",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"filename",
")",
"{",
"return",
"$",
"this",
"->",
"filename",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hash_filename",
")",
"{",
"return",
"$",
"this",
"->",
"ge... | Generate the model's filename.
@return string | [
"Generate",
"the",
"model",
"s",
"filename",
"."
] | 034b79452aac0e9e0a42372af21cd8dfe83a6da2 | https://github.com/plank/laravel-mediable/blob/034b79452aac0e9e0a42372af21cd8dfe83a6da2/src/MediaUploader.php#L777-L788 | train |
plank/laravel-mediable | src/MediaUploader.php | MediaUploader.generateHash | private function generateHash()
{
$ctx = hash_init('md5');
// We don't need to read the file contents if the source has a path
if ($this->source->path()) {
hash_update_file($ctx, $this->source->path());
} else {
hash_update($ctx, $this->source->contents());
}
return hash_final($ctx);
} | php | private function generateHash()
{
$ctx = hash_init('md5');
// We don't need to read the file contents if the source has a path
if ($this->source->path()) {
hash_update_file($ctx, $this->source->path());
} else {
hash_update($ctx, $this->source->contents());
}
return hash_final($ctx);
} | [
"private",
"function",
"generateHash",
"(",
")",
"{",
"$",
"ctx",
"=",
"hash_init",
"(",
"'md5'",
")",
";",
"// We don't need to read the file contents if the source has a path",
"if",
"(",
"$",
"this",
"->",
"source",
"->",
"path",
"(",
")",
")",
"{",
"hash_upd... | Calculate hash of source contents.
@return string | [
"Calculate",
"hash",
"of",
"source",
"contents",
"."
] | 034b79452aac0e9e0a42372af21cd8dfe83a6da2 | https://github.com/plank/laravel-mediable/blob/034b79452aac0e9e0a42372af21cd8dfe83a6da2/src/MediaUploader.php#L794-L806 | train |
plank/laravel-mediable | src/UrlGenerators/UrlGeneratorFactory.php | UrlGeneratorFactory.create | public function create(Media $media)
{
$driver = $this->getDriverForDisk($media->disk);
if (array_key_exists($driver, $this->driver_generators)) {
$class = $this->driver_generators[$driver];
$generator = app($class);
$generator->setMedia($media);
return $generator;
}
throw MediaUrlException::generatorNotFound($media->disk, $driver);
} | php | public function create(Media $media)
{
$driver = $this->getDriverForDisk($media->disk);
if (array_key_exists($driver, $this->driver_generators)) {
$class = $this->driver_generators[$driver];
$generator = app($class);
$generator->setMedia($media);
return $generator;
}
throw MediaUrlException::generatorNotFound($media->disk, $driver);
} | [
"public",
"function",
"create",
"(",
"Media",
"$",
"media",
")",
"{",
"$",
"driver",
"=",
"$",
"this",
"->",
"getDriverForDisk",
"(",
"$",
"media",
"->",
"disk",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"driver",
",",
"$",
"this",
"->",
"dr... | Get a UrlGenerator instance for a media.
@param \Plank\Mediable\Media $media
@return \Plank\Mediable\UrlGenerators\UrlGeneratorInterface
@throws \Plank\Mediable\Exceptions\MediaUrlException If no generator class has been assigned for the media's disk's driver | [
"Get",
"a",
"UrlGenerator",
"instance",
"for",
"a",
"media",
"."
] | 034b79452aac0e9e0a42372af21cd8dfe83a6da2 | https://github.com/plank/laravel-mediable/blob/034b79452aac0e9e0a42372af21cd8dfe83a6da2/src/UrlGenerators/UrlGeneratorFactory.php#L27-L40 | train |
plank/laravel-mediable | src/MediableServiceProvider.php | MediableServiceProvider.registerSourceAdapterFactory | public function registerSourceAdapterFactory()
{
$this->app->singleton('mediable.source.factory', function (Container $app) {
$factory = new SourceAdapterFactory;
$adapters = $app['config']->get('mediable.source_adapters');
foreach ($adapters['class'] as $source => $adapter) {
$factory->setAdapterForClass($adapter, $source);
}
foreach ($adapters['pattern'] as $source => $adapter) {
$factory->setAdapterForPattern($adapter, $source);
}
return $factory;
});
$this->app->alias('mediable.source.factory', SourceAdapterFactory::class);
} | php | public function registerSourceAdapterFactory()
{
$this->app->singleton('mediable.source.factory', function (Container $app) {
$factory = new SourceAdapterFactory;
$adapters = $app['config']->get('mediable.source_adapters');
foreach ($adapters['class'] as $source => $adapter) {
$factory->setAdapterForClass($adapter, $source);
}
foreach ($adapters['pattern'] as $source => $adapter) {
$factory->setAdapterForPattern($adapter, $source);
}
return $factory;
});
$this->app->alias('mediable.source.factory', SourceAdapterFactory::class);
} | [
"public",
"function",
"registerSourceAdapterFactory",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'mediable.source.factory'",
",",
"function",
"(",
"Container",
"$",
"app",
")",
"{",
"$",
"factory",
"=",
"new",
"SourceAdapterFactory",
";",
... | Bind an instance of the Source Adapter Factory to the container.
Attaches the default adapter types
@return void | [
"Bind",
"an",
"instance",
"of",
"the",
"Source",
"Adapter",
"Factory",
"to",
"the",
"container",
"."
] | 034b79452aac0e9e0a42372af21cd8dfe83a6da2 | https://github.com/plank/laravel-mediable/blob/034b79452aac0e9e0a42372af21cd8dfe83a6da2/src/MediableServiceProvider.php#L62-L79 | train |
plank/laravel-mediable | src/MediableServiceProvider.php | MediableServiceProvider.registerConsoleCommands | public function registerConsoleCommands()
{
$this->commands([
\Plank\Mediable\Commands\ImportMediaCommand::class,
\Plank\Mediable\Commands\PruneMediaCommand::class,
\Plank\Mediable\Commands\SyncMediaCommand::class,
]);
} | php | public function registerConsoleCommands()
{
$this->commands([
\Plank\Mediable\Commands\ImportMediaCommand::class,
\Plank\Mediable\Commands\PruneMediaCommand::class,
\Plank\Mediable\Commands\SyncMediaCommand::class,
]);
} | [
"public",
"function",
"registerConsoleCommands",
"(",
")",
"{",
"$",
"this",
"->",
"commands",
"(",
"[",
"\\",
"Plank",
"\\",
"Mediable",
"\\",
"Commands",
"\\",
"ImportMediaCommand",
"::",
"class",
",",
"\\",
"Plank",
"\\",
"Mediable",
"\\",
"Commands",
"\\... | Add package commands to artisan console.
@return void | [
"Add",
"package",
"commands",
"to",
"artisan",
"console",
"."
] | 034b79452aac0e9e0a42372af21cd8dfe83a6da2 | https://github.com/plank/laravel-mediable/blob/034b79452aac0e9e0a42372af21cd8dfe83a6da2/src/MediableServiceProvider.php#L128-L135 | train |
plank/laravel-mediable | src/SourceAdapters/SourceAdapterFactory.php | SourceAdapterFactory.create | public function create($source)
{
$adapter = null;
if ($source instanceof SourceAdapterInterface) {
return $source;
} elseif (is_object($source)) {
$adapter = $this->adaptClass($source);
} elseif (is_resource($source)) {
$adapter = StreamResourceAdapter::class;
} elseif (is_string($source)) {
$adapter = $this->adaptString($source);
}
if ($adapter) {
return new $adapter($source);
}
throw ConfigurationException::unrecognizedSource($source);
} | php | public function create($source)
{
$adapter = null;
if ($source instanceof SourceAdapterInterface) {
return $source;
} elseif (is_object($source)) {
$adapter = $this->adaptClass($source);
} elseif (is_resource($source)) {
$adapter = StreamResourceAdapter::class;
} elseif (is_string($source)) {
$adapter = $this->adaptString($source);
}
if ($adapter) {
return new $adapter($source);
}
throw ConfigurationException::unrecognizedSource($source);
} | [
"public",
"function",
"create",
"(",
"$",
"source",
")",
"{",
"$",
"adapter",
"=",
"null",
";",
"if",
"(",
"$",
"source",
"instanceof",
"SourceAdapterInterface",
")",
"{",
"return",
"$",
"source",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"source",... | Create a Source Adapter for the provided source.
@param object|string $source
@return \Plank\Mediable\SourceAdapters\SourceAdapterInterface
@throws \Plank\Mediable\Exceptions\MediaUpload\ConfigurationException If the provided source does not match any of the mapped classes or patterns | [
"Create",
"a",
"Source",
"Adapter",
"for",
"the",
"provided",
"source",
"."
] | 034b79452aac0e9e0a42372af21cd8dfe83a6da2 | https://github.com/plank/laravel-mediable/blob/034b79452aac0e9e0a42372af21cd8dfe83a6da2/src/SourceAdapters/SourceAdapterFactory.php#L35-L54 | train |
plank/laravel-mediable | src/SourceAdapters/SourceAdapterFactory.php | SourceAdapterFactory.setAdapterForClass | public function setAdapterForClass($adapter_class, $source_class)
{
$this->validateAdapterClass($adapter_class);
$this->class_adapters[$source_class] = $adapter_class;
} | php | public function setAdapterForClass($adapter_class, $source_class)
{
$this->validateAdapterClass($adapter_class);
$this->class_adapters[$source_class] = $adapter_class;
} | [
"public",
"function",
"setAdapterForClass",
"(",
"$",
"adapter_class",
",",
"$",
"source_class",
")",
"{",
"$",
"this",
"->",
"validateAdapterClass",
"(",
"$",
"adapter_class",
")",
";",
"$",
"this",
"->",
"class_adapters",
"[",
"$",
"source_class",
"]",
"=",
... | Specify the FQCN of a SourceAdapter class to use when the source inherits from a given class.
@param string $adapter_class
@param string $source_class
@return void | [
"Specify",
"the",
"FQCN",
"of",
"a",
"SourceAdapter",
"class",
"to",
"use",
"when",
"the",
"source",
"inherits",
"from",
"a",
"given",
"class",
"."
] | 034b79452aac0e9e0a42372af21cd8dfe83a6da2 | https://github.com/plank/laravel-mediable/blob/034b79452aac0e9e0a42372af21cd8dfe83a6da2/src/SourceAdapters/SourceAdapterFactory.php#L62-L66 | train |
plank/laravel-mediable | src/SourceAdapters/SourceAdapterFactory.php | SourceAdapterFactory.setAdapterForPattern | public function setAdapterForPattern($adapter_class, $source_pattern)
{
$this->validateAdapterClass($adapter_class);
$this->pattern_adapters[$source_pattern] = $adapter_class;
} | php | public function setAdapterForPattern($adapter_class, $source_pattern)
{
$this->validateAdapterClass($adapter_class);
$this->pattern_adapters[$source_pattern] = $adapter_class;
} | [
"public",
"function",
"setAdapterForPattern",
"(",
"$",
"adapter_class",
",",
"$",
"source_pattern",
")",
"{",
"$",
"this",
"->",
"validateAdapterClass",
"(",
"$",
"adapter_class",
")",
";",
"$",
"this",
"->",
"pattern_adapters",
"[",
"$",
"source_pattern",
"]",... | Specify the FQCN of a SourceAdapter class to use when the source is a string matching the given pattern.
@param string $adapter_class
@param string $source_pattern
@return void | [
"Specify",
"the",
"FQCN",
"of",
"a",
"SourceAdapter",
"class",
"to",
"use",
"when",
"the",
"source",
"is",
"a",
"string",
"matching",
"the",
"given",
"pattern",
"."
] | 034b79452aac0e9e0a42372af21cd8dfe83a6da2 | https://github.com/plank/laravel-mediable/blob/034b79452aac0e9e0a42372af21cd8dfe83a6da2/src/SourceAdapters/SourceAdapterFactory.php#L74-L78 | train |
plank/laravel-mediable | src/SourceAdapters/SourceAdapterFactory.php | SourceAdapterFactory.adaptString | private function adaptString($source)
{
foreach ($this->pattern_adapters as $pattern => $adapter) {
$pattern = '/'.str_replace('/', '\\/', $pattern).'/i';
if (preg_match($pattern, $source)) {
return $adapter;
}
}
} | php | private function adaptString($source)
{
foreach ($this->pattern_adapters as $pattern => $adapter) {
$pattern = '/'.str_replace('/', '\\/', $pattern).'/i';
if (preg_match($pattern, $source)) {
return $adapter;
}
}
} | [
"private",
"function",
"adaptString",
"(",
"$",
"source",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"pattern_adapters",
"as",
"$",
"pattern",
"=>",
"$",
"adapter",
")",
"{",
"$",
"pattern",
"=",
"'/'",
".",
"str_replace",
"(",
"'/'",
",",
"'\\\\/'",
... | Choose an adapter class for the provided string.
@param string $source
@return string|null | [
"Choose",
"an",
"adapter",
"class",
"for",
"the",
"provided",
"string",
"."
] | 034b79452aac0e9e0a42372af21cd8dfe83a6da2 | https://github.com/plank/laravel-mediable/blob/034b79452aac0e9e0a42372af21cd8dfe83a6da2/src/SourceAdapters/SourceAdapterFactory.php#L99-L107 | train |
plank/laravel-mediable | src/UrlGenerators/LocalUrlGenerator.php | LocalUrlGenerator.getPublicPath | public function getPublicPath()
{
if (! $this->isPubliclyAccessible()) {
throw MediaUrlException::mediaNotPubliclyAccessible($this->getAbsolutePath(), public_path());
}
if ($this->isInWebroot()) {
$path = str_replace(public_path(), '', $this->getAbsolutePath());
} else {
$path = rtrim($this->getPrefix(), '/').'/'.$this->media->getDiskPath();
}
return $this->cleanDirectorySeparators($path);
} | php | public function getPublicPath()
{
if (! $this->isPubliclyAccessible()) {
throw MediaUrlException::mediaNotPubliclyAccessible($this->getAbsolutePath(), public_path());
}
if ($this->isInWebroot()) {
$path = str_replace(public_path(), '', $this->getAbsolutePath());
} else {
$path = rtrim($this->getPrefix(), '/').'/'.$this->media->getDiskPath();
}
return $this->cleanDirectorySeparators($path);
} | [
"public",
"function",
"getPublicPath",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isPubliclyAccessible",
"(",
")",
")",
"{",
"throw",
"MediaUrlException",
"::",
"mediaNotPubliclyAccessible",
"(",
"$",
"this",
"->",
"getAbsolutePath",
"(",
")",
",",
"... | Get the path to relative to the webroot.
@return string
@throws \Plank\Mediable\Exceptions\MediaUrlException If media's disk is not publicly accessible | [
"Get",
"the",
"path",
"to",
"relative",
"to",
"the",
"webroot",
"."
] | 034b79452aac0e9e0a42372af21cd8dfe83a6da2 | https://github.com/plank/laravel-mediable/blob/034b79452aac0e9e0a42372af21cd8dfe83a6da2/src/UrlGenerators/LocalUrlGenerator.php#L45-L57 | train |
plank/laravel-mediable | src/UrlGenerators/LocalUrlGenerator.php | LocalUrlGenerator.getPrefix | private function getPrefix()
{
$prefix = $this->getDiskConfig('prefix', '');
$url = $this->getDiskConfig('url');
if (! $prefix && ! $url) {
return 'storage';
}
return $prefix;
} | php | private function getPrefix()
{
$prefix = $this->getDiskConfig('prefix', '');
$url = $this->getDiskConfig('url');
if (! $prefix && ! $url) {
return 'storage';
}
return $prefix;
} | [
"private",
"function",
"getPrefix",
"(",
")",
"{",
"$",
"prefix",
"=",
"$",
"this",
"->",
"getDiskConfig",
"(",
"'prefix'",
",",
"''",
")",
";",
"$",
"url",
"=",
"$",
"this",
"->",
"getDiskConfig",
"(",
"'url'",
")",
";",
"if",
"(",
"!",
"$",
"pref... | Get the prefix.
If the prefix and the url are not set, we will assume the prefix
is "storage", in order to point to the default symbolink link.
Otherwise, we will trust the user has correctly set the prefix and/or the url.
@return string | [
"Get",
"the",
"prefix",
"."
] | 034b79452aac0e9e0a42372af21cd8dfe83a6da2 | https://github.com/plank/laravel-mediable/blob/034b79452aac0e9e0a42372af21cd8dfe83a6da2/src/UrlGenerators/LocalUrlGenerator.php#L117-L127 | train |
aimeos/aimeos-typo3 | Classes/Flexform/Catalog.php | Catalog.getCategories | public function getCategories( array $config, $tceForms = null, $sitecode = 'default' )
{
try
{
if( isset( $config['flexParentDatabaseRow']['pid'] ) ) { // TYPO3 7+
$pid = $config['flexParentDatabaseRow']['pid'];
} elseif( isset( $config['row']['pid'] ) ) { // TYPO3 6.2
$pid = $config['row']['pid'];
} else {
throw new \Exception( 'No PID found in "flexParentDatabaseRow" or "row" array key: ' . print_r( $config, true ) );
}
$pageTSConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getModTSconfig( $pid, 'tx_aimeos' );
if( isset( $pageTSConfig['properties']['mshop.']['locale.']['site'] ) ) {
$sitecode = $pageTSConfig['properties']['mshop.']['locale.']['site'];
}
$context = Base::getContext( Base::getConfig() );
$context->setEditor( 'flexform' );
$localeManager = \Aimeos\MShop::create( $context, 'locale' );
$context->setLocale( $localeManager->bootstrap( $sitecode, '', '', false ) );
$manager = \Aimeos\MShop::create( $context, 'catalog' );
$item = $manager->getTree( null, array(), \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
$config['items'] = array_merge( $config['items'], $this->getCategoryList( $item, $item->getName() ) );
}
catch( \Exception $e )
{
error_log( $e->getMessage() . PHP_EOL . $e->getTraceAsString() );
}
return $config;
} | php | public function getCategories( array $config, $tceForms = null, $sitecode = 'default' )
{
try
{
if( isset( $config['flexParentDatabaseRow']['pid'] ) ) { // TYPO3 7+
$pid = $config['flexParentDatabaseRow']['pid'];
} elseif( isset( $config['row']['pid'] ) ) { // TYPO3 6.2
$pid = $config['row']['pid'];
} else {
throw new \Exception( 'No PID found in "flexParentDatabaseRow" or "row" array key: ' . print_r( $config, true ) );
}
$pageTSConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getModTSconfig( $pid, 'tx_aimeos' );
if( isset( $pageTSConfig['properties']['mshop.']['locale.']['site'] ) ) {
$sitecode = $pageTSConfig['properties']['mshop.']['locale.']['site'];
}
$context = Base::getContext( Base::getConfig() );
$context->setEditor( 'flexform' );
$localeManager = \Aimeos\MShop::create( $context, 'locale' );
$context->setLocale( $localeManager->bootstrap( $sitecode, '', '', false ) );
$manager = \Aimeos\MShop::create( $context, 'catalog' );
$item = $manager->getTree( null, array(), \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
$config['items'] = array_merge( $config['items'], $this->getCategoryList( $item, $item->getName() ) );
}
catch( \Exception $e )
{
error_log( $e->getMessage() . PHP_EOL . $e->getTraceAsString() );
}
return $config;
} | [
"public",
"function",
"getCategories",
"(",
"array",
"$",
"config",
",",
"$",
"tceForms",
"=",
"null",
",",
"$",
"sitecode",
"=",
"'default'",
")",
"{",
"try",
"{",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'flexParentDatabaseRow'",
"]",
"[",
"'pid'"... | Returns the list of categories with their ID.
@param array $config Associative array of existing configurations
@param \TYPO3\CMS\Backend\Form\FormEngine|\TYPO3\CMS\Backend\Form\DataPreprocessor $tceForms TCE forms object
@param string $sitecode Unique code of the site to retrieve the categories for
@return array Associative array with existing and new entries | [
"Returns",
"the",
"list",
"of",
"categories",
"with",
"their",
"ID",
"."
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Flexform/Catalog.php#L31-L68 | train |
aimeos/aimeos-typo3 | Classes/Controller/JqadmController.php | JqadmController.exportAction | public function exportAction()
{
$cntl = $this->createAdmin();
if( ( $html = $cntl->export() ) == '' ) {
return $this->setPsrResponse( $cntl->getView()->response() );
}
$this->view->assign( 'content', $html );
} | php | public function exportAction()
{
$cntl = $this->createAdmin();
if( ( $html = $cntl->export() ) == '' ) {
return $this->setPsrResponse( $cntl->getView()->response() );
}
$this->view->assign( 'content', $html );
} | [
"public",
"function",
"exportAction",
"(",
")",
"{",
"$",
"cntl",
"=",
"$",
"this",
"->",
"createAdmin",
"(",
")",
";",
"if",
"(",
"(",
"$",
"html",
"=",
"$",
"cntl",
"->",
"export",
"(",
")",
")",
"==",
"''",
")",
"{",
"return",
"$",
"this",
"... | Exports the resource object
@return string Generated output | [
"Exports",
"the",
"resource",
"object"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Controller/JqadmController.php#L132-L141 | train |
aimeos/aimeos-typo3 | Classes/Controller/JqadmController.php | JqadmController.importAction | public function importAction()
{
$cntl = $this->createAdmin();
if( ( $html = $cntl->import() ) == '' ) {
return $this->setPsrResponse( $cntl->getView()->response() );
}
$this->view->assign( 'content', $html );
} | php | public function importAction()
{
$cntl = $this->createAdmin();
if( ( $html = $cntl->import() ) == '' ) {
return $this->setPsrResponse( $cntl->getView()->response() );
}
$this->view->assign( 'content', $html );
} | [
"public",
"function",
"importAction",
"(",
")",
"{",
"$",
"cntl",
"=",
"$",
"this",
"->",
"createAdmin",
"(",
")",
";",
"if",
"(",
"(",
"$",
"html",
"=",
"$",
"cntl",
"->",
"import",
"(",
")",
")",
"==",
"''",
")",
"{",
"return",
"$",
"this",
"... | Imports the resource object
@return string Generated output | [
"Imports",
"the",
"resource",
"object"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Controller/JqadmController.php#L166-L175 | train |
aimeos/aimeos-typo3 | Classes/Controller/JqadmController.php | JqadmController.setPsrResponse | protected function setPsrResponse( \Psr\Http\Message\ResponseInterface $response )
{
$this->response->setStatus( $response->getStatusCode() );
foreach( $response->getHeaders() as $key => $value ) {
foreach( (array) $value as $val ) {
$this->response->setHeader( $key, $val );
}
}
return (string) $response->getBody();
} | php | protected function setPsrResponse( \Psr\Http\Message\ResponseInterface $response )
{
$this->response->setStatus( $response->getStatusCode() );
foreach( $response->getHeaders() as $key => $value ) {
foreach( (array) $value as $val ) {
$this->response->setHeader( $key, $val );
}
}
return (string) $response->getBody();
} | [
"protected",
"function",
"setPsrResponse",
"(",
"\\",
"Psr",
"\\",
"Http",
"\\",
"Message",
"\\",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"this",
"->",
"response",
"->",
"setStatus",
"(",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
")",
... | Set the response data from a PSR-7 response object and returns the message content
@param \Psr\Http\Message\ResponseInterface $response PSR-7 response object
@return string Generated output | [
"Set",
"the",
"response",
"data",
"from",
"a",
"PSR",
"-",
"7",
"response",
"object",
"and",
"returns",
"the",
"message",
"content"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Controller/JqadmController.php#L259-L270 | train |
aimeos/aimeos-typo3 | Classes/Base.php | Base.getConfig | public static function getConfig( array $local = array() )
{
$name = 'Aimeos\Aimeos\Base\Config';
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_config'] ) ) {
if( ( $name = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_config'] ) instanceof \Closure ) {
return $name( self::getAimeos()->getConfigPaths(), $local );
}
}
return $name::get( self::getAimeos()->getConfigPaths(), $local );
} | php | public static function getConfig( array $local = array() )
{
$name = 'Aimeos\Aimeos\Base\Config';
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_config'] ) ) {
if( ( $name = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_config'] ) instanceof \Closure ) {
return $name( self::getAimeos()->getConfigPaths(), $local );
}
}
return $name::get( self::getAimeos()->getConfigPaths(), $local );
} | [
"public",
"static",
"function",
"getConfig",
"(",
"array",
"$",
"local",
"=",
"array",
"(",
")",
")",
"{",
"$",
"name",
"=",
"'Aimeos\\Aimeos\\Base\\Config'",
";",
"if",
"(",
"isset",
"(",
"$",
"GLOBALS",
"[",
"'TYPO3_CONF_VARS'",
"]",
"[",
"'EXTCONF'",
"]... | Creates a new configuration object
@param array $local Multi-dimensional associative list with local configuration
@return \Aimeos\MW\Config\Iface Configuration object | [
"Creates",
"a",
"new",
"configuration",
"object"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Base.php#L58-L69 | train |
aimeos/aimeos-typo3 | Classes/Base.php | Base.getExtConfig | public static function getExtConfig( $name, $default = null )
{
if( self::$extConfig === null )
{
if( class_exists( '\TYPO3\CMS\Core\Configuration\ExtensionConfiguration' ) ) {
self::$extConfig = GeneralUtility::makeInstance( 'TYPO3\CMS\Core\Configuration\ExtensionConfiguration' )->get( 'aimeos' );
} else { // @deprecated Since TYPO3 9.x
self::$extConfig = unserialize( $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['aimeos'] );
}
}
if( isset( self::$extConfig[$name] ) ) {
return self::$extConfig[$name];
}
return $default;
} | php | public static function getExtConfig( $name, $default = null )
{
if( self::$extConfig === null )
{
if( class_exists( '\TYPO3\CMS\Core\Configuration\ExtensionConfiguration' ) ) {
self::$extConfig = GeneralUtility::makeInstance( 'TYPO3\CMS\Core\Configuration\ExtensionConfiguration' )->get( 'aimeos' );
} else { // @deprecated Since TYPO3 9.x
self::$extConfig = unserialize( $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['aimeos'] );
}
}
if( isset( self::$extConfig[$name] ) ) {
return self::$extConfig[$name];
}
return $default;
} | [
"public",
"static",
"function",
"getExtConfig",
"(",
"$",
"name",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"extConfig",
"===",
"null",
")",
"{",
"if",
"(",
"class_exists",
"(",
"'\\TYPO3\\CMS\\Core\\Configuration\\ExtensionConf... | Returns the extension configuration
@param string Name of the configuration setting
@param mixed Value returned if no value in extension configuration was found
@return mixed Value associated with the configuration setting | [
"Returns",
"the",
"extension",
"configuration"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Base.php#L99-L115 | train |
aimeos/aimeos-typo3 | Classes/Base.php | Base.getI18n | public static function getI18n( array $languageIds, array $local = array() )
{
$name = 'Aimeos\Aimeos\Base\I18n';
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_i18n'] ) ) {
if( ( $name = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_i18n'] ) instanceof \Closure ) {
return $name( self::getAimeos()->getI18nPaths(), $languageIds, $local );
}
}
return $name::get( self::getAimeos()->getI18nPaths(), $languageIds, $local );
} | php | public static function getI18n( array $languageIds, array $local = array() )
{
$name = 'Aimeos\Aimeos\Base\I18n';
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_i18n'] ) ) {
if( ( $name = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_i18n'] ) instanceof \Closure ) {
return $name( self::getAimeos()->getI18nPaths(), $languageIds, $local );
}
}
return $name::get( self::getAimeos()->getI18nPaths(), $languageIds, $local );
} | [
"public",
"static",
"function",
"getI18n",
"(",
"array",
"$",
"languageIds",
",",
"array",
"$",
"local",
"=",
"array",
"(",
")",
")",
"{",
"$",
"name",
"=",
"'Aimeos\\Aimeos\\Base\\I18n'",
";",
"if",
"(",
"isset",
"(",
"$",
"GLOBALS",
"[",
"'TYPO3_CONF_VAR... | Creates new translation objects
@param array $languageIds List of two letter ISO language IDs
@param array $local List of local translation entries overwriting the standard ones
@return array List of translation objects implementing MW_Translation_Interface | [
"Creates",
"new",
"translation",
"objects"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Base.php#L125-L136 | train |
aimeos/aimeos-typo3 | Classes/Base.php | Base.getVersion | public static function getVersion()
{
$match = array();
$content = @file_get_contents( dirname( __DIR__ ) . DIRECTORY_SEPARATOR . 'ext_emconf.php' );
if( preg_match( "/'version' => '([^']+)'/", $content, $match ) === 1 ) {
return $match[1];
}
return '';
} | php | public static function getVersion()
{
$match = array();
$content = @file_get_contents( dirname( __DIR__ ) . DIRECTORY_SEPARATOR . 'ext_emconf.php' );
if( preg_match( "/'version' => '([^']+)'/", $content, $match ) === 1 ) {
return $match[1];
}
return '';
} | [
"public",
"static",
"function",
"getVersion",
"(",
")",
"{",
"$",
"match",
"=",
"array",
"(",
")",
";",
"$",
"content",
"=",
"@",
"file_get_contents",
"(",
"dirname",
"(",
"__DIR__",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'ext_emconf.php'",
")",
";",
"if",... | Returns the version of the Aimeos TYPO3 extension
@return string Version string | [
"Returns",
"the",
"version",
"of",
"the",
"Aimeos",
"TYPO3",
"extension"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Base.php#L194-L204 | train |
aimeos/aimeos-typo3 | Classes/Base/Locale.php | Locale.get | public static function get( \Aimeos\MShop\Context\Item\Iface $context, \TYPO3\CMS\Extbase\Mvc\RequestInterface $request = null )
{
if( !isset( self::$locale ) )
{
$config = $context->getConfig();
$sitecode = $config->get( 'mshop/locale/site', 'default' );
$name = $config->get( 'typo3/param/name/site', 'site' );
if( $request !== null && $request->hasArgument( $name ) === true ) {
$sitecode = $request->getArgument( $name );
} elseif( ( $value = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP( 'S' ) ) !== null ) {
$sitecode = $value;
}
$langid = $config->get( 'mshop/locale/language', '' );
$name = $config->get( 'typo3/param/name/language', 'locale' );
if( $request !== null && $request->hasArgument( $name ) === true ) {
$langid = $request->getArgument( $name );
} elseif( isset( $GLOBALS['TSFE']->config['config']['language'] ) ) {
$langid = $GLOBALS['TSFE']->config['config']['language'];
}
$currency = $config->get( 'mshop/locale/currency', '' );
$name = $config->get( 'typo3/param/name/currency', 'currency' );
if( $request !== null && $request->hasArgument( $name ) === true ) {
$currency = $request->getArgument( $name );
} elseif( ( $value = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP( 'C' ) ) !== null ) {
$currency = $value;
}
$localeManager = \Aimeos\MShop::create( $context, 'locale' );
self::$locale = $localeManager->bootstrap( $sitecode, $langid, $currency );
}
return self::$locale;
} | php | public static function get( \Aimeos\MShop\Context\Item\Iface $context, \TYPO3\CMS\Extbase\Mvc\RequestInterface $request = null )
{
if( !isset( self::$locale ) )
{
$config = $context->getConfig();
$sitecode = $config->get( 'mshop/locale/site', 'default' );
$name = $config->get( 'typo3/param/name/site', 'site' );
if( $request !== null && $request->hasArgument( $name ) === true ) {
$sitecode = $request->getArgument( $name );
} elseif( ( $value = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP( 'S' ) ) !== null ) {
$sitecode = $value;
}
$langid = $config->get( 'mshop/locale/language', '' );
$name = $config->get( 'typo3/param/name/language', 'locale' );
if( $request !== null && $request->hasArgument( $name ) === true ) {
$langid = $request->getArgument( $name );
} elseif( isset( $GLOBALS['TSFE']->config['config']['language'] ) ) {
$langid = $GLOBALS['TSFE']->config['config']['language'];
}
$currency = $config->get( 'mshop/locale/currency', '' );
$name = $config->get( 'typo3/param/name/currency', 'currency' );
if( $request !== null && $request->hasArgument( $name ) === true ) {
$currency = $request->getArgument( $name );
} elseif( ( $value = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP( 'C' ) ) !== null ) {
$currency = $value;
}
$localeManager = \Aimeos\MShop::create( $context, 'locale' );
self::$locale = $localeManager->bootstrap( $sitecode, $langid, $currency );
}
return self::$locale;
} | [
"public",
"static",
"function",
"get",
"(",
"\\",
"Aimeos",
"\\",
"MShop",
"\\",
"Context",
"\\",
"Item",
"\\",
"Iface",
"$",
"context",
",",
"\\",
"TYPO3",
"\\",
"CMS",
"\\",
"Extbase",
"\\",
"Mvc",
"\\",
"RequestInterface",
"$",
"request",
"=",
"null",... | Returns the locale object for frontend
@param \Aimeos\MShop\Context\Item\Iface $context Context object
@param \TYPO3\CMS\Extbase\Mvc\RequestInterface|null $request Request object
@return \Aimeos\MShop\Locale\Item\Iface Locale item object | [
"Returns",
"the",
"locale",
"object",
"for",
"frontend"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Base/Locale.php#L30-L72 | train |
aimeos/aimeos-typo3 | Classes/Base/Locale.php | Locale.getBackend | public static function getBackend( \Aimeos\MShop\Context\Item\Iface $context, $site )
{
$localeManager = \Aimeos\MShop::create( $context, 'locale' );
try {
$localeItem = $localeManager->bootstrap( $site, '', '', false, null, true );
} catch( \Aimeos\MShop\Exception $e ) {
$localeItem = $localeManager->createItem();
}
return $localeItem;
} | php | public static function getBackend( \Aimeos\MShop\Context\Item\Iface $context, $site )
{
$localeManager = \Aimeos\MShop::create( $context, 'locale' );
try {
$localeItem = $localeManager->bootstrap( $site, '', '', false, null, true );
} catch( \Aimeos\MShop\Exception $e ) {
$localeItem = $localeManager->createItem();
}
return $localeItem;
} | [
"public",
"static",
"function",
"getBackend",
"(",
"\\",
"Aimeos",
"\\",
"MShop",
"\\",
"Context",
"\\",
"Item",
"\\",
"Iface",
"$",
"context",
",",
"$",
"site",
")",
"{",
"$",
"localeManager",
"=",
"\\",
"Aimeos",
"\\",
"MShop",
"::",
"create",
"(",
"... | Returns the locale item for the backend
@param \Aimeos\MShop\Context\Item\Iface $context Context object
@param string $site Unique site code
@return \Aimeos\MShop\Context\Item\Iface Modified context object | [
"Returns",
"the",
"locale",
"item",
"for",
"the",
"backend"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Base/Locale.php#L82-L93 | train |
aimeos/aimeos-typo3 | Classes/Base/Context.php | Context.addHasher | protected static function addHasher( \Aimeos\MShop\Context\Item\Iface $context )
{
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_hasher'] )
&& is_callable( ( $fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_hasher'] ) )
) {
return $fcn( $context );
}
if( class_exists( '\TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory' ) ) // TYPO3 9+
{
$factory = GeneralUtility::makeInstance( 'TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory' );
$context->setHasherTypo3( $factory->getDefaultHashInstance( 'FE' ) );
}
elseif( class_exists( '\TYPO3\CMS\Saltedpasswords\Salt\SaltFactory' ) ) // TYPO3 7/8
{
$context->setHasherTypo3( \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getSaltingInstance() );
}
return $context;
} | php | protected static function addHasher( \Aimeos\MShop\Context\Item\Iface $context )
{
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_hasher'] )
&& is_callable( ( $fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_hasher'] ) )
) {
return $fcn( $context );
}
if( class_exists( '\TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory' ) ) // TYPO3 9+
{
$factory = GeneralUtility::makeInstance( 'TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory' );
$context->setHasherTypo3( $factory->getDefaultHashInstance( 'FE' ) );
}
elseif( class_exists( '\TYPO3\CMS\Saltedpasswords\Salt\SaltFactory' ) ) // TYPO3 7/8
{
$context->setHasherTypo3( \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getSaltingInstance() );
}
return $context;
} | [
"protected",
"static",
"function",
"addHasher",
"(",
"\\",
"Aimeos",
"\\",
"MShop",
"\\",
"Context",
"\\",
"Item",
"\\",
"Iface",
"$",
"context",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"GLOBALS",
"[",
"'TYPO3_CONF_VARS'",
"]",
"[",
"'EXTCONF'",
"]",
"["... | Adds the password hasher object to the context
@param \Aimeos\MShop\Context\Item\Iface $context Context object
@return \Aimeos\MShop\Context\Item\Iface Modified context object | [
"Adds",
"the",
"password",
"hasher",
"object",
"to",
"the",
"context"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Base/Context.php#L142-L161 | train |
aimeos/aimeos-typo3 | Classes/Base/Context.php | Context.addUser | protected static function addUser( \Aimeos\MShop\Context\Item\Iface $context )
{
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_user'] )
&& is_callable( ( $fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_user'] ) )
) {
return $fcn( $context );
}
if( TYPO3_MODE === 'FE' && $GLOBALS['TSFE']->loginUser == 1 )
{
$context->setUserId( $GLOBALS['TSFE']->fe_user->user[$GLOBALS['TSFE']->fe_user->userid_column] );
$context->setEditor( $GLOBALS['TSFE']->fe_user->user['username'] );
}
elseif( TYPO3_MODE === 'BE' && isset( $GLOBALS['BE_USER']->user['username'] ) )
{
$context->setEditor( $GLOBALS['BE_USER']->user['username'] );
}
else
{
$context->setEditor( GeneralUtility::getIndpEnv( 'REMOTE_ADDR' ) );
}
return $context;
} | php | protected static function addUser( \Aimeos\MShop\Context\Item\Iface $context )
{
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_user'] )
&& is_callable( ( $fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_user'] ) )
) {
return $fcn( $context );
}
if( TYPO3_MODE === 'FE' && $GLOBALS['TSFE']->loginUser == 1 )
{
$context->setUserId( $GLOBALS['TSFE']->fe_user->user[$GLOBALS['TSFE']->fe_user->userid_column] );
$context->setEditor( $GLOBALS['TSFE']->fe_user->user['username'] );
}
elseif( TYPO3_MODE === 'BE' && isset( $GLOBALS['BE_USER']->user['username'] ) )
{
$context->setEditor( $GLOBALS['BE_USER']->user['username'] );
}
else
{
$context->setEditor( GeneralUtility::getIndpEnv( 'REMOTE_ADDR' ) );
}
return $context;
} | [
"protected",
"static",
"function",
"addUser",
"(",
"\\",
"Aimeos",
"\\",
"MShop",
"\\",
"Context",
"\\",
"Item",
"\\",
"Iface",
"$",
"context",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"GLOBALS",
"[",
"'TYPO3_CONF_VARS'",
"]",
"[",
"'EXTCONF'",
"]",
"[",
... | Adds the user ID and editor name to the context
@param \Aimeos\MShop\Context\Item\Iface $context Context object
@return \Aimeos\MShop\Context\Item\Iface Modified context object | [
"Adds",
"the",
"user",
"ID",
"and",
"editor",
"name",
"to",
"the",
"context"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Base/Context.php#L280-L303 | train |
aimeos/aimeos-typo3 | Classes/Base/Context.php | Context.addGroups | protected static function addGroups( \Aimeos\MShop\Context\Item\Iface $context )
{
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_groups'] )
&& is_callable( ( $fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_groups'] ) )
) {
return $fcn( $context );
}
if( TYPO3_MODE === 'FE' && $GLOBALS['TSFE']->loginUser == 1 )
{
$ids = GeneralUtility::trimExplode( ',', $GLOBALS['TSFE']->fe_user->user['usergroup'] );
$context->setGroupIds( $ids );
}
elseif( TYPO3_MODE === 'BE' && $GLOBALS['BE_USER']->userGroups )
{
$ids = array_keys( $GLOBALS['BE_USER']->userGroups );
$context->setGroupIds( $ids );
}
return $context;
} | php | protected static function addGroups( \Aimeos\MShop\Context\Item\Iface $context )
{
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_groups'] )
&& is_callable( ( $fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_groups'] ) )
) {
return $fcn( $context );
}
if( TYPO3_MODE === 'FE' && $GLOBALS['TSFE']->loginUser == 1 )
{
$ids = GeneralUtility::trimExplode( ',', $GLOBALS['TSFE']->fe_user->user['usergroup'] );
$context->setGroupIds( $ids );
}
elseif( TYPO3_MODE === 'BE' && $GLOBALS['BE_USER']->userGroups )
{
$ids = array_keys( $GLOBALS['BE_USER']->userGroups );
$context->setGroupIds( $ids );
}
return $context;
} | [
"protected",
"static",
"function",
"addGroups",
"(",
"\\",
"Aimeos",
"\\",
"MShop",
"\\",
"Context",
"\\",
"Item",
"\\",
"Iface",
"$",
"context",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"GLOBALS",
"[",
"'TYPO3_CONF_VARS'",
"]",
"[",
"'EXTCONF'",
"]",
"["... | Adds the group IDs to the context
@param \Aimeos\MShop\Context\Item\Iface $context Context object
@return \Aimeos\MShop\Context\Item\Iface Modified context object | [
"Adds",
"the",
"group",
"IDs",
"to",
"the",
"context"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Base/Context.php#L312-L332 | train |
aimeos/aimeos-typo3 | Classes/Controller/AbstractController.php | AbstractController.getContext | protected function getContext( $templatePath = 'client/html/templates', $withView = true )
{
$config = Base::getConfig( (array) $this->settings );
if( !isset( self::$context ) )
{
$context = Base::getContext( $config );
$locale = Base::getLocale( $context, $this->request );
$context->setI18n( Base::getI18n( array( $locale->getLanguageId() ), $config->get( 'i18n', array() ) ) );
$context->setLocale( $locale );
self::$context = $context;
}
// Use plugin specific configuration
self::$context->setConfig( $config );
if( $withView === true )
{
$langid = self::$context->getLocale()->getLanguageId();
$paths = self::$aimeos->getCustomPaths( $templatePath );
$view = Base::getView( self::$context, $this->uriBuilder, $paths, $this->request, $langid );
self::$context->setView( $view );
}
return self::$context;
} | php | protected function getContext( $templatePath = 'client/html/templates', $withView = true )
{
$config = Base::getConfig( (array) $this->settings );
if( !isset( self::$context ) )
{
$context = Base::getContext( $config );
$locale = Base::getLocale( $context, $this->request );
$context->setI18n( Base::getI18n( array( $locale->getLanguageId() ), $config->get( 'i18n', array() ) ) );
$context->setLocale( $locale );
self::$context = $context;
}
// Use plugin specific configuration
self::$context->setConfig( $config );
if( $withView === true )
{
$langid = self::$context->getLocale()->getLanguageId();
$paths = self::$aimeos->getCustomPaths( $templatePath );
$view = Base::getView( self::$context, $this->uriBuilder, $paths, $this->request, $langid );
self::$context->setView( $view );
}
return self::$context;
} | [
"protected",
"function",
"getContext",
"(",
"$",
"templatePath",
"=",
"'client/html/templates'",
",",
"$",
"withView",
"=",
"true",
")",
"{",
"$",
"config",
"=",
"Base",
"::",
"getConfig",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"settings",
")",
";",
... | Returns the context item for the frontend
@param string $templatePath Path for retrieving the template paths used in the view
@param boolean $withView True to add view to context object, false for no view
@return \Aimeos\MShop\Context\Item\Iface Context item | [
"Returns",
"the",
"context",
"item",
"for",
"the",
"frontend"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Controller/AbstractController.php#L48-L75 | train |
aimeos/aimeos-typo3 | Classes/Controller/AbstractController.php | AbstractController.getContextBackend | protected function getContextBackend( $templatePath = 'admin/jqadm/templates', $withView = true )
{
if( !isset( $this->contextBE ) )
{
$lang = 'en';
$site = 'default';
if( isset( $GLOBALS['BE_USER']->uc['lang'] ) && $GLOBALS['BE_USER']->uc['lang'] != '' ) {
$lang = $GLOBALS['BE_USER']->uc['lang'];
}
if( $this->request->hasArgument( 'lang' )
&& ( $value = $this->request->getArgument( 'lang' ) ) != ''
) {
$lang = $value;
}
if( $this->request->hasArgument( 'site' )
&& ( $value = $this->request->getArgument( 'site' ) ) != ''
) {
$site = $value;
}
$config = Base::getConfig( (array) $this->settings );
$context = Base::getContext( $config );
$locale = Base::getLocaleBackend( $context, $site );
$context->setLocale( $locale );
$i18n = Base::getI18n( array( $lang, 'en' ), $config->get( 'i18n', array() ) );
$context->setI18n( $i18n );
if( $withView )
{
$paths = self::$aimeos->getCustomPaths( $templatePath );
$view = Base::getView( $context, $this->uriBuilder, $paths, $this->request, $lang, false );
$context->setView( $view );
}
$this->contextBE = $context;
}
return $this->contextBE;
} | php | protected function getContextBackend( $templatePath = 'admin/jqadm/templates', $withView = true )
{
if( !isset( $this->contextBE ) )
{
$lang = 'en';
$site = 'default';
if( isset( $GLOBALS['BE_USER']->uc['lang'] ) && $GLOBALS['BE_USER']->uc['lang'] != '' ) {
$lang = $GLOBALS['BE_USER']->uc['lang'];
}
if( $this->request->hasArgument( 'lang' )
&& ( $value = $this->request->getArgument( 'lang' ) ) != ''
) {
$lang = $value;
}
if( $this->request->hasArgument( 'site' )
&& ( $value = $this->request->getArgument( 'site' ) ) != ''
) {
$site = $value;
}
$config = Base::getConfig( (array) $this->settings );
$context = Base::getContext( $config );
$locale = Base::getLocaleBackend( $context, $site );
$context->setLocale( $locale );
$i18n = Base::getI18n( array( $lang, 'en' ), $config->get( 'i18n', array() ) );
$context->setI18n( $i18n );
if( $withView )
{
$paths = self::$aimeos->getCustomPaths( $templatePath );
$view = Base::getView( $context, $this->uriBuilder, $paths, $this->request, $lang, false );
$context->setView( $view );
}
$this->contextBE = $context;
}
return $this->contextBE;
} | [
"protected",
"function",
"getContextBackend",
"(",
"$",
"templatePath",
"=",
"'admin/jqadm/templates'",
",",
"$",
"withView",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"contextBE",
")",
")",
"{",
"$",
"lang",
"=",
"'en'",
";... | Returns the context item for backend operations
@param array $templatePaths List of paths to the view templates
@param boolean $withView True to add view to context object, false for no view
@return \Aimeos\MShop\Context\Item\Iface Context item | [
"Returns",
"the",
"context",
"item",
"for",
"backend",
"operations"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Controller/AbstractController.php#L85-L128 | train |
aimeos/aimeos-typo3 | Classes/Controller/AbstractController.php | AbstractController.getClientOutput | protected function getClientOutput( $client )
{
$client->setView( $this->getContext()->getView() );
$client->process();
$this->response->addAdditionalHeaderData( (string) $client->getHeader() );
return $client->getBody();
} | php | protected function getClientOutput( $client )
{
$client->setView( $this->getContext()->getView() );
$client->process();
$this->response->addAdditionalHeaderData( (string) $client->getHeader() );
return $client->getBody();
} | [
"protected",
"function",
"getClientOutput",
"(",
"$",
"client",
")",
"{",
"$",
"client",
"->",
"setView",
"(",
"$",
"this",
"->",
"getContext",
"(",
")",
"->",
"getView",
"(",
")",
")",
";",
"$",
"client",
"->",
"process",
"(",
")",
";",
"$",
"this",... | Returns the output of the client and adds the header.
@param \Aimeos\Client\Html\Iface $client Html client object (no type hint to prevent reflection)
@return string HTML code for inserting into the HTML body | [
"Returns",
"the",
"output",
"of",
"the",
"client",
"and",
"adds",
"the",
"header",
"."
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Controller/AbstractController.php#L150-L158 | train |
aimeos/aimeos-typo3 | Classes/Controller/AccountController.php | AccountController.downloadAction | public function downloadAction()
{
$paths = Base::getAimeos()->getCustomPaths( 'client/html' );
$context = $this->getContext();
$view = $context->getView();
$client = \Aimeos\Client\Html::create( $context, 'account/download' );
$client->setView( $view );
$client->process();
$response = $view->response();
$this->response->setStatus( $response->getStatusCode() );
foreach( $response->getHeaders() as $key => $value ) {
$this->response->setHeader( $key, implode( ', ', $value ) );
}
return (string) $response->getBody();
} | php | public function downloadAction()
{
$paths = Base::getAimeos()->getCustomPaths( 'client/html' );
$context = $this->getContext();
$view = $context->getView();
$client = \Aimeos\Client\Html::create( $context, 'account/download' );
$client->setView( $view );
$client->process();
$response = $view->response();
$this->response->setStatus( $response->getStatusCode() );
foreach( $response->getHeaders() as $key => $value ) {
$this->response->setHeader( $key, implode( ', ', $value ) );
}
return (string) $response->getBody();
} | [
"public",
"function",
"downloadAction",
"(",
")",
"{",
"$",
"paths",
"=",
"Base",
"::",
"getAimeos",
"(",
")",
"->",
"getCustomPaths",
"(",
"'client/html'",
")",
";",
"$",
"context",
"=",
"$",
"this",
"->",
"getContext",
"(",
")",
";",
"$",
"view",
"="... | Renders the account download | [
"Renders",
"the",
"account",
"download"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Controller/AccountController.php#L27-L45 | train |
aimeos/aimeos-typo3 | Classes/Controller/AccountController.php | AccountController.historyAction | public function historyAction()
{
$client = \Aimeos\Client\Html::create( $this->getContext(), 'account/history' );
return $this->getClientOutput( $client );
} | php | public function historyAction()
{
$client = \Aimeos\Client\Html::create( $this->getContext(), 'account/history' );
return $this->getClientOutput( $client );
} | [
"public",
"function",
"historyAction",
"(",
")",
"{",
"$",
"client",
"=",
"\\",
"Aimeos",
"\\",
"Client",
"\\",
"Html",
"::",
"create",
"(",
"$",
"this",
"->",
"getContext",
"(",
")",
",",
"'account/history'",
")",
";",
"return",
"$",
"this",
"->",
"ge... | Renders the account history. | [
"Renders",
"the",
"account",
"history",
"."
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Controller/AccountController.php#L51-L55 | train |
aimeos/aimeos-typo3 | Classes/Base/View.php | View.addFormparam | protected static function addFormparam( \Aimeos\MW\View\Iface $view, array $prefixes )
{
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_formparam'] )
&& is_callable( ( $fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_formparam'] ) )
) {
return $fcn( $view, $prefixes );
}
$helper = new \Aimeos\MW\View\Helper\Formparam\Standard( $view, $prefixes );
$view->addHelper( 'formparam', $helper );
return $view;
} | php | protected static function addFormparam( \Aimeos\MW\View\Iface $view, array $prefixes )
{
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_formparam'] )
&& is_callable( ( $fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_formparam'] ) )
) {
return $fcn( $view, $prefixes );
}
$helper = new \Aimeos\MW\View\Helper\Formparam\Standard( $view, $prefixes );
$view->addHelper( 'formparam', $helper );
return $view;
} | [
"protected",
"static",
"function",
"addFormparam",
"(",
"\\",
"Aimeos",
"\\",
"MW",
"\\",
"View",
"\\",
"Iface",
"$",
"view",
",",
"array",
"$",
"prefixes",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"GLOBALS",
"[",
"'TYPO3_CONF_VARS'",
"]",
"[",
"'EXTCONF'... | Adds the "formparam" helper to the view object
@param \Aimeos\MW\View\Iface $view View object
@param array $prefixes List of prefixes for the form name to build multi-dimensional arrays
@return \Aimeos\MW\View\Iface Modified view object | [
"Adds",
"the",
"formparam",
"helper",
"to",
"the",
"view",
"object"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Base/View.php#L133-L145 | train |
aimeos/aimeos-typo3 | Classes/Base/View.php | View.addSession | protected static function addSession( \Aimeos\MW\View\Iface $view, \Aimeos\MW\Session\Iface $session )
{
$helper = new \Aimeos\MW\View\Helper\Session\Standard( $view, $session );
$view->addHelper( 'session', $helper );
return $view;
} | php | protected static function addSession( \Aimeos\MW\View\Iface $view, \Aimeos\MW\Session\Iface $session )
{
$helper = new \Aimeos\MW\View\Helper\Session\Standard( $view, $session );
$view->addHelper( 'session', $helper );
return $view;
} | [
"protected",
"static",
"function",
"addSession",
"(",
"\\",
"Aimeos",
"\\",
"MW",
"\\",
"View",
"\\",
"Iface",
"$",
"view",
",",
"\\",
"Aimeos",
"\\",
"MW",
"\\",
"Session",
"\\",
"Iface",
"$",
"session",
")",
"{",
"$",
"helper",
"=",
"new",
"\\",
"A... | Adds the "session" helper to the view object
@param \Aimeos\MW\View\Iface $view View object
@param \Aimeos\MW\Session\Iface $session Session object
@return \Aimeos\MW\View\Iface Modified view object | [
"Adds",
"the",
"session",
"helper",
"to",
"the",
"view",
"object"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Base/View.php#L249-L255 | train |
aimeos/aimeos-typo3 | Classes/Custom/Composer.php | Composer.install | public static function install( \Composer\Script\Event $event )
{
$repository = $event->getComposer()->getRepositoryManager()->getLocalRepository();
if( ( $t3package = $repository->findPackage( 'aimeos/aimeos-typo3', '*' ) ) === null
&& ( $t3package = $repository->findPackage( 'typo3-ter/aimeos-typo3', '*' ) ) === null
) {
throw new \RuntimeException( 'No installed package "aimeos/aimeos-typo3" or "typo3-ter/aimeos-typo3" found' );
}
$installer = $event->getComposer()->getInstallationManager();
$t3path = $installer->getInstallPath( $t3package );
if( ( $package = $repository->findPackage( 'aimeos/ai-client-html', '*' ) ) !== null )
{
$event->getIO()->write( 'Installing Aimeos public files from HTML client' );
$path = $installer->getInstallPath( $package );
self::copyRecursive( $path . '/client/html/themes', $t3path . '/Resources/Public/Themes' );
}
if( ( $package = $repository->findPackage( 'aimeos/ai-typo3', '*' ) ) !== null )
{
$event->getIO()->write( 'Creating symlink to Aimeos extension directory' );
$path = dirname( $installer->getInstallPath( $package ) );
self::createLink( '../../../../../../' . $path, $t3path . '/Resources/Private/Extensions' );
}
} | php | public static function install( \Composer\Script\Event $event )
{
$repository = $event->getComposer()->getRepositoryManager()->getLocalRepository();
if( ( $t3package = $repository->findPackage( 'aimeos/aimeos-typo3', '*' ) ) === null
&& ( $t3package = $repository->findPackage( 'typo3-ter/aimeos-typo3', '*' ) ) === null
) {
throw new \RuntimeException( 'No installed package "aimeos/aimeos-typo3" or "typo3-ter/aimeos-typo3" found' );
}
$installer = $event->getComposer()->getInstallationManager();
$t3path = $installer->getInstallPath( $t3package );
if( ( $package = $repository->findPackage( 'aimeos/ai-client-html', '*' ) ) !== null )
{
$event->getIO()->write( 'Installing Aimeos public files from HTML client' );
$path = $installer->getInstallPath( $package );
self::copyRecursive( $path . '/client/html/themes', $t3path . '/Resources/Public/Themes' );
}
if( ( $package = $repository->findPackage( 'aimeos/ai-typo3', '*' ) ) !== null )
{
$event->getIO()->write( 'Creating symlink to Aimeos extension directory' );
$path = dirname( $installer->getInstallPath( $package ) );
self::createLink( '../../../../../../' . $path, $t3path . '/Resources/Private/Extensions' );
}
} | [
"public",
"static",
"function",
"install",
"(",
"\\",
"Composer",
"\\",
"Script",
"\\",
"Event",
"$",
"event",
")",
"{",
"$",
"repository",
"=",
"$",
"event",
"->",
"getComposer",
"(",
")",
"->",
"getRepositoryManager",
"(",
")",
"->",
"getLocalRepository",
... | Installs the shop files.
@param \Composer\Script\Event $event Event instance
@throws \RuntimeException If an error occured | [
"Installs",
"the",
"shop",
"files",
"."
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Custom/Composer.php#L26-L54 | train |
aimeos/aimeos-typo3 | Classes/Custom/Composer.php | Composer.copyRecursive | protected static function copyRecursive( $src, $dest )
{
self::createDirectory( $dest );
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator( $src, \RecursiveDirectoryIterator::SKIP_DOTS ),
\RecursiveIteratorIterator::SELF_FIRST
);
foreach( $iterator as $item )
{
$target = $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName();
if( $item->isDir() === false )
{
if( copy( $item, $target ) === false ) {
throw new \RuntimeException( sprintf( 'Unable to copy file "%1$s"', $item ) );
}
}
else
{
self::createDirectory( $target );
}
}
} | php | protected static function copyRecursive( $src, $dest )
{
self::createDirectory( $dest );
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator( $src, \RecursiveDirectoryIterator::SKIP_DOTS ),
\RecursiveIteratorIterator::SELF_FIRST
);
foreach( $iterator as $item )
{
$target = $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName();
if( $item->isDir() === false )
{
if( copy( $item, $target ) === false ) {
throw new \RuntimeException( sprintf( 'Unable to copy file "%1$s"', $item ) );
}
}
else
{
self::createDirectory( $target );
}
}
} | [
"protected",
"static",
"function",
"copyRecursive",
"(",
"$",
"src",
",",
"$",
"dest",
")",
"{",
"self",
"::",
"createDirectory",
"(",
"$",
"dest",
")",
";",
"$",
"iterator",
"=",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"new",
"\\",
"RecursiveDirector... | Copies the source directory recursively to the destination
@param string $src Source directory path
@param string $dest Target directory path
@throws \RuntimeException If an error occured | [
"Copies",
"the",
"source",
"directory",
"recursively",
"to",
"the",
"destination"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Custom/Composer.php#L64-L88 | train |
aimeos/aimeos-typo3 | Classes/Custom/Composer.php | Composer.createLink | protected static function createLink( $source, $target )
{
if( file_exists( $target ) === false && @symlink( $source, $target ) === false )
{
$source = realpath( __DIR__ . '/' . $source );
if( symlink( $source, $target ) === false ) {
throw new \RuntimeException( sprintf( 'Failed to create symlink for "%1$s" to "%2$s"', $source, $target ) );
}
}
} | php | protected static function createLink( $source, $target )
{
if( file_exists( $target ) === false && @symlink( $source, $target ) === false )
{
$source = realpath( __DIR__ . '/' . $source );
if( symlink( $source, $target ) === false ) {
throw new \RuntimeException( sprintf( 'Failed to create symlink for "%1$s" to "%2$s"', $source, $target ) );
}
}
} | [
"protected",
"static",
"function",
"createLink",
"(",
"$",
"source",
",",
"$",
"target",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"target",
")",
"===",
"false",
"&&",
"@",
"symlink",
"(",
"$",
"source",
",",
"$",
"target",
")",
"===",
"false",
"... | Creates a link if it doesn't exist
@param string $source Relative source path
@param string $target Absolute target path | [
"Creates",
"a",
"link",
"if",
"it",
"doesn",
"t",
"exist"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Custom/Composer.php#L115-L125 | train |
aimeos/aimeos-typo3 | Classes/Controller/CheckoutController.php | CheckoutController.confirmAction | public function confirmAction()
{
$context = $this->getContext();
$client = \Aimeos\Client\Html::create( $context, 'checkout/confirm' );
$view = $context->getView();
$param = array_merge( \TYPO3\CMS\Core\Utility\GeneralUtility::_GET(), \TYPO3\CMS\Core\Utility\GeneralUtility::_POST() );
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param );
$view->addHelper( 'param', $helper );
$client->setView( $view );
$client->process();
$this->response->addAdditionalHeaderData( (string) $client->getHeader() );
return $client->getBody();
} | php | public function confirmAction()
{
$context = $this->getContext();
$client = \Aimeos\Client\Html::create( $context, 'checkout/confirm' );
$view = $context->getView();
$param = array_merge( \TYPO3\CMS\Core\Utility\GeneralUtility::_GET(), \TYPO3\CMS\Core\Utility\GeneralUtility::_POST() );
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param );
$view->addHelper( 'param', $helper );
$client->setView( $view );
$client->process();
$this->response->addAdditionalHeaderData( (string) $client->getHeader() );
return $client->getBody();
} | [
"public",
"function",
"confirmAction",
"(",
")",
"{",
"$",
"context",
"=",
"$",
"this",
"->",
"getContext",
"(",
")",
";",
"$",
"client",
"=",
"\\",
"Aimeos",
"\\",
"Client",
"\\",
"Html",
"::",
"create",
"(",
"$",
"context",
",",
"'checkout/confirm'",
... | Processes requests and renders the checkout confirmation. | [
"Processes",
"requests",
"and",
"renders",
"the",
"checkout",
"confirmation",
"."
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Controller/CheckoutController.php#L37-L53 | train |
aimeos/aimeos-typo3 | Classes/Scheduler/Base.php | Base.execute | public static function execute( array $conf, array $jobs, $sites )
{
$aimeos = Aimeos\Base::getAimeos();
$context = self::getContext( $conf );
$process = $context->getProcess();
// Reset before child processes are spawned to avoid lost DB connections afterwards (TYPO3 9.4 and above)
if( method_exists( '\TYPO3\CMS\Core\Database\ConnectionPool', 'resetConnections' ) ) {
GeneralUtility::makeInstance( 'TYPO3\CMS\Core\Database\ConnectionPool' )->resetConnections();
}
$manager = \Aimeos\MShop::create( $context, 'locale' );
foreach( self::getSiteItems( $context, $sites ) as $siteItem )
{
$localeItem = $manager->bootstrap( $siteItem->getCode(), '', '', false );
$localeItem->setLanguageId( null );
$localeItem->setCurrencyId( null );
$context->setLocale( $localeItem );
foreach( $jobs as $jobname )
{
$fcn = function( $context, $aimeos, $jobname ) {
\Aimeos\Controller\Jobs::create( $context, $aimeos, $jobname )->run();
};
$process->start( $fcn, [$context, $aimeos, $jobname], true );
}
}
} | php | public static function execute( array $conf, array $jobs, $sites )
{
$aimeos = Aimeos\Base::getAimeos();
$context = self::getContext( $conf );
$process = $context->getProcess();
// Reset before child processes are spawned to avoid lost DB connections afterwards (TYPO3 9.4 and above)
if( method_exists( '\TYPO3\CMS\Core\Database\ConnectionPool', 'resetConnections' ) ) {
GeneralUtility::makeInstance( 'TYPO3\CMS\Core\Database\ConnectionPool' )->resetConnections();
}
$manager = \Aimeos\MShop::create( $context, 'locale' );
foreach( self::getSiteItems( $context, $sites ) as $siteItem )
{
$localeItem = $manager->bootstrap( $siteItem->getCode(), '', '', false );
$localeItem->setLanguageId( null );
$localeItem->setCurrencyId( null );
$context->setLocale( $localeItem );
foreach( $jobs as $jobname )
{
$fcn = function( $context, $aimeos, $jobname ) {
\Aimeos\Controller\Jobs::create( $context, $aimeos, $jobname )->run();
};
$process->start( $fcn, [$context, $aimeos, $jobname], true );
}
}
} | [
"public",
"static",
"function",
"execute",
"(",
"array",
"$",
"conf",
",",
"array",
"$",
"jobs",
",",
"$",
"sites",
")",
"{",
"$",
"aimeos",
"=",
"Aimeos",
"\\",
"Base",
"::",
"getAimeos",
"(",
")",
";",
"$",
"context",
"=",
"self",
"::",
"getContext... | Execute the list of jobs for the given sites
@param array $conf Multi-dimensional array of configuration options
@param array $jobs List of job names
@param string $sites List of site names | [
"Execute",
"the",
"list",
"of",
"jobs",
"for",
"the",
"given",
"sites"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Scheduler/Base.php#L32-L62 | train |
aimeos/aimeos-typo3 | Classes/Scheduler/Base.php | Base.initFrontend | public static function initFrontend( $pageid )
{
if( !is_object( $GLOBALS['TT'] ) )
{
$GLOBALS['TT'] = GeneralUtility::makeInstance( 'TYPO3\CMS\Core\TimeTracker\TimeTracker' );
$GLOBALS['TT']->start();
}
$page = GeneralUtility::makeInstance( 'TYPO3\CMS\Frontend\Page\PageRepository' );
$page->init( true );
$name = 'TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController';
$GLOBALS['TSFE'] = GeneralUtility::makeInstance( $name, $GLOBALS['TYPO3_CONF_VARS'], $pageid, 0 );
$GLOBALS['TSFE']->connectToDB();
$GLOBALS['TSFE']->initFEuser();
$GLOBALS['TSFE']->no_cache = true;
$GLOBALS['TSFE']->sys_page = $page;
$GLOBALS['TSFE']->rootLine = $page->getRootLine( $pageid );
$GLOBALS['TSFE']->determineId();
$GLOBALS['TSFE']->initTemplate();
$GLOBALS['TSFE']->getConfigArray();
$rootline = BackendUtility::BEgetRootLine( $pageid );
$host = BackendUtility::firstDomainRecord( $rootline );
if( $host == null && ( $host = getenv( 'SCHEDULER_HTTP_HOST' ) ) == null ) {
throw new \RuntimeException( 'No domain record in root page or SCHEDULER_HTTP_HOST env variable found' );
}
$_SERVER['HTTP_HOST'] = $host;
GeneralUtility::flushInternalRuntimeCaches();
} | php | public static function initFrontend( $pageid )
{
if( !is_object( $GLOBALS['TT'] ) )
{
$GLOBALS['TT'] = GeneralUtility::makeInstance( 'TYPO3\CMS\Core\TimeTracker\TimeTracker' );
$GLOBALS['TT']->start();
}
$page = GeneralUtility::makeInstance( 'TYPO3\CMS\Frontend\Page\PageRepository' );
$page->init( true );
$name = 'TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController';
$GLOBALS['TSFE'] = GeneralUtility::makeInstance( $name, $GLOBALS['TYPO3_CONF_VARS'], $pageid, 0 );
$GLOBALS['TSFE']->connectToDB();
$GLOBALS['TSFE']->initFEuser();
$GLOBALS['TSFE']->no_cache = true;
$GLOBALS['TSFE']->sys_page = $page;
$GLOBALS['TSFE']->rootLine = $page->getRootLine( $pageid );
$GLOBALS['TSFE']->determineId();
$GLOBALS['TSFE']->initTemplate();
$GLOBALS['TSFE']->getConfigArray();
$rootline = BackendUtility::BEgetRootLine( $pageid );
$host = BackendUtility::firstDomainRecord( $rootline );
if( $host == null && ( $host = getenv( 'SCHEDULER_HTTP_HOST' ) ) == null ) {
throw new \RuntimeException( 'No domain record in root page or SCHEDULER_HTTP_HOST env variable found' );
}
$_SERVER['HTTP_HOST'] = $host;
GeneralUtility::flushInternalRuntimeCaches();
} | [
"public",
"static",
"function",
"initFrontend",
"(",
"$",
"pageid",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"GLOBALS",
"[",
"'TT'",
"]",
")",
")",
"{",
"$",
"GLOBALS",
"[",
"'TT'",
"]",
"=",
"GeneralUtility",
"::",
"makeInstance",
"(",
"'TYPO3... | Initializes the frontend to render frontend links in scheduler tasks
@param integer $pageid Page ID for the frontend configuration | [
"Initializes",
"the",
"frontend",
"to",
"render",
"frontend",
"links",
"in",
"scheduler",
"tasks"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Scheduler/Base.php#L164-L195 | train |
aimeos/aimeos-typo3 | Classes/Scheduler/Provider/AbstractProvider.php | AbstractProvider.getAvailableSites | protected function getAvailableSites()
{
$manager = \Aimeos\MShop::create( Scheduler\Base::getContext(), 'locale/site' );
$search = $manager->createSearch();
$search->setConditions( $search->compare( '==', 'locale.site.level', 0 ) );
$search->setSortations( array( $search->sort( '+', 'locale.site.label' ) ) );
$sites = $manager->searchItems( $search );
foreach( $sites as $id => $siteItem ) {
$sites[$id] = $manager->getTree( $id, array(), \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
}
return $sites;
} | php | protected function getAvailableSites()
{
$manager = \Aimeos\MShop::create( Scheduler\Base::getContext(), 'locale/site' );
$search = $manager->createSearch();
$search->setConditions( $search->compare( '==', 'locale.site.level', 0 ) );
$search->setSortations( array( $search->sort( '+', 'locale.site.label' ) ) );
$sites = $manager->searchItems( $search );
foreach( $sites as $id => $siteItem ) {
$sites[$id] = $manager->getTree( $id, array(), \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
}
return $sites;
} | [
"protected",
"function",
"getAvailableSites",
"(",
")",
"{",
"$",
"manager",
"=",
"\\",
"Aimeos",
"\\",
"MShop",
"::",
"create",
"(",
"Scheduler",
"\\",
"Base",
"::",
"getContext",
"(",
")",
",",
"'locale/site'",
")",
";",
"$",
"search",
"=",
"$",
"manag... | Returns the list of site trees.
@return array Associative list of items and children implementing \Aimeos\MShop\Locale\Item\Site\Iface | [
"Returns",
"the",
"list",
"of",
"site",
"trees",
"."
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Scheduler/Provider/AbstractProvider.php#L172-L187 | train |
aimeos/aimeos-typo3 | Classes/Scheduler/Provider/AbstractProvider.php | AbstractProvider.getSiteOptions | protected function getSiteOptions( array $siteItems, array $selected, $level )
{
$html = '';
$prefix = str_repeat( '-', $level ) . ' ';
foreach( $siteItems as $item )
{
$active = ( in_array( $item->getCode(), $selected ) ? 'selected="selected"' : '' );
$disabled = ( $item->getStatus() > 0 ? '' : 'disabled="disabled"' );
$string = '<option value="%1$s" %2$s %3$s>%4$s</option>';
$html .= sprintf( $string, $item->getCode(), $active, $disabled, $prefix . $item->getLabel() );
$html .= $this->getSiteOptions( $item->getChildren(), $selected, $level+1 );
}
return $html;
} | php | protected function getSiteOptions( array $siteItems, array $selected, $level )
{
$html = '';
$prefix = str_repeat( '-', $level ) . ' ';
foreach( $siteItems as $item )
{
$active = ( in_array( $item->getCode(), $selected ) ? 'selected="selected"' : '' );
$disabled = ( $item->getStatus() > 0 ? '' : 'disabled="disabled"' );
$string = '<option value="%1$s" %2$s %3$s>%4$s</option>';
$html .= sprintf( $string, $item->getCode(), $active, $disabled, $prefix . $item->getLabel() );
$html .= $this->getSiteOptions( $item->getChildren(), $selected, $level+1 );
}
return $html;
} | [
"protected",
"function",
"getSiteOptions",
"(",
"array",
"$",
"siteItems",
",",
"array",
"$",
"selected",
",",
"$",
"level",
")",
"{",
"$",
"html",
"=",
"''",
";",
"$",
"prefix",
"=",
"str_repeat",
"(",
"'-'",
",",
"$",
"level",
")",
".",
"' '",
";",... | Returns the HTML code for the select control.
The method adds every site and its children recursively.
@param array $siteItems List of items implementing \Aimeos\MShop\Locale\Item\Site\Iface
@param array $selected List of site codes that were previously selected by the user
@param integer $level Nesting level of the sites (should start with 0)
@return string HTML code with <option> tags for the select box | [
"Returns",
"the",
"HTML",
"code",
"for",
"the",
"select",
"control",
".",
"The",
"method",
"adds",
"every",
"site",
"and",
"its",
"children",
"recursively",
"."
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Scheduler/Provider/AbstractProvider.php#L199-L215 | train |
aimeos/aimeos-typo3 | Classes/Scheduler/Provider/AbstractProvider.php | AbstractProvider.getControllerOptions | protected function getControllerOptions( array $selected )
{
$html = '';
$aimeos = Base::getAimeos();
$context = Scheduler\Base::getContext();
$cntlPaths = $aimeos->getCustomPaths( 'controller/jobs' );
$langid = 'en';
if( isset( $GLOBALS['BE_USER']->uc['lang'] ) && $GLOBALS['BE_USER']->uc['lang'] != '' ) {
$langid = $GLOBALS['BE_USER']->uc['lang'];
}
$localeItem = \Aimeos\MShop::create( $context, 'locale' )->createItem();
$localeItem->setLanguageId( $langid );
$context->setLocale( $localeItem );
$controllers = \Aimeos\Controller\Jobs::get( $context, $aimeos, $cntlPaths );
foreach( $controllers as $name => $controller )
{
$active = ( in_array( $name, $selected ) ? 'selected="selected"' : '' );
$title = htmlspecialchars( $controller->getDescription(), ENT_QUOTES, 'UTF-8' );
$cntl = htmlspecialchars( $controller->getName(), ENT_QUOTES, 'UTF-8' );
$name = htmlspecialchars( $name, ENT_QUOTES, 'UTF-8' );
$html .= sprintf( '<option value="%1$s" title="%2$s" %3$s>%4$s</option>', $name, $title, $active, $cntl );
}
return $html;
} | php | protected function getControllerOptions( array $selected )
{
$html = '';
$aimeos = Base::getAimeos();
$context = Scheduler\Base::getContext();
$cntlPaths = $aimeos->getCustomPaths( 'controller/jobs' );
$langid = 'en';
if( isset( $GLOBALS['BE_USER']->uc['lang'] ) && $GLOBALS['BE_USER']->uc['lang'] != '' ) {
$langid = $GLOBALS['BE_USER']->uc['lang'];
}
$localeItem = \Aimeos\MShop::create( $context, 'locale' )->createItem();
$localeItem->setLanguageId( $langid );
$context->setLocale( $localeItem );
$controllers = \Aimeos\Controller\Jobs::get( $context, $aimeos, $cntlPaths );
foreach( $controllers as $name => $controller )
{
$active = ( in_array( $name, $selected ) ? 'selected="selected"' : '' );
$title = htmlspecialchars( $controller->getDescription(), ENT_QUOTES, 'UTF-8' );
$cntl = htmlspecialchars( $controller->getName(), ENT_QUOTES, 'UTF-8' );
$name = htmlspecialchars( $name, ENT_QUOTES, 'UTF-8' );
$html .= sprintf( '<option value="%1$s" title="%2$s" %3$s>%4$s</option>', $name, $title, $active, $cntl );
}
return $html;
} | [
"protected",
"function",
"getControllerOptions",
"(",
"array",
"$",
"selected",
")",
"{",
"$",
"html",
"=",
"''",
";",
"$",
"aimeos",
"=",
"Base",
"::",
"getAimeos",
"(",
")",
";",
"$",
"context",
"=",
"Scheduler",
"\\",
"Base",
"::",
"getContext",
"(",
... | Returns the HTML code for the controller control.
@param array $selected List of site codes that were previously selected by the user
@return string HTML code with <option> tags for the select box | [
"Returns",
"the",
"HTML",
"code",
"for",
"the",
"controller",
"control",
"."
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Scheduler/Provider/AbstractProvider.php#L224-L253 | train |
aimeos/aimeos-typo3 | class.ext_update.php | ext_update.main | public function main()
{
ob_start();
$exectimeStart = microtime( true );
if( ( $result = $this->checkEnvironment() ) !== null ) {
return $result;
}
try
{
\Aimeos\Aimeos\Setup::execute();
$output = ob_get_contents();
}
catch( Exception $e )
{
$output = ob_get_contents();
$output .= PHP_EOL . $e->getMessage();
$output .= PHP_EOL . $e->getTraceAsString();
}
ob_end_clean();
return '<pre>' . $output . '</pre>' . PHP_EOL .
sprintf( "Setup process lasted %1\$f sec</br>\n", (microtime( true ) - $exectimeStart) );
} | php | public function main()
{
ob_start();
$exectimeStart = microtime( true );
if( ( $result = $this->checkEnvironment() ) !== null ) {
return $result;
}
try
{
\Aimeos\Aimeos\Setup::execute();
$output = ob_get_contents();
}
catch( Exception $e )
{
$output = ob_get_contents();
$output .= PHP_EOL . $e->getMessage();
$output .= PHP_EOL . $e->getTraceAsString();
}
ob_end_clean();
return '<pre>' . $output . '</pre>' . PHP_EOL .
sprintf( "Setup process lasted %1\$f sec</br>\n", (microtime( true ) - $exectimeStart) );
} | [
"public",
"function",
"main",
"(",
")",
"{",
"ob_start",
"(",
")",
";",
"$",
"exectimeStart",
"=",
"microtime",
"(",
"true",
")",
";",
"if",
"(",
"(",
"$",
"result",
"=",
"$",
"this",
"->",
"checkEnvironment",
"(",
")",
")",
"!==",
"null",
")",
"{"... | Main update method called by the extension manager.
@return string Messages | [
"Main",
"update",
"method",
"called",
"by",
"the",
"extension",
"manager",
"."
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/class.ext_update.php#L46-L72 | train |
aimeos/aimeos-typo3 | class.ext_update.php | ext_update.checkEnvironment | protected function checkEnvironment()
{
if( version_compare( TYPO3_version, '9.0', '<' ) ) {
return;
}
$objectManager = GeneralUtility::makeInstance( ObjectManager::class );
$connectionPool = $objectManager->get( TYPO3\CMS\Core\Database\ConnectionPool::class );
$connection = $connectionPool->getQueryBuilderForTable( 'fe_user' )->getConnection();
$params = $connection->getParams();
if( strpos( $connection->getServerVersion(), 'MySQL' ) === false ) {
return;
}
// MariaDB might get identified as a 'MySQL 5.5.5' for some reason
$result = $connection->prepare('SELECT version()');
$result->execute();
$rows = $result->fetchAll();
if( !isset( $rows[0]['version()'] ) ) {
return;
}
$version = $rows[0]['version()']; // Something like '10.1.29-MariaDB' or '5.6.33-0ubuntu0'
// Only MySQL < 5.7 and MariaDB < 10.2 don't work
if( ( strpos( $version, 'MariaDB' ) !== false && version_compare( $version, '10.2', '>=' ) )
|| version_compare( $version, '5.7', '>=' )
) {
return;
}
// MySQL < 5.7 and utf8mb4 charset doesn't work due to missing long index support
if( isset( $params['tableoptions']['charset'] ) && $params['tableoptions']['charset'] !== 'utf8mb4' ) {
return;
}
// Retrieve the name of the connection (which is not part of the connection class)
foreach ( $connectionPool->getConnectionNames() as $name )
{
if( $connectionPool->getConnectionByName( $name ) === $connection ) {
break;
}
}
$msg = $objectManager->get(
FlashMessage::class,
LocalizationUtility::translate( 'LLL:EXT:aimeos/Resources/Private/Language/admin.xlf:t3_9x_config_error_text', 'aimeos', [$name] ),
LocalizationUtility::translate( 'LLL:EXT:aimeos/Resources/Private/Language/admin.xlf:t3_9x_config_error_header' ),
FlashMessage::ERROR
);
return $objectManager->get( FlashMessageRendererResolver::class )->resolve()->render( [$msg] ) .
LocalizationUtility::translate( 'LLL:EXT:aimeos/Resources/Private/Language/admin.xlf:t3_9x_config_error_remedy' );
} | php | protected function checkEnvironment()
{
if( version_compare( TYPO3_version, '9.0', '<' ) ) {
return;
}
$objectManager = GeneralUtility::makeInstance( ObjectManager::class );
$connectionPool = $objectManager->get( TYPO3\CMS\Core\Database\ConnectionPool::class );
$connection = $connectionPool->getQueryBuilderForTable( 'fe_user' )->getConnection();
$params = $connection->getParams();
if( strpos( $connection->getServerVersion(), 'MySQL' ) === false ) {
return;
}
// MariaDB might get identified as a 'MySQL 5.5.5' for some reason
$result = $connection->prepare('SELECT version()');
$result->execute();
$rows = $result->fetchAll();
if( !isset( $rows[0]['version()'] ) ) {
return;
}
$version = $rows[0]['version()']; // Something like '10.1.29-MariaDB' or '5.6.33-0ubuntu0'
// Only MySQL < 5.7 and MariaDB < 10.2 don't work
if( ( strpos( $version, 'MariaDB' ) !== false && version_compare( $version, '10.2', '>=' ) )
|| version_compare( $version, '5.7', '>=' )
) {
return;
}
// MySQL < 5.7 and utf8mb4 charset doesn't work due to missing long index support
if( isset( $params['tableoptions']['charset'] ) && $params['tableoptions']['charset'] !== 'utf8mb4' ) {
return;
}
// Retrieve the name of the connection (which is not part of the connection class)
foreach ( $connectionPool->getConnectionNames() as $name )
{
if( $connectionPool->getConnectionByName( $name ) === $connection ) {
break;
}
}
$msg = $objectManager->get(
FlashMessage::class,
LocalizationUtility::translate( 'LLL:EXT:aimeos/Resources/Private/Language/admin.xlf:t3_9x_config_error_text', 'aimeos', [$name] ),
LocalizationUtility::translate( 'LLL:EXT:aimeos/Resources/Private/Language/admin.xlf:t3_9x_config_error_header' ),
FlashMessage::ERROR
);
return $objectManager->get( FlashMessageRendererResolver::class )->resolve()->render( [$msg] ) .
LocalizationUtility::translate( 'LLL:EXT:aimeos/Resources/Private/Language/admin.xlf:t3_9x_config_error_remedy' );
} | [
"protected",
"function",
"checkEnvironment",
"(",
")",
"{",
"if",
"(",
"version_compare",
"(",
"TYPO3_version",
",",
"'9.0'",
",",
"'<'",
")",
")",
"{",
"return",
";",
"}",
"$",
"objectManager",
"=",
"GeneralUtility",
"::",
"makeInstance",
"(",
"ObjectManager"... | Check the environment.
TYPO3 9.5 and MySql 5.6 or MariaDB 10.1 might make problems.
@return string|null A possible return message, stating what went wrong, if anything at all | [
"Check",
"the",
"environment",
"."
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/class.ext_update.php#L82-L137 | train |
aimeos/aimeos-typo3 | Classes/Setup.php | Setup.execute | public static function execute()
{
ini_set( 'max_execution_time', 0 );
$aimeos = \Aimeos\Aimeos\Base::getAimeos();
$sitecode = \Aimeos\Aimeos\Base::getExtConfig( 'siteCode', 'default' );
$siteTpl = \Aimeos\Aimeos\Base::getExtConfig( 'siteTpl', 'default' );
$taskPaths = $aimeos->getSetupPaths( $siteTpl );
$ctx = self::getContext();
$dbm = $ctx->getDatabaseManager();
$config = $ctx->getConfig();
$config->set( 'setup/site', $sitecode );
$dbconfig = $config->get( 'resource', array() );
foreach( $dbconfig as $rname => $dbconf )
{
if( strncmp( $rname, 'db', 2 ) !== 0 ) {
unset( $dbconfig[$rname] );
} else {
$config->set( "resource/$rname/limit", 3 );
}
}
$class = \TYPO3\CMS\Extbase\Object\ObjectManager::class;
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( $class );
if( class_exists( '\TYPO3\CMS\Core\Configuration\ExtensionConfiguration' ) )
{
$object = $objectManager->get( 'TYPO3\CMS\Core\Configuration\ExtensionConfiguration' ); // TYPO3 9
$demo = $object->get( 'aimeos', 'useDemoData' );
}
else
{
$object = $objectManager->get( 'TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility' ); // TYPO3 7+8
$conf = $object->convertValuedToNestedConfiguration( $object->getCurrentConfiguration( 'aimeos' ) );
$demo = ( isset( $conf['useDemoData'] ) ? $conf['useDemoData'] : '' );
}
$local = array( 'setup' => array( 'default' => array( 'demo' => (string) $demo ) ) );
$ctx->setConfig( new \Aimeos\MW\Config\Decorator\Memory( $config, $local ) );
$manager = new \Aimeos\MW\Setup\Manager\Multiple( $dbm, $dbconfig, $taskPaths, $ctx );
$manager->migrate();
if( \Aimeos\Aimeos\Base::getExtConfig( 'cleanDb', 1 ) == 1 ) {
$manager->clean();
}
if( class_exists( '\TYPO3\CMS\Core\Configuration\ExtensionConfiguration' ) )
{
$object->set( 'aimeos', 'useDemoData', '' );
}
else
{
$conf['useDemoData'] = '';
$object->writeConfiguration( $conf, 'aimeos' );
}
} | php | public static function execute()
{
ini_set( 'max_execution_time', 0 );
$aimeos = \Aimeos\Aimeos\Base::getAimeos();
$sitecode = \Aimeos\Aimeos\Base::getExtConfig( 'siteCode', 'default' );
$siteTpl = \Aimeos\Aimeos\Base::getExtConfig( 'siteTpl', 'default' );
$taskPaths = $aimeos->getSetupPaths( $siteTpl );
$ctx = self::getContext();
$dbm = $ctx->getDatabaseManager();
$config = $ctx->getConfig();
$config->set( 'setup/site', $sitecode );
$dbconfig = $config->get( 'resource', array() );
foreach( $dbconfig as $rname => $dbconf )
{
if( strncmp( $rname, 'db', 2 ) !== 0 ) {
unset( $dbconfig[$rname] );
} else {
$config->set( "resource/$rname/limit", 3 );
}
}
$class = \TYPO3\CMS\Extbase\Object\ObjectManager::class;
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( $class );
if( class_exists( '\TYPO3\CMS\Core\Configuration\ExtensionConfiguration' ) )
{
$object = $objectManager->get( 'TYPO3\CMS\Core\Configuration\ExtensionConfiguration' ); // TYPO3 9
$demo = $object->get( 'aimeos', 'useDemoData' );
}
else
{
$object = $objectManager->get( 'TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility' ); // TYPO3 7+8
$conf = $object->convertValuedToNestedConfiguration( $object->getCurrentConfiguration( 'aimeos' ) );
$demo = ( isset( $conf['useDemoData'] ) ? $conf['useDemoData'] : '' );
}
$local = array( 'setup' => array( 'default' => array( 'demo' => (string) $demo ) ) );
$ctx->setConfig( new \Aimeos\MW\Config\Decorator\Memory( $config, $local ) );
$manager = new \Aimeos\MW\Setup\Manager\Multiple( $dbm, $dbconfig, $taskPaths, $ctx );
$manager->migrate();
if( \Aimeos\Aimeos\Base::getExtConfig( 'cleanDb', 1 ) == 1 ) {
$manager->clean();
}
if( class_exists( '\TYPO3\CMS\Core\Configuration\ExtensionConfiguration' ) )
{
$object->set( 'aimeos', 'useDemoData', '' );
}
else
{
$conf['useDemoData'] = '';
$object->writeConfiguration( $conf, 'aimeos' );
}
} | [
"public",
"static",
"function",
"execute",
"(",
")",
"{",
"ini_set",
"(",
"'max_execution_time'",
",",
"0",
")",
";",
"$",
"aimeos",
"=",
"\\",
"Aimeos",
"\\",
"Aimeos",
"\\",
"Base",
"::",
"getAimeos",
"(",
")",
";",
"$",
"sitecode",
"=",
"\\",
"Aimeo... | Executes the setup tasks for updating the database.
The setup tasks print their information directly to the standard output.
To avoid this, it's necessary to use the output buffering handler
(ob_start(), ob_get_contents() and ob_end_clean()).
@param string|null $extname Installed extension name | [
"Executes",
"the",
"setup",
"tasks",
"for",
"updating",
"the",
"database",
"."
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Setup.php#L39-L103 | train |
aimeos/aimeos-typo3 | Classes/Setup.php | Setup.schema | public function schema( array $sql )
{
$ctx = self::getContext();
$dbm = $ctx->getDatabaseManager();
$conn = $dbm->acquire();
try
{
$tables = [];
foreach( ['fe_users_', 'madmin_', 'mshop_'] as $prefix )
{
$result = $conn->create( 'SHOW TABLES like \'' . $prefix . '%\'' )->execute();
while( ( $row = $result->fetch( \Aimeos\MW\DB\Result\Base::FETCH_NUM ) ) !== false ) {
$tables[] = $row[0];
}
}
foreach( $tables as $table )
{
$result = $conn->create( 'SHOW CREATE TABLE ' . $table )->execute();
while( ( $row = $result->fetch( \Aimeos\MW\DB\Result\Base::FETCH_NUM ) ) !== false )
{
$str = preg_replace( '/,[\n ]*CONSTRAINT.+CASCADE/', '', $row[1] );
$str = str_replace( '"', '`', $str );
$sql[] = $str . ";\n";
}
}
$dbm->release( $conn );
}
catch( \Exception $e )
{
$dbm->release( $conn );
}
return ['sqlString' => $sql ];
} | php | public function schema( array $sql )
{
$ctx = self::getContext();
$dbm = $ctx->getDatabaseManager();
$conn = $dbm->acquire();
try
{
$tables = [];
foreach( ['fe_users_', 'madmin_', 'mshop_'] as $prefix )
{
$result = $conn->create( 'SHOW TABLES like \'' . $prefix . '%\'' )->execute();
while( ( $row = $result->fetch( \Aimeos\MW\DB\Result\Base::FETCH_NUM ) ) !== false ) {
$tables[] = $row[0];
}
}
foreach( $tables as $table )
{
$result = $conn->create( 'SHOW CREATE TABLE ' . $table )->execute();
while( ( $row = $result->fetch( \Aimeos\MW\DB\Result\Base::FETCH_NUM ) ) !== false )
{
$str = preg_replace( '/,[\n ]*CONSTRAINT.+CASCADE/', '', $row[1] );
$str = str_replace( '"', '`', $str );
$sql[] = $str . ";\n";
}
}
$dbm->release( $conn );
}
catch( \Exception $e )
{
$dbm->release( $conn );
}
return ['sqlString' => $sql ];
} | [
"public",
"function",
"schema",
"(",
"array",
"$",
"sql",
")",
"{",
"$",
"ctx",
"=",
"self",
"::",
"getContext",
"(",
")",
";",
"$",
"dbm",
"=",
"$",
"ctx",
"->",
"getDatabaseManager",
"(",
")",
";",
"$",
"conn",
"=",
"$",
"dbm",
"->",
"acquire",
... | Executes the setup tasks if extension is installed.
@param string|null $extname Installed extension name | [
"Executes",
"the",
"setup",
"tasks",
"if",
"extension",
"is",
"installed",
"."
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Setup.php#L111-L152 | train |
aimeos/aimeos-typo3 | Classes/Setup.php | Setup.signal | public static function signal( $extname = null )
{
if( $extname === 'aimeos' && \Aimeos\Aimeos\Base::getExtConfig( 'autoSetup', true ) ) {
self::execute();
}
} | php | public static function signal( $extname = null )
{
if( $extname === 'aimeos' && \Aimeos\Aimeos\Base::getExtConfig( 'autoSetup', true ) ) {
self::execute();
}
} | [
"public",
"static",
"function",
"signal",
"(",
"$",
"extname",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"extname",
"===",
"'aimeos'",
"&&",
"\\",
"Aimeos",
"\\",
"Aimeos",
"\\",
"Base",
"::",
"getExtConfig",
"(",
"'autoSetup'",
",",
"true",
")",
")",
"{"... | Update schema if extension is installed
@param string|null $extname Installed extension name | [
"Update",
"schema",
"if",
"extension",
"is",
"installed"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Setup.php#L169-L174 | train |
aimeos/aimeos-typo3 | Classes/Setup.php | Setup.getContext | protected static function getContext()
{
$ctx = new \Aimeos\MShop\Context\Item\Typo3();
$conf = \Aimeos\Aimeos\Base::getConfig();
$ctx->setConfig( $conf );
$ctx->setDatabaseManager( new \Aimeos\MW\DB\Manager\DBAL( $conf ) );
$ctx->setLogger( new \Aimeos\MW\Logger\Errorlog( \Aimeos\MW\Logger\Base::INFO ) );
$ctx->setSession( new \Aimeos\MW\Session\None() );
$ctx->setCache( new \Aimeos\MW\Cache\None() );
// Reset before child processes are spawned to avoid lost DB connections afterwards (TYPO3 9.4 and above)
if ( php_sapi_name() === 'cli' && class_exists( '\TYPO3\CMS\Core\Database\ConnectionPool' )
&& method_exists( '\TYPO3\CMS\Core\Database\ConnectionPool', 'resetConnections' ) )
{
$ctx->setProcess( new \Aimeos\MW\Process\Pcntl( \Aimeos\Aimeos\Base::getExtConfig( 'pcntlMax', 4 ) ) );
} else {
$ctx->setProcess( new \Aimeos\MW\Process\None() );
}
if( class_exists( '\TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory' ) ) // TYPO3 9+
{
$factory = GeneralUtility::makeInstance( 'TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory' );
$ctx->setHasherTypo3( $factory->getDefaultHashInstance( 'FE' ) );
}
elseif( class_exists( '\TYPO3\CMS\Saltedpasswords\Salt\SaltFactory' ) ) // TYPO3 7/8
{
$ctx->setHasherTypo3( \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getSaltingInstance() );
}
return $ctx;
} | php | protected static function getContext()
{
$ctx = new \Aimeos\MShop\Context\Item\Typo3();
$conf = \Aimeos\Aimeos\Base::getConfig();
$ctx->setConfig( $conf );
$ctx->setDatabaseManager( new \Aimeos\MW\DB\Manager\DBAL( $conf ) );
$ctx->setLogger( new \Aimeos\MW\Logger\Errorlog( \Aimeos\MW\Logger\Base::INFO ) );
$ctx->setSession( new \Aimeos\MW\Session\None() );
$ctx->setCache( new \Aimeos\MW\Cache\None() );
// Reset before child processes are spawned to avoid lost DB connections afterwards (TYPO3 9.4 and above)
if ( php_sapi_name() === 'cli' && class_exists( '\TYPO3\CMS\Core\Database\ConnectionPool' )
&& method_exists( '\TYPO3\CMS\Core\Database\ConnectionPool', 'resetConnections' ) )
{
$ctx->setProcess( new \Aimeos\MW\Process\Pcntl( \Aimeos\Aimeos\Base::getExtConfig( 'pcntlMax', 4 ) ) );
} else {
$ctx->setProcess( new \Aimeos\MW\Process\None() );
}
if( class_exists( '\TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory' ) ) // TYPO3 9+
{
$factory = GeneralUtility::makeInstance( 'TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory' );
$ctx->setHasherTypo3( $factory->getDefaultHashInstance( 'FE' ) );
}
elseif( class_exists( '\TYPO3\CMS\Saltedpasswords\Salt\SaltFactory' ) ) // TYPO3 7/8
{
$ctx->setHasherTypo3( \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getSaltingInstance() );
}
return $ctx;
} | [
"protected",
"static",
"function",
"getContext",
"(",
")",
"{",
"$",
"ctx",
"=",
"new",
"\\",
"Aimeos",
"\\",
"MShop",
"\\",
"Context",
"\\",
"Item",
"\\",
"Typo3",
"(",
")",
";",
"$",
"conf",
"=",
"\\",
"Aimeos",
"\\",
"Aimeos",
"\\",
"Base",
"::",
... | Returns a new context object.
@return MShop_Context_Item_Interface Context object | [
"Returns",
"a",
"new",
"context",
"object",
"."
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Setup.php#L182-L214 | train |
aimeos/aimeos-typo3 | Classes/Custom/Wizicon.php | Wizicon.proc | public function proc( $wizardItems )
{
$path = ExtensionManagementUtility::extPath( 'aimeos' );
$relpath = ExtensionManagementUtility::siteRelPath( 'aimeos' );
$langfile = $path . 'Resources/Private/Language/extension.xlf';
$languageFactory = GeneralUtility::makeInstance( 'TYPO3\CMS\Core\Localization\LocalizationFactory' );
$xml = $languageFactory->getParsedData( $langfile, $GLOBALS['LANG']->lang, '', 0 );
$wizardItems['plugins_tx_aimeos'] = array(
'icon' => $relpath . 'Resources/Public/Icons/Extension.svg',
'title' => $GLOBALS['LANG']->getLLL( 'ext-wizard-title', $xml ),
'description' => $GLOBALS['LANG']->getLLL( 'ext-wizard-description', $xml ),
'params' => '&defVals[tt_content][CType]=list'
);
return $wizardItems;
} | php | public function proc( $wizardItems )
{
$path = ExtensionManagementUtility::extPath( 'aimeos' );
$relpath = ExtensionManagementUtility::siteRelPath( 'aimeos' );
$langfile = $path . 'Resources/Private/Language/extension.xlf';
$languageFactory = GeneralUtility::makeInstance( 'TYPO3\CMS\Core\Localization\LocalizationFactory' );
$xml = $languageFactory->getParsedData( $langfile, $GLOBALS['LANG']->lang, '', 0 );
$wizardItems['plugins_tx_aimeos'] = array(
'icon' => $relpath . 'Resources/Public/Icons/Extension.svg',
'title' => $GLOBALS['LANG']->getLLL( 'ext-wizard-title', $xml ),
'description' => $GLOBALS['LANG']->getLLL( 'ext-wizard-description', $xml ),
'params' => '&defVals[tt_content][CType]=list'
);
return $wizardItems;
} | [
"public",
"function",
"proc",
"(",
"$",
"wizardItems",
")",
"{",
"$",
"path",
"=",
"ExtensionManagementUtility",
"::",
"extPath",
"(",
"'aimeos'",
")",
";",
"$",
"relpath",
"=",
"ExtensionManagementUtility",
"::",
"siteRelPath",
"(",
"'aimeos'",
")",
";",
"$",... | Adds the wizard icon
@param array Input array with wizard items for plugins
@return array Modified input array, having the item for Aimeos added. | [
"Adds",
"the",
"wizard",
"icon"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Custom/Wizicon.php#L31-L48 | train |
aimeos/aimeos-typo3 | Classes/Flexform/Attribute.php | Attribute.getTypes | public function getTypes( array $config, $tceForms = null, $sitecode = 'default' )
{
try
{
if( isset( $config['flexParentDatabaseRow']['pid'] ) ) { // TYPO3 7+
$pid = $config['flexParentDatabaseRow']['pid'];
} elseif( isset( $config['row']['pid'] ) ) { // TYPO3 6.2
$pid = $config['row']['pid'];
} else {
throw new \Exception( 'No PID found in "flexParentDatabaseRow" or "row" array key: ' . print_r( $config, true ) );
}
$pageTSConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getModTSconfig( $pid, 'tx_aimeos' );
if( isset( $pageTSConfig['properties']['mshop.']['locale.']['site'] ) ) {
$sitecode = $pageTSConfig['properties']['mshop.']['locale.']['site'];
}
$context = Base::getContext( Base::getConfig() );
$context->setEditor( 'flexform' );
$localeManager = \Aimeos\MShop::create( $context, 'locale' );
$context->setLocale( $localeManager->bootstrap( $sitecode, '', '', false ) );
$manager = \Aimeos\MShop::create( $context, 'attribute/type' );
$items = $manager->searchItems( $manager->createSearch( true ) );
foreach( $items as $item ) {
$config['items'][] = [$item->getName(), $item->getCode()];
}
}
catch( \Exception $e )
{
error_log( $e->getMessage() . PHP_EOL . $e->getTraceAsString() );
}
return $config;
} | php | public function getTypes( array $config, $tceForms = null, $sitecode = 'default' )
{
try
{
if( isset( $config['flexParentDatabaseRow']['pid'] ) ) { // TYPO3 7+
$pid = $config['flexParentDatabaseRow']['pid'];
} elseif( isset( $config['row']['pid'] ) ) { // TYPO3 6.2
$pid = $config['row']['pid'];
} else {
throw new \Exception( 'No PID found in "flexParentDatabaseRow" or "row" array key: ' . print_r( $config, true ) );
}
$pageTSConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getModTSconfig( $pid, 'tx_aimeos' );
if( isset( $pageTSConfig['properties']['mshop.']['locale.']['site'] ) ) {
$sitecode = $pageTSConfig['properties']['mshop.']['locale.']['site'];
}
$context = Base::getContext( Base::getConfig() );
$context->setEditor( 'flexform' );
$localeManager = \Aimeos\MShop::create( $context, 'locale' );
$context->setLocale( $localeManager->bootstrap( $sitecode, '', '', false ) );
$manager = \Aimeos\MShop::create( $context, 'attribute/type' );
$items = $manager->searchItems( $manager->createSearch( true ) );
foreach( $items as $item ) {
$config['items'][] = [$item->getName(), $item->getCode()];
}
}
catch( \Exception $e )
{
error_log( $e->getMessage() . PHP_EOL . $e->getTraceAsString() );
}
return $config;
} | [
"public",
"function",
"getTypes",
"(",
"array",
"$",
"config",
",",
"$",
"tceForms",
"=",
"null",
",",
"$",
"sitecode",
"=",
"'default'",
")",
"{",
"try",
"{",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'flexParentDatabaseRow'",
"]",
"[",
"'pid'",
"... | Returns the list of attribute types with their ID
@param array $config Associative array of existing configurations
@param \TYPO3\CMS\Backend\Form\FormEngine|\TYPO3\CMS\Backend\Form\DataPreprocessor $tceForms TCE forms object
@param string $sitecode Unique code of the site to retrieve the categories for
@return array Associative array with existing and new entries | [
"Returns",
"the",
"list",
"of",
"attribute",
"types",
"with",
"their",
"ID"
] | a18cb7fd14bc760dfa54757b9b99d26862bf175e | https://github.com/aimeos/aimeos-typo3/blob/a18cb7fd14bc760dfa54757b9b99d26862bf175e/Classes/Flexform/Attribute.php#L30-L68 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Query/Builder.php | Builder.distanceMultiplier | public function distanceMultiplier($distanceMultiplier)
{
if ($this->query['type'] !== Query::TYPE_GEO_NEAR) {
throw new BadMethodCallException('This method requires a geoNear command (call geoNear() first)');
}
$this->query['geoNear']['options']['distanceMultiplier'] = $distanceMultiplier;
return $this;
} | php | public function distanceMultiplier($distanceMultiplier)
{
if ($this->query['type'] !== Query::TYPE_GEO_NEAR) {
throw new BadMethodCallException('This method requires a geoNear command (call geoNear() first)');
}
$this->query['geoNear']['options']['distanceMultiplier'] = $distanceMultiplier;
return $this;
} | [
"public",
"function",
"distanceMultiplier",
"(",
"$",
"distanceMultiplier",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"query",
"[",
"'type'",
"]",
"!==",
"Query",
"::",
"TYPE_GEO_NEAR",
")",
"{",
"throw",
"new",
"BadMethodCallException",
"(",
"'This method require... | Set the "distanceMultiplier" option for a geoNear command query.
@param float $distanceMultiplier
@return $this
@throws BadMethodCallException if the query is not a geoNear command | [
"Set",
"the",
"distanceMultiplier",
"option",
"for",
"a",
"geoNear",
"command",
"query",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Query/Builder.php#L362-L370 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Query/Builder.php | Builder.finalize | public function finalize($finalize)
{
switch ($this->query['type']) {
case Query::TYPE_MAP_REDUCE:
$this->query['mapReduce']['options']['finalize'] = $finalize;
break;
case Query::TYPE_GROUP:
$this->query['group']['options']['finalize'] = $finalize;
break;
default:
throw new BadMethodCallException('mapReduce(), map() or group() must be called before finalize()');
}
return $this;
} | php | public function finalize($finalize)
{
switch ($this->query['type']) {
case Query::TYPE_MAP_REDUCE:
$this->query['mapReduce']['options']['finalize'] = $finalize;
break;
case Query::TYPE_GROUP:
$this->query['group']['options']['finalize'] = $finalize;
break;
default:
throw new BadMethodCallException('mapReduce(), map() or group() must be called before finalize()');
}
return $this;
} | [
"public",
"function",
"finalize",
"(",
"$",
"finalize",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"query",
"[",
"'type'",
"]",
")",
"{",
"case",
"Query",
"::",
"TYPE_MAP_REDUCE",
":",
"$",
"this",
"->",
"query",
"[",
"'mapReduce'",
"]",
"[",
"'option... | Set the "finalize" option for a mapReduce or group command.
@param string|\MongoCode $finalize
@return $this
@throws BadMethodCallException if the query is not a mapReduce or group command | [
"Set",
"the",
"finalize",
"option",
"for",
"a",
"mapReduce",
"or",
"group",
"command",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Query/Builder.php#L496-L512 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Query/Builder.php | Builder.group | public function group($keys, array $initial, $reduce = null, array $options = [])
{
$this->query['type'] = Query::TYPE_GROUP;
$this->query['group'] = [
'keys' => $keys,
'initial' => $initial,
'reduce' => $reduce,
'options' => $options,
];
return $this;
} | php | public function group($keys, array $initial, $reduce = null, array $options = [])
{
$this->query['type'] = Query::TYPE_GROUP;
$this->query['group'] = [
'keys' => $keys,
'initial' => $initial,
'reduce' => $reduce,
'options' => $options,
];
return $this;
} | [
"public",
"function",
"group",
"(",
"$",
"keys",
",",
"array",
"$",
"initial",
",",
"$",
"reduce",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"query",
"[",
"'type'",
"]",
"=",
"Query",
"::",
"TYPE_GROUP",... | Change the query type to a group command.
If the "reduce" option is not specified when calling this method, it must
be set with the {@link Builder::reduce()} method.
@see http://docs.mongodb.org/manual/reference/command/group/
@param mixed $keys
@param array $initial
@param string|\MongoCode $reduce
@param array $options
@return $this | [
"Change",
"the",
"query",
"type",
"to",
"a",
"group",
"command",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Query/Builder.php#L785-L795 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Query/Builder.php | Builder.mapReduceOptions | public function mapReduceOptions(array $options)
{
if ($this->query['type'] !== Query::TYPE_MAP_REDUCE) {
throw new BadMethodCallException('This method requires a mapReduce command (call map() or mapReduce() first)');
}
$this->query['mapReduce']['options'] = $options;
return $this;
} | php | public function mapReduceOptions(array $options)
{
if ($this->query['type'] !== Query::TYPE_MAP_REDUCE) {
throw new BadMethodCallException('This method requires a mapReduce command (call map() or mapReduce() first)');
}
$this->query['mapReduce']['options'] = $options;
return $this;
} | [
"public",
"function",
"mapReduceOptions",
"(",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"query",
"[",
"'type'",
"]",
"!==",
"Query",
"::",
"TYPE_MAP_REDUCE",
")",
"{",
"throw",
"new",
"BadMethodCallException",
"(",
"'This method require... | Set additional options for a mapReduce command.
@param array $options
@return $this
@throws BadMethodCallException if the query is not a mapReduce command | [
"Set",
"additional",
"options",
"for",
"a",
"mapReduce",
"command",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Query/Builder.php#L1003-L1011 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Query/Builder.php | Builder.out | public function out($out)
{
if ($this->query['type'] !== Query::TYPE_MAP_REDUCE) {
throw new BadMethodCallException('This method requires a mapReduce command (call map() or mapReduce() first)');
}
$this->query['mapReduce']['out'] = $out;
return $this;
} | php | public function out($out)
{
if ($this->query['type'] !== Query::TYPE_MAP_REDUCE) {
throw new BadMethodCallException('This method requires a mapReduce command (call map() or mapReduce() first)');
}
$this->query['mapReduce']['out'] = $out;
return $this;
} | [
"public",
"function",
"out",
"(",
"$",
"out",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"query",
"[",
"'type'",
"]",
"!==",
"Query",
"::",
"TYPE_MAP_REDUCE",
")",
"{",
"throw",
"new",
"BadMethodCallException",
"(",
"'This method requires a mapReduce command (call ... | Set the "out" option for a mapReduce command.
@param array|string $out
@return $this
@throws BadMethodCallException if the query is not a mapReduce command | [
"Set",
"the",
"out",
"option",
"for",
"a",
"mapReduce",
"command",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Query/Builder.php#L1247-L1255 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Query/Builder.php | Builder.reduce | public function reduce($reduce)
{
switch ($this->query['type']) {
case Query::TYPE_MAP_REDUCE:
$this->query['mapReduce']['reduce'] = $reduce;
break;
case Query::TYPE_GROUP:
$this->query['group']['reduce'] = $reduce;
break;
default:
throw new BadMethodCallException('mapReduce(), map() or group() must be called before reduce()');
}
return $this;
} | php | public function reduce($reduce)
{
switch ($this->query['type']) {
case Query::TYPE_MAP_REDUCE:
$this->query['mapReduce']['reduce'] = $reduce;
break;
case Query::TYPE_GROUP:
$this->query['group']['reduce'] = $reduce;
break;
default:
throw new BadMethodCallException('mapReduce(), map() or group() must be called before reduce()');
}
return $this;
} | [
"public",
"function",
"reduce",
"(",
"$",
"reduce",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"query",
"[",
"'type'",
"]",
")",
"{",
"case",
"Query",
"::",
"TYPE_MAP_REDUCE",
":",
"$",
"this",
"->",
"query",
"[",
"'mapReduce'",
"]",
"[",
"'reduce'",
... | Set the "reduce" option for a mapReduce or group command.
@param string|\MongoCode $reduce
@return $this
@throws BadMethodCallException if the query is not a mapReduce or group command | [
"Set",
"the",
"reduce",
"option",
"for",
"a",
"mapReduce",
"or",
"group",
"command",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Query/Builder.php#L1383-L1399 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Query/Builder.php | Builder.setReadPreference | public function setReadPreference($readPreference, array $tags = null)
{
$this->query['readPreference'] = $readPreference;
$this->query['readPreferenceTags'] = $tags;
return $this;
} | php | public function setReadPreference($readPreference, array $tags = null)
{
$this->query['readPreference'] = $readPreference;
$this->query['readPreferenceTags'] = $tags;
return $this;
} | [
"public",
"function",
"setReadPreference",
"(",
"$",
"readPreference",
",",
"array",
"$",
"tags",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"query",
"[",
"'readPreference'",
"]",
"=",
"$",
"readPreference",
";",
"$",
"this",
"->",
"query",
"[",
"'readPrefe... | Set the read preference for the query.
This is only relevant for read-only queries and commands.
@see http://docs.mongodb.org/manual/core/read-preference/
@param mixed $value
@param boolean $atomic
@return $this | [
"Set",
"the",
"read",
"preference",
"for",
"the",
"query",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Query/Builder.php#L1563-L1568 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Query/Builder.php | Builder.spherical | public function spherical($spherical = true)
{
if ($this->query['type'] !== Query::TYPE_GEO_NEAR) {
throw new BadMethodCallException('This method requires a geoNear command (call geoNear() first)');
}
$this->query['geoNear']['options']['spherical'] = $spherical;
return $this;
} | php | public function spherical($spherical = true)
{
if ($this->query['type'] !== Query::TYPE_GEO_NEAR) {
throw new BadMethodCallException('This method requires a geoNear command (call geoNear() first)');
}
$this->query['geoNear']['options']['spherical'] = $spherical;
return $this;
} | [
"public",
"function",
"spherical",
"(",
"$",
"spherical",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"query",
"[",
"'type'",
"]",
"!==",
"Query",
"::",
"TYPE_GEO_NEAR",
")",
"{",
"throw",
"new",
"BadMethodCallException",
"(",
"'This method requires... | Set the "spherical" option for a geoNear command query.
@param bool $spherical
@return $this
@throws BadMethodCallException if the query is not a geoNear command | [
"Set",
"the",
"spherical",
"option",
"for",
"a",
"geoNear",
"command",
"query",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Query/Builder.php#L1692-L1700 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/GridFSFile.php | GridFSFile.isDirty | public function isDirty($isDirty = null)
{
if ($isDirty !== null) {
$this->isDirty = (boolean) $isDirty;
}
return $this->isDirty;
} | php | public function isDirty($isDirty = null)
{
if ($isDirty !== null) {
$this->isDirty = (boolean) $isDirty;
}
return $this->isDirty;
} | [
"public",
"function",
"isDirty",
"(",
"$",
"isDirty",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"isDirty",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"isDirty",
"=",
"(",
"boolean",
")",
"$",
"isDirty",
";",
"}",
"return",
"$",
"this",
"->",
"isDirty... | Check whether the file is dirty.
If $isDirty is not null, the dirty state will be set before its new value
is returned.
@param boolean $isDirty
@return boolean | [
"Check",
"whether",
"the",
"file",
"is",
"dirty",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/GridFSFile.php#L191-L197 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Query/Expr.php | Expr.currentDate | public function currentDate($type = 'date')
{
if (! in_array($type, ['date', 'timestamp'])) {
throw new InvalidArgumentException('Type for currentDate operator must be date or timestamp.');
}
$this->requiresCurrentField();
$this->newObj['$currentDate'][$this->currentField]['$type'] = $type;
return $this;
} | php | public function currentDate($type = 'date')
{
if (! in_array($type, ['date', 'timestamp'])) {
throw new InvalidArgumentException('Type for currentDate operator must be date or timestamp.');
}
$this->requiresCurrentField();
$this->newObj['$currentDate'][$this->currentField]['$type'] = $type;
return $this;
} | [
"public",
"function",
"currentDate",
"(",
"$",
"type",
"=",
"'date'",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"type",
",",
"[",
"'date'",
",",
"'timestamp'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Type for currentDat... | Sets the value of the current field to the current date, either as a date or a timestamp.
@see Builder::currentDate()
@see http://docs.mongodb.org/manual/reference/operator/update/currentDate/
@param string $type
@return $this
@throws InvalidArgumentException if an invalid type is given | [
"Sets",
"the",
"value",
"of",
"the",
"current",
"field",
"to",
"the",
"current",
"date",
"either",
"as",
"a",
"date",
"or",
"a",
"timestamp",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Query/Expr.php#L343-L352 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Query/Expr.php | Expr.max | public function max($value)
{
$this->requiresCurrentField();
$this->newObj['$max'][$this->currentField] = $value;
return $this;
} | php | public function max($value)
{
$this->requiresCurrentField();
$this->newObj['$max'][$this->currentField] = $value;
return $this;
} | [
"public",
"function",
"max",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"requiresCurrentField",
"(",
")",
";",
"$",
"this",
"->",
"newObj",
"[",
"'$max'",
"]",
"[",
"$",
"this",
"->",
"currentField",
"]",
"=",
"$",
"value",
";",
"return",
"$",
... | Updates the value of the field to a specified value if the specified value is greater than the current value of the field.
@see Builder::max()
@see http://docs.mongodb.org/manual/reference/operator/update/max/
@param mixed $value
@return $this | [
"Updates",
"the",
"value",
"of",
"the",
"field",
"to",
"a",
"specified",
"value",
"if",
"the",
"specified",
"value",
"is",
"greater",
"than",
"the",
"current",
"value",
"of",
"the",
"field",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Query/Expr.php#L752-L757 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Query/Expr.php | Expr.min | public function min($value)
{
$this->requiresCurrentField();
$this->newObj['$min'][$this->currentField] = $value;
return $this;
} | php | public function min($value)
{
$this->requiresCurrentField();
$this->newObj['$min'][$this->currentField] = $value;
return $this;
} | [
"public",
"function",
"min",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"requiresCurrentField",
"(",
")",
";",
"$",
"this",
"->",
"newObj",
"[",
"'$min'",
"]",
"[",
"$",
"this",
"->",
"currentField",
"]",
"=",
"$",
"value",
";",
"return",
"$",
... | Updates the value of the field to a specified value if the specified value is less than the current value of the field.
@see Builder::min()
@see http://docs.mongodb.org/manual/reference/operator/update/min/
@param mixed $value
@return $this | [
"Updates",
"the",
"value",
"of",
"the",
"field",
"to",
"a",
"specified",
"value",
"if",
"the",
"specified",
"value",
"is",
"less",
"than",
"the",
"current",
"value",
"of",
"the",
"field",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Query/Expr.php#L804-L809 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Query/Expr.php | Expr.mul | public function mul($value)
{
$this->requiresCurrentField();
$this->newObj['$mul'][$this->currentField] = $value;
return $this;
} | php | public function mul($value)
{
$this->requiresCurrentField();
$this->newObj['$mul'][$this->currentField] = $value;
return $this;
} | [
"public",
"function",
"mul",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"requiresCurrentField",
"(",
")",
";",
"$",
"this",
"->",
"newObj",
"[",
"'$mul'",
"]",
"[",
"$",
"this",
"->",
"currentField",
"]",
"=",
"$",
"value",
";",
"return",
"$",
... | Multiply the current field.
If the field does not exist, it will be set to 0.
@see Builder::mul()
@see http://docs.mongodb.org/manual/reference/operator/mul/
@param float|integer $value
@return $this | [
"Multiply",
"the",
"current",
"field",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Query/Expr.php#L872-L877 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Query/Expr.php | Expr.pullAll | public function pullAll(array $values)
{
$this->requiresCurrentField();
$this->newObj['$pullAll'][$this->currentField] = $values;
return $this;
} | php | public function pullAll(array $values)
{
$this->requiresCurrentField();
$this->newObj['$pullAll'][$this->currentField] = $values;
return $this;
} | [
"public",
"function",
"pullAll",
"(",
"array",
"$",
"values",
")",
"{",
"$",
"this",
"->",
"requiresCurrentField",
"(",
")",
";",
"$",
"this",
"->",
"newObj",
"[",
"'$pullAll'",
"]",
"[",
"$",
"this",
"->",
"currentField",
"]",
"=",
"$",
"values",
";",... | Remove all elements matching any of the given values from the current
array field.
@see Builder::pullAll()
@see http://docs.mongodb.org/manual/reference/operator/pullAll/
@param array $values
@return $this | [
"Remove",
"all",
"elements",
"matching",
"any",
"of",
"the",
"given",
"values",
"from",
"the",
"current",
"array",
"field",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Query/Expr.php#L1064-L1069 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Query/Expr.php | Expr.pushAll | public function pushAll(array $values)
{
$this->requiresCurrentField();
$this->newObj['$pushAll'][$this->currentField] = $values;
return $this;
} | php | public function pushAll(array $values)
{
$this->requiresCurrentField();
$this->newObj['$pushAll'][$this->currentField] = $values;
return $this;
} | [
"public",
"function",
"pushAll",
"(",
"array",
"$",
"values",
")",
"{",
"$",
"this",
"->",
"requiresCurrentField",
"(",
")",
";",
"$",
"this",
"->",
"newObj",
"[",
"'$pushAll'",
"]",
"[",
"$",
"this",
"->",
"currentField",
"]",
"=",
"$",
"values",
";",... | Append multiple values to the current array field.
If the field does not exist, it will be set to an array containing the
values in the argument. If the field is not an array, the query will
yield an error.
This operator is deprecated in MongoDB 2.4. {@link Expr::push()} and
{@link Expr::each()} should be used in its place.
@see Builder::pushAll()
@see http://docs.mongodb.org/manual/reference/operator/pushAll/
@param array $values
@return $this | [
"Append",
"multiple",
"values",
"to",
"the",
"current",
"array",
"field",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Query/Expr.php#L1119-L1124 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Query/Expr.php | Expr.setOnInsert | public function setOnInsert($value)
{
$this->requiresCurrentField();
$this->newObj['$setOnInsert'][$this->currentField] = $value;
return $this;
} | php | public function setOnInsert($value)
{
$this->requiresCurrentField();
$this->newObj['$setOnInsert'][$this->currentField] = $value;
return $this;
} | [
"public",
"function",
"setOnInsert",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"requiresCurrentField",
"(",
")",
";",
"$",
"this",
"->",
"newObj",
"[",
"'$setOnInsert'",
"]",
"[",
"$",
"this",
"->",
"currentField",
"]",
"=",
"$",
"value",
";",
"r... | Set the current field to the value if the document is inserted in an
upsert operation.
If an update operation with upsert: true results in an insert of a
document, then $setOnInsert assigns the specified values to the fields in
the document. If the update operation does not result in an insert,
$setOnInsert does nothing.
@see Builder::setOnInsert()
@see https://docs.mongodb.org/manual/reference/operator/update/setOnInsert/
@param mixed $value
@return $this | [
"Set",
"the",
"current",
"field",
"to",
"the",
"value",
"if",
"the",
"document",
"is",
"inserted",
"in",
"an",
"upsert",
"operation",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Query/Expr.php#L1208-L1214 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Collection.php | Collection.findAndRemove | public function findAndRemove(array $query, array $options = [])
{
if ($this->eventManager->hasListeners(Events::preFindAndRemove)) {
$eventArgs = new MutableEventArgs($this, $query, $options);
$this->eventManager->dispatchEvent(Events::preFindAndRemove, $eventArgs);
$query = $eventArgs->getData();
$options = $eventArgs->getOptions();
}
$result = $this->doFindAndRemove($query, $options);
if ($this->eventManager->hasListeners(Events::postFindAndRemove)) {
$eventArgs = new MutableEventArgs($this, $result);
$this->eventManager->dispatchEvent(Events::postFindAndRemove, $eventArgs);
$result = $eventArgs->getData();
}
return $result;
} | php | public function findAndRemove(array $query, array $options = [])
{
if ($this->eventManager->hasListeners(Events::preFindAndRemove)) {
$eventArgs = new MutableEventArgs($this, $query, $options);
$this->eventManager->dispatchEvent(Events::preFindAndRemove, $eventArgs);
$query = $eventArgs->getData();
$options = $eventArgs->getOptions();
}
$result = $this->doFindAndRemove($query, $options);
if ($this->eventManager->hasListeners(Events::postFindAndRemove)) {
$eventArgs = new MutableEventArgs($this, $result);
$this->eventManager->dispatchEvent(Events::postFindAndRemove, $eventArgs);
$result = $eventArgs->getData();
}
return $result;
} | [
"public",
"function",
"findAndRemove",
"(",
"array",
"$",
"query",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"eventManager",
"->",
"hasListeners",
"(",
"Events",
"::",
"preFindAndRemove",
")",
")",
"{",
"$",
"... | Invokes the findAndModify command with the remove option.
This method will dispatch preFindAndRemove and postFindAndRemove events.
@see http://docs.mongodb.org/manual/reference/command/findAndModify/
@param array $query
@param array $options
@return array|null
@throws ResultException if the command fails | [
"Invokes",
"the",
"findAndModify",
"command",
"with",
"the",
"remove",
"option",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Collection.php#L347-L365 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Collection.php | Collection.findAndUpdate | public function findAndUpdate(array $query, array $newObj, array $options = [])
{
if ($this->eventManager->hasListeners(Events::preFindAndUpdate)) {
$updateEventArgs = new UpdateEventArgs($this, $query, $newObj, $options);
$this->eventManager->dispatchEvent(Events::preFindAndUpdate, $updateEventArgs);
$query = $updateEventArgs->getQuery();
$newObj = $updateEventArgs->getNewObj();
$options = $updateEventArgs->getOptions();
}
$result = $this->doFindAndUpdate($query, $newObj, $options);
if ($this->eventManager->hasListeners(Events::postFindAndUpdate)) {
$eventArgs = new MutableEventArgs($this, $result);
$this->eventManager->dispatchEvent(Events::postFindAndUpdate, $eventArgs);
$result = $eventArgs->getData();
}
return $result;
} | php | public function findAndUpdate(array $query, array $newObj, array $options = [])
{
if ($this->eventManager->hasListeners(Events::preFindAndUpdate)) {
$updateEventArgs = new UpdateEventArgs($this, $query, $newObj, $options);
$this->eventManager->dispatchEvent(Events::preFindAndUpdate, $updateEventArgs);
$query = $updateEventArgs->getQuery();
$newObj = $updateEventArgs->getNewObj();
$options = $updateEventArgs->getOptions();
}
$result = $this->doFindAndUpdate($query, $newObj, $options);
if ($this->eventManager->hasListeners(Events::postFindAndUpdate)) {
$eventArgs = new MutableEventArgs($this, $result);
$this->eventManager->dispatchEvent(Events::postFindAndUpdate, $eventArgs);
$result = $eventArgs->getData();
}
return $result;
} | [
"public",
"function",
"findAndUpdate",
"(",
"array",
"$",
"query",
",",
"array",
"$",
"newObj",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"eventManager",
"->",
"hasListeners",
"(",
"Events",
"::",
"preFindAndUpd... | Invokes the findAndModify command with the update option.
This method will dispatch preFindAndUpdate and postFindAndUpdate events.
@see http://docs.mongodb.org/manual/reference/command/findAndModify/
@param array $query
@param array $newObj
@param array $options
@return array|null
@throws ResultException if the command fails | [
"Invokes",
"the",
"findAndModify",
"command",
"with",
"the",
"update",
"option",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Collection.php#L379-L398 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Collection.php | Collection.setSlaveOkay | public function setSlaveOkay($ok = true)
{
$prevSlaveOkay = $this->getSlaveOkay();
if ($ok) {
// Preserve existing tags for non-primary read preferences
$readPref = $this->getReadPreference();
$tags = ! empty($readPref['tagsets']) ? $readPref['tagsets'] : [];
$this->mongoCollection->setReadPreference(\MongoClient::RP_SECONDARY_PREFERRED, $tags);
} else {
$this->mongoCollection->setReadPreference(\MongoClient::RP_PRIMARY);
}
return $prevSlaveOkay;
} | php | public function setSlaveOkay($ok = true)
{
$prevSlaveOkay = $this->getSlaveOkay();
if ($ok) {
// Preserve existing tags for non-primary read preferences
$readPref = $this->getReadPreference();
$tags = ! empty($readPref['tagsets']) ? $readPref['tagsets'] : [];
$this->mongoCollection->setReadPreference(\MongoClient::RP_SECONDARY_PREFERRED, $tags);
} else {
$this->mongoCollection->setReadPreference(\MongoClient::RP_PRIMARY);
}
return $prevSlaveOkay;
} | [
"public",
"function",
"setSlaveOkay",
"(",
"$",
"ok",
"=",
"true",
")",
"{",
"$",
"prevSlaveOkay",
"=",
"$",
"this",
"->",
"getSlaveOkay",
"(",
")",
";",
"if",
"(",
"$",
"ok",
")",
"{",
"// Preserve existing tags for non-primary read preferences",
"$",
"readPr... | Set whether secondary read queries are allowed for this collection.
This method wraps setSlaveOkay() for driver versions before 1.3.0. For
newer drivers, this method wraps setReadPreference() and specifies
SECONDARY_PREFERRED.
@see http://php.net/manual/en/mongocollection.setreadpreference.php
@see http://php.net/manual/en/mongocollection.setslaveokay.php
@param boolean $ok
@return boolean Previous slaveOk value | [
"Set",
"whether",
"secondary",
"read",
"queries",
"are",
"allowed",
"for",
"this",
"collection",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Collection.php#L561-L575 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Collection.php | Collection.isFieldIndexed | public function isFieldIndexed($fieldName)
{
$indexes = $this->getIndexInfo();
foreach ($indexes as $index) {
if (isset($index['key']) && isset($index['key'][$fieldName])) {
return true;
}
}
return false;
} | php | public function isFieldIndexed($fieldName)
{
$indexes = $this->getIndexInfo();
foreach ($indexes as $index) {
if (isset($index['key']) && isset($index['key'][$fieldName])) {
return true;
}
}
return false;
} | [
"public",
"function",
"isFieldIndexed",
"(",
"$",
"fieldName",
")",
"{",
"$",
"indexes",
"=",
"$",
"this",
"->",
"getIndexInfo",
"(",
")",
";",
"foreach",
"(",
"$",
"indexes",
"as",
"$",
"index",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"index",
"[",
... | Check if a given field name is indexed in MongoDB.
@param string $fieldName
@return boolean | [
"Check",
"if",
"a",
"given",
"field",
"name",
"is",
"indexed",
"in",
"MongoDB",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Collection.php#L648-L657 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Collection.php | Collection.doCount | protected function doCount(array $query, array $options)
{
list($commandOptions, $clientOptions) = isset($options['socketTimeoutMS']) || isset($options['timeout'])
? $this->splitCommandAndClientOptions($options)
: [$options, []];
$command = [];
$command['count'] = $this->mongoCollection->getName();
$command['query'] = (object) $query;
$command = array_merge($command, $commandOptions);
$database = $this->database;
$result = $this->retry(function() use ($database, $command, $clientOptions) {
return $database->command($command, $clientOptions);
});
if (empty($result['ok']) || ! isset($result['n'])) {
throw new ResultException($result);
}
return (integer) $result['n'];
} | php | protected function doCount(array $query, array $options)
{
list($commandOptions, $clientOptions) = isset($options['socketTimeoutMS']) || isset($options['timeout'])
? $this->splitCommandAndClientOptions($options)
: [$options, []];
$command = [];
$command['count'] = $this->mongoCollection->getName();
$command['query'] = (object) $query;
$command = array_merge($command, $commandOptions);
$database = $this->database;
$result = $this->retry(function() use ($database, $command, $clientOptions) {
return $database->command($command, $clientOptions);
});
if (empty($result['ok']) || ! isset($result['n'])) {
throw new ResultException($result);
}
return (integer) $result['n'];
} | [
"protected",
"function",
"doCount",
"(",
"array",
"$",
"query",
",",
"array",
"$",
"options",
")",
"{",
"list",
"(",
"$",
"commandOptions",
",",
"$",
"clientOptions",
")",
"=",
"isset",
"(",
"$",
"options",
"[",
"'socketTimeoutMS'",
"]",
")",
"||",
"isse... | Execute the count command.
@see Collection::count()
@param array $query
@param array $options
@return integer
@throws ResultException if the command fails or omits the result field | [
"Execute",
"the",
"count",
"command",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Collection.php#L1017-L1038 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Collection.php | Collection.doDistinct | protected function doDistinct($field, array $query, array $options)
{
list($commandOptions, $clientOptions) = isset($options['socketTimeoutMS']) || isset($options['timeout'])
? $this->splitCommandAndClientOptions($options)
: [$options, []];
$command = [];
$command['distinct'] = $this->mongoCollection->getName();
$command['key'] = $field;
$command['query'] = (object) $query;
$command = array_merge($command, $commandOptions);
$database = $this->database;
$result = $this->retry(function() use ($database, $command, $clientOptions) {
return $database->command($command, $clientOptions);
});
if (empty($result['ok'])) {
throw new ResultException($result);
}
$arrayIterator = new ArrayIterator(isset($result['values']) ? $result['values'] : []);
$arrayIterator->setCommandResult($result);
return $arrayIterator;
} | php | protected function doDistinct($field, array $query, array $options)
{
list($commandOptions, $clientOptions) = isset($options['socketTimeoutMS']) || isset($options['timeout'])
? $this->splitCommandAndClientOptions($options)
: [$options, []];
$command = [];
$command['distinct'] = $this->mongoCollection->getName();
$command['key'] = $field;
$command['query'] = (object) $query;
$command = array_merge($command, $commandOptions);
$database = $this->database;
$result = $this->retry(function() use ($database, $command, $clientOptions) {
return $database->command($command, $clientOptions);
});
if (empty($result['ok'])) {
throw new ResultException($result);
}
$arrayIterator = new ArrayIterator(isset($result['values']) ? $result['values'] : []);
$arrayIterator->setCommandResult($result);
return $arrayIterator;
} | [
"protected",
"function",
"doDistinct",
"(",
"$",
"field",
",",
"array",
"$",
"query",
",",
"array",
"$",
"options",
")",
"{",
"list",
"(",
"$",
"commandOptions",
",",
"$",
"clientOptions",
")",
"=",
"isset",
"(",
"$",
"options",
"[",
"'socketTimeoutMS'",
... | Execute the distinct command.
@see Collection::distinct()
@param string $field
@param array $query
@param array $options
@return ArrayIterator
@throws ResultException if the command fails | [
"Execute",
"the",
"distinct",
"command",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Collection.php#L1050-L1075 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Collection.php | Collection.doGroup | protected function doGroup($keys, array $initial, $reduce, array $options)
{
list($commandOptions, $clientOptions) = isset($options['socketTimeoutMS']) || isset($options['timeout'])
? $this->splitCommandAndClientOptions($options)
: [$options, []];
$command = [];
$command['ns'] = $this->mongoCollection->getName();
$command['initial'] = (object) $initial;
$command['$reduce'] = $reduce;
if (is_string($keys) || $keys instanceof \MongoCode) {
$command['$keyf'] = $keys;
} else {
$command['key'] = $keys;
}
$command = array_merge($command, $commandOptions);
foreach (['$keyf', '$reduce', 'finalize'] as $key) {
if (isset($command[$key]) && is_string($command[$key])) {
$command[$key] = new \MongoCode($command[$key]);
}
}
if (isset($command['cond']) && is_array($command['cond'])) {
$command['cond'] = (object) $command['cond'];
}
$database = $this->database;
$result = $this->retry(function() use ($database, $command, $clientOptions) {
return $database->command(['group' => $command], $clientOptions);
});
if (empty($result['ok'])) {
throw new ResultException($result);
}
$arrayIterator = new ArrayIterator(isset($result['retval']) ? $result['retval'] : []);
$arrayIterator->setCommandResult($result);
return $arrayIterator;
} | php | protected function doGroup($keys, array $initial, $reduce, array $options)
{
list($commandOptions, $clientOptions) = isset($options['socketTimeoutMS']) || isset($options['timeout'])
? $this->splitCommandAndClientOptions($options)
: [$options, []];
$command = [];
$command['ns'] = $this->mongoCollection->getName();
$command['initial'] = (object) $initial;
$command['$reduce'] = $reduce;
if (is_string($keys) || $keys instanceof \MongoCode) {
$command['$keyf'] = $keys;
} else {
$command['key'] = $keys;
}
$command = array_merge($command, $commandOptions);
foreach (['$keyf', '$reduce', 'finalize'] as $key) {
if (isset($command[$key]) && is_string($command[$key])) {
$command[$key] = new \MongoCode($command[$key]);
}
}
if (isset($command['cond']) && is_array($command['cond'])) {
$command['cond'] = (object) $command['cond'];
}
$database = $this->database;
$result = $this->retry(function() use ($database, $command, $clientOptions) {
return $database->command(['group' => $command], $clientOptions);
});
if (empty($result['ok'])) {
throw new ResultException($result);
}
$arrayIterator = new ArrayIterator(isset($result['retval']) ? $result['retval'] : []);
$arrayIterator->setCommandResult($result);
return $arrayIterator;
} | [
"protected",
"function",
"doGroup",
"(",
"$",
"keys",
",",
"array",
"$",
"initial",
",",
"$",
"reduce",
",",
"array",
"$",
"options",
")",
"{",
"list",
"(",
"$",
"commandOptions",
",",
"$",
"clientOptions",
")",
"=",
"isset",
"(",
"$",
"options",
"[",
... | Execute the group command.
@see Collection::group()
@param array|string|\MongoCode $keys
@param array $initial
@param string|\MongoCode $reduce
@param array $options
@return ArrayIterator
@throws ResultException if the command fails | [
"Execute",
"the",
"group",
"command",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Collection.php#L1208-L1250 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Collection.php | Collection.doInsert | protected function doInsert(array &$a, array $options)
{
$document = $a;
$options = isset($options['safe']) ? $this->convertWriteConcern($options) : $options;
$options = isset($options['wtimeout']) ? $this->convertWriteTimeout($options) : $options;
$options = isset($options['timeout']) ? $this->convertSocketTimeout($options) : $options;
$result = $this->mongoCollection->insert($document, $options);
if (isset($document['_id'])) {
$a['_id'] = $document['_id'];
}
return $result;
} | php | protected function doInsert(array &$a, array $options)
{
$document = $a;
$options = isset($options['safe']) ? $this->convertWriteConcern($options) : $options;
$options = isset($options['wtimeout']) ? $this->convertWriteTimeout($options) : $options;
$options = isset($options['timeout']) ? $this->convertSocketTimeout($options) : $options;
$result = $this->mongoCollection->insert($document, $options);
if (isset($document['_id'])) {
$a['_id'] = $document['_id'];
}
return $result;
} | [
"protected",
"function",
"doInsert",
"(",
"array",
"&",
"$",
"a",
",",
"array",
"$",
"options",
")",
"{",
"$",
"document",
"=",
"$",
"a",
";",
"$",
"options",
"=",
"isset",
"(",
"$",
"options",
"[",
"'safe'",
"]",
")",
"?",
"$",
"this",
"->",
"co... | Execute the insert query.
@see Collection::insert()
@param array $a
@param array $options
@return array|boolean | [
"Execute",
"the",
"insert",
"query",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Collection.php#L1260-L1271 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Collection.php | Collection.doMapReduce | protected function doMapReduce($map, $reduce, $out, array $query, array $options)
{
list($commandOptions, $clientOptions) = isset($options['socketTimeoutMS']) || isset($options['timeout'])
? $this->splitCommandAndClientOptions($options)
: [$options, []];
$command = [];
$command['mapreduce'] = $this->mongoCollection->getName();
$command['map'] = $map;
$command['reduce'] = $reduce;
$command['query'] = (object) $query;
$command['out'] = $out;
$command = array_merge($command, $commandOptions);
foreach (['map', 'reduce', 'finalize'] as $key) {
if (isset($command[$key]) && is_string($command[$key])) {
$command[$key] = new \MongoCode($command[$key]);
}
}
$result = $this->database->command($command, $clientOptions);
if (empty($result['ok'])) {
throw new ResultException($result);
}
if (isset($result['result']) && is_string($result['result'])) {
return $this->database->selectCollection($result['result'])->find();
}
if (isset($result['result']) && is_array($result['result']) &&
isset($result['result']['db'], $result['result']['collection'])) {
return $this->database->getConnection()
->selectCollection($result['result']['db'], $result['result']['collection'])
->find();
}
$arrayIterator = new ArrayIterator(isset($result['results']) ? $result['results'] : []);
$arrayIterator->setCommandResult($result);
return $arrayIterator;
} | php | protected function doMapReduce($map, $reduce, $out, array $query, array $options)
{
list($commandOptions, $clientOptions) = isset($options['socketTimeoutMS']) || isset($options['timeout'])
? $this->splitCommandAndClientOptions($options)
: [$options, []];
$command = [];
$command['mapreduce'] = $this->mongoCollection->getName();
$command['map'] = $map;
$command['reduce'] = $reduce;
$command['query'] = (object) $query;
$command['out'] = $out;
$command = array_merge($command, $commandOptions);
foreach (['map', 'reduce', 'finalize'] as $key) {
if (isset($command[$key]) && is_string($command[$key])) {
$command[$key] = new \MongoCode($command[$key]);
}
}
$result = $this->database->command($command, $clientOptions);
if (empty($result['ok'])) {
throw new ResultException($result);
}
if (isset($result['result']) && is_string($result['result'])) {
return $this->database->selectCollection($result['result'])->find();
}
if (isset($result['result']) && is_array($result['result']) &&
isset($result['result']['db'], $result['result']['collection'])) {
return $this->database->getConnection()
->selectCollection($result['result']['db'], $result['result']['collection'])
->find();
}
$arrayIterator = new ArrayIterator(isset($result['results']) ? $result['results'] : []);
$arrayIterator->setCommandResult($result);
return $arrayIterator;
} | [
"protected",
"function",
"doMapReduce",
"(",
"$",
"map",
",",
"$",
"reduce",
",",
"$",
"out",
",",
"array",
"$",
"query",
",",
"array",
"$",
"options",
")",
"{",
"list",
"(",
"$",
"commandOptions",
",",
"$",
"clientOptions",
")",
"=",
"isset",
"(",
"... | Execute the mapReduce command.
@see Collection::mapReduce()
@param string|\MongoCode $map
@param string|\MongoCode $reduce
@param array|string $out
@param array $query
@param array $options
@return ArrayIterator
@throws ResultException if the command fails | [
"Execute",
"the",
"mapReduce",
"command",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Collection.php#L1285-L1326 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Collection.php | Collection.doNear | protected function doNear($near, array $query, array $options)
{
if ($near instanceof Point) {
$near = $near->jsonSerialize();
}
list($commandOptions, $clientOptions) = isset($options['socketTimeoutMS']) || isset($options['timeout'])
? $this->splitCommandAndClientOptions($options)
: [$options, []];
$command = [];
$command['geoNear'] = $this->mongoCollection->getName();
$command['near'] = $near;
$command['spherical'] = isset($near['type']);
$command['query'] = (object) $query;
$command = array_merge($command, $commandOptions);
$database = $this->database;
$result = $this->retry(function() use ($database, $command, $clientOptions) {
return $database->command($command, $clientOptions);
});
if (empty($result['ok'])) {
throw new ResultException($result);
}
$arrayIterator = new ArrayIterator(isset($result['results']) ? $result['results'] : []);
$arrayIterator->setCommandResult($result);
return $arrayIterator;
} | php | protected function doNear($near, array $query, array $options)
{
if ($near instanceof Point) {
$near = $near->jsonSerialize();
}
list($commandOptions, $clientOptions) = isset($options['socketTimeoutMS']) || isset($options['timeout'])
? $this->splitCommandAndClientOptions($options)
: [$options, []];
$command = [];
$command['geoNear'] = $this->mongoCollection->getName();
$command['near'] = $near;
$command['spherical'] = isset($near['type']);
$command['query'] = (object) $query;
$command = array_merge($command, $commandOptions);
$database = $this->database;
$result = $this->retry(function() use ($database, $command, $clientOptions) {
return $database->command($command, $clientOptions);
});
if (empty($result['ok'])) {
throw new ResultException($result);
}
$arrayIterator = new ArrayIterator(isset($result['results']) ? $result['results'] : []);
$arrayIterator->setCommandResult($result);
return $arrayIterator;
} | [
"protected",
"function",
"doNear",
"(",
"$",
"near",
",",
"array",
"$",
"query",
",",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"$",
"near",
"instanceof",
"Point",
")",
"{",
"$",
"near",
"=",
"$",
"near",
"->",
"jsonSerialize",
"(",
")",
";",
"... | Execute the geoNear command.
@see Collection::near()
@param array|Point $near
@param array $query
@param array $options
@return ArrayIterator
@throws ResultException if the command fails | [
"Execute",
"the",
"geoNear",
"command",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Collection.php#L1338-L1368 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Collection.php | Collection.doRemove | protected function doRemove(array $query, array $options)
{
$options = isset($options['safe']) ? $this->convertWriteConcern($options) : $options;
$options = isset($options['wtimeout']) ? $this->convertWriteTimeout($options) : $options;
$options = isset($options['timeout']) ? $this->convertSocketTimeout($options) : $options;
return $this->mongoCollection->remove($query, $options);
} | php | protected function doRemove(array $query, array $options)
{
$options = isset($options['safe']) ? $this->convertWriteConcern($options) : $options;
$options = isset($options['wtimeout']) ? $this->convertWriteTimeout($options) : $options;
$options = isset($options['timeout']) ? $this->convertSocketTimeout($options) : $options;
return $this->mongoCollection->remove($query, $options);
} | [
"protected",
"function",
"doRemove",
"(",
"array",
"$",
"query",
",",
"array",
"$",
"options",
")",
"{",
"$",
"options",
"=",
"isset",
"(",
"$",
"options",
"[",
"'safe'",
"]",
")",
"?",
"$",
"this",
"->",
"convertWriteConcern",
"(",
"$",
"options",
")"... | Execute the remove query.
@see Collection::remove()
@param array $query
@param array $options
@return array|boolean | [
"Execute",
"the",
"remove",
"query",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Collection.php#L1378-L1384 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Collection.php | Collection.wrapCursor | protected function wrapCursor(\MongoCursor $cursor, $query, $fields)
{
return new Cursor($this, $cursor, $query, $fields, $this->numRetries);
} | php | protected function wrapCursor(\MongoCursor $cursor, $query, $fields)
{
return new Cursor($this, $cursor, $query, $fields, $this->numRetries);
} | [
"protected",
"function",
"wrapCursor",
"(",
"\\",
"MongoCursor",
"$",
"cursor",
",",
"$",
"query",
",",
"$",
"fields",
")",
"{",
"return",
"new",
"Cursor",
"(",
"$",
"this",
",",
"$",
"cursor",
",",
"$",
"query",
",",
"$",
"fields",
",",
"$",
"this",... | Wraps a MongoCursor instance with a Cursor.
@param \MongoCursor $cursor
@param array $query
@param array $fields
@return Cursor | [
"Wraps",
"a",
"MongoCursor",
"instance",
"with",
"a",
"Cursor",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Collection.php#L1480-L1483 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Collection.php | Collection.convertWriteTimeout | protected function convertWriteTimeout(array $options)
{
if (isset($options['wtimeout']) && ! isset($options['wTimeoutMS'])) {
$options['wTimeoutMS'] = $options['wtimeout'];
unset($options['wtimeout']);
}
return $options;
} | php | protected function convertWriteTimeout(array $options)
{
if (isset($options['wtimeout']) && ! isset($options['wTimeoutMS'])) {
$options['wTimeoutMS'] = $options['wtimeout'];
unset($options['wtimeout']);
}
return $options;
} | [
"protected",
"function",
"convertWriteTimeout",
"(",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'wtimeout'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"options",
"[",
"'wTimeoutMS'",
"]",
")",
")",
"{",
"$",
"option... | Convert "wtimeout" write option to "wTimeoutMS" for driver version
1.5.0+.
@param array $options
@return array | [
"Convert",
"wtimeout",
"write",
"option",
"to",
"wTimeoutMS",
"for",
"driver",
"version",
"1",
".",
"5",
".",
"0",
"+",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Collection.php#L1508-L1516 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/EagerCursor.php | EagerCursor.initialize | public function initialize()
{
if ($this->initialized === false) {
$this->data = $this->cursor->toArray();
}
$this->initialized = true;
} | php | public function initialize()
{
if ($this->initialized === false) {
$this->data = $this->cursor->toArray();
}
$this->initialized = true;
} | [
"public",
"function",
"initialize",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"initialized",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"$",
"this",
"->",
"cursor",
"->",
"toArray",
"(",
")",
";",
"}",
"$",
"this",
"->",
"initiali... | Initialize the internal data by converting the Cursor to an array. | [
"Initialize",
"the",
"internal",
"data",
"by",
"converting",
"the",
"Cursor",
"to",
"an",
"array",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/EagerCursor.php#L101-L107 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/GridFS.php | GridFS.doUpdate | protected function doUpdate(array $query, array $newObj, array $options = [])
{
$file = isset($newObj['$set']['file']) ? $newObj['$set']['file'] : null;
unset($newObj['$set']['file']);
if ($file === null) {
$file = isset($newObj['file']) ? $newObj['file'] : null;
unset($newObj['file']);
}
/* Before we inspect $newObj, remove an empty $set operator we may have
* left behind due to extracting the file field above.
*/
if (empty($newObj['$set'])) {
unset($newObj['$set']);
}
/* Determine if $newObj includes atomic modifiers, which will tell us if
* we can get by with a storeFile() in some situations or if a two-step
* storeFile() and update() is necessary.
*/
$newObjHasModifiers = false;
foreach (array_keys($newObj) as $key) {
if ('$' === $key[0]) {
$newObjHasModifiers = true;
}
}
// Is there a file in need of persisting?
if (isset($file) && $file->isDirty()) {
/* It is impossible to overwrite a file's chunks in GridFS so we
* must remove it and re-persist a new file with the same data.
*
* First, use findAndRemove() to remove the file metadata and chunks
* prior to storing the file again below. Exclude metadata fields
* from the result, since those will be reset later.
*/
$document = $this->findAndRemove($query, ['fields' => [
'filename' => 0,
'length' => 0,
'chunkSize' => 0,
'uploadDate' => 0,
'md5' => 0,
'file' => 0,
]]);
/* If findAndRemove() returned nothing (no match or removal), create
* a new document with the query's "_id" if available.
*/
if (! isset($document)) {
/* If $newObj had modifiers, we'll need to do an update later,
* so default to an empty array for now. Otherwise, we can do
* without that update and store $newObj now.
*/
$document = $newObjHasModifiers ? [] : $newObj;
/* If the document has no "_id" but there was one in the query
* or $newObj, we can use that instead of having storeFile()
* generate one.
*/
if (! isset($document['_id']) && isset($query['_id'])) {
$document['_id'] = $query['_id'];
}
if (! isset($document['_id']) && isset($newObj['_id'])) {
$document['_id'] = $newObj['_id'];
}
}
// Document will definitely have an "_id" after storing the file.
$this->storeFile($file, $document);
if (! $newObjHasModifiers) {
/* TODO: MongoCollection::update() would return a boolean if
* $newObj was not empty, or an array describing the update
* operation. Improvise, since we only stored the file and that
* returns the "_id" field.
*/
return true;
}
}
// Now send the original update bringing the file up to date
$options = isset($options['safe']) ? $this->convertWriteConcern($options) : $options;
return $this->mongoCollection->update($query, $newObj, $options);
} | php | protected function doUpdate(array $query, array $newObj, array $options = [])
{
$file = isset($newObj['$set']['file']) ? $newObj['$set']['file'] : null;
unset($newObj['$set']['file']);
if ($file === null) {
$file = isset($newObj['file']) ? $newObj['file'] : null;
unset($newObj['file']);
}
/* Before we inspect $newObj, remove an empty $set operator we may have
* left behind due to extracting the file field above.
*/
if (empty($newObj['$set'])) {
unset($newObj['$set']);
}
/* Determine if $newObj includes atomic modifiers, which will tell us if
* we can get by with a storeFile() in some situations or if a two-step
* storeFile() and update() is necessary.
*/
$newObjHasModifiers = false;
foreach (array_keys($newObj) as $key) {
if ('$' === $key[0]) {
$newObjHasModifiers = true;
}
}
// Is there a file in need of persisting?
if (isset($file) && $file->isDirty()) {
/* It is impossible to overwrite a file's chunks in GridFS so we
* must remove it and re-persist a new file with the same data.
*
* First, use findAndRemove() to remove the file metadata and chunks
* prior to storing the file again below. Exclude metadata fields
* from the result, since those will be reset later.
*/
$document = $this->findAndRemove($query, ['fields' => [
'filename' => 0,
'length' => 0,
'chunkSize' => 0,
'uploadDate' => 0,
'md5' => 0,
'file' => 0,
]]);
/* If findAndRemove() returned nothing (no match or removal), create
* a new document with the query's "_id" if available.
*/
if (! isset($document)) {
/* If $newObj had modifiers, we'll need to do an update later,
* so default to an empty array for now. Otherwise, we can do
* without that update and store $newObj now.
*/
$document = $newObjHasModifiers ? [] : $newObj;
/* If the document has no "_id" but there was one in the query
* or $newObj, we can use that instead of having storeFile()
* generate one.
*/
if (! isset($document['_id']) && isset($query['_id'])) {
$document['_id'] = $query['_id'];
}
if (! isset($document['_id']) && isset($newObj['_id'])) {
$document['_id'] = $newObj['_id'];
}
}
// Document will definitely have an "_id" after storing the file.
$this->storeFile($file, $document);
if (! $newObjHasModifiers) {
/* TODO: MongoCollection::update() would return a boolean if
* $newObj was not empty, or an array describing the update
* operation. Improvise, since we only stored the file and that
* returns the "_id" field.
*/
return true;
}
}
// Now send the original update bringing the file up to date
$options = isset($options['safe']) ? $this->convertWriteConcern($options) : $options;
return $this->mongoCollection->update($query, $newObj, $options);
} | [
"protected",
"function",
"doUpdate",
"(",
"array",
"$",
"query",
",",
"array",
"$",
"newObj",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"file",
"=",
"isset",
"(",
"$",
"newObj",
"[",
"'$set'",
"]",
"[",
"'file'",
"]",
")",
"?",
... | Execute the update query and persist its GridFSFile if necessary.
@see Collection::doFindOne()
@param array $query
@param array $newObj
@param array $options
@return array|null | [
"Execute",
"the",
"update",
"query",
"and",
"persist",
"its",
"GridFSFile",
"if",
"necessary",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/GridFS.php#L209-L295 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/GridFS.php | GridFS.withPrimaryReadPreference | private function withPrimaryReadPreference(\Closure $closure)
{
$prevReadPref = $this->mongoCollection->getReadPreference();
$this->mongoCollection->setReadPreference(\MongoClient::RP_PRIMARY);
try {
return $closure();
} finally {
$prevTags = ! empty($prevReadPref['tagsets']) ? $prevReadPref['tagsets'] : [];
$this->mongoCollection->setReadPreference($prevReadPref['type'], $prevTags);
}
} | php | private function withPrimaryReadPreference(\Closure $closure)
{
$prevReadPref = $this->mongoCollection->getReadPreference();
$this->mongoCollection->setReadPreference(\MongoClient::RP_PRIMARY);
try {
return $closure();
} finally {
$prevTags = ! empty($prevReadPref['tagsets']) ? $prevReadPref['tagsets'] : [];
$this->mongoCollection->setReadPreference($prevReadPref['type'], $prevTags);
}
} | [
"private",
"function",
"withPrimaryReadPreference",
"(",
"\\",
"Closure",
"$",
"closure",
")",
"{",
"$",
"prevReadPref",
"=",
"$",
"this",
"->",
"mongoCollection",
"->",
"getReadPreference",
"(",
")",
";",
"$",
"this",
"->",
"mongoCollection",
"->",
"setReadPref... | Executes a closure with a temporary primary read preference.
@param \Closure $closure
@return mixed | [
"Executes",
"a",
"closure",
"with",
"a",
"temporary",
"primary",
"read",
"preference",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/GridFS.php#L304-L315 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Query/Query.php | Query.withPrimaryReadPreference | private function withPrimaryReadPreference($object, \Closure $closure)
{
$this->query['readPreference'] = \MongoClient::RP_PRIMARY;
$this->query['readPreferenceTags'] = null;
return $this->withReadPreference($object, $closure);
} | php | private function withPrimaryReadPreference($object, \Closure $closure)
{
$this->query['readPreference'] = \MongoClient::RP_PRIMARY;
$this->query['readPreferenceTags'] = null;
return $this->withReadPreference($object, $closure);
} | [
"private",
"function",
"withPrimaryReadPreference",
"(",
"$",
"object",
",",
"\\",
"Closure",
"$",
"closure",
")",
"{",
"$",
"this",
"->",
"query",
"[",
"'readPreference'",
"]",
"=",
"\\",
"MongoClient",
"::",
"RP_PRIMARY",
";",
"$",
"this",
"->",
"query",
... | Executes a closure with a temporary primary read preference on a database
or collection.
@param Database|Collection $object
@param \Closure $closure
@return mixed | [
"Executes",
"a",
"closure",
"with",
"a",
"temporary",
"primary",
"read",
"preference",
"on",
"a",
"database",
"or",
"collection",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Query/Query.php#L458-L464 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Connection.php | Connection.setMongo | public function setMongo($mongoClient)
{
if ( ! ($mongoClient instanceof \MongoClient || $mongoClient instanceof \Mongo)) {
throw new \InvalidArgumentException('MongoClient or Mongo instance required');
}
$this->mongoClient = $mongoClient;
} | php | public function setMongo($mongoClient)
{
if ( ! ($mongoClient instanceof \MongoClient || $mongoClient instanceof \Mongo)) {
throw new \InvalidArgumentException('MongoClient or Mongo instance required');
}
$this->mongoClient = $mongoClient;
} | [
"public",
"function",
"setMongo",
"(",
"$",
"mongoClient",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"mongoClient",
"instanceof",
"\\",
"MongoClient",
"||",
"$",
"mongoClient",
"instanceof",
"\\",
"Mongo",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentExcep... | Set the MongoClient instance to wrap.
@deprecated 1.1 Will be removed for 2.0
@param \MongoClient $mongoClient | [
"Set",
"the",
"MongoClient",
"instance",
"to",
"wrap",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Connection.php#L173-L180 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Connection.php | Connection.initialize | public function initialize()
{
if ($this->mongoClient !== null) {
return;
}
if ($this->eventManager->hasListeners(Events::preConnect)) {
$this->eventManager->dispatchEvent(Events::preConnect, new EventArgs($this));
}
$server = $this->server ?: 'mongodb://localhost:27017';
$options = $this->options;
$options = isset($options['timeout']) ? $this->convertConnectTimeout($options) : $options;
$options = isset($options['wTimeout']) ? $this->convertWriteTimeout($options) : $options;
$this->mongoClient = $this->retry(function() use ($server, $options) {
return new \MongoClient($server, $options, $this->driverOptions);
});
if ($this->eventManager->hasListeners(Events::postConnect)) {
$this->eventManager->dispatchEvent(Events::postConnect, new EventArgs($this));
}
} | php | public function initialize()
{
if ($this->mongoClient !== null) {
return;
}
if ($this->eventManager->hasListeners(Events::preConnect)) {
$this->eventManager->dispatchEvent(Events::preConnect, new EventArgs($this));
}
$server = $this->server ?: 'mongodb://localhost:27017';
$options = $this->options;
$options = isset($options['timeout']) ? $this->convertConnectTimeout($options) : $options;
$options = isset($options['wTimeout']) ? $this->convertWriteTimeout($options) : $options;
$this->mongoClient = $this->retry(function() use ($server, $options) {
return new \MongoClient($server, $options, $this->driverOptions);
});
if ($this->eventManager->hasListeners(Events::postConnect)) {
$this->eventManager->dispatchEvent(Events::postConnect, new EventArgs($this));
}
} | [
"public",
"function",
"initialize",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"mongoClient",
"!==",
"null",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"eventManager",
"->",
"hasListeners",
"(",
"Events",
"::",
"preConnect",
")",
")"... | Construct the wrapped MongoClient instance if necessary.
This method will dispatch preConnect and postConnect events. | [
"Construct",
"the",
"wrapped",
"MongoClient",
"instance",
"if",
"necessary",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Connection.php#L257-L280 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Connection.php | Connection.convertConnectTimeout | protected function convertConnectTimeout(array $options)
{
if (isset($options['timeout']) && ! isset($options['connectTimeoutMS'])) {
$options['connectTimeoutMS'] = $options['timeout'];
unset($options['timeout']);
}
return $options;
} | php | protected function convertConnectTimeout(array $options)
{
if (isset($options['timeout']) && ! isset($options['connectTimeoutMS'])) {
$options['connectTimeoutMS'] = $options['timeout'];
unset($options['timeout']);
}
return $options;
} | [
"protected",
"function",
"convertConnectTimeout",
"(",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'timeout'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"options",
"[",
"'connectTimeoutMS'",
"]",
")",
")",
"{",
"$",
... | Converts "timeout" MongoClient constructor option to "connectTimeoutMS"
for driver versions 1.4.0+.
Note: MongoClient actually allows case-insensitive option names, but
we'll only process the canonical version here.
@param array $options
@return array | [
"Converts",
"timeout",
"MongoClient",
"constructor",
"option",
"to",
"connectTimeoutMS",
"for",
"driver",
"versions",
"1",
".",
"4",
".",
"0",
"+",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Connection.php#L448-L456 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Aggregation/Expr.php | Expr.convertExpression | public static function convertExpression($expression)
{
if (is_array($expression)) {
return array_map(['static', 'convertExpression'], $expression);
} elseif ($expression instanceof self) {
return $expression->getExpression();
}
return $expression;
} | php | public static function convertExpression($expression)
{
if (is_array($expression)) {
return array_map(['static', 'convertExpression'], $expression);
} elseif ($expression instanceof self) {
return $expression->getExpression();
}
return $expression;
} | [
"public",
"static",
"function",
"convertExpression",
"(",
"$",
"expression",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"expression",
")",
")",
"{",
"return",
"array_map",
"(",
"[",
"'static'",
",",
"'convertExpression'",
"]",
",",
"$",
"expression",
")",
... | Converts an expression object into an array, recursing into nested items
For expression objects, it calls getExpression on the expression object.
For arrays, it recursively calls itself for each array item. Other values
are returned directly.
@param mixed|self $expression
@return string|array
@internal | [
"Converts",
"an",
"expression",
"object",
"into",
"an",
"array",
"recursing",
"into",
"nested",
"items"
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Aggregation/Expr.php#L324-L333 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Aggregation/Stage/Project.php | Project.excludeIdField | public function excludeIdField($exclude = true)
{
@trigger_error(__METHOD__ . ' has been deprecated in favor of excludeFields.', E_USER_DEPRECATED);
return $this->field('_id')->expression( ! $exclude);
} | php | public function excludeIdField($exclude = true)
{
@trigger_error(__METHOD__ . ' has been deprecated in favor of excludeFields.', E_USER_DEPRECATED);
return $this->field('_id')->expression( ! $exclude);
} | [
"public",
"function",
"excludeIdField",
"(",
"$",
"exclude",
"=",
"true",
")",
"{",
"@",
"trigger_error",
"(",
"__METHOD__",
".",
"' has been deprecated in favor of excludeFields.'",
",",
"E_USER_DEPRECATED",
")",
";",
"return",
"$",
"this",
"->",
"field",
"(",
"'... | Shorthand method to exclude the _id field.
@deprecated Deprecated in 1.5, please use {@link excludeFields()}.
@param bool $exclude
@return $this | [
"Shorthand",
"method",
"to",
"exclude",
"the",
"_id",
"field",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Aggregation/Stage/Project.php#L52-L57 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Aggregation/Stage/Project.php | Project.includeFields | public function includeFields(array $fields)
{
foreach ($fields as $fieldName) {
$this->field($fieldName)->expression(true);
}
return $this;
} | php | public function includeFields(array $fields)
{
foreach ($fields as $fieldName) {
$this->field($fieldName)->expression(true);
}
return $this;
} | [
"public",
"function",
"includeFields",
"(",
"array",
"$",
"fields",
")",
"{",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"fieldName",
")",
"{",
"$",
"this",
"->",
"field",
"(",
"$",
"fieldName",
")",
"->",
"expression",
"(",
"true",
")",
";",
"}",
"re... | Shorthand method to define which fields to be included.
@param array $fields
@return $this | [
"Shorthand",
"method",
"to",
"define",
"which",
"fields",
"to",
"be",
"included",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Aggregation/Stage/Project.php#L65-L72 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Aggregation/Stage/Project.php | Project.excludeFields | public function excludeFields(array $fields)
{
foreach ($fields as $fieldName) {
$this->field($fieldName)->expression(false);
}
return $this;
} | php | public function excludeFields(array $fields)
{
foreach ($fields as $fieldName) {
$this->field($fieldName)->expression(false);
}
return $this;
} | [
"public",
"function",
"excludeFields",
"(",
"array",
"$",
"fields",
")",
"{",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"fieldName",
")",
"{",
"$",
"this",
"->",
"field",
"(",
"$",
"fieldName",
")",
"->",
"expression",
"(",
"false",
")",
";",
"}",
"r... | Shorthand method to define which fields to be excluded.
If you specify the exclusion of a field other than _id, you cannot employ
any other $project specification forms.
@since 1.5
@param array $fields
@return $this | [
"Shorthand",
"method",
"to",
"define",
"which",
"fields",
"to",
"be",
"excluded",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Aggregation/Stage/Project.php#L84-L91 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Cursor.php | Cursor.getSingleResult | public function getSingleResult()
{
$originalLimit = $this->limit;
$originalUseIdentifierKeys = $this->useIdentifierKeys;
$this->reset();
$this->limit(1);
$this->setUseIdentifierKeys(false);
$result = current($this->toArray()) ?: null;
$this->reset();
$this->limit($originalLimit);
$this->setUseIdentifierKeys($originalUseIdentifierKeys);
return $result;
} | php | public function getSingleResult()
{
$originalLimit = $this->limit;
$originalUseIdentifierKeys = $this->useIdentifierKeys;
$this->reset();
$this->limit(1);
$this->setUseIdentifierKeys(false);
$result = current($this->toArray()) ?: null;
$this->reset();
$this->limit($originalLimit);
$this->setUseIdentifierKeys($originalUseIdentifierKeys);
return $result;
} | [
"public",
"function",
"getSingleResult",
"(",
")",
"{",
"$",
"originalLimit",
"=",
"$",
"this",
"->",
"limit",
";",
"$",
"originalUseIdentifierKeys",
"=",
"$",
"this",
"->",
"useIdentifierKeys",
";",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"$",
"this",
... | Reset the cursor and return its first result.
The cursor will be reset both before and after the single result is
fetched. The original cursor limit (if any) will remain in place.
@see Iterator::getSingleResult()
@return array|object|null | [
"Reset",
"the",
"cursor",
"and",
"return",
"its",
"first",
"result",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Cursor.php#L301-L317 | train |
doctrine/mongodb | lib/Doctrine/MongoDB/Cursor.php | Cursor.recreate | public function recreate()
{
$this->mongoCursor = $this->collection->getMongoCollection()->find($this->query, $this->fields);
if ($this->hint !== null) {
$this->mongoCursor->hint($this->hint);
}
if ($this->immortal !== null) {
$this->mongoCursor->immortal($this->immortal);
}
foreach ($this->options as $key => $value) {
$this->mongoCursor->addOption($key, $value);
}
if ($this->batchSize !== null) {
$this->mongoCursor->batchSize($this->batchSize);
}
if ($this->limit !== null) {
$this->mongoCursor->limit($this->limit);
}
if ($this->maxTimeMS !== null) {
$this->mongoCursor->maxTimeMS($this->maxTimeMS);
}
if ($this->skip !== null) {
$this->mongoCursor->skip($this->skip);
}
if ($this->slaveOkay !== null) {
$this->setMongoCursorSlaveOkay($this->slaveOkay);
}
// Set read preferences after slaveOkay, since they may be more specific
if ($this->readPreference !== null) {
if ($this->readPreferenceTags !== null) {
$this->mongoCursor->setReadPreference($this->readPreference, $this->readPreferenceTags);
} else {
$this->mongoCursor->setReadPreference($this->readPreference);
}
}
if ($this->snapshot) {
$this->mongoCursor->snapshot();
}
if ($this->sort !== null) {
$this->mongoCursor->sort($this->sort);
}
if ($this->tailable !== null) {
$this->mongoCursor->tailable($this->tailable);
}
if ($this->timeout !== null) {
$this->mongoCursor->timeout($this->timeout);
}
} | php | public function recreate()
{
$this->mongoCursor = $this->collection->getMongoCollection()->find($this->query, $this->fields);
if ($this->hint !== null) {
$this->mongoCursor->hint($this->hint);
}
if ($this->immortal !== null) {
$this->mongoCursor->immortal($this->immortal);
}
foreach ($this->options as $key => $value) {
$this->mongoCursor->addOption($key, $value);
}
if ($this->batchSize !== null) {
$this->mongoCursor->batchSize($this->batchSize);
}
if ($this->limit !== null) {
$this->mongoCursor->limit($this->limit);
}
if ($this->maxTimeMS !== null) {
$this->mongoCursor->maxTimeMS($this->maxTimeMS);
}
if ($this->skip !== null) {
$this->mongoCursor->skip($this->skip);
}
if ($this->slaveOkay !== null) {
$this->setMongoCursorSlaveOkay($this->slaveOkay);
}
// Set read preferences after slaveOkay, since they may be more specific
if ($this->readPreference !== null) {
if ($this->readPreferenceTags !== null) {
$this->mongoCursor->setReadPreference($this->readPreference, $this->readPreferenceTags);
} else {
$this->mongoCursor->setReadPreference($this->readPreference);
}
}
if ($this->snapshot) {
$this->mongoCursor->snapshot();
}
if ($this->sort !== null) {
$this->mongoCursor->sort($this->sort);
}
if ($this->tailable !== null) {
$this->mongoCursor->tailable($this->tailable);
}
if ($this->timeout !== null) {
$this->mongoCursor->timeout($this->timeout);
}
} | [
"public",
"function",
"recreate",
"(",
")",
"{",
"$",
"this",
"->",
"mongoCursor",
"=",
"$",
"this",
"->",
"collection",
"->",
"getMongoCollection",
"(",
")",
"->",
"find",
"(",
"$",
"this",
"->",
"query",
",",
"$",
"this",
"->",
"fields",
")",
";",
... | Recreates the internal MongoCursor. | [
"Recreates",
"the",
"internal",
"MongoCursor",
"."
] | c5b69ffeda86a256dfcee890ee831c3d1456421a | https://github.com/doctrine/mongodb/blob/c5b69ffeda86a256dfcee890ee831c3d1456421a/lib/Doctrine/MongoDB/Cursor.php#L463-L510 | train |
paragonie/csp-builder | src/CSPBuilder.php | CSPBuilder.compile | public function compile(): string
{
$ruleKeys = \array_keys($this->policies);
if (\in_array('report-only', $ruleKeys)) {
$this->reportOnly = !!$this->policies['report-only'];
} else {
$this->reportOnly = false;
}
$compiled = [];
foreach (self::$directives as $dir) {
if (\in_array($dir, $ruleKeys)) {
if (empty($ruleKeys)) {
if ($dir === 'base-uri') {
continue;
}
}
$compiled []= $this->compileSubgroup(
$dir,
$this->policies[$dir]
);
}
}
if (!empty($this->policies['report-uri'])) {
if (!\is_string($this->policies['report-uri'])) {
throw new \TypeError('report-uri policy somehow not a string');
}
if ($this->supportOldBrowsers) {
$compiled [] = 'report-uri ' . $this->policies['report-uri'] . '; ';
}
$compiled []= 'report-to ' . $this->policies['report-uri'] . '; ';
}
if (!empty($this->policies['upgrade-insecure-requests'])) {
$compiled []= 'upgrade-insecure-requests';
}
$this->compiled = \implode('', $compiled);
$this->needsCompile = false;
return $this->compiled;
} | php | public function compile(): string
{
$ruleKeys = \array_keys($this->policies);
if (\in_array('report-only', $ruleKeys)) {
$this->reportOnly = !!$this->policies['report-only'];
} else {
$this->reportOnly = false;
}
$compiled = [];
foreach (self::$directives as $dir) {
if (\in_array($dir, $ruleKeys)) {
if (empty($ruleKeys)) {
if ($dir === 'base-uri') {
continue;
}
}
$compiled []= $this->compileSubgroup(
$dir,
$this->policies[$dir]
);
}
}
if (!empty($this->policies['report-uri'])) {
if (!\is_string($this->policies['report-uri'])) {
throw new \TypeError('report-uri policy somehow not a string');
}
if ($this->supportOldBrowsers) {
$compiled [] = 'report-uri ' . $this->policies['report-uri'] . '; ';
}
$compiled []= 'report-to ' . $this->policies['report-uri'] . '; ';
}
if (!empty($this->policies['upgrade-insecure-requests'])) {
$compiled []= 'upgrade-insecure-requests';
}
$this->compiled = \implode('', $compiled);
$this->needsCompile = false;
return $this->compiled;
} | [
"public",
"function",
"compile",
"(",
")",
":",
"string",
"{",
"$",
"ruleKeys",
"=",
"\\",
"array_keys",
"(",
"$",
"this",
"->",
"policies",
")",
";",
"if",
"(",
"\\",
"in_array",
"(",
"'report-only'",
",",
"$",
"ruleKeys",
")",
")",
"{",
"$",
"this"... | Compile the current policies into a CSP header
@return string
@throws \TypeError | [
"Compile",
"the",
"current",
"policies",
"into",
"a",
"CSP",
"header"
] | 3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e | https://github.com/paragonie/csp-builder/blob/3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e/src/CSPBuilder.php#L88-L129 | train |
paragonie/csp-builder | src/CSPBuilder.php | CSPBuilder.addSource | public function addSource(string $directive, string $path): self
{
switch ($directive) {
case 'child':
case 'frame':
case 'frame-src':
if ($this->supportOldBrowsers) {
$this->policies['child-src']['allow'][] = $path;
$this->policies['frame-src']['allow'][] = $path;
return $this;
}
$directive = 'child-src';
break;
case 'connect':
case 'socket':
case 'websocket':
$directive = 'connect-src';
break;
case 'font':
case 'fonts':
$directive = 'font-src';
break;
case 'form':
case 'forms':
$directive = 'form-action';
break;
case 'ancestor':
case 'parent':
$directive = 'frame-ancestors';
break;
case 'img':
case 'image':
case 'image-src':
$directive = 'img-src';
break;
case 'media':
$directive = 'media-src';
break;
case 'object':
$directive = 'object-src';
break;
case 'js':
case 'javascript':
case 'script':
case 'scripts':
$directive = 'script-src';
break;
case 'style':
case 'css':
case 'css-src':
$directive = 'style-src';
break;
case 'worker':
$directive = 'worker-src';
break;
}
$this->policies[$directive]['allow'][] = $path;
return $this;
} | php | public function addSource(string $directive, string $path): self
{
switch ($directive) {
case 'child':
case 'frame':
case 'frame-src':
if ($this->supportOldBrowsers) {
$this->policies['child-src']['allow'][] = $path;
$this->policies['frame-src']['allow'][] = $path;
return $this;
}
$directive = 'child-src';
break;
case 'connect':
case 'socket':
case 'websocket':
$directive = 'connect-src';
break;
case 'font':
case 'fonts':
$directive = 'font-src';
break;
case 'form':
case 'forms':
$directive = 'form-action';
break;
case 'ancestor':
case 'parent':
$directive = 'frame-ancestors';
break;
case 'img':
case 'image':
case 'image-src':
$directive = 'img-src';
break;
case 'media':
$directive = 'media-src';
break;
case 'object':
$directive = 'object-src';
break;
case 'js':
case 'javascript':
case 'script':
case 'scripts':
$directive = 'script-src';
break;
case 'style':
case 'css':
case 'css-src':
$directive = 'style-src';
break;
case 'worker':
$directive = 'worker-src';
break;
}
$this->policies[$directive]['allow'][] = $path;
return $this;
} | [
"public",
"function",
"addSource",
"(",
"string",
"$",
"directive",
",",
"string",
"$",
"path",
")",
":",
"self",
"{",
"switch",
"(",
"$",
"directive",
")",
"{",
"case",
"'child'",
":",
"case",
"'frame'",
":",
"case",
"'frame-src'",
":",
"if",
"(",
"$"... | Add a source to our allow white-list
@param string $directive
@param string $path
@return self | [
"Add",
"a",
"source",
"to",
"our",
"allow",
"white",
"-",
"list"
] | 3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e | https://github.com/paragonie/csp-builder/blob/3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e/src/CSPBuilder.php#L139-L197 | train |
paragonie/csp-builder | src/CSPBuilder.php | CSPBuilder.addDirective | public function addDirective(string $key, $value = null): self
{
if ($value === null) {
if (!isset($this->policies[$key])) {
$this->policies[$key] = true;
}
} elseif (empty($this->policies[$key])) {
$this->policies[$key] = $value;
}
return $this;
} | php | public function addDirective(string $key, $value = null): self
{
if ($value === null) {
if (!isset($this->policies[$key])) {
$this->policies[$key] = true;
}
} elseif (empty($this->policies[$key])) {
$this->policies[$key] = $value;
}
return $this;
} | [
"public",
"function",
"addDirective",
"(",
"string",
"$",
"key",
",",
"$",
"value",
"=",
"null",
")",
":",
"self",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"policies",
"[",
"$",
"key"... | Add a directive if it doesn't already exist
If it already exists, do nothing
@param string $key
@param mixed $value
@return self | [
"Add",
"a",
"directive",
"if",
"it",
"doesn",
"t",
"already",
"exist"
] | 3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e | https://github.com/paragonie/csp-builder/blob/3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e/src/CSPBuilder.php#L209-L219 | train |
paragonie/csp-builder | src/CSPBuilder.php | CSPBuilder.allowPluginType | public function allowPluginType(string $mime = 'text/plain'): self
{
$this->policies['plugin-types']['types'] []= $mime;
$this->needsCompile = true;
return $this;
} | php | public function allowPluginType(string $mime = 'text/plain'): self
{
$this->policies['plugin-types']['types'] []= $mime;
$this->needsCompile = true;
return $this;
} | [
"public",
"function",
"allowPluginType",
"(",
"string",
"$",
"mime",
"=",
"'text/plain'",
")",
":",
"self",
"{",
"$",
"this",
"->",
"policies",
"[",
"'plugin-types'",
"]",
"[",
"'types'",
"]",
"[",
"]",
"=",
"$",
"mime",
";",
"$",
"this",
"->",
"needsC... | Add a plugin type to be added
@param string $mime
@return self | [
"Add",
"a",
"plugin",
"type",
"to",
"be",
"added"
] | 3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e | https://github.com/paragonie/csp-builder/blob/3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e/src/CSPBuilder.php#L227-L233 | train |
paragonie/csp-builder | src/CSPBuilder.php | CSPBuilder.fromFile | public static function fromFile(string $filename = ''): self
{
if (!\file_exists($filename)) {
throw new \Exception($filename.' does not exist');
}
$contents = \file_get_contents($filename);
if (!\is_string($contents)) {
throw new \Exception('Could not read file contents');
}
return self::fromData($contents);
} | php | public static function fromFile(string $filename = ''): self
{
if (!\file_exists($filename)) {
throw new \Exception($filename.' does not exist');
}
$contents = \file_get_contents($filename);
if (!\is_string($contents)) {
throw new \Exception('Could not read file contents');
}
return self::fromData($contents);
} | [
"public",
"static",
"function",
"fromFile",
"(",
"string",
"$",
"filename",
"=",
"''",
")",
":",
"self",
"{",
"if",
"(",
"!",
"\\",
"file_exists",
"(",
"$",
"filename",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"filename",
".",
"' d... | Factory method - create a new CSPBuilder object from a JSON file
@param string $filename
@return self
@throws \Exception | [
"Factory",
"method",
"-",
"create",
"a",
"new",
"CSPBuilder",
"object",
"from",
"a",
"JSON",
"file"
] | 3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e | https://github.com/paragonie/csp-builder/blob/3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e/src/CSPBuilder.php#L298-L308 | train |
paragonie/csp-builder | src/CSPBuilder.php | CSPBuilder.getHeaderArray | public function getHeaderArray(bool $legacy = true): array
{
if ($this->needsCompile) {
$this->compile();
}
$return = [];
foreach ($this->getHeaderKeys($legacy) as $key) {
$return[(string) $key] = $this->compiled;
}
return $return;
} | php | public function getHeaderArray(bool $legacy = true): array
{
if ($this->needsCompile) {
$this->compile();
}
$return = [];
foreach ($this->getHeaderKeys($legacy) as $key) {
$return[(string) $key] = $this->compiled;
}
return $return;
} | [
"public",
"function",
"getHeaderArray",
"(",
"bool",
"$",
"legacy",
"=",
"true",
")",
":",
"array",
"{",
"if",
"(",
"$",
"this",
"->",
"needsCompile",
")",
"{",
"$",
"this",
"->",
"compile",
"(",
")",
";",
"}",
"$",
"return",
"=",
"[",
"]",
";",
... | Get an associative array of headers to return.
@param bool $legacy
@return array<string, string> | [
"Get",
"an",
"associative",
"array",
"of",
"headers",
"to",
"return",
"."
] | 3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e | https://github.com/paragonie/csp-builder/blob/3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e/src/CSPBuilder.php#L329-L339 | train |
paragonie/csp-builder | src/CSPBuilder.php | CSPBuilder.hash | public function hash(
string $directive = 'script-src',
string $script = '',
string $algorithm = 'sha384'
): self {
$ruleKeys = \array_keys($this->policies);
if (\in_array($directive, $ruleKeys)) {
$this->policies[$directive]['hashes'] []= [
$algorithm => Base64::encode(
\hash($algorithm, $script, true)
)
];
}
return $this;
} | php | public function hash(
string $directive = 'script-src',
string $script = '',
string $algorithm = 'sha384'
): self {
$ruleKeys = \array_keys($this->policies);
if (\in_array($directive, $ruleKeys)) {
$this->policies[$directive]['hashes'] []= [
$algorithm => Base64::encode(
\hash($algorithm, $script, true)
)
];
}
return $this;
} | [
"public",
"function",
"hash",
"(",
"string",
"$",
"directive",
"=",
"'script-src'",
",",
"string",
"$",
"script",
"=",
"''",
",",
"string",
"$",
"algorithm",
"=",
"'sha384'",
")",
":",
"self",
"{",
"$",
"ruleKeys",
"=",
"\\",
"array_keys",
"(",
"$",
"t... | Add a new hash to the existing CSP
@param string $directive
@param string $script
@param string $algorithm
@return self | [
"Add",
"a",
"new",
"hash",
"to",
"the",
"existing",
"CSP"
] | 3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e | https://github.com/paragonie/csp-builder/blob/3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e/src/CSPBuilder.php#L364-L378 | train |
paragonie/csp-builder | src/CSPBuilder.php | CSPBuilder.injectCSPHeader | public function injectCSPHeader(MessageInterface $message, bool $legacy = false): MessageInterface
{
if ($this->needsCompile) {
$this->compile();
}
foreach ($this->getRequireHeaders() as $header) {
list ($key, $value) = $header;
$message = $message->withAddedHeader($key, $value);
}
foreach ($this->getHeaderKeys($legacy) as $key) {
$message = $message->withAddedHeader($key, $this->compiled);
}
return $message;
} | php | public function injectCSPHeader(MessageInterface $message, bool $legacy = false): MessageInterface
{
if ($this->needsCompile) {
$this->compile();
}
foreach ($this->getRequireHeaders() as $header) {
list ($key, $value) = $header;
$message = $message->withAddedHeader($key, $value);
}
foreach ($this->getHeaderKeys($legacy) as $key) {
$message = $message->withAddedHeader($key, $this->compiled);
}
return $message;
} | [
"public",
"function",
"injectCSPHeader",
"(",
"MessageInterface",
"$",
"message",
",",
"bool",
"$",
"legacy",
"=",
"false",
")",
":",
"MessageInterface",
"{",
"if",
"(",
"$",
"this",
"->",
"needsCompile",
")",
"{",
"$",
"this",
"->",
"compile",
"(",
")",
... | PSR-7 header injection.
This will inject the header into your PSR-7 object. (Request, Response,
etc.) This method returns an instance of whatever you passed, so long
as it implements MessageInterface.
@param \Psr\Http\Message\MessageInterface $message
@param bool $legacy
@return \Psr\Http\Message\MessageInterface | [
"PSR",
"-",
"7",
"header",
"injection",
"."
] | 3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e | https://github.com/paragonie/csp-builder/blob/3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e/src/CSPBuilder.php#L391-L404 | train |
paragonie/csp-builder | src/CSPBuilder.php | CSPBuilder.nonce | public function nonce(string $directive = 'script-src', string $nonce = ''): string
{
$ruleKeys = \array_keys($this->policies);
if (!\in_array($directive, $ruleKeys)) {
return '';
}
if (empty($nonce)) {
$nonce = Base64::encode(\random_bytes(18));
}
$this->policies[$directive]['nonces'] []= $nonce;
return $nonce;
} | php | public function nonce(string $directive = 'script-src', string $nonce = ''): string
{
$ruleKeys = \array_keys($this->policies);
if (!\in_array($directive, $ruleKeys)) {
return '';
}
if (empty($nonce)) {
$nonce = Base64::encode(\random_bytes(18));
}
$this->policies[$directive]['nonces'] []= $nonce;
return $nonce;
} | [
"public",
"function",
"nonce",
"(",
"string",
"$",
"directive",
"=",
"'script-src'",
",",
"string",
"$",
"nonce",
"=",
"''",
")",
":",
"string",
"{",
"$",
"ruleKeys",
"=",
"\\",
"array_keys",
"(",
"$",
"this",
"->",
"policies",
")",
";",
"if",
"(",
"... | Add a new nonce to the existing CSP. Returns the nonce generated.
@param string $directive
@param string $nonce (if empty, it will be generated)
@return string
@throws \Exception | [
"Add",
"a",
"new",
"nonce",
"to",
"the",
"existing",
"CSP",
".",
"Returns",
"the",
"nonce",
"generated",
"."
] | 3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e | https://github.com/paragonie/csp-builder/blob/3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e/src/CSPBuilder.php#L414-L426 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.