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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
markuspoerschke/iCal | src/Property/Event/RecurrenceRule.php | RecurrenceRule.setBySecond | public function setBySecond($value)
{
if (!is_integer($value) || $value < 0 || $value > 60) {
throw new \InvalidArgumentException('Invalid value for BYSECOND');
}
$this->bySecond = $value;
$this->canUseBySetPos = true;
return $this;
} | php | public function setBySecond($value)
{
if (!is_integer($value) || $value < 0 || $value > 60) {
throw new \InvalidArgumentException('Invalid value for BYSECOND');
}
$this->bySecond = $value;
$this->canUseBySetPos = true;
return $this;
} | [
"public",
"function",
"setBySecond",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_integer",
"(",
"$",
"value",
")",
"||",
"$",
"value",
"<",
"0",
"||",
"$",
"value",
">",
"60",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'In... | The BYSECOND rule part specifies a COMMA-separated list of seconds within a minute.
Valid values are 0 to 60.
@param int $value
@return $this
@throws \InvalidArgumentException | [
"The",
"BYSECOND",
"rule",
"part",
"specifies",
"a",
"COMMA",
"-",
"separated",
"list",
"of",
"seconds",
"within",
"a",
"minute",
".",
"Valid",
"values",
"are",
"0",
"to",
"60",
"."
] | 42155dc800a9bb5058fbad3ecf208401efb454dc | https://github.com/markuspoerschke/iCal/blob/42155dc800a9bb5058fbad3ecf208401efb454dc/src/Property/Event/RecurrenceRule.php#L538-L549 | train |
markuspoerschke/iCal | src/Property.php | Property.toLine | public function toLine()
{
// Property-name
$line = $this->getName();
// Adding params
//@todo added check for $this->parameterBag because doctrine/orm proxies won't execute constructor - ok?
if ($this->parameterBag && $this->parameterBag->hasParams()) {
$line .= ';' . $this->parameterBag->toString();
}
// Property value
$line .= ':' . $this->value->getEscapedValue();
return $line;
} | php | public function toLine()
{
// Property-name
$line = $this->getName();
// Adding params
//@todo added check for $this->parameterBag because doctrine/orm proxies won't execute constructor - ok?
if ($this->parameterBag && $this->parameterBag->hasParams()) {
$line .= ';' . $this->parameterBag->toString();
}
// Property value
$line .= ':' . $this->value->getEscapedValue();
return $line;
} | [
"public",
"function",
"toLine",
"(",
")",
"{",
"// Property-name",
"$",
"line",
"=",
"$",
"this",
"->",
"getName",
"(",
")",
";",
"// Adding params",
"//@todo added check for $this->parameterBag because doctrine/orm proxies won't execute constructor - ok?",
"if",
"(",
"$",
... | Renders an unfolded line.
@return string | [
"Renders",
"an",
"unfolded",
"line",
"."
] | 42155dc800a9bb5058fbad3ecf208401efb454dc | https://github.com/markuspoerschke/iCal/blob/42155dc800a9bb5058fbad3ecf208401efb454dc/src/Property.php#L63-L78 | train |
markuspoerschke/iCal | src/Util/DateUtil.php | DateUtil.getDateString | public static function getDateString(\DateTimeInterface $dateTime = null, $noTime = false, $useTimezone = false, $useUtc = false)
{
if (empty($dateTime)) {
$dateTime = new \DateTimeImmutable();
}
// Only convert the DateTime to UTC if there is a time present. For date-only the
// timezone is meaningless and converting it might shift it to the wrong date.
// Do not convert DateTime to UTC if a timezone it specified, as it should be local time.
if (!$noTime && $useUtc && !$useTimezone) {
$dateTime = clone $dateTime;
$dateTime = $dateTime->setTimezone(new \DateTimeZone('UTC'));
}
return $dateTime->format(self::getDateFormat($noTime, $useTimezone, $useUtc));
} | php | public static function getDateString(\DateTimeInterface $dateTime = null, $noTime = false, $useTimezone = false, $useUtc = false)
{
if (empty($dateTime)) {
$dateTime = new \DateTimeImmutable();
}
// Only convert the DateTime to UTC if there is a time present. For date-only the
// timezone is meaningless and converting it might shift it to the wrong date.
// Do not convert DateTime to UTC if a timezone it specified, as it should be local time.
if (!$noTime && $useUtc && !$useTimezone) {
$dateTime = clone $dateTime;
$dateTime = $dateTime->setTimezone(new \DateTimeZone('UTC'));
}
return $dateTime->format(self::getDateFormat($noTime, $useTimezone, $useUtc));
} | [
"public",
"static",
"function",
"getDateString",
"(",
"\\",
"DateTimeInterface",
"$",
"dateTime",
"=",
"null",
",",
"$",
"noTime",
"=",
"false",
",",
"$",
"useTimezone",
"=",
"false",
",",
"$",
"useUtc",
"=",
"false",
")",
"{",
"if",
"(",
"empty",
"(",
... | Returns a formatted date string.
@param \DateTimeInterface|null $dateTime The DateTime object
@param bool $noTime Indicates if the time will be added
@param bool $useTimezone
@param bool $useUtc
@return mixed | [
"Returns",
"a",
"formatted",
"date",
"string",
"."
] | 42155dc800a9bb5058fbad3ecf208401efb454dc | https://github.com/markuspoerschke/iCal/blob/42155dc800a9bb5058fbad3ecf208401efb454dc/src/Util/DateUtil.php#L42-L57 | train |
markuspoerschke/iCal | src/Component.php | Component.addComponent | public function addComponent(self $component, $key = null)
{
if (null == $key) {
$this->components[] = $component;
} else {
$this->components[$key] = $component;
}
} | php | public function addComponent(self $component, $key = null)
{
if (null == $key) {
$this->components[] = $component;
} else {
$this->components[$key] = $component;
}
} | [
"public",
"function",
"addComponent",
"(",
"self",
"$",
"component",
",",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"==",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"components",
"[",
"]",
"=",
"$",
"component",
";",
"}",
"else",
"{",
"... | Adds a Component.
If $key is given, the component at $key will be replaced else the component will be append.
@param Component $component The Component that will be added
@param null $key The key of the Component | [
"Adds",
"a",
"Component",
"."
] | 42155dc800a9bb5058fbad3ecf208401efb454dc | https://github.com/markuspoerschke/iCal/blob/42155dc800a9bb5058fbad3ecf208401efb454dc/src/Component.php#L63-L70 | train |
markuspoerschke/iCal | src/Component.php | Component.build | public function build()
{
$lines = [];
$lines[] = sprintf('BEGIN:%s', $this->getType());
/** @var $property Property */
foreach ($this->buildPropertyBag() as $property) {
foreach ($property->toLines() as $l) {
$lines[] = $l;
}
}
$this->buildComponents($lines);
$lines[] = sprintf('END:%s', $this->getType());
$ret = [];
foreach ($lines as $line) {
foreach (ComponentUtil::fold($line) as $l) {
$ret[] = $l;
}
}
return $ret;
} | php | public function build()
{
$lines = [];
$lines[] = sprintf('BEGIN:%s', $this->getType());
/** @var $property Property */
foreach ($this->buildPropertyBag() as $property) {
foreach ($property->toLines() as $l) {
$lines[] = $l;
}
}
$this->buildComponents($lines);
$lines[] = sprintf('END:%s', $this->getType());
$ret = [];
foreach ($lines as $line) {
foreach (ComponentUtil::fold($line) as $l) {
$ret[] = $l;
}
}
return $ret;
} | [
"public",
"function",
"build",
"(",
")",
"{",
"$",
"lines",
"=",
"[",
"]",
";",
"$",
"lines",
"[",
"]",
"=",
"sprintf",
"(",
"'BEGIN:%s'",
",",
"$",
"this",
"->",
"getType",
"(",
")",
")",
";",
"/** @var $property Property */",
"foreach",
"(",
"$",
"... | Renders an array containing the lines of the iCal file.
@return array | [
"Renders",
"an",
"array",
"containing",
"the",
"lines",
"of",
"the",
"iCal",
"file",
"."
] | 42155dc800a9bb5058fbad3ecf208401efb454dc | https://github.com/markuspoerschke/iCal/blob/42155dc800a9bb5058fbad3ecf208401efb454dc/src/Component.php#L90-L116 | train |
sonata-project/SonataMediaBundle | src/DependencyInjection/SonataMediaExtension.php | SonataMediaExtension.configureCdnAdapter | public function configureCdnAdapter(ContainerBuilder $container, array $config)
{
// add the default configuration for the server cdn
if ($container->hasDefinition('sonata.media.cdn.server') && isset($config['cdn']['server'])) {
$container->getDefinition('sonata.media.cdn.server')
->replaceArgument(0, $config['cdn']['server']['path'])
;
} else {
$container->removeDefinition('sonata.media.cdn.server');
}
if ($container->hasDefinition('sonata.media.cdn.panther') && isset($config['cdn']['panther'])) {
$container->getDefinition('sonata.media.cdn.panther')
->replaceArgument(0, $config['cdn']['panther']['path'])
->replaceArgument(1, $config['cdn']['panther']['username'])
->replaceArgument(2, $config['cdn']['panther']['password'])
->replaceArgument(3, $config['cdn']['panther']['site_id'])
;
} else {
$container->removeDefinition('sonata.media.cdn.panther');
}
if ($container->hasDefinition('sonata.media.cdn.cloudfront') && isset($config['cdn']['cloudfront'])) {
$container->getDefinition('sonata.media.cdn.cloudfront')
->replaceArgument(0, $config['cdn']['cloudfront']['path'])
->replaceArgument(1, $config['cdn']['cloudfront']['key'])
->replaceArgument(2, $config['cdn']['cloudfront']['secret'])
->replaceArgument(3, $config['cdn']['cloudfront']['distribution_id'])
;
} else {
$container->removeDefinition('sonata.media.cdn.cloudfront');
}
if ($container->hasDefinition('sonata.media.cdn.fallback') && isset($config['cdn']['fallback'])) {
$container->getDefinition('sonata.media.cdn.fallback')
->replaceArgument(0, new Reference($config['cdn']['fallback']['master']))
->replaceArgument(1, new Reference($config['cdn']['fallback']['fallback']))
;
} else {
$container->removeDefinition('sonata.media.cdn.fallback');
}
} | php | public function configureCdnAdapter(ContainerBuilder $container, array $config)
{
// add the default configuration for the server cdn
if ($container->hasDefinition('sonata.media.cdn.server') && isset($config['cdn']['server'])) {
$container->getDefinition('sonata.media.cdn.server')
->replaceArgument(0, $config['cdn']['server']['path'])
;
} else {
$container->removeDefinition('sonata.media.cdn.server');
}
if ($container->hasDefinition('sonata.media.cdn.panther') && isset($config['cdn']['panther'])) {
$container->getDefinition('sonata.media.cdn.panther')
->replaceArgument(0, $config['cdn']['panther']['path'])
->replaceArgument(1, $config['cdn']['panther']['username'])
->replaceArgument(2, $config['cdn']['panther']['password'])
->replaceArgument(3, $config['cdn']['panther']['site_id'])
;
} else {
$container->removeDefinition('sonata.media.cdn.panther');
}
if ($container->hasDefinition('sonata.media.cdn.cloudfront') && isset($config['cdn']['cloudfront'])) {
$container->getDefinition('sonata.media.cdn.cloudfront')
->replaceArgument(0, $config['cdn']['cloudfront']['path'])
->replaceArgument(1, $config['cdn']['cloudfront']['key'])
->replaceArgument(2, $config['cdn']['cloudfront']['secret'])
->replaceArgument(3, $config['cdn']['cloudfront']['distribution_id'])
;
} else {
$container->removeDefinition('sonata.media.cdn.cloudfront');
}
if ($container->hasDefinition('sonata.media.cdn.fallback') && isset($config['cdn']['fallback'])) {
$container->getDefinition('sonata.media.cdn.fallback')
->replaceArgument(0, new Reference($config['cdn']['fallback']['master']))
->replaceArgument(1, new Reference($config['cdn']['fallback']['fallback']))
;
} else {
$container->removeDefinition('sonata.media.cdn.fallback');
}
} | [
"public",
"function",
"configureCdnAdapter",
"(",
"ContainerBuilder",
"$",
"container",
",",
"array",
"$",
"config",
")",
"{",
"// add the default configuration for the server cdn",
"if",
"(",
"$",
"container",
"->",
"hasDefinition",
"(",
"'sonata.media.cdn.server'",
")",... | Inject CDN dependency to default provider.
@param ContainerBuilder $container
@param array $config | [
"Inject",
"CDN",
"dependency",
"to",
"default",
"provider",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/DependencyInjection/SonataMediaExtension.php#L364-L405 | train |
sonata-project/SonataMediaBundle | src/DependencyInjection/SonataMediaExtension.php | SonataMediaExtension.configureClassesToCompile | public function configureClassesToCompile()
{
if (\PHP_VERSION_ID >= 70000) {
return;
}
$this->addClassesToCompile([
CDNInterface::class,
CloudFront::class,
Fallback::class,
PantherPortal::class,
Server::class,
Pixlr::class,
Local::class,
Replicate::class,
DefaultGenerator::class,
GeneratorInterface::class,
ODMGenerator::class,
PHPCRGenerator::class,
AmazonMetadataBuilder::class,
MetadataBuilderInterface::class,
NoopMetadataBuilder::class,
ProxyMetadataBuilder::class,
Gallery::class,
GalleryHasMedia::class,
GalleryHasMediaInterface::class,
GalleryInterface::class,
GalleryManager::class,
GalleryManagerInterface::class,
Media::class,
MediaInterface::class,
MediaManagerInterface::class,
BaseProvider::class,
BaseVideoProvider::class,
DailyMotionProvider::class,
FileProvider::class,
ImageProvider::class,
MediaProviderInterface::class,
Pool::class,
VimeoProvider::class,
YouTubeProvider::class,
ResizerInterface::class,
SimpleResizer::class,
SquareResizer::class,
DownloadStrategyInterface::class,
ForbiddenDownloadStrategy::class,
PublicDownloadStrategy::class,
RolesDownloadStrategy::class,
SessionDownloadStrategy::class,
ConsumerThumbnail::class,
FormatThumbnail::class,
ThumbnailInterface::class,
MediaExtension::class,
]);
} | php | public function configureClassesToCompile()
{
if (\PHP_VERSION_ID >= 70000) {
return;
}
$this->addClassesToCompile([
CDNInterface::class,
CloudFront::class,
Fallback::class,
PantherPortal::class,
Server::class,
Pixlr::class,
Local::class,
Replicate::class,
DefaultGenerator::class,
GeneratorInterface::class,
ODMGenerator::class,
PHPCRGenerator::class,
AmazonMetadataBuilder::class,
MetadataBuilderInterface::class,
NoopMetadataBuilder::class,
ProxyMetadataBuilder::class,
Gallery::class,
GalleryHasMedia::class,
GalleryHasMediaInterface::class,
GalleryInterface::class,
GalleryManager::class,
GalleryManagerInterface::class,
Media::class,
MediaInterface::class,
MediaManagerInterface::class,
BaseProvider::class,
BaseVideoProvider::class,
DailyMotionProvider::class,
FileProvider::class,
ImageProvider::class,
MediaProviderInterface::class,
Pool::class,
VimeoProvider::class,
YouTubeProvider::class,
ResizerInterface::class,
SimpleResizer::class,
SquareResizer::class,
DownloadStrategyInterface::class,
ForbiddenDownloadStrategy::class,
PublicDownloadStrategy::class,
RolesDownloadStrategy::class,
SessionDownloadStrategy::class,
ConsumerThumbnail::class,
FormatThumbnail::class,
ThumbnailInterface::class,
MediaExtension::class,
]);
} | [
"public",
"function",
"configureClassesToCompile",
"(",
")",
"{",
"if",
"(",
"\\",
"PHP_VERSION_ID",
">=",
"70000",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"addClassesToCompile",
"(",
"[",
"CDNInterface",
"::",
"class",
",",
"CloudFront",
"::",
"cla... | Add class to compile. | [
"Add",
"class",
"to",
"compile",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/DependencyInjection/SonataMediaExtension.php#L556-L610 | train |
sonata-project/SonataMediaBundle | src/DependencyInjection/Compiler/AddProviderCompilerPass.php | AddProviderCompilerPass.applyFormats | public function applyFormats(ContainerBuilder $container, array $settings)
{
foreach ($settings['contexts'] as $name => $context) {
// add the different related formats
foreach ($context['providers'] as $id) {
$definition = $container->getDefinition($id);
foreach ($context['formats'] as $format => $config) {
$config['quality'] = $config['quality'] ?? 80;
$config['format'] = $config['format'] ?? 'jpg';
$config['height'] = $config['height'] ?? null;
$config['constraint'] = $config['constraint'] ?? true;
$config['resizer'] = $config['resizer'] ?? false;
$formatName = sprintf('%s_%s', $name, $format);
$definition->addMethodCall('addFormat', [$formatName, $config]);
}
}
}
} | php | public function applyFormats(ContainerBuilder $container, array $settings)
{
foreach ($settings['contexts'] as $name => $context) {
// add the different related formats
foreach ($context['providers'] as $id) {
$definition = $container->getDefinition($id);
foreach ($context['formats'] as $format => $config) {
$config['quality'] = $config['quality'] ?? 80;
$config['format'] = $config['format'] ?? 'jpg';
$config['height'] = $config['height'] ?? null;
$config['constraint'] = $config['constraint'] ?? true;
$config['resizer'] = $config['resizer'] ?? false;
$formatName = sprintf('%s_%s', $name, $format);
$definition->addMethodCall('addFormat', [$formatName, $config]);
}
}
}
} | [
"public",
"function",
"applyFormats",
"(",
"ContainerBuilder",
"$",
"container",
",",
"array",
"$",
"settings",
")",
"{",
"foreach",
"(",
"$",
"settings",
"[",
"'contexts'",
"]",
"as",
"$",
"name",
"=>",
"$",
"context",
")",
"{",
"// add the different related ... | Define the default settings to the config array.
@param ContainerBuilder $container
@param array $settings | [
"Define",
"the",
"default",
"settings",
"to",
"the",
"config",
"array",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/DependencyInjection/Compiler/AddProviderCompilerPass.php#L110-L129 | train |
sonata-project/SonataMediaBundle | src/Templating/Helper/MediaHelper.php | MediaHelper.media | public function media($media, $format, $options = [])
{
if (!$media) {
return '';
}
$provider = $this->getProvider($media);
$format = $provider->getFormatName($media, $format);
$options = $provider->getHelperProperties($media, $format, $options);
return $this->templating->render($provider->getTemplate('helper_view'), [
'media' => $media,
'format' => $format,
'options' => $options,
]);
} | php | public function media($media, $format, $options = [])
{
if (!$media) {
return '';
}
$provider = $this->getProvider($media);
$format = $provider->getFormatName($media, $format);
$options = $provider->getHelperProperties($media, $format, $options);
return $this->templating->render($provider->getTemplate('helper_view'), [
'media' => $media,
'format' => $format,
'options' => $options,
]);
} | [
"public",
"function",
"media",
"(",
"$",
"media",
",",
"$",
"format",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"media",
")",
"{",
"return",
"''",
";",
"}",
"$",
"provider",
"=",
"$",
"this",
"->",
"getProvider",
"(",
"... | Returns the provider view for the provided media.
@param MediaInterface $media
@param string $format
@param array $options
@return string | [
"Returns",
"the",
"provider",
"view",
"for",
"the",
"provided",
"media",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/Templating/Helper/MediaHelper.php#L69-L86 | train |
sonata-project/SonataMediaBundle | src/Controller/GalleryAdminController.php | GalleryAdminController.listAction | public function listAction(Request $request = null)
{
$this->admin->checkAccess('list');
if ($listMode = $request->get('_list_mode')) {
$this->admin->setListMode($listMode);
}
$datagrid = $this->admin->getDatagrid();
$datagrid->setValue('context', null, $this->admin->getPersistentParameter('context'));
$formView = $datagrid->getForm()->createView();
// set the theme for the current Admin Form
$this->setFormTheme($formView, $this->admin->getFilterTheme());
return $this->render($this->admin->getTemplate('list'), [
'action' => 'list',
'form' => $formView,
'datagrid' => $datagrid,
'csrf_token' => $this->getCsrfToken('sonata.batch'),
]);
} | php | public function listAction(Request $request = null)
{
$this->admin->checkAccess('list');
if ($listMode = $request->get('_list_mode')) {
$this->admin->setListMode($listMode);
}
$datagrid = $this->admin->getDatagrid();
$datagrid->setValue('context', null, $this->admin->getPersistentParameter('context'));
$formView = $datagrid->getForm()->createView();
// set the theme for the current Admin Form
$this->setFormTheme($formView, $this->admin->getFilterTheme());
return $this->render($this->admin->getTemplate('list'), [
'action' => 'list',
'form' => $formView,
'datagrid' => $datagrid,
'csrf_token' => $this->getCsrfToken('sonata.batch'),
]);
} | [
"public",
"function",
"listAction",
"(",
"Request",
"$",
"request",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"admin",
"->",
"checkAccess",
"(",
"'list'",
")",
";",
"if",
"(",
"$",
"listMode",
"=",
"$",
"request",
"->",
"get",
"(",
"'_list_mode'",
")",... | return the Response object associated to the list action.
@param Request $request
@return Response | [
"return",
"the",
"Response",
"object",
"associated",
"to",
"the",
"list",
"action",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/Controller/GalleryAdminController.php#L50-L72 | train |
sonata-project/SonataMediaBundle | src/Command/UpdateCdnStatusCommand.php | UpdateCdnStatusCommand.log | protected function log($message, $newLine = true)
{
if (false === $this->quiet) {
if ($newLine) {
$this->output->writeln($message);
} else {
$this->output->write($message);
}
}
} | php | protected function log($message, $newLine = true)
{
if (false === $this->quiet) {
if ($newLine) {
$this->output->writeln($message);
} else {
$this->output->write($message);
}
}
} | [
"protected",
"function",
"log",
"(",
"$",
"message",
",",
"$",
"newLine",
"=",
"true",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"quiet",
")",
"{",
"if",
"(",
"$",
"newLine",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"... | Write a message to the output.
@param string $message
@param bool|true $newLine | [
"Write",
"a",
"message",
"to",
"the",
"output",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/Command/UpdateCdnStatusCommand.php#L135-L144 | train |
sonata-project/SonataMediaBundle | src/Controller/Api/GalleryController.php | GalleryController.getGalleryMediasAction | public function getGalleryMediasAction($id)
{
$ghms = $this->getGallery($id)->getGalleryHasMedias();
$media = [];
foreach ($ghms as $ghm) {
$media[] = $ghm->getMedia();
}
return $media;
} | php | public function getGalleryMediasAction($id)
{
$ghms = $this->getGallery($id)->getGalleryHasMedias();
$media = [];
foreach ($ghms as $ghm) {
$media[] = $ghm->getMedia();
}
return $media;
} | [
"public",
"function",
"getGalleryMediasAction",
"(",
"$",
"id",
")",
"{",
"$",
"ghms",
"=",
"$",
"this",
"->",
"getGallery",
"(",
"$",
"id",
")",
"->",
"getGalleryHasMedias",
"(",
")",
";",
"$",
"media",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"ghms... | Retrieves the medias of specified gallery.
@ApiDoc(
requirements={
{"name"="id", "dataType"="integer", "requirement"="\d+", "description"="gallery id"}
},
output={"class"="Sonata\MediaBundle\Model\Media", "groups"={"sonata_api_read"}},
statusCodes={
200="Returned when successful",
404="Returned when gallery is not found"
}
)
@View(serializerGroups={"sonata_api_read"}, serializerEnableMaxDepthChecks=true)
@param $id
@return MediaInterface[] | [
"Retrieves",
"the",
"medias",
"of",
"specified",
"gallery",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/Controller/Api/GalleryController.php#L165-L175 | train |
sonata-project/SonataMediaBundle | src/Controller/Api/GalleryController.php | GalleryController.postGalleryMediaGalleryhasmediaAction | public function postGalleryMediaGalleryhasmediaAction($galleryId, $mediaId, Request $request)
{
$gallery = $this->getGallery($galleryId);
$media = $this->getMedia($mediaId);
foreach ($gallery->getGalleryHasMedias() as $galleryHasMedia) {
if ($galleryHasMedia->getMedia()->getId() === $media->getId()) {
return FOSRestView::create([
'error' => sprintf('Gallery "%s" already has media "%s"', $galleryId, $mediaId),
], 400);
}
}
return $this->handleWriteGalleryhasmedia($gallery, $media, null, $request);
} | php | public function postGalleryMediaGalleryhasmediaAction($galleryId, $mediaId, Request $request)
{
$gallery = $this->getGallery($galleryId);
$media = $this->getMedia($mediaId);
foreach ($gallery->getGalleryHasMedias() as $galleryHasMedia) {
if ($galleryHasMedia->getMedia()->getId() === $media->getId()) {
return FOSRestView::create([
'error' => sprintf('Gallery "%s" already has media "%s"', $galleryId, $mediaId),
], 400);
}
}
return $this->handleWriteGalleryhasmedia($gallery, $media, null, $request);
} | [
"public",
"function",
"postGalleryMediaGalleryhasmediaAction",
"(",
"$",
"galleryId",
",",
"$",
"mediaId",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"gallery",
"=",
"$",
"this",
"->",
"getGallery",
"(",
"$",
"galleryId",
")",
";",
"$",
"media",
"=",
"... | Adds a media to a gallery.
@ApiDoc(
requirements={
{"name"="galleryId", "dataType"="integer", "requirement"="\d+", "description"="gallery identifier"},
{"name"="mediaId", "dataType"="integer", "requirement"="\d+", "description"="media identifier"}
},
input={"class"="sonata_media_api_form_gallery_has_media", "name"="", "groups"={"sonata_api_write"}},
output={"class"="sonata_media_api_form_gallery", "groups"={"sonata_api_read"}},
statusCodes={
200="Returned when successful",
400="Returned when an error has occurred while gallery/media attachment",
}
)
@param int $galleryId A gallery identifier
@param int $mediaId A media identifier
@param Request $request A Symfony request
@throws NotFoundHttpException
@return GalleryInterface | [
"Adds",
"a",
"media",
"to",
"a",
"gallery",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/Controller/Api/GalleryController.php#L277-L291 | train |
sonata-project/SonataMediaBundle | src/Controller/Api/GalleryController.php | GalleryController.putGalleryMediaGalleryhasmediaAction | public function putGalleryMediaGalleryhasmediaAction($galleryId, $mediaId, Request $request)
{
$gallery = $this->getGallery($galleryId);
$media = $this->getMedia($mediaId);
foreach ($gallery->getGalleryHasMedias() as $galleryHasMedia) {
if ($galleryHasMedia->getMedia()->getId() === $media->getId()) {
return $this->handleWriteGalleryhasmedia($gallery, $media, $galleryHasMedia, $request);
}
}
throw new NotFoundHttpException(sprintf('Gallery "%s" does not have media "%s"', $galleryId, $mediaId));
} | php | public function putGalleryMediaGalleryhasmediaAction($galleryId, $mediaId, Request $request)
{
$gallery = $this->getGallery($galleryId);
$media = $this->getMedia($mediaId);
foreach ($gallery->getGalleryHasMedias() as $galleryHasMedia) {
if ($galleryHasMedia->getMedia()->getId() === $media->getId()) {
return $this->handleWriteGalleryhasmedia($gallery, $media, $galleryHasMedia, $request);
}
}
throw new NotFoundHttpException(sprintf('Gallery "%s" does not have media "%s"', $galleryId, $mediaId));
} | [
"public",
"function",
"putGalleryMediaGalleryhasmediaAction",
"(",
"$",
"galleryId",
",",
"$",
"mediaId",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"gallery",
"=",
"$",
"this",
"->",
"getGallery",
"(",
"$",
"galleryId",
")",
";",
"$",
"media",
"=",
"$... | Updates a media to a gallery.
@ApiDoc(
requirements={
{"name"="galleryId", "dataType"="integer", "requirement"="\d+", "description"="gallery identifier"},
{"name"="mediaId", "dataType"="integer", "requirement"="\d+", "description"="media identifier"}
},
input={"class"="sonata_media_api_form_gallery_has_media", "name"="", "groups"={"sonata_api_write"}},
output={"class"="sonata_media_api_form_gallery", "groups"={"sonata_api_read"}},
statusCodes={
200="Returned when successful",
404="Returned when an error if media cannot be found in gallery",
}
)
@param int $galleryId A gallery identifier
@param int $mediaId A media identifier
@param Request $request A Symfony request
@throws NotFoundHttpException
@return GalleryInterface | [
"Updates",
"a",
"media",
"to",
"a",
"gallery",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/Controller/Api/GalleryController.php#L317-L329 | train |
sonata-project/SonataMediaBundle | src/Controller/Api/GalleryController.php | GalleryController.deleteGalleryMediaGalleryhasmediaAction | public function deleteGalleryMediaGalleryhasmediaAction($galleryId, $mediaId)
{
$gallery = $this->getGallery($galleryId);
$media = $this->getMedia($mediaId);
foreach ($gallery->getGalleryHasMedias() as $key => $galleryHasMedia) {
if ($galleryHasMedia->getMedia()->getId() === $media->getId()) {
$gallery->getGalleryHasMedias()->remove($key);
$this->getGalleryManager()->save($gallery);
return ['deleted' => true];
}
}
return FOSRestView::create([
'error' => sprintf('Gallery "%s" does not have media "%s" associated', $galleryId, $mediaId),
], 400);
} | php | public function deleteGalleryMediaGalleryhasmediaAction($galleryId, $mediaId)
{
$gallery = $this->getGallery($galleryId);
$media = $this->getMedia($mediaId);
foreach ($gallery->getGalleryHasMedias() as $key => $galleryHasMedia) {
if ($galleryHasMedia->getMedia()->getId() === $media->getId()) {
$gallery->getGalleryHasMedias()->remove($key);
$this->getGalleryManager()->save($gallery);
return ['deleted' => true];
}
}
return FOSRestView::create([
'error' => sprintf('Gallery "%s" does not have media "%s" associated', $galleryId, $mediaId),
], 400);
} | [
"public",
"function",
"deleteGalleryMediaGalleryhasmediaAction",
"(",
"$",
"galleryId",
",",
"$",
"mediaId",
")",
"{",
"$",
"gallery",
"=",
"$",
"this",
"->",
"getGallery",
"(",
"$",
"galleryId",
")",
";",
"$",
"media",
"=",
"$",
"this",
"->",
"getMedia",
... | Deletes a media association to a gallery.
@ApiDoc(
requirements={
{"name"="galleryId", "dataType"="integer", "requirement"="\d+", "description"="gallery identifier"},
{"name"="mediaId", "dataType"="integer", "requirement"="\d+", "description"="media identifier"}
},
statusCodes={
200="Returned when media is successfully deleted from gallery",
400="Returned when an error has occurred while media deletion of gallery",
404="Returned when unable to find gallery or media"
}
)
@param int $galleryId A gallery identifier
@param int $mediaId A media identifier
@throws NotFoundHttpException
@return View | [
"Deletes",
"a",
"media",
"association",
"to",
"a",
"gallery",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/Controller/Api/GalleryController.php#L353-L370 | train |
sonata-project/SonataMediaBundle | src/Controller/Api/GalleryController.php | GalleryController.deleteGalleryAction | public function deleteGalleryAction($id)
{
$gallery = $this->getGallery($id);
$this->galleryManager->delete($gallery);
return ['deleted' => true];
} | php | public function deleteGalleryAction($id)
{
$gallery = $this->getGallery($id);
$this->galleryManager->delete($gallery);
return ['deleted' => true];
} | [
"public",
"function",
"deleteGalleryAction",
"(",
"$",
"id",
")",
"{",
"$",
"gallery",
"=",
"$",
"this",
"->",
"getGallery",
"(",
"$",
"id",
")",
";",
"$",
"this",
"->",
"galleryManager",
"->",
"delete",
"(",
"$",
"gallery",
")",
";",
"return",
"[",
... | Deletes a gallery.
@ApiDoc(
requirements={
{"name"="id", "dataType"="integer", "requirement"="\d+", "description"="gallery identifier"}
},
statusCodes={
200="Returned when gallery is successfully deleted",
400="Returned when an error has occurred while gallery deletion",
404="Returned when unable to find gallery"
}
)
@param int $id A Gallery identifier
@throws NotFoundHttpException
@return View | [
"Deletes",
"a",
"gallery",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/Controller/Api/GalleryController.php#L392-L399 | train |
sonata-project/SonataMediaBundle | src/Controller/Api/GalleryController.php | GalleryController.handleWriteGalleryhasmedia | protected function handleWriteGalleryhasmedia(GalleryInterface $gallery, MediaInterface $media, GalleryHasMediaInterface $galleryHasMedia = null, Request $request)
{
$form = $this->formFactory->createNamed(null, 'sonata_media_api_form_gallery_has_media', $galleryHasMedia, [
'csrf_protection' => false,
]);
$form->handleRequest($request);
if ($form->isValid()) {
$galleryHasMedia = $form->getData();
$galleryHasMedia->setMedia($media);
// NEXT_MAJOR: remove this if/else block. Just call `$gallery->addGalleryHasMedia($galleryHasMedia);`
if ($gallery instanceof GalleryMediaCollectionInterface) {
$gallery->addGalleryHasMedia($galleryHasMedia);
} else {
$gallery->addGalleryHasMedias($galleryHasMedia);
}
$this->galleryManager->save($gallery);
$context = new Context();
$context->setGroups(['sonata_api_read']);
$context->enableMaxDepth();
$view = FOSRestView::create($galleryHasMedia);
$view->setContext($context);
return $view;
}
return $form;
} | php | protected function handleWriteGalleryhasmedia(GalleryInterface $gallery, MediaInterface $media, GalleryHasMediaInterface $galleryHasMedia = null, Request $request)
{
$form = $this->formFactory->createNamed(null, 'sonata_media_api_form_gallery_has_media', $galleryHasMedia, [
'csrf_protection' => false,
]);
$form->handleRequest($request);
if ($form->isValid()) {
$galleryHasMedia = $form->getData();
$galleryHasMedia->setMedia($media);
// NEXT_MAJOR: remove this if/else block. Just call `$gallery->addGalleryHasMedia($galleryHasMedia);`
if ($gallery instanceof GalleryMediaCollectionInterface) {
$gallery->addGalleryHasMedia($galleryHasMedia);
} else {
$gallery->addGalleryHasMedias($galleryHasMedia);
}
$this->galleryManager->save($gallery);
$context = new Context();
$context->setGroups(['sonata_api_read']);
$context->enableMaxDepth();
$view = FOSRestView::create($galleryHasMedia);
$view->setContext($context);
return $view;
}
return $form;
} | [
"protected",
"function",
"handleWriteGalleryhasmedia",
"(",
"GalleryInterface",
"$",
"gallery",
",",
"MediaInterface",
"$",
"media",
",",
"GalleryHasMediaInterface",
"$",
"galleryHasMedia",
"=",
"null",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"form",
"=",
"... | Write a GalleryHasMedia, this method is used by both POST and PUT action methods.
@param GalleryInterface $gallery
@param MediaInterface $media
@param GalleryHasMediaInterface $galleryHasMedia
@param Request $request
@return FormInterface | [
"Write",
"a",
"GalleryHasMedia",
"this",
"method",
"is",
"used",
"by",
"both",
"POST",
"and",
"PUT",
"action",
"methods",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/Controller/Api/GalleryController.php#L411-L442 | train |
sonata-project/SonataMediaBundle | src/Controller/Api/GalleryController.php | GalleryController.handleWriteGallery | protected function handleWriteGallery($request, $id = null)
{
$gallery = $id ? $this->getGallery($id) : null;
$form = $this->formFactory->createNamed(null, 'sonata_media_api_form_gallery', $gallery, [
'csrf_protection' => false,
]);
$form->handleRequest($request);
if ($form->isValid()) {
$gallery = $form->getData();
$this->galleryManager->save($gallery);
$context = new Context();
$context->setGroups(['sonata_api_read']);
$context->enableMaxDepth();
$view = FOSRestView::create($gallery);
$view->setContext($context);
return $view;
}
return $form;
} | php | protected function handleWriteGallery($request, $id = null)
{
$gallery = $id ? $this->getGallery($id) : null;
$form = $this->formFactory->createNamed(null, 'sonata_media_api_form_gallery', $gallery, [
'csrf_protection' => false,
]);
$form->handleRequest($request);
if ($form->isValid()) {
$gallery = $form->getData();
$this->galleryManager->save($gallery);
$context = new Context();
$context->setGroups(['sonata_api_read']);
$context->enableMaxDepth();
$view = FOSRestView::create($gallery);
$view->setContext($context);
return $view;
}
return $form;
} | [
"protected",
"function",
"handleWriteGallery",
"(",
"$",
"request",
",",
"$",
"id",
"=",
"null",
")",
"{",
"$",
"gallery",
"=",
"$",
"id",
"?",
"$",
"this",
"->",
"getGallery",
"(",
"$",
"id",
")",
":",
"null",
";",
"$",
"form",
"=",
"$",
"this",
... | Write a Gallery, this method is used by both POST and PUT action methods.
@param Request $request Symfony request
@param int|null $id A Gallery identifier
@return View|FormInterface | [
"Write",
"a",
"Gallery",
"this",
"method",
"is",
"used",
"by",
"both",
"POST",
"and",
"PUT",
"action",
"methods",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/Controller/Api/GalleryController.php#L508-L533 | train |
sonata-project/SonataMediaBundle | src/CDN/CloudFront.php | CloudFront.setClient | public function setClient($client)
{
if (!$client instanceof CloudFrontClient) {
@trigger_error('The '.__METHOD__.' expects a CloudFrontClient as parameter.', E_USER_DEPRECATED);
}
$this->client = $client;
} | php | public function setClient($client)
{
if (!$client instanceof CloudFrontClient) {
@trigger_error('The '.__METHOD__.' expects a CloudFrontClient as parameter.', E_USER_DEPRECATED);
}
$this->client = $client;
} | [
"public",
"function",
"setClient",
"(",
"$",
"client",
")",
"{",
"if",
"(",
"!",
"$",
"client",
"instanceof",
"CloudFrontClient",
")",
"{",
"@",
"trigger_error",
"(",
"'The '",
".",
"__METHOD__",
".",
"' expects a CloudFrontClient as parameter.'",
",",
"E_USER_DEP... | For testing only.
@param CloudFrontClient $client | [
"For",
"testing",
"only",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/CDN/CloudFront.php#L156-L163 | train |
sonata-project/SonataMediaBundle | src/Provider/FileProvider.php | FileProvider.setFileContents | protected function setFileContents(MediaInterface $media, $contents = null)
{
$file = $this->getFilesystem()->get(sprintf('%s/%s', $this->generatePath($media), $media->getProviderReference()), true);
$metadata = $this->metadata ? $this->metadata->get($media, $file->getName()) : [];
if ($contents) {
$file->setContent($contents, $metadata);
return;
}
$binaryContent = $media->getBinaryContent();
if ($binaryContent instanceof File) {
$path = $binaryContent->getRealPath() ?: $binaryContent->getPathname();
$file->setContent(file_get_contents($path), $metadata);
return;
}
} | php | protected function setFileContents(MediaInterface $media, $contents = null)
{
$file = $this->getFilesystem()->get(sprintf('%s/%s', $this->generatePath($media), $media->getProviderReference()), true);
$metadata = $this->metadata ? $this->metadata->get($media, $file->getName()) : [];
if ($contents) {
$file->setContent($contents, $metadata);
return;
}
$binaryContent = $media->getBinaryContent();
if ($binaryContent instanceof File) {
$path = $binaryContent->getRealPath() ?: $binaryContent->getPathname();
$file->setContent(file_get_contents($path), $metadata);
return;
}
} | [
"protected",
"function",
"setFileContents",
"(",
"MediaInterface",
"$",
"media",
",",
"$",
"contents",
"=",
"null",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"getFilesystem",
"(",
")",
"->",
"get",
"(",
"sprintf",
"(",
"'%s/%s'",
",",
"$",
"this",
... | Set the file contents for an image.
@param MediaInterface $media
@param string $contents path to contents, defaults to MediaInterface BinaryContent | [
"Set",
"the",
"file",
"contents",
"for",
"an",
"image",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/Provider/FileProvider.php#L420-L438 | train |
sonata-project/SonataMediaBundle | src/Provider/FileProvider.php | FileProvider.generateBinaryFromRequest | protected function generateBinaryFromRequest(MediaInterface $media)
{
if (!$media->getContentType()) {
throw new \RuntimeException(
'You must provide the content type value for your media before setting the binary content'
);
}
$request = $media->getBinaryContent();
if (!$request instanceof Request) {
throw new \RuntimeException('Expected Request in binary content');
}
$content = $request->getContent();
// create unique id for media reference
$guesser = ExtensionGuesser::getInstance();
$extension = $guesser->guess($media->getContentType());
if (!$extension) {
throw new \RuntimeException(
sprintf('Unable to guess extension for content type %s', $media->getContentType())
);
}
$handle = tmpfile();
fwrite($handle, $content);
$file = new ApiMediaFile($handle);
$file->setExtension($extension);
$file->setMimetype($media->getContentType());
$media->setBinaryContent($file);
} | php | protected function generateBinaryFromRequest(MediaInterface $media)
{
if (!$media->getContentType()) {
throw new \RuntimeException(
'You must provide the content type value for your media before setting the binary content'
);
}
$request = $media->getBinaryContent();
if (!$request instanceof Request) {
throw new \RuntimeException('Expected Request in binary content');
}
$content = $request->getContent();
// create unique id for media reference
$guesser = ExtensionGuesser::getInstance();
$extension = $guesser->guess($media->getContentType());
if (!$extension) {
throw new \RuntimeException(
sprintf('Unable to guess extension for content type %s', $media->getContentType())
);
}
$handle = tmpfile();
fwrite($handle, $content);
$file = new ApiMediaFile($handle);
$file->setExtension($extension);
$file->setMimetype($media->getContentType());
$media->setBinaryContent($file);
} | [
"protected",
"function",
"generateBinaryFromRequest",
"(",
"MediaInterface",
"$",
"media",
")",
"{",
"if",
"(",
"!",
"$",
"media",
"->",
"getContentType",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'You must provide the content type value fo... | Set media binary content according to request content.
@param MediaInterface $media | [
"Set",
"media",
"binary",
"content",
"according",
"to",
"request",
"content",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/Provider/FileProvider.php#L465-L498 | train |
sonata-project/SonataMediaBundle | src/Controller/Api/MediaController.php | MediaController.getMediumFormatsAction | public function getMediumFormatsAction($id)
{
$media = $this->getMedium($id);
$formats = [MediaProviderInterface::FORMAT_REFERENCE];
$formats = array_merge($formats, array_keys($this->mediaPool->getFormatNamesByContext($media->getContext())));
$provider = $this->mediaPool->getProvider($media->getProviderName());
$properties = [];
foreach ($formats as $format) {
$properties[$format]['url'] = $provider->generatePublicUrl($media, $format);
$properties[$format]['properties'] = $provider->getHelperProperties($media, $format);
}
return $properties;
} | php | public function getMediumFormatsAction($id)
{
$media = $this->getMedium($id);
$formats = [MediaProviderInterface::FORMAT_REFERENCE];
$formats = array_merge($formats, array_keys($this->mediaPool->getFormatNamesByContext($media->getContext())));
$provider = $this->mediaPool->getProvider($media->getProviderName());
$properties = [];
foreach ($formats as $format) {
$properties[$format]['url'] = $provider->generatePublicUrl($media, $format);
$properties[$format]['properties'] = $provider->getHelperProperties($media, $format);
}
return $properties;
} | [
"public",
"function",
"getMediumFormatsAction",
"(",
"$",
"id",
")",
"{",
"$",
"media",
"=",
"$",
"this",
"->",
"getMedium",
"(",
"$",
"id",
")",
";",
"$",
"formats",
"=",
"[",
"MediaProviderInterface",
"::",
"FORMAT_REFERENCE",
"]",
";",
"$",
"formats",
... | Returns media urls for each format.
@ApiDoc(
requirements={
{"name"="id", "dataType"="integer", "requirement"="\d+", "description"="media id"}
},
statusCodes={
200="Returned when successful",
404="Returned when media is not found"
}
)
@param $id
@return array | [
"Returns",
"media",
"urls",
"for",
"each",
"format",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/Controller/Api/MediaController.php#L159-L175 | train |
sonata-project/SonataMediaBundle | src/Controller/Api/MediaController.php | MediaController.getMediumBinaryAction | public function getMediumBinaryAction($id, $format, Request $request)
{
$media = $this->getMedium($id);
$response = $this->mediaPool->getProvider($media->getProviderName())->getDownloadResponse($media, $format, $this->mediaPool->getDownloadMode($media));
if ($response instanceof BinaryFileResponse) {
$response->prepare($request);
}
return $response;
} | php | public function getMediumBinaryAction($id, $format, Request $request)
{
$media = $this->getMedium($id);
$response = $this->mediaPool->getProvider($media->getProviderName())->getDownloadResponse($media, $format, $this->mediaPool->getDownloadMode($media));
if ($response instanceof BinaryFileResponse) {
$response->prepare($request);
}
return $response;
} | [
"public",
"function",
"getMediumBinaryAction",
"(",
"$",
"id",
",",
"$",
"format",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"media",
"=",
"$",
"this",
"->",
"getMedium",
"(",
"$",
"id",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"mediaP... | Returns media binary content for each format.
@ApiDoc(
requirements={
{"name"="id", "dataType"="integer", "requirement"="\d+", "description"="media id"},
{"name"="format", "dataType"="string", "description"="media format"}
},
statusCodes={
200="Returned when successful",
404="Returned when media is not found"
}
)
@param int $id The media id
@param string $format The format
@param Request $request
@return Response | [
"Returns",
"media",
"binary",
"content",
"for",
"each",
"format",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/Controller/Api/MediaController.php#L197-L208 | train |
sonata-project/SonataMediaBundle | src/Controller/Api/MediaController.php | MediaController.deleteMediumAction | public function deleteMediumAction($id)
{
$medium = $this->getMedium($id);
$this->mediaManager->delete($medium);
return ['deleted' => true];
} | php | public function deleteMediumAction($id)
{
$medium = $this->getMedium($id);
$this->mediaManager->delete($medium);
return ['deleted' => true];
} | [
"public",
"function",
"deleteMediumAction",
"(",
"$",
"id",
")",
"{",
"$",
"medium",
"=",
"$",
"this",
"->",
"getMedium",
"(",
"$",
"id",
")",
";",
"$",
"this",
"->",
"mediaManager",
"->",
"delete",
"(",
"$",
"medium",
")",
";",
"return",
"[",
"'dele... | Deletes a medium.
@ApiDoc(
requirements={
{"name"="id", "dataType"="integer", "requirement"="\d+", "description"="medium identifier"}
},
statusCodes={
200="Returned when medium is successfully deleted",
400="Returned when an error has occurred while deleting the medium",
404="Returned when unable to find medium"
}
)
@param int $id A medium identifier
@throws NotFoundHttpException
@return View | [
"Deletes",
"a",
"medium",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/Controller/Api/MediaController.php#L230-L237 | train |
sonata-project/SonataMediaBundle | src/Controller/Api/MediaController.php | MediaController.putMediumBinaryContentAction | public function putMediumBinaryContentAction($id, Request $request)
{
$media = $this->getMedium($id);
$media->setBinaryContent($request);
$this->mediaManager->save($media);
return $media;
} | php | public function putMediumBinaryContentAction($id, Request $request)
{
$media = $this->getMedium($id);
$media->setBinaryContent($request);
$this->mediaManager->save($media);
return $media;
} | [
"public",
"function",
"putMediumBinaryContentAction",
"(",
"$",
"id",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"media",
"=",
"$",
"this",
"->",
"getMedium",
"(",
"$",
"id",
")",
";",
"$",
"media",
"->",
"setBinaryContent",
"(",
"$",
"request",
")",... | Set Binary content for a specific media.
@ApiDoc(
input={"class"="Sonata\MediaBundle\Model\Media", "groups"={"sonata_api_write"}},
output={"class"="Sonata\MediaBundle\Model\Media", "groups"={"sonata_api_read"}},
statusCodes={
200="Returned when successful",
404="Returned when media is not found"
}
)
@View(serializerGroups={"sonata_api_read"}, serializerEnableMaxDepthChecks=true)
@param $id
@param Request $request A Symfony request
@throws NotFoundHttpException
@return MediaInterface | [
"Set",
"Binary",
"content",
"for",
"a",
"specific",
"media",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/Controller/Api/MediaController.php#L341-L350 | train |
sonata-project/SonataMediaBundle | src/Controller/Api/MediaController.php | MediaController.handleWriteMedium | protected function handleWriteMedium(Request $request, MediaInterface $media, MediaProviderInterface $provider)
{
$form = $this->formFactory->createNamed(null, 'sonata_media_api_form_media', $media, [
'provider_name' => $provider->getName(),
'csrf_protection' => false,
]);
$form->handleRequest($request);
if ($form->isValid()) {
$media = $form->getData();
$this->mediaManager->save($media);
$context = new Context();
$context->setGroups(['sonata_api_read']);
$context->enableMaxDepth();
$view = FOSRestView::create($media);
$view->setContext($context);
return $view;
}
return $form;
} | php | protected function handleWriteMedium(Request $request, MediaInterface $media, MediaProviderInterface $provider)
{
$form = $this->formFactory->createNamed(null, 'sonata_media_api_form_media', $media, [
'provider_name' => $provider->getName(),
'csrf_protection' => false,
]);
$form->handleRequest($request);
if ($form->isValid()) {
$media = $form->getData();
$this->mediaManager->save($media);
$context = new Context();
$context->setGroups(['sonata_api_read']);
$context->enableMaxDepth();
$view = FOSRestView::create($media);
$view->setContext($context);
return $view;
}
return $form;
} | [
"protected",
"function",
"handleWriteMedium",
"(",
"Request",
"$",
"request",
",",
"MediaInterface",
"$",
"media",
",",
"MediaProviderInterface",
"$",
"provider",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"formFactory",
"->",
"createNamed",
"(",
"null",
"... | Write a medium, this method is used by both POST and PUT action methods.
@param Request $request
@param MediaInterface $media
@param MediaProviderInterface $provider
@return View|FormInterface | [
"Write",
"a",
"medium",
"this",
"method",
"is",
"used",
"by",
"both",
"POST",
"and",
"PUT",
"action",
"methods",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/Controller/Api/MediaController.php#L382-L406 | train |
sonata-project/SonataMediaBundle | src/Metadata/AmazonMetadataBuilder.php | AmazonMetadataBuilder.getDefaultMetadata | protected function getDefaultMetadata()
{
//merge acl
$output = [];
if (isset($this->settings['acl']) && !empty($this->settings['acl'])) {
$output['ACL'] = $this->acl[$this->settings['acl']];
}
//merge storage
if (isset($this->settings['storage'])) {
if ('standard' === $this->settings['storage']) {
$output['storage'] = static::STORAGE_STANDARD;
} elseif ('reduced' === $this->settings['storage']) {
$output['storage'] = static::STORAGE_REDUCED;
}
}
//merge meta
if (isset($this->settings['meta']) && !empty($this->settings['meta'])) {
$output['meta'] = $this->settings['meta'];
}
//merge cache control header
if (isset($this->settings['cache_control']) && !empty($this->settings['cache_control'])) {
$output['CacheControl'] = $this->settings['cache_control'];
}
//merge encryption
if (isset($this->settings['encryption']) && !empty($this->settings['encryption'])) {
if ('aes256' === $this->settings['encryption']) {
$output['encryption'] = 'AES256';
}
}
return $output;
} | php | protected function getDefaultMetadata()
{
//merge acl
$output = [];
if (isset($this->settings['acl']) && !empty($this->settings['acl'])) {
$output['ACL'] = $this->acl[$this->settings['acl']];
}
//merge storage
if (isset($this->settings['storage'])) {
if ('standard' === $this->settings['storage']) {
$output['storage'] = static::STORAGE_STANDARD;
} elseif ('reduced' === $this->settings['storage']) {
$output['storage'] = static::STORAGE_REDUCED;
}
}
//merge meta
if (isset($this->settings['meta']) && !empty($this->settings['meta'])) {
$output['meta'] = $this->settings['meta'];
}
//merge cache control header
if (isset($this->settings['cache_control']) && !empty($this->settings['cache_control'])) {
$output['CacheControl'] = $this->settings['cache_control'];
}
//merge encryption
if (isset($this->settings['encryption']) && !empty($this->settings['encryption'])) {
if ('aes256' === $this->settings['encryption']) {
$output['encryption'] = 'AES256';
}
}
return $output;
} | [
"protected",
"function",
"getDefaultMetadata",
"(",
")",
"{",
"//merge acl",
"$",
"output",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"settings",
"[",
"'acl'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"settings",
"[... | Get data passed from the config.
@return array | [
"Get",
"data",
"passed",
"from",
"the",
"config",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/Metadata/AmazonMetadataBuilder.php#L73-L108 | train |
sonata-project/SonataMediaBundle | src/Metadata/AmazonMetadataBuilder.php | AmazonMetadataBuilder.getContentType | protected function getContentType($filename)
{
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$contentType = Psr7\mimetype_from_extension($extension);
return ['contentType' => $contentType];
} | php | protected function getContentType($filename)
{
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$contentType = Psr7\mimetype_from_extension($extension);
return ['contentType' => $contentType];
} | [
"protected",
"function",
"getContentType",
"(",
"$",
"filename",
")",
"{",
"$",
"extension",
"=",
"pathinfo",
"(",
"$",
"filename",
",",
"PATHINFO_EXTENSION",
")",
";",
"$",
"contentType",
"=",
"Psr7",
"\\",
"mimetype_from_extension",
"(",
"$",
"extension",
")... | Gets the correct content-type.
@param string $filename
@return array | [
"Gets",
"the",
"correct",
"content",
"-",
"type",
"."
] | f9ba37f94c0beeffb585b6f9547a9e5e5a40508b | https://github.com/sonata-project/SonataMediaBundle/blob/f9ba37f94c0beeffb585b6f9547a9e5e5a40508b/src/Metadata/AmazonMetadataBuilder.php#L117-L123 | train |
paragonie/easydb | src/EasyStatement.php | EasyStatement.andIn | public function andIn(string $condition, array $values): self
{
return $this->andWith($this->unpackCondition($condition, \count($values)), ...$values);
} | php | public function andIn(string $condition, array $values): self
{
return $this->andWith($this->unpackCondition($condition, \count($values)), ...$values);
} | [
"public",
"function",
"andIn",
"(",
"string",
"$",
"condition",
",",
"array",
"$",
"values",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"andWith",
"(",
"$",
"this",
"->",
"unpackCondition",
"(",
"$",
"condition",
",",
"\\",
"count",
"(",
"$",
... | Add an IN condition that will be applied with a logical "AND".
Instead of using ? to denote the placeholder, ?* must be used!
@param string $condition
@param array $values
@return self
@throws \TypeError | [
"Add",
"an",
"IN",
"condition",
"that",
"will",
"be",
"applied",
"with",
"a",
"logical",
"AND",
"."
] | 2823ff47192a54a315c8f16d548896debc4694ff | https://github.com/paragonie/easydb/blob/2823ff47192a54a315c8f16d548896debc4694ff/src/EasyStatement.php#L160-L163 | train |
paragonie/easydb | src/EasyStatement.php | EasyStatement.orIn | public function orIn(string $condition, array $values): self
{
return $this->orWith($this->unpackCondition($condition, \count($values)), ...$values);
} | php | public function orIn(string $condition, array $values): self
{
return $this->orWith($this->unpackCondition($condition, \count($values)), ...$values);
} | [
"public",
"function",
"orIn",
"(",
"string",
"$",
"condition",
",",
"array",
"$",
"values",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"orWith",
"(",
"$",
"this",
"->",
"unpackCondition",
"(",
"$",
"condition",
",",
"\\",
"count",
"(",
"$",
... | Add an IN condition that will be applied with a logical "OR".
Instead of using "?" to denote the placeholder, "?*" must be used!
@param string $condition
@param array $values
@return self
@throws \TypeError | [
"Add",
"an",
"IN",
"condition",
"that",
"will",
"be",
"applied",
"with",
"a",
"logical",
"OR",
"."
] | 2823ff47192a54a315c8f16d548896debc4694ff | https://github.com/paragonie/easydb/blob/2823ff47192a54a315c8f16d548896debc4694ff/src/EasyStatement.php#L176-L179 | train |
paragonie/easydb | src/EasyStatement.php | EasyStatement.sql | public function sql(): string
{
if (empty($this->parts)) {
return '1';
}
return (string) \array_reduce(
$this->parts,
function (string $sql, array $part): string {
/** @var string|self $condition */
$condition = $part['condition'];
if ($this->isGroup($condition)) {
// (...)
if (\is_string($condition)) {
$statement = '(' . $condition . ')';
} else {
$statement = '(' . $condition->sql() . ')';
}
} else {
// foo = ?
$statement = $condition;
}
/** @var string $statement */
$statement = (string) $statement;
$part['type'] = (string) $part['type'];
if ($sql) {
switch ($part['type']) {
case 'AND':
case 'OR':
$statement = $part['type'] . ' ' . $statement;
break;
default:
throw new RuntimeException(
\sprintf('Invalid joiner %s', $part['type'])
);
}
}
return \trim($sql . ' ' . $statement);
},
''
);
} | php | public function sql(): string
{
if (empty($this->parts)) {
return '1';
}
return (string) \array_reduce(
$this->parts,
function (string $sql, array $part): string {
/** @var string|self $condition */
$condition = $part['condition'];
if ($this->isGroup($condition)) {
// (...)
if (\is_string($condition)) {
$statement = '(' . $condition . ')';
} else {
$statement = '(' . $condition->sql() . ')';
}
} else {
// foo = ?
$statement = $condition;
}
/** @var string $statement */
$statement = (string) $statement;
$part['type'] = (string) $part['type'];
if ($sql) {
switch ($part['type']) {
case 'AND':
case 'OR':
$statement = $part['type'] . ' ' . $statement;
break;
default:
throw new RuntimeException(
\sprintf('Invalid joiner %s', $part['type'])
);
}
}
return \trim($sql . ' ' . $statement);
},
''
);
} | [
"public",
"function",
"sql",
"(",
")",
":",
"string",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"parts",
")",
")",
"{",
"return",
"'1'",
";",
"}",
"return",
"(",
"string",
")",
"\\",
"array_reduce",
"(",
"$",
"this",
"->",
"parts",
",",
"f... | Compile the current statement into PDO-ready SQL.
@return string | [
"Compile",
"the",
"current",
"statement",
"into",
"PDO",
"-",
"ready",
"SQL",
"."
] | 2823ff47192a54a315c8f16d548896debc4694ff | https://github.com/paragonie/easydb/blob/2823ff47192a54a315c8f16d548896debc4694ff/src/EasyStatement.php#L261-L304 | train |
paragonie/easydb | src/EasyStatement.php | EasyStatement.values | public function values(): array
{
return (array) \array_reduce(
$this->parts,
function (array $values, array $part): array {
if ($this->isGroup($part['condition'])) {
/** @var EasyStatement $condition */
$condition = $part['condition'];
return \array_merge(
$values,
$condition->values()
);
}
return \array_merge($values, $part['values']);
},
[]
);
} | php | public function values(): array
{
return (array) \array_reduce(
$this->parts,
function (array $values, array $part): array {
if ($this->isGroup($part['condition'])) {
/** @var EasyStatement $condition */
$condition = $part['condition'];
return \array_merge(
$values,
$condition->values()
);
}
return \array_merge($values, $part['values']);
},
[]
);
} | [
"public",
"function",
"values",
"(",
")",
":",
"array",
"{",
"return",
"(",
"array",
")",
"\\",
"array_reduce",
"(",
"$",
"this",
"->",
"parts",
",",
"function",
"(",
"array",
"$",
"values",
",",
"array",
"$",
"part",
")",
":",
"array",
"{",
"if",
... | Get all of the parameters attached to this statement.
@return array | [
"Get",
"all",
"of",
"the",
"parameters",
"attached",
"to",
"this",
"statement",
"."
] | 2823ff47192a54a315c8f16d548896debc4694ff | https://github.com/paragonie/easydb/blob/2823ff47192a54a315c8f16d548896debc4694ff/src/EasyStatement.php#L311-L328 | train |
paragonie/easydb | src/EasyStatement.php | EasyStatement.unpackCondition | private function unpackCondition(string $condition, int $count): string
{
// Replace a grouped placeholder with an matching count of placeholders.
$params = '?' . \str_repeat(', ?', $count - 1);
return \str_replace('?*', $params, $condition);
} | php | private function unpackCondition(string $condition, int $count): string
{
// Replace a grouped placeholder with an matching count of placeholders.
$params = '?' . \str_repeat(', ?', $count - 1);
return \str_replace('?*', $params, $condition);
} | [
"private",
"function",
"unpackCondition",
"(",
"string",
"$",
"condition",
",",
"int",
"$",
"count",
")",
":",
"string",
"{",
"// Replace a grouped placeholder with an matching count of placeholders.",
"$",
"params",
"=",
"'?'",
".",
"\\",
"str_repeat",
"(",
"', ?'",
... | Replace a grouped placeholder with a list of placeholders.
Given a count of 3, the placeholder ?* will become ?, ?, ?
@param string $condition
@param int $count
@return string | [
"Replace",
"a",
"grouped",
"placeholder",
"with",
"a",
"list",
"of",
"placeholders",
"."
] | 2823ff47192a54a315c8f16d548896debc4694ff | https://github.com/paragonie/easydb/blob/2823ff47192a54a315c8f16d548896debc4694ff/src/EasyStatement.php#L377-L382 | train |
paragonie/easydb | src/Factory.php | Factory.create | public static function create(
string $dsn,
string $username = null,
string $password = null,
array $options = []
): EasyDB {
return static::fromArray([$dsn, $username, $password, $options]);
} | php | public static function create(
string $dsn,
string $username = null,
string $password = null,
array $options = []
): EasyDB {
return static::fromArray([$dsn, $username, $password, $options]);
} | [
"public",
"static",
"function",
"create",
"(",
"string",
"$",
"dsn",
",",
"string",
"$",
"username",
"=",
"null",
",",
"string",
"$",
"password",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"EasyDB",
"{",
"return",
"static",
"... | Create a new EasyDB object based on PDO constructors
@param string $dsn
@param string $username
@param string $password
@param array $options
@return \ParagonIE\EasyDB\EasyDB
@throws Issues\ConstructorFailed | [
"Create",
"a",
"new",
"EasyDB",
"object",
"based",
"on",
"PDO",
"constructors"
] | 2823ff47192a54a315c8f16d548896debc4694ff | https://github.com/paragonie/easydb/blob/2823ff47192a54a315c8f16d548896debc4694ff/src/Factory.php#L25-L32 | train |
paragonie/easydb | src/Factory.php | Factory.fromArray | public static function fromArray(array $config): EasyDB
{
/** @var string $dsn */
$dsn = $config[0];
/** @var string|null $username */
$username = $config[1] ?? null;
/** @var string|null $password */
$password = $config[2] ?? null;
/** @var array $options */
$options = $config[3] ?? [];
$dbEngine = '';
$post_query = null;
if (!\is_string($username)) {
$username = '';
}
if (!\is_string($password)) {
$password = '';
}
// Let's grab the DB engine
if (strpos($dsn, ':') !== false) {
$dbEngine = explode(':', $dsn)[0];
}
/** @var string $post_query */
$post_query = '';
// If no charset is specified, default to UTF-8
switch ($dbEngine) {
case 'mysql':
if (\strpos($dsn, ';charset=') === false) {
$dsn .= ';charset=utf8mb4';
}
break;
case 'pgsql':
$post_query = "SET NAMES 'UNICODE'";
break;
}
try {
$pdo = new \PDO($dsn, $username, $password, $options);
} catch (\PDOException $e) {
if (\strpos((string) $e->getMessage(), 'could not find driver') !== false) {
throw (new Issues\ConstructorFailed(
'Could not create a PDO connection. Is the driver installed/enabled?'
))->setRealException($e);
}
if (\strpos((string) $e->getMessage(), 'unknown database') !== false) {
throw (new Issues\ConstructorFailed(
'Could not create a PDO connection. Check that your database exists.'
))->setRealException($e);
}
// Don't leak credentials directly if we can.
throw (new Issues\ConstructorFailed(
'Could not create a PDO connection. Please check your username and password.'
))->setRealException($e);
}
if (!empty($post_query)) {
$pdo->query($post_query);
}
return new EasyDB($pdo, $dbEngine, $options);
} | php | public static function fromArray(array $config): EasyDB
{
/** @var string $dsn */
$dsn = $config[0];
/** @var string|null $username */
$username = $config[1] ?? null;
/** @var string|null $password */
$password = $config[2] ?? null;
/** @var array $options */
$options = $config[3] ?? [];
$dbEngine = '';
$post_query = null;
if (!\is_string($username)) {
$username = '';
}
if (!\is_string($password)) {
$password = '';
}
// Let's grab the DB engine
if (strpos($dsn, ':') !== false) {
$dbEngine = explode(':', $dsn)[0];
}
/** @var string $post_query */
$post_query = '';
// If no charset is specified, default to UTF-8
switch ($dbEngine) {
case 'mysql':
if (\strpos($dsn, ';charset=') === false) {
$dsn .= ';charset=utf8mb4';
}
break;
case 'pgsql':
$post_query = "SET NAMES 'UNICODE'";
break;
}
try {
$pdo = new \PDO($dsn, $username, $password, $options);
} catch (\PDOException $e) {
if (\strpos((string) $e->getMessage(), 'could not find driver') !== false) {
throw (new Issues\ConstructorFailed(
'Could not create a PDO connection. Is the driver installed/enabled?'
))->setRealException($e);
}
if (\strpos((string) $e->getMessage(), 'unknown database') !== false) {
throw (new Issues\ConstructorFailed(
'Could not create a PDO connection. Check that your database exists.'
))->setRealException($e);
}
// Don't leak credentials directly if we can.
throw (new Issues\ConstructorFailed(
'Could not create a PDO connection. Please check your username and password.'
))->setRealException($e);
}
if (!empty($post_query)) {
$pdo->query($post_query);
}
return new EasyDB($pdo, $dbEngine, $options);
} | [
"public",
"static",
"function",
"fromArray",
"(",
"array",
"$",
"config",
")",
":",
"EasyDB",
"{",
"/** @var string $dsn */",
"$",
"dsn",
"=",
"$",
"config",
"[",
"0",
"]",
";",
"/** @var string|null $username */",
"$",
"username",
"=",
"$",
"config",
"[",
"... | Create a new EasyDB object from array of parameters
@param array $config
@return \ParagonIE\EasyDB\EasyDB
@throws Issues\ConstructorFailed | [
"Create",
"a",
"new",
"EasyDB",
"object",
"from",
"array",
"of",
"parameters"
] | 2823ff47192a54a315c8f16d548896debc4694ff | https://github.com/paragonie/easydb/blob/2823ff47192a54a315c8f16d548896debc4694ff/src/Factory.php#L41-L109 | train |
paragonie/easydb | src/EasyDB.php | EasyDB.column | public function column(string $statement, array $params = [], int $offset = 0)
{
$stmt = $this->prepare($statement);
if (!$this->is1DArray($params)) {
throw new Issues\MustBeOneDimensionalArray(
'Only one-dimensional arrays are allowed.'
);
}
$stmt->execute($params);
return $stmt->fetchAll(
\PDO::FETCH_COLUMN,
$offset
);
} | php | public function column(string $statement, array $params = [], int $offset = 0)
{
$stmt = $this->prepare($statement);
if (!$this->is1DArray($params)) {
throw new Issues\MustBeOneDimensionalArray(
'Only one-dimensional arrays are allowed.'
);
}
$stmt->execute($params);
return $stmt->fetchAll(
\PDO::FETCH_COLUMN,
$offset
);
} | [
"public",
"function",
"column",
"(",
"string",
"$",
"statement",
",",
"array",
"$",
"params",
"=",
"[",
"]",
",",
"int",
"$",
"offset",
"=",
"0",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"prepare",
"(",
"$",
"statement",
")",
";",
"if",
"("... | Fetch a column
@param string $statement SQL query without user data
@param array $params Parameters
@param int $offset How many columns from the left are we grabbing
from each row?
@return mixed | [
"Fetch",
"a",
"column"
] | 2823ff47192a54a315c8f16d548896debc4694ff | https://github.com/paragonie/easydb/blob/2823ff47192a54a315c8f16d548896debc4694ff/src/EasyDB.php#L88-L101 | train |
paragonie/easydb | src/EasyDB.php | EasyDB.escapeLikeValue | public function escapeLikeValue(string $value): string
{
// Backslash is used to escape wildcards.
$value = str_replace('\\', '\\\\', $value);
// Standard wildcards are underscore and percent sign.
$value = str_replace('%', '\\%', $value);
$value = str_replace('_', '\\_', $value);
if ($this->dbEngine === 'mssql') {
// MSSQL also includes character ranges.
$value = str_replace('[', '\\[', $value);
$value = str_replace(']', '\\]', $value);
}
return $value;
} | php | public function escapeLikeValue(string $value): string
{
// Backslash is used to escape wildcards.
$value = str_replace('\\', '\\\\', $value);
// Standard wildcards are underscore and percent sign.
$value = str_replace('%', '\\%', $value);
$value = str_replace('_', '\\_', $value);
if ($this->dbEngine === 'mssql') {
// MSSQL also includes character ranges.
$value = str_replace('[', '\\[', $value);
$value = str_replace(']', '\\]', $value);
}
return $value;
} | [
"public",
"function",
"escapeLikeValue",
"(",
"string",
"$",
"value",
")",
":",
"string",
"{",
"// Backslash is used to escape wildcards.",
"$",
"value",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'\\\\\\\\'",
",",
"$",
"value",
")",
";",
"// Standard wildcards are un... | Escape a value that will be used as a LIKE condition.
Input: ("string_not%escaped")
Output: "string\_not\%escaped"
WARNING: This function always escapes wildcards using backslash!
@param string $value
@return string | [
"Escape",
"a",
"value",
"that",
"will",
"be",
"used",
"as",
"a",
"LIKE",
"condition",
"."
] | 2823ff47192a54a315c8f16d548896debc4694ff | https://github.com/paragonie/easydb/blob/2823ff47192a54a315c8f16d548896debc4694ff/src/EasyDB.php#L431-L446 | train |
paragonie/easydb | src/EasyDB.php | EasyDB.exists | public function exists(string $statement, ...$params): bool
{
/**
* @var string|int|float|bool|null $result
*/
$result = $this->single($statement, $params);
return !empty($result);
} | php | public function exists(string $statement, ...$params): bool
{
/**
* @var string|int|float|bool|null $result
*/
$result = $this->single($statement, $params);
return !empty($result);
} | [
"public",
"function",
"exists",
"(",
"string",
"$",
"statement",
",",
"...",
"$",
"params",
")",
":",
"bool",
"{",
"/**\n * @var string|int|float|bool|null $result\n */",
"$",
"result",
"=",
"$",
"this",
"->",
"single",
"(",
"$",
"statement",
",",
... | Use with SELECT COUNT queries to determine if a record exists.
@param string $statement
@param mixed ...$params
@return bool
@psalm-suppress MixedAssignment | [
"Use",
"with",
"SELECT",
"COUNT",
"queries",
"to",
"determine",
"if",
"a",
"record",
"exists",
"."
] | 2823ff47192a54a315c8f16d548896debc4694ff | https://github.com/paragonie/easydb/blob/2823ff47192a54a315c8f16d548896debc4694ff/src/EasyDB.php#L456-L463 | train |
paragonie/easydb | src/EasyDB.php | EasyDB.insert | public function insert(string $table, array $map): int
{
if (!empty($map)) {
if (!$this->is1DArray($map)) {
throw new Issues\MustBeOneDimensionalArray(
'Only one-dimensional arrays are allowed.'
);
}
}
list($queryString, $values) = $this->buildInsertQueryBoolSafe(
$table,
$map
);
/** @var string $queryString */
/** @var array $values */
return (int) $this->safeQuery(
(string) $queryString,
$values,
\PDO::FETCH_BOTH,
true
);
} | php | public function insert(string $table, array $map): int
{
if (!empty($map)) {
if (!$this->is1DArray($map)) {
throw new Issues\MustBeOneDimensionalArray(
'Only one-dimensional arrays are allowed.'
);
}
}
list($queryString, $values) = $this->buildInsertQueryBoolSafe(
$table,
$map
);
/** @var string $queryString */
/** @var array $values */
return (int) $this->safeQuery(
(string) $queryString,
$values,
\PDO::FETCH_BOTH,
true
);
} | [
"public",
"function",
"insert",
"(",
"string",
"$",
"table",
",",
"array",
"$",
"map",
")",
":",
"int",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"map",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"is1DArray",
"(",
"$",
"map",
")",
")",
"... | Insert a new row to a table in a database.
@param string $table - table name
@param array $map - associative array of which values should be assigned to each field
@return int
@throws \InvalidArgumentException
@throws \TypeError | [
"Insert",
"a",
"new",
"row",
"to",
"a",
"table",
"in",
"a",
"database",
"."
] | 2823ff47192a54a315c8f16d548896debc4694ff | https://github.com/paragonie/easydb/blob/2823ff47192a54a315c8f16d548896debc4694ff/src/EasyDB.php#L505-L528 | train |
paragonie/easydb | src/EasyDB.php | EasyDB.insertGet | public function insertGet(string $table, array $map, string $field)
{
if (empty($map)) {
throw new \Exception('An empty array is not allowed for insertGet()');
}
if ($this->insert($table, $map) < 1) {
throw new \Exception('Insert failed');
}
$post = [];
$params = [];
/**
* @var string $i
* @var string|bool|null|int|float $v
*/
foreach ($map as $i => $v) {
// Escape the identifier to prevent stupidity
$i = $this->escapeIdentifier($i);
if ($v === null) {
$post []= " {$i} IS NULL ";
} elseif (\is_bool($v)) {
$post []= $this->makeBooleanArgument($i, $v);
} else {
// We use prepared statements for handling the users' data
$post []= " {$i} = ? ";
$params[] = $v;
}
}
$conditions = \implode(' AND ', $post);
// We want the latest value:
switch ($this->dbEngine) {
case 'mysql':
$limiter = ' ORDER BY ' .
$this->escapeIdentifier($field) .
' DESC LIMIT 0, 1 ';
break;
case 'pgsql':
$limiter = ' ORDER BY ' .
$this->escapeIdentifier($field) .
' DESC OFFSET 0 LIMIT 1 ';
break;
default:
$limiter = '';
}
$query = 'SELECT ' .
$this->escapeIdentifier($field) .
' FROM ' .
$this->escapeIdentifier($table) .
' WHERE ' .
$conditions .
$limiter;
return $this->single($query, $params);
} | php | public function insertGet(string $table, array $map, string $field)
{
if (empty($map)) {
throw new \Exception('An empty array is not allowed for insertGet()');
}
if ($this->insert($table, $map) < 1) {
throw new \Exception('Insert failed');
}
$post = [];
$params = [];
/**
* @var string $i
* @var string|bool|null|int|float $v
*/
foreach ($map as $i => $v) {
// Escape the identifier to prevent stupidity
$i = $this->escapeIdentifier($i);
if ($v === null) {
$post []= " {$i} IS NULL ";
} elseif (\is_bool($v)) {
$post []= $this->makeBooleanArgument($i, $v);
} else {
// We use prepared statements for handling the users' data
$post []= " {$i} = ? ";
$params[] = $v;
}
}
$conditions = \implode(' AND ', $post);
// We want the latest value:
switch ($this->dbEngine) {
case 'mysql':
$limiter = ' ORDER BY ' .
$this->escapeIdentifier($field) .
' DESC LIMIT 0, 1 ';
break;
case 'pgsql':
$limiter = ' ORDER BY ' .
$this->escapeIdentifier($field) .
' DESC OFFSET 0 LIMIT 1 ';
break;
default:
$limiter = '';
}
$query = 'SELECT ' .
$this->escapeIdentifier($field) .
' FROM ' .
$this->escapeIdentifier($table) .
' WHERE ' .
$conditions .
$limiter;
return $this->single($query, $params);
} | [
"public",
"function",
"insertGet",
"(",
"string",
"$",
"table",
",",
"array",
"$",
"map",
",",
"string",
"$",
"field",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"map",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'An empty array is not allowed f... | Insert a new record then get a particular field from the new row
@param string $table
@param array $map
@param string $field
@return mixed
@throws \Exception
@psalm-suppress MixedAssignment
@psalm-suppress MixedArgument | [
"Insert",
"a",
"new",
"record",
"then",
"get",
"a",
"particular",
"field",
"from",
"the",
"new",
"row"
] | 2823ff47192a54a315c8f16d548896debc4694ff | https://github.com/paragonie/easydb/blob/2823ff47192a54a315c8f16d548896debc4694ff/src/EasyDB.php#L541-L592 | train |
paragonie/easydb | src/EasyDB.php | EasyDB.insertMany | public function insertMany(string $table, array $maps): int
{
if (count($maps) < 1) {
throw new \InvalidArgumentException(
'Argument 2 passed to ' .
static::class .
'::' .
__METHOD__ .
'() must contain at least one field set!'
);
}
/**
* @var array $first
*/
$first = $maps[0];
/**
* @var array $map
*/
foreach ($maps as $map) {
if (!$this->is1DArray($map)) {
throw new Issues\MustBeOneDimensionalArray(
'Every map in the second argument should have the same number of columns.'
);
}
}
$queryString = $this->buildInsertQuery($table, \array_keys($first));
// Now let's run a query with the parameters
$stmt = $this->prepare($queryString);
$count = 0;
/**
* @var array $params
*/
foreach ($maps as $params) {
$stmt->execute(\array_values($params));
$count += $stmt->rowCount();
}
return $count;
} | php | public function insertMany(string $table, array $maps): int
{
if (count($maps) < 1) {
throw new \InvalidArgumentException(
'Argument 2 passed to ' .
static::class .
'::' .
__METHOD__ .
'() must contain at least one field set!'
);
}
/**
* @var array $first
*/
$first = $maps[0];
/**
* @var array $map
*/
foreach ($maps as $map) {
if (!$this->is1DArray($map)) {
throw new Issues\MustBeOneDimensionalArray(
'Every map in the second argument should have the same number of columns.'
);
}
}
$queryString = $this->buildInsertQuery($table, \array_keys($first));
// Now let's run a query with the parameters
$stmt = $this->prepare($queryString);
$count = 0;
/**
* @var array $params
*/
foreach ($maps as $params) {
$stmt->execute(\array_values($params));
$count += $stmt->rowCount();
}
return $count;
} | [
"public",
"function",
"insertMany",
"(",
"string",
"$",
"table",
",",
"array",
"$",
"maps",
")",
":",
"int",
"{",
"if",
"(",
"count",
"(",
"$",
"maps",
")",
"<",
"1",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Argument 2 passed to... | Insert many new rows to a table in a database. using the same prepared statement
@param string $table - table name
@param array $maps - array of associative array specifying values should be assigned to each field
@return int
@throws \InvalidArgumentException
@throws Issues\QueryError
@psalm-suppress MixedAssignment
@psalm-suppress MixedArgument | [
"Insert",
"many",
"new",
"rows",
"to",
"a",
"table",
"in",
"a",
"database",
".",
"using",
"the",
"same",
"prepared",
"statement"
] | 2823ff47192a54a315c8f16d548896debc4694ff | https://github.com/paragonie/easydb/blob/2823ff47192a54a315c8f16d548896debc4694ff/src/EasyDB.php#L605-L644 | train |
paragonie/easydb | src/EasyDB.php | EasyDB.safeQuery | public function safeQuery(
string $statement,
array $params = [],
int $fetchStyle = self::DEFAULT_FETCH_STYLE,
bool $returnNumAffected = false,
bool $calledWithVariadicParams = false
) {
if ($fetchStyle === self::DEFAULT_FETCH_STYLE) {
if (isset($this->options[\PDO::ATTR_DEFAULT_FETCH_MODE])) {
/**
* @var int $fetchStyle
*/
$fetchStyle = $this->options[\PDO::ATTR_DEFAULT_FETCH_MODE];
} else {
$fetchStyle = \PDO::FETCH_ASSOC;
}
}
if (empty($params)) {
$stmt = $this->pdo->query($statement);
if ($returnNumAffected) {
return (int) $stmt->rowCount();
}
return $this->getResultsStrictTyped($stmt, $fetchStyle);
}
if (!$this->is1DArray($params)) {
if ($calledWithVariadicParams) {
throw new Issues\MustBeOneDimensionalArray(
'Only one-dimensional arrays are allowed, please use ' .
__METHOD__ .
'()'
);
}
throw new Issues\MustBeOneDimensionalArray(
'Only one-dimensional arrays are allowed.'
);
}
$stmt = $this->prepare($statement);
$stmt->execute($params);
if ($returnNumAffected) {
return (int) $stmt->rowCount();
}
return $this->getResultsStrictTyped($stmt, $fetchStyle);
} | php | public function safeQuery(
string $statement,
array $params = [],
int $fetchStyle = self::DEFAULT_FETCH_STYLE,
bool $returnNumAffected = false,
bool $calledWithVariadicParams = false
) {
if ($fetchStyle === self::DEFAULT_FETCH_STYLE) {
if (isset($this->options[\PDO::ATTR_DEFAULT_FETCH_MODE])) {
/**
* @var int $fetchStyle
*/
$fetchStyle = $this->options[\PDO::ATTR_DEFAULT_FETCH_MODE];
} else {
$fetchStyle = \PDO::FETCH_ASSOC;
}
}
if (empty($params)) {
$stmt = $this->pdo->query($statement);
if ($returnNumAffected) {
return (int) $stmt->rowCount();
}
return $this->getResultsStrictTyped($stmt, $fetchStyle);
}
if (!$this->is1DArray($params)) {
if ($calledWithVariadicParams) {
throw new Issues\MustBeOneDimensionalArray(
'Only one-dimensional arrays are allowed, please use ' .
__METHOD__ .
'()'
);
}
throw new Issues\MustBeOneDimensionalArray(
'Only one-dimensional arrays are allowed.'
);
}
$stmt = $this->prepare($statement);
$stmt->execute($params);
if ($returnNumAffected) {
return (int) $stmt->rowCount();
}
return $this->getResultsStrictTyped($stmt, $fetchStyle);
} | [
"public",
"function",
"safeQuery",
"(",
"string",
"$",
"statement",
",",
"array",
"$",
"params",
"=",
"[",
"]",
",",
"int",
"$",
"fetchStyle",
"=",
"self",
"::",
"DEFAULT_FETCH_STYLE",
",",
"bool",
"$",
"returnNumAffected",
"=",
"false",
",",
"bool",
"$",
... | Perform a Parametrized Query
@param string $statement The query string (hopefully untainted
by user input)
@param array $params The parameters (used in prepared
statements)
@param int $fetchStyle PDO::FETCH_STYLE
@param bool $returnNumAffected Return the number of rows affected?
@param bool $calledWithVariadicParams Indicates method is being invoked from variadic $params method
@return array|int|object
@throws \InvalidArgumentException
@throws Issues\QueryError
@throws \TypeError | [
"Perform",
"a",
"Parametrized",
"Query"
] | 2823ff47192a54a315c8f16d548896debc4694ff | https://github.com/paragonie/easydb/blob/2823ff47192a54a315c8f16d548896debc4694ff/src/EasyDB.php#L834-L878 | train |
paragonie/easydb | src/EasyDB.php | EasyDB.is1DArray | public function is1DArray(array $params): bool
{
return (
\count($params) === \count($params, COUNT_RECURSIVE) &&
\count(\array_filter($params, 'is_array')) < 1
);
} | php | public function is1DArray(array $params): bool
{
return (
\count($params) === \count($params, COUNT_RECURSIVE) &&
\count(\array_filter($params, 'is_array')) < 1
);
} | [
"public",
"function",
"is1DArray",
"(",
"array",
"$",
"params",
")",
":",
"bool",
"{",
"return",
"(",
"\\",
"count",
"(",
"$",
"params",
")",
"===",
"\\",
"count",
"(",
"$",
"params",
",",
"COUNT_RECURSIVE",
")",
"&&",
"\\",
"count",
"(",
"\\",
"arra... | Make sure none of this array's elements are arrays
@param array $params
@return bool | [
"Make",
"sure",
"none",
"of",
"this",
"array",
"s",
"elements",
"are",
"arrays"
] | 2823ff47192a54a315c8f16d548896debc4694ff | https://github.com/paragonie/easydb/blob/2823ff47192a54a315c8f16d548896debc4694ff/src/EasyDB.php#L1092-L1098 | train |
paragonie/easydb | src/EasyDB.php | EasyDB.getValueType | protected function getValueType($v = null): string
{
if (\is_scalar($v) || \is_array($v)) {
return (string) \gettype($v);
}
if (\is_object($v)) {
return 'an instance of ' . \get_class($v);
}
return (string) \var_export($v, true);
} | php | protected function getValueType($v = null): string
{
if (\is_scalar($v) || \is_array($v)) {
return (string) \gettype($v);
}
if (\is_object($v)) {
return 'an instance of ' . \get_class($v);
}
return (string) \var_export($v, true);
} | [
"protected",
"function",
"getValueType",
"(",
"$",
"v",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"\\",
"is_scalar",
"(",
"$",
"v",
")",
"||",
"\\",
"is_array",
"(",
"$",
"v",
")",
")",
"{",
"return",
"(",
"string",
")",
"\\",
"gettype",
"... | Get the type of a variable.
@param mixed $v
@return string | [
"Get",
"the",
"type",
"of",
"a",
"variable",
"."
] | 2823ff47192a54a315c8f16d548896debc4694ff | https://github.com/paragonie/easydb/blob/2823ff47192a54a315c8f16d548896debc4694ff/src/EasyDB.php#L1146-L1155 | train |
thephpleague/flysystem-sftp | src/SftpAdapter.php | SftpAdapter.getHexFingerprintFromSshPublicKey | private function getHexFingerprintFromSshPublicKey ($publickey)
{
$content = explode(' ', $publickey, 3);
return implode(':', str_split(md5(base64_decode($content[1])), 2));
} | php | private function getHexFingerprintFromSshPublicKey ($publickey)
{
$content = explode(' ', $publickey, 3);
return implode(':', str_split(md5(base64_decode($content[1])), 2));
} | [
"private",
"function",
"getHexFingerprintFromSshPublicKey",
"(",
"$",
"publickey",
")",
"{",
"$",
"content",
"=",
"explode",
"(",
"' '",
",",
"$",
"publickey",
",",
"3",
")",
";",
"return",
"implode",
"(",
"':'",
",",
"str_split",
"(",
"md5",
"(",
"base64_... | Convert the SSH RSA public key into a hex formatted fingerprint.
@param string $publickey
@return string Hex formatted fingerprint, e.g. '88:76:75:96:c1:26:7c:dd:9f:87:50:db:ac:c4:a8:7c'. | [
"Convert",
"the",
"SSH",
"RSA",
"public",
"key",
"into",
"a",
"hex",
"formatted",
"fingerprint",
"."
] | d1ac352947ddf375ecb42a024d2072c9a294fee9 | https://github.com/thephpleague/flysystem-sftp/blob/d1ac352947ddf375ecb42a024d2072c9a294fee9/src/SftpAdapter.php#L220-L224 | train |
thephpleague/flysystem-sftp | src/SftpAdapter.php | SftpAdapter.getAuthentication | public function getAuthentication()
{
if ($this->useAgent) {
return $this->getAgent();
}
if ($this->privateKey) {
return $this->getPrivateKey();
}
return $this->getPassword();
} | php | public function getAuthentication()
{
if ($this->useAgent) {
return $this->getAgent();
}
if ($this->privateKey) {
return $this->getPrivateKey();
}
return $this->getPassword();
} | [
"public",
"function",
"getAuthentication",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"useAgent",
")",
"{",
"return",
"$",
"this",
"->",
"getAgent",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"privateKey",
")",
"{",
"return",
"$",
"this",
... | Get the password, either the private key or a plain text password.
@return Agent|RSA|string | [
"Get",
"the",
"password",
"either",
"the",
"private",
"key",
"or",
"a",
"plain",
"text",
"password",
"."
] | d1ac352947ddf375ecb42a024d2072c9a294fee9 | https://github.com/thephpleague/flysystem-sftp/blob/d1ac352947ddf375ecb42a024d2072c9a294fee9/src/SftpAdapter.php#L248-L259 | train |
thephpleague/flysystem-sftp | src/SftpAdapter.php | SftpAdapter.getPrivateKey | public function getPrivateKey()
{
if ("---" !== substr($this->privateKey, 0, 3) && is_file($this->privateKey)) {
$this->privateKey = file_get_contents($this->privateKey);
}
$key = new RSA();
if ($password = $this->getPassword()) {
$key->setPassword($password);
}
$key->loadKey($this->privateKey);
return $key;
} | php | public function getPrivateKey()
{
if ("---" !== substr($this->privateKey, 0, 3) && is_file($this->privateKey)) {
$this->privateKey = file_get_contents($this->privateKey);
}
$key = new RSA();
if ($password = $this->getPassword()) {
$key->setPassword($password);
}
$key->loadKey($this->privateKey);
return $key;
} | [
"public",
"function",
"getPrivateKey",
"(",
")",
"{",
"if",
"(",
"\"---\"",
"!==",
"substr",
"(",
"$",
"this",
"->",
"privateKey",
",",
"0",
",",
"3",
")",
"&&",
"is_file",
"(",
"$",
"this",
"->",
"privateKey",
")",
")",
"{",
"$",
"this",
"->",
"pr... | Get the private key with the password or private key contents.
@return RSA | [
"Get",
"the",
"private",
"key",
"with",
"the",
"password",
"or",
"private",
"key",
"contents",
"."
] | d1ac352947ddf375ecb42a024d2072c9a294fee9 | https://github.com/thephpleague/flysystem-sftp/blob/d1ac352947ddf375ecb42a024d2072c9a294fee9/src/SftpAdapter.php#L266-L281 | train |
thephpleague/flysystem-sftp | src/SftpAdapter.php | SftpAdapter.normalizeListingObject | protected function normalizeListingObject($path, array $object)
{
$permissions = $this->normalizePermissions($object['permissions']);
$type = isset($object['type']) && ($object['type'] === 2) ? 'dir' : 'file';
$timestamp = $object['mtime'];
if ($type === 'dir') {
return compact('path', 'timestamp', 'type');
}
$visibility = $permissions & 0044 ? AdapterInterface::VISIBILITY_PUBLIC : AdapterInterface::VISIBILITY_PRIVATE;
$size = (int) $object['size'];
return compact('path', 'timestamp', 'type', 'visibility', 'size');
} | php | protected function normalizeListingObject($path, array $object)
{
$permissions = $this->normalizePermissions($object['permissions']);
$type = isset($object['type']) && ($object['type'] === 2) ? 'dir' : 'file';
$timestamp = $object['mtime'];
if ($type === 'dir') {
return compact('path', 'timestamp', 'type');
}
$visibility = $permissions & 0044 ? AdapterInterface::VISIBILITY_PUBLIC : AdapterInterface::VISIBILITY_PRIVATE;
$size = (int) $object['size'];
return compact('path', 'timestamp', 'type', 'visibility', 'size');
} | [
"protected",
"function",
"normalizeListingObject",
"(",
"$",
"path",
",",
"array",
"$",
"object",
")",
"{",
"$",
"permissions",
"=",
"$",
"this",
"->",
"normalizePermissions",
"(",
"$",
"object",
"[",
"'permissions'",
"]",
")",
";",
"$",
"type",
"=",
"isse... | Normalize a listing response.
@param string $path
@param array $object
@return array | [
"Normalize",
"a",
"listing",
"response",
"."
] | d1ac352947ddf375ecb42a024d2072c9a294fee9 | https://github.com/thephpleague/flysystem-sftp/blob/d1ac352947ddf375ecb42a024d2072c9a294fee9/src/SftpAdapter.php#L338-L353 | train |
portphp/portphp | src/Writer/BatchWriter.php | BatchWriter.flush | private function flush()
{
foreach ($this->queue as $item) {
$this->delegate->writeItem($item);
}
if ($this->delegate instanceof FlushableWriter) {
$this->delegate->flush();
}
} | php | private function flush()
{
foreach ($this->queue as $item) {
$this->delegate->writeItem($item);
}
if ($this->delegate instanceof FlushableWriter) {
$this->delegate->flush();
}
} | [
"private",
"function",
"flush",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"queue",
"as",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"delegate",
"->",
"writeItem",
"(",
"$",
"item",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"delegate",
"... | Flush the internal buffer to the delegated writer | [
"Flush",
"the",
"internal",
"buffer",
"to",
"the",
"delegated",
"writer"
] | 2c337c28e4802b9d541041891d15268c3961a16e | https://github.com/portphp/portphp/blob/2c337c28e4802b9d541041891d15268c3961a16e/src/Writer/BatchWriter.php#L73-L82 | train |
portphp/portphp | src/ValueConverter/ArrayValueConverterMap.php | ArrayValueConverterMap.convertItem | protected function convertItem($item)
{
foreach ($item as $key => $value) {
if (!isset($this->converters[$key])) {
continue;
}
foreach ($this->converters[$key] as $converter) {
$item[$key] = call_user_func($converter, $item[$key]);
}
}
return $item;
} | php | protected function convertItem($item)
{
foreach ($item as $key => $value) {
if (!isset($this->converters[$key])) {
continue;
}
foreach ($this->converters[$key] as $converter) {
$item[$key] = call_user_func($converter, $item[$key]);
}
}
return $item;
} | [
"protected",
"function",
"convertItem",
"(",
"$",
"item",
")",
"{",
"foreach",
"(",
"$",
"item",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"converters",
"[",
"$",
"key",
"]",
")",
")",
"{",
... | Convert an item of the array using the converter-map
@param $item
@return mixed | [
"Convert",
"an",
"item",
"of",
"the",
"array",
"using",
"the",
"converter",
"-",
"map"
] | 2c337c28e4802b9d541041891d15268c3961a16e | https://github.com/portphp/portphp/blob/2c337c28e4802b9d541041891d15268c3961a16e/src/ValueConverter/ArrayValueConverterMap.php#L48-L61 | train |
portphp/portphp | src/Writer/StreamMergeWriter.php | StreamMergeWriter.setStreamWriters | public function setStreamWriters(array $writers)
{
foreach ($writers as $key => $writer) {
$this->setStreamWriter($key, $writer);
}
return $this;
} | php | public function setStreamWriters(array $writers)
{
foreach ($writers as $key => $writer) {
$this->setStreamWriter($key, $writer);
}
return $this;
} | [
"public",
"function",
"setStreamWriters",
"(",
"array",
"$",
"writers",
")",
"{",
"foreach",
"(",
"$",
"writers",
"as",
"$",
"key",
"=>",
"$",
"writer",
")",
"{",
"$",
"this",
"->",
"setStreamWriter",
"(",
"$",
"key",
",",
"$",
"writer",
")",
";",
"}... | Set stream writers
@param AbstractStreamWriter[] $writers
@return $this | [
"Set",
"stream",
"writers"
] | 2c337c28e4802b9d541041891d15268c3961a16e | https://github.com/portphp/portphp/blob/2c337c28e4802b9d541041891d15268c3961a16e/src/Writer/StreamMergeWriter.php#L68-L75 | train |
portphp/portphp | src/Writer/StreamMergeWriter.php | StreamMergeWriter.setStream | public function setStream($stream)
{
parent::setStream($stream);
foreach ($this->getStreamWriters() as $writer) {
$writer->setStream($stream);
}
return $this;
} | php | public function setStream($stream)
{
parent::setStream($stream);
foreach ($this->getStreamWriters() as $writer) {
$writer->setStream($stream);
}
return $this;
} | [
"public",
"function",
"setStream",
"(",
"$",
"stream",
")",
"{",
"parent",
"::",
"setStream",
"(",
"$",
"stream",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getStreamWriters",
"(",
")",
"as",
"$",
"writer",
")",
"{",
"$",
"writer",
"->",
"setStream"... | Set a stream
@param resource $stream | [
"Set",
"a",
"stream"
] | 2c337c28e4802b9d541041891d15268c3961a16e | https://github.com/portphp/portphp/blob/2c337c28e4802b9d541041891d15268c3961a16e/src/Writer/StreamMergeWriter.php#L131-L139 | train |
portphp/portphp | src/Reader/OneToManyReader.php | OneToManyReader.current | public function current()
{
$leftRow = $this->leftReader->current();
if (array_key_exists($this->nestKey, $leftRow)) {
throw new ReaderException(
sprintf(
'Left Row: "%s" Reader already contains a field named "%s". Please choose a different nest key field',
$this->key(),
$this->nestKey
)
);
}
$leftRow[$this->nestKey] = [];
$leftId = $this->getRowId($leftRow, $this->leftJoinField);
$rightRow = $this->rightReader->current();
$rightId = $this->getRowId($rightRow, $this->rightJoinField);
while ($leftId == $rightId && $this->rightReader->valid()) {
$leftRow[$this->nestKey][] = $rightRow;
$this->rightReader->next();
$rightRow = $this->rightReader->current();
if($this->rightReader->valid()) {
$rightId = $this->getRowId($rightRow, $this->rightJoinField);
}
}
return $leftRow;
} | php | public function current()
{
$leftRow = $this->leftReader->current();
if (array_key_exists($this->nestKey, $leftRow)) {
throw new ReaderException(
sprintf(
'Left Row: "%s" Reader already contains a field named "%s". Please choose a different nest key field',
$this->key(),
$this->nestKey
)
);
}
$leftRow[$this->nestKey] = [];
$leftId = $this->getRowId($leftRow, $this->leftJoinField);
$rightRow = $this->rightReader->current();
$rightId = $this->getRowId($rightRow, $this->rightJoinField);
while ($leftId == $rightId && $this->rightReader->valid()) {
$leftRow[$this->nestKey][] = $rightRow;
$this->rightReader->next();
$rightRow = $this->rightReader->current();
if($this->rightReader->valid()) {
$rightId = $this->getRowId($rightRow, $this->rightJoinField);
}
}
return $leftRow;
} | [
"public",
"function",
"current",
"(",
")",
"{",
"$",
"leftRow",
"=",
"$",
"this",
"->",
"leftReader",
"->",
"current",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"this",
"->",
"nestKey",
",",
"$",
"leftRow",
")",
")",
"{",
"throw",
"new"... | Create an array of children in the leftRow,
with the data returned from the right reader
Where the ID fields Match
@return array
@throws ReaderException | [
"Create",
"an",
"array",
"of",
"children",
"in",
"the",
"leftRow",
"with",
"the",
"data",
"returned",
"from",
"the",
"right",
"reader",
"Where",
"the",
"ID",
"fields",
"Match"
] | 2c337c28e4802b9d541041891d15268c3961a16e | https://github.com/portphp/portphp/blob/2c337c28e4802b9d541041891d15268c3961a16e/src/Reader/OneToManyReader.php#L77-L109 | train |
prestaconcept/PrestaSitemapBundle | Sitemap/Url/GoogleMultilangUrlDecorator.php | GoogleMultilangUrlDecorator.addLink | public function addLink($href, $hreflang, $rel = null)
{
$this->linkXml .= $this->generateLinkXml($href, $hreflang, $rel);
return $this;
} | php | public function addLink($href, $hreflang, $rel = null)
{
$this->linkXml .= $this->generateLinkXml($href, $hreflang, $rel);
return $this;
} | [
"public",
"function",
"addLink",
"(",
"$",
"href",
",",
"$",
"hreflang",
",",
"$",
"rel",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"linkXml",
".=",
"$",
"this",
"->",
"generateLinkXml",
"(",
"$",
"href",
",",
"$",
"hreflang",
",",
"$",
"rel",
")",... | add an alternative language to the url
@param string $href Valid url of the translated page
@param string $hreflang Valid language code @see
http://www.w3.org/TR/xhtml-modularization/abstraction.html#dt_LanguageCode
@param string|null $rel (default is alternate) - valid link type @see
http://www.w3.org/TR/xhtml-modularization/abstraction.html#dt_LinkTypes
@return GoogleMultilangUrlDecorator | [
"add",
"an",
"alternative",
"language",
"to",
"the",
"url"
] | 5c9f41e6fee40477f256250a1f1859b2208ff4b7 | https://github.com/prestaconcept/PrestaSitemapBundle/blob/5c9f41e6fee40477f256250a1f1859b2208ff4b7/Sitemap/Url/GoogleMultilangUrlDecorator.php#L48-L53 | train |
prestaconcept/PrestaSitemapBundle | Sitemap/Url/GoogleImage.php | GoogleImage.toXML | public function toXML()
{
$xml = '<image:image>';
$xml .= '<image:loc>' . Utils::encode($this->getLoc()) . '</image:loc>';
if ($this->getCaption()) {
$xml .= '<image:caption>' . Utils::render($this->getCaption()) . '</image:caption>';
}
if ($this->getGeoLocation()) {
$xml .= '<image:geo_location>' . Utils::render($this->getGeoLocation()) . '</image:geo_location>';
}
if ($this->getTitle()) {
$xml .= '<image:title>' . Utils::render($this->getTitle()) . '</image:title>';
}
if ($this->getLicense()) {
$xml .= '<image:license>' . Utils::render($this->getLicense()) . '</image:license>';
}
$xml .= '</image:image>';
return $xml;
} | php | public function toXML()
{
$xml = '<image:image>';
$xml .= '<image:loc>' . Utils::encode($this->getLoc()) . '</image:loc>';
if ($this->getCaption()) {
$xml .= '<image:caption>' . Utils::render($this->getCaption()) . '</image:caption>';
}
if ($this->getGeoLocation()) {
$xml .= '<image:geo_location>' . Utils::render($this->getGeoLocation()) . '</image:geo_location>';
}
if ($this->getTitle()) {
$xml .= '<image:title>' . Utils::render($this->getTitle()) . '</image:title>';
}
if ($this->getLicense()) {
$xml .= '<image:license>' . Utils::render($this->getLicense()) . '</image:license>';
}
$xml .= '</image:image>';
return $xml;
} | [
"public",
"function",
"toXML",
"(",
")",
"{",
"$",
"xml",
"=",
"'<image:image>'",
";",
"$",
"xml",
".=",
"'<image:loc>'",
".",
"Utils",
"::",
"encode",
"(",
"$",
"this",
"->",
"getLoc",
"(",
")",
")",
".",
"'</image:loc>'",
";",
"if",
"(",
"$",
"this... | Return the xml representation for the image
@return string | [
"Return",
"the",
"xml",
"representation",
"for",
"the",
"image"
] | 5c9f41e6fee40477f256250a1f1859b2208ff4b7 | https://github.com/prestaconcept/PrestaSitemapBundle/blob/5c9f41e6fee40477f256250a1f1859b2208ff4b7/Sitemap/Url/GoogleImage.php#L172-L197 | train |
prestaconcept/PrestaSitemapBundle | Sitemap/Utils.php | Utils.getSetMethod | public static function getSetMethod($object, $name)
{
$methodName = 'set' . self::camelize($name);
if (!method_exists($object, $methodName)) {
throw new Exception(sprintf('The set method for parameter %s is missing', $name));
}
return $methodName;
} | php | public static function getSetMethod($object, $name)
{
$methodName = 'set' . self::camelize($name);
if (!method_exists($object, $methodName)) {
throw new Exception(sprintf('The set method for parameter %s is missing', $name));
}
return $methodName;
} | [
"public",
"static",
"function",
"getSetMethod",
"(",
"$",
"object",
",",
"$",
"name",
")",
"{",
"$",
"methodName",
"=",
"'set'",
".",
"self",
"::",
"camelize",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"object",
",",
"$",... | Verify method affiliated to given param
@param object $object
@param string $name
@return string | [
"Verify",
"method",
"affiliated",
"to",
"given",
"param"
] | 5c9f41e6fee40477f256250a1f1859b2208ff4b7 | https://github.com/prestaconcept/PrestaSitemapBundle/blob/5c9f41e6fee40477f256250a1f1859b2208ff4b7/Sitemap/Utils.php#L35-L44 | train |
prestaconcept/PrestaSitemapBundle | Controller/SitemapController.php | SitemapController.sectionAction | public function sectionAction($name)
{
$section = $this->getGenerator()->fetch($name);
if (!$section) {
throw $this->createNotFoundException();
}
$response = Response::create($section->toXml());
$response->setPublic();
$response->setClientTtl($this->getTtl());
return $response;
} | php | public function sectionAction($name)
{
$section = $this->getGenerator()->fetch($name);
if (!$section) {
throw $this->createNotFoundException();
}
$response = Response::create($section->toXml());
$response->setPublic();
$response->setClientTtl($this->getTtl());
return $response;
} | [
"public",
"function",
"sectionAction",
"(",
"$",
"name",
")",
"{",
"$",
"section",
"=",
"$",
"this",
"->",
"getGenerator",
"(",
")",
"->",
"fetch",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"$",
"section",
")",
"{",
"throw",
"$",
"this",
"->",
... | list urls of a section
@param string $name
@return Response | [
"list",
"urls",
"of",
"a",
"section"
] | 5c9f41e6fee40477f256250a1f1859b2208ff4b7 | https://github.com/prestaconcept/PrestaSitemapBundle/blob/5c9f41e6fee40477f256250a1f1859b2208ff4b7/Controller/SitemapController.php#L52-L65 | train |
prestaconcept/PrestaSitemapBundle | Service/Dumper.php | Dumper.prepareTempFolder | protected function prepareTempFolder()
{
$this->tmpFolder = sys_get_temp_dir() . '/PrestaSitemaps-' . uniqid();
$this->filesystem->mkdir($this->tmpFolder);
} | php | protected function prepareTempFolder()
{
$this->tmpFolder = sys_get_temp_dir() . '/PrestaSitemaps-' . uniqid();
$this->filesystem->mkdir($this->tmpFolder);
} | [
"protected",
"function",
"prepareTempFolder",
"(",
")",
"{",
"$",
"this",
"->",
"tmpFolder",
"=",
"sys_get_temp_dir",
"(",
")",
".",
"'/PrestaSitemaps-'",
".",
"uniqid",
"(",
")",
";",
"$",
"this",
"->",
"filesystem",
"->",
"mkdir",
"(",
"$",
"this",
"->",... | Prepares temp folder for storing sitemap files
@return void | [
"Prepares",
"temp",
"folder",
"for",
"storing",
"sitemap",
"files"
] | 5c9f41e6fee40477f256250a1f1859b2208ff4b7 | https://github.com/prestaconcept/PrestaSitemapBundle/blob/5c9f41e6fee40477f256250a1f1859b2208ff4b7/Service/Dumper.php#L128-L132 | train |
prestaconcept/PrestaSitemapBundle | Service/Dumper.php | Dumper.cleanup | protected function cleanup()
{
$this->filesystem->remove($this->tmpFolder);
$this->root = null;
$this->urlsets = array();
} | php | protected function cleanup()
{
$this->filesystem->remove($this->tmpFolder);
$this->root = null;
$this->urlsets = array();
} | [
"protected",
"function",
"cleanup",
"(",
")",
"{",
"$",
"this",
"->",
"filesystem",
"->",
"remove",
"(",
"$",
"this",
"->",
"tmpFolder",
")",
";",
"$",
"this",
"->",
"root",
"=",
"null",
";",
"$",
"this",
"->",
"urlsets",
"=",
"array",
"(",
")",
";... | Cleans up temporary files
@return void | [
"Cleans",
"up",
"temporary",
"files"
] | 5c9f41e6fee40477f256250a1f1859b2208ff4b7 | https://github.com/prestaconcept/PrestaSitemapBundle/blob/5c9f41e6fee40477f256250a1f1859b2208ff4b7/Service/Dumper.php#L139-L144 | train |
prestaconcept/PrestaSitemapBundle | Service/Dumper.php | Dumper.loadCurrentSitemapIndex | protected function loadCurrentSitemapIndex($filename)
{
if (!file_exists($filename)) {
return array();
}
$urlsets = array();
$index = simplexml_load_file($filename);
foreach ($index->children() as $child) {
/** @var $child \SimpleXMLElement */
if ($child->getName() == 'sitemap') {
if (!isset($child->loc)) {
throw new \InvalidArgumentException(
"One of referenced sitemaps in $filename doesn't contain 'loc' attribute"
);
}
$basename = preg_replace(
'/^' . preg_quote($this->sitemapFilePrefix) . '\.(.+)\.xml(?:\.gz)?$/',
'\1',
basename($child->loc)
); // cut .xml|.xml.gz
if (!isset($child->lastmod)) {
throw new \InvalidArgumentException(
"One of referenced sitemaps in $filename doesn't contain 'lastmod' attribute"
);
}
$lastmod = new \DateTime($child->lastmod);
$urlsets[$basename] = $this->newUrlset($basename, $lastmod);
}
}
return $urlsets;
} | php | protected function loadCurrentSitemapIndex($filename)
{
if (!file_exists($filename)) {
return array();
}
$urlsets = array();
$index = simplexml_load_file($filename);
foreach ($index->children() as $child) {
/** @var $child \SimpleXMLElement */
if ($child->getName() == 'sitemap') {
if (!isset($child->loc)) {
throw new \InvalidArgumentException(
"One of referenced sitemaps in $filename doesn't contain 'loc' attribute"
);
}
$basename = preg_replace(
'/^' . preg_quote($this->sitemapFilePrefix) . '\.(.+)\.xml(?:\.gz)?$/',
'\1',
basename($child->loc)
); // cut .xml|.xml.gz
if (!isset($child->lastmod)) {
throw new \InvalidArgumentException(
"One of referenced sitemaps in $filename doesn't contain 'lastmod' attribute"
);
}
$lastmod = new \DateTime($child->lastmod);
$urlsets[$basename] = $this->newUrlset($basename, $lastmod);
}
}
return $urlsets;
} | [
"protected",
"function",
"loadCurrentSitemapIndex",
"(",
"$",
"filename",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"filename",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"urlsets",
"=",
"array",
"(",
")",
";",
"$",
"index",
... | Loads sitemap index XML file and returns array of Urlset objects
@param string $filename
@return Urlset[]
@throws \InvalidArgumentException | [
"Loads",
"sitemap",
"index",
"XML",
"file",
"and",
"returns",
"array",
"of",
"Urlset",
"objects"
] | 5c9f41e6fee40477f256250a1f1859b2208ff4b7 | https://github.com/prestaconcept/PrestaSitemapBundle/blob/5c9f41e6fee40477f256250a1f1859b2208ff4b7/Service/Dumper.php#L154-L187 | train |
prestaconcept/PrestaSitemapBundle | Service/Dumper.php | Dumper.activate | protected function activate($targetDir)
{
if (!is_dir($targetDir)) {
mkdir($targetDir, 0777, true);
}
if (!is_writable($targetDir)) {
$this->cleanup();
throw new \RuntimeException(
sprintf('Can\'t move sitemaps to "%s" - directory is not writeable', $targetDir)
);
}
$this->deleteExistingSitemaps($targetDir);
// no need to delete the root file as it always exists, it will be overwritten
$this->filesystem->mirror($this->tmpFolder, $targetDir, null, array('override' => true));
$this->cleanup();
} | php | protected function activate($targetDir)
{
if (!is_dir($targetDir)) {
mkdir($targetDir, 0777, true);
}
if (!is_writable($targetDir)) {
$this->cleanup();
throw new \RuntimeException(
sprintf('Can\'t move sitemaps to "%s" - directory is not writeable', $targetDir)
);
}
$this->deleteExistingSitemaps($targetDir);
// no need to delete the root file as it always exists, it will be overwritten
$this->filesystem->mirror($this->tmpFolder, $targetDir, null, array('override' => true));
$this->cleanup();
} | [
"protected",
"function",
"activate",
"(",
"$",
"targetDir",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"targetDir",
")",
")",
"{",
"mkdir",
"(",
"$",
"targetDir",
",",
"0777",
",",
"true",
")",
";",
"}",
"if",
"(",
"!",
"is_writable",
"(",
"$",
... | Moves sitemaps created in a temporary folder to their real location
@param string $targetDir Directory to move created sitemaps to
@throws \RuntimeException | [
"Moves",
"sitemaps",
"created",
"in",
"a",
"temporary",
"folder",
"to",
"their",
"real",
"location"
] | 5c9f41e6fee40477f256250a1f1859b2208ff4b7 | https://github.com/prestaconcept/PrestaSitemapBundle/blob/5c9f41e6fee40477f256250a1f1859b2208ff4b7/Service/Dumper.php#L196-L213 | train |
prestaconcept/PrestaSitemapBundle | Service/Dumper.php | Dumper.deleteExistingSitemaps | protected function deleteExistingSitemaps($targetDir)
{
foreach ($this->urlsets as $urlset) {
$basename = basename($urlset->getLoc());
if (preg_match('/(.*)_[\d]+\.xml(?:\.gz)?$/', $basename)) {
continue; // skip numbered files
}
// pattern is base name of sitemap file (with .xml cut) optionally followed by _X for numbered files
$basename = preg_replace('/\.xml(?:\.gz)?$/', '', $basename); // cut .xml|.xml.gz
$pattern = '/' . preg_quote($basename, '/') . '(_\d+)?\.xml(?:\.gz)?$/';
foreach (Finder::create()->in($targetDir)->depth(0)->name($pattern)->files() as $file) {
$this->filesystem->remove($file);
}
}
} | php | protected function deleteExistingSitemaps($targetDir)
{
foreach ($this->urlsets as $urlset) {
$basename = basename($urlset->getLoc());
if (preg_match('/(.*)_[\d]+\.xml(?:\.gz)?$/', $basename)) {
continue; // skip numbered files
}
// pattern is base name of sitemap file (with .xml cut) optionally followed by _X for numbered files
$basename = preg_replace('/\.xml(?:\.gz)?$/', '', $basename); // cut .xml|.xml.gz
$pattern = '/' . preg_quote($basename, '/') . '(_\d+)?\.xml(?:\.gz)?$/';
foreach (Finder::create()->in($targetDir)->depth(0)->name($pattern)->files() as $file) {
$this->filesystem->remove($file);
}
}
} | [
"protected",
"function",
"deleteExistingSitemaps",
"(",
"$",
"targetDir",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"urlsets",
"as",
"$",
"urlset",
")",
"{",
"$",
"basename",
"=",
"basename",
"(",
"$",
"urlset",
"->",
"getLoc",
"(",
")",
")",
";",
"... | Deletes sitemap files matching filename patterns of newly generated files
@param string $targetDir | [
"Deletes",
"sitemap",
"files",
"matching",
"filename",
"patterns",
"of",
"newly",
"generated",
"files"
] | 5c9f41e6fee40477f256250a1f1859b2208ff4b7 | https://github.com/prestaconcept/PrestaSitemapBundle/blob/5c9f41e6fee40477f256250a1f1859b2208ff4b7/Service/Dumper.php#L220-L234 | train |
prestaconcept/PrestaSitemapBundle | Sitemap/Url/UrlConcrete.php | UrlConcrete.setChangefreq | public function setChangefreq($changefreq = null)
{
$frequencies = [
self::CHANGEFREQ_ALWAYS,
self::CHANGEFREQ_HOURLY,
self::CHANGEFREQ_DAILY,
self::CHANGEFREQ_WEEKLY,
self::CHANGEFREQ_MONTHLY,
self::CHANGEFREQ_YEARLY,
self::CHANGEFREQ_NEVER,
null,
];
if (!in_array($changefreq, $frequencies)) {
throw new \RuntimeException(
sprintf(
'The value "%s" is not supported by the option changefreq. See http://www.sitemaps.org/protocol.html#xmlTagDefinitions',
$changefreq
)
);
}
$this->changefreq = $changefreq;
return $this;
} | php | public function setChangefreq($changefreq = null)
{
$frequencies = [
self::CHANGEFREQ_ALWAYS,
self::CHANGEFREQ_HOURLY,
self::CHANGEFREQ_DAILY,
self::CHANGEFREQ_WEEKLY,
self::CHANGEFREQ_MONTHLY,
self::CHANGEFREQ_YEARLY,
self::CHANGEFREQ_NEVER,
null,
];
if (!in_array($changefreq, $frequencies)) {
throw new \RuntimeException(
sprintf(
'The value "%s" is not supported by the option changefreq. See http://www.sitemaps.org/protocol.html#xmlTagDefinitions',
$changefreq
)
);
}
$this->changefreq = $changefreq;
return $this;
} | [
"public",
"function",
"setChangefreq",
"(",
"$",
"changefreq",
"=",
"null",
")",
"{",
"$",
"frequencies",
"=",
"[",
"self",
"::",
"CHANGEFREQ_ALWAYS",
",",
"self",
"::",
"CHANGEFREQ_HOURLY",
",",
"self",
"::",
"CHANGEFREQ_DAILY",
",",
"self",
"::",
"CHANGEFREQ... | Define the change frequency of this entry
@param string|null $changefreq Define the change frequency
@return UrlConcrete | [
"Define",
"the",
"change",
"frequency",
"of",
"this",
"entry"
] | 5c9f41e6fee40477f256250a1f1859b2208ff4b7 | https://github.com/prestaconcept/PrestaSitemapBundle/blob/5c9f41e6fee40477f256250a1f1859b2208ff4b7/Sitemap/Url/UrlConcrete.php#L116-L140 | train |
prestaconcept/PrestaSitemapBundle | Sitemap/Url/UrlConcrete.php | UrlConcrete.setPriority | public function setPriority($priority = null)
{
if (!$priority) {
return $this;
}
if ($priority && is_numeric($priority) && $priority >= 0 && $priority <= 1) {
$this->priority = number_format($priority, 1);
} else {
throw new \RuntimeException(
sprintf(
'The value "%s" is not supported by the option priority, it must be a numeric between 0.0 and 1.0. See http://www.sitemaps.org/protocol.html#xmlTagDefinitions',
$priority
)
);
}
return $this;
} | php | public function setPriority($priority = null)
{
if (!$priority) {
return $this;
}
if ($priority && is_numeric($priority) && $priority >= 0 && $priority <= 1) {
$this->priority = number_format($priority, 1);
} else {
throw new \RuntimeException(
sprintf(
'The value "%s" is not supported by the option priority, it must be a numeric between 0.0 and 1.0. See http://www.sitemaps.org/protocol.html#xmlTagDefinitions',
$priority
)
);
}
return $this;
} | [
"public",
"function",
"setPriority",
"(",
"$",
"priority",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"priority",
")",
"{",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"$",
"priority",
"&&",
"is_numeric",
"(",
"$",
"priority",
")",
"&&",
"$",
"pri... | Define the priority of this entry
@param float|null $priority Define the priority
@return UrlConcrete | [
"Define",
"the",
"priority",
"of",
"this",
"entry"
] | 5c9f41e6fee40477f256250a1f1859b2208ff4b7 | https://github.com/prestaconcept/PrestaSitemapBundle/blob/5c9f41e6fee40477f256250a1f1859b2208ff4b7/Sitemap/Url/UrlConcrete.php#L159-L177 | train |
prestaconcept/PrestaSitemapBundle | Service/AbstractGenerator.php | AbstractGenerator.getUrlset | public function getUrlset($name)
{
if (!isset($this->urlsets[$name])) {
$this->urlsets[$name] = $this->newUrlset($name);
}
return $this->urlsets[$name];
} | php | public function getUrlset($name)
{
if (!isset($this->urlsets[$name])) {
$this->urlsets[$name] = $this->newUrlset($name);
}
return $this->urlsets[$name];
} | [
"public",
"function",
"getUrlset",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"urlsets",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"urlsets",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"newUr... | get or create urlset
@param string $name
@return Urlset | [
"get",
"or",
"create",
"urlset"
] | 5c9f41e6fee40477f256250a1f1859b2208ff4b7 | https://github.com/prestaconcept/PrestaSitemapBundle/blob/5c9f41e6fee40477f256250a1f1859b2208ff4b7/Service/AbstractGenerator.php#L120-L127 | train |
prestaconcept/PrestaSitemapBundle | Service/AbstractGenerator.php | AbstractGenerator.populate | protected function populate($section = null)
{
$event = new SitemapPopulateEvent($this, $section);
$this->dispatcher->dispatch(SitemapPopulateEvent::ON_SITEMAP_POPULATE, $event);
} | php | protected function populate($section = null)
{
$event = new SitemapPopulateEvent($this, $section);
$this->dispatcher->dispatch(SitemapPopulateEvent::ON_SITEMAP_POPULATE, $event);
} | [
"protected",
"function",
"populate",
"(",
"$",
"section",
"=",
"null",
")",
"{",
"$",
"event",
"=",
"new",
"SitemapPopulateEvent",
"(",
"$",
"this",
",",
"$",
"section",
")",
";",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"SitemapPopulateEven... | Dispatches SitemapPopulate Event - the listeners should use it to add their URLs to the sitemap
@param string|null $section | [
"Dispatches",
"SitemapPopulate",
"Event",
"-",
"the",
"listeners",
"should",
"use",
"it",
"to",
"add",
"their",
"URLs",
"to",
"the",
"sitemap"
] | 5c9f41e6fee40477f256250a1f1859b2208ff4b7 | https://github.com/prestaconcept/PrestaSitemapBundle/blob/5c9f41e6fee40477f256250a1f1859b2208ff4b7/Service/AbstractGenerator.php#L144-L148 | train |
prestaconcept/PrestaSitemapBundle | Sitemap/Url/GoogleVideoUrlDecorator.php | GoogleVideoUrlDecorator.addPrice | public function addPrice($amount, $currency, $type = null, $resolution = null)
{
$this->prices[] = array(
'amount' => $amount,
'currency' => $currency,
'type' => $type,
'resolution' => $resolution,
);
return $this;
} | php | public function addPrice($amount, $currency, $type = null, $resolution = null)
{
$this->prices[] = array(
'amount' => $amount,
'currency' => $currency,
'type' => $type,
'resolution' => $resolution,
);
return $this;
} | [
"public",
"function",
"addPrice",
"(",
"$",
"amount",
",",
"$",
"currency",
",",
"$",
"type",
"=",
"null",
",",
"$",
"resolution",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"prices",
"[",
"]",
"=",
"array",
"(",
"'amount'",
"=>",
"$",
"amount",
","... | add price element
@param float $amount
@param string $currency - ISO 4217 format.
@param string|null $type - rent or own
@param string|null $resolution - hd or sd
@return GoogleVideoUrlDecorator | [
"add",
"price",
"element"
] | 5c9f41e6fee40477f256250a1f1859b2208ff4b7 | https://github.com/prestaconcept/PrestaSitemapBundle/blob/5c9f41e6fee40477f256250a1f1859b2208ff4b7/Sitemap/Url/GoogleVideoUrlDecorator.php#L770-L780 | train |
prestaconcept/PrestaSitemapBundle | Sitemap/Urlset.php | Urlset.addUrl | public function addUrl(Url $url)
{
if ($this->isFull()) {
throw new \RuntimeException('The urlset limit has been exceeded');
}
$urlXml = $url->toXml();
$this->appendXML($urlXml);
//add unknown custom namespaces
$this->customNamespaces = array_merge($this->customNamespaces, $url->getCustomNamespaces());
//---------------------
//Check limits
if ($this->countItems++ >= self::LIMIT_ITEMS) {
$this->limitItemsReached = true;
}
$urlLength = strlen($urlXml);
$this->countBytes += $urlLength;
if ($this->countBytes + $urlLength + strlen($this->getStructureXml()) > self::LIMIT_BYTES) {
//we suppose the next url is almost the same length and cannot be added
//plus we keep 500kB (@see self::LIMIT_BYTES)
//... beware of numerous images set in url
$this->limitBytesReached = true;
}
//---------------------
} | php | public function addUrl(Url $url)
{
if ($this->isFull()) {
throw new \RuntimeException('The urlset limit has been exceeded');
}
$urlXml = $url->toXml();
$this->appendXML($urlXml);
//add unknown custom namespaces
$this->customNamespaces = array_merge($this->customNamespaces, $url->getCustomNamespaces());
//---------------------
//Check limits
if ($this->countItems++ >= self::LIMIT_ITEMS) {
$this->limitItemsReached = true;
}
$urlLength = strlen($urlXml);
$this->countBytes += $urlLength;
if ($this->countBytes + $urlLength + strlen($this->getStructureXml()) > self::LIMIT_BYTES) {
//we suppose the next url is almost the same length and cannot be added
//plus we keep 500kB (@see self::LIMIT_BYTES)
//... beware of numerous images set in url
$this->limitBytesReached = true;
}
//---------------------
} | [
"public",
"function",
"addUrl",
"(",
"Url",
"$",
"url",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isFull",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'The urlset limit has been exceeded'",
")",
";",
"}",
"$",
"urlXml",
"=",
"$",
... | add url to pool and check limits
@param Url $url
@throws \RuntimeException | [
"add",
"url",
"to",
"pool",
"and",
"check",
"limits"
] | 5c9f41e6fee40477f256250a1f1859b2208ff4b7 | https://github.com/prestaconcept/PrestaSitemapBundle/blob/5c9f41e6fee40477f256250a1f1859b2208ff4b7/Sitemap/Urlset.php#L79-L107 | train |
prestaconcept/PrestaSitemapBundle | Sitemap/Urlset.php | Urlset.getStructureXml | protected function getStructureXml()
{
$struct = '<?xml version="1.0" encoding="UTF-8"?>';
$struct .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" NAMESPACES>URLS</urlset>';
$namespaces = '';
foreach ($this->customNamespaces as $key => $location) {
$namespaces .= ' xmlns:' . $key . '="' . $location . '"';
}
$struct = str_replace('NAMESPACES', $namespaces, $struct);
return $struct;
} | php | protected function getStructureXml()
{
$struct = '<?xml version="1.0" encoding="UTF-8"?>';
$struct .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" NAMESPACES>URLS</urlset>';
$namespaces = '';
foreach ($this->customNamespaces as $key => $location) {
$namespaces .= ' xmlns:' . $key . '="' . $location . '"';
}
$struct = str_replace('NAMESPACES', $namespaces, $struct);
return $struct;
} | [
"protected",
"function",
"getStructureXml",
"(",
")",
"{",
"$",
"struct",
"=",
"'<?xml version=\"1.0\" encoding=\"UTF-8\"?>'",
";",
"$",
"struct",
".=",
"'<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" NAMESPACES>URLS</urlset>'",
";",
"$",
"namespaces",
"=",
"''"... | get the xml structure of the current urlset
@return string | [
"get",
"the",
"xml",
"structure",
"of",
"the",
"current",
"urlset"
] | 5c9f41e6fee40477f256250a1f1859b2208ff4b7 | https://github.com/prestaconcept/PrestaSitemapBundle/blob/5c9f41e6fee40477f256250a1f1859b2208ff4b7/Sitemap/Urlset.php#L124-L137 | train |
cloudinary/cloudinary_php | src/Cache/Adapter/KeyValueCacheAdapter.php | KeyValueCacheAdapter.generateCacheKey | public static function generateCacheKey($publicId, $type, $resourceType, $transformation, $format)
{
return sha1(implode("/", array_filter([$publicId, $type, $resourceType, $transformation, $format])));
} | php | public static function generateCacheKey($publicId, $type, $resourceType, $transformation, $format)
{
return sha1(implode("/", array_filter([$publicId, $type, $resourceType, $transformation, $format])));
} | [
"public",
"static",
"function",
"generateCacheKey",
"(",
"$",
"publicId",
",",
"$",
"type",
",",
"$",
"resourceType",
",",
"$",
"transformation",
",",
"$",
"format",
")",
"{",
"return",
"sha1",
"(",
"implode",
"(",
"\"/\"",
",",
"array_filter",
"(",
"[",
... | Generates key-value storage key from parameters
@param string $publicId The public ID of the resource
@param string $type The storage type
@param string $resourceType The type of the resource
@param string $transformation The transformation string
@param string $format The format of the resource
@return string Resulting cache key | [
"Generates",
"key",
"-",
"value",
"storage",
"key",
"from",
"parameters"
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/src/Cache/Adapter/KeyValueCacheAdapter.php#L106-L109 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Driver_PDO.connect | public function connect() {
if ($this->isConnected) return;
$user = $this->connectInfo['user'];
$pass = $this->connectInfo['pass'];
//PDO::MYSQL_ATTR_INIT_COMMAND
$this->pdo = new PDO(
$this->dsn,
$user,
$pass,
array(1002 => 'SET NAMES utf8',
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
)
);
$this->pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
$this->isConnected = true;
} | php | public function connect() {
if ($this->isConnected) return;
$user = $this->connectInfo['user'];
$pass = $this->connectInfo['pass'];
//PDO::MYSQL_ATTR_INIT_COMMAND
$this->pdo = new PDO(
$this->dsn,
$user,
$pass,
array(1002 => 'SET NAMES utf8',
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
)
);
$this->pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
$this->isConnected = true;
} | [
"public",
"function",
"connect",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isConnected",
")",
"return",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"connectInfo",
"[",
"'user'",
"]",
";",
"$",
"pass",
"=",
"$",
"this",
"->",
"connectInfo",
"[",
"... | Establishes a connection to the database using PHP PDO
functionality. If a connection has already been established this
method will simply return directly. This method also turns on
UTF8 for the database and PDO-ERRMODE-EXCEPTION as well as
PDO-FETCH-ASSOC.
@return void | [
"Establishes",
"a",
"connection",
"to",
"the",
"database",
"using",
"PHP",
"PDO",
"functionality",
".",
"If",
"a",
"connection",
"has",
"already",
"been",
"established",
"this",
"method",
"will",
"simply",
"return",
"directly",
".",
"This",
"method",
"also",
"... | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L598-L615 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Driver_PDO.bindParams | protected function bindParams($s,$aValues) {
foreach($aValues as $key=>&$value) {
if (is_integer($key)) {
if (is_null($value)){
$s->bindValue($key+1,null,PDO::PARAM_NULL);
}
elseif (!$this->flagUseStringOnlyBinding && RedBean_QueryWriter_AQueryWriter::canBeTreatedAsInt($value) && $value < 2147483648) {
$s->bindParam($key+1,$value,PDO::PARAM_INT);
}
else {
$s->bindParam($key+1,$value,PDO::PARAM_STR);
}
}
else {
if (is_null($value)){
$s->bindValue($key,null,PDO::PARAM_NULL);
}
elseif (!$this->flagUseStringOnlyBinding && RedBean_QueryWriter_AQueryWriter::canBeTreatedAsInt($value) && $value < 2147483648) {
$s->bindParam($key,$value,PDO::PARAM_INT);
}
else {
$s->bindParam($key,$value,PDO::PARAM_STR);
}
}
}
} | php | protected function bindParams($s,$aValues) {
foreach($aValues as $key=>&$value) {
if (is_integer($key)) {
if (is_null($value)){
$s->bindValue($key+1,null,PDO::PARAM_NULL);
}
elseif (!$this->flagUseStringOnlyBinding && RedBean_QueryWriter_AQueryWriter::canBeTreatedAsInt($value) && $value < 2147483648) {
$s->bindParam($key+1,$value,PDO::PARAM_INT);
}
else {
$s->bindParam($key+1,$value,PDO::PARAM_STR);
}
}
else {
if (is_null($value)){
$s->bindValue($key,null,PDO::PARAM_NULL);
}
elseif (!$this->flagUseStringOnlyBinding && RedBean_QueryWriter_AQueryWriter::canBeTreatedAsInt($value) && $value < 2147483648) {
$s->bindParam($key,$value,PDO::PARAM_INT);
}
else {
$s->bindParam($key,$value,PDO::PARAM_STR);
}
}
}
} | [
"protected",
"function",
"bindParams",
"(",
"$",
"s",
",",
"$",
"aValues",
")",
"{",
"foreach",
"(",
"$",
"aValues",
"as",
"$",
"key",
"=>",
"&",
"$",
"value",
")",
"{",
"if",
"(",
"is_integer",
"(",
"$",
"key",
")",
")",
"{",
"if",
"(",
"is_null... | Binds parameters. This method binds parameters to a PDOStatement for
Query Execution. This method binds parameters as NULL, INTEGER or STRING
and supports both named keys and question mark keys.
@param PDOStatement $s PDO Statement instance
@param array $aValues values that need to get bound to the statement
@return void | [
"Binds",
"parameters",
".",
"This",
"method",
"binds",
"parameters",
"to",
"a",
"PDOStatement",
"for",
"Query",
"Execution",
".",
"This",
"method",
"binds",
"parameters",
"as",
"NULL",
"INTEGER",
"or",
"STRING",
"and",
"supports",
"both",
"named",
"keys",
"and... | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L627-L654 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Driver_PDO.GetCol | public function GetCol($sql, $aValues=array()) {
$rows = $this->GetAll($sql,$aValues);
$cols = array();
if ($rows && is_array($rows) && count($rows)>0) {
foreach ($rows as $row) {
$cols[] = array_shift($row);
}
}
return $cols;
} | php | public function GetCol($sql, $aValues=array()) {
$rows = $this->GetAll($sql,$aValues);
$cols = array();
if ($rows && is_array($rows) && count($rows)>0) {
foreach ($rows as $row) {
$cols[] = array_shift($row);
}
}
return $cols;
} | [
"public",
"function",
"GetCol",
"(",
"$",
"sql",
",",
"$",
"aValues",
"=",
"array",
"(",
")",
")",
"{",
"$",
"rows",
"=",
"$",
"this",
"->",
"GetAll",
"(",
"$",
"sql",
",",
"$",
"aValues",
")",
";",
"$",
"cols",
"=",
"array",
"(",
")",
";",
"... | Runs a query and fetches results as a column.
@param string $sql SQL Code to execute
@return array $results Resultset | [
"Runs",
"a",
"query",
"and",
"fetches",
"results",
"as",
"a",
"column",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L722-L731 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Driver_PDO.GetCell | public function GetCell($sql, $aValues=array()) {
$arr = $this->GetAll($sql,$aValues);
$row1 = array_shift($arr);
$col1 = array_shift($row1);
return $col1;
} | php | public function GetCell($sql, $aValues=array()) {
$arr = $this->GetAll($sql,$aValues);
$row1 = array_shift($arr);
$col1 = array_shift($row1);
return $col1;
} | [
"public",
"function",
"GetCell",
"(",
"$",
"sql",
",",
"$",
"aValues",
"=",
"array",
"(",
")",
")",
"{",
"$",
"arr",
"=",
"$",
"this",
"->",
"GetAll",
"(",
"$",
"sql",
",",
"$",
"aValues",
")",
";",
"$",
"row1",
"=",
"array_shift",
"(",
"$",
"a... | Runs a query an returns results as a single cell.
@param string $sql SQL to execute
@return mixed $cellvalue result cell | [
"Runs",
"a",
"query",
"an",
"returns",
"results",
"as",
"a",
"single",
"cell",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L740-L745 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Driver_PDO.GetRow | public function GetRow($sql, $aValues=array()) {
$arr = $this->GetAll($sql, $aValues);
return array_shift($arr);
} | php | public function GetRow($sql, $aValues=array()) {
$arr = $this->GetAll($sql, $aValues);
return array_shift($arr);
} | [
"public",
"function",
"GetRow",
"(",
"$",
"sql",
",",
"$",
"aValues",
"=",
"array",
"(",
")",
")",
"{",
"$",
"arr",
"=",
"$",
"this",
"->",
"GetAll",
"(",
"$",
"sql",
",",
"$",
"aValues",
")",
";",
"return",
"array_shift",
"(",
"$",
"arr",
")",
... | Runs a query and returns a flat array containing the values of
one row.
@param string $sql SQL to execute
@return array $row result row | [
"Runs",
"a",
"query",
"and",
"returns",
"a",
"flat",
"array",
"containing",
"the",
"values",
"of",
"one",
"row",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L755-L758 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Driver_PDO.Escape | public function Escape( $str ) {
$this->connect();
return substr(substr($this->pdo->quote($str), 1), 0, -1);
} | php | public function Escape( $str ) {
$this->connect();
return substr(substr($this->pdo->quote($str), 1), 0, -1);
} | [
"public",
"function",
"Escape",
"(",
"$",
"str",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"return",
"substr",
"(",
"substr",
"(",
"$",
"this",
"->",
"pdo",
"->",
"quote",
"(",
"$",
"str",
")",
",",
"1",
")",
",",
"0",
",",
"-",
... | Escapes a string for use in SQL using the currently selected
PDO driver.
@param string $string string to be escaped
@return string $string escaped string | [
"Escapes",
"a",
"string",
"for",
"use",
"in",
"SQL",
"using",
"the",
"currently",
"selected",
"PDO",
"driver",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L790-L793 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Driver_PDO.setDebugMode | public function setDebugMode( $tf, $logger = NULL ) {
$this->connect();
$this->debug = (bool)$tf;
if ($this->debug and !$logger) $logger = new RedBean_Logger_Default();
$this->setLogger($logger);
} | php | public function setDebugMode( $tf, $logger = NULL ) {
$this->connect();
$this->debug = (bool)$tf;
if ($this->debug and !$logger) $logger = new RedBean_Logger_Default();
$this->setLogger($logger);
} | [
"public",
"function",
"setDebugMode",
"(",
"$",
"tf",
",",
"$",
"logger",
"=",
"NULL",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"$",
"this",
"->",
"debug",
"=",
"(",
"bool",
")",
"$",
"tf",
";",
"if",
"(",
"$",
"this",
"->",
"debu... | Toggles debug mode. In debug mode the driver will print all
SQL to the screen together with some information about the
results. All SQL code that passes through the driver will be
passes on to the screen for inspection.
This method has no return value.
Additionally you can inject RedBean_Logger implementation
where you can define your own log() method
@param boolean $trueFalse turn on/off
@param RedBean_Logger $logger
@return void | [
"Toggles",
"debug",
"mode",
".",
"In",
"debug",
"mode",
"the",
"driver",
"will",
"print",
"all",
"SQL",
"to",
"the",
"screen",
"together",
"with",
"some",
"information",
"about",
"the",
"results",
".",
"All",
"SQL",
"code",
"that",
"passes",
"through",
"th... | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L832-L837 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_OODBBean.getAlias | private function getAlias( $type ) {
if ($this->fetchType) {
$type = $this->fetchType;
$this->fetchType = null;
}
return $type;
} | php | private function getAlias( $type ) {
if ($this->fetchType) {
$type = $this->fetchType;
$this->fetchType = null;
}
return $type;
} | [
"private",
"function",
"getAlias",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"fetchType",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"fetchType",
";",
"$",
"this",
"->",
"fetchType",
"=",
"null",
";",
"}",
"return",
"$",
"type",... | Returns the alias for a type
@param $type aliased type
@return string $type type | [
"Returns",
"the",
"alias",
"for",
"a",
"type"
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L1052-L1058 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_OODBBean.exportToObj | public function exportToObj($obj) {
foreach($this->properties as $k=>$v) {
if (!is_array($v) && !is_object($v))
$obj->$k = $v;
}
} | php | public function exportToObj($obj) {
foreach($this->properties as $k=>$v) {
if (!is_array($v) && !is_object($v))
$obj->$k = $v;
}
} | [
"public",
"function",
"exportToObj",
"(",
"$",
"obj",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"properties",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"v",
")",
"&&",
"!",
"is_object",
"(",
"$",
"v",
")... | Exports the bean to an object.
This function exports the contents of a bean to an object.
@param object $obj
@return array $arr | [
"Exports",
"the",
"bean",
"to",
"an",
"object",
".",
"This",
"function",
"exports",
"the",
"contents",
"of",
"a",
"bean",
"to",
"an",
"object",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L1194-L1199 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_OODBBean.unsetAll | public function unsetAll($properties) {
foreach($properties as $prop) {
if (isset($this->properties[$prop])) {
unset($this->properties[$prop]);
}
}
return $this;
} | php | public function unsetAll($properties) {
foreach($properties as $prop) {
if (isset($this->properties[$prop])) {
unset($this->properties[$prop]);
}
}
return $this;
} | [
"public",
"function",
"unsetAll",
"(",
"$",
"properties",
")",
"{",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"prop",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"properties",
"[",
"$",
"prop",
"]",
")",
")",
"{",
"unset",
"(",
"$",
... | Comfort method.
Unsets all properties in array.
@param array $properties properties you want to unset.
@return RedBean_OODBBean | [
"Comfort",
"method",
".",
"Unsets",
"all",
"properties",
"in",
"array",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L1634-L1641 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_OODBBean.hasChanged | public function hasChanged($property) {
if (!isset($this->properties[$property])) return false;
return ($this->old($property)!=$this->properties[$property]);
} | php | public function hasChanged($property) {
if (!isset($this->properties[$property])) return false;
return ($this->old($property)!=$this->properties[$property]);
} | [
"public",
"function",
"hasChanged",
"(",
"$",
"property",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"properties",
"[",
"$",
"property",
"]",
")",
")",
"return",
"false",
";",
"return",
"(",
"$",
"this",
"->",
"old",
"(",
"$",
"prop... | Returns TRUE if the value of a certain property of the bean has been changed and
FALSE otherwise.
@param string $property name of the property you want the change-status of
@return boolean | [
"Returns",
"TRUE",
"if",
"the",
"value",
"of",
"a",
"certain",
"property",
"of",
"the",
"bean",
"has",
"been",
"changed",
"and",
"FALSE",
"otherwise",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L1683-L1686 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_QueryWriter_AQueryWriter.insertRecord | protected function insertRecord( $table, $insertcolumns, $insertvalues ) {
$default = $this->defaultValue;
$suffix = $this->getInsertSuffix($table);
$table = $this->safeTable($table);
if (count($insertvalues)>0 && is_array($insertvalues[0]) && count($insertvalues[0])>0) {
foreach($insertcolumns as $k=>$v) {
$insertcolumns[$k] = $this->safeColumn($v);
}
$insertSQL = "INSERT INTO $table ( id, ".implode(',',$insertcolumns)." ) VALUES
( $default, ". implode(',',array_fill(0,count($insertcolumns),' ? '))." ) $suffix";
foreach($insertvalues as $i=>$insertvalue) {
$ids[] = $this->adapter->getCell( $insertSQL, $insertvalue, $i );
}
$result = count($ids)===1 ? array_pop($ids) : $ids;
}
else {
$result = $this->adapter->getCell( "INSERT INTO $table (id) VALUES($default) $suffix");
}
if ($suffix) return $result;
$last_id = $this->adapter->getInsertID();
return $last_id;
} | php | protected function insertRecord( $table, $insertcolumns, $insertvalues ) {
$default = $this->defaultValue;
$suffix = $this->getInsertSuffix($table);
$table = $this->safeTable($table);
if (count($insertvalues)>0 && is_array($insertvalues[0]) && count($insertvalues[0])>0) {
foreach($insertcolumns as $k=>$v) {
$insertcolumns[$k] = $this->safeColumn($v);
}
$insertSQL = "INSERT INTO $table ( id, ".implode(',',$insertcolumns)." ) VALUES
( $default, ". implode(',',array_fill(0,count($insertcolumns),' ? '))." ) $suffix";
foreach($insertvalues as $i=>$insertvalue) {
$ids[] = $this->adapter->getCell( $insertSQL, $insertvalue, $i );
}
$result = count($ids)===1 ? array_pop($ids) : $ids;
}
else {
$result = $this->adapter->getCell( "INSERT INTO $table (id) VALUES($default) $suffix");
}
if ($suffix) return $result;
$last_id = $this->adapter->getInsertID();
return $last_id;
} | [
"protected",
"function",
"insertRecord",
"(",
"$",
"table",
",",
"$",
"insertcolumns",
",",
"$",
"insertvalues",
")",
"{",
"$",
"default",
"=",
"$",
"this",
"->",
"defaultValue",
";",
"$",
"suffix",
"=",
"$",
"this",
"->",
"getInsertSuffix",
"(",
"$",
"t... | Inserts a record into the database using a series of insert columns
and corresponding insertvalues. Returns the insert id.
@param string $table table to perform query on
@param array $insertcolumns columns to be inserted
@param array $insertvalues values to be inserted
@return integer $insertid insert id from driver, new record id | [
"Inserts",
"a",
"record",
"into",
"the",
"database",
"using",
"a",
"series",
"of",
"insert",
"columns",
"and",
"corresponding",
"insertvalues",
".",
"Returns",
"the",
"insert",
"id",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L2716-L2738 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_QueryWriter_AQueryWriter.count | public function count($beanType,$addSQL = '',$params = array()) {
$sql = "SELECT count(*) FROM {$this->safeTable($beanType)} ";
if ($addSQL!='') $addSQL = ' WHERE '.$addSQL;
return (int) $this->adapter->getCell($sql.$addSQL,$params);
} | php | public function count($beanType,$addSQL = '',$params = array()) {
$sql = "SELECT count(*) FROM {$this->safeTable($beanType)} ";
if ($addSQL!='') $addSQL = ' WHERE '.$addSQL;
return (int) $this->adapter->getCell($sql.$addSQL,$params);
} | [
"public",
"function",
"count",
"(",
"$",
"beanType",
",",
"$",
"addSQL",
"=",
"''",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"sql",
"=",
"\"SELECT count(*) FROM {$this->safeTable($beanType)} \"",
";",
"if",
"(",
"$",
"addSQL",
"!=",
"''",... | Counts rows in a table.
@param string $beanType type of bean to count
@param string $addSQL additional SQL
@param array $params parameters to bind to SQL
@return integer $numRowsFound | [
"Counts",
"rows",
"in",
"a",
"table",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L2846-L2850 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_QueryWriter_AQueryWriter.startsWithZeros | protected function startsWithZeros($value) {
$value = strval($value);
if (strlen($value)>1 && strpos($value,'0')===0 && strpos($value,'0.')!==0) {
return true;
}
else {
return false;
}
} | php | protected function startsWithZeros($value) {
$value = strval($value);
if (strlen($value)>1 && strpos($value,'0')===0 && strpos($value,'0.')!==0) {
return true;
}
else {
return false;
}
} | [
"protected",
"function",
"startsWithZeros",
"(",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"strval",
"(",
"$",
"value",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"value",
")",
">",
"1",
"&&",
"strpos",
"(",
"$",
"value",
",",
"'0'",
")",
"===",
"... | Checks whether a value starts with zeros. In this case
the value should probably be stored using a text datatype instead of a
numerical type in order to preserve the zeros.
@param string $value value to be checked. | [
"Checks",
"whether",
"a",
"value",
"starts",
"with",
"zeros",
".",
"In",
"this",
"case",
"the",
"value",
"should",
"probably",
"be",
"stored",
"using",
"a",
"text",
"datatype",
"instead",
"of",
"a",
"numerical",
"type",
"in",
"order",
"to",
"preserve",
"th... | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L2983-L2991 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_QueryWriter_MySQL.getColumns | public function getColumns( $table ) {
$table = $this->safeTable($table);
$columnsRaw = $this->adapter->get("DESCRIBE $table");
foreach($columnsRaw as $r) {
$columns[$r['Field']]=$r['Type'];
}
return $columns;
} | php | public function getColumns( $table ) {
$table = $this->safeTable($table);
$columnsRaw = $this->adapter->get("DESCRIBE $table");
foreach($columnsRaw as $r) {
$columns[$r['Field']]=$r['Type'];
}
return $columns;
} | [
"public",
"function",
"getColumns",
"(",
"$",
"table",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"safeTable",
"(",
"$",
"table",
")",
";",
"$",
"columnsRaw",
"=",
"$",
"this",
"->",
"adapter",
"->",
"get",
"(",
"\"DESCRIBE $table\"",
")",
";",
... | Returns an array containing the column names of the specified table.
@param string $table table
@return array $columns columns | [
"Returns",
"an",
"array",
"containing",
"the",
"column",
"names",
"of",
"the",
"specified",
"table",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L3197-L3204 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_QueryWriter_MySQL.code | public function code( $typedescription, $includeSpecials = false ) {
$r = ((isset($this->sqltype_typeno[$typedescription])) ? $this->sqltype_typeno[$typedescription] : self::C_DATATYPE_SPECIFIED);
if ($includeSpecials) return $r;
if ($r > self::C_DATATYPE_SPECIFIED) return self::C_DATATYPE_SPECIFIED;
return $r;
} | php | public function code( $typedescription, $includeSpecials = false ) {
$r = ((isset($this->sqltype_typeno[$typedescription])) ? $this->sqltype_typeno[$typedescription] : self::C_DATATYPE_SPECIFIED);
if ($includeSpecials) return $r;
if ($r > self::C_DATATYPE_SPECIFIED) return self::C_DATATYPE_SPECIFIED;
return $r;
} | [
"public",
"function",
"code",
"(",
"$",
"typedescription",
",",
"$",
"includeSpecials",
"=",
"false",
")",
"{",
"$",
"r",
"=",
"(",
"(",
"isset",
"(",
"$",
"this",
"->",
"sqltype_typeno",
"[",
"$",
"typedescription",
"]",
")",
")",
"?",
"$",
"this",
... | Returns the Type Code for a Column Description.
Given an SQL column description this method will return the corresponding
code for the writer. If the include specials flag is set it will also
return codes for special columns. Otherwise special columns will be identified
as specified columns.
@param string $typedescription description
@param boolean $includeSpecials whether you want to get codes for special columns as well
@return integer $typecode code | [
"Returns",
"the",
"Type",
"Code",
"for",
"a",
"Column",
"Description",
".",
"Given",
"an",
"SQL",
"column",
"description",
"this",
"method",
"will",
"return",
"the",
"corresponding",
"code",
"for",
"the",
"writer",
".",
"If",
"the",
"include",
"specials",
"f... | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L3266-L3271 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_QueryWriter_SQLiteT.addColumn | public function addColumn( $table, $column, $type) {
$column = $this->check($column);
$table = $this->check($table);
$type=$this->typeno_sqltype[$type];
$sql = "ALTER TABLE `$table` ADD `$column` $type ";
$this->adapter->exec( $sql );
} | php | public function addColumn( $table, $column, $type) {
$column = $this->check($column);
$table = $this->check($table);
$type=$this->typeno_sqltype[$type];
$sql = "ALTER TABLE `$table` ADD `$column` $type ";
$this->adapter->exec( $sql );
} | [
"public",
"function",
"addColumn",
"(",
"$",
"table",
",",
"$",
"column",
",",
"$",
"type",
")",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"check",
"(",
"$",
"column",
")",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"check",
"(",
"$",
"table",
... | Adds a column of a given type to a table
@param string $table table
@param string $column column
@param integer $type type | [
"Adds",
"a",
"column",
"of",
"a",
"given",
"type",
"to",
"a",
"table"
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L3556-L3562 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_QueryWriter_SQLiteT.createTable | public function createTable( $table ) {
$table = $this->safeTable($table);
$sql = "CREATE TABLE $table ( id INTEGER PRIMARY KEY AUTOINCREMENT ) ";
$this->adapter->exec( $sql );
} | php | public function createTable( $table ) {
$table = $this->safeTable($table);
$sql = "CREATE TABLE $table ( id INTEGER PRIMARY KEY AUTOINCREMENT ) ";
$this->adapter->exec( $sql );
} | [
"public",
"function",
"createTable",
"(",
"$",
"table",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"safeTable",
"(",
"$",
"table",
")",
";",
"$",
"sql",
"=",
"\"CREATE TABLE $table ( id INTEGER PRIMARY KEY AUTOINCREMENT ) \"",
";",
"$",
"this",
"->",
"ada... | Creates an empty, column-less table for a bean.
@param string $table table | [
"Creates",
"an",
"empty",
"column",
"-",
"less",
"table",
"for",
"a",
"bean",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L3689-L3693 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_QueryWriter_PostgreSQL.addFK | public function addFK( $type, $targetType, $field, $targetField, $isDep = false) {
try{
$table = $this->safeTable($type);
$column = $this->safeColumn($field);
$tableNoQ = $this->safeTable($type,true);
$columnNoQ = $this->safeColumn($field,true);
$targetTable = $this->safeTable($targetType);
$targetTableNoQ = $this->safeTable($targetType,true);
$targetColumn = $this->safeColumn($targetField);
$targetColumnNoQ = $this->safeColumn($targetField,true);
$sql = "SELECT
tc.constraint_name,
tc.table_name,
kcu.column_name,
ccu.table_name AS foreign_table_name,
ccu.column_name AS foreign_column_name,
rc.delete_rule
FROM
information_schema.table_constraints AS tc
JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name
JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name
JOIN information_schema.referential_constraints AS rc ON ccu.constraint_name = rc.constraint_name
WHERE constraint_type = 'FOREIGN KEY' AND tc.table_catalog=current_database()
AND tc.table_name = '$tableNoQ'
AND ccu.table_name = '$targetTableNoQ'
AND kcu.column_name = '$columnNoQ'
AND ccu.column_name = '$targetColumnNoQ'
";
$row = $this->adapter->getRow($sql);
$flagAddKey = false;
if (!$row) $flagAddKey = true;
if ($row) {
if (($row['delete_rule']=='SET NULL' && $isDep) ||
($row['delete_rule']!='SET NULL' && !$isDep)) {
//delete old key
$flagAddKey = true; //and order a new one
$cName = $row['constraint_name'];
$sql = "ALTER TABLE $table DROP CONSTRAINT $cName ";
$this->adapter->exec($sql);
}
}
if ($flagAddKey) {
$delRule = ($isDep ? 'CASCADE' : 'SET NULL');
$this->adapter->exec("ALTER TABLE $table
ADD FOREIGN KEY ( $column ) REFERENCES $targetTable (
$targetColumn) ON DELETE $delRule ON UPDATE SET NULL DEFERRABLE ;");
return true;
}
return false;
}
catch(Exception $e){ return false; }
} | php | public function addFK( $type, $targetType, $field, $targetField, $isDep = false) {
try{
$table = $this->safeTable($type);
$column = $this->safeColumn($field);
$tableNoQ = $this->safeTable($type,true);
$columnNoQ = $this->safeColumn($field,true);
$targetTable = $this->safeTable($targetType);
$targetTableNoQ = $this->safeTable($targetType,true);
$targetColumn = $this->safeColumn($targetField);
$targetColumnNoQ = $this->safeColumn($targetField,true);
$sql = "SELECT
tc.constraint_name,
tc.table_name,
kcu.column_name,
ccu.table_name AS foreign_table_name,
ccu.column_name AS foreign_column_name,
rc.delete_rule
FROM
information_schema.table_constraints AS tc
JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name
JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name
JOIN information_schema.referential_constraints AS rc ON ccu.constraint_name = rc.constraint_name
WHERE constraint_type = 'FOREIGN KEY' AND tc.table_catalog=current_database()
AND tc.table_name = '$tableNoQ'
AND ccu.table_name = '$targetTableNoQ'
AND kcu.column_name = '$columnNoQ'
AND ccu.column_name = '$targetColumnNoQ'
";
$row = $this->adapter->getRow($sql);
$flagAddKey = false;
if (!$row) $flagAddKey = true;
if ($row) {
if (($row['delete_rule']=='SET NULL' && $isDep) ||
($row['delete_rule']!='SET NULL' && !$isDep)) {
//delete old key
$flagAddKey = true; //and order a new one
$cName = $row['constraint_name'];
$sql = "ALTER TABLE $table DROP CONSTRAINT $cName ";
$this->adapter->exec($sql);
}
}
if ($flagAddKey) {
$delRule = ($isDep ? 'CASCADE' : 'SET NULL');
$this->adapter->exec("ALTER TABLE $table
ADD FOREIGN KEY ( $column ) REFERENCES $targetTable (
$targetColumn) ON DELETE $delRule ON UPDATE SET NULL DEFERRABLE ;");
return true;
}
return false;
}
catch(Exception $e){ return false; }
} | [
"public",
"function",
"addFK",
"(",
"$",
"type",
",",
"$",
"targetType",
",",
"$",
"field",
",",
"$",
"targetField",
",",
"$",
"isDep",
"=",
"false",
")",
"{",
"try",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"safeTable",
"(",
"$",
"type",
")",
... | Adds a foreign key to a table. The foreign key will not have any action; you
may configure this afterwards.
@param string $type type you want to modify table of
@param string $targetType target type
@param string $field field of the type that needs to get the fk
@param string $targetField field where the fk needs to point to
@return bool $success whether an FK has been added | [
"Adds",
"a",
"foreign",
"key",
"to",
"a",
"table",
".",
"The",
"foreign",
"key",
"will",
"not",
"have",
"any",
"action",
";",
"you",
"may",
"configure",
"this",
"afterwards",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L4253-L4314 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_QueryWriter_PostgreSQL.wipe | public function wipe($type) {
$table = $type;
$table = $this->safeTable($table);
$sql = "TRUNCATE $table CASCADE";
$this->adapter->exec($sql);
} | php | public function wipe($type) {
$table = $type;
$table = $this->safeTable($table);
$sql = "TRUNCATE $table CASCADE";
$this->adapter->exec($sql);
} | [
"public",
"function",
"wipe",
"(",
"$",
"type",
")",
"{",
"$",
"table",
"=",
"$",
"type",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"safeTable",
"(",
"$",
"table",
")",
";",
"$",
"sql",
"=",
"\"TRUNCATE $table CASCADE\"",
";",
"$",
"this",
"->",
"... | This method removes all beans of a certain type.
This methods accepts a type and infers the corresponding table name.
@param string $type bean type
@return void | [
"This",
"method",
"removes",
"all",
"beans",
"of",
"a",
"certain",
"type",
".",
"This",
"methods",
"accepts",
"a",
"type",
"and",
"infers",
"the",
"corresponding",
"table",
"name",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L4401-L4406 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_QueryWriter_CUBRID.safeTable | public function safeTable($name, $noQuotes = false) {
$name = strtolower($name);
$name = $this->check($name);
if (!$noQuotes) $name = $this->noKW($name);
return $name;
} | php | public function safeTable($name, $noQuotes = false) {
$name = strtolower($name);
$name = $this->check($name);
if (!$noQuotes) $name = $this->noKW($name);
return $name;
} | [
"public",
"function",
"safeTable",
"(",
"$",
"name",
",",
"$",
"noQuotes",
"=",
"false",
")",
"{",
"$",
"name",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"$",
"name",
"=",
"$",
"this",
"->",
"check",
"(",
"$",
"name",
")",
";",
"if",
"(",
... | Do everything that needs to be done to format a table name.
@param string $name of table
@return string table name | [
"Do",
"everything",
"that",
"needs",
"to",
"be",
"done",
"to",
"format",
"a",
"table",
"name",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L4504-L4509 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_QueryWriter_CUBRID.safeColumn | public function safeColumn($name, $noQuotes = false) {
$name = strtolower($name);
$name = $this->check($name);
if (!$noQuotes) $name = $this->noKW($name);
return $name;
} | php | public function safeColumn($name, $noQuotes = false) {
$name = strtolower($name);
$name = $this->check($name);
if (!$noQuotes) $name = $this->noKW($name);
return $name;
} | [
"public",
"function",
"safeColumn",
"(",
"$",
"name",
",",
"$",
"noQuotes",
"=",
"false",
")",
"{",
"$",
"name",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"$",
"name",
"=",
"$",
"this",
"->",
"check",
"(",
"$",
"name",
")",
";",
"if",
"(",
... | Do everything that needs to be done to format a column name.
@param string $name of column
@return string $column name | [
"Do",
"everything",
"that",
"needs",
"to",
"be",
"done",
"to",
"format",
"a",
"column",
"name",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L4519-L4524 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_QueryWriter_CUBRID.addColumn | public function addColumn( $type, $column, $field ) {
$table = $type;
$type = $field;
$table = $this->safeTable($table);
$column = $this->safeColumn($column);
$type = array_key_exists($type, $this->typeno_sqltype) ? $this->typeno_sqltype[$type] : '';
$sql = "ALTER TABLE $table ADD COLUMN $column $type ";
$this->adapter->exec( $sql );
} | php | public function addColumn( $type, $column, $field ) {
$table = $type;
$type = $field;
$table = $this->safeTable($table);
$column = $this->safeColumn($column);
$type = array_key_exists($type, $this->typeno_sqltype) ? $this->typeno_sqltype[$type] : '';
$sql = "ALTER TABLE $table ADD COLUMN $column $type ";
$this->adapter->exec( $sql );
} | [
"public",
"function",
"addColumn",
"(",
"$",
"type",
",",
"$",
"column",
",",
"$",
"field",
")",
"{",
"$",
"table",
"=",
"$",
"type",
";",
"$",
"type",
"=",
"$",
"field",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"safeTable",
"(",
"$",
"table",
... | This method adds a column to a table.
This methods accepts a type and infers the corresponding table name.
@param string $type name of the table
@param string $column name of the column
@param integer $field data type for field
@return void | [
"This",
"method",
"adds",
"a",
"column",
"to",
"a",
"table",
".",
"This",
"methods",
"accepts",
"a",
"type",
"and",
"infers",
"the",
"corresponding",
"table",
"name",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L4681-L4689 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_QueryWriter_CUBRID.getKeys | protected function getKeys($table,$table2=null) {
$pdo = $this->adapter->getDatabase()->getPDO();
$keys = $pdo->cubrid_schema(PDO::CUBRID_SCH_EXPORTED_KEYS,$table);//print_r($keys);
if ($table2) $keys = array_merge($keys, $pdo->cubrid_schema(PDO::CUBRID_SCH_IMPORTED_KEYS,$table2) );//print_r($keys);
return $keys;
} | php | protected function getKeys($table,$table2=null) {
$pdo = $this->adapter->getDatabase()->getPDO();
$keys = $pdo->cubrid_schema(PDO::CUBRID_SCH_EXPORTED_KEYS,$table);//print_r($keys);
if ($table2) $keys = array_merge($keys, $pdo->cubrid_schema(PDO::CUBRID_SCH_IMPORTED_KEYS,$table2) );//print_r($keys);
return $keys;
} | [
"protected",
"function",
"getKeys",
"(",
"$",
"table",
",",
"$",
"table2",
"=",
"null",
")",
"{",
"$",
"pdo",
"=",
"$",
"this",
"->",
"adapter",
"->",
"getDatabase",
"(",
")",
"->",
"getPDO",
"(",
")",
";",
"$",
"keys",
"=",
"$",
"pdo",
"->",
"cu... | Obtains the keys of a table using the PDO schema function.
@param type $table
@return type | [
"Obtains",
"the",
"keys",
"of",
"a",
"table",
"using",
"the",
"PDO",
"schema",
"function",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L4916-L4922 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_OODB.freeze | public function freeze( $tf ) {
if (is_array($tf)) {
$this->chillList = $tf;
$this->isFrozen = false;
}
else
$this->isFrozen = (boolean) $tf;
} | php | public function freeze( $tf ) {
if (is_array($tf)) {
$this->chillList = $tf;
$this->isFrozen = false;
}
else
$this->isFrozen = (boolean) $tf;
} | [
"public",
"function",
"freeze",
"(",
"$",
"tf",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"tf",
")",
")",
"{",
"$",
"this",
"->",
"chillList",
"=",
"$",
"tf",
";",
"$",
"this",
"->",
"isFrozen",
"=",
"false",
";",
"}",
"else",
"$",
"this",
"->... | Toggles fluid or frozen mode. In fluid mode the database
structure is adjusted to accomodate your objects. In frozen mode
this is not the case.
You can also pass an array containing a selection of frozen types.
Let's call this chilly mode, it's just like fluid mode except that
certain types (i.e. tables) aren't touched.
@param boolean|array $trueFalse | [
"Toggles",
"fluid",
"or",
"frozen",
"mode",
".",
"In",
"fluid",
"mode",
"the",
"database",
"structure",
"is",
"adjusted",
"to",
"accomodate",
"your",
"objects",
".",
"In",
"frozen",
"mode",
"this",
"is",
"not",
"the",
"case",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L5116-L5123 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_OODB.processBuildCommands | protected function processBuildCommands($table, $property, RedBean_OODBBean $bean) {
if ($inx = ($bean->getMeta('buildcommand.indexes'))) {
if (isset($inx[$property])) $this->writer->addIndex($table,$inx[$property],$property);
}
} | php | protected function processBuildCommands($table, $property, RedBean_OODBBean $bean) {
if ($inx = ($bean->getMeta('buildcommand.indexes'))) {
if (isset($inx[$property])) $this->writer->addIndex($table,$inx[$property],$property);
}
} | [
"protected",
"function",
"processBuildCommands",
"(",
"$",
"table",
",",
"$",
"property",
",",
"RedBean_OODBBean",
"$",
"bean",
")",
"{",
"if",
"(",
"$",
"inx",
"=",
"(",
"$",
"bean",
"->",
"getMeta",
"(",
"'buildcommand.indexes'",
")",
")",
")",
"{",
"i... | Processes all column based build commands.
A build command is an additional instruction for the Query Writer. It is processed only when
a column gets created. The build command is often used to instruct the writer to write some
extra SQL to create indexes or constraints. Build commands are stored in meta data of the bean.
They are only for internal use, try to refrain from using them in your code directly.
@param string $table name of the table to process build commands for
@param string $property name of the property to process build commands for
@param RedBean_OODBBean $bean bean that contains the build commands
@return void | [
"Processes",
"all",
"column",
"based",
"build",
"commands",
".",
"A",
"build",
"command",
"is",
"an",
"additional",
"instruction",
"for",
"the",
"Query",
"Writer",
".",
"It",
"is",
"processed",
"only",
"when",
"a",
"column",
"gets",
"created",
".",
"The",
... | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L5285-L5289 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_OODB.getTypeFromCast | private function getTypeFromCast($cast) {
if ($cast=='string') {
$typeno = $this->writer->scanType('STRING');
}
elseif ($cast=='id') {
$typeno = $this->writer->getTypeForID();
}
elseif(isset($this->writer->sqltype_typeno[$cast])) {
$typeno = $this->writer->sqltype_typeno[$cast];
}
else {
throw new RedBean_Exception('Invalid Cast');
}
return $typeno;
} | php | private function getTypeFromCast($cast) {
if ($cast=='string') {
$typeno = $this->writer->scanType('STRING');
}
elseif ($cast=='id') {
$typeno = $this->writer->getTypeForID();
}
elseif(isset($this->writer->sqltype_typeno[$cast])) {
$typeno = $this->writer->sqltype_typeno[$cast];
}
else {
throw new RedBean_Exception('Invalid Cast');
}
return $typeno;
} | [
"private",
"function",
"getTypeFromCast",
"(",
"$",
"cast",
")",
"{",
"if",
"(",
"$",
"cast",
"==",
"'string'",
")",
"{",
"$",
"typeno",
"=",
"$",
"this",
"->",
"writer",
"->",
"scanType",
"(",
"'STRING'",
")",
";",
"}",
"elseif",
"(",
"$",
"cast",
... | Figures out the desired type given the cast string ID.
@param string $cast cast identifier
@return integer $typeno | [
"Figures",
"out",
"the",
"desired",
"type",
"given",
"the",
"cast",
"string",
"ID",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L5324-L5338 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_OODB.prepareEmbeddedBean | private function prepareEmbeddedBean($v) {
if (!$v->id || $v->getMeta('tainted')) {
$this->store($v);
}
return $v->id;
} | php | private function prepareEmbeddedBean($v) {
if (!$v->id || $v->getMeta('tainted')) {
$this->store($v);
}
return $v->id;
} | [
"private",
"function",
"prepareEmbeddedBean",
"(",
"$",
"v",
")",
"{",
"if",
"(",
"!",
"$",
"v",
"->",
"id",
"||",
"$",
"v",
"->",
"getMeta",
"(",
"'tainted'",
")",
")",
"{",
"$",
"this",
"->",
"store",
"(",
"$",
"v",
")",
";",
"}",
"return",
"... | Processes an embedded bean. First the bean gets unboxed if possible.
Then, the bean is stored if needed and finally the ID of the bean
will be returned.
@param RedBean_OODBBean|Model $v the bean or model
@return integer $id | [
"Processes",
"an",
"embedded",
"bean",
".",
"First",
"the",
"bean",
"gets",
"unboxed",
"if",
"possible",
".",
"Then",
"the",
"bean",
"is",
"stored",
"if",
"needed",
"and",
"finally",
"the",
"ID",
"of",
"the",
"bean",
"will",
"be",
"returned",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L5349-L5354 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_OODB.processEmbeddedBeans | private function processEmbeddedBeans($bean, $embeddedBeans) {
foreach($embeddedBeans as $linkField=>$embeddedBean) {
if (!$this->isFrozen) {
$this->writer->addIndex($bean->getMeta('type'),
'index_foreignkey_'.$bean->getMeta('type').'_'.$embeddedBean->getMeta('type'),
$linkField);
$isDep = $this->isDependentOn($bean->getMeta('type'),$embeddedBean->getMeta('type'));
$this->writer->addFK($bean->getMeta('type'),$embeddedBean->getMeta('type'),$linkField,'id',$isDep);
}
}
} | php | private function processEmbeddedBeans($bean, $embeddedBeans) {
foreach($embeddedBeans as $linkField=>$embeddedBean) {
if (!$this->isFrozen) {
$this->writer->addIndex($bean->getMeta('type'),
'index_foreignkey_'.$bean->getMeta('type').'_'.$embeddedBean->getMeta('type'),
$linkField);
$isDep = $this->isDependentOn($bean->getMeta('type'),$embeddedBean->getMeta('type'));
$this->writer->addFK($bean->getMeta('type'),$embeddedBean->getMeta('type'),$linkField,'id',$isDep);
}
}
} | [
"private",
"function",
"processEmbeddedBeans",
"(",
"$",
"bean",
",",
"$",
"embeddedBeans",
")",
"{",
"foreach",
"(",
"$",
"embeddedBeans",
"as",
"$",
"linkField",
"=>",
"$",
"embeddedBean",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isFrozen",
")",
"... | Processes embedded beans.
Each embedded bean will be indexed and foreign keys will
be created if the bean is in the dependency list.
@param RedBean_OODBBean $bean bean
@param array $embeddedBeans embedded beans | [
"Processes",
"embedded",
"beans",
".",
"Each",
"embedded",
"bean",
"will",
"be",
"indexed",
"and",
"foreign",
"keys",
"will",
"be",
"created",
"if",
"the",
"bean",
"is",
"in",
"the",
"dependency",
"list",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L5583-L5594 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_OODB.trash | public function trash( $bean ) {
if ($bean instanceof RedBean_SimpleModel) $bean = $bean->unbox();
if (!($bean instanceof RedBean_OODBBean)) throw new RedBean_Exception_Security('OODB Store requires a bean, got: '.gettype($bean));
$this->signal('delete',$bean);
foreach($bean as $p=>$v) {
if ($v instanceof RedBean_OODBBean) {
$bean->removeProperty($p);
}
if (is_array($v)) {
if (strpos($p,'own')===0) {
$bean->removeProperty($p);
}
elseif (strpos($p,'shared')===0) {
$bean->removeProperty($p);
}
}
}
if (!$this->isFrozen) $this->check( $bean );
try {
$this->writer->selectRecord($bean->getMeta('type'),
array('id' => array( $bean->id) ),null,true );
}catch(RedBean_Exception_SQL $e) {
if (!$this->writer->sqlStateIn($e->getSQLState(),
array(
RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN,
RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_TABLE)
)) throw $e;
}
$bean->id = 0;
$this->signal('after_delete', $bean );
} | php | public function trash( $bean ) {
if ($bean instanceof RedBean_SimpleModel) $bean = $bean->unbox();
if (!($bean instanceof RedBean_OODBBean)) throw new RedBean_Exception_Security('OODB Store requires a bean, got: '.gettype($bean));
$this->signal('delete',$bean);
foreach($bean as $p=>$v) {
if ($v instanceof RedBean_OODBBean) {
$bean->removeProperty($p);
}
if (is_array($v)) {
if (strpos($p,'own')===0) {
$bean->removeProperty($p);
}
elseif (strpos($p,'shared')===0) {
$bean->removeProperty($p);
}
}
}
if (!$this->isFrozen) $this->check( $bean );
try {
$this->writer->selectRecord($bean->getMeta('type'),
array('id' => array( $bean->id) ),null,true );
}catch(RedBean_Exception_SQL $e) {
if (!$this->writer->sqlStateIn($e->getSQLState(),
array(
RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN,
RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_TABLE)
)) throw $e;
}
$bean->id = 0;
$this->signal('after_delete', $bean );
} | [
"public",
"function",
"trash",
"(",
"$",
"bean",
")",
"{",
"if",
"(",
"$",
"bean",
"instanceof",
"RedBean_SimpleModel",
")",
"$",
"bean",
"=",
"$",
"bean",
"->",
"unbox",
"(",
")",
";",
"if",
"(",
"!",
"(",
"$",
"bean",
"instanceof",
"RedBean_OODBBean"... | Removes a bean from the database.
This function will remove the specified RedBean_OODBBean
Bean Object from the database.
@throws RedBean_Exception_Security $exception
@param RedBean_OODBBean|RedBean_SimpleModel $bean bean you want to remove from database | [
"Removes",
"a",
"bean",
"from",
"the",
"database",
".",
"This",
"function",
"will",
"remove",
"the",
"specified",
"RedBean_OODBBean",
"Bean",
"Object",
"from",
"the",
"database",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L5715-L5745 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.