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
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
spatie/laravel-medialibrary | src/HasMedia/HasMediaTrait.php | HasMediaTrait.clearMediaCollection | public function clearMediaCollection(string $collectionName = 'default'): self
{
$this->getMedia($collectionName)
->each->delete();
event(new CollectionHasBeenCleared($this, $collectionName));
if ($this->mediaIsPreloaded()) {
unset($this->media);
}
return $this;
} | php | public function clearMediaCollection(string $collectionName = 'default'): self
{
$this->getMedia($collectionName)
->each->delete();
event(new CollectionHasBeenCleared($this, $collectionName));
if ($this->mediaIsPreloaded()) {
unset($this->media);
}
return $this;
} | [
"public",
"function",
"clearMediaCollection",
"(",
"string",
"$",
"collectionName",
"=",
"'default'",
")",
":",
"self",
"{",
"$",
"this",
"->",
"getMedia",
"(",
"$",
"collectionName",
")",
"->",
"each",
"->",
"delete",
"(",
")",
";",
"event",
"(",
"new",
"CollectionHasBeenCleared",
"(",
"$",
"this",
",",
"$",
"collectionName",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"mediaIsPreloaded",
"(",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"media",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Remove all media in the given collection.
@param string $collectionName
@return $this | [
"Remove",
"all",
"media",
"in",
"the",
"given",
"collection",
"."
] | 6ffb8a41e60f024abd35ff47e08628354d6efd0e | https://github.com/spatie/laravel-medialibrary/blob/6ffb8a41e60f024abd35ff47e08628354d6efd0e/src/HasMedia/HasMediaTrait.php#L337-L349 | train |
spatie/laravel-medialibrary | src/HasMedia/HasMediaTrait.php | HasMediaTrait.clearMediaCollectionExcept | public function clearMediaCollectionExcept(string $collectionName = 'default', $excludedMedia = [])
{
if ($excludedMedia instanceof Media) {
$excludedMedia = collect()->push($excludedMedia);
}
$excludedMedia = collect($excludedMedia);
if ($excludedMedia->isEmpty()) {
return $this->clearMediaCollection($collectionName);
}
$this->getMedia($collectionName)
->reject(function (Media $media) use ($excludedMedia) {
return $excludedMedia->where('id', $media->id)->count();
})
->each->delete();
if ($this->mediaIsPreloaded()) {
unset($this->media);
}
return $this;
} | php | public function clearMediaCollectionExcept(string $collectionName = 'default', $excludedMedia = [])
{
if ($excludedMedia instanceof Media) {
$excludedMedia = collect()->push($excludedMedia);
}
$excludedMedia = collect($excludedMedia);
if ($excludedMedia->isEmpty()) {
return $this->clearMediaCollection($collectionName);
}
$this->getMedia($collectionName)
->reject(function (Media $media) use ($excludedMedia) {
return $excludedMedia->where('id', $media->id)->count();
})
->each->delete();
if ($this->mediaIsPreloaded()) {
unset($this->media);
}
return $this;
} | [
"public",
"function",
"clearMediaCollectionExcept",
"(",
"string",
"$",
"collectionName",
"=",
"'default'",
",",
"$",
"excludedMedia",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"excludedMedia",
"instanceof",
"Media",
")",
"{",
"$",
"excludedMedia",
"=",
"collect",
"(",
")",
"->",
"push",
"(",
"$",
"excludedMedia",
")",
";",
"}",
"$",
"excludedMedia",
"=",
"collect",
"(",
"$",
"excludedMedia",
")",
";",
"if",
"(",
"$",
"excludedMedia",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"clearMediaCollection",
"(",
"$",
"collectionName",
")",
";",
"}",
"$",
"this",
"->",
"getMedia",
"(",
"$",
"collectionName",
")",
"->",
"reject",
"(",
"function",
"(",
"Media",
"$",
"media",
")",
"use",
"(",
"$",
"excludedMedia",
")",
"{",
"return",
"$",
"excludedMedia",
"->",
"where",
"(",
"'id'",
",",
"$",
"media",
"->",
"id",
")",
"->",
"count",
"(",
")",
";",
"}",
")",
"->",
"each",
"->",
"delete",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"mediaIsPreloaded",
"(",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"media",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Remove all media in the given collection except some.
@param string $collectionName
@param \Spatie\MediaLibrary\Models\Media[]|\Illuminate\Support\Collection $excludedMedia
@return $this | [
"Remove",
"all",
"media",
"in",
"the",
"given",
"collection",
"except",
"some",
"."
] | 6ffb8a41e60f024abd35ff47e08628354d6efd0e | https://github.com/spatie/laravel-medialibrary/blob/6ffb8a41e60f024abd35ff47e08628354d6efd0e/src/HasMedia/HasMediaTrait.php#L359-L382 | train |
spatie/laravel-medialibrary | src/HasMedia/HasMediaTrait.php | HasMediaTrait.deleteMedia | public function deleteMedia($mediaId)
{
if ($mediaId instanceof Media) {
$mediaId = $mediaId->id;
}
$media = $this->media->find($mediaId);
if (! $media) {
throw MediaCannotBeDeleted::doesNotBelongToModel($mediaId, $this);
}
$media->delete();
} | php | public function deleteMedia($mediaId)
{
if ($mediaId instanceof Media) {
$mediaId = $mediaId->id;
}
$media = $this->media->find($mediaId);
if (! $media) {
throw MediaCannotBeDeleted::doesNotBelongToModel($mediaId, $this);
}
$media->delete();
} | [
"public",
"function",
"deleteMedia",
"(",
"$",
"mediaId",
")",
"{",
"if",
"(",
"$",
"mediaId",
"instanceof",
"Media",
")",
"{",
"$",
"mediaId",
"=",
"$",
"mediaId",
"->",
"id",
";",
"}",
"$",
"media",
"=",
"$",
"this",
"->",
"media",
"->",
"find",
"(",
"$",
"mediaId",
")",
";",
"if",
"(",
"!",
"$",
"media",
")",
"{",
"throw",
"MediaCannotBeDeleted",
"::",
"doesNotBelongToModel",
"(",
"$",
"mediaId",
",",
"$",
"this",
")",
";",
"}",
"$",
"media",
"->",
"delete",
"(",
")",
";",
"}"
] | Delete the associated media with the given id.
You may also pass a media object.
@param int|\Spatie\MediaLibrary\Models\Media $mediaId
@throws \Spatie\MediaLibrary\Exceptions\MediaCannotBeDeleted | [
"Delete",
"the",
"associated",
"media",
"with",
"the",
"given",
"id",
".",
"You",
"may",
"also",
"pass",
"a",
"media",
"object",
"."
] | 6ffb8a41e60f024abd35ff47e08628354d6efd0e | https://github.com/spatie/laravel-medialibrary/blob/6ffb8a41e60f024abd35ff47e08628354d6efd0e/src/HasMedia/HasMediaTrait.php#L392-L405 | train |
spatie/laravel-medialibrary | src/HasMedia/HasMediaTrait.php | HasMediaTrait.loadMedia | public function loadMedia(string $collectionName)
{
$collection = $this->exists
? $this->media
: collect($this->unAttachedMediaLibraryItems)->pluck('media');
return $collection
->filter(function (Media $mediaItem) use ($collectionName) {
if ($collectionName == '') {
return true;
}
return $mediaItem->collection_name === $collectionName;
})
->sortBy('order_column')
->values();
} | php | public function loadMedia(string $collectionName)
{
$collection = $this->exists
? $this->media
: collect($this->unAttachedMediaLibraryItems)->pluck('media');
return $collection
->filter(function (Media $mediaItem) use ($collectionName) {
if ($collectionName == '') {
return true;
}
return $mediaItem->collection_name === $collectionName;
})
->sortBy('order_column')
->values();
} | [
"public",
"function",
"loadMedia",
"(",
"string",
"$",
"collectionName",
")",
"{",
"$",
"collection",
"=",
"$",
"this",
"->",
"exists",
"?",
"$",
"this",
"->",
"media",
":",
"collect",
"(",
"$",
"this",
"->",
"unAttachedMediaLibraryItems",
")",
"->",
"pluck",
"(",
"'media'",
")",
";",
"return",
"$",
"collection",
"->",
"filter",
"(",
"function",
"(",
"Media",
"$",
"mediaItem",
")",
"use",
"(",
"$",
"collectionName",
")",
"{",
"if",
"(",
"$",
"collectionName",
"==",
"''",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"mediaItem",
"->",
"collection_name",
"===",
"$",
"collectionName",
";",
"}",
")",
"->",
"sortBy",
"(",
"'order_column'",
")",
"->",
"values",
"(",
")",
";",
"}"
] | Cache the media on the object.
@param string $collectionName
@return mixed | [
"Cache",
"the",
"media",
"on",
"the",
"object",
"."
] | 6ffb8a41e60f024abd35ff47e08628354d6efd0e | https://github.com/spatie/laravel-medialibrary/blob/6ffb8a41e60f024abd35ff47e08628354d6efd0e/src/HasMedia/HasMediaTrait.php#L462-L478 | train |
mpociot/laravel-apidoc-generator | src/Tools/Traits/ParamHelpers.php | ParamHelpers.cleanParams | protected function cleanParams(array $params)
{
$values = [];
foreach ($params as $name => $details) {
$this->cleanValueFrom($name, $details['value'], $values);
}
return $values;
} | php | protected function cleanParams(array $params)
{
$values = [];
foreach ($params as $name => $details) {
$this->cleanValueFrom($name, $details['value'], $values);
}
return $values;
} | [
"protected",
"function",
"cleanParams",
"(",
"array",
"$",
"params",
")",
"{",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"name",
"=>",
"$",
"details",
")",
"{",
"$",
"this",
"->",
"cleanValueFrom",
"(",
"$",
"name",
",",
"$",
"details",
"[",
"'value'",
"]",
",",
"$",
"values",
")",
";",
"}",
"return",
"$",
"values",
";",
"}"
] | Create proper arrays from dot-noted parameter names.
@param array $params
@return array | [
"Create",
"proper",
"arrays",
"from",
"dot",
"-",
"noted",
"parameter",
"names",
"."
] | 793f15ace8bf95d13a14d7f90e5be9f28c788c78 | https://github.com/mpociot/laravel-apidoc-generator/blob/793f15ace8bf95d13a14d7f90e5be9f28c788c78/src/Tools/Traits/ParamHelpers.php#L14-L22 | train |
mpociot/laravel-apidoc-generator | src/Tools/Traits/ParamHelpers.php | ParamHelpers.cleanValueFrom | protected function cleanValueFrom($name, $value, array &$values = [])
{
if (str_contains($name, '[')) {
$name = str_replace(['][', '[', ']', '..'], ['.', '.', '', '.*.'], $name);
}
array_set($values, str_replace('.*', '.0', $name), $value);
} | php | protected function cleanValueFrom($name, $value, array &$values = [])
{
if (str_contains($name, '[')) {
$name = str_replace(['][', '[', ']', '..'], ['.', '.', '', '.*.'], $name);
}
array_set($values, str_replace('.*', '.0', $name), $value);
} | [
"protected",
"function",
"cleanValueFrom",
"(",
"$",
"name",
",",
"$",
"value",
",",
"array",
"&",
"$",
"values",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"str_contains",
"(",
"$",
"name",
",",
"'['",
")",
")",
"{",
"$",
"name",
"=",
"str_replace",
"(",
"[",
"']['",
",",
"'['",
",",
"']'",
",",
"'..'",
"]",
",",
"[",
"'.'",
",",
"'.'",
",",
"''",
",",
"'.*.'",
"]",
",",
"$",
"name",
")",
";",
"}",
"array_set",
"(",
"$",
"values",
",",
"str_replace",
"(",
"'.*'",
",",
"'.0'",
",",
"$",
"name",
")",
",",
"$",
"value",
")",
";",
"}"
] | Converts dot notation names to arrays and sets the value at the right depth.
@param string $name
@param mixed $value
@param array $values The array that holds the result
@return void | [
"Converts",
"dot",
"notation",
"names",
"to",
"arrays",
"and",
"sets",
"the",
"value",
"at",
"the",
"right",
"depth",
"."
] | 793f15ace8bf95d13a14d7f90e5be9f28c788c78 | https://github.com/mpociot/laravel-apidoc-generator/blob/793f15ace8bf95d13a14d7f90e5be9f28c788c78/src/Tools/Traits/ParamHelpers.php#L33-L39 | train |
mpociot/laravel-apidoc-generator | src/Tools/ResponseStrategies/ResponseTagStrategy.php | ResponseTagStrategy.getDocBlockResponses | protected function getDocBlockResponses(array $tags)
{
$responseTags = array_values(
array_filter($tags, function ($tag) {
return $tag instanceof Tag && strtolower($tag->getName()) === 'response';
})
);
if (empty($responseTags)) {
return;
}
return array_map(function (Tag $responseTag) {
preg_match('/^(\d{3})?\s?([\s\S]*)$/', $responseTag->getContent(), $result);
$status = $result[1] ?: 200;
$content = $result[2] ?: '{}';
return new JsonResponse(json_decode($content, true), (int) $status);
}, $responseTags);
} | php | protected function getDocBlockResponses(array $tags)
{
$responseTags = array_values(
array_filter($tags, function ($tag) {
return $tag instanceof Tag && strtolower($tag->getName()) === 'response';
})
);
if (empty($responseTags)) {
return;
}
return array_map(function (Tag $responseTag) {
preg_match('/^(\d{3})?\s?([\s\S]*)$/', $responseTag->getContent(), $result);
$status = $result[1] ?: 200;
$content = $result[2] ?: '{}';
return new JsonResponse(json_decode($content, true), (int) $status);
}, $responseTags);
} | [
"protected",
"function",
"getDocBlockResponses",
"(",
"array",
"$",
"tags",
")",
"{",
"$",
"responseTags",
"=",
"array_values",
"(",
"array_filter",
"(",
"$",
"tags",
",",
"function",
"(",
"$",
"tag",
")",
"{",
"return",
"$",
"tag",
"instanceof",
"Tag",
"&&",
"strtolower",
"(",
"$",
"tag",
"->",
"getName",
"(",
")",
")",
"===",
"'response'",
";",
"}",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"responseTags",
")",
")",
"{",
"return",
";",
"}",
"return",
"array_map",
"(",
"function",
"(",
"Tag",
"$",
"responseTag",
")",
"{",
"preg_match",
"(",
"'/^(\\d{3})?\\s?([\\s\\S]*)$/'",
",",
"$",
"responseTag",
"->",
"getContent",
"(",
")",
",",
"$",
"result",
")",
";",
"$",
"status",
"=",
"$",
"result",
"[",
"1",
"]",
"?",
":",
"200",
";",
"$",
"content",
"=",
"$",
"result",
"[",
"2",
"]",
"?",
":",
"'{}'",
";",
"return",
"new",
"JsonResponse",
"(",
"json_decode",
"(",
"$",
"content",
",",
"true",
")",
",",
"(",
"int",
")",
"$",
"status",
")",
";",
"}",
",",
"$",
"responseTags",
")",
";",
"}"
] | Get the response from the docblock if available.
@param array $tags
@return array|null | [
"Get",
"the",
"response",
"from",
"the",
"docblock",
"if",
"available",
"."
] | 793f15ace8bf95d13a14d7f90e5be9f28c788c78 | https://github.com/mpociot/laravel-apidoc-generator/blob/793f15ace8bf95d13a14d7f90e5be9f28c788c78/src/Tools/ResponseStrategies/ResponseTagStrategy.php#L33-L53 | train |
mpociot/laravel-apidoc-generator | src/Tools/ResponseStrategies/ResponseFileStrategy.php | ResponseFileStrategy.getFileResponses | protected function getFileResponses(array $tags)
{
// avoid "holes" in the keys of the filtered array, by using array_values on the filtered array
$responseFileTags = array_values(
array_filter($tags, function ($tag) {
return $tag instanceof Tag && strtolower($tag->getName()) === 'responsefile';
})
);
if (empty($responseFileTags)) {
return;
}
return array_map(function (Tag $responseFileTag) {
preg_match('/^(\d{3})?\s?([\S]*[\s]*?)(\{.*\})?$/', $responseFileTag->getContent(), $result);
$status = $result[1] ?: 200;
$content = $result[2] ? file_get_contents(storage_path(trim($result[2])), true) : '{}';
$json = ! empty($result[3]) ? str_replace("'", '"', $result[3]) : '{}';
$merged = array_merge(json_decode($content, true), json_decode($json, true));
return new JsonResponse($merged, (int) $status);
}, $responseFileTags);
} | php | protected function getFileResponses(array $tags)
{
// avoid "holes" in the keys of the filtered array, by using array_values on the filtered array
$responseFileTags = array_values(
array_filter($tags, function ($tag) {
return $tag instanceof Tag && strtolower($tag->getName()) === 'responsefile';
})
);
if (empty($responseFileTags)) {
return;
}
return array_map(function (Tag $responseFileTag) {
preg_match('/^(\d{3})?\s?([\S]*[\s]*?)(\{.*\})?$/', $responseFileTag->getContent(), $result);
$status = $result[1] ?: 200;
$content = $result[2] ? file_get_contents(storage_path(trim($result[2])), true) : '{}';
$json = ! empty($result[3]) ? str_replace("'", '"', $result[3]) : '{}';
$merged = array_merge(json_decode($content, true), json_decode($json, true));
return new JsonResponse($merged, (int) $status);
}, $responseFileTags);
} | [
"protected",
"function",
"getFileResponses",
"(",
"array",
"$",
"tags",
")",
"{",
"// avoid \"holes\" in the keys of the filtered array, by using array_values on the filtered array",
"$",
"responseFileTags",
"=",
"array_values",
"(",
"array_filter",
"(",
"$",
"tags",
",",
"function",
"(",
"$",
"tag",
")",
"{",
"return",
"$",
"tag",
"instanceof",
"Tag",
"&&",
"strtolower",
"(",
"$",
"tag",
"->",
"getName",
"(",
")",
")",
"===",
"'responsefile'",
";",
"}",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"responseFileTags",
")",
")",
"{",
"return",
";",
"}",
"return",
"array_map",
"(",
"function",
"(",
"Tag",
"$",
"responseFileTag",
")",
"{",
"preg_match",
"(",
"'/^(\\d{3})?\\s?([\\S]*[\\s]*?)(\\{.*\\})?$/'",
",",
"$",
"responseFileTag",
"->",
"getContent",
"(",
")",
",",
"$",
"result",
")",
";",
"$",
"status",
"=",
"$",
"result",
"[",
"1",
"]",
"?",
":",
"200",
";",
"$",
"content",
"=",
"$",
"result",
"[",
"2",
"]",
"?",
"file_get_contents",
"(",
"storage_path",
"(",
"trim",
"(",
"$",
"result",
"[",
"2",
"]",
")",
")",
",",
"true",
")",
":",
"'{}'",
";",
"$",
"json",
"=",
"!",
"empty",
"(",
"$",
"result",
"[",
"3",
"]",
")",
"?",
"str_replace",
"(",
"\"'\"",
",",
"'\"'",
",",
"$",
"result",
"[",
"3",
"]",
")",
":",
"'{}'",
";",
"$",
"merged",
"=",
"array_merge",
"(",
"json_decode",
"(",
"$",
"content",
",",
"true",
")",
",",
"json_decode",
"(",
"$",
"json",
",",
"true",
")",
")",
";",
"return",
"new",
"JsonResponse",
"(",
"$",
"merged",
",",
"(",
"int",
")",
"$",
"status",
")",
";",
"}",
",",
"$",
"responseFileTags",
")",
";",
"}"
] | Get the response from the file if available.
@param array $tags
@return array|null | [
"Get",
"the",
"response",
"from",
"the",
"file",
"if",
"available",
"."
] | 793f15ace8bf95d13a14d7f90e5be9f28c788c78 | https://github.com/mpociot/laravel-apidoc-generator/blob/793f15ace8bf95d13a14d7f90e5be9f28c788c78/src/Tools/ResponseStrategies/ResponseFileStrategy.php#L33-L55 | train |
mpociot/laravel-apidoc-generator | src/Tools/Generator.php | Generator.castToType | private function castToType(string $value, string $type)
{
$casts = [
'integer' => 'intval',
'number' => 'floatval',
'float' => 'floatval',
'boolean' => 'boolval',
];
// First, we handle booleans. We can't use a regular cast,
//because PHP considers string 'false' as true.
if ($value == 'false' && $type == 'boolean') {
return false;
}
if (isset($casts[$type])) {
return $casts[$type]($value);
}
return $value;
} | php | private function castToType(string $value, string $type)
{
$casts = [
'integer' => 'intval',
'number' => 'floatval',
'float' => 'floatval',
'boolean' => 'boolval',
];
// First, we handle booleans. We can't use a regular cast,
//because PHP considers string 'false' as true.
if ($value == 'false' && $type == 'boolean') {
return false;
}
if (isset($casts[$type])) {
return $casts[$type]($value);
}
return $value;
} | [
"private",
"function",
"castToType",
"(",
"string",
"$",
"value",
",",
"string",
"$",
"type",
")",
"{",
"$",
"casts",
"=",
"[",
"'integer'",
"=>",
"'intval'",
",",
"'number'",
"=>",
"'floatval'",
",",
"'float'",
"=>",
"'floatval'",
",",
"'boolean'",
"=>",
"'boolval'",
",",
"]",
";",
"// First, we handle booleans. We can't use a regular cast,",
"//because PHP considers string 'false' as true.",
"if",
"(",
"$",
"value",
"==",
"'false'",
"&&",
"$",
"type",
"==",
"'boolean'",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"casts",
"[",
"$",
"type",
"]",
")",
")",
"{",
"return",
"$",
"casts",
"[",
"$",
"type",
"]",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Cast a value from a string to a specified type.
@param string $value
@param string $type
@return mixed | [
"Cast",
"a",
"value",
"from",
"a",
"string",
"to",
"a",
"specified",
"type",
"."
] | 793f15ace8bf95d13a14d7f90e5be9f28c788c78 | https://github.com/mpociot/laravel-apidoc-generator/blob/793f15ace8bf95d13a14d7f90e5be9f28c788c78/src/Tools/Generator.php#L379-L399 | train |
mpociot/laravel-apidoc-generator | src/Tools/ResponseStrategies/TransformerTagsStrategy.php | TransformerTagsStrategy.getTransformerResponse | protected function getTransformerResponse(array $tags)
{
try {
if (empty($transformerTag = $this->getTransformerTag($tags))) {
return;
}
$transformer = $this->getTransformerClass($transformerTag);
$model = $this->getClassToBeTransformed($tags, (new ReflectionClass($transformer))->getMethod('transform'));
$modelInstance = $this->instantiateTransformerModel($model);
$fractal = new Manager();
if (! is_null(config('apidoc.fractal.serializer'))) {
$fractal->setSerializer(app(config('apidoc.fractal.serializer')));
}
$resource = (strtolower($transformerTag->getName()) == 'transformercollection')
? new Collection([$modelInstance, $modelInstance], new $transformer)
: new Item($modelInstance, new $transformer);
return [response($fractal->createData($resource)->toJson())];
} catch (\Exception $e) {
return;
}
} | php | protected function getTransformerResponse(array $tags)
{
try {
if (empty($transformerTag = $this->getTransformerTag($tags))) {
return;
}
$transformer = $this->getTransformerClass($transformerTag);
$model = $this->getClassToBeTransformed($tags, (new ReflectionClass($transformer))->getMethod('transform'));
$modelInstance = $this->instantiateTransformerModel($model);
$fractal = new Manager();
if (! is_null(config('apidoc.fractal.serializer'))) {
$fractal->setSerializer(app(config('apidoc.fractal.serializer')));
}
$resource = (strtolower($transformerTag->getName()) == 'transformercollection')
? new Collection([$modelInstance, $modelInstance], new $transformer)
: new Item($modelInstance, new $transformer);
return [response($fractal->createData($resource)->toJson())];
} catch (\Exception $e) {
return;
}
} | [
"protected",
"function",
"getTransformerResponse",
"(",
"array",
"$",
"tags",
")",
"{",
"try",
"{",
"if",
"(",
"empty",
"(",
"$",
"transformerTag",
"=",
"$",
"this",
"->",
"getTransformerTag",
"(",
"$",
"tags",
")",
")",
")",
"{",
"return",
";",
"}",
"$",
"transformer",
"=",
"$",
"this",
"->",
"getTransformerClass",
"(",
"$",
"transformerTag",
")",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"getClassToBeTransformed",
"(",
"$",
"tags",
",",
"(",
"new",
"ReflectionClass",
"(",
"$",
"transformer",
")",
")",
"->",
"getMethod",
"(",
"'transform'",
")",
")",
";",
"$",
"modelInstance",
"=",
"$",
"this",
"->",
"instantiateTransformerModel",
"(",
"$",
"model",
")",
";",
"$",
"fractal",
"=",
"new",
"Manager",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"config",
"(",
"'apidoc.fractal.serializer'",
")",
")",
")",
"{",
"$",
"fractal",
"->",
"setSerializer",
"(",
"app",
"(",
"config",
"(",
"'apidoc.fractal.serializer'",
")",
")",
")",
";",
"}",
"$",
"resource",
"=",
"(",
"strtolower",
"(",
"$",
"transformerTag",
"->",
"getName",
"(",
")",
")",
"==",
"'transformercollection'",
")",
"?",
"new",
"Collection",
"(",
"[",
"$",
"modelInstance",
",",
"$",
"modelInstance",
"]",
",",
"new",
"$",
"transformer",
")",
":",
"new",
"Item",
"(",
"$",
"modelInstance",
",",
"new",
"$",
"transformer",
")",
";",
"return",
"[",
"response",
"(",
"$",
"fractal",
"->",
"createData",
"(",
"$",
"resource",
")",
"->",
"toJson",
"(",
")",
")",
"]",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
";",
"}",
"}"
] | Get a response from the transformer tags.
@param array $tags
@return array|null | [
"Get",
"a",
"response",
"from",
"the",
"transformer",
"tags",
"."
] | 793f15ace8bf95d13a14d7f90e5be9f28c788c78 | https://github.com/mpociot/laravel-apidoc-generator/blob/793f15ace8bf95d13a14d7f90e5be9f28c788c78/src/Tools/ResponseStrategies/TransformerTagsStrategy.php#L37-L62 | train |
UniSharp/laravel-filemanager | src/Lfm.php | Lfm.currentLfmType | public function currentLfmType()
{
$lfm_type = 'file';
$request_type = lcfirst(str_singular($this->input('type') ?: ''));
$available_types = array_keys($this->config->get('lfm.folder_categories') ?: []);
if (in_array($request_type, $available_types)) {
$lfm_type = $request_type;
}
return $lfm_type;
} | php | public function currentLfmType()
{
$lfm_type = 'file';
$request_type = lcfirst(str_singular($this->input('type') ?: ''));
$available_types = array_keys($this->config->get('lfm.folder_categories') ?: []);
if (in_array($request_type, $available_types)) {
$lfm_type = $request_type;
}
return $lfm_type;
} | [
"public",
"function",
"currentLfmType",
"(",
")",
"{",
"$",
"lfm_type",
"=",
"'file'",
";",
"$",
"request_type",
"=",
"lcfirst",
"(",
"str_singular",
"(",
"$",
"this",
"->",
"input",
"(",
"'type'",
")",
"?",
":",
"''",
")",
")",
";",
"$",
"available_types",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'lfm.folder_categories'",
")",
"?",
":",
"[",
"]",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"request_type",
",",
"$",
"available_types",
")",
")",
"{",
"$",
"lfm_type",
"=",
"$",
"request_type",
";",
"}",
"return",
"$",
"lfm_type",
";",
"}"
] | Get current lfm type.
@return string | [
"Get",
"current",
"lfm",
"type",
"."
] | 64ac677461e14bc9883faa8d9bb3bbd72f707257 | https://github.com/UniSharp/laravel-filemanager/blob/64ac677461e14bc9883faa8d9bb3bbd72f707257/src/Lfm.php#L72-L84 | train |
UniSharp/laravel-filemanager | src/Lfm.php | Lfm.translateFromUtf8 | public function translateFromUtf8($input)
{
if ($this->isRunningOnWindows()) {
$input = iconv('UTF-8', mb_detect_encoding($input), $input);
}
return $input;
} | php | public function translateFromUtf8($input)
{
if ($this->isRunningOnWindows()) {
$input = iconv('UTF-8', mb_detect_encoding($input), $input);
}
return $input;
} | [
"public",
"function",
"translateFromUtf8",
"(",
"$",
"input",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isRunningOnWindows",
"(",
")",
")",
"{",
"$",
"input",
"=",
"iconv",
"(",
"'UTF-8'",
",",
"mb_detect_encoding",
"(",
"$",
"input",
")",
",",
"$",
"input",
")",
";",
"}",
"return",
"$",
"input",
";",
"}"
] | Translate file name to make it compatible on Windows.
@param string $input Any string.
@return string | [
"Translate",
"file",
"name",
"to",
"make",
"it",
"compatible",
"on",
"Windows",
"."
] | 64ac677461e14bc9883faa8d9bb3bbd72f707257 | https://github.com/UniSharp/laravel-filemanager/blob/64ac677461e14bc9883faa8d9bb3bbd72f707257/src/Lfm.php#L191-L198 | train |
UniSharp/laravel-filemanager | src/Lfm.php | Lfm.routes | public static function routes()
{
$middleware = [ CreateDefaultFolder::class, MultiUser::class ];
$as = 'unisharp.lfm.';
$namespace = '\\UniSharp\\LaravelFilemanager\\Controllers\\';
Route::group(compact('middleware', 'as', 'namespace'), function () {
// display main layout
Route::get('/', [
'uses' => 'LfmController@show',
'as' => 'show',
]);
// display integration error messages
Route::get('/errors', [
'uses' => 'LfmController@getErrors',
'as' => 'getErrors',
]);
// upload
Route::any('/upload', [
'uses' => 'UploadController@upload',
'as' => 'upload',
]);
// list images & files
Route::get('/jsonitems', [
'uses' => 'ItemsController@getItems',
'as' => 'getItems',
]);
Route::get('/move', [
'uses' => 'ItemsController@move',
'as' => 'move',
]);
Route::get('/domove', [
'uses' => 'ItemsController@domove',
'as' => 'domove'
]);
// folders
Route::get('/newfolder', [
'uses' => 'FolderController@getAddfolder',
'as' => 'getAddfolder',
]);
// list folders
Route::get('/folders', [
'uses' => 'FolderController@getFolders',
'as' => 'getFolders',
]);
// crop
Route::get('/crop', [
'uses' => 'CropController@getCrop',
'as' => 'getCrop',
]);
Route::get('/cropimage', [
'uses' => 'CropController@getCropimage',
'as' => 'getCropimage',
]);
Route::get('/cropnewimage', [
'uses' => 'CropController@getNewCropimage',
'as' => 'getCropimage',
]);
// rename
Route::get('/rename', [
'uses' => 'RenameController@getRename',
'as' => 'getRename',
]);
// scale/resize
Route::get('/resize', [
'uses' => 'ResizeController@getResize',
'as' => 'getResize',
]);
Route::get('/doresize', [
'uses' => 'ResizeController@performResize',
'as' => 'performResize',
]);
// download
Route::get('/download', [
'uses' => 'DownloadController@getDownload',
'as' => 'getDownload',
]);
// delete
Route::get('/delete', [
'uses' => 'DeleteController@getDelete',
'as' => 'getDelete',
]);
Route::get('/demo', 'DemoController@index');
});
} | php | public static function routes()
{
$middleware = [ CreateDefaultFolder::class, MultiUser::class ];
$as = 'unisharp.lfm.';
$namespace = '\\UniSharp\\LaravelFilemanager\\Controllers\\';
Route::group(compact('middleware', 'as', 'namespace'), function () {
// display main layout
Route::get('/', [
'uses' => 'LfmController@show',
'as' => 'show',
]);
// display integration error messages
Route::get('/errors', [
'uses' => 'LfmController@getErrors',
'as' => 'getErrors',
]);
// upload
Route::any('/upload', [
'uses' => 'UploadController@upload',
'as' => 'upload',
]);
// list images & files
Route::get('/jsonitems', [
'uses' => 'ItemsController@getItems',
'as' => 'getItems',
]);
Route::get('/move', [
'uses' => 'ItemsController@move',
'as' => 'move',
]);
Route::get('/domove', [
'uses' => 'ItemsController@domove',
'as' => 'domove'
]);
// folders
Route::get('/newfolder', [
'uses' => 'FolderController@getAddfolder',
'as' => 'getAddfolder',
]);
// list folders
Route::get('/folders', [
'uses' => 'FolderController@getFolders',
'as' => 'getFolders',
]);
// crop
Route::get('/crop', [
'uses' => 'CropController@getCrop',
'as' => 'getCrop',
]);
Route::get('/cropimage', [
'uses' => 'CropController@getCropimage',
'as' => 'getCropimage',
]);
Route::get('/cropnewimage', [
'uses' => 'CropController@getNewCropimage',
'as' => 'getCropimage',
]);
// rename
Route::get('/rename', [
'uses' => 'RenameController@getRename',
'as' => 'getRename',
]);
// scale/resize
Route::get('/resize', [
'uses' => 'ResizeController@getResize',
'as' => 'getResize',
]);
Route::get('/doresize', [
'uses' => 'ResizeController@performResize',
'as' => 'performResize',
]);
// download
Route::get('/download', [
'uses' => 'DownloadController@getDownload',
'as' => 'getDownload',
]);
// delete
Route::get('/delete', [
'uses' => 'DeleteController@getDelete',
'as' => 'getDelete',
]);
Route::get('/demo', 'DemoController@index');
});
} | [
"public",
"static",
"function",
"routes",
"(",
")",
"{",
"$",
"middleware",
"=",
"[",
"CreateDefaultFolder",
"::",
"class",
",",
"MultiUser",
"::",
"class",
"]",
";",
"$",
"as",
"=",
"'unisharp.lfm.'",
";",
"$",
"namespace",
"=",
"'\\\\UniSharp\\\\LaravelFilemanager\\\\Controllers\\\\'",
";",
"Route",
"::",
"group",
"(",
"compact",
"(",
"'middleware'",
",",
"'as'",
",",
"'namespace'",
")",
",",
"function",
"(",
")",
"{",
"// display main layout",
"Route",
"::",
"get",
"(",
"'/'",
",",
"[",
"'uses'",
"=>",
"'LfmController@show'",
",",
"'as'",
"=>",
"'show'",
",",
"]",
")",
";",
"// display integration error messages",
"Route",
"::",
"get",
"(",
"'/errors'",
",",
"[",
"'uses'",
"=>",
"'LfmController@getErrors'",
",",
"'as'",
"=>",
"'getErrors'",
",",
"]",
")",
";",
"// upload",
"Route",
"::",
"any",
"(",
"'/upload'",
",",
"[",
"'uses'",
"=>",
"'UploadController@upload'",
",",
"'as'",
"=>",
"'upload'",
",",
"]",
")",
";",
"// list images & files",
"Route",
"::",
"get",
"(",
"'/jsonitems'",
",",
"[",
"'uses'",
"=>",
"'ItemsController@getItems'",
",",
"'as'",
"=>",
"'getItems'",
",",
"]",
")",
";",
"Route",
"::",
"get",
"(",
"'/move'",
",",
"[",
"'uses'",
"=>",
"'ItemsController@move'",
",",
"'as'",
"=>",
"'move'",
",",
"]",
")",
";",
"Route",
"::",
"get",
"(",
"'/domove'",
",",
"[",
"'uses'",
"=>",
"'ItemsController@domove'",
",",
"'as'",
"=>",
"'domove'",
"]",
")",
";",
"// folders",
"Route",
"::",
"get",
"(",
"'/newfolder'",
",",
"[",
"'uses'",
"=>",
"'FolderController@getAddfolder'",
",",
"'as'",
"=>",
"'getAddfolder'",
",",
"]",
")",
";",
"// list folders",
"Route",
"::",
"get",
"(",
"'/folders'",
",",
"[",
"'uses'",
"=>",
"'FolderController@getFolders'",
",",
"'as'",
"=>",
"'getFolders'",
",",
"]",
")",
";",
"// crop",
"Route",
"::",
"get",
"(",
"'/crop'",
",",
"[",
"'uses'",
"=>",
"'CropController@getCrop'",
",",
"'as'",
"=>",
"'getCrop'",
",",
"]",
")",
";",
"Route",
"::",
"get",
"(",
"'/cropimage'",
",",
"[",
"'uses'",
"=>",
"'CropController@getCropimage'",
",",
"'as'",
"=>",
"'getCropimage'",
",",
"]",
")",
";",
"Route",
"::",
"get",
"(",
"'/cropnewimage'",
",",
"[",
"'uses'",
"=>",
"'CropController@getNewCropimage'",
",",
"'as'",
"=>",
"'getCropimage'",
",",
"]",
")",
";",
"// rename",
"Route",
"::",
"get",
"(",
"'/rename'",
",",
"[",
"'uses'",
"=>",
"'RenameController@getRename'",
",",
"'as'",
"=>",
"'getRename'",
",",
"]",
")",
";",
"// scale/resize",
"Route",
"::",
"get",
"(",
"'/resize'",
",",
"[",
"'uses'",
"=>",
"'ResizeController@getResize'",
",",
"'as'",
"=>",
"'getResize'",
",",
"]",
")",
";",
"Route",
"::",
"get",
"(",
"'/doresize'",
",",
"[",
"'uses'",
"=>",
"'ResizeController@performResize'",
",",
"'as'",
"=>",
"'performResize'",
",",
"]",
")",
";",
"// download",
"Route",
"::",
"get",
"(",
"'/download'",
",",
"[",
"'uses'",
"=>",
"'DownloadController@getDownload'",
",",
"'as'",
"=>",
"'getDownload'",
",",
"]",
")",
";",
"// delete",
"Route",
"::",
"get",
"(",
"'/delete'",
",",
"[",
"'uses'",
"=>",
"'DeleteController@getDelete'",
",",
"'as'",
"=>",
"'getDelete'",
",",
"]",
")",
";",
"Route",
"::",
"get",
"(",
"'/demo'",
",",
"'DemoController@index'",
")",
";",
"}",
")",
";",
"}"
] | Generates routes of this package.
@return void | [
"Generates",
"routes",
"of",
"this",
"package",
"."
] | 64ac677461e14bc9883faa8d9bb3bbd72f707257 | https://github.com/UniSharp/laravel-filemanager/blob/64ac677461e14bc9883faa8d9bb3bbd72f707257/src/Lfm.php#L242-L340 | train |
UniSharp/laravel-filemanager | src/Controllers/ItemsController.php | ItemsController.getItems | public function getItems()
{
return [
'items' => array_map(function ($item) {
return $item->fill()->attributes;
}, array_merge($this->lfm->folders(), $this->lfm->files())),
'display' => $this->helper->getDisplayMode(),
'working_dir' => $this->lfm->path('working_dir'),
];
} | php | public function getItems()
{
return [
'items' => array_map(function ($item) {
return $item->fill()->attributes;
}, array_merge($this->lfm->folders(), $this->lfm->files())),
'display' => $this->helper->getDisplayMode(),
'working_dir' => $this->lfm->path('working_dir'),
];
} | [
"public",
"function",
"getItems",
"(",
")",
"{",
"return",
"[",
"'items'",
"=>",
"array_map",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"return",
"$",
"item",
"->",
"fill",
"(",
")",
"->",
"attributes",
";",
"}",
",",
"array_merge",
"(",
"$",
"this",
"->",
"lfm",
"->",
"folders",
"(",
")",
",",
"$",
"this",
"->",
"lfm",
"->",
"files",
"(",
")",
")",
")",
",",
"'display'",
"=>",
"$",
"this",
"->",
"helper",
"->",
"getDisplayMode",
"(",
")",
",",
"'working_dir'",
"=>",
"$",
"this",
"->",
"lfm",
"->",
"path",
"(",
"'working_dir'",
")",
",",
"]",
";",
"}"
] | Get the images to load for a selected folder.
@return mixed | [
"Get",
"the",
"images",
"to",
"load",
"for",
"a",
"selected",
"folder",
"."
] | 64ac677461e14bc9883faa8d9bb3bbd72f707257 | https://github.com/UniSharp/laravel-filemanager/blob/64ac677461e14bc9883faa8d9bb3bbd72f707257/src/Controllers/ItemsController.php#L17-L26 | train |
UniSharp/laravel-filemanager | src/Controllers/FolderController.php | FolderController.getAddfolder | public function getAddfolder()
{
$folder_name = $this->helper->input('name');
try {
if (empty($folder_name)) {
return $this->helper->error('folder-name');
} elseif ($this->lfm->setName($folder_name)->exists()) {
return $this->helper->error('folder-exist');
} elseif (config('lfm.alphanumeric_directory') && preg_match('/[^\w-]/i', $folder_name)) {
return $this->helper->error('folder-alnum');
} else {
$this->lfm->setName($folder_name)->createFolder();
}
} catch (\Exception $e) {
return $e->getMessage();
}
return parent::$success_response;
} | php | public function getAddfolder()
{
$folder_name = $this->helper->input('name');
try {
if (empty($folder_name)) {
return $this->helper->error('folder-name');
} elseif ($this->lfm->setName($folder_name)->exists()) {
return $this->helper->error('folder-exist');
} elseif (config('lfm.alphanumeric_directory') && preg_match('/[^\w-]/i', $folder_name)) {
return $this->helper->error('folder-alnum');
} else {
$this->lfm->setName($folder_name)->createFolder();
}
} catch (\Exception $e) {
return $e->getMessage();
}
return parent::$success_response;
} | [
"public",
"function",
"getAddfolder",
"(",
")",
"{",
"$",
"folder_name",
"=",
"$",
"this",
"->",
"helper",
"->",
"input",
"(",
"'name'",
")",
";",
"try",
"{",
"if",
"(",
"empty",
"(",
"$",
"folder_name",
")",
")",
"{",
"return",
"$",
"this",
"->",
"helper",
"->",
"error",
"(",
"'folder-name'",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"lfm",
"->",
"setName",
"(",
"$",
"folder_name",
")",
"->",
"exists",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"helper",
"->",
"error",
"(",
"'folder-exist'",
")",
";",
"}",
"elseif",
"(",
"config",
"(",
"'lfm.alphanumeric_directory'",
")",
"&&",
"preg_match",
"(",
"'/[^\\w-]/i'",
",",
"$",
"folder_name",
")",
")",
"{",
"return",
"$",
"this",
"->",
"helper",
"->",
"error",
"(",
"'folder-alnum'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"lfm",
"->",
"setName",
"(",
"$",
"folder_name",
")",
"->",
"createFolder",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"}",
"return",
"parent",
"::",
"$",
"success_response",
";",
"}"
] | Add a new folder.
@return mixed | [
"Add",
"a",
"new",
"folder",
"."
] | 64ac677461e14bc9883faa8d9bb3bbd72f707257 | https://github.com/UniSharp/laravel-filemanager/blob/64ac677461e14bc9883faa8d9bb3bbd72f707257/src/Controllers/FolderController.php#L38-L57 | train |
UniSharp/laravel-filemanager | src/Controllers/DeleteController.php | DeleteController.getDelete | public function getDelete()
{
$item_names = request('items');
$errors = [];
foreach ($item_names as $name_to_delete) {
$file_to_delete = $this->lfm->pretty($name_to_delete);
$file_path = $file_to_delete->path();
event(new ImageIsDeleting($file_path));
if (is_null($name_to_delete)) {
array_push($errors, parent::error('folder-name'));
continue;
}
if (! $this->lfm->setName($name_to_delete)->exists()) {
array_push($errors, parent::error('folder-not-found', ['folder' => $file_path]));
continue;
}
if ($this->lfm->setName($name_to_delete)->isDirectory()) {
if (! $this->lfm->setName($name_to_delete)->directoryIsEmpty()) {
array_push($errors, parent::error('delete-folder'));
continue;
}
} else {
if ($file_to_delete->isImage()) {
$this->lfm->setName($name_to_delete)->thumb()->delete();
}
}
$this->lfm->setName($name_to_delete)->delete();
event(new ImageWasDeleted($file_path));
}
if (count($errors) > 0) {
return $errors;
}
return parent::$success_response;
} | php | public function getDelete()
{
$item_names = request('items');
$errors = [];
foreach ($item_names as $name_to_delete) {
$file_to_delete = $this->lfm->pretty($name_to_delete);
$file_path = $file_to_delete->path();
event(new ImageIsDeleting($file_path));
if (is_null($name_to_delete)) {
array_push($errors, parent::error('folder-name'));
continue;
}
if (! $this->lfm->setName($name_to_delete)->exists()) {
array_push($errors, parent::error('folder-not-found', ['folder' => $file_path]));
continue;
}
if ($this->lfm->setName($name_to_delete)->isDirectory()) {
if (! $this->lfm->setName($name_to_delete)->directoryIsEmpty()) {
array_push($errors, parent::error('delete-folder'));
continue;
}
} else {
if ($file_to_delete->isImage()) {
$this->lfm->setName($name_to_delete)->thumb()->delete();
}
}
$this->lfm->setName($name_to_delete)->delete();
event(new ImageWasDeleted($file_path));
}
if (count($errors) > 0) {
return $errors;
}
return parent::$success_response;
} | [
"public",
"function",
"getDelete",
"(",
")",
"{",
"$",
"item_names",
"=",
"request",
"(",
"'items'",
")",
";",
"$",
"errors",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"item_names",
"as",
"$",
"name_to_delete",
")",
"{",
"$",
"file_to_delete",
"=",
"$",
"this",
"->",
"lfm",
"->",
"pretty",
"(",
"$",
"name_to_delete",
")",
";",
"$",
"file_path",
"=",
"$",
"file_to_delete",
"->",
"path",
"(",
")",
";",
"event",
"(",
"new",
"ImageIsDeleting",
"(",
"$",
"file_path",
")",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"name_to_delete",
")",
")",
"{",
"array_push",
"(",
"$",
"errors",
",",
"parent",
"::",
"error",
"(",
"'folder-name'",
")",
")",
";",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"lfm",
"->",
"setName",
"(",
"$",
"name_to_delete",
")",
"->",
"exists",
"(",
")",
")",
"{",
"array_push",
"(",
"$",
"errors",
",",
"parent",
"::",
"error",
"(",
"'folder-not-found'",
",",
"[",
"'folder'",
"=>",
"$",
"file_path",
"]",
")",
")",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"lfm",
"->",
"setName",
"(",
"$",
"name_to_delete",
")",
"->",
"isDirectory",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"lfm",
"->",
"setName",
"(",
"$",
"name_to_delete",
")",
"->",
"directoryIsEmpty",
"(",
")",
")",
"{",
"array_push",
"(",
"$",
"errors",
",",
"parent",
"::",
"error",
"(",
"'delete-folder'",
")",
")",
";",
"continue",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"file_to_delete",
"->",
"isImage",
"(",
")",
")",
"{",
"$",
"this",
"->",
"lfm",
"->",
"setName",
"(",
"$",
"name_to_delete",
")",
"->",
"thumb",
"(",
")",
"->",
"delete",
"(",
")",
";",
"}",
"}",
"$",
"this",
"->",
"lfm",
"->",
"setName",
"(",
"$",
"name_to_delete",
")",
"->",
"delete",
"(",
")",
";",
"event",
"(",
"new",
"ImageWasDeleted",
"(",
"$",
"file_path",
")",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"errors",
")",
">",
"0",
")",
"{",
"return",
"$",
"errors",
";",
"}",
"return",
"parent",
"::",
"$",
"success_response",
";",
"}"
] | Delete image and associated thumbnail.
@return mixed | [
"Delete",
"image",
"and",
"associated",
"thumbnail",
"."
] | 64ac677461e14bc9883faa8d9bb3bbd72f707257 | https://github.com/UniSharp/laravel-filemanager/blob/64ac677461e14bc9883faa8d9bb3bbd72f707257/src/Controllers/DeleteController.php#L15-L57 | train |
UniSharp/laravel-filemanager | src/LfmPath.php | LfmPath.createFolder | public function createFolder()
{
if ($this->storage->exists($this)) {
return false;
}
$this->storage->makeDirectory(0777, true, true);
} | php | public function createFolder()
{
if ($this->storage->exists($this)) {
return false;
}
$this->storage->makeDirectory(0777, true, true);
} | [
"public",
"function",
"createFolder",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"storage",
"->",
"exists",
"(",
"$",
"this",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"storage",
"->",
"makeDirectory",
"(",
"0777",
",",
"true",
",",
"true",
")",
";",
"}"
] | Create folder if not exist.
@param string $path Real path of a directory.
@return bool | [
"Create",
"folder",
"if",
"not",
"exist",
"."
] | 64ac677461e14bc9883faa8d9bb3bbd72f707257 | https://github.com/UniSharp/laravel-filemanager/blob/64ac677461e14bc9883faa8d9bb3bbd72f707257/src/LfmPath.php#L141-L148 | train |
UniSharp/laravel-filemanager | src/LfmPath.php | LfmPath.sortByColumn | public function sortByColumn($arr_items)
{
$sort_by = $this->helper->input('sort_type');
if (in_array($sort_by, ['name', 'time'])) {
$key_to_sort = $sort_by;
} else {
$key_to_sort = 'name';
}
uasort($arr_items, function ($a, $b) use ($key_to_sort) {
return strcmp($a->{$key_to_sort}, $b->{$key_to_sort});
});
return $arr_items;
} | php | public function sortByColumn($arr_items)
{
$sort_by = $this->helper->input('sort_type');
if (in_array($sort_by, ['name', 'time'])) {
$key_to_sort = $sort_by;
} else {
$key_to_sort = 'name';
}
uasort($arr_items, function ($a, $b) use ($key_to_sort) {
return strcmp($a->{$key_to_sort}, $b->{$key_to_sort});
});
return $arr_items;
} | [
"public",
"function",
"sortByColumn",
"(",
"$",
"arr_items",
")",
"{",
"$",
"sort_by",
"=",
"$",
"this",
"->",
"helper",
"->",
"input",
"(",
"'sort_type'",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"sort_by",
",",
"[",
"'name'",
",",
"'time'",
"]",
")",
")",
"{",
"$",
"key_to_sort",
"=",
"$",
"sort_by",
";",
"}",
"else",
"{",
"$",
"key_to_sort",
"=",
"'name'",
";",
"}",
"uasort",
"(",
"$",
"arr_items",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"use",
"(",
"$",
"key_to_sort",
")",
"{",
"return",
"strcmp",
"(",
"$",
"a",
"->",
"{",
"$",
"key_to_sort",
"}",
",",
"$",
"b",
"->",
"{",
"$",
"key_to_sort",
"}",
")",
";",
"}",
")",
";",
"return",
"$",
"arr_items",
";",
"}"
] | Sort files and directories.
@param mixed $arr_items Array of files or folders or both.
@return array of object | [
"Sort",
"files",
"and",
"directories",
"."
] | 64ac677461e14bc9883faa8d9bb3bbd72f707257 | https://github.com/UniSharp/laravel-filemanager/blob/64ac677461e14bc9883faa8d9bb3bbd72f707257/src/LfmPath.php#L196-L210 | train |
UniSharp/laravel-filemanager | src/Controllers/LfmController.php | LfmController.getErrors | public function getErrors()
{
$arr_errors = [];
if (! extension_loaded('gd') && ! extension_loaded('imagick')) {
array_push($arr_errors, trans('laravel-filemanager::lfm.message-extension_not_found'));
}
if (! extension_loaded('exif')) {
array_push($arr_errors, 'EXIF extension not found.');
}
if (! extension_loaded('fileinfo')) {
array_push($arr_errors, 'Fileinfo extension not found.');
}
$mine_config_key = 'lfm.folder_categories.'
. $this->helper->currentLfmType()
. '.valid_mime';
if (! is_array(config($mine_config_key))) {
array_push($arr_errors, 'Config : ' . $mine_config_key . ' is not a valid array.');
}
return $arr_errors;
} | php | public function getErrors()
{
$arr_errors = [];
if (! extension_loaded('gd') && ! extension_loaded('imagick')) {
array_push($arr_errors, trans('laravel-filemanager::lfm.message-extension_not_found'));
}
if (! extension_loaded('exif')) {
array_push($arr_errors, 'EXIF extension not found.');
}
if (! extension_loaded('fileinfo')) {
array_push($arr_errors, 'Fileinfo extension not found.');
}
$mine_config_key = 'lfm.folder_categories.'
. $this->helper->currentLfmType()
. '.valid_mime';
if (! is_array(config($mine_config_key))) {
array_push($arr_errors, 'Config : ' . $mine_config_key . ' is not a valid array.');
}
return $arr_errors;
} | [
"public",
"function",
"getErrors",
"(",
")",
"{",
"$",
"arr_errors",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"extension_loaded",
"(",
"'gd'",
")",
"&&",
"!",
"extension_loaded",
"(",
"'imagick'",
")",
")",
"{",
"array_push",
"(",
"$",
"arr_errors",
",",
"trans",
"(",
"'laravel-filemanager::lfm.message-extension_not_found'",
")",
")",
";",
"}",
"if",
"(",
"!",
"extension_loaded",
"(",
"'exif'",
")",
")",
"{",
"array_push",
"(",
"$",
"arr_errors",
",",
"'EXIF extension not found.'",
")",
";",
"}",
"if",
"(",
"!",
"extension_loaded",
"(",
"'fileinfo'",
")",
")",
"{",
"array_push",
"(",
"$",
"arr_errors",
",",
"'Fileinfo extension not found.'",
")",
";",
"}",
"$",
"mine_config_key",
"=",
"'lfm.folder_categories.'",
".",
"$",
"this",
"->",
"helper",
"->",
"currentLfmType",
"(",
")",
".",
"'.valid_mime'",
";",
"if",
"(",
"!",
"is_array",
"(",
"config",
"(",
"$",
"mine_config_key",
")",
")",
")",
"{",
"array_push",
"(",
"$",
"arr_errors",
",",
"'Config : '",
".",
"$",
"mine_config_key",
".",
"' is not a valid array.'",
")",
";",
"}",
"return",
"$",
"arr_errors",
";",
"}"
] | Check if any extension or config is missing.
@return array | [
"Check",
"if",
"any",
"extension",
"or",
"config",
"is",
"missing",
"."
] | 64ac677461e14bc9883faa8d9bb3bbd72f707257 | https://github.com/UniSharp/laravel-filemanager/blob/64ac677461e14bc9883faa8d9bb3bbd72f707257/src/Controllers/LfmController.php#L47-L72 | train |
UniSharp/laravel-filemanager | src/Controllers/LfmController.php | LfmController.applyIniOverrides | public function applyIniOverrides()
{
$overrides = config('lfm.php_ini_overrides');
if ($overrides && is_array($overrides) && count($overrides) === 0) {
return;
}
foreach ($overrides as $key => $value) {
if ($value && $value != 'false') {
ini_set($key, $value);
}
}
} | php | public function applyIniOverrides()
{
$overrides = config('lfm.php_ini_overrides');
if ($overrides && is_array($overrides) && count($overrides) === 0) {
return;
}
foreach ($overrides as $key => $value) {
if ($value && $value != 'false') {
ini_set($key, $value);
}
}
} | [
"public",
"function",
"applyIniOverrides",
"(",
")",
"{",
"$",
"overrides",
"=",
"config",
"(",
"'lfm.php_ini_overrides'",
")",
";",
"if",
"(",
"$",
"overrides",
"&&",
"is_array",
"(",
"$",
"overrides",
")",
"&&",
"count",
"(",
"$",
"overrides",
")",
"===",
"0",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"overrides",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"&&",
"$",
"value",
"!=",
"'false'",
")",
"{",
"ini_set",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"}"
] | Overrides settings in php.ini.
@return null | [
"Overrides",
"settings",
"in",
"php",
".",
"ini",
"."
] | 64ac677461e14bc9883faa8d9bb3bbd72f707257 | https://github.com/UniSharp/laravel-filemanager/blob/64ac677461e14bc9883faa8d9bb3bbd72f707257/src/Controllers/LfmController.php#L84-L96 | train |
UniSharp/laravel-filemanager | src/Controllers/ResizeController.php | ResizeController.getResize | public function getResize()
{
$ratio = 1.0;
$image = request('img');
$original_image = Image::make($this->lfm->setName($image)->path('absolute'));
$original_width = $original_image->width();
$original_height = $original_image->height();
$scaled = false;
// FIXME size should be configurable
if ($original_width > 600) {
$ratio = 600 / $original_width;
$width = $original_width * $ratio;
$height = $original_height * $ratio;
$scaled = true;
} else {
$width = $original_width;
$height = $original_height;
}
if ($height > 400) {
$ratio = 400 / $original_height;
$width = $original_width * $ratio;
$height = $original_height * $ratio;
$scaled = true;
}
return view('laravel-filemanager::resize')
->with('img', $this->lfm->pretty($image))
->with('height', number_format($height, 0))
->with('width', $width)
->with('original_height', $original_height)
->with('original_width', $original_width)
->with('scaled', $scaled)
->with('ratio', $ratio);
} | php | public function getResize()
{
$ratio = 1.0;
$image = request('img');
$original_image = Image::make($this->lfm->setName($image)->path('absolute'));
$original_width = $original_image->width();
$original_height = $original_image->height();
$scaled = false;
// FIXME size should be configurable
if ($original_width > 600) {
$ratio = 600 / $original_width;
$width = $original_width * $ratio;
$height = $original_height * $ratio;
$scaled = true;
} else {
$width = $original_width;
$height = $original_height;
}
if ($height > 400) {
$ratio = 400 / $original_height;
$width = $original_width * $ratio;
$height = $original_height * $ratio;
$scaled = true;
}
return view('laravel-filemanager::resize')
->with('img', $this->lfm->pretty($image))
->with('height', number_format($height, 0))
->with('width', $width)
->with('original_height', $original_height)
->with('original_width', $original_width)
->with('scaled', $scaled)
->with('ratio', $ratio);
} | [
"public",
"function",
"getResize",
"(",
")",
"{",
"$",
"ratio",
"=",
"1.0",
";",
"$",
"image",
"=",
"request",
"(",
"'img'",
")",
";",
"$",
"original_image",
"=",
"Image",
"::",
"make",
"(",
"$",
"this",
"->",
"lfm",
"->",
"setName",
"(",
"$",
"image",
")",
"->",
"path",
"(",
"'absolute'",
")",
")",
";",
"$",
"original_width",
"=",
"$",
"original_image",
"->",
"width",
"(",
")",
";",
"$",
"original_height",
"=",
"$",
"original_image",
"->",
"height",
"(",
")",
";",
"$",
"scaled",
"=",
"false",
";",
"// FIXME size should be configurable",
"if",
"(",
"$",
"original_width",
">",
"600",
")",
"{",
"$",
"ratio",
"=",
"600",
"/",
"$",
"original_width",
";",
"$",
"width",
"=",
"$",
"original_width",
"*",
"$",
"ratio",
";",
"$",
"height",
"=",
"$",
"original_height",
"*",
"$",
"ratio",
";",
"$",
"scaled",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"width",
"=",
"$",
"original_width",
";",
"$",
"height",
"=",
"$",
"original_height",
";",
"}",
"if",
"(",
"$",
"height",
">",
"400",
")",
"{",
"$",
"ratio",
"=",
"400",
"/",
"$",
"original_height",
";",
"$",
"width",
"=",
"$",
"original_width",
"*",
"$",
"ratio",
";",
"$",
"height",
"=",
"$",
"original_height",
"*",
"$",
"ratio",
";",
"$",
"scaled",
"=",
"true",
";",
"}",
"return",
"view",
"(",
"'laravel-filemanager::resize'",
")",
"->",
"with",
"(",
"'img'",
",",
"$",
"this",
"->",
"lfm",
"->",
"pretty",
"(",
"$",
"image",
")",
")",
"->",
"with",
"(",
"'height'",
",",
"number_format",
"(",
"$",
"height",
",",
"0",
")",
")",
"->",
"with",
"(",
"'width'",
",",
"$",
"width",
")",
"->",
"with",
"(",
"'original_height'",
",",
"$",
"original_height",
")",
"->",
"with",
"(",
"'original_width'",
",",
"$",
"original_width",
")",
"->",
"with",
"(",
"'scaled'",
",",
"$",
"scaled",
")",
"->",
"with",
"(",
"'ratio'",
",",
"$",
"ratio",
")",
";",
"}"
] | Dipsplay image for resizing.
@return mixed | [
"Dipsplay",
"image",
"for",
"resizing",
"."
] | 64ac677461e14bc9883faa8d9bb3bbd72f707257 | https://github.com/UniSharp/laravel-filemanager/blob/64ac677461e14bc9883faa8d9bb3bbd72f707257/src/Controllers/ResizeController.php#L16-L53 | train |
ratchetphp/Ratchet | src/Ratchet/Server/FlashPolicy.php | FlashPolicy.addAllowedAccess | public function addAllowedAccess($domain, $ports = '*', $secure = false) {
if (!$this->validateDomain($domain)) {
throw new \UnexpectedValueException('Invalid domain');
}
if (!$this->validatePorts($ports)) {
throw new \UnexpectedValueException('Invalid Port');
}
$this->_access[] = array($domain, $ports, (boolean)$secure);
$this->_cacheValid = false;
return $this;
} | php | public function addAllowedAccess($domain, $ports = '*', $secure = false) {
if (!$this->validateDomain($domain)) {
throw new \UnexpectedValueException('Invalid domain');
}
if (!$this->validatePorts($ports)) {
throw new \UnexpectedValueException('Invalid Port');
}
$this->_access[] = array($domain, $ports, (boolean)$secure);
$this->_cacheValid = false;
return $this;
} | [
"public",
"function",
"addAllowedAccess",
"(",
"$",
"domain",
",",
"$",
"ports",
"=",
"'*'",
",",
"$",
"secure",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"validateDomain",
"(",
"$",
"domain",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"'Invalid domain'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"validatePorts",
"(",
"$",
"ports",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"'Invalid Port'",
")",
";",
"}",
"$",
"this",
"->",
"_access",
"[",
"]",
"=",
"array",
"(",
"$",
"domain",
",",
"$",
"ports",
",",
"(",
"boolean",
")",
"$",
"secure",
")",
";",
"$",
"this",
"->",
"_cacheValid",
"=",
"false",
";",
"return",
"$",
"this",
";",
"}"
] | Add a domain to an allowed access list.
@param string $domain Specifies a requesting domain to be granted access. Both named domains and IP
addresses are acceptable values. Subdomains are considered different domains. A wildcard (*) can
be used to match all domains when used alone, or multiple domains (subdomains) when used as a
prefix for an explicit, second-level domain name separated with a dot (.)
@param string $ports A comma-separated list of ports or range of ports that a socket connection
is allowed to connect to. A range of ports is specified through a dash (-) between two port numbers.
Ranges can be used with individual ports when separated with a comma. A single wildcard (*) can
be used to allow all ports.
@param bool $secure
@throws \UnexpectedValueException
@return FlashPolicy | [
"Add",
"a",
"domain",
"to",
"an",
"allowed",
"access",
"list",
"."
] | b85c2a1f189e43f7f0861daf7ff81d016c5d6403 | https://github.com/ratchetphp/Ratchet/blob/b85c2a1f189e43f7f0861daf7ff81d016c5d6403/src/Ratchet/Server/FlashPolicy.php#L60-L73 | train |
ratchetphp/Ratchet | src/Ratchet/Server/FlashPolicy.php | FlashPolicy.setSiteControl | public function setSiteControl($permittedCrossDomainPolicies = 'all') {
if (!$this->validateSiteControl($permittedCrossDomainPolicies)) {
throw new \UnexpectedValueException('Invalid site control set');
}
$this->_siteControl = $permittedCrossDomainPolicies;
$this->_cacheValid = false;
return $this;
} | php | public function setSiteControl($permittedCrossDomainPolicies = 'all') {
if (!$this->validateSiteControl($permittedCrossDomainPolicies)) {
throw new \UnexpectedValueException('Invalid site control set');
}
$this->_siteControl = $permittedCrossDomainPolicies;
$this->_cacheValid = false;
return $this;
} | [
"public",
"function",
"setSiteControl",
"(",
"$",
"permittedCrossDomainPolicies",
"=",
"'all'",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"validateSiteControl",
"(",
"$",
"permittedCrossDomainPolicies",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"'Invalid site control set'",
")",
";",
"}",
"$",
"this",
"->",
"_siteControl",
"=",
"$",
"permittedCrossDomainPolicies",
";",
"$",
"this",
"->",
"_cacheValid",
"=",
"false",
";",
"return",
"$",
"this",
";",
"}"
] | site-control defines the meta-policy for the current domain. A meta-policy specifies acceptable
domain policy files other than the master policy file located in the target domain's root and named
crossdomain.xml.
@param string $permittedCrossDomainPolicies
@throws \UnexpectedValueException
@return FlashPolicy | [
"site",
"-",
"control",
"defines",
"the",
"meta",
"-",
"policy",
"for",
"the",
"current",
"domain",
".",
"A",
"meta",
"-",
"policy",
"specifies",
"acceptable",
"domain",
"policy",
"files",
"other",
"than",
"the",
"master",
"policy",
"file",
"located",
"in",
"the",
"target",
"domain",
"s",
"root",
"and",
"named",
"crossdomain",
".",
"xml",
"."
] | b85c2a1f189e43f7f0861daf7ff81d016c5d6403 | https://github.com/ratchetphp/Ratchet/blob/b85c2a1f189e43f7f0861daf7ff81d016c5d6403/src/Ratchet/Server/FlashPolicy.php#L96-L105 | train |
ratchetphp/Ratchet | src/Ratchet/Server/FlashPolicy.php | FlashPolicy.renderPolicy | public function renderPolicy() {
$policy = new \SimpleXMLElement($this->_policy);
$siteControl = $policy->addChild('site-control');
if ($this->_siteControl == '') {
$this->setSiteControl();
}
$siteControl->addAttribute('permitted-cross-domain-policies', $this->_siteControl);
if (empty($this->_access)) {
throw new \UnexpectedValueException('You must add a domain through addAllowedAccess()');
}
foreach ($this->_access as $access) {
$tmp = $policy->addChild('allow-access-from');
$tmp->addAttribute('domain', $access[0]);
$tmp->addAttribute('to-ports', $access[1]);
$tmp->addAttribute('secure', ($access[2] === true) ? 'true' : 'false');
}
return $policy;
} | php | public function renderPolicy() {
$policy = new \SimpleXMLElement($this->_policy);
$siteControl = $policy->addChild('site-control');
if ($this->_siteControl == '') {
$this->setSiteControl();
}
$siteControl->addAttribute('permitted-cross-domain-policies', $this->_siteControl);
if (empty($this->_access)) {
throw new \UnexpectedValueException('You must add a domain through addAllowedAccess()');
}
foreach ($this->_access as $access) {
$tmp = $policy->addChild('allow-access-from');
$tmp->addAttribute('domain', $access[0]);
$tmp->addAttribute('to-ports', $access[1]);
$tmp->addAttribute('secure', ($access[2] === true) ? 'true' : 'false');
}
return $policy;
} | [
"public",
"function",
"renderPolicy",
"(",
")",
"{",
"$",
"policy",
"=",
"new",
"\\",
"SimpleXMLElement",
"(",
"$",
"this",
"->",
"_policy",
")",
";",
"$",
"siteControl",
"=",
"$",
"policy",
"->",
"addChild",
"(",
"'site-control'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_siteControl",
"==",
"''",
")",
"{",
"$",
"this",
"->",
"setSiteControl",
"(",
")",
";",
"}",
"$",
"siteControl",
"->",
"addAttribute",
"(",
"'permitted-cross-domain-policies'",
",",
"$",
"this",
"->",
"_siteControl",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_access",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"'You must add a domain through addAllowedAccess()'",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"_access",
"as",
"$",
"access",
")",
"{",
"$",
"tmp",
"=",
"$",
"policy",
"->",
"addChild",
"(",
"'allow-access-from'",
")",
";",
"$",
"tmp",
"->",
"addAttribute",
"(",
"'domain'",
",",
"$",
"access",
"[",
"0",
"]",
")",
";",
"$",
"tmp",
"->",
"addAttribute",
"(",
"'to-ports'",
",",
"$",
"access",
"[",
"1",
"]",
")",
";",
"$",
"tmp",
"->",
"addAttribute",
"(",
"'secure'",
",",
"(",
"$",
"access",
"[",
"2",
"]",
"===",
"true",
")",
"?",
"'true'",
":",
"'false'",
")",
";",
"}",
"return",
"$",
"policy",
";",
"}"
] | Builds the crossdomain file based on the template policy
@throws \UnexpectedValueException
@return \SimpleXMLElement | [
"Builds",
"the",
"crossdomain",
"file",
"based",
"on",
"the",
"template",
"policy"
] | b85c2a1f189e43f7f0861daf7ff81d016c5d6403 | https://github.com/ratchetphp/Ratchet/blob/b85c2a1f189e43f7f0861daf7ff81d016c5d6403/src/Ratchet/Server/FlashPolicy.php#L145-L168 | train |
ratchetphp/Ratchet | src/Ratchet/Wamp/Topic.php | Topic.broadcast | public function broadcast($msg, array $exclude = array(), array $eligible = array()) {
$useEligible = (bool)count($eligible);
foreach ($this->subscribers as $client) {
if (in_array($client->WAMP->sessionId, $exclude)) {
continue;
}
if ($useEligible && !in_array($client->WAMP->sessionId, $eligible)) {
continue;
}
$client->event($this->id, $msg);
}
return $this;
} | php | public function broadcast($msg, array $exclude = array(), array $eligible = array()) {
$useEligible = (bool)count($eligible);
foreach ($this->subscribers as $client) {
if (in_array($client->WAMP->sessionId, $exclude)) {
continue;
}
if ($useEligible && !in_array($client->WAMP->sessionId, $eligible)) {
continue;
}
$client->event($this->id, $msg);
}
return $this;
} | [
"public",
"function",
"broadcast",
"(",
"$",
"msg",
",",
"array",
"$",
"exclude",
"=",
"array",
"(",
")",
",",
"array",
"$",
"eligible",
"=",
"array",
"(",
")",
")",
"{",
"$",
"useEligible",
"=",
"(",
"bool",
")",
"count",
"(",
"$",
"eligible",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"subscribers",
"as",
"$",
"client",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"client",
"->",
"WAMP",
"->",
"sessionId",
",",
"$",
"exclude",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"useEligible",
"&&",
"!",
"in_array",
"(",
"$",
"client",
"->",
"WAMP",
"->",
"sessionId",
",",
"$",
"eligible",
")",
")",
"{",
"continue",
";",
"}",
"$",
"client",
"->",
"event",
"(",
"$",
"this",
"->",
"id",
",",
"$",
"msg",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Send a message to all the connections in this topic
@param string|array $msg Payload to publish
@param array $exclude A list of session IDs the message should be excluded from (blacklist)
@param array $eligible A list of session Ids the message should be send to (whitelist)
@return Topic The same Topic object to chain | [
"Send",
"a",
"message",
"to",
"all",
"the",
"connections",
"in",
"this",
"topic"
] | b85c2a1f189e43f7f0861daf7ff81d016c5d6403 | https://github.com/ratchetphp/Ratchet/blob/b85c2a1f189e43f7f0861daf7ff81d016c5d6403/src/Ratchet/Wamp/Topic.php#L39-L54 | train |
ratchetphp/Ratchet | src/Ratchet/Server/IoServer.php | IoServer.handleConnect | public function handleConnect($conn) {
$conn->decor = new IoConnection($conn);
$conn->decor->resourceId = (int)$conn->stream;
$uri = $conn->getRemoteAddress();
$conn->decor->remoteAddress = trim(
parse_url((strpos($uri, '://') === false ? 'tcp://' : '') . $uri, PHP_URL_HOST),
'[]'
);
$this->app->onOpen($conn->decor);
$conn->on('data', function ($data) use ($conn) {
$this->handleData($data, $conn);
});
$conn->on('close', function () use ($conn) {
$this->handleEnd($conn);
});
$conn->on('error', function (\Exception $e) use ($conn) {
$this->handleError($e, $conn);
});
} | php | public function handleConnect($conn) {
$conn->decor = new IoConnection($conn);
$conn->decor->resourceId = (int)$conn->stream;
$uri = $conn->getRemoteAddress();
$conn->decor->remoteAddress = trim(
parse_url((strpos($uri, '://') === false ? 'tcp://' : '') . $uri, PHP_URL_HOST),
'[]'
);
$this->app->onOpen($conn->decor);
$conn->on('data', function ($data) use ($conn) {
$this->handleData($data, $conn);
});
$conn->on('close', function () use ($conn) {
$this->handleEnd($conn);
});
$conn->on('error', function (\Exception $e) use ($conn) {
$this->handleError($e, $conn);
});
} | [
"public",
"function",
"handleConnect",
"(",
"$",
"conn",
")",
"{",
"$",
"conn",
"->",
"decor",
"=",
"new",
"IoConnection",
"(",
"$",
"conn",
")",
";",
"$",
"conn",
"->",
"decor",
"->",
"resourceId",
"=",
"(",
"int",
")",
"$",
"conn",
"->",
"stream",
";",
"$",
"uri",
"=",
"$",
"conn",
"->",
"getRemoteAddress",
"(",
")",
";",
"$",
"conn",
"->",
"decor",
"->",
"remoteAddress",
"=",
"trim",
"(",
"parse_url",
"(",
"(",
"strpos",
"(",
"$",
"uri",
",",
"'://'",
")",
"===",
"false",
"?",
"'tcp://'",
":",
"''",
")",
".",
"$",
"uri",
",",
"PHP_URL_HOST",
")",
",",
"'[]'",
")",
";",
"$",
"this",
"->",
"app",
"->",
"onOpen",
"(",
"$",
"conn",
"->",
"decor",
")",
";",
"$",
"conn",
"->",
"on",
"(",
"'data'",
",",
"function",
"(",
"$",
"data",
")",
"use",
"(",
"$",
"conn",
")",
"{",
"$",
"this",
"->",
"handleData",
"(",
"$",
"data",
",",
"$",
"conn",
")",
";",
"}",
")",
";",
"$",
"conn",
"->",
"on",
"(",
"'close'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"conn",
")",
"{",
"$",
"this",
"->",
"handleEnd",
"(",
"$",
"conn",
")",
";",
"}",
")",
";",
"$",
"conn",
"->",
"on",
"(",
"'error'",
",",
"function",
"(",
"\\",
"Exception",
"$",
"e",
")",
"use",
"(",
"$",
"conn",
")",
"{",
"$",
"this",
"->",
"handleError",
"(",
"$",
"e",
",",
"$",
"conn",
")",
";",
"}",
")",
";",
"}"
] | Triggered when a new connection is received from React
@param \React\Socket\ConnectionInterface $conn | [
"Triggered",
"when",
"a",
"new",
"connection",
"is",
"received",
"from",
"React"
] | b85c2a1f189e43f7f0861daf7ff81d016c5d6403 | https://github.com/ratchetphp/Ratchet/blob/b85c2a1f189e43f7f0861daf7ff81d016c5d6403/src/Ratchet/Server/IoServer.php#L82-L103 | train |
ratchetphp/Ratchet | src/Ratchet/Server/IoServer.php | IoServer.handleData | public function handleData($data, $conn) {
try {
$this->app->onMessage($conn->decor, $data);
} catch (\Exception $e) {
$this->handleError($e, $conn);
}
} | php | public function handleData($data, $conn) {
try {
$this->app->onMessage($conn->decor, $data);
} catch (\Exception $e) {
$this->handleError($e, $conn);
}
} | [
"public",
"function",
"handleData",
"(",
"$",
"data",
",",
"$",
"conn",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"app",
"->",
"onMessage",
"(",
"$",
"conn",
"->",
"decor",
",",
"$",
"data",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"handleError",
"(",
"$",
"e",
",",
"$",
"conn",
")",
";",
"}",
"}"
] | Data has been received from React
@param string $data
@param \React\Socket\ConnectionInterface $conn | [
"Data",
"has",
"been",
"received",
"from",
"React"
] | b85c2a1f189e43f7f0861daf7ff81d016c5d6403 | https://github.com/ratchetphp/Ratchet/blob/b85c2a1f189e43f7f0861daf7ff81d016c5d6403/src/Ratchet/Server/IoServer.php#L110-L116 | train |
ratchetphp/Ratchet | src/Ratchet/Server/IoServer.php | IoServer.handleEnd | public function handleEnd($conn) {
try {
$this->app->onClose($conn->decor);
} catch (\Exception $e) {
$this->handleError($e, $conn);
}
unset($conn->decor);
} | php | public function handleEnd($conn) {
try {
$this->app->onClose($conn->decor);
} catch (\Exception $e) {
$this->handleError($e, $conn);
}
unset($conn->decor);
} | [
"public",
"function",
"handleEnd",
"(",
"$",
"conn",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"app",
"->",
"onClose",
"(",
"$",
"conn",
"->",
"decor",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"handleError",
"(",
"$",
"e",
",",
"$",
"conn",
")",
";",
"}",
"unset",
"(",
"$",
"conn",
"->",
"decor",
")",
";",
"}"
] | A connection has been closed by React
@param \React\Socket\ConnectionInterface $conn | [
"A",
"connection",
"has",
"been",
"closed",
"by",
"React"
] | b85c2a1f189e43f7f0861daf7ff81d016c5d6403 | https://github.com/ratchetphp/Ratchet/blob/b85c2a1f189e43f7f0861daf7ff81d016c5d6403/src/Ratchet/Server/IoServer.php#L122-L130 | train |
ratchetphp/Ratchet | src/Ratchet/Server/IoServer.php | IoServer.handleError | public function handleError(\Exception $e, $conn) {
$this->app->onError($conn->decor, $e);
} | php | public function handleError(\Exception $e, $conn) {
$this->app->onError($conn->decor, $e);
} | [
"public",
"function",
"handleError",
"(",
"\\",
"Exception",
"$",
"e",
",",
"$",
"conn",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"onError",
"(",
"$",
"conn",
"->",
"decor",
",",
"$",
"e",
")",
";",
"}"
] | An error has occurred, let the listening application know
@param \Exception $e
@param \React\Socket\ConnectionInterface $conn | [
"An",
"error",
"has",
"occurred",
"let",
"the",
"listening",
"application",
"know"
] | b85c2a1f189e43f7f0861daf7ff81d016c5d6403 | https://github.com/ratchetphp/Ratchet/blob/b85c2a1f189e43f7f0861daf7ff81d016c5d6403/src/Ratchet/Server/IoServer.php#L137-L139 | train |
ratchetphp/Ratchet | src/Ratchet/Http/CloseResponseTrait.php | CloseResponseTrait.close | private function close(ConnectionInterface $conn, $code = 400, array $additional_headers = []) {
$response = new Response($code, array_merge([
'X-Powered-By' => \Ratchet\VERSION
], $additional_headers));
$conn->send(gPsr\str($response));
$conn->close();
} | php | private function close(ConnectionInterface $conn, $code = 400, array $additional_headers = []) {
$response = new Response($code, array_merge([
'X-Powered-By' => \Ratchet\VERSION
], $additional_headers));
$conn->send(gPsr\str($response));
$conn->close();
} | [
"private",
"function",
"close",
"(",
"ConnectionInterface",
"$",
"conn",
",",
"$",
"code",
"=",
"400",
",",
"array",
"$",
"additional_headers",
"=",
"[",
"]",
")",
"{",
"$",
"response",
"=",
"new",
"Response",
"(",
"$",
"code",
",",
"array_merge",
"(",
"[",
"'X-Powered-By'",
"=>",
"\\",
"Ratchet",
"\\",
"VERSION",
"]",
",",
"$",
"additional_headers",
")",
")",
";",
"$",
"conn",
"->",
"send",
"(",
"gPsr",
"\\",
"str",
"(",
"$",
"response",
")",
")",
";",
"$",
"conn",
"->",
"close",
"(",
")",
";",
"}"
] | Close a connection with an HTTP response
@param \Ratchet\ConnectionInterface $conn
@param int $code HTTP status code
@return null | [
"Close",
"a",
"connection",
"with",
"an",
"HTTP",
"response"
] | b85c2a1f189e43f7f0861daf7ff81d016c5d6403 | https://github.com/ratchetphp/Ratchet/blob/b85c2a1f189e43f7f0861daf7ff81d016c5d6403/src/Ratchet/Http/CloseResponseTrait.php#L14-L21 | train |
ratchetphp/Ratchet | src/Ratchet/Session/SessionProvider.php | SessionProvider.parseCookie | private function parseCookie($cookie, $host = null, $path = null, $decode = false) {
// Explode the cookie string using a series of semicolons
$pieces = array_filter(array_map('trim', explode(';', $cookie)));
// The name of the cookie (first kvp) must include an equal sign.
if (empty($pieces) || !strpos($pieces[0], '=')) {
return false;
}
// Create the default return array
$data = array_merge(array_fill_keys(array_keys(self::$cookieParts), null), array(
'cookies' => array(),
'data' => array(),
'path' => $path ?: '/',
'http_only' => false,
'discard' => false,
'domain' => $host
));
$foundNonCookies = 0;
// Add the cookie pieces into the parsed data array
foreach ($pieces as $part) {
$cookieParts = explode('=', $part, 2);
$key = trim($cookieParts[0]);
if (count($cookieParts) == 1) {
// Can be a single value (e.g. secure, httpOnly)
$value = true;
} else {
// Be sure to strip wrapping quotes
$value = trim($cookieParts[1], " \n\r\t\0\x0B\"");
if ($decode) {
$value = urldecode($value);
}
}
// Only check for non-cookies when cookies have been found
if (!empty($data['cookies'])) {
foreach (self::$cookieParts as $mapValue => $search) {
if (!strcasecmp($search, $key)) {
$data[$mapValue] = $mapValue == 'port' ? array_map('trim', explode(',', $value)) : $value;
$foundNonCookies++;
continue 2;
}
}
}
// If cookies have not yet been retrieved, or this value was not found in the pieces array, treat it as a
// cookie. IF non-cookies have been parsed, then this isn't a cookie, it's cookie data. Cookies then data.
$data[$foundNonCookies ? 'data' : 'cookies'][$key] = $value;
}
// Calculate the expires date
if (!$data['expires'] && $data['max_age']) {
$data['expires'] = time() + (int) $data['max_age'];
}
return $data;
} | php | private function parseCookie($cookie, $host = null, $path = null, $decode = false) {
// Explode the cookie string using a series of semicolons
$pieces = array_filter(array_map('trim', explode(';', $cookie)));
// The name of the cookie (first kvp) must include an equal sign.
if (empty($pieces) || !strpos($pieces[0], '=')) {
return false;
}
// Create the default return array
$data = array_merge(array_fill_keys(array_keys(self::$cookieParts), null), array(
'cookies' => array(),
'data' => array(),
'path' => $path ?: '/',
'http_only' => false,
'discard' => false,
'domain' => $host
));
$foundNonCookies = 0;
// Add the cookie pieces into the parsed data array
foreach ($pieces as $part) {
$cookieParts = explode('=', $part, 2);
$key = trim($cookieParts[0]);
if (count($cookieParts) == 1) {
// Can be a single value (e.g. secure, httpOnly)
$value = true;
} else {
// Be sure to strip wrapping quotes
$value = trim($cookieParts[1], " \n\r\t\0\x0B\"");
if ($decode) {
$value = urldecode($value);
}
}
// Only check for non-cookies when cookies have been found
if (!empty($data['cookies'])) {
foreach (self::$cookieParts as $mapValue => $search) {
if (!strcasecmp($search, $key)) {
$data[$mapValue] = $mapValue == 'port' ? array_map('trim', explode(',', $value)) : $value;
$foundNonCookies++;
continue 2;
}
}
}
// If cookies have not yet been retrieved, or this value was not found in the pieces array, treat it as a
// cookie. IF non-cookies have been parsed, then this isn't a cookie, it's cookie data. Cookies then data.
$data[$foundNonCookies ? 'data' : 'cookies'][$key] = $value;
}
// Calculate the expires date
if (!$data['expires'] && $data['max_age']) {
$data['expires'] = time() + (int) $data['max_age'];
}
return $data;
} | [
"private",
"function",
"parseCookie",
"(",
"$",
"cookie",
",",
"$",
"host",
"=",
"null",
",",
"$",
"path",
"=",
"null",
",",
"$",
"decode",
"=",
"false",
")",
"{",
"// Explode the cookie string using a series of semicolons",
"$",
"pieces",
"=",
"array_filter",
"(",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"';'",
",",
"$",
"cookie",
")",
")",
")",
";",
"// The name of the cookie (first kvp) must include an equal sign.",
"if",
"(",
"empty",
"(",
"$",
"pieces",
")",
"||",
"!",
"strpos",
"(",
"$",
"pieces",
"[",
"0",
"]",
",",
"'='",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Create the default return array",
"$",
"data",
"=",
"array_merge",
"(",
"array_fill_keys",
"(",
"array_keys",
"(",
"self",
"::",
"$",
"cookieParts",
")",
",",
"null",
")",
",",
"array",
"(",
"'cookies'",
"=>",
"array",
"(",
")",
",",
"'data'",
"=>",
"array",
"(",
")",
",",
"'path'",
"=>",
"$",
"path",
"?",
":",
"'/'",
",",
"'http_only'",
"=>",
"false",
",",
"'discard'",
"=>",
"false",
",",
"'domain'",
"=>",
"$",
"host",
")",
")",
";",
"$",
"foundNonCookies",
"=",
"0",
";",
"// Add the cookie pieces into the parsed data array",
"foreach",
"(",
"$",
"pieces",
"as",
"$",
"part",
")",
"{",
"$",
"cookieParts",
"=",
"explode",
"(",
"'='",
",",
"$",
"part",
",",
"2",
")",
";",
"$",
"key",
"=",
"trim",
"(",
"$",
"cookieParts",
"[",
"0",
"]",
")",
";",
"if",
"(",
"count",
"(",
"$",
"cookieParts",
")",
"==",
"1",
")",
"{",
"// Can be a single value (e.g. secure, httpOnly)",
"$",
"value",
"=",
"true",
";",
"}",
"else",
"{",
"// Be sure to strip wrapping quotes",
"$",
"value",
"=",
"trim",
"(",
"$",
"cookieParts",
"[",
"1",
"]",
",",
"\" \\n\\r\\t\\0\\x0B\\\"\"",
")",
";",
"if",
"(",
"$",
"decode",
")",
"{",
"$",
"value",
"=",
"urldecode",
"(",
"$",
"value",
")",
";",
"}",
"}",
"// Only check for non-cookies when cookies have been found",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'cookies'",
"]",
")",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"cookieParts",
"as",
"$",
"mapValue",
"=>",
"$",
"search",
")",
"{",
"if",
"(",
"!",
"strcasecmp",
"(",
"$",
"search",
",",
"$",
"key",
")",
")",
"{",
"$",
"data",
"[",
"$",
"mapValue",
"]",
"=",
"$",
"mapValue",
"==",
"'port'",
"?",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"','",
",",
"$",
"value",
")",
")",
":",
"$",
"value",
";",
"$",
"foundNonCookies",
"++",
";",
"continue",
"2",
";",
"}",
"}",
"}",
"// If cookies have not yet been retrieved, or this value was not found in the pieces array, treat it as a",
"// cookie. IF non-cookies have been parsed, then this isn't a cookie, it's cookie data. Cookies then data.",
"$",
"data",
"[",
"$",
"foundNonCookies",
"?",
"'data'",
":",
"'cookies'",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"// Calculate the expires date",
"if",
"(",
"!",
"$",
"data",
"[",
"'expires'",
"]",
"&&",
"$",
"data",
"[",
"'max_age'",
"]",
")",
"{",
"$",
"data",
"[",
"'expires'",
"]",
"=",
"time",
"(",
")",
"+",
"(",
"int",
")",
"$",
"data",
"[",
"'max_age'",
"]",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Taken from Guzzle3 | [
"Taken",
"from",
"Guzzle3"
] | b85c2a1f189e43f7f0861daf7ff81d016c5d6403 | https://github.com/ratchetphp/Ratchet/blob/b85c2a1f189e43f7f0861daf7ff81d016c5d6403/src/Ratchet/Session/SessionProvider.php#L183-L242 | train |
ratchetphp/Ratchet | src/Ratchet/Server/IpBlackList.php | IpBlackList.unblockAddress | public function unblockAddress($ip) {
if (isset($this->_blacklist[$this->filterAddress($ip)])) {
unset($this->_blacklist[$this->filterAddress($ip)]);
}
return $this;
} | php | public function unblockAddress($ip) {
if (isset($this->_blacklist[$this->filterAddress($ip)])) {
unset($this->_blacklist[$this->filterAddress($ip)]);
}
return $this;
} | [
"public",
"function",
"unblockAddress",
"(",
"$",
"ip",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_blacklist",
"[",
"$",
"this",
"->",
"filterAddress",
"(",
"$",
"ip",
")",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_blacklist",
"[",
"$",
"this",
"->",
"filterAddress",
"(",
"$",
"ip",
")",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Unblock an address so they can access your application again
@param string $ip IP address to unblock from connecting to your application
@return IpBlackList | [
"Unblock",
"an",
"address",
"so",
"they",
"can",
"access",
"your",
"application",
"again"
] | b85c2a1f189e43f7f0861daf7ff81d016c5d6403 | https://github.com/ratchetphp/Ratchet/blob/b85c2a1f189e43f7f0861daf7ff81d016c5d6403/src/Ratchet/Server/IpBlackList.php#L40-L46 | train |
ratchetphp/Ratchet | src/Ratchet/Wamp/WampConnection.php | WampConnection.callResult | public function callResult($id, $data = array()) {
return $this->send(json_encode(array(WAMP::MSG_CALL_RESULT, $id, $data)));
} | php | public function callResult($id, $data = array()) {
return $this->send(json_encode(array(WAMP::MSG_CALL_RESULT, $id, $data)));
} | [
"public",
"function",
"callResult",
"(",
"$",
"id",
",",
"$",
"data",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"send",
"(",
"json_encode",
"(",
"array",
"(",
"WAMP",
"::",
"MSG_CALL_RESULT",
",",
"$",
"id",
",",
"$",
"data",
")",
")",
")",
";",
"}"
] | Successfully respond to a call made by the client
@param string $id The unique ID given by the client to respond to
@param array $data an object or array
@return WampConnection | [
"Successfully",
"respond",
"to",
"a",
"call",
"made",
"by",
"the",
"client"
] | b85c2a1f189e43f7f0861daf7ff81d016c5d6403 | https://github.com/ratchetphp/Ratchet/blob/b85c2a1f189e43f7f0861daf7ff81d016c5d6403/src/Ratchet/Wamp/WampConnection.php#L32-L34 | train |
ratchetphp/Ratchet | src/Ratchet/Wamp/WampConnection.php | WampConnection.callError | public function callError($id, $errorUri, $desc = '', $details = null) {
if ($errorUri instanceof Topic) {
$errorUri = (string)$errorUri;
}
$data = array(WAMP::MSG_CALL_ERROR, $id, $errorUri, $desc);
if (null !== $details) {
$data[] = $details;
}
return $this->send(json_encode($data));
} | php | public function callError($id, $errorUri, $desc = '', $details = null) {
if ($errorUri instanceof Topic) {
$errorUri = (string)$errorUri;
}
$data = array(WAMP::MSG_CALL_ERROR, $id, $errorUri, $desc);
if (null !== $details) {
$data[] = $details;
}
return $this->send(json_encode($data));
} | [
"public",
"function",
"callError",
"(",
"$",
"id",
",",
"$",
"errorUri",
",",
"$",
"desc",
"=",
"''",
",",
"$",
"details",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"errorUri",
"instanceof",
"Topic",
")",
"{",
"$",
"errorUri",
"=",
"(",
"string",
")",
"$",
"errorUri",
";",
"}",
"$",
"data",
"=",
"array",
"(",
"WAMP",
"::",
"MSG_CALL_ERROR",
",",
"$",
"id",
",",
"$",
"errorUri",
",",
"$",
"desc",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"details",
")",
"{",
"$",
"data",
"[",
"]",
"=",
"$",
"details",
";",
"}",
"return",
"$",
"this",
"->",
"send",
"(",
"json_encode",
"(",
"$",
"data",
")",
")",
";",
"}"
] | Respond with an error to a client call
@param string $id The unique ID given by the client to respond to
@param string $errorUri The URI given to identify the specific error
@param string $desc A developer-oriented description of the error
@param string $details An optional human readable detail message to send back
@return WampConnection | [
"Respond",
"with",
"an",
"error",
"to",
"a",
"client",
"call"
] | b85c2a1f189e43f7f0861daf7ff81d016c5d6403 | https://github.com/ratchetphp/Ratchet/blob/b85c2a1f189e43f7f0861daf7ff81d016c5d6403/src/Ratchet/Wamp/WampConnection.php#L44-L56 | train |
ratchetphp/Ratchet | src/Ratchet/Wamp/WampConnection.php | WampConnection.getUri | public function getUri($uri) {
$curieSeperator = ':';
if (preg_match('/http(s*)\:\/\//', $uri) == false) {
if (strpos($uri, $curieSeperator) !== false) {
list($prefix, $action) = explode($curieSeperator, $uri);
if(isset($this->WAMP->prefixes[$prefix]) === true){
return $this->WAMP->prefixes[$prefix] . '#' . $action;
}
}
}
return $uri;
} | php | public function getUri($uri) {
$curieSeperator = ':';
if (preg_match('/http(s*)\:\/\//', $uri) == false) {
if (strpos($uri, $curieSeperator) !== false) {
list($prefix, $action) = explode($curieSeperator, $uri);
if(isset($this->WAMP->prefixes[$prefix]) === true){
return $this->WAMP->prefixes[$prefix] . '#' . $action;
}
}
}
return $uri;
} | [
"public",
"function",
"getUri",
"(",
"$",
"uri",
")",
"{",
"$",
"curieSeperator",
"=",
"':'",
";",
"if",
"(",
"preg_match",
"(",
"'/http(s*)\\:\\/\\//'",
",",
"$",
"uri",
")",
"==",
"false",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"uri",
",",
"$",
"curieSeperator",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"prefix",
",",
"$",
"action",
")",
"=",
"explode",
"(",
"$",
"curieSeperator",
",",
"$",
"uri",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"WAMP",
"->",
"prefixes",
"[",
"$",
"prefix",
"]",
")",
"===",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"WAMP",
"->",
"prefixes",
"[",
"$",
"prefix",
"]",
".",
"'#'",
".",
"$",
"action",
";",
"}",
"}",
"}",
"return",
"$",
"uri",
";",
"}"
] | Get the full request URI from the connection object if a prefix has been established for it
@param string $uri
@return string | [
"Get",
"the",
"full",
"request",
"URI",
"from",
"the",
"connection",
"object",
"if",
"a",
"prefix",
"has",
"been",
"established",
"for",
"it"
] | b85c2a1f189e43f7f0861daf7ff81d016c5d6403 | https://github.com/ratchetphp/Ratchet/blob/b85c2a1f189e43f7f0861daf7ff81d016c5d6403/src/Ratchet/Wamp/WampConnection.php#L83-L97 | train |
doctrine/orm | lib/Doctrine/ORM/Query/Parameter.php | Parameter.setValue | public function setValue($value, $type = null)
{
$this->value = $value;
$this->type = $type ?: ParameterTypeInferer::inferType($value);
} | php | public function setValue($value, $type = null)
{
$this->value = $value;
$this->type = $type ?: ParameterTypeInferer::inferType($value);
} | [
"public",
"function",
"setValue",
"(",
"$",
"value",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"value",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"type",
"=",
"$",
"type",
"?",
":",
"ParameterTypeInferer",
"::",
"inferType",
"(",
"$",
"value",
")",
";",
"}"
] | Defines the Parameter value.
@param mixed $value Parameter value.
@param mixed $type Parameter type. | [
"Defines",
"the",
"Parameter",
"value",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Query/Parameter.php#L83-L87 | train |
doctrine/orm | lib/Doctrine/ORM/Mapping/Driver/FileDriver.php | FileDriver.getElement | public function getElement($className)
{
if ($this->classCache === null) {
$this->initialize();
}
if (isset($this->classCache[$className])) {
return $this->classCache[$className];
}
$result = $this->loadMappingFile($this->locator->findMappingFile($className));
if (! isset($result[$className])) {
throw MappingException::invalidMappingFile($className, str_replace('\\', '.', $className) . $this->locator->getFileExtension());
}
$this->classCache[$className] = $result[$className];
return $result[$className];
} | php | public function getElement($className)
{
if ($this->classCache === null) {
$this->initialize();
}
if (isset($this->classCache[$className])) {
return $this->classCache[$className];
}
$result = $this->loadMappingFile($this->locator->findMappingFile($className));
if (! isset($result[$className])) {
throw MappingException::invalidMappingFile($className, str_replace('\\', '.', $className) . $this->locator->getFileExtension());
}
$this->classCache[$className] = $result[$className];
return $result[$className];
} | [
"public",
"function",
"getElement",
"(",
"$",
"className",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"classCache",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"initialize",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"classCache",
"[",
"$",
"className",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"classCache",
"[",
"$",
"className",
"]",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"loadMappingFile",
"(",
"$",
"this",
"->",
"locator",
"->",
"findMappingFile",
"(",
"$",
"className",
")",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"result",
"[",
"$",
"className",
"]",
")",
")",
"{",
"throw",
"MappingException",
"::",
"invalidMappingFile",
"(",
"$",
"className",
",",
"str_replace",
"(",
"'\\\\'",
",",
"'.'",
",",
"$",
"className",
")",
".",
"$",
"this",
"->",
"locator",
"->",
"getFileExtension",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"classCache",
"[",
"$",
"className",
"]",
"=",
"$",
"result",
"[",
"$",
"className",
"]",
";",
"return",
"$",
"result",
"[",
"$",
"className",
"]",
";",
"}"
] | Gets the element of schema meta data for the class from the mapping file.
This will lazily load the mapping file if it is not loaded yet.
@param string $className
@return mixed[] The element of schema meta data.
@throws MappingException | [
"Gets",
"the",
"element",
"of",
"schema",
"meta",
"data",
"for",
"the",
"class",
"from",
"the",
"mapping",
"file",
".",
"This",
"will",
"lazily",
"load",
"the",
"mapping",
"file",
"if",
"it",
"is",
"not",
"loaded",
"yet",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Mapping/Driver/FileDriver.php#L99-L117 | train |
doctrine/orm | lib/Doctrine/ORM/Mapping/Driver/FileDriver.php | FileDriver.initialize | protected function initialize()
{
$this->classCache = [];
if ($this->globalBasename !== null) {
foreach ($this->locator->getPaths() as $path) {
$file = $path . '/' . $this->globalBasename . $this->locator->getFileExtension();
if (is_file($file)) {
$this->classCache = array_merge(
$this->classCache,
$this->loadMappingFile($file)
);
}
}
}
} | php | protected function initialize()
{
$this->classCache = [];
if ($this->globalBasename !== null) {
foreach ($this->locator->getPaths() as $path) {
$file = $path . '/' . $this->globalBasename . $this->locator->getFileExtension();
if (is_file($file)) {
$this->classCache = array_merge(
$this->classCache,
$this->loadMappingFile($file)
);
}
}
}
} | [
"protected",
"function",
"initialize",
"(",
")",
"{",
"$",
"this",
"->",
"classCache",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"globalBasename",
"!==",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"locator",
"->",
"getPaths",
"(",
")",
"as",
"$",
"path",
")",
"{",
"$",
"file",
"=",
"$",
"path",
".",
"'/'",
".",
"$",
"this",
"->",
"globalBasename",
".",
"$",
"this",
"->",
"locator",
"->",
"getFileExtension",
"(",
")",
";",
"if",
"(",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"$",
"this",
"->",
"classCache",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"classCache",
",",
"$",
"this",
"->",
"loadMappingFile",
"(",
"$",
"file",
")",
")",
";",
"}",
"}",
"}",
"}"
] | Initializes the class cache from all the global files.
Using this feature adds a substantial performance hit to file drivers as
more metadata has to be loaded into memory than might actually be
necessary. This may not be relevant to scenarios where caching of
metadata is in place, however hits very hard in scenarios where no
caching is used. | [
"Initializes",
"the",
"class",
"cache",
"from",
"all",
"the",
"global",
"files",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Mapping/Driver/FileDriver.php#L173-L187 | train |
doctrine/orm | lib/Doctrine/ORM/QueryBuilder.php | QueryBuilder.findRootAlias | private function findRootAlias($alias, $parentAlias)
{
$rootAlias = null;
if (in_array($parentAlias, $this->getRootAliases(), true)) {
$rootAlias = $parentAlias;
} elseif (isset($this->joinRootAliases[$parentAlias])) {
$rootAlias = $this->joinRootAliases[$parentAlias];
} else {
// Should never happen with correct joining order. Might be
// thoughtful to throw exception instead.
$rootAlias = $this->getRootAlias();
}
$this->joinRootAliases[$alias] = $rootAlias;
return $rootAlias;
} | php | private function findRootAlias($alias, $parentAlias)
{
$rootAlias = null;
if (in_array($parentAlias, $this->getRootAliases(), true)) {
$rootAlias = $parentAlias;
} elseif (isset($this->joinRootAliases[$parentAlias])) {
$rootAlias = $this->joinRootAliases[$parentAlias];
} else {
// Should never happen with correct joining order. Might be
// thoughtful to throw exception instead.
$rootAlias = $this->getRootAlias();
}
$this->joinRootAliases[$alias] = $rootAlias;
return $rootAlias;
} | [
"private",
"function",
"findRootAlias",
"(",
"$",
"alias",
",",
"$",
"parentAlias",
")",
"{",
"$",
"rootAlias",
"=",
"null",
";",
"if",
"(",
"in_array",
"(",
"$",
"parentAlias",
",",
"$",
"this",
"->",
"getRootAliases",
"(",
")",
",",
"true",
")",
")",
"{",
"$",
"rootAlias",
"=",
"$",
"parentAlias",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"joinRootAliases",
"[",
"$",
"parentAlias",
"]",
")",
")",
"{",
"$",
"rootAlias",
"=",
"$",
"this",
"->",
"joinRootAliases",
"[",
"$",
"parentAlias",
"]",
";",
"}",
"else",
"{",
"// Should never happen with correct joining order. Might be",
"// thoughtful to throw exception instead.",
"$",
"rootAlias",
"=",
"$",
"this",
"->",
"getRootAlias",
"(",
")",
";",
"}",
"$",
"this",
"->",
"joinRootAliases",
"[",
"$",
"alias",
"]",
"=",
"$",
"rootAlias",
";",
"return",
"$",
"rootAlias",
";",
"}"
] | Finds the root entity alias of the joined entity.
@param string $alias The alias of the new join entity
@param string $parentAlias The parent entity alias of the join relationship
@return string | [
"Finds",
"the",
"root",
"entity",
"alias",
"of",
"the",
"joined",
"entity",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/QueryBuilder.php#L379-L396 | train |
doctrine/orm | lib/Doctrine/ORM/QueryBuilder.php | QueryBuilder.getRootAliases | public function getRootAliases()
{
$aliases = [];
foreach ($this->dqlParts['from'] as &$fromClause) {
if (is_string($fromClause)) {
$spacePos = strrpos($fromClause, ' ');
$from = substr($fromClause, 0, $spacePos);
$alias = substr($fromClause, $spacePos + 1);
$fromClause = new Query\Expr\From($from, $alias);
}
$aliases[] = $fromClause->getAlias();
}
return $aliases;
} | php | public function getRootAliases()
{
$aliases = [];
foreach ($this->dqlParts['from'] as &$fromClause) {
if (is_string($fromClause)) {
$spacePos = strrpos($fromClause, ' ');
$from = substr($fromClause, 0, $spacePos);
$alias = substr($fromClause, $spacePos + 1);
$fromClause = new Query\Expr\From($from, $alias);
}
$aliases[] = $fromClause->getAlias();
}
return $aliases;
} | [
"public",
"function",
"getRootAliases",
"(",
")",
"{",
"$",
"aliases",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"dqlParts",
"[",
"'from'",
"]",
"as",
"&",
"$",
"fromClause",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"fromClause",
")",
")",
"{",
"$",
"spacePos",
"=",
"strrpos",
"(",
"$",
"fromClause",
",",
"' '",
")",
";",
"$",
"from",
"=",
"substr",
"(",
"$",
"fromClause",
",",
"0",
",",
"$",
"spacePos",
")",
";",
"$",
"alias",
"=",
"substr",
"(",
"$",
"fromClause",
",",
"$",
"spacePos",
"+",
"1",
")",
";",
"$",
"fromClause",
"=",
"new",
"Query",
"\\",
"Expr",
"\\",
"From",
"(",
"$",
"from",
",",
"$",
"alias",
")",
";",
"}",
"$",
"aliases",
"[",
"]",
"=",
"$",
"fromClause",
"->",
"getAlias",
"(",
")",
";",
"}",
"return",
"$",
"aliases",
";",
"}"
] | Gets the root aliases of the query. This is the entity aliases involved
in the construction of the query.
<code>
$qb = $em->createQueryBuilder()
->select('u')
->from('User', 'u');
$qb->getRootAliases(); // array('u')
</code>
@return string[] | [
"Gets",
"the",
"root",
"aliases",
"of",
"the",
"query",
".",
"This",
"is",
"the",
"entity",
"aliases",
"involved",
"in",
"the",
"construction",
"of",
"the",
"query",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/QueryBuilder.php#L441-L458 | train |
doctrine/orm | lib/Doctrine/ORM/QueryBuilder.php | QueryBuilder.getRootEntities | public function getRootEntities()
{
$entities = [];
foreach ($this->dqlParts['from'] as &$fromClause) {
if (is_string($fromClause)) {
$spacePos = strrpos($fromClause, ' ');
$from = substr($fromClause, 0, $spacePos);
$alias = substr($fromClause, $spacePos + 1);
$fromClause = new Query\Expr\From($from, $alias);
}
$entities[] = $fromClause->getFrom();
}
return $entities;
} | php | public function getRootEntities()
{
$entities = [];
foreach ($this->dqlParts['from'] as &$fromClause) {
if (is_string($fromClause)) {
$spacePos = strrpos($fromClause, ' ');
$from = substr($fromClause, 0, $spacePos);
$alias = substr($fromClause, $spacePos + 1);
$fromClause = new Query\Expr\From($from, $alias);
}
$entities[] = $fromClause->getFrom();
}
return $entities;
} | [
"public",
"function",
"getRootEntities",
"(",
")",
"{",
"$",
"entities",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"dqlParts",
"[",
"'from'",
"]",
"as",
"&",
"$",
"fromClause",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"fromClause",
")",
")",
"{",
"$",
"spacePos",
"=",
"strrpos",
"(",
"$",
"fromClause",
",",
"' '",
")",
";",
"$",
"from",
"=",
"substr",
"(",
"$",
"fromClause",
",",
"0",
",",
"$",
"spacePos",
")",
";",
"$",
"alias",
"=",
"substr",
"(",
"$",
"fromClause",
",",
"$",
"spacePos",
"+",
"1",
")",
";",
"$",
"fromClause",
"=",
"new",
"Query",
"\\",
"Expr",
"\\",
"From",
"(",
"$",
"from",
",",
"$",
"alias",
")",
";",
"}",
"$",
"entities",
"[",
"]",
"=",
"$",
"fromClause",
"->",
"getFrom",
"(",
")",
";",
"}",
"return",
"$",
"entities",
";",
"}"
] | Gets the root entities of the query. This is the entity aliases involved
in the construction of the query.
<code>
$qb = $em->createQueryBuilder()
->select('u')
->from('User', 'u');
$qb->getRootEntities(); // array('User')
</code>
@return string[] | [
"Gets",
"the",
"root",
"entities",
"of",
"the",
"query",
".",
"This",
"is",
"the",
"entity",
"aliases",
"involved",
"in",
"the",
"construction",
"of",
"the",
"query",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/QueryBuilder.php#L494-L511 | train |
doctrine/orm | lib/Doctrine/ORM/QueryBuilder.php | QueryBuilder.update | public function update($update = null, $alias = null)
{
$this->type = self::UPDATE;
if (! $update) {
return $this;
}
return $this->add('from', new Expr\From($update, $alias));
} | php | public function update($update = null, $alias = null)
{
$this->type = self::UPDATE;
if (! $update) {
return $this;
}
return $this->add('from', new Expr\From($update, $alias));
} | [
"public",
"function",
"update",
"(",
"$",
"update",
"=",
"null",
",",
"$",
"alias",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"type",
"=",
"self",
"::",
"UPDATE",
";",
"if",
"(",
"!",
"$",
"update",
")",
"{",
"return",
"$",
"this",
";",
"}",
"return",
"$",
"this",
"->",
"add",
"(",
"'from'",
",",
"new",
"Expr",
"\\",
"From",
"(",
"$",
"update",
",",
"$",
"alias",
")",
")",
";",
"}"
] | Turns the query being built into a bulk update query that ranges over
a certain entity type.
<code>
$qb = $em->createQueryBuilder()
->update('User', 'u')
->set('u.password', '?1')
->where('u.id = ?2');
</code>
@param string $update The class/type whose instances are subject to the update.
@param string $alias The class/type alias used in the constructed query.
@return self | [
"Turns",
"the",
"query",
"being",
"built",
"into",
"a",
"bulk",
"update",
"query",
"that",
"ranges",
"over",
"a",
"certain",
"entity",
"type",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/QueryBuilder.php#L843-L852 | train |
doctrine/orm | lib/Doctrine/ORM/QueryBuilder.php | QueryBuilder.from | public function from($from, $alias, $indexBy = null)
{
return $this->add('from', new Expr\From($from, $alias, $indexBy), true);
} | php | public function from($from, $alias, $indexBy = null)
{
return $this->add('from', new Expr\From($from, $alias, $indexBy), true);
} | [
"public",
"function",
"from",
"(",
"$",
"from",
",",
"$",
"alias",
",",
"$",
"indexBy",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"add",
"(",
"'from'",
",",
"new",
"Expr",
"\\",
"From",
"(",
"$",
"from",
",",
"$",
"alias",
",",
"$",
"indexBy",
")",
",",
"true",
")",
";",
"}"
] | Creates and adds a query root corresponding to the entity identified by the given alias,
forming a cartesian product with any existing query roots.
<code>
$qb = $em->createQueryBuilder()
->select('u')
->from('User', 'u');
</code>
@param string $from The class name.
@param string $alias The alias of the class.
@param string $indexBy The index for the from.
@return self | [
"Creates",
"and",
"adds",
"a",
"query",
"root",
"corresponding",
"to",
"the",
"entity",
"identified",
"by",
"the",
"given",
"alias",
"forming",
"a",
"cartesian",
"product",
"with",
"any",
"existing",
"query",
"roots",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/QueryBuilder.php#L870-L873 | train |
doctrine/orm | lib/Doctrine/ORM/QueryBuilder.php | QueryBuilder.set | public function set($key, $value)
{
return $this->add('set', new Expr\Comparison($key, Expr\Comparison::EQ, $value), true);
} | php | public function set($key, $value)
{
return $this->add('set', new Expr\Comparison($key, Expr\Comparison::EQ, $value), true);
} | [
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"return",
"$",
"this",
"->",
"add",
"(",
"'set'",
",",
"new",
"Expr",
"\\",
"Comparison",
"(",
"$",
"key",
",",
"Expr",
"\\",
"Comparison",
"::",
"EQ",
",",
"$",
"value",
")",
",",
"true",
")",
";",
"}"
] | Sets a new value for a field in a bulk update query.
<code>
$qb = $em->createQueryBuilder()
->update('User', 'u')
->set('u.password', '?1')
->where('u.id = ?2');
</code>
@param string $key The key/field to set.
@param string $value The value, expression, placeholder, etc.
@return self | [
"Sets",
"a",
"new",
"value",
"for",
"a",
"field",
"in",
"a",
"bulk",
"update",
"query",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/QueryBuilder.php#L1032-L1035 | train |
doctrine/orm | lib/Doctrine/ORM/QueryBuilder.php | QueryBuilder.addCriteria | public function addCriteria(Criteria $criteria)
{
$allAliases = $this->getAllAliases();
if (! isset($allAliases[0])) {
throw new Query\QueryException('No aliases are set before invoking addCriteria().');
}
$visitor = new QueryExpressionVisitor($this->getAllAliases());
$whereExpression = $criteria->getWhereExpression();
if ($whereExpression) {
$this->andWhere($visitor->dispatch($whereExpression));
foreach ($visitor->getParameters() as $parameter) {
$this->parameters->add($parameter);
}
}
if ($criteria->getOrderings()) {
foreach ($criteria->getOrderings() as $sort => $order) {
$hasValidAlias = false;
foreach ($allAliases as $alias) {
if (strpos($sort . '.', $alias . '.') === 0) {
$hasValidAlias = true;
break;
}
}
if (! $hasValidAlias) {
$sort = $allAliases[0] . '.' . $sort;
}
$this->addOrderBy($sort, $order);
}
}
$firstResult = $criteria->getFirstResult();
$maxResults = $criteria->getMaxResults();
// Overwrite limits only if they was set in criteria
if ($firstResult !== null) {
$this->setFirstResult($firstResult);
}
if ($maxResults !== null) {
$this->setMaxResults($maxResults);
}
return $this;
} | php | public function addCriteria(Criteria $criteria)
{
$allAliases = $this->getAllAliases();
if (! isset($allAliases[0])) {
throw new Query\QueryException('No aliases are set before invoking addCriteria().');
}
$visitor = new QueryExpressionVisitor($this->getAllAliases());
$whereExpression = $criteria->getWhereExpression();
if ($whereExpression) {
$this->andWhere($visitor->dispatch($whereExpression));
foreach ($visitor->getParameters() as $parameter) {
$this->parameters->add($parameter);
}
}
if ($criteria->getOrderings()) {
foreach ($criteria->getOrderings() as $sort => $order) {
$hasValidAlias = false;
foreach ($allAliases as $alias) {
if (strpos($sort . '.', $alias . '.') === 0) {
$hasValidAlias = true;
break;
}
}
if (! $hasValidAlias) {
$sort = $allAliases[0] . '.' . $sort;
}
$this->addOrderBy($sort, $order);
}
}
$firstResult = $criteria->getFirstResult();
$maxResults = $criteria->getMaxResults();
// Overwrite limits only if they was set in criteria
if ($firstResult !== null) {
$this->setFirstResult($firstResult);
}
if ($maxResults !== null) {
$this->setMaxResults($maxResults);
}
return $this;
} | [
"public",
"function",
"addCriteria",
"(",
"Criteria",
"$",
"criteria",
")",
"{",
"$",
"allAliases",
"=",
"$",
"this",
"->",
"getAllAliases",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"allAliases",
"[",
"0",
"]",
")",
")",
"{",
"throw",
"new",
"Query",
"\\",
"QueryException",
"(",
"'No aliases are set before invoking addCriteria().'",
")",
";",
"}",
"$",
"visitor",
"=",
"new",
"QueryExpressionVisitor",
"(",
"$",
"this",
"->",
"getAllAliases",
"(",
")",
")",
";",
"$",
"whereExpression",
"=",
"$",
"criteria",
"->",
"getWhereExpression",
"(",
")",
";",
"if",
"(",
"$",
"whereExpression",
")",
"{",
"$",
"this",
"->",
"andWhere",
"(",
"$",
"visitor",
"->",
"dispatch",
"(",
"$",
"whereExpression",
")",
")",
";",
"foreach",
"(",
"$",
"visitor",
"->",
"getParameters",
"(",
")",
"as",
"$",
"parameter",
")",
"{",
"$",
"this",
"->",
"parameters",
"->",
"add",
"(",
"$",
"parameter",
")",
";",
"}",
"}",
"if",
"(",
"$",
"criteria",
"->",
"getOrderings",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"criteria",
"->",
"getOrderings",
"(",
")",
"as",
"$",
"sort",
"=>",
"$",
"order",
")",
"{",
"$",
"hasValidAlias",
"=",
"false",
";",
"foreach",
"(",
"$",
"allAliases",
"as",
"$",
"alias",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"sort",
".",
"'.'",
",",
"$",
"alias",
".",
"'.'",
")",
"===",
"0",
")",
"{",
"$",
"hasValidAlias",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"hasValidAlias",
")",
"{",
"$",
"sort",
"=",
"$",
"allAliases",
"[",
"0",
"]",
".",
"'.'",
".",
"$",
"sort",
";",
"}",
"$",
"this",
"->",
"addOrderBy",
"(",
"$",
"sort",
",",
"$",
"order",
")",
";",
"}",
"}",
"$",
"firstResult",
"=",
"$",
"criteria",
"->",
"getFirstResult",
"(",
")",
";",
"$",
"maxResults",
"=",
"$",
"criteria",
"->",
"getMaxResults",
"(",
")",
";",
"// Overwrite limits only if they was set in criteria",
"if",
"(",
"$",
"firstResult",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"setFirstResult",
"(",
"$",
"firstResult",
")",
";",
"}",
"if",
"(",
"$",
"maxResults",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"setMaxResults",
"(",
"$",
"maxResults",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Adds criteria to the query.
Adds where expressions with AND operator.
Adds orderings.
Overrides firstResult and maxResults if they're set.
@return self
@throws Query\QueryException | [
"Adds",
"criteria",
"to",
"the",
"query",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/QueryBuilder.php#L1277-L1324 | train |
doctrine/orm | lib/Doctrine/ORM/Tools/SchemaTool.php | SchemaTool.createSchema | public function createSchema(array $classes)
{
$createSchemaSql = $this->getCreateSchemaSql($classes);
$conn = $this->em->getConnection();
foreach ($createSchemaSql as $sql) {
try {
$conn->executeQuery($sql);
} catch (Throwable $e) {
throw ToolsException::schemaToolFailure($sql, $e);
}
}
} | php | public function createSchema(array $classes)
{
$createSchemaSql = $this->getCreateSchemaSql($classes);
$conn = $this->em->getConnection();
foreach ($createSchemaSql as $sql) {
try {
$conn->executeQuery($sql);
} catch (Throwable $e) {
throw ToolsException::schemaToolFailure($sql, $e);
}
}
} | [
"public",
"function",
"createSchema",
"(",
"array",
"$",
"classes",
")",
"{",
"$",
"createSchemaSql",
"=",
"$",
"this",
"->",
"getCreateSchemaSql",
"(",
"$",
"classes",
")",
";",
"$",
"conn",
"=",
"$",
"this",
"->",
"em",
"->",
"getConnection",
"(",
")",
";",
"foreach",
"(",
"$",
"createSchemaSql",
"as",
"$",
"sql",
")",
"{",
"try",
"{",
"$",
"conn",
"->",
"executeQuery",
"(",
"$",
"sql",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"e",
")",
"{",
"throw",
"ToolsException",
"::",
"schemaToolFailure",
"(",
"$",
"sql",
",",
"$",
"e",
")",
";",
"}",
"}",
"}"
] | Creates the database schema for the given array of ClassMetadata instances.
@param ClassMetadata[] $classes
@throws ToolsException | [
"Creates",
"the",
"database",
"schema",
"for",
"the",
"given",
"array",
"of",
"ClassMetadata",
"instances",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Tools/SchemaTool.php#L71-L83 | train |
doctrine/orm | lib/Doctrine/ORM/Tools/SchemaTool.php | SchemaTool.getCreateSchemaSql | public function getCreateSchemaSql(array $classes)
{
$schema = $this->getSchemaFromMetadata($classes);
return $schema->toSql($this->platform);
} | php | public function getCreateSchemaSql(array $classes)
{
$schema = $this->getSchemaFromMetadata($classes);
return $schema->toSql($this->platform);
} | [
"public",
"function",
"getCreateSchemaSql",
"(",
"array",
"$",
"classes",
")",
"{",
"$",
"schema",
"=",
"$",
"this",
"->",
"getSchemaFromMetadata",
"(",
"$",
"classes",
")",
";",
"return",
"$",
"schema",
"->",
"toSql",
"(",
"$",
"this",
"->",
"platform",
")",
";",
"}"
] | Gets the list of DDL statements that are required to create the database schema for
the given list of ClassMetadata instances.
@param ClassMetadata[] $classes
@return string[] The SQL statements needed to create the schema for the classes. | [
"Gets",
"the",
"list",
"of",
"DDL",
"statements",
"that",
"are",
"required",
"to",
"create",
"the",
"database",
"schema",
"for",
"the",
"given",
"list",
"of",
"ClassMetadata",
"instances",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Tools/SchemaTool.php#L93-L98 | train |
doctrine/orm | lib/Doctrine/ORM/Tools/SchemaTool.php | SchemaTool.dropSchema | public function dropSchema(array $classes)
{
$dropSchemaSql = $this->getDropSchemaSQL($classes);
$conn = $this->em->getConnection();
foreach ($dropSchemaSql as $sql) {
try {
$conn->executeQuery($sql);
} catch (Throwable $e) {
// ignored
}
}
} | php | public function dropSchema(array $classes)
{
$dropSchemaSql = $this->getDropSchemaSQL($classes);
$conn = $this->em->getConnection();
foreach ($dropSchemaSql as $sql) {
try {
$conn->executeQuery($sql);
} catch (Throwable $e) {
// ignored
}
}
} | [
"public",
"function",
"dropSchema",
"(",
"array",
"$",
"classes",
")",
"{",
"$",
"dropSchemaSql",
"=",
"$",
"this",
"->",
"getDropSchemaSQL",
"(",
"$",
"classes",
")",
";",
"$",
"conn",
"=",
"$",
"this",
"->",
"em",
"->",
"getConnection",
"(",
")",
";",
"foreach",
"(",
"$",
"dropSchemaSql",
"as",
"$",
"sql",
")",
"{",
"try",
"{",
"$",
"conn",
"->",
"executeQuery",
"(",
"$",
"sql",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"e",
")",
"{",
"// ignored",
"}",
"}",
"}"
] | Drops the database schema for the given classes.
In any way when an exception is thrown it is suppressed since drop was
issued for all classes of the schema and some probably just don't exist.
@param ClassMetadata[] $classes | [
"Drops",
"the",
"database",
"schema",
"for",
"the",
"given",
"classes",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Tools/SchemaTool.php#L786-L798 | train |
doctrine/orm | lib/Doctrine/ORM/Tools/SchemaTool.php | SchemaTool.dropDatabase | public function dropDatabase()
{
$dropSchemaSql = $this->getDropDatabaseSQL();
$conn = $this->em->getConnection();
foreach ($dropSchemaSql as $sql) {
$conn->executeQuery($sql);
}
} | php | public function dropDatabase()
{
$dropSchemaSql = $this->getDropDatabaseSQL();
$conn = $this->em->getConnection();
foreach ($dropSchemaSql as $sql) {
$conn->executeQuery($sql);
}
} | [
"public",
"function",
"dropDatabase",
"(",
")",
"{",
"$",
"dropSchemaSql",
"=",
"$",
"this",
"->",
"getDropDatabaseSQL",
"(",
")",
";",
"$",
"conn",
"=",
"$",
"this",
"->",
"em",
"->",
"getConnection",
"(",
")",
";",
"foreach",
"(",
"$",
"dropSchemaSql",
"as",
"$",
"sql",
")",
"{",
"$",
"conn",
"->",
"executeQuery",
"(",
"$",
"sql",
")",
";",
"}",
"}"
] | Drops all elements in the database of the current connection. | [
"Drops",
"all",
"elements",
"in",
"the",
"database",
"of",
"the",
"current",
"connection",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Tools/SchemaTool.php#L803-L811 | train |
doctrine/orm | lib/Doctrine/ORM/Tools/SchemaTool.php | SchemaTool.getDropDatabaseSQL | public function getDropDatabaseSQL()
{
$sm = $this->em->getConnection()->getSchemaManager();
$schema = $sm->createSchema();
$visitor = new DropSchemaSqlCollector($this->platform);
$schema->visit($visitor);
return $visitor->getQueries();
} | php | public function getDropDatabaseSQL()
{
$sm = $this->em->getConnection()->getSchemaManager();
$schema = $sm->createSchema();
$visitor = new DropSchemaSqlCollector($this->platform);
$schema->visit($visitor);
return $visitor->getQueries();
} | [
"public",
"function",
"getDropDatabaseSQL",
"(",
")",
"{",
"$",
"sm",
"=",
"$",
"this",
"->",
"em",
"->",
"getConnection",
"(",
")",
"->",
"getSchemaManager",
"(",
")",
";",
"$",
"schema",
"=",
"$",
"sm",
"->",
"createSchema",
"(",
")",
";",
"$",
"visitor",
"=",
"new",
"DropSchemaSqlCollector",
"(",
"$",
"this",
"->",
"platform",
")",
";",
"$",
"schema",
"->",
"visit",
"(",
"$",
"visitor",
")",
";",
"return",
"$",
"visitor",
"->",
"getQueries",
"(",
")",
";",
"}"
] | Gets the SQL needed to drop the database schema for the connections database.
@return string[] | [
"Gets",
"the",
"SQL",
"needed",
"to",
"drop",
"the",
"database",
"schema",
"for",
"the",
"connections",
"database",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Tools/SchemaTool.php#L818-L827 | train |
doctrine/orm | lib/Doctrine/ORM/Tools/SchemaTool.php | SchemaTool.getDropSchemaSQL | public function getDropSchemaSQL(array $classes)
{
$visitor = new DropSchemaSqlCollector($this->platform);
$schema = $this->getSchemaFromMetadata($classes);
$sm = $this->em->getConnection()->getSchemaManager();
$fullSchema = $sm->createSchema();
foreach ($fullSchema->getTables() as $table) {
if (! $schema->hasTable($table->getName())) {
foreach ($table->getForeignKeys() as $foreignKey) {
/** @var $foreignKey \Doctrine\DBAL\Schema\ForeignKeyConstraint */
if ($schema->hasTable($foreignKey->getForeignTableName())) {
$visitor->acceptForeignKey($table, $foreignKey);
}
}
} else {
$visitor->acceptTable($table);
foreach ($table->getForeignKeys() as $foreignKey) {
$visitor->acceptForeignKey($table, $foreignKey);
}
}
}
if ($this->platform->supportsSequences()) {
foreach ($schema->getSequences() as $sequence) {
$visitor->acceptSequence($sequence);
}
foreach ($schema->getTables() as $table) {
/** @var $sequence Table */
if ($table->hasPrimaryKey()) {
$columns = $table->getPrimaryKey()->getColumns();
if (count($columns) === 1) {
$checkSequence = $table->getName() . '_' . $columns[0] . '_seq';
if ($fullSchema->hasSequence($checkSequence)) {
$visitor->acceptSequence($fullSchema->getSequence($checkSequence));
}
}
}
}
}
return $visitor->getQueries();
} | php | public function getDropSchemaSQL(array $classes)
{
$visitor = new DropSchemaSqlCollector($this->platform);
$schema = $this->getSchemaFromMetadata($classes);
$sm = $this->em->getConnection()->getSchemaManager();
$fullSchema = $sm->createSchema();
foreach ($fullSchema->getTables() as $table) {
if (! $schema->hasTable($table->getName())) {
foreach ($table->getForeignKeys() as $foreignKey) {
/** @var $foreignKey \Doctrine\DBAL\Schema\ForeignKeyConstraint */
if ($schema->hasTable($foreignKey->getForeignTableName())) {
$visitor->acceptForeignKey($table, $foreignKey);
}
}
} else {
$visitor->acceptTable($table);
foreach ($table->getForeignKeys() as $foreignKey) {
$visitor->acceptForeignKey($table, $foreignKey);
}
}
}
if ($this->platform->supportsSequences()) {
foreach ($schema->getSequences() as $sequence) {
$visitor->acceptSequence($sequence);
}
foreach ($schema->getTables() as $table) {
/** @var $sequence Table */
if ($table->hasPrimaryKey()) {
$columns = $table->getPrimaryKey()->getColumns();
if (count($columns) === 1) {
$checkSequence = $table->getName() . '_' . $columns[0] . '_seq';
if ($fullSchema->hasSequence($checkSequence)) {
$visitor->acceptSequence($fullSchema->getSequence($checkSequence));
}
}
}
}
}
return $visitor->getQueries();
} | [
"public",
"function",
"getDropSchemaSQL",
"(",
"array",
"$",
"classes",
")",
"{",
"$",
"visitor",
"=",
"new",
"DropSchemaSqlCollector",
"(",
"$",
"this",
"->",
"platform",
")",
";",
"$",
"schema",
"=",
"$",
"this",
"->",
"getSchemaFromMetadata",
"(",
"$",
"classes",
")",
";",
"$",
"sm",
"=",
"$",
"this",
"->",
"em",
"->",
"getConnection",
"(",
")",
"->",
"getSchemaManager",
"(",
")",
";",
"$",
"fullSchema",
"=",
"$",
"sm",
"->",
"createSchema",
"(",
")",
";",
"foreach",
"(",
"$",
"fullSchema",
"->",
"getTables",
"(",
")",
"as",
"$",
"table",
")",
"{",
"if",
"(",
"!",
"$",
"schema",
"->",
"hasTable",
"(",
"$",
"table",
"->",
"getName",
"(",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"table",
"->",
"getForeignKeys",
"(",
")",
"as",
"$",
"foreignKey",
")",
"{",
"/** @var $foreignKey \\Doctrine\\DBAL\\Schema\\ForeignKeyConstraint */",
"if",
"(",
"$",
"schema",
"->",
"hasTable",
"(",
"$",
"foreignKey",
"->",
"getForeignTableName",
"(",
")",
")",
")",
"{",
"$",
"visitor",
"->",
"acceptForeignKey",
"(",
"$",
"table",
",",
"$",
"foreignKey",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"visitor",
"->",
"acceptTable",
"(",
"$",
"table",
")",
";",
"foreach",
"(",
"$",
"table",
"->",
"getForeignKeys",
"(",
")",
"as",
"$",
"foreignKey",
")",
"{",
"$",
"visitor",
"->",
"acceptForeignKey",
"(",
"$",
"table",
",",
"$",
"foreignKey",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"platform",
"->",
"supportsSequences",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"schema",
"->",
"getSequences",
"(",
")",
"as",
"$",
"sequence",
")",
"{",
"$",
"visitor",
"->",
"acceptSequence",
"(",
"$",
"sequence",
")",
";",
"}",
"foreach",
"(",
"$",
"schema",
"->",
"getTables",
"(",
")",
"as",
"$",
"table",
")",
"{",
"/** @var $sequence Table */",
"if",
"(",
"$",
"table",
"->",
"hasPrimaryKey",
"(",
")",
")",
"{",
"$",
"columns",
"=",
"$",
"table",
"->",
"getPrimaryKey",
"(",
")",
"->",
"getColumns",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"columns",
")",
"===",
"1",
")",
"{",
"$",
"checkSequence",
"=",
"$",
"table",
"->",
"getName",
"(",
")",
".",
"'_'",
".",
"$",
"columns",
"[",
"0",
"]",
".",
"'_seq'",
";",
"if",
"(",
"$",
"fullSchema",
"->",
"hasSequence",
"(",
"$",
"checkSequence",
")",
")",
"{",
"$",
"visitor",
"->",
"acceptSequence",
"(",
"$",
"fullSchema",
"->",
"getSequence",
"(",
"$",
"checkSequence",
")",
")",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"$",
"visitor",
"->",
"getQueries",
"(",
")",
";",
"}"
] | Gets SQL to drop the tables defined by the passed classes.
@param ClassMetadata[] $classes
@return string[] | [
"Gets",
"SQL",
"to",
"drop",
"the",
"tables",
"defined",
"by",
"the",
"passed",
"classes",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Tools/SchemaTool.php#L836-L880 | train |
doctrine/orm | lib/Doctrine/ORM/Tools/SchemaTool.php | SchemaTool.updateSchema | public function updateSchema(array $classes, $saveMode = false)
{
$updateSchemaSql = $this->getUpdateSchemaSql($classes, $saveMode);
$conn = $this->em->getConnection();
foreach ($updateSchemaSql as $sql) {
$conn->executeQuery($sql);
}
} | php | public function updateSchema(array $classes, $saveMode = false)
{
$updateSchemaSql = $this->getUpdateSchemaSql($classes, $saveMode);
$conn = $this->em->getConnection();
foreach ($updateSchemaSql as $sql) {
$conn->executeQuery($sql);
}
} | [
"public",
"function",
"updateSchema",
"(",
"array",
"$",
"classes",
",",
"$",
"saveMode",
"=",
"false",
")",
"{",
"$",
"updateSchemaSql",
"=",
"$",
"this",
"->",
"getUpdateSchemaSql",
"(",
"$",
"classes",
",",
"$",
"saveMode",
")",
";",
"$",
"conn",
"=",
"$",
"this",
"->",
"em",
"->",
"getConnection",
"(",
")",
";",
"foreach",
"(",
"$",
"updateSchemaSql",
"as",
"$",
"sql",
")",
"{",
"$",
"conn",
"->",
"executeQuery",
"(",
"$",
"sql",
")",
";",
"}",
"}"
] | Updates the database schema of the given classes by comparing the ClassMetadata
instances to the current database schema that is inspected.
@param ClassMetadata[] $classes
@param bool $saveMode If TRUE, only performs a partial update
without dropping assets which are scheduled for deletion. | [
"Updates",
"the",
"database",
"schema",
"of",
"the",
"given",
"classes",
"by",
"comparing",
"the",
"ClassMetadata",
"instances",
"to",
"the",
"current",
"database",
"schema",
"that",
"is",
"inspected",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Tools/SchemaTool.php#L890-L898 | train |
doctrine/orm | lib/Doctrine/ORM/Tools/SchemaTool.php | SchemaTool.getUpdateSchemaSql | public function getUpdateSchemaSql(array $classes, $saveMode = false)
{
$sm = $this->em->getConnection()->getSchemaManager();
$fromSchema = $sm->createSchema();
$toSchema = $this->getSchemaFromMetadata($classes);
$comparator = new Comparator();
$schemaDiff = $comparator->compare($fromSchema, $toSchema);
if ($saveMode) {
return $schemaDiff->toSaveSql($this->platform);
}
return $schemaDiff->toSql($this->platform);
} | php | public function getUpdateSchemaSql(array $classes, $saveMode = false)
{
$sm = $this->em->getConnection()->getSchemaManager();
$fromSchema = $sm->createSchema();
$toSchema = $this->getSchemaFromMetadata($classes);
$comparator = new Comparator();
$schemaDiff = $comparator->compare($fromSchema, $toSchema);
if ($saveMode) {
return $schemaDiff->toSaveSql($this->platform);
}
return $schemaDiff->toSql($this->platform);
} | [
"public",
"function",
"getUpdateSchemaSql",
"(",
"array",
"$",
"classes",
",",
"$",
"saveMode",
"=",
"false",
")",
"{",
"$",
"sm",
"=",
"$",
"this",
"->",
"em",
"->",
"getConnection",
"(",
")",
"->",
"getSchemaManager",
"(",
")",
";",
"$",
"fromSchema",
"=",
"$",
"sm",
"->",
"createSchema",
"(",
")",
";",
"$",
"toSchema",
"=",
"$",
"this",
"->",
"getSchemaFromMetadata",
"(",
"$",
"classes",
")",
";",
"$",
"comparator",
"=",
"new",
"Comparator",
"(",
")",
";",
"$",
"schemaDiff",
"=",
"$",
"comparator",
"->",
"compare",
"(",
"$",
"fromSchema",
",",
"$",
"toSchema",
")",
";",
"if",
"(",
"$",
"saveMode",
")",
"{",
"return",
"$",
"schemaDiff",
"->",
"toSaveSql",
"(",
"$",
"this",
"->",
"platform",
")",
";",
"}",
"return",
"$",
"schemaDiff",
"->",
"toSql",
"(",
"$",
"this",
"->",
"platform",
")",
";",
"}"
] | Gets the sequence of SQL statements that need to be performed in order
to bring the given class mappings in-synch with the relational schema.
@param ClassMetadata[] $classes The classes to consider.
@param bool $saveMode If TRUE, only generates SQL for a partial update
that does not include SQL for dropping assets which are scheduled for deletion.
@return string[] The sequence of SQL statements. | [
"Gets",
"the",
"sequence",
"of",
"SQL",
"statements",
"that",
"need",
"to",
"be",
"performed",
"in",
"order",
"to",
"bring",
"the",
"given",
"class",
"mappings",
"in",
"-",
"synch",
"with",
"the",
"relational",
"schema",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Tools/SchemaTool.php#L910-L925 | train |
doctrine/orm | lib/Doctrine/ORM/AbstractQuery.php | AbstractQuery.setParameters | public function setParameters($parameters)
{
// BC compatibility with 2.3-
if (is_array($parameters)) {
$parameterCollection = new ArrayCollection();
foreach ($parameters as $key => $value) {
$parameterCollection->add(new Parameter($key, $value));
}
$parameters = $parameterCollection;
}
$this->parameters = $parameters;
return $this;
} | php | public function setParameters($parameters)
{
// BC compatibility with 2.3-
if (is_array($parameters)) {
$parameterCollection = new ArrayCollection();
foreach ($parameters as $key => $value) {
$parameterCollection->add(new Parameter($key, $value));
}
$parameters = $parameterCollection;
}
$this->parameters = $parameters;
return $this;
} | [
"public",
"function",
"setParameters",
"(",
"$",
"parameters",
")",
"{",
"// BC compatibility with 2.3-",
"if",
"(",
"is_array",
"(",
"$",
"parameters",
")",
")",
"{",
"$",
"parameterCollection",
"=",
"new",
"ArrayCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"parameterCollection",
"->",
"add",
"(",
"new",
"Parameter",
"(",
"$",
"key",
",",
"$",
"value",
")",
")",
";",
"}",
"$",
"parameters",
"=",
"$",
"parameterCollection",
";",
"}",
"$",
"this",
"->",
"parameters",
"=",
"$",
"parameters",
";",
"return",
"$",
"this",
";",
"}"
] | Sets a collection of query parameters.
@param ArrayCollection|array|Parameter[]|mixed[] $parameters
@return static This query instance. | [
"Sets",
"a",
"collection",
"of",
"query",
"parameters",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/AbstractQuery.php#L320-L336 | train |
doctrine/orm | lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php | DefaultRepositoryFactory.createRepository | private function createRepository(EntityManagerInterface $entityManager, $entityName)
{
/** @var ClassMetadata $metadata */
$metadata = $entityManager->getClassMetadata($entityName);
$repositoryClassName = $metadata->getCustomRepositoryClassName()
?: $entityManager->getConfiguration()->getDefaultRepositoryClassName();
return new $repositoryClassName($entityManager, $metadata);
} | php | private function createRepository(EntityManagerInterface $entityManager, $entityName)
{
/** @var ClassMetadata $metadata */
$metadata = $entityManager->getClassMetadata($entityName);
$repositoryClassName = $metadata->getCustomRepositoryClassName()
?: $entityManager->getConfiguration()->getDefaultRepositoryClassName();
return new $repositoryClassName($entityManager, $metadata);
} | [
"private",
"function",
"createRepository",
"(",
"EntityManagerInterface",
"$",
"entityManager",
",",
"$",
"entityName",
")",
"{",
"/** @var ClassMetadata $metadata */",
"$",
"metadata",
"=",
"$",
"entityManager",
"->",
"getClassMetadata",
"(",
"$",
"entityName",
")",
";",
"$",
"repositoryClassName",
"=",
"$",
"metadata",
"->",
"getCustomRepositoryClassName",
"(",
")",
"?",
":",
"$",
"entityManager",
"->",
"getConfiguration",
"(",
")",
"->",
"getDefaultRepositoryClassName",
"(",
")",
";",
"return",
"new",
"$",
"repositoryClassName",
"(",
"$",
"entityManager",
",",
"$",
"metadata",
")",
";",
"}"
] | Create a new repository instance for an entity class.
@param EntityManagerInterface $entityManager The EntityManager instance.
@param string $entityName The name of the entity.
@return ObjectRepository | [
"Create",
"a",
"new",
"repository",
"instance",
"for",
"an",
"entity",
"class",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php#L43-L51 | train |
doctrine/orm | lib/Doctrine/ORM/Internal/CommitOrderCalculator.php | CommitOrderCalculator.sort | public function sort()
{
foreach ($this->nodeList as $vertex) {
if ($vertex->state !== self::NOT_VISITED) {
continue;
}
$this->visit($vertex);
}
$sortedList = $this->sortedNodeList;
$this->nodeList = [];
$this->sortedNodeList = [];
return array_reverse($sortedList);
} | php | public function sort()
{
foreach ($this->nodeList as $vertex) {
if ($vertex->state !== self::NOT_VISITED) {
continue;
}
$this->visit($vertex);
}
$sortedList = $this->sortedNodeList;
$this->nodeList = [];
$this->sortedNodeList = [];
return array_reverse($sortedList);
} | [
"public",
"function",
"sort",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"nodeList",
"as",
"$",
"vertex",
")",
"{",
"if",
"(",
"$",
"vertex",
"->",
"state",
"!==",
"self",
"::",
"NOT_VISITED",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"visit",
"(",
"$",
"vertex",
")",
";",
"}",
"$",
"sortedList",
"=",
"$",
"this",
"->",
"sortedNodeList",
";",
"$",
"this",
"->",
"nodeList",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"sortedNodeList",
"=",
"[",
"]",
";",
"return",
"array_reverse",
"(",
"$",
"sortedList",
")",
";",
"}"
] | Return a valid order list of all current nodes.
The desired topological sorting is the reverse post order of these searches.
{@internal Highly performance-sensitive method. }}
@return object[] | [
"Return",
"a",
"valid",
"order",
"list",
"of",
"all",
"current",
"nodes",
".",
"The",
"desired",
"topological",
"sorting",
"is",
"the",
"reverse",
"post",
"order",
"of",
"these",
"searches",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php#L106-L122 | train |
doctrine/orm | lib/Doctrine/ORM/Mapping/ClassMetadata.php | ClassMetadata.validateLifecycleCallbacks | public function validateLifecycleCallbacks(ReflectionService $reflectionService) : void
{
foreach ($this->lifecycleCallbacks as $callbacks) {
/** @var array $callbacks */
foreach ($callbacks as $callbackFuncName) {
if (! $reflectionService->hasPublicMethod($this->className, $callbackFuncName)) {
throw MappingException::lifecycleCallbackMethodNotFound($this->className, $callbackFuncName);
}
}
}
} | php | public function validateLifecycleCallbacks(ReflectionService $reflectionService) : void
{
foreach ($this->lifecycleCallbacks as $callbacks) {
/** @var array $callbacks */
foreach ($callbacks as $callbackFuncName) {
if (! $reflectionService->hasPublicMethod($this->className, $callbackFuncName)) {
throw MappingException::lifecycleCallbackMethodNotFound($this->className, $callbackFuncName);
}
}
}
} | [
"public",
"function",
"validateLifecycleCallbacks",
"(",
"ReflectionService",
"$",
"reflectionService",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"this",
"->",
"lifecycleCallbacks",
"as",
"$",
"callbacks",
")",
"{",
"/** @var array $callbacks */",
"foreach",
"(",
"$",
"callbacks",
"as",
"$",
"callbackFuncName",
")",
"{",
"if",
"(",
"!",
"$",
"reflectionService",
"->",
"hasPublicMethod",
"(",
"$",
"this",
"->",
"className",
",",
"$",
"callbackFuncName",
")",
")",
"{",
"throw",
"MappingException",
"::",
"lifecycleCallbackMethodNotFound",
"(",
"$",
"this",
"->",
"className",
",",
"$",
"callbackFuncName",
")",
";",
"}",
"}",
"}",
"}"
] | Validates lifecycle callbacks.
@throws MappingException | [
"Validates",
"lifecycle",
"callbacks",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Mapping/ClassMetadata.php#L419-L429 | train |
doctrine/orm | lib/Doctrine/ORM/Mapping/ClassMetadata.php | ClassMetadata.validateAndCompleteToOneAssociationMetadata | protected function validateAndCompleteToOneAssociationMetadata(ToOneAssociationMetadata $property)
{
$fieldName = $property->getName();
if ($property->isOwningSide()) {
if (empty($property->getJoinColumns())) {
// Apply default join column
$property->addJoinColumn(new JoinColumnMetadata());
}
$uniqueConstraintColumns = [];
foreach ($property->getJoinColumns() as $joinColumn) {
/** @var JoinColumnMetadata $joinColumn */
if ($property instanceof OneToOneAssociationMetadata && $this->inheritanceType !== InheritanceType::SINGLE_TABLE) {
if (count($property->getJoinColumns()) === 1) {
if (! $property->isPrimaryKey()) {
$joinColumn->setUnique(true);
}
} else {
$uniqueConstraintColumns[] = $joinColumn->getColumnName();
}
}
$joinColumn->setTableName(! $this->isMappedSuperclass ? $this->getTableName() : null);
if (! $joinColumn->getColumnName()) {
$joinColumn->setColumnName($this->namingStrategy->joinColumnName($fieldName, $this->className));
}
if (! $joinColumn->getReferencedColumnName()) {
$joinColumn->setReferencedColumnName($this->namingStrategy->referenceColumnName());
}
$this->fieldNames[$joinColumn->getColumnName()] = $fieldName;
}
if ($uniqueConstraintColumns) {
if (! $this->table) {
throw new RuntimeException(
'ClassMetadata::setTable() has to be called before defining a one to one relationship.'
);
}
$this->table->addUniqueConstraint(
[
'name' => sprintf('%s_uniq', $fieldName),
'columns' => $uniqueConstraintColumns,
'options' => [],
'flags' => [],
]
);
}
}
if ($property->isOrphanRemoval()) {
$cascades = $property->getCascade();
if (! in_array('remove', $cascades, true)) {
$cascades[] = 'remove';
$property->setCascade($cascades);
}
// @todo guilhermeblanco where is this used?
// @todo guilhermeblanco Shouldn't we iterate through JoinColumns to set non-uniqueness?
//$property->setUnique(false);
}
if ($property->isPrimaryKey() && ! $property->isOwningSide()) {
throw MappingException::illegalInverseIdentifierAssociation($this->className, $fieldName);
}
} | php | protected function validateAndCompleteToOneAssociationMetadata(ToOneAssociationMetadata $property)
{
$fieldName = $property->getName();
if ($property->isOwningSide()) {
if (empty($property->getJoinColumns())) {
// Apply default join column
$property->addJoinColumn(new JoinColumnMetadata());
}
$uniqueConstraintColumns = [];
foreach ($property->getJoinColumns() as $joinColumn) {
/** @var JoinColumnMetadata $joinColumn */
if ($property instanceof OneToOneAssociationMetadata && $this->inheritanceType !== InheritanceType::SINGLE_TABLE) {
if (count($property->getJoinColumns()) === 1) {
if (! $property->isPrimaryKey()) {
$joinColumn->setUnique(true);
}
} else {
$uniqueConstraintColumns[] = $joinColumn->getColumnName();
}
}
$joinColumn->setTableName(! $this->isMappedSuperclass ? $this->getTableName() : null);
if (! $joinColumn->getColumnName()) {
$joinColumn->setColumnName($this->namingStrategy->joinColumnName($fieldName, $this->className));
}
if (! $joinColumn->getReferencedColumnName()) {
$joinColumn->setReferencedColumnName($this->namingStrategy->referenceColumnName());
}
$this->fieldNames[$joinColumn->getColumnName()] = $fieldName;
}
if ($uniqueConstraintColumns) {
if (! $this->table) {
throw new RuntimeException(
'ClassMetadata::setTable() has to be called before defining a one to one relationship.'
);
}
$this->table->addUniqueConstraint(
[
'name' => sprintf('%s_uniq', $fieldName),
'columns' => $uniqueConstraintColumns,
'options' => [],
'flags' => [],
]
);
}
}
if ($property->isOrphanRemoval()) {
$cascades = $property->getCascade();
if (! in_array('remove', $cascades, true)) {
$cascades[] = 'remove';
$property->setCascade($cascades);
}
// @todo guilhermeblanco where is this used?
// @todo guilhermeblanco Shouldn't we iterate through JoinColumns to set non-uniqueness?
//$property->setUnique(false);
}
if ($property->isPrimaryKey() && ! $property->isOwningSide()) {
throw MappingException::illegalInverseIdentifierAssociation($this->className, $fieldName);
}
} | [
"protected",
"function",
"validateAndCompleteToOneAssociationMetadata",
"(",
"ToOneAssociationMetadata",
"$",
"property",
")",
"{",
"$",
"fieldName",
"=",
"$",
"property",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"$",
"property",
"->",
"isOwningSide",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"property",
"->",
"getJoinColumns",
"(",
")",
")",
")",
"{",
"// Apply default join column",
"$",
"property",
"->",
"addJoinColumn",
"(",
"new",
"JoinColumnMetadata",
"(",
")",
")",
";",
"}",
"$",
"uniqueConstraintColumns",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"property",
"->",
"getJoinColumns",
"(",
")",
"as",
"$",
"joinColumn",
")",
"{",
"/** @var JoinColumnMetadata $joinColumn */",
"if",
"(",
"$",
"property",
"instanceof",
"OneToOneAssociationMetadata",
"&&",
"$",
"this",
"->",
"inheritanceType",
"!==",
"InheritanceType",
"::",
"SINGLE_TABLE",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"property",
"->",
"getJoinColumns",
"(",
")",
")",
"===",
"1",
")",
"{",
"if",
"(",
"!",
"$",
"property",
"->",
"isPrimaryKey",
"(",
")",
")",
"{",
"$",
"joinColumn",
"->",
"setUnique",
"(",
"true",
")",
";",
"}",
"}",
"else",
"{",
"$",
"uniqueConstraintColumns",
"[",
"]",
"=",
"$",
"joinColumn",
"->",
"getColumnName",
"(",
")",
";",
"}",
"}",
"$",
"joinColumn",
"->",
"setTableName",
"(",
"!",
"$",
"this",
"->",
"isMappedSuperclass",
"?",
"$",
"this",
"->",
"getTableName",
"(",
")",
":",
"null",
")",
";",
"if",
"(",
"!",
"$",
"joinColumn",
"->",
"getColumnName",
"(",
")",
")",
"{",
"$",
"joinColumn",
"->",
"setColumnName",
"(",
"$",
"this",
"->",
"namingStrategy",
"->",
"joinColumnName",
"(",
"$",
"fieldName",
",",
"$",
"this",
"->",
"className",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"joinColumn",
"->",
"getReferencedColumnName",
"(",
")",
")",
"{",
"$",
"joinColumn",
"->",
"setReferencedColumnName",
"(",
"$",
"this",
"->",
"namingStrategy",
"->",
"referenceColumnName",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"fieldNames",
"[",
"$",
"joinColumn",
"->",
"getColumnName",
"(",
")",
"]",
"=",
"$",
"fieldName",
";",
"}",
"if",
"(",
"$",
"uniqueConstraintColumns",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"table",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'ClassMetadata::setTable() has to be called before defining a one to one relationship.'",
")",
";",
"}",
"$",
"this",
"->",
"table",
"->",
"addUniqueConstraint",
"(",
"[",
"'name'",
"=>",
"sprintf",
"(",
"'%s_uniq'",
",",
"$",
"fieldName",
")",
",",
"'columns'",
"=>",
"$",
"uniqueConstraintColumns",
",",
"'options'",
"=>",
"[",
"]",
",",
"'flags'",
"=>",
"[",
"]",
",",
"]",
")",
";",
"}",
"}",
"if",
"(",
"$",
"property",
"->",
"isOrphanRemoval",
"(",
")",
")",
"{",
"$",
"cascades",
"=",
"$",
"property",
"->",
"getCascade",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"'remove'",
",",
"$",
"cascades",
",",
"true",
")",
")",
"{",
"$",
"cascades",
"[",
"]",
"=",
"'remove'",
";",
"$",
"property",
"->",
"setCascade",
"(",
"$",
"cascades",
")",
";",
"}",
"// @todo guilhermeblanco where is this used?",
"// @todo guilhermeblanco Shouldn't we iterate through JoinColumns to set non-uniqueness?",
"//$property->setUnique(false);",
"}",
"if",
"(",
"$",
"property",
"->",
"isPrimaryKey",
"(",
")",
"&&",
"!",
"$",
"property",
"->",
"isOwningSide",
"(",
")",
")",
"{",
"throw",
"MappingException",
"::",
"illegalInverseIdentifierAssociation",
"(",
"$",
"this",
"->",
"className",
",",
"$",
"fieldName",
")",
";",
"}",
"}"
] | Validates & completes a to-one association mapping.
@param ToOneAssociationMetadata $property The association mapping to validate & complete.
@throws RuntimeException
@throws MappingException | [
"Validates",
"&",
"completes",
"a",
"to",
"-",
"one",
"association",
"mapping",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Mapping/ClassMetadata.php#L609-L681 | train |
doctrine/orm | lib/Doctrine/ORM/Mapping/ClassMetadata.php | ClassMetadata.validateAndCompleteManyToOneMapping | protected function validateAndCompleteManyToOneMapping(ManyToOneAssociationMetadata $property)
{
// A many-to-one mapping is essentially a one-one backreference
if ($property->isOrphanRemoval()) {
throw MappingException::illegalOrphanRemoval($this->className, $property->getName());
}
} | php | protected function validateAndCompleteManyToOneMapping(ManyToOneAssociationMetadata $property)
{
// A many-to-one mapping is essentially a one-one backreference
if ($property->isOrphanRemoval()) {
throw MappingException::illegalOrphanRemoval($this->className, $property->getName());
}
} | [
"protected",
"function",
"validateAndCompleteManyToOneMapping",
"(",
"ManyToOneAssociationMetadata",
"$",
"property",
")",
"{",
"// A many-to-one mapping is essentially a one-one backreference",
"if",
"(",
"$",
"property",
"->",
"isOrphanRemoval",
"(",
")",
")",
"{",
"throw",
"MappingException",
"::",
"illegalOrphanRemoval",
"(",
"$",
"this",
"->",
"className",
",",
"$",
"property",
"->",
"getName",
"(",
")",
")",
";",
"}",
"}"
] | Validates & completes a many-to-one association mapping.
@param ManyToOneAssociationMetadata $property The association mapping to validate & complete.
@throws MappingException | [
"Validates",
"&",
"completes",
"a",
"many",
"-",
"to",
"-",
"one",
"association",
"mapping",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Mapping/ClassMetadata.php#L712-L718 | train |
doctrine/orm | lib/Doctrine/ORM/Mapping/ClassMetadata.php | ClassMetadata.getSingleIdentifierFieldName | public function getSingleIdentifierFieldName()
{
if ($this->isIdentifierComposite()) {
throw MappingException::singleIdNotAllowedOnCompositePrimaryKey($this->className);
}
if (! isset($this->identifier[0])) {
throw MappingException::noIdDefined($this->className);
}
return $this->identifier[0];
} | php | public function getSingleIdentifierFieldName()
{
if ($this->isIdentifierComposite()) {
throw MappingException::singleIdNotAllowedOnCompositePrimaryKey($this->className);
}
if (! isset($this->identifier[0])) {
throw MappingException::noIdDefined($this->className);
}
return $this->identifier[0];
} | [
"public",
"function",
"getSingleIdentifierFieldName",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isIdentifierComposite",
"(",
")",
")",
"{",
"throw",
"MappingException",
"::",
"singleIdNotAllowedOnCompositePrimaryKey",
"(",
"$",
"this",
"->",
"className",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"identifier",
"[",
"0",
"]",
")",
")",
"{",
"throw",
"MappingException",
"::",
"noIdDefined",
"(",
"$",
"this",
"->",
"className",
")",
";",
"}",
"return",
"$",
"this",
"->",
"identifier",
"[",
"0",
"]",
";",
"}"
] | Gets the name of the single id field. Note that this only works on
entity classes that have a single-field pk.
@return string
@throws MappingException If the class has a composite primary key. | [
"Gets",
"the",
"name",
"of",
"the",
"single",
"id",
"field",
".",
"Note",
"that",
"this",
"only",
"works",
"on",
"entity",
"classes",
"that",
"have",
"a",
"single",
"-",
"field",
"pk",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Mapping/ClassMetadata.php#L852-L863 | train |
doctrine/orm | lib/Doctrine/ORM/Mapping/ClassMetadata.php | ClassMetadata.getIdentifierColumns | public function getIdentifierColumns(EntityManagerInterface $em) : array
{
$columns = [];
foreach ($this->identifier as $idProperty) {
$property = $this->getProperty($idProperty);
if ($property instanceof FieldMetadata) {
$columns[$property->getColumnName()] = $property;
continue;
}
/** @var AssociationMetadata $property */
// Association defined as Id field
$targetClass = $em->getClassMetadata($property->getTargetEntity());
if (! $property->isOwningSide()) {
$property = $targetClass->getProperty($property->getMappedBy());
$targetClass = $em->getClassMetadata($property->getTargetEntity());
}
$joinColumns = $property instanceof ManyToManyAssociationMetadata
? $property->getJoinTable()->getInverseJoinColumns()
: $property->getJoinColumns();
foreach ($joinColumns as $joinColumn) {
/** @var JoinColumnMetadata $joinColumn */
$columnName = $joinColumn->getColumnName();
$referencedColumnName = $joinColumn->getReferencedColumnName();
if (! $joinColumn->getType()) {
$joinColumn->setType(PersisterHelper::getTypeOfColumn($referencedColumnName, $targetClass, $em));
}
$columns[$columnName] = $joinColumn;
}
}
return $columns;
} | php | public function getIdentifierColumns(EntityManagerInterface $em) : array
{
$columns = [];
foreach ($this->identifier as $idProperty) {
$property = $this->getProperty($idProperty);
if ($property instanceof FieldMetadata) {
$columns[$property->getColumnName()] = $property;
continue;
}
/** @var AssociationMetadata $property */
// Association defined as Id field
$targetClass = $em->getClassMetadata($property->getTargetEntity());
if (! $property->isOwningSide()) {
$property = $targetClass->getProperty($property->getMappedBy());
$targetClass = $em->getClassMetadata($property->getTargetEntity());
}
$joinColumns = $property instanceof ManyToManyAssociationMetadata
? $property->getJoinTable()->getInverseJoinColumns()
: $property->getJoinColumns();
foreach ($joinColumns as $joinColumn) {
/** @var JoinColumnMetadata $joinColumn */
$columnName = $joinColumn->getColumnName();
$referencedColumnName = $joinColumn->getReferencedColumnName();
if (! $joinColumn->getType()) {
$joinColumn->setType(PersisterHelper::getTypeOfColumn($referencedColumnName, $targetClass, $em));
}
$columns[$columnName] = $joinColumn;
}
}
return $columns;
} | [
"public",
"function",
"getIdentifierColumns",
"(",
"EntityManagerInterface",
"$",
"em",
")",
":",
"array",
"{",
"$",
"columns",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"identifier",
"as",
"$",
"idProperty",
")",
"{",
"$",
"property",
"=",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"idProperty",
")",
";",
"if",
"(",
"$",
"property",
"instanceof",
"FieldMetadata",
")",
"{",
"$",
"columns",
"[",
"$",
"property",
"->",
"getColumnName",
"(",
")",
"]",
"=",
"$",
"property",
";",
"continue",
";",
"}",
"/** @var AssociationMetadata $property */",
"// Association defined as Id field",
"$",
"targetClass",
"=",
"$",
"em",
"->",
"getClassMetadata",
"(",
"$",
"property",
"->",
"getTargetEntity",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"property",
"->",
"isOwningSide",
"(",
")",
")",
"{",
"$",
"property",
"=",
"$",
"targetClass",
"->",
"getProperty",
"(",
"$",
"property",
"->",
"getMappedBy",
"(",
")",
")",
";",
"$",
"targetClass",
"=",
"$",
"em",
"->",
"getClassMetadata",
"(",
"$",
"property",
"->",
"getTargetEntity",
"(",
")",
")",
";",
"}",
"$",
"joinColumns",
"=",
"$",
"property",
"instanceof",
"ManyToManyAssociationMetadata",
"?",
"$",
"property",
"->",
"getJoinTable",
"(",
")",
"->",
"getInverseJoinColumns",
"(",
")",
":",
"$",
"property",
"->",
"getJoinColumns",
"(",
")",
";",
"foreach",
"(",
"$",
"joinColumns",
"as",
"$",
"joinColumn",
")",
"{",
"/** @var JoinColumnMetadata $joinColumn */",
"$",
"columnName",
"=",
"$",
"joinColumn",
"->",
"getColumnName",
"(",
")",
";",
"$",
"referencedColumnName",
"=",
"$",
"joinColumn",
"->",
"getReferencedColumnName",
"(",
")",
";",
"if",
"(",
"!",
"$",
"joinColumn",
"->",
"getType",
"(",
")",
")",
"{",
"$",
"joinColumn",
"->",
"setType",
"(",
"PersisterHelper",
"::",
"getTypeOfColumn",
"(",
"$",
"referencedColumnName",
",",
"$",
"targetClass",
",",
"$",
"em",
")",
")",
";",
"}",
"$",
"columns",
"[",
"$",
"columnName",
"]",
"=",
"$",
"joinColumn",
";",
"}",
"}",
"return",
"$",
"columns",
";",
"}"
] | Returns an array with identifier column names and their corresponding ColumnMetadata.
@return ColumnMetadata[] | [
"Returns",
"an",
"array",
"with",
"identifier",
"column",
"names",
"and",
"their",
"corresponding",
"ColumnMetadata",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Mapping/ClassMetadata.php#L899-L940 | train |
doctrine/orm | lib/Doctrine/ORM/Mapping/ClassMetadata.php | ClassMetadata.getTemporaryIdTableName | public function getTemporaryIdTableName() : string
{
$schema = $this->getSchemaName() === null
? ''
: $this->getSchemaName() . '_';
// replace dots with underscores because PostgreSQL creates temporary tables in a special schema
return $schema . $this->getTableName() . '_id_tmp';
} | php | public function getTemporaryIdTableName() : string
{
$schema = $this->getSchemaName() === null
? ''
: $this->getSchemaName() . '_';
// replace dots with underscores because PostgreSQL creates temporary tables in a special schema
return $schema . $this->getTableName() . '_id_tmp';
} | [
"public",
"function",
"getTemporaryIdTableName",
"(",
")",
":",
"string",
"{",
"$",
"schema",
"=",
"$",
"this",
"->",
"getSchemaName",
"(",
")",
"===",
"null",
"?",
"''",
":",
"$",
"this",
"->",
"getSchemaName",
"(",
")",
".",
"'_'",
";",
"// replace dots with underscores because PostgreSQL creates temporary tables in a special schema",
"return",
"$",
"schema",
".",
"$",
"this",
"->",
"getTableName",
"(",
")",
".",
"'_id_tmp'",
";",
"}"
] | Gets the table name to use for temporary identifier tables of this class. | [
"Gets",
"the",
"table",
"name",
"to",
"use",
"for",
"temporary",
"identifier",
"tables",
"of",
"this",
"class",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Mapping/ClassMetadata.php#L961-L969 | train |
doctrine/orm | lib/Doctrine/ORM/Mapping/ClassMetadata.php | ClassMetadata.setPropertyOverride | public function setPropertyOverride(Property $property) : void
{
$fieldName = $property->getName();
if (! isset($this->declaredProperties[$fieldName])) {
throw MappingException::invalidOverrideFieldName($this->className, $fieldName);
}
$originalProperty = $this->getProperty($fieldName);
$originalPropertyClassName = get_class($originalProperty);
// If moving from transient to persistent, assume it's a new property
if ($originalPropertyClassName === TransientMetadata::class) {
unset($this->declaredProperties[$fieldName]);
$this->addProperty($property);
return;
}
// Do not allow to change property type
if ($originalPropertyClassName !== get_class($property)) {
throw MappingException::invalidOverridePropertyType($this->className, $fieldName);
}
// Do not allow to change version property
if ($originalProperty instanceof VersionFieldMetadata) {
throw MappingException::invalidOverrideVersionField($this->className, $fieldName);
}
unset($this->declaredProperties[$fieldName]);
if ($property instanceof FieldMetadata) {
// Unset defined fieldName prior to override
unset($this->fieldNames[$originalProperty->getColumnName()]);
// Revert what should not be allowed to change
$property->setDeclaringClass($originalProperty->getDeclaringClass());
$property->setPrimaryKey($originalProperty->isPrimaryKey());
} elseif ($property instanceof AssociationMetadata) {
// Unset all defined fieldNames prior to override
if ($originalProperty instanceof ToOneAssociationMetadata && $originalProperty->isOwningSide()) {
foreach ($originalProperty->getJoinColumns() as $joinColumn) {
unset($this->fieldNames[$joinColumn->getColumnName()]);
}
}
// Override what it should be allowed to change
if ($property->getInversedBy()) {
$originalProperty->setInversedBy($property->getInversedBy());
}
if ($property->getFetchMode() !== $originalProperty->getFetchMode()) {
$originalProperty->setFetchMode($property->getFetchMode());
}
if ($originalProperty instanceof ToOneAssociationMetadata && $property->getJoinColumns()) {
$originalProperty->setJoinColumns($property->getJoinColumns());
} elseif ($originalProperty instanceof ManyToManyAssociationMetadata && $property->getJoinTable()) {
$originalProperty->setJoinTable($property->getJoinTable());
}
$property = $originalProperty;
}
$this->addProperty($property);
} | php | public function setPropertyOverride(Property $property) : void
{
$fieldName = $property->getName();
if (! isset($this->declaredProperties[$fieldName])) {
throw MappingException::invalidOverrideFieldName($this->className, $fieldName);
}
$originalProperty = $this->getProperty($fieldName);
$originalPropertyClassName = get_class($originalProperty);
// If moving from transient to persistent, assume it's a new property
if ($originalPropertyClassName === TransientMetadata::class) {
unset($this->declaredProperties[$fieldName]);
$this->addProperty($property);
return;
}
// Do not allow to change property type
if ($originalPropertyClassName !== get_class($property)) {
throw MappingException::invalidOverridePropertyType($this->className, $fieldName);
}
// Do not allow to change version property
if ($originalProperty instanceof VersionFieldMetadata) {
throw MappingException::invalidOverrideVersionField($this->className, $fieldName);
}
unset($this->declaredProperties[$fieldName]);
if ($property instanceof FieldMetadata) {
// Unset defined fieldName prior to override
unset($this->fieldNames[$originalProperty->getColumnName()]);
// Revert what should not be allowed to change
$property->setDeclaringClass($originalProperty->getDeclaringClass());
$property->setPrimaryKey($originalProperty->isPrimaryKey());
} elseif ($property instanceof AssociationMetadata) {
// Unset all defined fieldNames prior to override
if ($originalProperty instanceof ToOneAssociationMetadata && $originalProperty->isOwningSide()) {
foreach ($originalProperty->getJoinColumns() as $joinColumn) {
unset($this->fieldNames[$joinColumn->getColumnName()]);
}
}
// Override what it should be allowed to change
if ($property->getInversedBy()) {
$originalProperty->setInversedBy($property->getInversedBy());
}
if ($property->getFetchMode() !== $originalProperty->getFetchMode()) {
$originalProperty->setFetchMode($property->getFetchMode());
}
if ($originalProperty instanceof ToOneAssociationMetadata && $property->getJoinColumns()) {
$originalProperty->setJoinColumns($property->getJoinColumns());
} elseif ($originalProperty instanceof ManyToManyAssociationMetadata && $property->getJoinTable()) {
$originalProperty->setJoinTable($property->getJoinTable());
}
$property = $originalProperty;
}
$this->addProperty($property);
} | [
"public",
"function",
"setPropertyOverride",
"(",
"Property",
"$",
"property",
")",
":",
"void",
"{",
"$",
"fieldName",
"=",
"$",
"property",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"declaredProperties",
"[",
"$",
"fieldName",
"]",
")",
")",
"{",
"throw",
"MappingException",
"::",
"invalidOverrideFieldName",
"(",
"$",
"this",
"->",
"className",
",",
"$",
"fieldName",
")",
";",
"}",
"$",
"originalProperty",
"=",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"fieldName",
")",
";",
"$",
"originalPropertyClassName",
"=",
"get_class",
"(",
"$",
"originalProperty",
")",
";",
"// If moving from transient to persistent, assume it's a new property",
"if",
"(",
"$",
"originalPropertyClassName",
"===",
"TransientMetadata",
"::",
"class",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"declaredProperties",
"[",
"$",
"fieldName",
"]",
")",
";",
"$",
"this",
"->",
"addProperty",
"(",
"$",
"property",
")",
";",
"return",
";",
"}",
"// Do not allow to change property type",
"if",
"(",
"$",
"originalPropertyClassName",
"!==",
"get_class",
"(",
"$",
"property",
")",
")",
"{",
"throw",
"MappingException",
"::",
"invalidOverridePropertyType",
"(",
"$",
"this",
"->",
"className",
",",
"$",
"fieldName",
")",
";",
"}",
"// Do not allow to change version property",
"if",
"(",
"$",
"originalProperty",
"instanceof",
"VersionFieldMetadata",
")",
"{",
"throw",
"MappingException",
"::",
"invalidOverrideVersionField",
"(",
"$",
"this",
"->",
"className",
",",
"$",
"fieldName",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"declaredProperties",
"[",
"$",
"fieldName",
"]",
")",
";",
"if",
"(",
"$",
"property",
"instanceof",
"FieldMetadata",
")",
"{",
"// Unset defined fieldName prior to override",
"unset",
"(",
"$",
"this",
"->",
"fieldNames",
"[",
"$",
"originalProperty",
"->",
"getColumnName",
"(",
")",
"]",
")",
";",
"// Revert what should not be allowed to change",
"$",
"property",
"->",
"setDeclaringClass",
"(",
"$",
"originalProperty",
"->",
"getDeclaringClass",
"(",
")",
")",
";",
"$",
"property",
"->",
"setPrimaryKey",
"(",
"$",
"originalProperty",
"->",
"isPrimaryKey",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"property",
"instanceof",
"AssociationMetadata",
")",
"{",
"// Unset all defined fieldNames prior to override",
"if",
"(",
"$",
"originalProperty",
"instanceof",
"ToOneAssociationMetadata",
"&&",
"$",
"originalProperty",
"->",
"isOwningSide",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"originalProperty",
"->",
"getJoinColumns",
"(",
")",
"as",
"$",
"joinColumn",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"fieldNames",
"[",
"$",
"joinColumn",
"->",
"getColumnName",
"(",
")",
"]",
")",
";",
"}",
"}",
"// Override what it should be allowed to change",
"if",
"(",
"$",
"property",
"->",
"getInversedBy",
"(",
")",
")",
"{",
"$",
"originalProperty",
"->",
"setInversedBy",
"(",
"$",
"property",
"->",
"getInversedBy",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"property",
"->",
"getFetchMode",
"(",
")",
"!==",
"$",
"originalProperty",
"->",
"getFetchMode",
"(",
")",
")",
"{",
"$",
"originalProperty",
"->",
"setFetchMode",
"(",
"$",
"property",
"->",
"getFetchMode",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"originalProperty",
"instanceof",
"ToOneAssociationMetadata",
"&&",
"$",
"property",
"->",
"getJoinColumns",
"(",
")",
")",
"{",
"$",
"originalProperty",
"->",
"setJoinColumns",
"(",
"$",
"property",
"->",
"getJoinColumns",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"originalProperty",
"instanceof",
"ManyToManyAssociationMetadata",
"&&",
"$",
"property",
"->",
"getJoinTable",
"(",
")",
")",
"{",
"$",
"originalProperty",
"->",
"setJoinTable",
"(",
"$",
"property",
"->",
"getJoinTable",
"(",
")",
")",
";",
"}",
"$",
"property",
"=",
"$",
"originalProperty",
";",
"}",
"$",
"this",
"->",
"addProperty",
"(",
"$",
"property",
")",
";",
"}"
] | Sets the override property mapping for an entity relationship.
@throws RuntimeException
@throws MappingException
@throws CacheException | [
"Sets",
"the",
"override",
"property",
"mapping",
"for",
"an",
"entity",
"relationship",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Mapping/ClassMetadata.php#L1016-L1082 | train |
doctrine/orm | lib/Doctrine/ORM/Mapping/ClassMetadata.php | ClassMetadata.isInheritedProperty | public function isInheritedProperty($fieldName)
{
$declaringClass = $this->declaredProperties[$fieldName]->getDeclaringClass();
return $declaringClass->className !== $this->className;
} | php | public function isInheritedProperty($fieldName)
{
$declaringClass = $this->declaredProperties[$fieldName]->getDeclaringClass();
return $declaringClass->className !== $this->className;
} | [
"public",
"function",
"isInheritedProperty",
"(",
"$",
"fieldName",
")",
"{",
"$",
"declaringClass",
"=",
"$",
"this",
"->",
"declaredProperties",
"[",
"$",
"fieldName",
"]",
"->",
"getDeclaringClass",
"(",
")",
";",
"return",
"$",
"declaringClass",
"->",
"className",
"!==",
"$",
"this",
"->",
"className",
";",
"}"
] | Checks whether a mapped field is inherited from a superclass.
@param string $fieldName
@return bool TRUE if the field is inherited, FALSE otherwise. | [
"Checks",
"whether",
"a",
"mapped",
"field",
"is",
"inherited",
"from",
"a",
"superclass",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Mapping/ClassMetadata.php#L1101-L1106 | train |
doctrine/orm | lib/Doctrine/ORM/Mapping/ClassMetadata.php | ClassMetadata.addProperty | public function addProperty(Property $property)
{
$fieldName = $property->getName();
// Check for empty field name
if (empty($fieldName)) {
throw MappingException::missingFieldName($this->className);
}
$property->setDeclaringClass($this);
switch (true) {
case $property instanceof VersionFieldMetadata:
$this->validateAndCompleteFieldMapping($property);
$this->validateAndCompleteVersionFieldMapping($property);
break;
case $property instanceof FieldMetadata:
$this->validateAndCompleteFieldMapping($property);
break;
case $property instanceof OneToOneAssociationMetadata:
$this->validateAndCompleteAssociationMapping($property);
$this->validateAndCompleteToOneAssociationMetadata($property);
$this->validateAndCompleteOneToOneMapping($property);
break;
case $property instanceof OneToManyAssociationMetadata:
$this->validateAndCompleteAssociationMapping($property);
$this->validateAndCompleteToManyAssociationMetadata($property);
$this->validateAndCompleteOneToManyMapping($property);
break;
case $property instanceof ManyToOneAssociationMetadata:
$this->validateAndCompleteAssociationMapping($property);
$this->validateAndCompleteToOneAssociationMetadata($property);
$this->validateAndCompleteManyToOneMapping($property);
break;
case $property instanceof ManyToManyAssociationMetadata:
$this->validateAndCompleteAssociationMapping($property);
$this->validateAndCompleteToManyAssociationMetadata($property);
$this->validateAndCompleteManyToManyMapping($property);
break;
default:
// Transient properties are ignored on purpose here! =)
break;
}
$this->addDeclaredProperty($property);
} | php | public function addProperty(Property $property)
{
$fieldName = $property->getName();
// Check for empty field name
if (empty($fieldName)) {
throw MappingException::missingFieldName($this->className);
}
$property->setDeclaringClass($this);
switch (true) {
case $property instanceof VersionFieldMetadata:
$this->validateAndCompleteFieldMapping($property);
$this->validateAndCompleteVersionFieldMapping($property);
break;
case $property instanceof FieldMetadata:
$this->validateAndCompleteFieldMapping($property);
break;
case $property instanceof OneToOneAssociationMetadata:
$this->validateAndCompleteAssociationMapping($property);
$this->validateAndCompleteToOneAssociationMetadata($property);
$this->validateAndCompleteOneToOneMapping($property);
break;
case $property instanceof OneToManyAssociationMetadata:
$this->validateAndCompleteAssociationMapping($property);
$this->validateAndCompleteToManyAssociationMetadata($property);
$this->validateAndCompleteOneToManyMapping($property);
break;
case $property instanceof ManyToOneAssociationMetadata:
$this->validateAndCompleteAssociationMapping($property);
$this->validateAndCompleteToOneAssociationMetadata($property);
$this->validateAndCompleteManyToOneMapping($property);
break;
case $property instanceof ManyToManyAssociationMetadata:
$this->validateAndCompleteAssociationMapping($property);
$this->validateAndCompleteToManyAssociationMetadata($property);
$this->validateAndCompleteManyToManyMapping($property);
break;
default:
// Transient properties are ignored on purpose here! =)
break;
}
$this->addDeclaredProperty($property);
} | [
"public",
"function",
"addProperty",
"(",
"Property",
"$",
"property",
")",
"{",
"$",
"fieldName",
"=",
"$",
"property",
"->",
"getName",
"(",
")",
";",
"// Check for empty field name",
"if",
"(",
"empty",
"(",
"$",
"fieldName",
")",
")",
"{",
"throw",
"MappingException",
"::",
"missingFieldName",
"(",
"$",
"this",
"->",
"className",
")",
";",
"}",
"$",
"property",
"->",
"setDeclaringClass",
"(",
"$",
"this",
")",
";",
"switch",
"(",
"true",
")",
"{",
"case",
"$",
"property",
"instanceof",
"VersionFieldMetadata",
":",
"$",
"this",
"->",
"validateAndCompleteFieldMapping",
"(",
"$",
"property",
")",
";",
"$",
"this",
"->",
"validateAndCompleteVersionFieldMapping",
"(",
"$",
"property",
")",
";",
"break",
";",
"case",
"$",
"property",
"instanceof",
"FieldMetadata",
":",
"$",
"this",
"->",
"validateAndCompleteFieldMapping",
"(",
"$",
"property",
")",
";",
"break",
";",
"case",
"$",
"property",
"instanceof",
"OneToOneAssociationMetadata",
":",
"$",
"this",
"->",
"validateAndCompleteAssociationMapping",
"(",
"$",
"property",
")",
";",
"$",
"this",
"->",
"validateAndCompleteToOneAssociationMetadata",
"(",
"$",
"property",
")",
";",
"$",
"this",
"->",
"validateAndCompleteOneToOneMapping",
"(",
"$",
"property",
")",
";",
"break",
";",
"case",
"$",
"property",
"instanceof",
"OneToManyAssociationMetadata",
":",
"$",
"this",
"->",
"validateAndCompleteAssociationMapping",
"(",
"$",
"property",
")",
";",
"$",
"this",
"->",
"validateAndCompleteToManyAssociationMetadata",
"(",
"$",
"property",
")",
";",
"$",
"this",
"->",
"validateAndCompleteOneToManyMapping",
"(",
"$",
"property",
")",
";",
"break",
";",
"case",
"$",
"property",
"instanceof",
"ManyToOneAssociationMetadata",
":",
"$",
"this",
"->",
"validateAndCompleteAssociationMapping",
"(",
"$",
"property",
")",
";",
"$",
"this",
"->",
"validateAndCompleteToOneAssociationMetadata",
"(",
"$",
"property",
")",
";",
"$",
"this",
"->",
"validateAndCompleteManyToOneMapping",
"(",
"$",
"property",
")",
";",
"break",
";",
"case",
"$",
"property",
"instanceof",
"ManyToManyAssociationMetadata",
":",
"$",
"this",
"->",
"validateAndCompleteAssociationMapping",
"(",
"$",
"property",
")",
";",
"$",
"this",
"->",
"validateAndCompleteToManyAssociationMetadata",
"(",
"$",
"property",
")",
";",
"$",
"this",
"->",
"validateAndCompleteManyToManyMapping",
"(",
"$",
"property",
")",
";",
"break",
";",
"default",
":",
"// Transient properties are ignored on purpose here! =)",
"break",
";",
"}",
"$",
"this",
"->",
"addDeclaredProperty",
"(",
"$",
"property",
")",
";",
"}"
] | Add a property mapping.
@throws RuntimeException
@throws MappingException
@throws CacheException | [
"Add",
"a",
"property",
"mapping",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Mapping/ClassMetadata.php#L1153-L1204 | train |
doctrine/orm | lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php | ArrayHydrator.updateResultPointer | private function updateResultPointer(array &$coll, $index, $dqlAlias, $oneToOne)
{
if ($coll === null) {
unset($this->resultPointers[$dqlAlias]); // Ticket #1228
return;
}
if ($oneToOne) {
$this->resultPointers[$dqlAlias] =& $coll;
return;
}
if ($index !== false) {
$this->resultPointers[$dqlAlias] =& $coll[$index];
return;
}
if (! $coll) {
return;
}
end($coll);
$this->resultPointers[$dqlAlias] =& $coll[key($coll)];
} | php | private function updateResultPointer(array &$coll, $index, $dqlAlias, $oneToOne)
{
if ($coll === null) {
unset($this->resultPointers[$dqlAlias]); // Ticket #1228
return;
}
if ($oneToOne) {
$this->resultPointers[$dqlAlias] =& $coll;
return;
}
if ($index !== false) {
$this->resultPointers[$dqlAlias] =& $coll[$index];
return;
}
if (! $coll) {
return;
}
end($coll);
$this->resultPointers[$dqlAlias] =& $coll[key($coll)];
} | [
"private",
"function",
"updateResultPointer",
"(",
"array",
"&",
"$",
"coll",
",",
"$",
"index",
",",
"$",
"dqlAlias",
",",
"$",
"oneToOne",
")",
"{",
"if",
"(",
"$",
"coll",
"===",
"null",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"resultPointers",
"[",
"$",
"dqlAlias",
"]",
")",
";",
"// Ticket #1228",
"return",
";",
"}",
"if",
"(",
"$",
"oneToOne",
")",
"{",
"$",
"this",
"->",
"resultPointers",
"[",
"$",
"dqlAlias",
"]",
"=",
"&",
"$",
"coll",
";",
"return",
";",
"}",
"if",
"(",
"$",
"index",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"resultPointers",
"[",
"$",
"dqlAlias",
"]",
"=",
"&",
"$",
"coll",
"[",
"$",
"index",
"]",
";",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"coll",
")",
"{",
"return",
";",
"}",
"end",
"(",
"$",
"coll",
")",
";",
"$",
"this",
"->",
"resultPointers",
"[",
"$",
"dqlAlias",
"]",
"=",
"&",
"$",
"coll",
"[",
"key",
"(",
"$",
"coll",
")",
"]",
";",
"}"
] | Updates the result pointer for an Entity. The result pointers point to the
last seen instance of each Entity type. This is used for graph construction.
@param mixed[] $coll The element.
@param bool|int $index Index of the element in the collection.
@param string $dqlAlias
@param bool $oneToOne Whether it is a single-valued association or not. | [
"Updates",
"the",
"result",
"pointer",
"for",
"an",
"Entity",
".",
"The",
"result",
"pointers",
"point",
"to",
"the",
"last",
"seen",
"instance",
"of",
"each",
"Entity",
"type",
".",
"This",
"is",
"used",
"for",
"graph",
"construction",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php#L253-L279 | train |
doctrine/orm | lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php | LimitSubqueryOutputWalker.platformSupportsRowNumber | private function platformSupportsRowNumber()
{
return $this->platform instanceof PostgreSqlPlatform
|| $this->platform instanceof SQLServerPlatform
|| $this->platform instanceof OraclePlatform
|| $this->platform instanceof SQLAnywherePlatform
|| $this->platform instanceof DB2Platform
|| (method_exists($this->platform, 'supportsRowNumberFunction')
&& $this->platform->supportsRowNumberFunction());
} | php | private function platformSupportsRowNumber()
{
return $this->platform instanceof PostgreSqlPlatform
|| $this->platform instanceof SQLServerPlatform
|| $this->platform instanceof OraclePlatform
|| $this->platform instanceof SQLAnywherePlatform
|| $this->platform instanceof DB2Platform
|| (method_exists($this->platform, 'supportsRowNumberFunction')
&& $this->platform->supportsRowNumberFunction());
} | [
"private",
"function",
"platformSupportsRowNumber",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"platform",
"instanceof",
"PostgreSqlPlatform",
"||",
"$",
"this",
"->",
"platform",
"instanceof",
"SQLServerPlatform",
"||",
"$",
"this",
"->",
"platform",
"instanceof",
"OraclePlatform",
"||",
"$",
"this",
"->",
"platform",
"instanceof",
"SQLAnywherePlatform",
"||",
"$",
"this",
"->",
"platform",
"instanceof",
"DB2Platform",
"||",
"(",
"method_exists",
"(",
"$",
"this",
"->",
"platform",
",",
"'supportsRowNumberFunction'",
")",
"&&",
"$",
"this",
"->",
"platform",
"->",
"supportsRowNumberFunction",
"(",
")",
")",
";",
"}"
] | Check if the platform supports the ROW_NUMBER window function.
@return bool | [
"Check",
"if",
"the",
"platform",
"supports",
"the",
"ROW_NUMBER",
"window",
"function",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php#L116-L125 | train |
doctrine/orm | lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php | LimitSubqueryOutputWalker.walkSelectStatement | public function walkSelectStatement(SelectStatement $AST)
{
if ($this->platformSupportsRowNumber()) {
return $this->walkSelectStatementWithRowNumber($AST);
}
return $this->walkSelectStatementWithoutRowNumber($AST);
} | php | public function walkSelectStatement(SelectStatement $AST)
{
if ($this->platformSupportsRowNumber()) {
return $this->walkSelectStatementWithRowNumber($AST);
}
return $this->walkSelectStatementWithoutRowNumber($AST);
} | [
"public",
"function",
"walkSelectStatement",
"(",
"SelectStatement",
"$",
"AST",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"platformSupportsRowNumber",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"walkSelectStatementWithRowNumber",
"(",
"$",
"AST",
")",
";",
"}",
"return",
"$",
"this",
"->",
"walkSelectStatementWithoutRowNumber",
"(",
"$",
"AST",
")",
";",
"}"
] | Walks down a SelectStatement AST node, wrapping it in a SELECT DISTINCT.
@return string
@throws RuntimeException | [
"Walks",
"down",
"a",
"SelectStatement",
"AST",
"node",
"wrapping",
"it",
"in",
"a",
"SELECT",
"DISTINCT",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php#L163-L170 | train |
doctrine/orm | lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php | LimitSubqueryOutputWalker.walkSelectStatementWithoutRowNumber | public function walkSelectStatementWithoutRowNumber(SelectStatement $AST, $addMissingItemsFromOrderByToSelect = true)
{
// We don't want to call this recursively!
if ($AST->orderByClause instanceof OrderByClause && $addMissingItemsFromOrderByToSelect) {
// In the case of ordering a query by columns from joined tables, we
// must add those columns to the select clause of the query BEFORE
// the SQL is generated.
$this->addMissingItemsFromOrderByToSelect($AST);
}
// Remove order by clause from the inner query
// It will be re-appended in the outer select generated by this method
$orderByClause = $AST->orderByClause;
$AST->orderByClause = null;
$innerSql = $this->getInnerSQL($AST);
$sqlIdentifier = $this->getSQLIdentifier($AST);
$sqlAliasIdentifier = array_map(static function ($info) {
return $info['alias'];
}, $sqlIdentifier);
// Build the counter query
$sql = sprintf('SELECT DISTINCT %s FROM (%s) dctrn_result', implode(', ', $sqlAliasIdentifier), $innerSql);
// http://www.doctrine-project.org/jira/browse/DDC-1958
$sql = $this->preserveSqlOrdering($sqlAliasIdentifier, $innerSql, $sql, $orderByClause);
// Apply the limit and offset.
$sql = $this->platform->modifyLimitQuery(
$sql,
$this->maxResults,
$this->firstResult ?? 0
);
// Add the columns to the ResultSetMapping. It's not really nice but
// it works. Preferably I'd clear the RSM or simply create a new one
// but that is not possible from inside the output walker, so we dirty
// up the one we have.
foreach ($sqlIdentifier as $property => $propertyMapping) {
$this->rsm->addScalarResult($propertyMapping['alias'], $property, $propertyMapping['type']);
}
// Restore orderByClause
$AST->orderByClause = $orderByClause;
return $sql;
} | php | public function walkSelectStatementWithoutRowNumber(SelectStatement $AST, $addMissingItemsFromOrderByToSelect = true)
{
// We don't want to call this recursively!
if ($AST->orderByClause instanceof OrderByClause && $addMissingItemsFromOrderByToSelect) {
// In the case of ordering a query by columns from joined tables, we
// must add those columns to the select clause of the query BEFORE
// the SQL is generated.
$this->addMissingItemsFromOrderByToSelect($AST);
}
// Remove order by clause from the inner query
// It will be re-appended in the outer select generated by this method
$orderByClause = $AST->orderByClause;
$AST->orderByClause = null;
$innerSql = $this->getInnerSQL($AST);
$sqlIdentifier = $this->getSQLIdentifier($AST);
$sqlAliasIdentifier = array_map(static function ($info) {
return $info['alias'];
}, $sqlIdentifier);
// Build the counter query
$sql = sprintf('SELECT DISTINCT %s FROM (%s) dctrn_result', implode(', ', $sqlAliasIdentifier), $innerSql);
// http://www.doctrine-project.org/jira/browse/DDC-1958
$sql = $this->preserveSqlOrdering($sqlAliasIdentifier, $innerSql, $sql, $orderByClause);
// Apply the limit and offset.
$sql = $this->platform->modifyLimitQuery(
$sql,
$this->maxResults,
$this->firstResult ?? 0
);
// Add the columns to the ResultSetMapping. It's not really nice but
// it works. Preferably I'd clear the RSM or simply create a new one
// but that is not possible from inside the output walker, so we dirty
// up the one we have.
foreach ($sqlIdentifier as $property => $propertyMapping) {
$this->rsm->addScalarResult($propertyMapping['alias'], $property, $propertyMapping['type']);
}
// Restore orderByClause
$AST->orderByClause = $orderByClause;
return $sql;
} | [
"public",
"function",
"walkSelectStatementWithoutRowNumber",
"(",
"SelectStatement",
"$",
"AST",
",",
"$",
"addMissingItemsFromOrderByToSelect",
"=",
"true",
")",
"{",
"// We don't want to call this recursively!",
"if",
"(",
"$",
"AST",
"->",
"orderByClause",
"instanceof",
"OrderByClause",
"&&",
"$",
"addMissingItemsFromOrderByToSelect",
")",
"{",
"// In the case of ordering a query by columns from joined tables, we",
"// must add those columns to the select clause of the query BEFORE",
"// the SQL is generated.",
"$",
"this",
"->",
"addMissingItemsFromOrderByToSelect",
"(",
"$",
"AST",
")",
";",
"}",
"// Remove order by clause from the inner query",
"// It will be re-appended in the outer select generated by this method",
"$",
"orderByClause",
"=",
"$",
"AST",
"->",
"orderByClause",
";",
"$",
"AST",
"->",
"orderByClause",
"=",
"null",
";",
"$",
"innerSql",
"=",
"$",
"this",
"->",
"getInnerSQL",
"(",
"$",
"AST",
")",
";",
"$",
"sqlIdentifier",
"=",
"$",
"this",
"->",
"getSQLIdentifier",
"(",
"$",
"AST",
")",
";",
"$",
"sqlAliasIdentifier",
"=",
"array_map",
"(",
"static",
"function",
"(",
"$",
"info",
")",
"{",
"return",
"$",
"info",
"[",
"'alias'",
"]",
";",
"}",
",",
"$",
"sqlIdentifier",
")",
";",
"// Build the counter query",
"$",
"sql",
"=",
"sprintf",
"(",
"'SELECT DISTINCT %s FROM (%s) dctrn_result'",
",",
"implode",
"(",
"', '",
",",
"$",
"sqlAliasIdentifier",
")",
",",
"$",
"innerSql",
")",
";",
"// http://www.doctrine-project.org/jira/browse/DDC-1958",
"$",
"sql",
"=",
"$",
"this",
"->",
"preserveSqlOrdering",
"(",
"$",
"sqlAliasIdentifier",
",",
"$",
"innerSql",
",",
"$",
"sql",
",",
"$",
"orderByClause",
")",
";",
"// Apply the limit and offset.",
"$",
"sql",
"=",
"$",
"this",
"->",
"platform",
"->",
"modifyLimitQuery",
"(",
"$",
"sql",
",",
"$",
"this",
"->",
"maxResults",
",",
"$",
"this",
"->",
"firstResult",
"??",
"0",
")",
";",
"// Add the columns to the ResultSetMapping. It's not really nice but",
"// it works. Preferably I'd clear the RSM or simply create a new one",
"// but that is not possible from inside the output walker, so we dirty",
"// up the one we have.",
"foreach",
"(",
"$",
"sqlIdentifier",
"as",
"$",
"property",
"=>",
"$",
"propertyMapping",
")",
"{",
"$",
"this",
"->",
"rsm",
"->",
"addScalarResult",
"(",
"$",
"propertyMapping",
"[",
"'alias'",
"]",
",",
"$",
"property",
",",
"$",
"propertyMapping",
"[",
"'type'",
"]",
")",
";",
"}",
"// Restore orderByClause",
"$",
"AST",
"->",
"orderByClause",
"=",
"$",
"orderByClause",
";",
"return",
"$",
"sql",
";",
"}"
] | Walks down a SelectStatement AST node, wrapping it in a SELECT DISTINCT.
This method is for platforms which DO NOT support ROW_NUMBER.
@param bool $addMissingItemsFromOrderByToSelect
@return string
@throws RuntimeException | [
"Walks",
"down",
"a",
"SelectStatement",
"AST",
"node",
"wrapping",
"it",
"in",
"a",
"SELECT",
"DISTINCT",
".",
"This",
"method",
"is",
"for",
"platforms",
"which",
"DO",
"NOT",
"support",
"ROW_NUMBER",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php#L240-L286 | train |
doctrine/orm | lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php | LimitSubqueryOutputWalker.addMissingItemsFromOrderByToSelect | private function addMissingItemsFromOrderByToSelect(SelectStatement $AST)
{
$this->orderByPathExpressions = [];
// We need to do this in another walker because otherwise we'll end up
// polluting the state of this one.
$walker = clone $this;
// This will populate $orderByPathExpressions via
// LimitSubqueryOutputWalker::walkPathExpression, which will be called
// as the select statement is walked. We'll end up with an array of all
// path expressions referenced in the query.
$walker->walkSelectStatementWithoutRowNumber($AST, false);
$orderByPathExpressions = $walker->getOrderByPathExpressions();
// Get a map of referenced identifiers to field names.
$selects = [];
foreach ($orderByPathExpressions as $pathExpression) {
$idVar = $pathExpression->identificationVariable;
$field = $pathExpression->field;
if (! isset($selects[$idVar])) {
$selects[$idVar] = [];
}
$selects[$idVar][$field] = true;
}
// Loop the select clause of the AST and exclude items from $select
// that are already being selected in the query.
foreach ($AST->selectClause->selectExpressions as $selectExpression) {
if ($selectExpression instanceof SelectExpression) {
$idVar = $selectExpression->expression;
if (! is_string($idVar)) {
continue;
}
$field = $selectExpression->fieldIdentificationVariable;
if ($field === null) {
// No need to add this select, as we're already fetching the whole object.
unset($selects[$idVar]);
} else {
unset($selects[$idVar][$field]);
}
}
}
// Add select items which were not excluded to the AST's select clause.
foreach ($selects as $idVar => $fields) {
$selectExpression = new SelectExpression(new PartialObjectExpression($idVar, array_keys($fields)), null, true);
$AST->selectClause->selectExpressions[] = $selectExpression;
}
} | php | private function addMissingItemsFromOrderByToSelect(SelectStatement $AST)
{
$this->orderByPathExpressions = [];
// We need to do this in another walker because otherwise we'll end up
// polluting the state of this one.
$walker = clone $this;
// This will populate $orderByPathExpressions via
// LimitSubqueryOutputWalker::walkPathExpression, which will be called
// as the select statement is walked. We'll end up with an array of all
// path expressions referenced in the query.
$walker->walkSelectStatementWithoutRowNumber($AST, false);
$orderByPathExpressions = $walker->getOrderByPathExpressions();
// Get a map of referenced identifiers to field names.
$selects = [];
foreach ($orderByPathExpressions as $pathExpression) {
$idVar = $pathExpression->identificationVariable;
$field = $pathExpression->field;
if (! isset($selects[$idVar])) {
$selects[$idVar] = [];
}
$selects[$idVar][$field] = true;
}
// Loop the select clause of the AST and exclude items from $select
// that are already being selected in the query.
foreach ($AST->selectClause->selectExpressions as $selectExpression) {
if ($selectExpression instanceof SelectExpression) {
$idVar = $selectExpression->expression;
if (! is_string($idVar)) {
continue;
}
$field = $selectExpression->fieldIdentificationVariable;
if ($field === null) {
// No need to add this select, as we're already fetching the whole object.
unset($selects[$idVar]);
} else {
unset($selects[$idVar][$field]);
}
}
}
// Add select items which were not excluded to the AST's select clause.
foreach ($selects as $idVar => $fields) {
$selectExpression = new SelectExpression(new PartialObjectExpression($idVar, array_keys($fields)), null, true);
$AST->selectClause->selectExpressions[] = $selectExpression;
}
} | [
"private",
"function",
"addMissingItemsFromOrderByToSelect",
"(",
"SelectStatement",
"$",
"AST",
")",
"{",
"$",
"this",
"->",
"orderByPathExpressions",
"=",
"[",
"]",
";",
"// We need to do this in another walker because otherwise we'll end up",
"// polluting the state of this one.",
"$",
"walker",
"=",
"clone",
"$",
"this",
";",
"// This will populate $orderByPathExpressions via",
"// LimitSubqueryOutputWalker::walkPathExpression, which will be called",
"// as the select statement is walked. We'll end up with an array of all",
"// path expressions referenced in the query.",
"$",
"walker",
"->",
"walkSelectStatementWithoutRowNumber",
"(",
"$",
"AST",
",",
"false",
")",
";",
"$",
"orderByPathExpressions",
"=",
"$",
"walker",
"->",
"getOrderByPathExpressions",
"(",
")",
";",
"// Get a map of referenced identifiers to field names.",
"$",
"selects",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"orderByPathExpressions",
"as",
"$",
"pathExpression",
")",
"{",
"$",
"idVar",
"=",
"$",
"pathExpression",
"->",
"identificationVariable",
";",
"$",
"field",
"=",
"$",
"pathExpression",
"->",
"field",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"selects",
"[",
"$",
"idVar",
"]",
")",
")",
"{",
"$",
"selects",
"[",
"$",
"idVar",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"selects",
"[",
"$",
"idVar",
"]",
"[",
"$",
"field",
"]",
"=",
"true",
";",
"}",
"// Loop the select clause of the AST and exclude items from $select",
"// that are already being selected in the query.",
"foreach",
"(",
"$",
"AST",
"->",
"selectClause",
"->",
"selectExpressions",
"as",
"$",
"selectExpression",
")",
"{",
"if",
"(",
"$",
"selectExpression",
"instanceof",
"SelectExpression",
")",
"{",
"$",
"idVar",
"=",
"$",
"selectExpression",
"->",
"expression",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"idVar",
")",
")",
"{",
"continue",
";",
"}",
"$",
"field",
"=",
"$",
"selectExpression",
"->",
"fieldIdentificationVariable",
";",
"if",
"(",
"$",
"field",
"===",
"null",
")",
"{",
"// No need to add this select, as we're already fetching the whole object.",
"unset",
"(",
"$",
"selects",
"[",
"$",
"idVar",
"]",
")",
";",
"}",
"else",
"{",
"unset",
"(",
"$",
"selects",
"[",
"$",
"idVar",
"]",
"[",
"$",
"field",
"]",
")",
";",
"}",
"}",
"}",
"// Add select items which were not excluded to the AST's select clause.",
"foreach",
"(",
"$",
"selects",
"as",
"$",
"idVar",
"=>",
"$",
"fields",
")",
"{",
"$",
"selectExpression",
"=",
"new",
"SelectExpression",
"(",
"new",
"PartialObjectExpression",
"(",
"$",
"idVar",
",",
"array_keys",
"(",
"$",
"fields",
")",
")",
",",
"null",
",",
"true",
")",
";",
"$",
"AST",
"->",
"selectClause",
"->",
"selectExpressions",
"[",
"]",
"=",
"$",
"selectExpression",
";",
"}",
"}"
] | Finds all PathExpressions in an AST's OrderByClause, and ensures that
the referenced fields are present in the SelectClause of the passed AST. | [
"Finds",
"all",
"PathExpressions",
"in",
"an",
"AST",
"s",
"OrderByClause",
"and",
"ensures",
"that",
"the",
"referenced",
"fields",
"are",
"present",
"in",
"the",
"SelectClause",
"of",
"the",
"passed",
"AST",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php#L292-L348 | train |
doctrine/orm | lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php | LimitSubqueryOutputWalker.recreateInnerSql | private function recreateInnerSql(
OrderByClause $orderByClause,
array $identifiers,
string $innerSql
) : string {
[$searchPatterns, $replacements] = $this->generateSqlAliasReplacements();
$orderByItems = [];
foreach ($orderByClause->orderByItems as $orderByItem) {
// Walk order by item to get string representation of it and
// replace path expressions in the order by clause with their column alias
$orderByItemString = preg_replace(
$searchPatterns,
$replacements,
$this->walkOrderByItem($orderByItem)
);
$orderByItems[] = $orderByItemString;
$identifier = substr($orderByItemString, 0, strrpos($orderByItemString, ' '));
if (! in_array($identifier, $identifiers, true)) {
$identifiers[] = $identifier;
}
}
return $sql = sprintf(
'SELECT DISTINCT %s FROM (%s) dctrn_result_inner ORDER BY %s',
implode(', ', $identifiers),
$innerSql,
implode(', ', $orderByItems)
);
} | php | private function recreateInnerSql(
OrderByClause $orderByClause,
array $identifiers,
string $innerSql
) : string {
[$searchPatterns, $replacements] = $this->generateSqlAliasReplacements();
$orderByItems = [];
foreach ($orderByClause->orderByItems as $orderByItem) {
// Walk order by item to get string representation of it and
// replace path expressions in the order by clause with their column alias
$orderByItemString = preg_replace(
$searchPatterns,
$replacements,
$this->walkOrderByItem($orderByItem)
);
$orderByItems[] = $orderByItemString;
$identifier = substr($orderByItemString, 0, strrpos($orderByItemString, ' '));
if (! in_array($identifier, $identifiers, true)) {
$identifiers[] = $identifier;
}
}
return $sql = sprintf(
'SELECT DISTINCT %s FROM (%s) dctrn_result_inner ORDER BY %s',
implode(', ', $identifiers),
$innerSql,
implode(', ', $orderByItems)
);
} | [
"private",
"function",
"recreateInnerSql",
"(",
"OrderByClause",
"$",
"orderByClause",
",",
"array",
"$",
"identifiers",
",",
"string",
"$",
"innerSql",
")",
":",
"string",
"{",
"[",
"$",
"searchPatterns",
",",
"$",
"replacements",
"]",
"=",
"$",
"this",
"->",
"generateSqlAliasReplacements",
"(",
")",
";",
"$",
"orderByItems",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"orderByClause",
"->",
"orderByItems",
"as",
"$",
"orderByItem",
")",
"{",
"// Walk order by item to get string representation of it and",
"// replace path expressions in the order by clause with their column alias",
"$",
"orderByItemString",
"=",
"preg_replace",
"(",
"$",
"searchPatterns",
",",
"$",
"replacements",
",",
"$",
"this",
"->",
"walkOrderByItem",
"(",
"$",
"orderByItem",
")",
")",
";",
"$",
"orderByItems",
"[",
"]",
"=",
"$",
"orderByItemString",
";",
"$",
"identifier",
"=",
"substr",
"(",
"$",
"orderByItemString",
",",
"0",
",",
"strrpos",
"(",
"$",
"orderByItemString",
",",
"' '",
")",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"identifier",
",",
"$",
"identifiers",
",",
"true",
")",
")",
"{",
"$",
"identifiers",
"[",
"]",
"=",
"$",
"identifier",
";",
"}",
"}",
"return",
"$",
"sql",
"=",
"sprintf",
"(",
"'SELECT DISTINCT %s FROM (%s) dctrn_result_inner ORDER BY %s'",
",",
"implode",
"(",
"', '",
",",
"$",
"identifiers",
")",
",",
"$",
"innerSql",
",",
"implode",
"(",
"', '",
",",
"$",
"orderByItems",
")",
")",
";",
"}"
] | Generates a new SQL statement for the inner query to keep the correct sorting
@param mixed[][] $identifiers | [
"Generates",
"a",
"new",
"SQL",
"statement",
"for",
"the",
"inner",
"query",
"to",
"keep",
"the",
"correct",
"sorting"
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php#L379-L411 | train |
doctrine/orm | lib/Doctrine/ORM/Cache/Persister/Collection/AbstractCollectionPersister.php | AbstractCollectionPersister.evictCollectionCache | protected function evictCollectionCache(PersistentCollection $collection)
{
$key = new CollectionCacheKey(
$this->sourceEntity->getRootClassName(),
$this->association->getName(),
$this->uow->getEntityIdentifier($collection->getOwner())
);
$this->region->evict($key);
if ($this->cacheLogger) {
$this->cacheLogger->collectionCachePut($this->regionName, $key);
}
} | php | protected function evictCollectionCache(PersistentCollection $collection)
{
$key = new CollectionCacheKey(
$this->sourceEntity->getRootClassName(),
$this->association->getName(),
$this->uow->getEntityIdentifier($collection->getOwner())
);
$this->region->evict($key);
if ($this->cacheLogger) {
$this->cacheLogger->collectionCachePut($this->regionName, $key);
}
} | [
"protected",
"function",
"evictCollectionCache",
"(",
"PersistentCollection",
"$",
"collection",
")",
"{",
"$",
"key",
"=",
"new",
"CollectionCacheKey",
"(",
"$",
"this",
"->",
"sourceEntity",
"->",
"getRootClassName",
"(",
")",
",",
"$",
"this",
"->",
"association",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"uow",
"->",
"getEntityIdentifier",
"(",
"$",
"collection",
"->",
"getOwner",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"region",
"->",
"evict",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"this",
"->",
"cacheLogger",
")",
"{",
"$",
"this",
"->",
"cacheLogger",
"->",
"collectionCachePut",
"(",
"$",
"this",
"->",
"regionName",
",",
"$",
"key",
")",
";",
"}",
"}"
] | Clears cache entries related to the current collection | [
"Clears",
"cache",
"entries",
"related",
"to",
"the",
"current",
"collection"
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Cache/Persister/Collection/AbstractCollectionPersister.php#L248-L261 | train |
doctrine/orm | lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php | AnnotationDriver.convertJoinTableAnnotationToJoinTableMetadata | private function convertJoinTableAnnotationToJoinTableMetadata(
Annotation\JoinTable $joinTableAnnot
) : Mapping\JoinTableMetadata {
$joinTable = new Mapping\JoinTableMetadata();
if (! empty($joinTableAnnot->name)) {
$joinTable->setName($joinTableAnnot->name);
}
if (! empty($joinTableAnnot->schema)) {
$joinTable->setSchema($joinTableAnnot->schema);
}
foreach ($joinTableAnnot->joinColumns as $joinColumnAnnot) {
$joinColumn = $this->convertJoinColumnAnnotationToJoinColumnMetadata($joinColumnAnnot);
$joinTable->addJoinColumn($joinColumn);
}
foreach ($joinTableAnnot->inverseJoinColumns as $joinColumnAnnot) {
$joinColumn = $this->convertJoinColumnAnnotationToJoinColumnMetadata($joinColumnAnnot);
$joinTable->addInverseJoinColumn($joinColumn);
}
return $joinTable;
} | php | private function convertJoinTableAnnotationToJoinTableMetadata(
Annotation\JoinTable $joinTableAnnot
) : Mapping\JoinTableMetadata {
$joinTable = new Mapping\JoinTableMetadata();
if (! empty($joinTableAnnot->name)) {
$joinTable->setName($joinTableAnnot->name);
}
if (! empty($joinTableAnnot->schema)) {
$joinTable->setSchema($joinTableAnnot->schema);
}
foreach ($joinTableAnnot->joinColumns as $joinColumnAnnot) {
$joinColumn = $this->convertJoinColumnAnnotationToJoinColumnMetadata($joinColumnAnnot);
$joinTable->addJoinColumn($joinColumn);
}
foreach ($joinTableAnnot->inverseJoinColumns as $joinColumnAnnot) {
$joinColumn = $this->convertJoinColumnAnnotationToJoinColumnMetadata($joinColumnAnnot);
$joinTable->addInverseJoinColumn($joinColumn);
}
return $joinTable;
} | [
"private",
"function",
"convertJoinTableAnnotationToJoinTableMetadata",
"(",
"Annotation",
"\\",
"JoinTable",
"$",
"joinTableAnnot",
")",
":",
"Mapping",
"\\",
"JoinTableMetadata",
"{",
"$",
"joinTable",
"=",
"new",
"Mapping",
"\\",
"JoinTableMetadata",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"joinTableAnnot",
"->",
"name",
")",
")",
"{",
"$",
"joinTable",
"->",
"setName",
"(",
"$",
"joinTableAnnot",
"->",
"name",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"joinTableAnnot",
"->",
"schema",
")",
")",
"{",
"$",
"joinTable",
"->",
"setSchema",
"(",
"$",
"joinTableAnnot",
"->",
"schema",
")",
";",
"}",
"foreach",
"(",
"$",
"joinTableAnnot",
"->",
"joinColumns",
"as",
"$",
"joinColumnAnnot",
")",
"{",
"$",
"joinColumn",
"=",
"$",
"this",
"->",
"convertJoinColumnAnnotationToJoinColumnMetadata",
"(",
"$",
"joinColumnAnnot",
")",
";",
"$",
"joinTable",
"->",
"addJoinColumn",
"(",
"$",
"joinColumn",
")",
";",
"}",
"foreach",
"(",
"$",
"joinTableAnnot",
"->",
"inverseJoinColumns",
"as",
"$",
"joinColumnAnnot",
")",
"{",
"$",
"joinColumn",
"=",
"$",
"this",
"->",
"convertJoinColumnAnnotationToJoinColumnMetadata",
"(",
"$",
"joinColumnAnnot",
")",
";",
"$",
"joinTable",
"->",
"addInverseJoinColumn",
"(",
"$",
"joinColumn",
")",
";",
"}",
"return",
"$",
"joinTable",
";",
"}"
] | Parse the given JoinTable as JoinTableMetadata | [
"Parse",
"the",
"given",
"JoinTable",
"as",
"JoinTableMetadata"
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php#L897-L923 | train |
doctrine/orm | lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php | AnnotationDriver.getCascade | private function getCascade(string $className, string $fieldName, array $originalCascades)
{
$cascadeTypes = ['remove', 'persist', 'refresh'];
$cascades = array_map('strtolower', $originalCascades);
if (in_array('all', $cascades, true)) {
$cascades = $cascadeTypes;
}
if (count($cascades) !== count(array_intersect($cascades, $cascadeTypes))) {
$diffCascades = array_diff($cascades, array_intersect($cascades, $cascadeTypes));
throw Mapping\MappingException::invalidCascadeOption($diffCascades, $className, $fieldName);
}
return $cascades;
} | php | private function getCascade(string $className, string $fieldName, array $originalCascades)
{
$cascadeTypes = ['remove', 'persist', 'refresh'];
$cascades = array_map('strtolower', $originalCascades);
if (in_array('all', $cascades, true)) {
$cascades = $cascadeTypes;
}
if (count($cascades) !== count(array_intersect($cascades, $cascadeTypes))) {
$diffCascades = array_diff($cascades, array_intersect($cascades, $cascadeTypes));
throw Mapping\MappingException::invalidCascadeOption($diffCascades, $className, $fieldName);
}
return $cascades;
} | [
"private",
"function",
"getCascade",
"(",
"string",
"$",
"className",
",",
"string",
"$",
"fieldName",
",",
"array",
"$",
"originalCascades",
")",
"{",
"$",
"cascadeTypes",
"=",
"[",
"'remove'",
",",
"'persist'",
",",
"'refresh'",
"]",
";",
"$",
"cascades",
"=",
"array_map",
"(",
"'strtolower'",
",",
"$",
"originalCascades",
")",
";",
"if",
"(",
"in_array",
"(",
"'all'",
",",
"$",
"cascades",
",",
"true",
")",
")",
"{",
"$",
"cascades",
"=",
"$",
"cascadeTypes",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"cascades",
")",
"!==",
"count",
"(",
"array_intersect",
"(",
"$",
"cascades",
",",
"$",
"cascadeTypes",
")",
")",
")",
"{",
"$",
"diffCascades",
"=",
"array_diff",
"(",
"$",
"cascades",
",",
"array_intersect",
"(",
"$",
"cascades",
",",
"$",
"cascadeTypes",
")",
")",
";",
"throw",
"Mapping",
"\\",
"MappingException",
"::",
"invalidCascadeOption",
"(",
"$",
"diffCascades",
",",
"$",
"className",
",",
"$",
"fieldName",
")",
";",
"}",
"return",
"$",
"cascades",
";",
"}"
] | Attempts to resolve the cascade modes.
@param string $className The class name.
@param string $fieldName The field name.
@param string[] $originalCascades The original unprocessed field cascades.
@return string[] The processed field cascades.
@throws Mapping\MappingException If a cascade option is not valid. | [
"Attempts",
"to",
"resolve",
"the",
"cascade",
"modes",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php#L1232-L1248 | train |
doctrine/orm | lib/Doctrine/ORM/EntityManager.php | EntityManager.clear | public function clear($entityName = null)
{
$this->unitOfWork->clear();
$this->unitOfWork = new UnitOfWork($this);
if ($this->eventManager->hasListeners(Events::onClear)) {
$this->eventManager->dispatchEvent(Events::onClear, new Event\OnClearEventArgs($this));
}
} | php | public function clear($entityName = null)
{
$this->unitOfWork->clear();
$this->unitOfWork = new UnitOfWork($this);
if ($this->eventManager->hasListeners(Events::onClear)) {
$this->eventManager->dispatchEvent(Events::onClear, new Event\OnClearEventArgs($this));
}
} | [
"public",
"function",
"clear",
"(",
"$",
"entityName",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"unitOfWork",
"->",
"clear",
"(",
")",
";",
"$",
"this",
"->",
"unitOfWork",
"=",
"new",
"UnitOfWork",
"(",
"$",
"this",
")",
";",
"if",
"(",
"$",
"this",
"->",
"eventManager",
"->",
"hasListeners",
"(",
"Events",
"::",
"onClear",
")",
")",
"{",
"$",
"this",
"->",
"eventManager",
"->",
"dispatchEvent",
"(",
"Events",
"::",
"onClear",
",",
"new",
"Event",
"\\",
"OnClearEventArgs",
"(",
"$",
"this",
")",
")",
";",
"}",
"}"
] | Clears the EntityManager. All entities that are currently managed
by this EntityManager become detached.
@param null $entityName Unused. @todo Remove from ObjectManager. | [
"Clears",
"the",
"EntityManager",
".",
"All",
"entities",
"that",
"are",
"currently",
"managed",
"by",
"this",
"EntityManager",
"become",
"detached",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/EntityManager.php#L592-L601 | train |
doctrine/orm | lib/Doctrine/ORM/EntityManager.php | EntityManager.persist | public function persist($entity)
{
if (! is_object($entity)) {
throw ORMInvalidArgumentException::invalidObject('EntityManager#persist()', $entity);
}
$this->errorIfClosed();
$this->unitOfWork->persist($entity);
} | php | public function persist($entity)
{
if (! is_object($entity)) {
throw ORMInvalidArgumentException::invalidObject('EntityManager#persist()', $entity);
}
$this->errorIfClosed();
$this->unitOfWork->persist($entity);
} | [
"public",
"function",
"persist",
"(",
"$",
"entity",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"entity",
")",
")",
"{",
"throw",
"ORMInvalidArgumentException",
"::",
"invalidObject",
"(",
"'EntityManager#persist()'",
",",
"$",
"entity",
")",
";",
"}",
"$",
"this",
"->",
"errorIfClosed",
"(",
")",
";",
"$",
"this",
"->",
"unitOfWork",
"->",
"persist",
"(",
"$",
"entity",
")",
";",
"}"
] | Tells the EntityManager to make an instance managed and persistent.
The entity will be entered into the database at or before transaction
commit or as a result of the flush operation.
NOTE: The persist operation always considers entities that are not yet known to
this EntityManager as NEW. Do not pass detached entities to the persist operation.
@param object $entity The instance to make managed and persistent.
@throws ORMInvalidArgumentException
@throws ORMException | [
"Tells",
"the",
"EntityManager",
"to",
"make",
"an",
"instance",
"managed",
"and",
"persistent",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/EntityManager.php#L627-L636 | train |
doctrine/orm | lib/Doctrine/ORM/EntityManager.php | EntityManager.refresh | public function refresh($entity)
{
if (! is_object($entity)) {
throw ORMInvalidArgumentException::invalidObject('EntityManager#refresh()', $entity);
}
$this->errorIfClosed();
$this->unitOfWork->refresh($entity);
} | php | public function refresh($entity)
{
if (! is_object($entity)) {
throw ORMInvalidArgumentException::invalidObject('EntityManager#refresh()', $entity);
}
$this->errorIfClosed();
$this->unitOfWork->refresh($entity);
} | [
"public",
"function",
"refresh",
"(",
"$",
"entity",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"entity",
")",
")",
"{",
"throw",
"ORMInvalidArgumentException",
"::",
"invalidObject",
"(",
"'EntityManager#refresh()'",
",",
"$",
"entity",
")",
";",
"}",
"$",
"this",
"->",
"errorIfClosed",
"(",
")",
";",
"$",
"this",
"->",
"unitOfWork",
"->",
"refresh",
"(",
"$",
"entity",
")",
";",
"}"
] | Refreshes the persistent state of an entity from the database,
overriding any local changes that have not yet been persisted.
@param object $entity The entity to refresh.
@throws ORMInvalidArgumentException
@throws ORMException | [
"Refreshes",
"the",
"persistent",
"state",
"of",
"an",
"entity",
"from",
"the",
"database",
"overriding",
"any",
"local",
"changes",
"that",
"have",
"not",
"yet",
"been",
"persisted",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/EntityManager.php#L669-L678 | train |
doctrine/orm | lib/Doctrine/ORM/EntityManager.php | EntityManager.contains | public function contains($entity)
{
return $this->unitOfWork->isScheduledForInsert($entity)
|| ($this->unitOfWork->isInIdentityMap($entity) && ! $this->unitOfWork->isScheduledForDelete($entity));
} | php | public function contains($entity)
{
return $this->unitOfWork->isScheduledForInsert($entity)
|| ($this->unitOfWork->isInIdentityMap($entity) && ! $this->unitOfWork->isScheduledForDelete($entity));
} | [
"public",
"function",
"contains",
"(",
"$",
"entity",
")",
"{",
"return",
"$",
"this",
"->",
"unitOfWork",
"->",
"isScheduledForInsert",
"(",
"$",
"entity",
")",
"||",
"(",
"$",
"this",
"->",
"unitOfWork",
"->",
"isInIdentityMap",
"(",
"$",
"entity",
")",
"&&",
"!",
"$",
"this",
"->",
"unitOfWork",
"->",
"isScheduledForDelete",
"(",
"$",
"entity",
")",
")",
";",
"}"
] | Determines whether an entity instance is managed in this EntityManager.
@param object $entity
@return bool TRUE if this EntityManager currently manages the given entity, FALSE otherwise. | [
"Determines",
"whether",
"an",
"entity",
"instance",
"is",
"managed",
"in",
"this",
"EntityManager",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/EntityManager.php#L707-L711 | train |
doctrine/orm | lib/Doctrine/ORM/EntityManager.php | EntityManager.createConnection | protected static function createConnection($connection, Configuration $config, ?EventManager $eventManager = null)
{
if (is_array($connection)) {
return DriverManager::getConnection($connection, $config, $eventManager ?: new EventManager());
}
if (! $connection instanceof Connection) {
throw new InvalidArgumentException(
sprintf(
'Invalid $connection argument of type %s given%s.',
is_object($connection) ? get_class($connection) : gettype($connection),
is_object($connection) ? '' : ': "' . $connection . '"'
)
);
}
if ($eventManager !== null && $connection->getEventManager() !== $eventManager) {
throw MismatchedEventManager::create();
}
return $connection;
} | php | protected static function createConnection($connection, Configuration $config, ?EventManager $eventManager = null)
{
if (is_array($connection)) {
return DriverManager::getConnection($connection, $config, $eventManager ?: new EventManager());
}
if (! $connection instanceof Connection) {
throw new InvalidArgumentException(
sprintf(
'Invalid $connection argument of type %s given%s.',
is_object($connection) ? get_class($connection) : gettype($connection),
is_object($connection) ? '' : ': "' . $connection . '"'
)
);
}
if ($eventManager !== null && $connection->getEventManager() !== $eventManager) {
throw MismatchedEventManager::create();
}
return $connection;
} | [
"protected",
"static",
"function",
"createConnection",
"(",
"$",
"connection",
",",
"Configuration",
"$",
"config",
",",
"?",
"EventManager",
"$",
"eventManager",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"connection",
")",
")",
"{",
"return",
"DriverManager",
"::",
"getConnection",
"(",
"$",
"connection",
",",
"$",
"config",
",",
"$",
"eventManager",
"?",
":",
"new",
"EventManager",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"connection",
"instanceof",
"Connection",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid $connection argument of type %s given%s.'",
",",
"is_object",
"(",
"$",
"connection",
")",
"?",
"get_class",
"(",
"$",
"connection",
")",
":",
"gettype",
"(",
"$",
"connection",
")",
",",
"is_object",
"(",
"$",
"connection",
")",
"?",
"''",
":",
"': \"'",
".",
"$",
"connection",
".",
"'\"'",
")",
")",
";",
"}",
"if",
"(",
"$",
"eventManager",
"!==",
"null",
"&&",
"$",
"connection",
"->",
"getEventManager",
"(",
")",
"!==",
"$",
"eventManager",
")",
"{",
"throw",
"MismatchedEventManager",
"::",
"create",
"(",
")",
";",
"}",
"return",
"$",
"connection",
";",
"}"
] | Factory method to create Connection instances.
@param Connection|mixed[] $connection An array with the connection parameters or an existing Connection instance.
@param Configuration $config The Configuration instance to use.
@param EventManager $eventManager The EventManager instance to use.
@return Connection
@throws InvalidArgumentException
@throws ORMException | [
"Factory",
"method",
"to",
"create",
"Connection",
"instances",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/EntityManager.php#L842-L863 | train |
doctrine/orm | lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php | MappingDescribeCommand.getClassMetadata | private function getClassMetadata($entityName, EntityManagerInterface $entityManager)
{
try {
return $entityManager->getClassMetadata($entityName);
} catch (MappingException $e) {
}
$matches = array_filter(
$this->getMappedEntities($entityManager),
static function ($mappedEntity) use ($entityName) {
return preg_match('{' . preg_quote($entityName) . '}', $mappedEntity);
}
);
if (! $matches) {
throw new InvalidArgumentException(sprintf(
'Could not find any mapped Entity classes matching "%s"',
$entityName
));
}
if (count($matches) > 1) {
throw new InvalidArgumentException(sprintf(
'Entity name "%s" is ambiguous, possible matches: "%s"',
$entityName,
implode(', ', $matches)
));
}
return $entityManager->getClassMetadata(current($matches));
} | php | private function getClassMetadata($entityName, EntityManagerInterface $entityManager)
{
try {
return $entityManager->getClassMetadata($entityName);
} catch (MappingException $e) {
}
$matches = array_filter(
$this->getMappedEntities($entityManager),
static function ($mappedEntity) use ($entityName) {
return preg_match('{' . preg_quote($entityName) . '}', $mappedEntity);
}
);
if (! $matches) {
throw new InvalidArgumentException(sprintf(
'Could not find any mapped Entity classes matching "%s"',
$entityName
));
}
if (count($matches) > 1) {
throw new InvalidArgumentException(sprintf(
'Entity name "%s" is ambiguous, possible matches: "%s"',
$entityName,
implode(', ', $matches)
));
}
return $entityManager->getClassMetadata(current($matches));
} | [
"private",
"function",
"getClassMetadata",
"(",
"$",
"entityName",
",",
"EntityManagerInterface",
"$",
"entityManager",
")",
"{",
"try",
"{",
"return",
"$",
"entityManager",
"->",
"getClassMetadata",
"(",
"$",
"entityName",
")",
";",
"}",
"catch",
"(",
"MappingException",
"$",
"e",
")",
"{",
"}",
"$",
"matches",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"getMappedEntities",
"(",
"$",
"entityManager",
")",
",",
"static",
"function",
"(",
"$",
"mappedEntity",
")",
"use",
"(",
"$",
"entityName",
")",
"{",
"return",
"preg_match",
"(",
"'{'",
".",
"preg_quote",
"(",
"$",
"entityName",
")",
".",
"'}'",
",",
"$",
"mappedEntity",
")",
";",
"}",
")",
";",
"if",
"(",
"!",
"$",
"matches",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Could not find any mapped Entity classes matching \"%s\"'",
",",
"$",
"entityName",
")",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"matches",
")",
">",
"1",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Entity name \"%s\" is ambiguous, possible matches: \"%s\"'",
",",
"$",
"entityName",
",",
"implode",
"(",
"', '",
",",
"$",
"matches",
")",
")",
")",
";",
"}",
"return",
"$",
"entityManager",
"->",
"getClassMetadata",
"(",
"current",
"(",
"$",
"matches",
")",
")",
";",
"}"
] | Return the class metadata for the given entity
name
@param string $entityName Full or partial entity name
@return ClassMetadata | [
"Return",
"the",
"class",
"metadata",
"for",
"the",
"given",
"entity",
"name"
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php#L163-L193 | train |
doctrine/orm | lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php | MappingDescribeCommand.formatValue | private function formatValue($value)
{
if ($value === '') {
return '';
}
if ($value === null) {
return '<comment>Null</comment>';
}
if (is_bool($value)) {
return '<comment>' . ($value ? 'True' : 'False') . '</comment>';
}
if (empty($value)) {
return '<comment>Empty</comment>';
}
if (is_array($value)) {
return json_encode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
if (is_object($value)) {
return sprintf('<%s>', get_class($value));
}
if (is_scalar($value)) {
return $value;
}
throw new InvalidArgumentException(sprintf('Do not know how to format value "%s"', print_r($value, true)));
} | php | private function formatValue($value)
{
if ($value === '') {
return '';
}
if ($value === null) {
return '<comment>Null</comment>';
}
if (is_bool($value)) {
return '<comment>' . ($value ? 'True' : 'False') . '</comment>';
}
if (empty($value)) {
return '<comment>Empty</comment>';
}
if (is_array($value)) {
return json_encode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
if (is_object($value)) {
return sprintf('<%s>', get_class($value));
}
if (is_scalar($value)) {
return $value;
}
throw new InvalidArgumentException(sprintf('Do not know how to format value "%s"', print_r($value, true)));
} | [
"private",
"function",
"formatValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"'<comment>Null</comment>'",
";",
"}",
"if",
"(",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"return",
"'<comment>'",
".",
"(",
"$",
"value",
"?",
"'True'",
":",
"'False'",
")",
".",
"'</comment>'",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"return",
"'<comment>Empty</comment>'",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"json_encode",
"(",
"$",
"value",
",",
"JSON_UNESCAPED_UNICODE",
"|",
"JSON_UNESCAPED_SLASHES",
")",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"return",
"sprintf",
"(",
"'<%s>'",
",",
"get_class",
"(",
"$",
"value",
")",
")",
";",
"}",
"if",
"(",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Do not know how to format value \"%s\"'",
",",
"print_r",
"(",
"$",
"value",
",",
"true",
")",
")",
")",
";",
"}"
] | Format the given value for console output
@param mixed $value
@return string | [
"Format",
"the",
"given",
"value",
"for",
"console",
"output"
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php#L243-L274 | train |
doctrine/orm | lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php | MappingDescribeCommand.formatField | private function formatField($label, $value)
{
if ($value === null) {
$value = '<comment>None</comment>';
}
return [sprintf('<info>%s</info>', $label), $this->formatValue($value)];
} | php | private function formatField($label, $value)
{
if ($value === null) {
$value = '<comment>None</comment>';
}
return [sprintf('<info>%s</info>', $label), $this->formatValue($value)];
} | [
"private",
"function",
"formatField",
"(",
"$",
"label",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"$",
"value",
"=",
"'<comment>None</comment>'",
";",
"}",
"return",
"[",
"sprintf",
"(",
"'<info>%s</info>'",
",",
"$",
"label",
")",
",",
"$",
"this",
"->",
"formatValue",
"(",
"$",
"value",
")",
"]",
";",
"}"
] | Add the given label and value to the two column table output
@param string $label Label for the value
@param mixed $value A Value to show
@return string[] | [
"Add",
"the",
"given",
"label",
"and",
"value",
"to",
"the",
"two",
"column",
"table",
"output"
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php#L284-L291 | train |
doctrine/orm | lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php | MappingDescribeCommand.formatPropertyMappings | private function formatPropertyMappings(iterable $propertyMappings)
{
$output = [];
foreach ($propertyMappings as $propertyName => $property) {
$output[] = $this->formatField(sprintf(' %s', $propertyName), '');
if ($property instanceof FieldMetadata) {
$output = array_merge($output, $this->formatColumn($property));
} elseif ($property instanceof AssociationMetadata) {
// @todo guilhermeblanco Fix me! We are trying to iterate through an AssociationMetadata instance
foreach ($property as $field => $value) {
$output[] = $this->formatField(sprintf(' %s', $field), $this->formatValue($value));
}
}
}
return $output;
} | php | private function formatPropertyMappings(iterable $propertyMappings)
{
$output = [];
foreach ($propertyMappings as $propertyName => $property) {
$output[] = $this->formatField(sprintf(' %s', $propertyName), '');
if ($property instanceof FieldMetadata) {
$output = array_merge($output, $this->formatColumn($property));
} elseif ($property instanceof AssociationMetadata) {
// @todo guilhermeblanco Fix me! We are trying to iterate through an AssociationMetadata instance
foreach ($property as $field => $value) {
$output[] = $this->formatField(sprintf(' %s', $field), $this->formatValue($value));
}
}
}
return $output;
} | [
"private",
"function",
"formatPropertyMappings",
"(",
"iterable",
"$",
"propertyMappings",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"propertyMappings",
"as",
"$",
"propertyName",
"=>",
"$",
"property",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"$",
"this",
"->",
"formatField",
"(",
"sprintf",
"(",
"' %s'",
",",
"$",
"propertyName",
")",
",",
"''",
")",
";",
"if",
"(",
"$",
"property",
"instanceof",
"FieldMetadata",
")",
"{",
"$",
"output",
"=",
"array_merge",
"(",
"$",
"output",
",",
"$",
"this",
"->",
"formatColumn",
"(",
"$",
"property",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"property",
"instanceof",
"AssociationMetadata",
")",
"{",
"// @todo guilhermeblanco Fix me! We are trying to iterate through an AssociationMetadata instance",
"foreach",
"(",
"$",
"property",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"$",
"this",
"->",
"formatField",
"(",
"sprintf",
"(",
"' %s'",
",",
"$",
"field",
")",
",",
"$",
"this",
"->",
"formatValue",
"(",
"$",
"value",
")",
")",
";",
"}",
"}",
"}",
"return",
"$",
"output",
";",
"}"
] | Format the property mappings
@param iterable|Property[] $propertyMappings
@return string[] | [
"Format",
"the",
"property",
"mappings"
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php#L300-L318 | train |
doctrine/orm | lib/Doctrine/ORM/Mapping/Factory/Autoloader.php | Autoloader.resolveFile | public static function resolveFile(string $metadataDir, string $metadataNamespace, string $className) : string
{
if (strpos($className, $metadataNamespace) !== 0) {
throw new InvalidArgumentException(
sprintf('The class "%s" is not part of the metadata namespace "%s"', $className, $metadataNamespace)
);
}
// remove metadata namespace from class name
$classNameRelativeToMetadataNamespace = substr($className, strlen($metadataNamespace));
// remove namespace separators from remaining class name
$fileName = str_replace('\\', '', $classNameRelativeToMetadataNamespace);
return $metadataDir . DIRECTORY_SEPARATOR . $fileName . '.php';
} | php | public static function resolveFile(string $metadataDir, string $metadataNamespace, string $className) : string
{
if (strpos($className, $metadataNamespace) !== 0) {
throw new InvalidArgumentException(
sprintf('The class "%s" is not part of the metadata namespace "%s"', $className, $metadataNamespace)
);
}
// remove metadata namespace from class name
$classNameRelativeToMetadataNamespace = substr($className, strlen($metadataNamespace));
// remove namespace separators from remaining class name
$fileName = str_replace('\\', '', $classNameRelativeToMetadataNamespace);
return $metadataDir . DIRECTORY_SEPARATOR . $fileName . '.php';
} | [
"public",
"static",
"function",
"resolveFile",
"(",
"string",
"$",
"metadataDir",
",",
"string",
"$",
"metadataNamespace",
",",
"string",
"$",
"className",
")",
":",
"string",
"{",
"if",
"(",
"strpos",
"(",
"$",
"className",
",",
"$",
"metadataNamespace",
")",
"!==",
"0",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The class \"%s\" is not part of the metadata namespace \"%s\"'",
",",
"$",
"className",
",",
"$",
"metadataNamespace",
")",
")",
";",
"}",
"// remove metadata namespace from class name",
"$",
"classNameRelativeToMetadataNamespace",
"=",
"substr",
"(",
"$",
"className",
",",
"strlen",
"(",
"$",
"metadataNamespace",
")",
")",
";",
"// remove namespace separators from remaining class name",
"$",
"fileName",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"''",
",",
"$",
"classNameRelativeToMetadataNamespace",
")",
";",
"return",
"$",
"metadataDir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"fileName",
".",
"'.php'",
";",
"}"
] | Resolves ClassMetadata class name to a filename based on the following pattern.
1. Remove Metadata namespace from class name.
2. Remove namespace separators from remaining class name.
3. Return PHP filename from metadata-dir with the result from 2.
@throws InvalidArgumentException | [
"Resolves",
"ClassMetadata",
"class",
"name",
"to",
"a",
"filename",
"based",
"on",
"the",
"following",
"pattern",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Mapping/Factory/Autoloader.php#L35-L50 | train |
doctrine/orm | lib/Doctrine/ORM/Mapping/Factory/Autoloader.php | Autoloader.register | public static function register(
string $metadataDir,
string $metadataNamespace,
?callable $notFoundCallback = null
) : Closure {
$metadataNamespace = ltrim($metadataNamespace, '\\');
if (! ($notFoundCallback === null || is_callable($notFoundCallback))) {
$type = is_object($notFoundCallback) ? get_class($notFoundCallback) : gettype($notFoundCallback);
throw new InvalidArgumentException(
sprintf('Invalid \$notFoundCallback given: must be a callable, "%s" given', $type)
);
}
$autoloader = static function ($className) use ($metadataDir, $metadataNamespace, $notFoundCallback) {
if (strpos($className, $metadataNamespace) === 0) {
$file = Autoloader::resolveFile($metadataDir, $metadataNamespace, $className);
if ($notFoundCallback && ! file_exists($file)) {
call_user_func($notFoundCallback, $metadataDir, $metadataNamespace, $className);
}
require $file;
}
};
spl_autoload_register($autoloader);
return $autoloader;
} | php | public static function register(
string $metadataDir,
string $metadataNamespace,
?callable $notFoundCallback = null
) : Closure {
$metadataNamespace = ltrim($metadataNamespace, '\\');
if (! ($notFoundCallback === null || is_callable($notFoundCallback))) {
$type = is_object($notFoundCallback) ? get_class($notFoundCallback) : gettype($notFoundCallback);
throw new InvalidArgumentException(
sprintf('Invalid \$notFoundCallback given: must be a callable, "%s" given', $type)
);
}
$autoloader = static function ($className) use ($metadataDir, $metadataNamespace, $notFoundCallback) {
if (strpos($className, $metadataNamespace) === 0) {
$file = Autoloader::resolveFile($metadataDir, $metadataNamespace, $className);
if ($notFoundCallback && ! file_exists($file)) {
call_user_func($notFoundCallback, $metadataDir, $metadataNamespace, $className);
}
require $file;
}
};
spl_autoload_register($autoloader);
return $autoloader;
} | [
"public",
"static",
"function",
"register",
"(",
"string",
"$",
"metadataDir",
",",
"string",
"$",
"metadataNamespace",
",",
"?",
"callable",
"$",
"notFoundCallback",
"=",
"null",
")",
":",
"Closure",
"{",
"$",
"metadataNamespace",
"=",
"ltrim",
"(",
"$",
"metadataNamespace",
",",
"'\\\\'",
")",
";",
"if",
"(",
"!",
"(",
"$",
"notFoundCallback",
"===",
"null",
"||",
"is_callable",
"(",
"$",
"notFoundCallback",
")",
")",
")",
"{",
"$",
"type",
"=",
"is_object",
"(",
"$",
"notFoundCallback",
")",
"?",
"get_class",
"(",
"$",
"notFoundCallback",
")",
":",
"gettype",
"(",
"$",
"notFoundCallback",
")",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid \\$notFoundCallback given: must be a callable, \"%s\" given'",
",",
"$",
"type",
")",
")",
";",
"}",
"$",
"autoloader",
"=",
"static",
"function",
"(",
"$",
"className",
")",
"use",
"(",
"$",
"metadataDir",
",",
"$",
"metadataNamespace",
",",
"$",
"notFoundCallback",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"className",
",",
"$",
"metadataNamespace",
")",
"===",
"0",
")",
"{",
"$",
"file",
"=",
"Autoloader",
"::",
"resolveFile",
"(",
"$",
"metadataDir",
",",
"$",
"metadataNamespace",
",",
"$",
"className",
")",
";",
"if",
"(",
"$",
"notFoundCallback",
"&&",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"call_user_func",
"(",
"$",
"notFoundCallback",
",",
"$",
"metadataDir",
",",
"$",
"metadataNamespace",
",",
"$",
"className",
")",
";",
"}",
"require",
"$",
"file",
";",
"}",
"}",
";",
"spl_autoload_register",
"(",
"$",
"autoloader",
")",
";",
"return",
"$",
"autoloader",
";",
"}"
] | Registers and returns autoloader callback for the given metadata dir and namespace.
@param callable|null $notFoundCallback Invoked when the proxy file is not found.
@throws InvalidArgumentException | [
"Registers",
"and",
"returns",
"autoloader",
"callback",
"for",
"the",
"given",
"metadata",
"dir",
"and",
"namespace",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Mapping/Factory/Autoloader.php#L59-L89 | train |
doctrine/orm | lib/Doctrine/ORM/Internal/HydrationCompleteHandler.php | HydrationCompleteHandler.deferPostLoadInvoking | public function deferPostLoadInvoking(ClassMetadata $class, $entity)
{
$invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::postLoad);
if ($invoke === ListenersInvoker::INVOKE_NONE) {
return;
}
$this->deferredPostLoadInvocations[] = [$class, $invoke, $entity];
} | php | public function deferPostLoadInvoking(ClassMetadata $class, $entity)
{
$invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::postLoad);
if ($invoke === ListenersInvoker::INVOKE_NONE) {
return;
}
$this->deferredPostLoadInvocations[] = [$class, $invoke, $entity];
} | [
"public",
"function",
"deferPostLoadInvoking",
"(",
"ClassMetadata",
"$",
"class",
",",
"$",
"entity",
")",
"{",
"$",
"invoke",
"=",
"$",
"this",
"->",
"listenersInvoker",
"->",
"getSubscribedSystems",
"(",
"$",
"class",
",",
"Events",
"::",
"postLoad",
")",
";",
"if",
"(",
"$",
"invoke",
"===",
"ListenersInvoker",
"::",
"INVOKE_NONE",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"deferredPostLoadInvocations",
"[",
"]",
"=",
"[",
"$",
"class",
",",
"$",
"invoke",
",",
"$",
"entity",
"]",
";",
"}"
] | Method schedules invoking of postLoad entity to the very end of current hydration cycle.
@param object $entity | [
"Method",
"schedules",
"invoking",
"of",
"postLoad",
"entity",
"to",
"the",
"very",
"end",
"of",
"current",
"hydration",
"cycle",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Internal/HydrationCompleteHandler.php#L42-L51 | train |
doctrine/orm | lib/Doctrine/ORM/Internal/HydrationCompleteHandler.php | HydrationCompleteHandler.hydrationComplete | public function hydrationComplete()
{
$toInvoke = $this->deferredPostLoadInvocations;
$this->deferredPostLoadInvocations = [];
foreach ($toInvoke as $classAndEntity) {
[$class, $invoke, $entity] = $classAndEntity;
$this->listenersInvoker->invoke(
$class,
Events::postLoad,
$entity,
new LifecycleEventArgs($entity, $this->em),
$invoke
);
}
} | php | public function hydrationComplete()
{
$toInvoke = $this->deferredPostLoadInvocations;
$this->deferredPostLoadInvocations = [];
foreach ($toInvoke as $classAndEntity) {
[$class, $invoke, $entity] = $classAndEntity;
$this->listenersInvoker->invoke(
$class,
Events::postLoad,
$entity,
new LifecycleEventArgs($entity, $this->em),
$invoke
);
}
} | [
"public",
"function",
"hydrationComplete",
"(",
")",
"{",
"$",
"toInvoke",
"=",
"$",
"this",
"->",
"deferredPostLoadInvocations",
";",
"$",
"this",
"->",
"deferredPostLoadInvocations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"toInvoke",
"as",
"$",
"classAndEntity",
")",
"{",
"[",
"$",
"class",
",",
"$",
"invoke",
",",
"$",
"entity",
"]",
"=",
"$",
"classAndEntity",
";",
"$",
"this",
"->",
"listenersInvoker",
"->",
"invoke",
"(",
"$",
"class",
",",
"Events",
"::",
"postLoad",
",",
"$",
"entity",
",",
"new",
"LifecycleEventArgs",
"(",
"$",
"entity",
",",
"$",
"this",
"->",
"em",
")",
",",
"$",
"invoke",
")",
";",
"}",
"}"
] | This method should me called after any hydration cycle completed.
Method fires all deferred invocations of postLoad events | [
"This",
"method",
"should",
"me",
"called",
"after",
"any",
"hydration",
"cycle",
"completed",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Internal/HydrationCompleteHandler.php#L58-L74 | train |
doctrine/orm | lib/Doctrine/ORM/Mapping/Factory/AbstractClassMetadataFactory.php | AbstractClassMetadataFactory.getOrCreateClassMetadataDefinition | private function getOrCreateClassMetadataDefinition(string $className, ?ClassMetadata $parent) : ClassMetadataDefinition
{
if (! isset($this->definitions[$className])) {
$this->definitions[$className] = $this->definitionFactory->build($className, $parent);
}
return $this->definitions[$className];
} | php | private function getOrCreateClassMetadataDefinition(string $className, ?ClassMetadata $parent) : ClassMetadataDefinition
{
if (! isset($this->definitions[$className])) {
$this->definitions[$className] = $this->definitionFactory->build($className, $parent);
}
return $this->definitions[$className];
} | [
"private",
"function",
"getOrCreateClassMetadataDefinition",
"(",
"string",
"$",
"className",
",",
"?",
"ClassMetadata",
"$",
"parent",
")",
":",
"ClassMetadataDefinition",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"definitions",
"[",
"$",
"className",
"]",
")",
")",
"{",
"$",
"this",
"->",
"definitions",
"[",
"$",
"className",
"]",
"=",
"$",
"this",
"->",
"definitionFactory",
"->",
"build",
"(",
"$",
"className",
",",
"$",
"parent",
")",
";",
"}",
"return",
"$",
"this",
"->",
"definitions",
"[",
"$",
"className",
"]",
";",
"}"
] | Create a class metadata definition for the given class name. | [
"Create",
"a",
"class",
"metadata",
"definition",
"for",
"the",
"given",
"class",
"name",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Mapping/Factory/AbstractClassMetadataFactory.php#L152-L159 | train |
doctrine/orm | lib/Doctrine/ORM/Cache/Logging/StatisticsCacheLogger.php | StatisticsCacheLogger.clearRegionStats | public function clearRegionStats($regionName)
{
$this->cachePutCountMap[$regionName] = 0;
$this->cacheHitCountMap[$regionName] = 0;
$this->cacheMissCountMap[$regionName] = 0;
} | php | public function clearRegionStats($regionName)
{
$this->cachePutCountMap[$regionName] = 0;
$this->cacheHitCountMap[$regionName] = 0;
$this->cacheMissCountMap[$regionName] = 0;
} | [
"public",
"function",
"clearRegionStats",
"(",
"$",
"regionName",
")",
"{",
"$",
"this",
"->",
"cachePutCountMap",
"[",
"$",
"regionName",
"]",
"=",
"0",
";",
"$",
"this",
"->",
"cacheHitCountMap",
"[",
"$",
"regionName",
"]",
"=",
"0",
";",
"$",
"this",
"->",
"cacheMissCountMap",
"[",
"$",
"regionName",
"]",
"=",
"0",
";",
"}"
] | Clear region statistics
@param string $regionName The name of the cache region. | [
"Clear",
"region",
"statistics"
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Cache/Logging/StatisticsCacheLogger.php#L181-L186 | train |
doctrine/orm | lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php | BasicEntityPersister.getSelectColumnSQL | protected function getSelectColumnSQL($field, ClassMetadata $class, $alias = 'r')
{
$property = $class->getProperty($field);
$columnAlias = $this->getSQLColumnAlias();
$sql = sprintf(
'%s.%s',
$this->getSQLTableAlias($property->getTableName(), ($alias === 'r' ? '' : $alias)),
$this->platform->quoteIdentifier($property->getColumnName())
);
$this->currentPersisterContext->rsm->addFieldResult($alias, $columnAlias, $field, $class->getClassName());
return $property->getType()->convertToPHPValueSQL($sql, $this->platform) . ' AS ' . $columnAlias;
} | php | protected function getSelectColumnSQL($field, ClassMetadata $class, $alias = 'r')
{
$property = $class->getProperty($field);
$columnAlias = $this->getSQLColumnAlias();
$sql = sprintf(
'%s.%s',
$this->getSQLTableAlias($property->getTableName(), ($alias === 'r' ? '' : $alias)),
$this->platform->quoteIdentifier($property->getColumnName())
);
$this->currentPersisterContext->rsm->addFieldResult($alias, $columnAlias, $field, $class->getClassName());
return $property->getType()->convertToPHPValueSQL($sql, $this->platform) . ' AS ' . $columnAlias;
} | [
"protected",
"function",
"getSelectColumnSQL",
"(",
"$",
"field",
",",
"ClassMetadata",
"$",
"class",
",",
"$",
"alias",
"=",
"'r'",
")",
"{",
"$",
"property",
"=",
"$",
"class",
"->",
"getProperty",
"(",
"$",
"field",
")",
";",
"$",
"columnAlias",
"=",
"$",
"this",
"->",
"getSQLColumnAlias",
"(",
")",
";",
"$",
"sql",
"=",
"sprintf",
"(",
"'%s.%s'",
",",
"$",
"this",
"->",
"getSQLTableAlias",
"(",
"$",
"property",
"->",
"getTableName",
"(",
")",
",",
"(",
"$",
"alias",
"===",
"'r'",
"?",
"''",
":",
"$",
"alias",
")",
")",
",",
"$",
"this",
"->",
"platform",
"->",
"quoteIdentifier",
"(",
"$",
"property",
"->",
"getColumnName",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"currentPersisterContext",
"->",
"rsm",
"->",
"addFieldResult",
"(",
"$",
"alias",
",",
"$",
"columnAlias",
",",
"$",
"field",
",",
"$",
"class",
"->",
"getClassName",
"(",
")",
")",
";",
"return",
"$",
"property",
"->",
"getType",
"(",
")",
"->",
"convertToPHPValueSQL",
"(",
"$",
"sql",
",",
"$",
"this",
"->",
"platform",
")",
".",
"' AS '",
".",
"$",
"columnAlias",
";",
"}"
] | Gets the SQL snippet of a qualified column name for the given field name.
@param string $field The field name.
@param ClassMetadata $class The class that declares this field. The table this class is
mapped to must own the column for the given field.
@param string $alias
@return string | [
"Gets",
"the",
"SQL",
"snippet",
"of",
"a",
"qualified",
"column",
"name",
"for",
"the",
"given",
"field",
"name",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php#L1581-L1594 | train |
doctrine/orm | lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php | BasicEntityPersister.getSelectConditionCriteriaSQL | protected function getSelectConditionCriteriaSQL(Criteria $criteria)
{
$expression = $criteria->getWhereExpression();
if ($expression === null) {
return '';
}
$visitor = new SqlExpressionVisitor($this, $this->class);
return $visitor->dispatch($expression);
} | php | protected function getSelectConditionCriteriaSQL(Criteria $criteria)
{
$expression = $criteria->getWhereExpression();
if ($expression === null) {
return '';
}
$visitor = new SqlExpressionVisitor($this, $this->class);
return $visitor->dispatch($expression);
} | [
"protected",
"function",
"getSelectConditionCriteriaSQL",
"(",
"Criteria",
"$",
"criteria",
")",
"{",
"$",
"expression",
"=",
"$",
"criteria",
"->",
"getWhereExpression",
"(",
")",
";",
"if",
"(",
"$",
"expression",
"===",
"null",
")",
"{",
"return",
"''",
";",
"}",
"$",
"visitor",
"=",
"new",
"SqlExpressionVisitor",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"class",
")",
";",
"return",
"$",
"visitor",
"->",
"dispatch",
"(",
"$",
"expression",
")",
";",
"}"
] | Gets the Select Where Condition from a Criteria object.
@return string | [
"Gets",
"the",
"Select",
"Where",
"Condition",
"from",
"a",
"Criteria",
"object",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php#L1673-L1684 | train |
doctrine/orm | lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php | BasicEntityPersister.getIndividualValue | private function getIndividualValue($value)
{
if (! is_object($value) || ! $this->em->getMetadataFactory()->hasMetadataFor(StaticClassNameConverter::getClass($value))) {
return $value;
}
return $this->em->getUnitOfWork()->getSingleIdentifierValue($value);
} | php | private function getIndividualValue($value)
{
if (! is_object($value) || ! $this->em->getMetadataFactory()->hasMetadataFor(StaticClassNameConverter::getClass($value))) {
return $value;
}
return $this->em->getUnitOfWork()->getSingleIdentifierValue($value);
} | [
"private",
"function",
"getIndividualValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"value",
")",
"||",
"!",
"$",
"this",
"->",
"em",
"->",
"getMetadataFactory",
"(",
")",
"->",
"hasMetadataFor",
"(",
"StaticClassNameConverter",
"::",
"getClass",
"(",
"$",
"value",
")",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"return",
"$",
"this",
"->",
"em",
"->",
"getUnitOfWork",
"(",
")",
"->",
"getSingleIdentifierValue",
"(",
"$",
"value",
")",
";",
"}"
] | Retrieves an individual parameter value.
@param mixed $value
@return mixed | [
"Retrieves",
"an",
"individual",
"parameter",
"value",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php#L2089-L2096 | train |
doctrine/orm | lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php | BasicEntityPersister.getJoinSQLForAssociation | protected function getJoinSQLForAssociation(AssociationMetadata $association)
{
if (! $association->isOwningSide()) {
return 'LEFT JOIN';
}
// if one of the join columns is nullable, return left join
foreach ($association->getJoinColumns() as $joinColumn) {
if (! $joinColumn->isNullable()) {
continue;
}
return 'LEFT JOIN';
}
return 'INNER JOIN';
} | php | protected function getJoinSQLForAssociation(AssociationMetadata $association)
{
if (! $association->isOwningSide()) {
return 'LEFT JOIN';
}
// if one of the join columns is nullable, return left join
foreach ($association->getJoinColumns() as $joinColumn) {
if (! $joinColumn->isNullable()) {
continue;
}
return 'LEFT JOIN';
}
return 'INNER JOIN';
} | [
"protected",
"function",
"getJoinSQLForAssociation",
"(",
"AssociationMetadata",
"$",
"association",
")",
"{",
"if",
"(",
"!",
"$",
"association",
"->",
"isOwningSide",
"(",
")",
")",
"{",
"return",
"'LEFT JOIN'",
";",
"}",
"// if one of the join columns is nullable, return left join",
"foreach",
"(",
"$",
"association",
"->",
"getJoinColumns",
"(",
")",
"as",
"$",
"joinColumn",
")",
"{",
"if",
"(",
"!",
"$",
"joinColumn",
"->",
"isNullable",
"(",
")",
")",
"{",
"continue",
";",
"}",
"return",
"'LEFT JOIN'",
";",
"}",
"return",
"'INNER JOIN'",
";",
"}"
] | Generates the appropriate join SQL for the given association.
@return string LEFT JOIN if one of the columns is nullable, INNER JOIN otherwise. | [
"Generates",
"the",
"appropriate",
"join",
"SQL",
"for",
"the",
"given",
"association",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php#L2139-L2155 | train |
doctrine/orm | lib/Doctrine/ORM/Query/SqlWalker.php | SqlWalker.setSQLTableAlias | public function setSQLTableAlias($tableName, $alias, $dqlAlias = '')
{
$tableName .= $dqlAlias ? '@[' . $dqlAlias . ']' : '';
$this->tableAliasMap[$tableName] = $alias;
return $alias;
} | php | public function setSQLTableAlias($tableName, $alias, $dqlAlias = '')
{
$tableName .= $dqlAlias ? '@[' . $dqlAlias . ']' : '';
$this->tableAliasMap[$tableName] = $alias;
return $alias;
} | [
"public",
"function",
"setSQLTableAlias",
"(",
"$",
"tableName",
",",
"$",
"alias",
",",
"$",
"dqlAlias",
"=",
"''",
")",
"{",
"$",
"tableName",
".=",
"$",
"dqlAlias",
"?",
"'@['",
".",
"$",
"dqlAlias",
".",
"']'",
":",
"''",
";",
"$",
"this",
"->",
"tableAliasMap",
"[",
"$",
"tableName",
"]",
"=",
"$",
"alias",
";",
"return",
"$",
"alias",
";",
"}"
] | Forces the SqlWalker to use a specific alias for a table name, rather than
generating an alias on its own.
@param string $tableName
@param string $alias
@param string $dqlAlias
@return string | [
"Forces",
"the",
"SqlWalker",
"to",
"use",
"a",
"specific",
"alias",
"for",
"a",
"table",
"name",
"rather",
"than",
"generating",
"an",
"alias",
"on",
"its",
"own",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Query/SqlWalker.php#L292-L299 | train |
doctrine/orm | lib/Doctrine/ORM/Query/SqlWalker.php | SqlWalker.walkIdentificationVariableDeclaration | public function walkIdentificationVariableDeclaration($identificationVariableDecl)
{
$sql = $this->walkRangeVariableDeclaration($identificationVariableDecl->rangeVariableDeclaration);
if ($identificationVariableDecl->indexBy) {
$this->walkIndexBy($identificationVariableDecl->indexBy);
}
foreach ($identificationVariableDecl->joins as $join) {
$sql .= $this->walkJoin($join);
}
return $sql;
} | php | public function walkIdentificationVariableDeclaration($identificationVariableDecl)
{
$sql = $this->walkRangeVariableDeclaration($identificationVariableDecl->rangeVariableDeclaration);
if ($identificationVariableDecl->indexBy) {
$this->walkIndexBy($identificationVariableDecl->indexBy);
}
foreach ($identificationVariableDecl->joins as $join) {
$sql .= $this->walkJoin($join);
}
return $sql;
} | [
"public",
"function",
"walkIdentificationVariableDeclaration",
"(",
"$",
"identificationVariableDecl",
")",
"{",
"$",
"sql",
"=",
"$",
"this",
"->",
"walkRangeVariableDeclaration",
"(",
"$",
"identificationVariableDecl",
"->",
"rangeVariableDeclaration",
")",
";",
"if",
"(",
"$",
"identificationVariableDecl",
"->",
"indexBy",
")",
"{",
"$",
"this",
"->",
"walkIndexBy",
"(",
"$",
"identificationVariableDecl",
"->",
"indexBy",
")",
";",
"}",
"foreach",
"(",
"$",
"identificationVariableDecl",
"->",
"joins",
"as",
"$",
"join",
")",
"{",
"$",
"sql",
".=",
"$",
"this",
"->",
"walkJoin",
"(",
"$",
"join",
")",
";",
"}",
"return",
"$",
"sql",
";",
"}"
] | Walks down a IdentificationVariableDeclaration AST node, thereby generating the appropriate SQL.
@param AST\IdentificationVariableDeclaration $identificationVariableDecl
@return string | [
"Walks",
"down",
"a",
"IdentificationVariableDeclaration",
"AST",
"node",
"thereby",
"generating",
"the",
"appropriate",
"SQL",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Query/SqlWalker.php#L864-L877 | train |
doctrine/orm | lib/Doctrine/ORM/Query/SqlWalker.php | SqlWalker.walkIndexBy | public function walkIndexBy($indexBy)
{
$pathExpression = $indexBy->simpleStateFieldPathExpression;
$alias = $pathExpression->identificationVariable;
$field = $pathExpression->field;
if (isset($this->scalarFields[$alias][$field])) {
$this->rsm->addIndexByScalar($this->scalarFields[$alias][$field]);
return;
}
$this->rsm->addIndexBy($alias, $field);
} | php | public function walkIndexBy($indexBy)
{
$pathExpression = $indexBy->simpleStateFieldPathExpression;
$alias = $pathExpression->identificationVariable;
$field = $pathExpression->field;
if (isset($this->scalarFields[$alias][$field])) {
$this->rsm->addIndexByScalar($this->scalarFields[$alias][$field]);
return;
}
$this->rsm->addIndexBy($alias, $field);
} | [
"public",
"function",
"walkIndexBy",
"(",
"$",
"indexBy",
")",
"{",
"$",
"pathExpression",
"=",
"$",
"indexBy",
"->",
"simpleStateFieldPathExpression",
";",
"$",
"alias",
"=",
"$",
"pathExpression",
"->",
"identificationVariable",
";",
"$",
"field",
"=",
"$",
"pathExpression",
"->",
"field",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"scalarFields",
"[",
"$",
"alias",
"]",
"[",
"$",
"field",
"]",
")",
")",
"{",
"$",
"this",
"->",
"rsm",
"->",
"addIndexByScalar",
"(",
"$",
"this",
"->",
"scalarFields",
"[",
"$",
"alias",
"]",
"[",
"$",
"field",
"]",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"rsm",
"->",
"addIndexBy",
"(",
"$",
"alias",
",",
"$",
"field",
")",
";",
"}"
] | Walks down a IndexBy AST node.
@param AST\IndexBy $indexBy | [
"Walks",
"down",
"a",
"IndexBy",
"AST",
"node",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Query/SqlWalker.php#L884-L897 | train |
doctrine/orm | lib/Doctrine/ORM/Query/SqlWalker.php | SqlWalker.generateRangeVariableDeclarationSQL | private function generateRangeVariableDeclarationSQL($rangeVariableDeclaration, bool $buildNestedJoins) : string
{
$class = $this->em->getClassMetadata($rangeVariableDeclaration->abstractSchemaName);
$dqlAlias = $rangeVariableDeclaration->aliasIdentificationVariable;
if ($rangeVariableDeclaration->isRoot) {
$this->rootAliases[] = $dqlAlias;
}
$tableName = $class->table->getQuotedQualifiedName($this->platform);
$tableAlias = $this->getSQLTableAlias($class->getTableName(), $dqlAlias);
$sql = $this->platform->appendLockHint(
$tableName . ' ' . $tableAlias,
$this->query->getHint(Query::HINT_LOCK_MODE)
);
if ($class->inheritanceType !== InheritanceType::JOINED) {
return $sql;
}
$classTableInheritanceJoins = $this->generateClassTableInheritanceJoins($class, $dqlAlias);
if (! $buildNestedJoins) {
return $sql . $classTableInheritanceJoins;
}
return $classTableInheritanceJoins === '' ? $sql : '(' . $sql . $classTableInheritanceJoins . ')';
} | php | private function generateRangeVariableDeclarationSQL($rangeVariableDeclaration, bool $buildNestedJoins) : string
{
$class = $this->em->getClassMetadata($rangeVariableDeclaration->abstractSchemaName);
$dqlAlias = $rangeVariableDeclaration->aliasIdentificationVariable;
if ($rangeVariableDeclaration->isRoot) {
$this->rootAliases[] = $dqlAlias;
}
$tableName = $class->table->getQuotedQualifiedName($this->platform);
$tableAlias = $this->getSQLTableAlias($class->getTableName(), $dqlAlias);
$sql = $this->platform->appendLockHint(
$tableName . ' ' . $tableAlias,
$this->query->getHint(Query::HINT_LOCK_MODE)
);
if ($class->inheritanceType !== InheritanceType::JOINED) {
return $sql;
}
$classTableInheritanceJoins = $this->generateClassTableInheritanceJoins($class, $dqlAlias);
if (! $buildNestedJoins) {
return $sql . $classTableInheritanceJoins;
}
return $classTableInheritanceJoins === '' ? $sql : '(' . $sql . $classTableInheritanceJoins . ')';
} | [
"private",
"function",
"generateRangeVariableDeclarationSQL",
"(",
"$",
"rangeVariableDeclaration",
",",
"bool",
"$",
"buildNestedJoins",
")",
":",
"string",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"em",
"->",
"getClassMetadata",
"(",
"$",
"rangeVariableDeclaration",
"->",
"abstractSchemaName",
")",
";",
"$",
"dqlAlias",
"=",
"$",
"rangeVariableDeclaration",
"->",
"aliasIdentificationVariable",
";",
"if",
"(",
"$",
"rangeVariableDeclaration",
"->",
"isRoot",
")",
"{",
"$",
"this",
"->",
"rootAliases",
"[",
"]",
"=",
"$",
"dqlAlias",
";",
"}",
"$",
"tableName",
"=",
"$",
"class",
"->",
"table",
"->",
"getQuotedQualifiedName",
"(",
"$",
"this",
"->",
"platform",
")",
";",
"$",
"tableAlias",
"=",
"$",
"this",
"->",
"getSQLTableAlias",
"(",
"$",
"class",
"->",
"getTableName",
"(",
")",
",",
"$",
"dqlAlias",
")",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"platform",
"->",
"appendLockHint",
"(",
"$",
"tableName",
".",
"' '",
".",
"$",
"tableAlias",
",",
"$",
"this",
"->",
"query",
"->",
"getHint",
"(",
"Query",
"::",
"HINT_LOCK_MODE",
")",
")",
";",
"if",
"(",
"$",
"class",
"->",
"inheritanceType",
"!==",
"InheritanceType",
"::",
"JOINED",
")",
"{",
"return",
"$",
"sql",
";",
"}",
"$",
"classTableInheritanceJoins",
"=",
"$",
"this",
"->",
"generateClassTableInheritanceJoins",
"(",
"$",
"class",
",",
"$",
"dqlAlias",
")",
";",
"if",
"(",
"!",
"$",
"buildNestedJoins",
")",
"{",
"return",
"$",
"sql",
".",
"$",
"classTableInheritanceJoins",
";",
"}",
"return",
"$",
"classTableInheritanceJoins",
"===",
"''",
"?",
"$",
"sql",
":",
"'('",
".",
"$",
"sql",
".",
"$",
"classTableInheritanceJoins",
".",
"')'",
";",
"}"
] | Generate appropriate SQL for RangeVariableDeclaration AST node
@param AST\RangeVariableDeclaration $rangeVariableDeclaration | [
"Generate",
"appropriate",
"SQL",
"for",
"RangeVariableDeclaration",
"AST",
"node"
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Query/SqlWalker.php#L916-L944 | train |
doctrine/orm | lib/Doctrine/ORM/Query/SqlWalker.php | SqlWalker.walkCoalesceExpression | public function walkCoalesceExpression($coalesceExpression)
{
$sql = 'COALESCE(';
$scalarExpressions = [];
foreach ($coalesceExpression->scalarExpressions as $scalarExpression) {
$scalarExpressions[] = $this->walkSimpleArithmeticExpression($scalarExpression);
}
return $sql . implode(', ', $scalarExpressions) . ')';
} | php | public function walkCoalesceExpression($coalesceExpression)
{
$sql = 'COALESCE(';
$scalarExpressions = [];
foreach ($coalesceExpression->scalarExpressions as $scalarExpression) {
$scalarExpressions[] = $this->walkSimpleArithmeticExpression($scalarExpression);
}
return $sql . implode(', ', $scalarExpressions) . ')';
} | [
"public",
"function",
"walkCoalesceExpression",
"(",
"$",
"coalesceExpression",
")",
"{",
"$",
"sql",
"=",
"'COALESCE('",
";",
"$",
"scalarExpressions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"coalesceExpression",
"->",
"scalarExpressions",
"as",
"$",
"scalarExpression",
")",
"{",
"$",
"scalarExpressions",
"[",
"]",
"=",
"$",
"this",
"->",
"walkSimpleArithmeticExpression",
"(",
"$",
"scalarExpression",
")",
";",
"}",
"return",
"$",
"sql",
".",
"implode",
"(",
"', '",
",",
"$",
"scalarExpressions",
")",
".",
"')'",
";",
"}"
] | Walks down a CoalesceExpression AST node and generates the corresponding SQL.
@param AST\CoalesceExpression $coalesceExpression
@return string The SQL. | [
"Walks",
"down",
"a",
"CoalesceExpression",
"AST",
"node",
"and",
"generates",
"the",
"corresponding",
"SQL",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Query/SqlWalker.php#L1252-L1263 | train |
doctrine/orm | lib/Doctrine/ORM/Query/SqlWalker.php | SqlWalker.walkNullIfExpression | public function walkNullIfExpression($nullIfExpression)
{
$firstExpression = is_string($nullIfExpression->firstExpression)
? $this->conn->quote($nullIfExpression->firstExpression)
: $this->walkSimpleArithmeticExpression($nullIfExpression->firstExpression);
$secondExpression = is_string($nullIfExpression->secondExpression)
? $this->conn->quote($nullIfExpression->secondExpression)
: $this->walkSimpleArithmeticExpression($nullIfExpression->secondExpression);
return 'NULLIF(' . $firstExpression . ', ' . $secondExpression . ')';
} | php | public function walkNullIfExpression($nullIfExpression)
{
$firstExpression = is_string($nullIfExpression->firstExpression)
? $this->conn->quote($nullIfExpression->firstExpression)
: $this->walkSimpleArithmeticExpression($nullIfExpression->firstExpression);
$secondExpression = is_string($nullIfExpression->secondExpression)
? $this->conn->quote($nullIfExpression->secondExpression)
: $this->walkSimpleArithmeticExpression($nullIfExpression->secondExpression);
return 'NULLIF(' . $firstExpression . ', ' . $secondExpression . ')';
} | [
"public",
"function",
"walkNullIfExpression",
"(",
"$",
"nullIfExpression",
")",
"{",
"$",
"firstExpression",
"=",
"is_string",
"(",
"$",
"nullIfExpression",
"->",
"firstExpression",
")",
"?",
"$",
"this",
"->",
"conn",
"->",
"quote",
"(",
"$",
"nullIfExpression",
"->",
"firstExpression",
")",
":",
"$",
"this",
"->",
"walkSimpleArithmeticExpression",
"(",
"$",
"nullIfExpression",
"->",
"firstExpression",
")",
";",
"$",
"secondExpression",
"=",
"is_string",
"(",
"$",
"nullIfExpression",
"->",
"secondExpression",
")",
"?",
"$",
"this",
"->",
"conn",
"->",
"quote",
"(",
"$",
"nullIfExpression",
"->",
"secondExpression",
")",
":",
"$",
"this",
"->",
"walkSimpleArithmeticExpression",
"(",
"$",
"nullIfExpression",
"->",
"secondExpression",
")",
";",
"return",
"'NULLIF('",
".",
"$",
"firstExpression",
".",
"', '",
".",
"$",
"secondExpression",
".",
"')'",
";",
"}"
] | Walks down a NullIfExpression AST node and generates the corresponding SQL.
@param AST\NullIfExpression $nullIfExpression
@return string The SQL. | [
"Walks",
"down",
"a",
"NullIfExpression",
"AST",
"node",
"and",
"generates",
"the",
"corresponding",
"SQL",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Query/SqlWalker.php#L1272-L1283 | train |
doctrine/orm | lib/Doctrine/ORM/Query/SqlWalker.php | SqlWalker.walkGeneralCaseExpression | public function walkGeneralCaseExpression(AST\GeneralCaseExpression $generalCaseExpression)
{
$sql = 'CASE';
foreach ($generalCaseExpression->whenClauses as $whenClause) {
$sql .= ' WHEN ' . $this->walkConditionalExpression($whenClause->caseConditionExpression);
$sql .= ' THEN ' . $this->walkSimpleArithmeticExpression($whenClause->thenScalarExpression);
}
$sql .= ' ELSE ' . $this->walkSimpleArithmeticExpression($generalCaseExpression->elseScalarExpression) . ' END';
return $sql;
} | php | public function walkGeneralCaseExpression(AST\GeneralCaseExpression $generalCaseExpression)
{
$sql = 'CASE';
foreach ($generalCaseExpression->whenClauses as $whenClause) {
$sql .= ' WHEN ' . $this->walkConditionalExpression($whenClause->caseConditionExpression);
$sql .= ' THEN ' . $this->walkSimpleArithmeticExpression($whenClause->thenScalarExpression);
}
$sql .= ' ELSE ' . $this->walkSimpleArithmeticExpression($generalCaseExpression->elseScalarExpression) . ' END';
return $sql;
} | [
"public",
"function",
"walkGeneralCaseExpression",
"(",
"AST",
"\\",
"GeneralCaseExpression",
"$",
"generalCaseExpression",
")",
"{",
"$",
"sql",
"=",
"'CASE'",
";",
"foreach",
"(",
"$",
"generalCaseExpression",
"->",
"whenClauses",
"as",
"$",
"whenClause",
")",
"{",
"$",
"sql",
".=",
"' WHEN '",
".",
"$",
"this",
"->",
"walkConditionalExpression",
"(",
"$",
"whenClause",
"->",
"caseConditionExpression",
")",
";",
"$",
"sql",
".=",
"' THEN '",
".",
"$",
"this",
"->",
"walkSimpleArithmeticExpression",
"(",
"$",
"whenClause",
"->",
"thenScalarExpression",
")",
";",
"}",
"$",
"sql",
".=",
"' ELSE '",
".",
"$",
"this",
"->",
"walkSimpleArithmeticExpression",
"(",
"$",
"generalCaseExpression",
"->",
"elseScalarExpression",
")",
".",
"' END'",
";",
"return",
"$",
"sql",
";",
"}"
] | Walks down a GeneralCaseExpression AST node and generates the corresponding SQL.
@return string The SQL. | [
"Walks",
"down",
"a",
"GeneralCaseExpression",
"AST",
"node",
"and",
"generates",
"the",
"corresponding",
"SQL",
"."
] | 8bb91280ed1d359c421f4b49ffca6d4453f1ef16 | https://github.com/doctrine/orm/blob/8bb91280ed1d359c421f4b49ffca6d4453f1ef16/lib/Doctrine/ORM/Query/SqlWalker.php#L1290-L1302 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.