repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6 values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1 value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
FrozenNode/Laravel-Administrator | src/Frozennode/Administrator/Includes/Resize.php | Resize.open_image | private function open_image( $file )
{
$sfile = new SFile($file);
// If $file isn't an array, we'll turn it into one
if ( !is_array($file) ) {
$file = array(
'type' => $sfile->getMimeType(),
'tmp_name' => $file
);
}
$mime = $file['type'];
$file_path = $file['tmp_name'];
switch ( $mime )
{
case 'image/pjpeg': // IE6
case 'image/jpeg': $img = @imagecreatefromjpeg( $file_path ); break;
case 'image/gif': $img = @imagecreatefromgif( $file_path ); break;
case 'image/png': $img = @imagecreatefrompng( $file_path ); break;
default: $img = false; break;
}
return $img;
} | php | private function open_image( $file )
{
$sfile = new SFile($file);
// If $file isn't an array, we'll turn it into one
if ( !is_array($file) ) {
$file = array(
'type' => $sfile->getMimeType(),
'tmp_name' => $file
);
}
$mime = $file['type'];
$file_path = $file['tmp_name'];
switch ( $mime )
{
case 'image/pjpeg': // IE6
case 'image/jpeg': $img = @imagecreatefromjpeg( $file_path ); break;
case 'image/gif': $img = @imagecreatefromgif( $file_path ); break;
case 'image/png': $img = @imagecreatefrompng( $file_path ); break;
default: $img = false; break;
}
return $img;
} | [
"private",
"function",
"open_image",
"(",
"$",
"file",
")",
"{",
"$",
"sfile",
"=",
"new",
"SFile",
"(",
"$",
"file",
")",
";",
"// If $file isn't an array, we'll turn it into one",
"if",
"(",
"!",
"is_array",
"(",
"$",
"file",
")",
")",
"{",
"$",
"file",
"=",
"array",
"(",
"'type'",
"=>",
"$",
"sfile",
"->",
"getMimeType",
"(",
")",
",",
"'tmp_name'",
"=>",
"$",
"file",
")",
";",
"}",
"$",
"mime",
"=",
"$",
"file",
"[",
"'type'",
"]",
";",
"$",
"file_path",
"=",
"$",
"file",
"[",
"'tmp_name'",
"]",
";",
"switch",
"(",
"$",
"mime",
")",
"{",
"case",
"'image/pjpeg'",
":",
"// IE6",
"case",
"'image/jpeg'",
":",
"$",
"img",
"=",
"@",
"imagecreatefromjpeg",
"(",
"$",
"file_path",
")",
";",
"break",
";",
"case",
"'image/gif'",
":",
"$",
"img",
"=",
"@",
"imagecreatefromgif",
"(",
"$",
"file_path",
")",
";",
"break",
";",
"case",
"'image/png'",
":",
"$",
"img",
"=",
"@",
"imagecreatefrompng",
"(",
"$",
"file_path",
")",
";",
"break",
";",
"default",
":",
"$",
"img",
"=",
"false",
";",
"break",
";",
"}",
"return",
"$",
"img",
";",
"}"
] | Open a file, detect its mime-type and create an image resrource from it.
@param array $file Attributes of file from the $_FILES array
@return mixed | [
"Open",
"a",
"file",
"detect",
"its",
"mime",
"-",
"type",
"and",
"create",
"an",
"image",
"resrource",
"from",
"it",
"."
] | train | https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/Includes/Resize.php#L172-L197 |
FrozenNode/Laravel-Administrator | src/Frozennode/Administrator/Includes/Resize.php | Resize.get_optimal_crop | private function get_optimal_crop( $new_width , $new_height )
{
$height_ratio = $this->height / $new_height;
$width_ratio = $this->width / $new_width;
if ( $height_ratio < $width_ratio ) {
$optimal_ratio = $height_ratio;
} else {
$optimal_ratio = $width_ratio;
}
$optimal_height = $this->height / $optimal_ratio;
$optimal_width = $this->width / $optimal_ratio;
return array(
'optimal_width' => $optimal_width,
'optimal_height' => $optimal_height
);
} | php | private function get_optimal_crop( $new_width , $new_height )
{
$height_ratio = $this->height / $new_height;
$width_ratio = $this->width / $new_width;
if ( $height_ratio < $width_ratio ) {
$optimal_ratio = $height_ratio;
} else {
$optimal_ratio = $width_ratio;
}
$optimal_height = $this->height / $optimal_ratio;
$optimal_width = $this->width / $optimal_ratio;
return array(
'optimal_width' => $optimal_width,
'optimal_height' => $optimal_height
);
} | [
"private",
"function",
"get_optimal_crop",
"(",
"$",
"new_width",
",",
"$",
"new_height",
")",
"{",
"$",
"height_ratio",
"=",
"$",
"this",
"->",
"height",
"/",
"$",
"new_height",
";",
"$",
"width_ratio",
"=",
"$",
"this",
"->",
"width",
"/",
"$",
"new_width",
";",
"if",
"(",
"$",
"height_ratio",
"<",
"$",
"width_ratio",
")",
"{",
"$",
"optimal_ratio",
"=",
"$",
"height_ratio",
";",
"}",
"else",
"{",
"$",
"optimal_ratio",
"=",
"$",
"width_ratio",
";",
"}",
"$",
"optimal_height",
"=",
"$",
"this",
"->",
"height",
"/",
"$",
"optimal_ratio",
";",
"$",
"optimal_width",
"=",
"$",
"this",
"->",
"width",
"/",
"$",
"optimal_ratio",
";",
"return",
"array",
"(",
"'optimal_width'",
"=>",
"$",
"optimal_width",
",",
"'optimal_height'",
"=>",
"$",
"optimal_height",
")",
";",
"}"
] | Attempts to find the best way to crop. Whether crop is based on the
image being portrait or landscape.
@param int $new_width The width of the image
@param int $new_height The height of the image
@return array | [
"Attempts",
"to",
"find",
"the",
"best",
"way",
"to",
"crop",
".",
"Whether",
"crop",
"is",
"based",
"on",
"the",
"image",
"being",
"portrait",
"or",
"landscape",
"."
] | train | https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/Includes/Resize.php#L345-L363 |
FrozenNode/Laravel-Administrator | src/Frozennode/Administrator/Actions/Action.php | Action.validateOptions | public function validateOptions()
{
//override the config
$this->validator->override($this->suppliedOptions, $this->rules);
//if the validator failed, throw an exception
if ($this->validator->fails())
{
throw new \InvalidArgumentException("There are problems with your '" . $this->suppliedOptions['action_name'] . "' action in the " .
$this->config->getOption('name') . " model: " . implode('. ', $this->validator->messages()->all()));
}
} | php | public function validateOptions()
{
//override the config
$this->validator->override($this->suppliedOptions, $this->rules);
//if the validator failed, throw an exception
if ($this->validator->fails())
{
throw new \InvalidArgumentException("There are problems with your '" . $this->suppliedOptions['action_name'] . "' action in the " .
$this->config->getOption('name') . " model: " . implode('. ', $this->validator->messages()->all()));
}
} | [
"public",
"function",
"validateOptions",
"(",
")",
"{",
"//override the config",
"$",
"this",
"->",
"validator",
"->",
"override",
"(",
"$",
"this",
"->",
"suppliedOptions",
",",
"$",
"this",
"->",
"rules",
")",
";",
"//if the validator failed, throw an exception",
"if",
"(",
"$",
"this",
"->",
"validator",
"->",
"fails",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"There are problems with your '\"",
".",
"$",
"this",
"->",
"suppliedOptions",
"[",
"'action_name'",
"]",
".",
"\"' action in the \"",
".",
"$",
"this",
"->",
"config",
"->",
"getOption",
"(",
"'name'",
")",
".",
"\" model: \"",
".",
"implode",
"(",
"'. '",
",",
"$",
"this",
"->",
"validator",
"->",
"messages",
"(",
")",
"->",
"all",
"(",
")",
")",
")",
";",
"}",
"}"
] | Validates the supplied options
@return void | [
"Validates",
"the",
"supplied",
"options"
] | train | https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/Actions/Action.php#L84-L95 |
FrozenNode/Laravel-Administrator | src/Frozennode/Administrator/Actions/Action.php | Action.buildStringOrCallable | public function buildStringOrCallable(array &$options, array $keys)
{
$model = $this->config->getDataModel();
//iterate over the keys
foreach ($keys as $key)
{
//check if the key's value was supplied
$suppliedValue = $this->validator->arrayGet($options, $key);
//if it's a string, simply set it
if (is_string($suppliedValue))
{
$options[$key] = $suppliedValue;
}
//if it's callable pass it the current model and run it
else if (is_callable($suppliedValue))
{
$options[$key] = $suppliedValue($model);
}
}
} | php | public function buildStringOrCallable(array &$options, array $keys)
{
$model = $this->config->getDataModel();
//iterate over the keys
foreach ($keys as $key)
{
//check if the key's value was supplied
$suppliedValue = $this->validator->arrayGet($options, $key);
//if it's a string, simply set it
if (is_string($suppliedValue))
{
$options[$key] = $suppliedValue;
}
//if it's callable pass it the current model and run it
else if (is_callable($suppliedValue))
{
$options[$key] = $suppliedValue($model);
}
}
} | [
"public",
"function",
"buildStringOrCallable",
"(",
"array",
"&",
"$",
"options",
",",
"array",
"$",
"keys",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"config",
"->",
"getDataModel",
"(",
")",
";",
"//iterate over the keys",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"//check if the key's value was supplied",
"$",
"suppliedValue",
"=",
"$",
"this",
"->",
"validator",
"->",
"arrayGet",
"(",
"$",
"options",
",",
"$",
"key",
")",
";",
"//if it's a string, simply set it",
"if",
"(",
"is_string",
"(",
"$",
"suppliedValue",
")",
")",
"{",
"$",
"options",
"[",
"$",
"key",
"]",
"=",
"$",
"suppliedValue",
";",
"}",
"//if it's callable pass it the current model and run it",
"else",
"if",
"(",
"is_callable",
"(",
"$",
"suppliedValue",
")",
")",
"{",
"$",
"options",
"[",
"$",
"key",
"]",
"=",
"$",
"suppliedValue",
"(",
"$",
"model",
")",
";",
"}",
"}",
"}"
] | Sets up the values of all the options that can be either strings or closures
@param array $options //the passed-by-reference array on which to do the transformation
@param array $keys //the keys to check
@return void | [
"Sets",
"up",
"the",
"values",
"of",
"all",
"the",
"options",
"that",
"can",
"be",
"either",
"strings",
"or",
"closures"
] | train | https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/Actions/Action.php#L126-L147 |
Herzult/php-ssh | src/Ssh/Sftp.php | Sftp.mkdir | public function mkdir($dirname, $mod = 0777, $recursive = false)
{
return ssh2_sftp_mkdir($this->getResource(), $dirname, $mod, $recursive);
} | php | public function mkdir($dirname, $mod = 0777, $recursive = false)
{
return ssh2_sftp_mkdir($this->getResource(), $dirname, $mod, $recursive);
} | [
"public",
"function",
"mkdir",
"(",
"$",
"dirname",
",",
"$",
"mod",
"=",
"0777",
",",
"$",
"recursive",
"=",
"false",
")",
"{",
"return",
"ssh2_sftp_mkdir",
"(",
"$",
"this",
"->",
"getResource",
"(",
")",
",",
"$",
"dirname",
",",
"$",
"mod",
",",
"$",
"recursive",
")",
";",
"}"
] | Creates a directory
@param string $dirname The name of the new directory
@param int $mod The permissions on the new directory
@param Boolean $recursive Whether to automatically create any required
parent directory
@return Boolean | [
"Creates",
"a",
"directory"
] | train | https://github.com/Herzult/php-ssh/blob/c56875c7d6a6ef070dee8db2b5e77d6f36a02b55/src/Ssh/Sftp.php#L36-L39 |
Herzult/php-ssh | src/Ssh/Sftp.php | Sftp.listDirectory | public function listDirectory($directory, $recursive = false)
{
$results = $this->scanDirectory($directory, $recursive);
if (false === $results) {
throw new \RuntimeException(sprintf(
'Unable to list directory "%s", maybe it is not a directory '.
'or it does not exist.',
$directory
));
}
return array(
'files' => $results[0],
'directories' => $results[1]
);
} | php | public function listDirectory($directory, $recursive = false)
{
$results = $this->scanDirectory($directory, $recursive);
if (false === $results) {
throw new \RuntimeException(sprintf(
'Unable to list directory "%s", maybe it is not a directory '.
'or it does not exist.',
$directory
));
}
return array(
'files' => $results[0],
'directories' => $results[1]
);
} | [
"public",
"function",
"listDirectory",
"(",
"$",
"directory",
",",
"$",
"recursive",
"=",
"false",
")",
"{",
"$",
"results",
"=",
"$",
"this",
"->",
"scanDirectory",
"(",
"$",
"directory",
",",
"$",
"recursive",
")",
";",
"if",
"(",
"false",
"===",
"$",
"results",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Unable to list directory \"%s\", maybe it is not a directory '",
".",
"'or it does not exist.'",
",",
"$",
"directory",
")",
")",
";",
"}",
"return",
"array",
"(",
"'files'",
"=>",
"$",
"results",
"[",
"0",
"]",
",",
"'directories'",
"=>",
"$",
"results",
"[",
"1",
"]",
")",
";",
"}"
] | Lists files and directories of the specified directory
The returned array is of the form:
array(
'files' => array(...),
'directories' => array(...)
)
@param string $directory
@param Boolean $recursive
@return array | [
"Lists",
"files",
"and",
"directories",
"of",
"the",
"specified",
"directory"
] | train | https://github.com/Herzult/php-ssh/blob/c56875c7d6a6ef070dee8db2b5e77d6f36a02b55/src/Ssh/Sftp.php#L223-L239 |
Herzult/php-ssh | src/Ssh/Sftp.php | Sftp.createResource | protected function createResource()
{
$resource = ssh2_sftp($this->getSessionResource());
if (!is_resource($resource)) {
throw new RuntimeException('The initialization of the SFTP subsystem failed.');
}
$this->resource = $resource;
} | php | protected function createResource()
{
$resource = ssh2_sftp($this->getSessionResource());
if (!is_resource($resource)) {
throw new RuntimeException('The initialization of the SFTP subsystem failed.');
}
$this->resource = $resource;
} | [
"protected",
"function",
"createResource",
"(",
")",
"{",
"$",
"resource",
"=",
"ssh2_sftp",
"(",
"$",
"this",
"->",
"getSessionResource",
"(",
")",
")",
";",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"resource",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'The initialization of the SFTP subsystem failed.'",
")",
";",
"}",
"$",
"this",
"->",
"resource",
"=",
"$",
"resource",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/Herzult/php-ssh/blob/c56875c7d6a6ef070dee8db2b5e77d6f36a02b55/src/Ssh/Sftp.php#L244-L253 |
Herzult/php-ssh | src/Ssh/Sftp.php | Sftp.scanDirectory | private function scanDirectory($directory, $recursive)
{
if (!$results = @scandir($this->getUrl($directory))) {
return false;
}
$files = array();
$directories = array();
foreach ($results as $result) {
if (in_array($result, array('.', '..'))) {
continue;
}
$filename = sprintf('%s/%s', $directory, $result);
if (false === @scandir($this->getUrl($filename))) {
$files[] = $filename;
} else {
$directories[] = $filename;
if ($recursive) {
$children = $this->scanDirectory($filename, $recursive);
if (is_array($children)) {
$files = array_merge($files, $children[0]);
$directories = array_merge($directories, $children[1]);
}
}
}
}
return array($files, $directories);
} | php | private function scanDirectory($directory, $recursive)
{
if (!$results = @scandir($this->getUrl($directory))) {
return false;
}
$files = array();
$directories = array();
foreach ($results as $result) {
if (in_array($result, array('.', '..'))) {
continue;
}
$filename = sprintf('%s/%s', $directory, $result);
if (false === @scandir($this->getUrl($filename))) {
$files[] = $filename;
} else {
$directories[] = $filename;
if ($recursive) {
$children = $this->scanDirectory($filename, $recursive);
if (is_array($children)) {
$files = array_merge($files, $children[0]);
$directories = array_merge($directories, $children[1]);
}
}
}
}
return array($files, $directories);
} | [
"private",
"function",
"scanDirectory",
"(",
"$",
"directory",
",",
"$",
"recursive",
")",
"{",
"if",
"(",
"!",
"$",
"results",
"=",
"@",
"scandir",
"(",
"$",
"this",
"->",
"getUrl",
"(",
"$",
"directory",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"files",
"=",
"array",
"(",
")",
";",
"$",
"directories",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"results",
"as",
"$",
"result",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"result",
",",
"array",
"(",
"'.'",
",",
"'..'",
")",
")",
")",
"{",
"continue",
";",
"}",
"$",
"filename",
"=",
"sprintf",
"(",
"'%s/%s'",
",",
"$",
"directory",
",",
"$",
"result",
")",
";",
"if",
"(",
"false",
"===",
"@",
"scandir",
"(",
"$",
"this",
"->",
"getUrl",
"(",
"$",
"filename",
")",
")",
")",
"{",
"$",
"files",
"[",
"]",
"=",
"$",
"filename",
";",
"}",
"else",
"{",
"$",
"directories",
"[",
"]",
"=",
"$",
"filename",
";",
"if",
"(",
"$",
"recursive",
")",
"{",
"$",
"children",
"=",
"$",
"this",
"->",
"scanDirectory",
"(",
"$",
"filename",
",",
"$",
"recursive",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"children",
")",
")",
"{",
"$",
"files",
"=",
"array_merge",
"(",
"$",
"files",
",",
"$",
"children",
"[",
"0",
"]",
")",
";",
"$",
"directories",
"=",
"array_merge",
"(",
"$",
"directories",
",",
"$",
"children",
"[",
"1",
"]",
")",
";",
"}",
"}",
"}",
"}",
"return",
"array",
"(",
"$",
"files",
",",
"$",
"directories",
")",
";",
"}"
] | Scans a directory
Unfortunately, using a (recursive) directory iterator is not possible
over SFTP: see https://bugs.php.net/bug.php?id=57378. Also, is_dir() is
unreliable and often returns false for valid directories. Therefore, I
use @scandir() instead.
@param string $directory
@param Boolean $recursive
@return array | [
"Scans",
"a",
"directory"
] | train | https://github.com/Herzult/php-ssh/blob/c56875c7d6a6ef070dee8db2b5e77d6f36a02b55/src/Ssh/Sftp.php#L268-L300 |
Herzult/php-ssh | src/Ssh/Session.php | Session.setAuthentication | public function setAuthentication(Authentication $authentication)
{
$firstAuthentication = null === $this->authentication;
$this->authentication = $authentication;
if ($firstAuthentication && is_resource($this->resource)) {
$this->authenticate();
}
} | php | public function setAuthentication(Authentication $authentication)
{
$firstAuthentication = null === $this->authentication;
$this->authentication = $authentication;
if ($firstAuthentication && is_resource($this->resource)) {
$this->authenticate();
}
} | [
"public",
"function",
"setAuthentication",
"(",
"Authentication",
"$",
"authentication",
")",
"{",
"$",
"firstAuthentication",
"=",
"null",
"===",
"$",
"this",
"->",
"authentication",
";",
"$",
"this",
"->",
"authentication",
"=",
"$",
"authentication",
";",
"if",
"(",
"$",
"firstAuthentication",
"&&",
"is_resource",
"(",
"$",
"this",
"->",
"resource",
")",
")",
"{",
"$",
"this",
"->",
"authenticate",
"(",
")",
";",
"}",
"}"
] | Defines the authentication. If the
@param Authentication $authentication | [
"Defines",
"the",
"authentication",
".",
"If",
"the"
] | train | https://github.com/Herzult/php-ssh/blob/c56875c7d6a6ef070dee8db2b5e77d6f36a02b55/src/Ssh/Session.php#L36-L45 |
Herzult/php-ssh | src/Ssh/Session.php | Session.getSubsystem | public function getSubsystem($name)
{
if (!isset($this->subsystems[$name])) {
$this->createSubsystem($name);
}
return $this->subsystems[$name];
} | php | public function getSubsystem($name)
{
if (!isset($this->subsystems[$name])) {
$this->createSubsystem($name);
}
return $this->subsystems[$name];
} | [
"public",
"function",
"getSubsystem",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"subsystems",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"createSubsystem",
"(",
"$",
"name",
")",
";",
"}",
"return",
"$",
"this",
"->",
"subsystems",
"[",
"$",
"name",
"]",
";",
"}"
] | Returns the specified subsystem
If the subsystem does not exists, it will create it
@param string $name The subsystem's name
@return Subsystem | [
"Returns",
"the",
"specified",
"subsystem"
] | train | https://github.com/Herzult/php-ssh/blob/c56875c7d6a6ef070dee8db2b5e77d6f36a02b55/src/Ssh/Session.php#L86-L93 |
Herzult/php-ssh | src/Ssh/Session.php | Session.createSubsystem | protected function createSubsystem($name)
{
switch ($name) {
case 'sftp':
$subsystem = new Sftp($this);
break;
case 'publickey':
$subsystem = new Publickey($this);
break;
case 'exec':
$subsystem = new Exec($this);
break;
default:
throw new InvalidArgumentException(sprintf('The subsystem \'%s\' is not supported.', $name));
}
$this->subsystems[$name] = $subsystem;
} | php | protected function createSubsystem($name)
{
switch ($name) {
case 'sftp':
$subsystem = new Sftp($this);
break;
case 'publickey':
$subsystem = new Publickey($this);
break;
case 'exec':
$subsystem = new Exec($this);
break;
default:
throw new InvalidArgumentException(sprintf('The subsystem \'%s\' is not supported.', $name));
}
$this->subsystems[$name] = $subsystem;
} | [
"protected",
"function",
"createSubsystem",
"(",
"$",
"name",
")",
"{",
"switch",
"(",
"$",
"name",
")",
"{",
"case",
"'sftp'",
":",
"$",
"subsystem",
"=",
"new",
"Sftp",
"(",
"$",
"this",
")",
";",
"break",
";",
"case",
"'publickey'",
":",
"$",
"subsystem",
"=",
"new",
"Publickey",
"(",
"$",
"this",
")",
";",
"break",
";",
"case",
"'exec'",
":",
"$",
"subsystem",
"=",
"new",
"Exec",
"(",
"$",
"this",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The subsystem \\'%s\\' is not supported.'",
",",
"$",
"name",
")",
")",
";",
"}",
"$",
"this",
"->",
"subsystems",
"[",
"$",
"name",
"]",
"=",
"$",
"subsystem",
";",
"}"
] | Creates the specified subsystem
@param string $name The subsystem's name
@throws InvalidArgumentException if the specified subsystem is no
supported (e.g does not exist) | [
"Creates",
"the",
"specified",
"subsystem"
] | train | https://github.com/Herzult/php-ssh/blob/c56875c7d6a6ef070dee8db2b5e77d6f36a02b55/src/Ssh/Session.php#L103-L120 |
Herzult/php-ssh | src/Ssh/Session.php | Session.createResource | protected function createResource()
{
$resource = $this->connect($this->configuration->asArguments());
if (!is_resource($resource)) {
throw new RuntimeException('The SSH connection failed.');
}
$this->resource = $resource;
if (null !== $this->authentication) {
$this->authenticate();
}
} | php | protected function createResource()
{
$resource = $this->connect($this->configuration->asArguments());
if (!is_resource($resource)) {
throw new RuntimeException('The SSH connection failed.');
}
$this->resource = $resource;
if (null !== $this->authentication) {
$this->authenticate();
}
} | [
"protected",
"function",
"createResource",
"(",
")",
"{",
"$",
"resource",
"=",
"$",
"this",
"->",
"connect",
"(",
"$",
"this",
"->",
"configuration",
"->",
"asArguments",
"(",
")",
")",
";",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"resource",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'The SSH connection failed.'",
")",
";",
"}",
"$",
"this",
"->",
"resource",
"=",
"$",
"resource",
";",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"authentication",
")",
"{",
"$",
"this",
"->",
"authenticate",
"(",
")",
";",
"}",
"}"
] | Creates the session resource
If there is a defined authentication, it will authenticate the session
@throws RuntimeException if the connection fail | [
"Creates",
"the",
"session",
"resource"
] | train | https://github.com/Herzult/php-ssh/blob/c56875c7d6a6ef070dee8db2b5e77d6f36a02b55/src/Ssh/Session.php#L129-L142 |
Herzult/php-ssh | src/Ssh/Authentication/PublicKeyFile.php | PublicKeyFile.authenticate | public function authenticate($session)
{
return ssh2_auth_pubkey_file(
$session,
$this->username,
$this->publicKeyFile,
$this->privateKeyFile,
$this->passPhrase
);
} | php | public function authenticate($session)
{
return ssh2_auth_pubkey_file(
$session,
$this->username,
$this->publicKeyFile,
$this->privateKeyFile,
$this->passPhrase
);
} | [
"public",
"function",
"authenticate",
"(",
"$",
"session",
")",
"{",
"return",
"ssh2_auth_pubkey_file",
"(",
"$",
"session",
",",
"$",
"this",
"->",
"username",
",",
"$",
"this",
"->",
"publicKeyFile",
",",
"$",
"this",
"->",
"privateKeyFile",
",",
"$",
"this",
"->",
"passPhrase",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/Herzult/php-ssh/blob/c56875c7d6a6ef070dee8db2b5e77d6f36a02b55/src/Ssh/Authentication/PublicKeyFile.php#L38-L47 |
Herzult/php-ssh | src/Ssh/SshConfigFileConfiguration.php | SshConfigFileConfiguration.parseSshConfigFile | protected function parseSshConfigFile($file)
{
if (!file_exists($file) || !is_readable($file)) {
throw new RuntimeException("The file '$file' does not exist or is not readable");
}
$contents = file_get_contents($file);
$configs = array();
$lineNumber = 1;
foreach (explode(PHP_EOL, $contents) as $line) {
$line = trim($line);
if ($line == '' || $line[0] == '#') {
continue;
}
$pos = strpos($line, '=');
if ($pos !== false) {
$key = strtolower(trim(substr($line, 0, $pos)));
$value = trim(substr($line, $pos + 1, strlen($line)));
} else {
$i = 0;
while ($i < strlen($line)) {
if ($line[$i] == ' ') {
break;
}
$i++;
}
if ($i == strlen($line)) {
throw new RuntimeException("The file '$file' is not parsable at line '$lineNumber'");
}
$key = strtolower(trim(substr($line, 0, $i)));
$value = trim(substr($line, $i + 1, strlen($line)));
}
if ($key == 'host') {
$this->configs = array_merge($this->configs, $configs);
$configs = array();
$hosts = explode(' ', $value);
foreach ($hosts as $host) {
$configs[] = array('host' => $host);
}
} else {
foreach ($configs as $host => $config) {
$configs[$host][$key] = $value;
}
}
$lineNumber++;
}
$this->configs = array_merge($this->configs, $configs);
} | php | protected function parseSshConfigFile($file)
{
if (!file_exists($file) || !is_readable($file)) {
throw new RuntimeException("The file '$file' does not exist or is not readable");
}
$contents = file_get_contents($file);
$configs = array();
$lineNumber = 1;
foreach (explode(PHP_EOL, $contents) as $line) {
$line = trim($line);
if ($line == '' || $line[0] == '#') {
continue;
}
$pos = strpos($line, '=');
if ($pos !== false) {
$key = strtolower(trim(substr($line, 0, $pos)));
$value = trim(substr($line, $pos + 1, strlen($line)));
} else {
$i = 0;
while ($i < strlen($line)) {
if ($line[$i] == ' ') {
break;
}
$i++;
}
if ($i == strlen($line)) {
throw new RuntimeException("The file '$file' is not parsable at line '$lineNumber'");
}
$key = strtolower(trim(substr($line, 0, $i)));
$value = trim(substr($line, $i + 1, strlen($line)));
}
if ($key == 'host') {
$this->configs = array_merge($this->configs, $configs);
$configs = array();
$hosts = explode(' ', $value);
foreach ($hosts as $host) {
$configs[] = array('host' => $host);
}
} else {
foreach ($configs as $host => $config) {
$configs[$host][$key] = $value;
}
}
$lineNumber++;
}
$this->configs = array_merge($this->configs, $configs);
} | [
"protected",
"function",
"parseSshConfigFile",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
"||",
"!",
"is_readable",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"The file '$file' does not exist or is not readable\"",
")",
";",
"}",
"$",
"contents",
"=",
"file_get_contents",
"(",
"$",
"file",
")",
";",
"$",
"configs",
"=",
"array",
"(",
")",
";",
"$",
"lineNumber",
"=",
"1",
";",
"foreach",
"(",
"explode",
"(",
"PHP_EOL",
",",
"$",
"contents",
")",
"as",
"$",
"line",
")",
"{",
"$",
"line",
"=",
"trim",
"(",
"$",
"line",
")",
";",
"if",
"(",
"$",
"line",
"==",
"''",
"||",
"$",
"line",
"[",
"0",
"]",
"==",
"'#'",
")",
"{",
"continue",
";",
"}",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"line",
",",
"'='",
")",
";",
"if",
"(",
"$",
"pos",
"!==",
"false",
")",
"{",
"$",
"key",
"=",
"strtolower",
"(",
"trim",
"(",
"substr",
"(",
"$",
"line",
",",
"0",
",",
"$",
"pos",
")",
")",
")",
";",
"$",
"value",
"=",
"trim",
"(",
"substr",
"(",
"$",
"line",
",",
"$",
"pos",
"+",
"1",
",",
"strlen",
"(",
"$",
"line",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"i",
"=",
"0",
";",
"while",
"(",
"$",
"i",
"<",
"strlen",
"(",
"$",
"line",
")",
")",
"{",
"if",
"(",
"$",
"line",
"[",
"$",
"i",
"]",
"==",
"' '",
")",
"{",
"break",
";",
"}",
"$",
"i",
"++",
";",
"}",
"if",
"(",
"$",
"i",
"==",
"strlen",
"(",
"$",
"line",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"The file '$file' is not parsable at line '$lineNumber'\"",
")",
";",
"}",
"$",
"key",
"=",
"strtolower",
"(",
"trim",
"(",
"substr",
"(",
"$",
"line",
",",
"0",
",",
"$",
"i",
")",
")",
")",
";",
"$",
"value",
"=",
"trim",
"(",
"substr",
"(",
"$",
"line",
",",
"$",
"i",
"+",
"1",
",",
"strlen",
"(",
"$",
"line",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"key",
"==",
"'host'",
")",
"{",
"$",
"this",
"->",
"configs",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"configs",
",",
"$",
"configs",
")",
";",
"$",
"configs",
"=",
"array",
"(",
")",
";",
"$",
"hosts",
"=",
"explode",
"(",
"' '",
",",
"$",
"value",
")",
";",
"foreach",
"(",
"$",
"hosts",
"as",
"$",
"host",
")",
"{",
"$",
"configs",
"[",
"]",
"=",
"array",
"(",
"'host'",
"=>",
"$",
"host",
")",
";",
"}",
"}",
"else",
"{",
"foreach",
"(",
"$",
"configs",
"as",
"$",
"host",
"=>",
"$",
"config",
")",
"{",
"$",
"configs",
"[",
"$",
"host",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"$",
"lineNumber",
"++",
";",
"}",
"$",
"this",
"->",
"configs",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"configs",
",",
"$",
"configs",
")",
";",
"}"
] | Parses the ssh config file into an array of configs for later matching against hosts
@param string $file | [
"Parses",
"the",
"ssh",
"config",
"file",
"into",
"an",
"array",
"of",
"configs",
"for",
"later",
"matching",
"against",
"hosts"
] | train | https://github.com/Herzult/php-ssh/blob/c56875c7d6a6ef070dee8db2b5e77d6f36a02b55/src/Ssh/SshConfigFileConfiguration.php#L61-L108 |
Herzult/php-ssh | src/Ssh/SshConfigFileConfiguration.php | SshConfigFileConfiguration.getConfigForHost | public function getConfigForHost($host)
{
$matches = array();
foreach ($this->configs as $config) {
if (fnmatch($config['host'], $host)) {
$matches[] = $config;
}
}
if (count($matches) == 0) {
throw new RuntimeException("Unable to find configuration for host '{$host}'");
}
usort($matches, function ($a, $b) {
return strlen($a['host']) > strlen($b['host']);
});
$result = array();
foreach ($matches as $match) {
$result = array_merge($result, $match);
}
unset($result['host']);
if (isset($result['identityfile'])) {
$result['identityfile'] = $this->processPath($result['identityfile']);
} else if (file_exists($file = $this->processPath($this->getIdentity()))) {
$result['identityfile'] = $file;
}
return $result;
} | php | public function getConfigForHost($host)
{
$matches = array();
foreach ($this->configs as $config) {
if (fnmatch($config['host'], $host)) {
$matches[] = $config;
}
}
if (count($matches) == 0) {
throw new RuntimeException("Unable to find configuration for host '{$host}'");
}
usort($matches, function ($a, $b) {
return strlen($a['host']) > strlen($b['host']);
});
$result = array();
foreach ($matches as $match) {
$result = array_merge($result, $match);
}
unset($result['host']);
if (isset($result['identityfile'])) {
$result['identityfile'] = $this->processPath($result['identityfile']);
} else if (file_exists($file = $this->processPath($this->getIdentity()))) {
$result['identityfile'] = $file;
}
return $result;
} | [
"public",
"function",
"getConfigForHost",
"(",
"$",
"host",
")",
"{",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"configs",
"as",
"$",
"config",
")",
"{",
"if",
"(",
"fnmatch",
"(",
"$",
"config",
"[",
"'host'",
"]",
",",
"$",
"host",
")",
")",
"{",
"$",
"matches",
"[",
"]",
"=",
"$",
"config",
";",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"matches",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Unable to find configuration for host '{$host}'\"",
")",
";",
"}",
"usort",
"(",
"$",
"matches",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"return",
"strlen",
"(",
"$",
"a",
"[",
"'host'",
"]",
")",
">",
"strlen",
"(",
"$",
"b",
"[",
"'host'",
"]",
")",
";",
"}",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"match",
")",
"{",
"$",
"result",
"=",
"array_merge",
"(",
"$",
"result",
",",
"$",
"match",
")",
";",
"}",
"unset",
"(",
"$",
"result",
"[",
"'host'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"'identityfile'",
"]",
")",
")",
"{",
"$",
"result",
"[",
"'identityfile'",
"]",
"=",
"$",
"this",
"->",
"processPath",
"(",
"$",
"result",
"[",
"'identityfile'",
"]",
")",
";",
"}",
"else",
"if",
"(",
"file_exists",
"(",
"$",
"file",
"=",
"$",
"this",
"->",
"processPath",
"(",
"$",
"this",
"->",
"getIdentity",
"(",
")",
")",
")",
")",
"{",
"$",
"result",
"[",
"'identityfile'",
"]",
"=",
"$",
"file",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Merges matches of the host in the config file using fnmatch and a length comparison
@param string $host
@return array | [
"Merges",
"matches",
"of",
"the",
"host",
"in",
"the",
"config",
"file",
"using",
"fnmatch",
"and",
"a",
"length",
"comparison"
] | train | https://github.com/Herzult/php-ssh/blob/c56875c7d6a6ef070dee8db2b5e77d6f36a02b55/src/Ssh/SshConfigFileConfiguration.php#L115-L141 |
Herzult/php-ssh | src/Ssh/SshConfigFileConfiguration.php | SshConfigFileConfiguration.getAuthentication | public function getAuthentication($passphrase = null, $user = null)
{
if (is_null($user) && !isset($this->config['user'])) {
throw new RuntimeException("Can not authenticate for '{$this->host}' could not find user to authenticate as");
}
$user = $user ?: $this->config['user'];
if (isset($this->config['identityfile'])) {
return new Authentication\PublicKeyFile(
$user,
$this->config['identityfile'] . '.pub',
$this->config['identityfile'],
$passphrase
);
} else {
return new Authentication\None(
$user
);
}
} | php | public function getAuthentication($passphrase = null, $user = null)
{
if (is_null($user) && !isset($this->config['user'])) {
throw new RuntimeException("Can not authenticate for '{$this->host}' could not find user to authenticate as");
}
$user = $user ?: $this->config['user'];
if (isset($this->config['identityfile'])) {
return new Authentication\PublicKeyFile(
$user,
$this->config['identityfile'] . '.pub',
$this->config['identityfile'],
$passphrase
);
} else {
return new Authentication\None(
$user
);
}
} | [
"public",
"function",
"getAuthentication",
"(",
"$",
"passphrase",
"=",
"null",
",",
"$",
"user",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"user",
")",
"&&",
"!",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'user'",
"]",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Can not authenticate for '{$this->host}' could not find user to authenticate as\"",
")",
";",
"}",
"$",
"user",
"=",
"$",
"user",
"?",
":",
"$",
"this",
"->",
"config",
"[",
"'user'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'identityfile'",
"]",
")",
")",
"{",
"return",
"new",
"Authentication",
"\\",
"PublicKeyFile",
"(",
"$",
"user",
",",
"$",
"this",
"->",
"config",
"[",
"'identityfile'",
"]",
".",
"'.pub'",
",",
"$",
"this",
"->",
"config",
"[",
"'identityfile'",
"]",
",",
"$",
"passphrase",
")",
";",
"}",
"else",
"{",
"return",
"new",
"Authentication",
"\\",
"None",
"(",
"$",
"user",
")",
";",
"}",
"}"
] | Return an authentication mechanism based on the configuration file
@param string|null $passphrase
@param string|null $user
@return PublicKeyFile|None | [
"Return",
"an",
"authentication",
"mechanism",
"based",
"on",
"the",
"configuration",
"file"
] | train | https://github.com/Herzult/php-ssh/blob/c56875c7d6a6ef070dee8db2b5e77d6f36a02b55/src/Ssh/SshConfigFileConfiguration.php#L149-L167 |
Herzult/php-ssh | src/Ssh/Publickey.php | Publickey.add | public function add($algoname, $blob, $overwrite = false, array $attributes = array())
{
return ssh2_publickey_add($this->getResource(), $algoname, $blob, $overwrite, $attributes);
} | php | public function add($algoname, $blob, $overwrite = false, array $attributes = array())
{
return ssh2_publickey_add($this->getResource(), $algoname, $blob, $overwrite, $attributes);
} | [
"public",
"function",
"add",
"(",
"$",
"algoname",
",",
"$",
"blob",
",",
"$",
"overwrite",
"=",
"false",
",",
"array",
"$",
"attributes",
"=",
"array",
"(",
")",
")",
"{",
"return",
"ssh2_publickey_add",
"(",
"$",
"this",
"->",
"getResource",
"(",
")",
",",
"$",
"algoname",
",",
"$",
"blob",
",",
"$",
"overwrite",
",",
"$",
"attributes",
")",
";",
"}"
] | Adds an authorized publickey
@param string $algoname The algorithm (e.g: ssh-dss, ssh-rsa)
@param string $blob The blob as binary data
@param Boolean $overwrite Whether to overwrite the key if it already
exist
@param array $attributes An associative array of attributes to assign
to the publickey. To mark an attribute as
mandatory, precede its name with an asterisk.
If the server is unable to support an
attribute marked mandatory, it will abort
the add process.
@return Boolean TRUE on success, or FALSE on failure | [
"Adds",
"an",
"authorized",
"publickey"
] | train | https://github.com/Herzult/php-ssh/blob/c56875c7d6a6ef070dee8db2b5e77d6f36a02b55/src/Ssh/Publickey.php#L30-L33 |
Herzult/php-ssh | src/Ssh/Publickey.php | Publickey.createResource | public function createResource()
{
$resource = ssh2_publickey_init($this->getSessionResource());
if (!is_resource($resource)) {
throw new RuntimeException('The initialization of the publickey subsystem failed.');
}
$this->resource = $resource;
} | php | public function createResource()
{
$resource = ssh2_publickey_init($this->getSessionResource());
if (!is_resource($resource)) {
throw new RuntimeException('The initialization of the publickey subsystem failed.');
}
$this->resource = $resource;
} | [
"public",
"function",
"createResource",
"(",
")",
"{",
"$",
"resource",
"=",
"ssh2_publickey_init",
"(",
"$",
"this",
"->",
"getSessionResource",
"(",
")",
")",
";",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"resource",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'The initialization of the publickey subsystem failed.'",
")",
";",
"}",
"$",
"this",
"->",
"resource",
"=",
"$",
"resource",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/Herzult/php-ssh/blob/c56875c7d6a6ef070dee8db2b5e77d6f36a02b55/src/Ssh/Publickey.php#L63-L72 |
sonata-project/SonataFormatterBundle | src/Controller/CkeditorAdminController.php | CkeditorAdminController.setFormTheme | private function setFormTheme(FormView $formView, array $theme): void
{
$this->get('twig')->getRuntime(FormRenderer::class)->setTheme($formView, $theme);
} | php | private function setFormTheme(FormView $formView, array $theme): void
{
$this->get('twig')->getRuntime(FormRenderer::class)->setTheme($formView, $theme);
} | [
"private",
"function",
"setFormTheme",
"(",
"FormView",
"$",
"formView",
",",
"array",
"$",
"theme",
")",
":",
"void",
"{",
"$",
"this",
"->",
"get",
"(",
"'twig'",
")",
"->",
"getRuntime",
"(",
"FormRenderer",
"::",
"class",
")",
"->",
"setTheme",
"(",
"$",
"formView",
",",
"$",
"theme",
")",
";",
"}"
] | Sets the admin form theme to form view. Used for compatibility between Symfony versions. | [
"Sets",
"the",
"admin",
"form",
"theme",
"to",
"form",
"view",
".",
"Used",
"for",
"compatibility",
"between",
"Symfony",
"versions",
"."
] | train | https://github.com/sonata-project/SonataFormatterBundle/blob/4302302d7db0db4cf5ca7ffb724764d37fb95790/src/Controller/CkeditorAdminController.php#L155-L158 |
sonata-project/SonataFormatterBundle | src/DependencyInjection/SonataFormatterExtension.php | SonataFormatterExtension.load | public function load(array $configs, ContainerBuilder $container): void
{
$processor = new Processor();
$configuration = new Configuration();
$config = $processor->processConfiguration($configuration, $configs);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('formatter.xml');
$loader->load('twig.xml');
$loader->load('validators.xml');
$bundles = $container->getParameter('kernel.bundles');
if (isset($bundles['FOSCKEditorBundle'])) {
$loader->load('form.xml');
}
if (isset($bundles['SonataBlockBundle'])) {
$loader->load('block.xml');
}
if (isset($bundles['SonataMediaBundle'])) {
$loader->load('ckeditor.xml');
}
if (!\array_key_exists($config['default_formatter'], $config['formatters'])) {
throw new \InvalidArgumentException(sprintf(
'SonataFormatterBundle - Invalid default formatter: %s, available: %s',
$config['default_formatter'],
sprintf('["%s"]', implode('", "', array_keys($config['formatters'])))
));
}
$pool = $container->getDefinition('sonata.formatter.pool');
$pool->addArgument($config['default_formatter']);
foreach ($config['formatters'] as $code => $configuration) {
if (0 === \count($configuration['extensions'])) {
$env = null;
} else {
$env = new Reference($this->createEnvironment(
$container,
$code,
$configuration['extensions']
));
}
$pool->addMethodCall(
'add',
[$code, new Reference($configuration['service']), $env]
);
}
$container->setParameter(
'sonata.formatter.ckeditor.configuration.templates',
$config['ckeditor']['templates']
);
} | php | public function load(array $configs, ContainerBuilder $container): void
{
$processor = new Processor();
$configuration = new Configuration();
$config = $processor->processConfiguration($configuration, $configs);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('formatter.xml');
$loader->load('twig.xml');
$loader->load('validators.xml');
$bundles = $container->getParameter('kernel.bundles');
if (isset($bundles['FOSCKEditorBundle'])) {
$loader->load('form.xml');
}
if (isset($bundles['SonataBlockBundle'])) {
$loader->load('block.xml');
}
if (isset($bundles['SonataMediaBundle'])) {
$loader->load('ckeditor.xml');
}
if (!\array_key_exists($config['default_formatter'], $config['formatters'])) {
throw new \InvalidArgumentException(sprintf(
'SonataFormatterBundle - Invalid default formatter: %s, available: %s',
$config['default_formatter'],
sprintf('["%s"]', implode('", "', array_keys($config['formatters'])))
));
}
$pool = $container->getDefinition('sonata.formatter.pool');
$pool->addArgument($config['default_formatter']);
foreach ($config['formatters'] as $code => $configuration) {
if (0 === \count($configuration['extensions'])) {
$env = null;
} else {
$env = new Reference($this->createEnvironment(
$container,
$code,
$configuration['extensions']
));
}
$pool->addMethodCall(
'add',
[$code, new Reference($configuration['service']), $env]
);
}
$container->setParameter(
'sonata.formatter.ckeditor.configuration.templates',
$config['ckeditor']['templates']
);
} | [
"public",
"function",
"load",
"(",
"array",
"$",
"configs",
",",
"ContainerBuilder",
"$",
"container",
")",
":",
"void",
"{",
"$",
"processor",
"=",
"new",
"Processor",
"(",
")",
";",
"$",
"configuration",
"=",
"new",
"Configuration",
"(",
")",
";",
"$",
"config",
"=",
"$",
"processor",
"->",
"processConfiguration",
"(",
"$",
"configuration",
",",
"$",
"configs",
")",
";",
"$",
"loader",
"=",
"new",
"XmlFileLoader",
"(",
"$",
"container",
",",
"new",
"FileLocator",
"(",
"__DIR__",
".",
"'/../Resources/config'",
")",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'formatter.xml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'twig.xml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'validators.xml'",
")",
";",
"$",
"bundles",
"=",
"$",
"container",
"->",
"getParameter",
"(",
"'kernel.bundles'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"bundles",
"[",
"'FOSCKEditorBundle'",
"]",
")",
")",
"{",
"$",
"loader",
"->",
"load",
"(",
"'form.xml'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"bundles",
"[",
"'SonataBlockBundle'",
"]",
")",
")",
"{",
"$",
"loader",
"->",
"load",
"(",
"'block.xml'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"bundles",
"[",
"'SonataMediaBundle'",
"]",
")",
")",
"{",
"$",
"loader",
"->",
"load",
"(",
"'ckeditor.xml'",
")",
";",
"}",
"if",
"(",
"!",
"\\",
"array_key_exists",
"(",
"$",
"config",
"[",
"'default_formatter'",
"]",
",",
"$",
"config",
"[",
"'formatters'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'SonataFormatterBundle - Invalid default formatter: %s, available: %s'",
",",
"$",
"config",
"[",
"'default_formatter'",
"]",
",",
"sprintf",
"(",
"'[\"%s\"]'",
",",
"implode",
"(",
"'\", \"'",
",",
"array_keys",
"(",
"$",
"config",
"[",
"'formatters'",
"]",
")",
")",
")",
")",
")",
";",
"}",
"$",
"pool",
"=",
"$",
"container",
"->",
"getDefinition",
"(",
"'sonata.formatter.pool'",
")",
";",
"$",
"pool",
"->",
"addArgument",
"(",
"$",
"config",
"[",
"'default_formatter'",
"]",
")",
";",
"foreach",
"(",
"$",
"config",
"[",
"'formatters'",
"]",
"as",
"$",
"code",
"=>",
"$",
"configuration",
")",
"{",
"if",
"(",
"0",
"===",
"\\",
"count",
"(",
"$",
"configuration",
"[",
"'extensions'",
"]",
")",
")",
"{",
"$",
"env",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"env",
"=",
"new",
"Reference",
"(",
"$",
"this",
"->",
"createEnvironment",
"(",
"$",
"container",
",",
"$",
"code",
",",
"$",
"configuration",
"[",
"'extensions'",
"]",
")",
")",
";",
"}",
"$",
"pool",
"->",
"addMethodCall",
"(",
"'add'",
",",
"[",
"$",
"code",
",",
"new",
"Reference",
"(",
"$",
"configuration",
"[",
"'service'",
"]",
")",
",",
"$",
"env",
"]",
")",
";",
"}",
"$",
"container",
"->",
"setParameter",
"(",
"'sonata.formatter.ckeditor.configuration.templates'",
",",
"$",
"config",
"[",
"'ckeditor'",
"]",
"[",
"'templates'",
"]",
")",
";",
"}"
] | Loads the url shortener configuration. | [
"Loads",
"the",
"url",
"shortener",
"configuration",
"."
] | train | https://github.com/sonata-project/SonataFormatterBundle/blob/4302302d7db0db4cf5ca7ffb724764d37fb95790/src/DependencyInjection/SonataFormatterExtension.php#L32-L90 |
morrisonlevi/Ardent | src/Collection/AbstractSet.php | AbstractSet.difference | function difference(Set $that) {
$difference = $this->cloneEmpty();
if ($that === $this) {
return $difference;
}
$this->addIf($difference, $this, negate([$that, 'has']));
$this->addIf($difference, $that, negate([$this, 'has']));
return $difference;
} | php | function difference(Set $that) {
$difference = $this->cloneEmpty();
if ($that === $this) {
return $difference;
}
$this->addIf($difference, $this, negate([$that, 'has']));
$this->addIf($difference, $that, negate([$this, 'has']));
return $difference;
} | [
"function",
"difference",
"(",
"Set",
"$",
"that",
")",
"{",
"$",
"difference",
"=",
"$",
"this",
"->",
"cloneEmpty",
"(",
")",
";",
"if",
"(",
"$",
"that",
"===",
"$",
"this",
")",
"{",
"return",
"$",
"difference",
";",
"}",
"$",
"this",
"->",
"addIf",
"(",
"$",
"difference",
",",
"$",
"this",
",",
"negate",
"(",
"[",
"$",
"that",
",",
"'has'",
"]",
")",
")",
";",
"$",
"this",
"->",
"addIf",
"(",
"$",
"difference",
",",
"$",
"that",
",",
"negate",
"(",
"[",
"$",
"this",
",",
"'has'",
"]",
")",
")",
";",
"return",
"$",
"difference",
";",
"}"
] | Creates the set that contains the items in the current set that are not
contained in the provided set, as well as items that are in the
provided set that are not in the current set.
Formally:
A ⊖ B = {x : x ∈ (A \ B) ∨ (B \ A)}
@param Set $that
@return Set | [
"Creates",
"the",
"set",
"that",
"contains",
"the",
"items",
"in",
"the",
"current",
"set",
"that",
"are",
"not",
"contained",
"in",
"the",
"provided",
"set",
"as",
"well",
"as",
"items",
"that",
"are",
"in",
"the",
"provided",
"set",
"that",
"are",
"not",
"in",
"the",
"current",
"set",
"."
] | train | https://github.com/morrisonlevi/Ardent/blob/972e9eea600edf9d0941c303f3b6a958e40dbb34/src/Collection/AbstractSet.php#L30-L41 |
morrisonlevi/Ardent | src/Collection/AbstractSet.php | AbstractSet.intersection | function intersection(Set $that) {
$intersection = $this->cloneEmpty();
$this->addIf($intersection, $this, [$that, 'has']);
return $intersection;
} | php | function intersection(Set $that) {
$intersection = $this->cloneEmpty();
$this->addIf($intersection, $this, [$that, 'has']);
return $intersection;
} | [
"function",
"intersection",
"(",
"Set",
"$",
"that",
")",
"{",
"$",
"intersection",
"=",
"$",
"this",
"->",
"cloneEmpty",
"(",
")",
";",
"$",
"this",
"->",
"addIf",
"(",
"$",
"intersection",
",",
"$",
"this",
",",
"[",
"$",
"that",
",",
"'has'",
"]",
")",
";",
"return",
"$",
"intersection",
";",
"}"
] | Creates a new set that contains the items that are in current set that
are also contained in the provided set.
Formally:
A ∩ B = {x : x ∈ A ∧ x ∈ B}
@param Set $that
@return Set | [
"Creates",
"a",
"new",
"set",
"that",
"contains",
"the",
"items",
"that",
"are",
"in",
"current",
"set",
"that",
"are",
"also",
"contained",
"in",
"the",
"provided",
"set",
"."
] | train | https://github.com/morrisonlevi/Ardent/blob/972e9eea600edf9d0941c303f3b6a958e40dbb34/src/Collection/AbstractSet.php#L54-L60 |
morrisonlevi/Ardent | src/Collection/AbstractSet.php | AbstractSet.complement | function complement(Set $that) {
$complement = $this->cloneEmpty();
if ($that === $this) {
return $complement;
}
$this->addIf($complement, $that, negate([$this, 'has']));
return $complement;
} | php | function complement(Set $that) {
$complement = $this->cloneEmpty();
if ($that === $this) {
return $complement;
}
$this->addIf($complement, $that, negate([$this, 'has']));
return $complement;
} | [
"function",
"complement",
"(",
"Set",
"$",
"that",
")",
"{",
"$",
"complement",
"=",
"$",
"this",
"->",
"cloneEmpty",
"(",
")",
";",
"if",
"(",
"$",
"that",
"===",
"$",
"this",
")",
"{",
"return",
"$",
"complement",
";",
"}",
"$",
"this",
"->",
"addIf",
"(",
"$",
"complement",
",",
"$",
"that",
",",
"negate",
"(",
"[",
"$",
"this",
",",
"'has'",
"]",
")",
")",
";",
"return",
"$",
"complement",
";",
"}"
] | Creates a new set which contains the items that exist in the provided
set and do not exist in the current set.
Formally:
B \ A = {x: x ∈ A ∧ x ∉ B}
@param Set $that
@return Set | [
"Creates",
"a",
"new",
"set",
"which",
"contains",
"the",
"items",
"that",
"exist",
"in",
"the",
"provided",
"set",
"and",
"do",
"not",
"exist",
"in",
"the",
"current",
"set",
"."
] | train | https://github.com/morrisonlevi/Ardent/blob/972e9eea600edf9d0941c303f3b6a958e40dbb34/src/Collection/AbstractSet.php#L73-L83 |
morrisonlevi/Ardent | src/Collection/AbstractSet.php | AbstractSet.union | function union(Set $that) {
$union = $this->cloneEmpty();
$this->for_each($this, [$union, 'add']);
$this->for_each($that, [$union, 'add']);
return $union;
} | php | function union(Set $that) {
$union = $this->cloneEmpty();
$this->for_each($this, [$union, 'add']);
$this->for_each($that, [$union, 'add']);
return $union;
} | [
"function",
"union",
"(",
"Set",
"$",
"that",
")",
"{",
"$",
"union",
"=",
"$",
"this",
"->",
"cloneEmpty",
"(",
")",
";",
"$",
"this",
"->",
"for_each",
"(",
"$",
"this",
",",
"[",
"$",
"union",
",",
"'add'",
"]",
")",
";",
"$",
"this",
"->",
"for_each",
"(",
"$",
"that",
",",
"[",
"$",
"union",
",",
"'add'",
"]",
")",
";",
"return",
"$",
"union",
";",
"}"
] | Creates a new set that contains the items of the current set and the
items of the provided set.
Formally:
A ∪ B = {x: x ∈ A ∨ x ∈ B}
@param Set $that
@return Set | [
"Creates",
"a",
"new",
"set",
"that",
"contains",
"the",
"items",
"of",
"the",
"current",
"set",
"and",
"the",
"items",
"of",
"the",
"provided",
"set",
"."
] | train | https://github.com/morrisonlevi/Ardent/blob/972e9eea600edf9d0941c303f3b6a958e40dbb34/src/Collection/AbstractSet.php#L96-L103 |
morrisonlevi/Ardent | src/Collection/LinkedList.php | LinkedList.tail | function tail() {
assert(!$this->isEmpty());
return $this->copyFromContext($this->head->next()->next());
} | php | function tail() {
assert(!$this->isEmpty());
return $this->copyFromContext($this->head->next()->next());
} | [
"function",
"tail",
"(",
")",
"{",
"assert",
"(",
"!",
"$",
"this",
"->",
"isEmpty",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"copyFromContext",
"(",
"$",
"this",
"->",
"head",
"->",
"next",
"(",
")",
"->",
"next",
"(",
")",
")",
";",
"}"
] | Extract the elements after the first of a list, which must be non-empty.
@return LinkedList | [
"Extract",
"the",
"elements",
"after",
"the",
"first",
"of",
"a",
"list",
"which",
"must",
"be",
"non",
"-",
"empty",
"."
] | train | https://github.com/morrisonlevi/Ardent/blob/972e9eea600edf9d0941c303f3b6a958e40dbb34/src/Collection/LinkedList.php#L270-L273 |
morrisonlevi/Ardent | src/Collection/BinaryTree.php | BinaryTree.inOrderPredecessor | function inOrderPredecessor() {
$current = $this->left();
while ($current->right() !== null) {
$current = $current->right();
}
return $current;
} | php | function inOrderPredecessor() {
$current = $this->left();
while ($current->right() !== null) {
$current = $current->right();
}
return $current;
} | [
"function",
"inOrderPredecessor",
"(",
")",
"{",
"$",
"current",
"=",
"$",
"this",
"->",
"left",
"(",
")",
";",
"while",
"(",
"$",
"current",
"->",
"right",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"current",
"=",
"$",
"current",
"->",
"right",
"(",
")",
";",
"}",
"return",
"$",
"current",
";",
"}"
] | Note that this function is only safe to call when it has a predecessor.
@return BinaryTree | [
"Note",
"that",
"this",
"function",
"is",
"only",
"safe",
"to",
"call",
"when",
"it",
"has",
"a",
"predecessor",
"."
] | train | https://github.com/morrisonlevi/Ardent/blob/972e9eea600edf9d0941c303f3b6a958e40dbb34/src/Collection/BinaryTree.php#L118-L124 |
morrisonlevi/Ardent | src/Collection/SortedMap.php | SortedMap.contains | function contains($item, callable $callback = null) {
if ($callback === null) {
$callback = __NAMESPACE__ . '\\compare';
}
foreach ($this->avl as $pair) {
/**
* @var Pair $pair
*/
if (call_user_func($callback, $pair->second, $item) === 0) {
return true;
}
}
return false;
} | php | function contains($item, callable $callback = null) {
if ($callback === null) {
$callback = __NAMESPACE__ . '\\compare';
}
foreach ($this->avl as $pair) {
/**
* @var Pair $pair
*/
if (call_user_func($callback, $pair->second, $item) === 0) {
return true;
}
}
return false;
} | [
"function",
"contains",
"(",
"$",
"item",
",",
"callable",
"$",
"callback",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"callback",
"===",
"null",
")",
"{",
"$",
"callback",
"=",
"__NAMESPACE__",
".",
"'\\\\compare'",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"avl",
"as",
"$",
"pair",
")",
"{",
"/**\n * @var Pair $pair\n */",
"if",
"(",
"call_user_func",
"(",
"$",
"callback",
",",
"$",
"pair",
"->",
"second",
",",
"$",
"item",
")",
"===",
"0",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | @param mixed $item
@param callable $callback
@return bool | [
"@param",
"mixed",
"$item",
"@param",
"callable",
"$callback"
] | train | https://github.com/morrisonlevi/Ardent/blob/972e9eea600edf9d0941c303f3b6a958e40dbb34/src/Collection/SortedMap.php#L45-L59 |
morrisonlevi/Ardent | src/Collection/SortedMap.php | SortedMap.get | function get($key) {
assert($this->offsetExists($key));
/**
* @var Pair $pair
*/
$pair = $this->avl->get(new Pair($key, null));
return $pair->second;
} | php | function get($key) {
assert($this->offsetExists($key));
/**
* @var Pair $pair
*/
$pair = $this->avl->get(new Pair($key, null));
return $pair->second;
} | [
"function",
"get",
"(",
"$",
"key",
")",
"{",
"assert",
"(",
"$",
"this",
"->",
"offsetExists",
"(",
"$",
"key",
")",
")",
";",
"/**\n * @var Pair $pair\n */",
"$",
"pair",
"=",
"$",
"this",
"->",
"avl",
"->",
"get",
"(",
"new",
"Pair",
"(",
"$",
"key",
",",
"null",
")",
")",
";",
"return",
"$",
"pair",
"->",
"second",
";",
"}"
] | @param $key
@return mixed | [
"@param",
"$key"
] | train | https://github.com/morrisonlevi/Ardent/blob/972e9eea600edf9d0941c303f3b6a958e40dbb34/src/Collection/SortedMap.php#L140-L149 |
morrisonlevi/Ardent | src/Collection/HashSet.php | HashSet.has | function has($item) {
$hash = call_user_func($this->hashFunction, $item);
assert(is_scalar($hash));
return array_key_exists($hash, $this->objects);
} | php | function has($item) {
$hash = call_user_func($this->hashFunction, $item);
assert(is_scalar($hash));
return array_key_exists($hash, $this->objects);
} | [
"function",
"has",
"(",
"$",
"item",
")",
"{",
"$",
"hash",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"hashFunction",
",",
"$",
"item",
")",
";",
"assert",
"(",
"is_scalar",
"(",
"$",
"hash",
")",
")",
";",
"return",
"array_key_exists",
"(",
"$",
"hash",
",",
"$",
"this",
"->",
"objects",
")",
";",
"}"
] | @param $item
@return bool | [
"@param",
"$item"
] | train | https://github.com/morrisonlevi/Ardent/blob/972e9eea600edf9d0941c303f3b6a958e40dbb34/src/Collection/HashSet.php#L29-L36 |
morrisonlevi/Ardent | src/Collection/HashSet.php | HashSet.remove | function remove($item) {
$hash = call_user_func($this->hashFunction, $item);
assert(is_scalar($hash));
unset($this->objects[$hash]);
} | php | function remove($item) {
$hash = call_user_func($this->hashFunction, $item);
assert(is_scalar($hash));
unset($this->objects[$hash]);
} | [
"function",
"remove",
"(",
"$",
"item",
")",
"{",
"$",
"hash",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"hashFunction",
",",
"$",
"item",
")",
";",
"assert",
"(",
"is_scalar",
"(",
"$",
"hash",
")",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"objects",
"[",
"$",
"hash",
"]",
")",
";",
"}"
] | @param $item
@return void | [
"@param",
"$item"
] | train | https://github.com/morrisonlevi/Ardent/blob/972e9eea600edf9d0941c303f3b6a958e40dbb34/src/Collection/HashSet.php#L86-L92 |
morrisonlevi/Ardent | src/Collection/AvlTree.php | AvlTree.get | function get($element) {
$node = $this->findNode($element, $this->root);
assert($node != null);
return $node->value();
} | php | function get($element) {
$node = $this->findNode($element, $this->root);
assert($node != null);
return $node->value();
} | [
"function",
"get",
"(",
"$",
"element",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"findNode",
"(",
"$",
"element",
",",
"$",
"this",
"->",
"root",
")",
";",
"assert",
"(",
"$",
"node",
"!=",
"null",
")",
";",
"return",
"$",
"node",
"->",
"value",
"(",
")",
";",
"}"
] | @param $element
@return mixed | [
"@param",
"$element"
] | train | https://github.com/morrisonlevi/Ardent/blob/972e9eea600edf9d0941c303f3b6a958e40dbb34/src/Collection/AvlTree.php#L64-L70 |
morrisonlevi/Ardent | src/Collection/AvlTree.php | AvlTree.addRecursive | protected function addRecursive($element, BinaryTree $node = null) {
$nullAction = [$this, 'createTree'];
$matchAction = function (BinaryTree $n) use ($element) {
$n->setValue($element);
return $n;
};
return $this->doRecursive($nullAction, $matchAction, $element, $node);
} | php | protected function addRecursive($element, BinaryTree $node = null) {
$nullAction = [$this, 'createTree'];
$matchAction = function (BinaryTree $n) use ($element) {
$n->setValue($element);
return $n;
};
return $this->doRecursive($nullAction, $matchAction, $element, $node);
} | [
"protected",
"function",
"addRecursive",
"(",
"$",
"element",
",",
"BinaryTree",
"$",
"node",
"=",
"null",
")",
"{",
"$",
"nullAction",
"=",
"[",
"$",
"this",
",",
"'createTree'",
"]",
";",
"$",
"matchAction",
"=",
"function",
"(",
"BinaryTree",
"$",
"n",
")",
"use",
"(",
"$",
"element",
")",
"{",
"$",
"n",
"->",
"setValue",
"(",
"$",
"element",
")",
";",
"return",
"$",
"n",
";",
"}",
";",
"return",
"$",
"this",
"->",
"doRecursive",
"(",
"$",
"nullAction",
",",
"$",
"matchAction",
",",
"$",
"element",
",",
"$",
"node",
")",
";",
"}"
] | @param $element
@param BinaryTree $node
@return BinaryTree | [
"@param",
"$element",
"@param",
"BinaryTree",
"$node"
] | train | https://github.com/morrisonlevi/Ardent/blob/972e9eea600edf9d0941c303f3b6a958e40dbb34/src/Collection/AvlTree.php#L168-L175 |
morrisonlevi/Ardent | src/Collection/AvlTree.php | AvlTree.removeRecursive | protected function removeRecursive($element, BinaryTree $node = null) {
$nullAction = [$this, 'doNothing'];
$matchAction = [$this, 'deleteNode'];
return $this->doRecursive($nullAction, $matchAction, $element, $node);
} | php | protected function removeRecursive($element, BinaryTree $node = null) {
$nullAction = [$this, 'doNothing'];
$matchAction = [$this, 'deleteNode'];
return $this->doRecursive($nullAction, $matchAction, $element, $node);
} | [
"protected",
"function",
"removeRecursive",
"(",
"$",
"element",
",",
"BinaryTree",
"$",
"node",
"=",
"null",
")",
"{",
"$",
"nullAction",
"=",
"[",
"$",
"this",
",",
"'doNothing'",
"]",
";",
"$",
"matchAction",
"=",
"[",
"$",
"this",
",",
"'deleteNode'",
"]",
";",
"return",
"$",
"this",
"->",
"doRecursive",
"(",
"$",
"nullAction",
",",
"$",
"matchAction",
",",
"$",
"element",
",",
"$",
"node",
")",
";",
"}"
] | @param $element
@param BinaryTree $node
@return BinaryTree|null | [
"@param",
"$element",
"@param",
"BinaryTree",
"$node"
] | train | https://github.com/morrisonlevi/Ardent/blob/972e9eea600edf9d0941c303f3b6a958e40dbb34/src/Collection/AvlTree.php#L184-L188 |
morrisonlevi/Ardent | src/Collection/AvlTree.php | AvlTree.deleteNode | protected function deleteNode(BinaryTree $node) {
$state = $this->deleteSelectState($node);
return $this->deleteOptions[$state]($node);
} | php | protected function deleteNode(BinaryTree $node) {
$state = $this->deleteSelectState($node);
return $this->deleteOptions[$state]($node);
} | [
"protected",
"function",
"deleteNode",
"(",
"BinaryTree",
"$",
"node",
")",
"{",
"$",
"state",
"=",
"$",
"this",
"->",
"deleteSelectState",
"(",
"$",
"node",
")",
";",
"return",
"$",
"this",
"->",
"deleteOptions",
"[",
"$",
"state",
"]",
"(",
"$",
"node",
")",
";",
"}"
] | @param BinaryTree $node
@return BinaryTree|null | [
"@param",
"BinaryTree",
"$node"
] | train | https://github.com/morrisonlevi/Ardent/blob/972e9eea600edf9d0941c303f3b6a958e40dbb34/src/Collection/AvlTree.php#L215-L218 |
morrisonlevi/Ardent | src/Collection/AvlTree.php | AvlTree.balance | protected function balance(BinaryTree $node = null) {
if ($node === null) {
return null;
}
$diff = $node->leftHeight() - $node->rightHeight();
if ($diff < -1) {
// right side is taller
$node = $this->rotateLeft($node);
} elseif ($diff > 1) {
// left side is taller
$node = $this->rotateRight($node);
}
return $node;
} | php | protected function balance(BinaryTree $node = null) {
if ($node === null) {
return null;
}
$diff = $node->leftHeight() - $node->rightHeight();
if ($diff < -1) {
// right side is taller
$node = $this->rotateLeft($node);
} elseif ($diff > 1) {
// left side is taller
$node = $this->rotateRight($node);
}
return $node;
} | [
"protected",
"function",
"balance",
"(",
"BinaryTree",
"$",
"node",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"node",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"$",
"diff",
"=",
"$",
"node",
"->",
"leftHeight",
"(",
")",
"-",
"$",
"node",
"->",
"rightHeight",
"(",
")",
";",
"if",
"(",
"$",
"diff",
"<",
"-",
"1",
")",
"{",
"// right side is taller",
"$",
"node",
"=",
"$",
"this",
"->",
"rotateLeft",
"(",
"$",
"node",
")",
";",
"}",
"elseif",
"(",
"$",
"diff",
">",
"1",
")",
"{",
"// left side is taller",
"$",
"node",
"=",
"$",
"this",
"->",
"rotateRight",
"(",
"$",
"node",
")",
";",
"}",
"return",
"$",
"node",
";",
"}"
] | @param BinaryTree $node
@return BinaryTree|null | [
"@param",
"BinaryTree",
"$node"
] | train | https://github.com/morrisonlevi/Ardent/blob/972e9eea600edf9d0941c303f3b6a958e40dbb34/src/Collection/AvlTree.php#L226-L242 |
morrisonlevi/Ardent | src/Collection/AvlTree.php | AvlTree.rotateRight | protected function rotateRight(BinaryTree $root) {
$leftNode = $root->left();
$leftHeight = $leftNode->leftHeight();
$rightHeight = $leftNode->rightHeight();
$diff = $leftHeight - $rightHeight;
if ($diff < 0) {
// Left-Right case
$pivot = $leftNode->right();
$leftNode->setRight($pivot->left());
$pivot->setLeft($leftNode);
$root->setLeft($pivot);
}
$pivot = $root->left();
$root->setLeft($pivot->right());
$pivot->setRight($root);
return $pivot;
} | php | protected function rotateRight(BinaryTree $root) {
$leftNode = $root->left();
$leftHeight = $leftNode->leftHeight();
$rightHeight = $leftNode->rightHeight();
$diff = $leftHeight - $rightHeight;
if ($diff < 0) {
// Left-Right case
$pivot = $leftNode->right();
$leftNode->setRight($pivot->left());
$pivot->setLeft($leftNode);
$root->setLeft($pivot);
}
$pivot = $root->left();
$root->setLeft($pivot->right());
$pivot->setRight($root);
return $pivot;
} | [
"protected",
"function",
"rotateRight",
"(",
"BinaryTree",
"$",
"root",
")",
"{",
"$",
"leftNode",
"=",
"$",
"root",
"->",
"left",
"(",
")",
";",
"$",
"leftHeight",
"=",
"$",
"leftNode",
"->",
"leftHeight",
"(",
")",
";",
"$",
"rightHeight",
"=",
"$",
"leftNode",
"->",
"rightHeight",
"(",
")",
";",
"$",
"diff",
"=",
"$",
"leftHeight",
"-",
"$",
"rightHeight",
";",
"if",
"(",
"$",
"diff",
"<",
"0",
")",
"{",
"// Left-Right case",
"$",
"pivot",
"=",
"$",
"leftNode",
"->",
"right",
"(",
")",
";",
"$",
"leftNode",
"->",
"setRight",
"(",
"$",
"pivot",
"->",
"left",
"(",
")",
")",
";",
"$",
"pivot",
"->",
"setLeft",
"(",
"$",
"leftNode",
")",
";",
"$",
"root",
"->",
"setLeft",
"(",
"$",
"pivot",
")",
";",
"}",
"$",
"pivot",
"=",
"$",
"root",
"->",
"left",
"(",
")",
";",
"$",
"root",
"->",
"setLeft",
"(",
"$",
"pivot",
"->",
"right",
"(",
")",
")",
";",
"$",
"pivot",
"->",
"setRight",
"(",
"$",
"root",
")",
";",
"return",
"$",
"pivot",
";",
"}"
] | @param BinaryTree $root
@return BinaryTree | [
"@param",
"BinaryTree",
"$root"
] | train | https://github.com/morrisonlevi/Ardent/blob/972e9eea600edf9d0941c303f3b6a958e40dbb34/src/Collection/AvlTree.php#L250-L270 |
morrisonlevi/Ardent | src/Collection/AvlTree.php | AvlTree.rotateLeft | protected function rotateLeft(BinaryTree $root) {
$rightNode = $root->right();
$diff = $rightNode->leftHeight() - $rightNode->rightHeight();
if ($diff >= 0) {
// Right-Left case
$pivot = $rightNode->left();
$rightNode->setLeft($pivot->right());
$pivot->setRight($rightNode);
$root->setRight($pivot);
}
$pivot = $root->right();
$root->setRight($pivot->left());
$pivot->setLeft($root);
return $pivot;
} | php | protected function rotateLeft(BinaryTree $root) {
$rightNode = $root->right();
$diff = $rightNode->leftHeight() - $rightNode->rightHeight();
if ($diff >= 0) {
// Right-Left case
$pivot = $rightNode->left();
$rightNode->setLeft($pivot->right());
$pivot->setRight($rightNode);
$root->setRight($pivot);
}
$pivot = $root->right();
$root->setRight($pivot->left());
$pivot->setLeft($root);
return $pivot;
} | [
"protected",
"function",
"rotateLeft",
"(",
"BinaryTree",
"$",
"root",
")",
"{",
"$",
"rightNode",
"=",
"$",
"root",
"->",
"right",
"(",
")",
";",
"$",
"diff",
"=",
"$",
"rightNode",
"->",
"leftHeight",
"(",
")",
"-",
"$",
"rightNode",
"->",
"rightHeight",
"(",
")",
";",
"if",
"(",
"$",
"diff",
">=",
"0",
")",
"{",
"// Right-Left case",
"$",
"pivot",
"=",
"$",
"rightNode",
"->",
"left",
"(",
")",
";",
"$",
"rightNode",
"->",
"setLeft",
"(",
"$",
"pivot",
"->",
"right",
"(",
")",
")",
";",
"$",
"pivot",
"->",
"setRight",
"(",
"$",
"rightNode",
")",
";",
"$",
"root",
"->",
"setRight",
"(",
"$",
"pivot",
")",
";",
"}",
"$",
"pivot",
"=",
"$",
"root",
"->",
"right",
"(",
")",
";",
"$",
"root",
"->",
"setRight",
"(",
"$",
"pivot",
"->",
"left",
"(",
")",
")",
";",
"$",
"pivot",
"->",
"setLeft",
"(",
"$",
"root",
")",
";",
"return",
"$",
"pivot",
";",
"}"
] | @param BinaryTree $root
@return BinaryTree | [
"@param",
"BinaryTree",
"$root"
] | train | https://github.com/morrisonlevi/Ardent/blob/972e9eea600edf9d0941c303f3b6a958e40dbb34/src/Collection/AvlTree.php#L278-L297 |
morrisonlevi/Ardent | src/Collection/HashMap.php | HashMap.contains | function contains($item, callable $comparator = null) {
$compare = $comparator ?: [$this, 'areEqual'];
$storage = $this->storage;
for (reset($storage); key($storage) !== null; next($storage)) {
/**
* @var Pair $pair
*/
$pair = current($storage);
if (call_user_func($compare, $item, $pair->second)) {
return true;
}
}
return false;
} | php | function contains($item, callable $comparator = null) {
$compare = $comparator ?: [$this, 'areEqual'];
$storage = $this->storage;
for (reset($storage); key($storage) !== null; next($storage)) {
/**
* @var Pair $pair
*/
$pair = current($storage);
if (call_user_func($compare, $item, $pair->second)) {
return true;
}
}
return false;
} | [
"function",
"contains",
"(",
"$",
"item",
",",
"callable",
"$",
"comparator",
"=",
"null",
")",
"{",
"$",
"compare",
"=",
"$",
"comparator",
"?",
":",
"[",
"$",
"this",
",",
"'areEqual'",
"]",
";",
"$",
"storage",
"=",
"$",
"this",
"->",
"storage",
";",
"for",
"(",
"reset",
"(",
"$",
"storage",
")",
";",
"key",
"(",
"$",
"storage",
")",
"!==",
"null",
";",
"next",
"(",
"$",
"storage",
")",
")",
"{",
"/**\n * @var Pair $pair\n */",
"$",
"pair",
"=",
"current",
"(",
"$",
"storage",
")",
";",
"if",
"(",
"call_user_func",
"(",
"$",
"compare",
",",
"$",
"item",
",",
"$",
"pair",
"->",
"second",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | @param $item
@param callable $comparator function($a, $b) returns bool
@return bool | [
"@param",
"$item",
"@param",
"callable",
"$comparator",
"function",
"(",
"$a",
"$b",
")",
"returns",
"bool"
] | train | https://github.com/morrisonlevi/Ardent/blob/972e9eea600edf9d0941c303f3b6a958e40dbb34/src/Collection/HashMap.php#L106-L120 |
Gregwar/CaptchaBundle | Generator/CaptchaGenerator.php | CaptchaGenerator.getCaptchaCode | public function getCaptchaCode(array &$options)
{
$this->builder->setPhrase($this->getPhrase($options));
// Randomly execute garbage collection and returns the image filename
if ($options['as_file']) {
$this->imageFileHandler->collectGarbage();
return $this->generate($options);
}
// Returns the image generation URL
if ($options['as_url']) {
return $this->router->generate('gregwar_captcha.generate_captcha',
array('key' => $options['session_key'], 'n' => md5(microtime(true).mt_rand())));
}
return 'data:image/jpeg;base64,' . base64_encode($this->generate($options));
} | php | public function getCaptchaCode(array &$options)
{
$this->builder->setPhrase($this->getPhrase($options));
// Randomly execute garbage collection and returns the image filename
if ($options['as_file']) {
$this->imageFileHandler->collectGarbage();
return $this->generate($options);
}
// Returns the image generation URL
if ($options['as_url']) {
return $this->router->generate('gregwar_captcha.generate_captcha',
array('key' => $options['session_key'], 'n' => md5(microtime(true).mt_rand())));
}
return 'data:image/jpeg;base64,' . base64_encode($this->generate($options));
} | [
"public",
"function",
"getCaptchaCode",
"(",
"array",
"&",
"$",
"options",
")",
"{",
"$",
"this",
"->",
"builder",
"->",
"setPhrase",
"(",
"$",
"this",
"->",
"getPhrase",
"(",
"$",
"options",
")",
")",
";",
"// Randomly execute garbage collection and returns the image filename",
"if",
"(",
"$",
"options",
"[",
"'as_file'",
"]",
")",
"{",
"$",
"this",
"->",
"imageFileHandler",
"->",
"collectGarbage",
"(",
")",
";",
"return",
"$",
"this",
"->",
"generate",
"(",
"$",
"options",
")",
";",
"}",
"// Returns the image generation URL",
"if",
"(",
"$",
"options",
"[",
"'as_url'",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"router",
"->",
"generate",
"(",
"'gregwar_captcha.generate_captcha'",
",",
"array",
"(",
"'key'",
"=>",
"$",
"options",
"[",
"'session_key'",
"]",
",",
"'n'",
"=>",
"md5",
"(",
"microtime",
"(",
"true",
")",
".",
"mt_rand",
"(",
")",
")",
")",
")",
";",
"}",
"return",
"'data:image/jpeg;base64,'",
".",
"base64_encode",
"(",
"$",
"this",
"->",
"generate",
"(",
"$",
"options",
")",
")",
";",
"}"
] | Get the captcha URL, stream, or filename that will go in the image's src attribute
@param array $options
@return array | [
"Get",
"the",
"captcha",
"URL",
"stream",
"or",
"filename",
"that",
"will",
"go",
"in",
"the",
"image",
"s",
"src",
"attribute"
] | train | https://github.com/Gregwar/CaptchaBundle/blob/c2d5468556890dd25e0b53bd345fc205562c86f7/Generator/CaptchaGenerator.php#L66-L84 |
Gregwar/CaptchaBundle | Generator/CaptchaGenerator.php | CaptchaGenerator.generate | public function generate(array &$options)
{
$this->builder->setDistortion($options['distortion']);
$this->builder->setMaxFrontLines($options['max_front_lines']);
$this->builder->setMaxBehindLines($options['max_behind_lines']);
if (isset($options['text_color']) && $options['text_color']) {
if (count($options['text_color']) !== 3) {
throw new \RuntimeException('text_color should be an array of r, g and b');
}
$color = $options['text_color'];
$this->builder->setTextColor($color[0], $color[1], $color[2]);
}
if (isset($options['background_color']) && $options['background_color']) {
if (count($options['background_color']) !== 3) {
throw new \RuntimeException('background_color should be an array of r, g and b');
}
$color = $options['background_color'];
$this->builder->setBackgroundColor($color[0], $color[1], $color[2]);
}
$this->builder->setInterpolation($options['interpolation']);
$fingerprint = isset($options['fingerprint']) ? $options['fingerprint'] : null;
$this->builder->setBackgroundImages($options['background_images']);
$this->builder->setIgnoreAllEffects($options['ignore_all_effects']);
$content = $this->builder->build(
$options['width'],
$options['height'],
$options['font'],
$fingerprint
)->getGd();
if ($options['keep_value']) {
$options['fingerprint'] = $this->builder->getFingerprint();
}
if (!$options['as_file']) {
ob_start();
imagejpeg($content, null, $options['quality']);
return ob_get_clean();
}
return $this->imageFileHandler->saveAsFile($content);
} | php | public function generate(array &$options)
{
$this->builder->setDistortion($options['distortion']);
$this->builder->setMaxFrontLines($options['max_front_lines']);
$this->builder->setMaxBehindLines($options['max_behind_lines']);
if (isset($options['text_color']) && $options['text_color']) {
if (count($options['text_color']) !== 3) {
throw new \RuntimeException('text_color should be an array of r, g and b');
}
$color = $options['text_color'];
$this->builder->setTextColor($color[0], $color[1], $color[2]);
}
if (isset($options['background_color']) && $options['background_color']) {
if (count($options['background_color']) !== 3) {
throw new \RuntimeException('background_color should be an array of r, g and b');
}
$color = $options['background_color'];
$this->builder->setBackgroundColor($color[0], $color[1], $color[2]);
}
$this->builder->setInterpolation($options['interpolation']);
$fingerprint = isset($options['fingerprint']) ? $options['fingerprint'] : null;
$this->builder->setBackgroundImages($options['background_images']);
$this->builder->setIgnoreAllEffects($options['ignore_all_effects']);
$content = $this->builder->build(
$options['width'],
$options['height'],
$options['font'],
$fingerprint
)->getGd();
if ($options['keep_value']) {
$options['fingerprint'] = $this->builder->getFingerprint();
}
if (!$options['as_file']) {
ob_start();
imagejpeg($content, null, $options['quality']);
return ob_get_clean();
}
return $this->imageFileHandler->saveAsFile($content);
} | [
"public",
"function",
"generate",
"(",
"array",
"&",
"$",
"options",
")",
"{",
"$",
"this",
"->",
"builder",
"->",
"setDistortion",
"(",
"$",
"options",
"[",
"'distortion'",
"]",
")",
";",
"$",
"this",
"->",
"builder",
"->",
"setMaxFrontLines",
"(",
"$",
"options",
"[",
"'max_front_lines'",
"]",
")",
";",
"$",
"this",
"->",
"builder",
"->",
"setMaxBehindLines",
"(",
"$",
"options",
"[",
"'max_behind_lines'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'text_color'",
"]",
")",
"&&",
"$",
"options",
"[",
"'text_color'",
"]",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"options",
"[",
"'text_color'",
"]",
")",
"!==",
"3",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'text_color should be an array of r, g and b'",
")",
";",
"}",
"$",
"color",
"=",
"$",
"options",
"[",
"'text_color'",
"]",
";",
"$",
"this",
"->",
"builder",
"->",
"setTextColor",
"(",
"$",
"color",
"[",
"0",
"]",
",",
"$",
"color",
"[",
"1",
"]",
",",
"$",
"color",
"[",
"2",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'background_color'",
"]",
")",
"&&",
"$",
"options",
"[",
"'background_color'",
"]",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"options",
"[",
"'background_color'",
"]",
")",
"!==",
"3",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'background_color should be an array of r, g and b'",
")",
";",
"}",
"$",
"color",
"=",
"$",
"options",
"[",
"'background_color'",
"]",
";",
"$",
"this",
"->",
"builder",
"->",
"setBackgroundColor",
"(",
"$",
"color",
"[",
"0",
"]",
",",
"$",
"color",
"[",
"1",
"]",
",",
"$",
"color",
"[",
"2",
"]",
")",
";",
"}",
"$",
"this",
"->",
"builder",
"->",
"setInterpolation",
"(",
"$",
"options",
"[",
"'interpolation'",
"]",
")",
";",
"$",
"fingerprint",
"=",
"isset",
"(",
"$",
"options",
"[",
"'fingerprint'",
"]",
")",
"?",
"$",
"options",
"[",
"'fingerprint'",
"]",
":",
"null",
";",
"$",
"this",
"->",
"builder",
"->",
"setBackgroundImages",
"(",
"$",
"options",
"[",
"'background_images'",
"]",
")",
";",
"$",
"this",
"->",
"builder",
"->",
"setIgnoreAllEffects",
"(",
"$",
"options",
"[",
"'ignore_all_effects'",
"]",
")",
";",
"$",
"content",
"=",
"$",
"this",
"->",
"builder",
"->",
"build",
"(",
"$",
"options",
"[",
"'width'",
"]",
",",
"$",
"options",
"[",
"'height'",
"]",
",",
"$",
"options",
"[",
"'font'",
"]",
",",
"$",
"fingerprint",
")",
"->",
"getGd",
"(",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'keep_value'",
"]",
")",
"{",
"$",
"options",
"[",
"'fingerprint'",
"]",
"=",
"$",
"this",
"->",
"builder",
"->",
"getFingerprint",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"options",
"[",
"'as_file'",
"]",
")",
"{",
"ob_start",
"(",
")",
";",
"imagejpeg",
"(",
"$",
"content",
",",
"null",
",",
"$",
"options",
"[",
"'quality'",
"]",
")",
";",
"return",
"ob_get_clean",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"imageFileHandler",
"->",
"saveAsFile",
"(",
"$",
"content",
")",
";",
"}"
] | @param array $options
@return string | [
"@param",
"array",
"$options"
] | train | https://github.com/Gregwar/CaptchaBundle/blob/c2d5468556890dd25e0b53bd345fc205562c86f7/Generator/CaptchaGenerator.php#L99-L150 |
Gregwar/CaptchaBundle | Generator/CaptchaGenerator.php | CaptchaGenerator.getPhrase | public function getPhrase(array &$options)
{
// Get the phrase that we'll use for this image
if ($options['keep_value'] && isset($options['phrase'])) {
$phrase = $options['phrase'];
} else {
$phrase = $this->phraseBuilder->build($options['length'], $options['charset']);
$options['phrase'] = $phrase;
}
return $phrase;
} | php | public function getPhrase(array &$options)
{
// Get the phrase that we'll use for this image
if ($options['keep_value'] && isset($options['phrase'])) {
$phrase = $options['phrase'];
} else {
$phrase = $this->phraseBuilder->build($options['length'], $options['charset']);
$options['phrase'] = $phrase;
}
return $phrase;
} | [
"public",
"function",
"getPhrase",
"(",
"array",
"&",
"$",
"options",
")",
"{",
"// Get the phrase that we'll use for this image",
"if",
"(",
"$",
"options",
"[",
"'keep_value'",
"]",
"&&",
"isset",
"(",
"$",
"options",
"[",
"'phrase'",
"]",
")",
")",
"{",
"$",
"phrase",
"=",
"$",
"options",
"[",
"'phrase'",
"]",
";",
"}",
"else",
"{",
"$",
"phrase",
"=",
"$",
"this",
"->",
"phraseBuilder",
"->",
"build",
"(",
"$",
"options",
"[",
"'length'",
"]",
",",
"$",
"options",
"[",
"'charset'",
"]",
")",
";",
"$",
"options",
"[",
"'phrase'",
"]",
"=",
"$",
"phrase",
";",
"}",
"return",
"$",
"phrase",
";",
"}"
] | @param array $options
@return string | [
"@param",
"array",
"$options"
] | train | https://github.com/Gregwar/CaptchaBundle/blob/c2d5468556890dd25e0b53bd345fc205562c86f7/Generator/CaptchaGenerator.php#L157-L168 |
Gregwar/CaptchaBundle | Type/CaptchaType.php | CaptchaType.buildForm | public function buildForm(FormBuilderInterface $builder, array $options)
{
$validator = new CaptchaValidator(
$this->translator,
$this->session,
sprintf('%s%s', self::SESSION_KEY_PREFIX, $options['session_key']),
$options['invalid_message'],
$options['bypass_code'],
$options['humanity']
);
$event = \Symfony\Component\HttpKernel\Kernel::VERSION >= 2.3 ? FormEvents::POST_SUBMIT : FormEvents::POST_BIND;
$builder->addEventListener($event, array($validator, 'validate'));
} | php | public function buildForm(FormBuilderInterface $builder, array $options)
{
$validator = new CaptchaValidator(
$this->translator,
$this->session,
sprintf('%s%s', self::SESSION_KEY_PREFIX, $options['session_key']),
$options['invalid_message'],
$options['bypass_code'],
$options['humanity']
);
$event = \Symfony\Component\HttpKernel\Kernel::VERSION >= 2.3 ? FormEvents::POST_SUBMIT : FormEvents::POST_BIND;
$builder->addEventListener($event, array($validator, 'validate'));
} | [
"public",
"function",
"buildForm",
"(",
"FormBuilderInterface",
"$",
"builder",
",",
"array",
"$",
"options",
")",
"{",
"$",
"validator",
"=",
"new",
"CaptchaValidator",
"(",
"$",
"this",
"->",
"translator",
",",
"$",
"this",
"->",
"session",
",",
"sprintf",
"(",
"'%s%s'",
",",
"self",
"::",
"SESSION_KEY_PREFIX",
",",
"$",
"options",
"[",
"'session_key'",
"]",
")",
",",
"$",
"options",
"[",
"'invalid_message'",
"]",
",",
"$",
"options",
"[",
"'bypass_code'",
"]",
",",
"$",
"options",
"[",
"'humanity'",
"]",
")",
";",
"$",
"event",
"=",
"\\",
"Symfony",
"\\",
"Component",
"\\",
"HttpKernel",
"\\",
"Kernel",
"::",
"VERSION",
">=",
"2.3",
"?",
"FormEvents",
"::",
"POST_SUBMIT",
":",
"FormEvents",
"::",
"POST_BIND",
";",
"$",
"builder",
"->",
"addEventListener",
"(",
"$",
"event",
",",
"array",
"(",
"$",
"validator",
",",
"'validate'",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/Gregwar/CaptchaBundle/blob/c2d5468556890dd25e0b53bd345fc205562c86f7/Type/CaptchaType.php#L65-L77 |
Gregwar/CaptchaBundle | Type/CaptchaType.php | CaptchaType.buildView | public function buildView(FormView $view, FormInterface $form, array $options)
{
if ($options['reload'] && !$options['as_url']) {
throw new \InvalidArgumentException('GregwarCaptcha: The reload option cannot be set without as_url, see the README for more information');
}
$sessionKey = sprintf('%s%s', self::SESSION_KEY_PREFIX, $options['session_key']);
$isHuman = false;
if ($options['humanity'] > 0) {
$humanityKey = sprintf('%s_humanity', $sessionKey);
if ($this->session->get($humanityKey, 0) > 0) {
$isHuman = true;
}
}
if ($options['as_url']) {
$keys = $this->session->get($options['whitelist_key'], array());
if (!in_array($sessionKey, $keys)) {
$keys[] = $sessionKey;
}
$this->session->set($options['whitelist_key'], $keys);
$options['session_key'] = $sessionKey;
}
$view->vars = array_merge($view->vars, array(
'captcha_width' => $options['width'],
'captcha_height' => $options['height'],
'reload' => $options['reload'],
'image_id' => uniqid('captcha_'),
'captcha_code' => $this->generator->getCaptchaCode($options),
'value' => '',
'is_human' => $isHuman
));
$persistOptions = array();
foreach (array('phrase', 'width', 'height', 'distortion', 'length',
'quality', 'background_color', 'background_images', 'text_color') as $key) {
$persistOptions[$key] = $options[$key];
}
$this->session->set($sessionKey, $persistOptions);
} | php | public function buildView(FormView $view, FormInterface $form, array $options)
{
if ($options['reload'] && !$options['as_url']) {
throw new \InvalidArgumentException('GregwarCaptcha: The reload option cannot be set without as_url, see the README for more information');
}
$sessionKey = sprintf('%s%s', self::SESSION_KEY_PREFIX, $options['session_key']);
$isHuman = false;
if ($options['humanity'] > 0) {
$humanityKey = sprintf('%s_humanity', $sessionKey);
if ($this->session->get($humanityKey, 0) > 0) {
$isHuman = true;
}
}
if ($options['as_url']) {
$keys = $this->session->get($options['whitelist_key'], array());
if (!in_array($sessionKey, $keys)) {
$keys[] = $sessionKey;
}
$this->session->set($options['whitelist_key'], $keys);
$options['session_key'] = $sessionKey;
}
$view->vars = array_merge($view->vars, array(
'captcha_width' => $options['width'],
'captcha_height' => $options['height'],
'reload' => $options['reload'],
'image_id' => uniqid('captcha_'),
'captcha_code' => $this->generator->getCaptchaCode($options),
'value' => '',
'is_human' => $isHuman
));
$persistOptions = array();
foreach (array('phrase', 'width', 'height', 'distortion', 'length',
'quality', 'background_color', 'background_images', 'text_color') as $key) {
$persistOptions[$key] = $options[$key];
}
$this->session->set($sessionKey, $persistOptions);
} | [
"public",
"function",
"buildView",
"(",
"FormView",
"$",
"view",
",",
"FormInterface",
"$",
"form",
",",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"$",
"options",
"[",
"'reload'",
"]",
"&&",
"!",
"$",
"options",
"[",
"'as_url'",
"]",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'GregwarCaptcha: The reload option cannot be set without as_url, see the README for more information'",
")",
";",
"}",
"$",
"sessionKey",
"=",
"sprintf",
"(",
"'%s%s'",
",",
"self",
"::",
"SESSION_KEY_PREFIX",
",",
"$",
"options",
"[",
"'session_key'",
"]",
")",
";",
"$",
"isHuman",
"=",
"false",
";",
"if",
"(",
"$",
"options",
"[",
"'humanity'",
"]",
">",
"0",
")",
"{",
"$",
"humanityKey",
"=",
"sprintf",
"(",
"'%s_humanity'",
",",
"$",
"sessionKey",
")",
";",
"if",
"(",
"$",
"this",
"->",
"session",
"->",
"get",
"(",
"$",
"humanityKey",
",",
"0",
")",
">",
"0",
")",
"{",
"$",
"isHuman",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"$",
"options",
"[",
"'as_url'",
"]",
")",
"{",
"$",
"keys",
"=",
"$",
"this",
"->",
"session",
"->",
"get",
"(",
"$",
"options",
"[",
"'whitelist_key'",
"]",
",",
"array",
"(",
")",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"sessionKey",
",",
"$",
"keys",
")",
")",
"{",
"$",
"keys",
"[",
"]",
"=",
"$",
"sessionKey",
";",
"}",
"$",
"this",
"->",
"session",
"->",
"set",
"(",
"$",
"options",
"[",
"'whitelist_key'",
"]",
",",
"$",
"keys",
")",
";",
"$",
"options",
"[",
"'session_key'",
"]",
"=",
"$",
"sessionKey",
";",
"}",
"$",
"view",
"->",
"vars",
"=",
"array_merge",
"(",
"$",
"view",
"->",
"vars",
",",
"array",
"(",
"'captcha_width'",
"=>",
"$",
"options",
"[",
"'width'",
"]",
",",
"'captcha_height'",
"=>",
"$",
"options",
"[",
"'height'",
"]",
",",
"'reload'",
"=>",
"$",
"options",
"[",
"'reload'",
"]",
",",
"'image_id'",
"=>",
"uniqid",
"(",
"'captcha_'",
")",
",",
"'captcha_code'",
"=>",
"$",
"this",
"->",
"generator",
"->",
"getCaptchaCode",
"(",
"$",
"options",
")",
",",
"'value'",
"=>",
"''",
",",
"'is_human'",
"=>",
"$",
"isHuman",
")",
")",
";",
"$",
"persistOptions",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"array",
"(",
"'phrase'",
",",
"'width'",
",",
"'height'",
",",
"'distortion'",
",",
"'length'",
",",
"'quality'",
",",
"'background_color'",
",",
"'background_images'",
",",
"'text_color'",
")",
"as",
"$",
"key",
")",
"{",
"$",
"persistOptions",
"[",
"$",
"key",
"]",
"=",
"$",
"options",
"[",
"$",
"key",
"]",
";",
"}",
"$",
"this",
"->",
"session",
"->",
"set",
"(",
"$",
"sessionKey",
",",
"$",
"persistOptions",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/Gregwar/CaptchaBundle/blob/c2d5468556890dd25e0b53bd345fc205562c86f7/Type/CaptchaType.php#L82-L124 |
Gregwar/CaptchaBundle | Validator/CaptchaValidator.php | CaptchaValidator.getExpectedCode | protected function getExpectedCode()
{
$options = $this->session->get($this->key, array());
if (is_array($options) && isset($options['phrase'])) {
return $options['phrase'];
}
return null;
} | php | protected function getExpectedCode()
{
$options = $this->session->get($this->key, array());
if (is_array($options) && isset($options['phrase'])) {
return $options['phrase'];
}
return null;
} | [
"protected",
"function",
"getExpectedCode",
"(",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"session",
"->",
"get",
"(",
"$",
"this",
"->",
"key",
",",
"array",
"(",
")",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"options",
")",
"&&",
"isset",
"(",
"$",
"options",
"[",
"'phrase'",
"]",
")",
")",
"{",
"return",
"$",
"options",
"[",
"'phrase'",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Retrieve the expected CAPTCHA code
@return mixed|null | [
"Retrieve",
"the",
"expected",
"CAPTCHA",
"code"
] | train | https://github.com/Gregwar/CaptchaBundle/blob/c2d5468556890dd25e0b53bd345fc205562c86f7/Validator/CaptchaValidator.php#L105-L114 |
Gregwar/CaptchaBundle | Validator/CaptchaValidator.php | CaptchaValidator.updateHumanity | protected function updateHumanity($newValue)
{
if ($newValue > 0) {
$this->session->set($this->key . '_humanity', $newValue);
} else {
$this->session->remove($this->key . '_humanity');
}
return null;
} | php | protected function updateHumanity($newValue)
{
if ($newValue > 0) {
$this->session->set($this->key . '_humanity', $newValue);
} else {
$this->session->remove($this->key . '_humanity');
}
return null;
} | [
"protected",
"function",
"updateHumanity",
"(",
"$",
"newValue",
")",
"{",
"if",
"(",
"$",
"newValue",
">",
"0",
")",
"{",
"$",
"this",
"->",
"session",
"->",
"set",
"(",
"$",
"this",
"->",
"key",
".",
"'_humanity'",
",",
"$",
"newValue",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"session",
"->",
"remove",
"(",
"$",
"this",
"->",
"key",
".",
"'_humanity'",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Updates the humanity | [
"Updates",
"the",
"humanity"
] | train | https://github.com/Gregwar/CaptchaBundle/blob/c2d5468556890dd25e0b53bd345fc205562c86f7/Validator/CaptchaValidator.php#L129-L138 |
Gregwar/CaptchaBundle | Validator/CaptchaValidator.php | CaptchaValidator.compare | protected function compare($code, $expectedCode)
{
return ($expectedCode !== null && is_string($expectedCode) && $this->niceize($code) == $this->niceize($expectedCode));
} | php | protected function compare($code, $expectedCode)
{
return ($expectedCode !== null && is_string($expectedCode) && $this->niceize($code) == $this->niceize($expectedCode));
} | [
"protected",
"function",
"compare",
"(",
"$",
"code",
",",
"$",
"expectedCode",
")",
"{",
"return",
"(",
"$",
"expectedCode",
"!==",
"null",
"&&",
"is_string",
"(",
"$",
"expectedCode",
")",
"&&",
"$",
"this",
"->",
"niceize",
"(",
"$",
"code",
")",
"==",
"$",
"this",
"->",
"niceize",
"(",
"$",
"expectedCode",
")",
")",
";",
"}"
] | Run a match comparison on the provided code and the expected code
@param $code
@param $expectedCode
@return bool | [
"Run",
"a",
"match",
"comparison",
"on",
"the",
"provided",
"code",
"and",
"the",
"expected",
"code"
] | train | https://github.com/Gregwar/CaptchaBundle/blob/c2d5468556890dd25e0b53bd345fc205562c86f7/Validator/CaptchaValidator.php#L160-L163 |
Gregwar/CaptchaBundle | DependencyInjection/Configuration.php | Configuration.getConfigTreeBuilder | public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('gregwar_captcha');
$rootNode
->addDefaultsIfNotSet()
->children()
->scalarNode('length')->defaultValue(5)->end()
->scalarNode('width')->defaultValue(130)->end()
->scalarNode('height')->defaultValue(50)->end()
->scalarNode('font')->defaultValue(__DIR__.'/../Generator/Font/captcha.ttf')->end()
->scalarNode('keep_value')->defaultValue(false)->end()
->scalarNode('charset')->defaultValue('abcdefhjkmnprstuvwxyz23456789')->end()
->scalarNode('as_file')->defaultValue(false)->end()
->scalarNode('as_url')->defaultValue(false)->end()
->scalarNode('reload')->defaultValue(false)->end()
->scalarNode('image_folder')->defaultValue('captcha')->end()
->scalarNode('web_path')->defaultValue('%kernel.root_dir%/../web')->end()
->scalarNode('gc_freq')->defaultValue(100)->end()
->scalarNode('expiration')->defaultValue(60)->end()
->scalarNode('quality')->defaultValue(50)->end()
->scalarNode('invalid_message')->defaultValue('Bad code value')->end()
->scalarNode('bypass_code')->defaultValue(null)->end()
->scalarNode('whitelist_key')->defaultValue('captcha_whitelist_key')->end()
->scalarNode('humanity')->defaultValue(0)->end()
->scalarNode('distortion')->defaultValue(true)->end()
->scalarNode('max_front_lines')->defaultValue(null)->end()
->scalarNode('max_behind_lines')->defaultValue(null)->end()
->scalarNode('interpolation')->defaultValue(true)->end()
->arrayNode('text_color')->prototype('scalar')->end()->end()
->arrayNode('background_color')->prototype('scalar')->end()->end()
->arrayNode('background_images')->prototype('scalar')->end()->end()
->scalarNode('disabled')->defaultValue(false)->end()
->scalarNode('ignore_all_effects')->defaultValue(false)->end()
->scalarNode('session_key')->defaultValue('captcha')->end()
->end()
;
return $treeBuilder;
} | php | public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('gregwar_captcha');
$rootNode
->addDefaultsIfNotSet()
->children()
->scalarNode('length')->defaultValue(5)->end()
->scalarNode('width')->defaultValue(130)->end()
->scalarNode('height')->defaultValue(50)->end()
->scalarNode('font')->defaultValue(__DIR__.'/../Generator/Font/captcha.ttf')->end()
->scalarNode('keep_value')->defaultValue(false)->end()
->scalarNode('charset')->defaultValue('abcdefhjkmnprstuvwxyz23456789')->end()
->scalarNode('as_file')->defaultValue(false)->end()
->scalarNode('as_url')->defaultValue(false)->end()
->scalarNode('reload')->defaultValue(false)->end()
->scalarNode('image_folder')->defaultValue('captcha')->end()
->scalarNode('web_path')->defaultValue('%kernel.root_dir%/../web')->end()
->scalarNode('gc_freq')->defaultValue(100)->end()
->scalarNode('expiration')->defaultValue(60)->end()
->scalarNode('quality')->defaultValue(50)->end()
->scalarNode('invalid_message')->defaultValue('Bad code value')->end()
->scalarNode('bypass_code')->defaultValue(null)->end()
->scalarNode('whitelist_key')->defaultValue('captcha_whitelist_key')->end()
->scalarNode('humanity')->defaultValue(0)->end()
->scalarNode('distortion')->defaultValue(true)->end()
->scalarNode('max_front_lines')->defaultValue(null)->end()
->scalarNode('max_behind_lines')->defaultValue(null)->end()
->scalarNode('interpolation')->defaultValue(true)->end()
->arrayNode('text_color')->prototype('scalar')->end()->end()
->arrayNode('background_color')->prototype('scalar')->end()->end()
->arrayNode('background_images')->prototype('scalar')->end()->end()
->scalarNode('disabled')->defaultValue(false)->end()
->scalarNode('ignore_all_effects')->defaultValue(false)->end()
->scalarNode('session_key')->defaultValue('captcha')->end()
->end()
;
return $treeBuilder;
} | [
"public",
"function",
"getConfigTreeBuilder",
"(",
")",
"{",
"$",
"treeBuilder",
"=",
"new",
"TreeBuilder",
"(",
")",
";",
"$",
"rootNode",
"=",
"$",
"treeBuilder",
"->",
"root",
"(",
"'gregwar_captcha'",
")",
";",
"$",
"rootNode",
"->",
"addDefaultsIfNotSet",
"(",
")",
"->",
"children",
"(",
")",
"->",
"scalarNode",
"(",
"'length'",
")",
"->",
"defaultValue",
"(",
"5",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'width'",
")",
"->",
"defaultValue",
"(",
"130",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'height'",
")",
"->",
"defaultValue",
"(",
"50",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'font'",
")",
"->",
"defaultValue",
"(",
"__DIR__",
".",
"'/../Generator/Font/captcha.ttf'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'keep_value'",
")",
"->",
"defaultValue",
"(",
"false",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'charset'",
")",
"->",
"defaultValue",
"(",
"'abcdefhjkmnprstuvwxyz23456789'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'as_file'",
")",
"->",
"defaultValue",
"(",
"false",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'as_url'",
")",
"->",
"defaultValue",
"(",
"false",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'reload'",
")",
"->",
"defaultValue",
"(",
"false",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'image_folder'",
")",
"->",
"defaultValue",
"(",
"'captcha'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'web_path'",
")",
"->",
"defaultValue",
"(",
"'%kernel.root_dir%/../web'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'gc_freq'",
")",
"->",
"defaultValue",
"(",
"100",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'expiration'",
")",
"->",
"defaultValue",
"(",
"60",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'quality'",
")",
"->",
"defaultValue",
"(",
"50",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'invalid_message'",
")",
"->",
"defaultValue",
"(",
"'Bad code value'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'bypass_code'",
")",
"->",
"defaultValue",
"(",
"null",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'whitelist_key'",
")",
"->",
"defaultValue",
"(",
"'captcha_whitelist_key'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'humanity'",
")",
"->",
"defaultValue",
"(",
"0",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'distortion'",
")",
"->",
"defaultValue",
"(",
"true",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'max_front_lines'",
")",
"->",
"defaultValue",
"(",
"null",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'max_behind_lines'",
")",
"->",
"defaultValue",
"(",
"null",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'interpolation'",
")",
"->",
"defaultValue",
"(",
"true",
")",
"->",
"end",
"(",
")",
"->",
"arrayNode",
"(",
"'text_color'",
")",
"->",
"prototype",
"(",
"'scalar'",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"arrayNode",
"(",
"'background_color'",
")",
"->",
"prototype",
"(",
"'scalar'",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"arrayNode",
"(",
"'background_images'",
")",
"->",
"prototype",
"(",
"'scalar'",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'disabled'",
")",
"->",
"defaultValue",
"(",
"false",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'ignore_all_effects'",
")",
"->",
"defaultValue",
"(",
"false",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'session_key'",
")",
"->",
"defaultValue",
"(",
"'captcha'",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
";",
"return",
"$",
"treeBuilder",
";",
"}"
] | Generates the configuration tree.
@return TreeBuilder | [
"Generates",
"the",
"configuration",
"tree",
"."
] | train | https://github.com/Gregwar/CaptchaBundle/blob/c2d5468556890dd25e0b53bd345fc205562c86f7/DependencyInjection/Configuration.php#L15-L55 |
Gregwar/CaptchaBundle | Controller/CaptchaController.php | CaptchaController.generateCaptchaAction | public function generateCaptchaAction($key)
{
$options = $this->container->getParameter('gregwar_captcha.config');
$session = $this->get('session');
$whitelistKey = $options['whitelist_key'];
$isOk = false;
if ($session->has($whitelistKey)) {
$keys = $session->get($whitelistKey);
if (is_array($keys) && in_array($key, $keys)) {
$isOk = true;
}
}
if (!$isOk) {
return $this->error($options);
}
/* @var \Gregwar\CaptchaBundle\Generator\CaptchaGenerator $generator */
$generator = $this->container->get('gregwar_captcha.generator');
$persistedOptions = $session->get($key, array());
$options = array_merge($options, $persistedOptions);
$phrase = $generator->getPhrase($options);
$generator->setPhrase($phrase);
$persistedOptions['phrase'] = $phrase;
$session->set($key, $persistedOptions);
$response = new Response($generator->generate($options));
$response->headers->set('Content-type', 'image/jpeg');
$response->headers->set('Pragma', 'no-cache');
$response->headers->set('Cache-Control', 'no-cache');
return $response;
} | php | public function generateCaptchaAction($key)
{
$options = $this->container->getParameter('gregwar_captcha.config');
$session = $this->get('session');
$whitelistKey = $options['whitelist_key'];
$isOk = false;
if ($session->has($whitelistKey)) {
$keys = $session->get($whitelistKey);
if (is_array($keys) && in_array($key, $keys)) {
$isOk = true;
}
}
if (!$isOk) {
return $this->error($options);
}
/* @var \Gregwar\CaptchaBundle\Generator\CaptchaGenerator $generator */
$generator = $this->container->get('gregwar_captcha.generator');
$persistedOptions = $session->get($key, array());
$options = array_merge($options, $persistedOptions);
$phrase = $generator->getPhrase($options);
$generator->setPhrase($phrase);
$persistedOptions['phrase'] = $phrase;
$session->set($key, $persistedOptions);
$response = new Response($generator->generate($options));
$response->headers->set('Content-type', 'image/jpeg');
$response->headers->set('Pragma', 'no-cache');
$response->headers->set('Cache-Control', 'no-cache');
return $response;
} | [
"public",
"function",
"generateCaptchaAction",
"(",
"$",
"key",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'gregwar_captcha.config'",
")",
";",
"$",
"session",
"=",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
";",
"$",
"whitelistKey",
"=",
"$",
"options",
"[",
"'whitelist_key'",
"]",
";",
"$",
"isOk",
"=",
"false",
";",
"if",
"(",
"$",
"session",
"->",
"has",
"(",
"$",
"whitelistKey",
")",
")",
"{",
"$",
"keys",
"=",
"$",
"session",
"->",
"get",
"(",
"$",
"whitelistKey",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"keys",
")",
"&&",
"in_array",
"(",
"$",
"key",
",",
"$",
"keys",
")",
")",
"{",
"$",
"isOk",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"isOk",
")",
"{",
"return",
"$",
"this",
"->",
"error",
"(",
"$",
"options",
")",
";",
"}",
"/* @var \\Gregwar\\CaptchaBundle\\Generator\\CaptchaGenerator $generator */",
"$",
"generator",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'gregwar_captcha.generator'",
")",
";",
"$",
"persistedOptions",
"=",
"$",
"session",
"->",
"get",
"(",
"$",
"key",
",",
"array",
"(",
")",
")",
";",
"$",
"options",
"=",
"array_merge",
"(",
"$",
"options",
",",
"$",
"persistedOptions",
")",
";",
"$",
"phrase",
"=",
"$",
"generator",
"->",
"getPhrase",
"(",
"$",
"options",
")",
";",
"$",
"generator",
"->",
"setPhrase",
"(",
"$",
"phrase",
")",
";",
"$",
"persistedOptions",
"[",
"'phrase'",
"]",
"=",
"$",
"phrase",
";",
"$",
"session",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"persistedOptions",
")",
";",
"$",
"response",
"=",
"new",
"Response",
"(",
"$",
"generator",
"->",
"generate",
"(",
"$",
"options",
")",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'Content-type'",
",",
"'image/jpeg'",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'Pragma'",
",",
"'no-cache'",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'Cache-Control'",
",",
"'no-cache'",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Action that is used to generate the captcha, save its code, and stream the image
@param string $key
@return Response
@throws NotFoundHttpException | [
"Action",
"that",
"is",
"used",
"to",
"generate",
"the",
"captcha",
"save",
"its",
"code",
"and",
"stream",
"the",
"image"
] | train | https://github.com/Gregwar/CaptchaBundle/blob/c2d5468556890dd25e0b53bd345fc205562c86f7/Controller/CaptchaController.php#L25-L60 |
Gregwar/CaptchaBundle | Controller/CaptchaController.php | CaptchaController.error | protected function error($options)
{
/* @var \Gregwar\CaptchaBundle\Generator\CaptchaGenerator $generator */
$generator = $this->container->get('gregwar_captcha.generator');
$generator->setPhrase('');
$response = new Response($generator->generate($options));
$response->setStatusCode(428);
$response->headers->set('Content-type', 'image/jpeg');
$response->headers->set('Pragma', 'no-cache');
$response->headers->set('Cache-Control', 'no-cache');
return $response;
} | php | protected function error($options)
{
/* @var \Gregwar\CaptchaBundle\Generator\CaptchaGenerator $generator */
$generator = $this->container->get('gregwar_captcha.generator');
$generator->setPhrase('');
$response = new Response($generator->generate($options));
$response->setStatusCode(428);
$response->headers->set('Content-type', 'image/jpeg');
$response->headers->set('Pragma', 'no-cache');
$response->headers->set('Cache-Control', 'no-cache');
return $response;
} | [
"protected",
"function",
"error",
"(",
"$",
"options",
")",
"{",
"/* @var \\Gregwar\\CaptchaBundle\\Generator\\CaptchaGenerator $generator */",
"$",
"generator",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'gregwar_captcha.generator'",
")",
";",
"$",
"generator",
"->",
"setPhrase",
"(",
"''",
")",
";",
"$",
"response",
"=",
"new",
"Response",
"(",
"$",
"generator",
"->",
"generate",
"(",
"$",
"options",
")",
")",
";",
"$",
"response",
"->",
"setStatusCode",
"(",
"428",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'Content-type'",
",",
"'image/jpeg'",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'Pragma'",
",",
"'no-cache'",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'Cache-Control'",
",",
"'no-cache'",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Returns an empty image with status code 428 Precondition Required
@param array $options
@return Response | [
"Returns",
"an",
"empty",
"image",
"with",
"status",
"code",
"428",
"Precondition",
"Required"
] | train | https://github.com/Gregwar/CaptchaBundle/blob/c2d5468556890dd25e0b53bd345fc205562c86f7/Controller/CaptchaController.php#L69-L82 |
moonlandsoft/yii2-phpexcel | Excel.php | Excel.init | public function init()
{
parent::init();
if ($this->formatter == null) {
$this->formatter = \Yii::$app->getFormatter();
} elseif (is_array($this->formatter)) {
$this->formatter = \Yii::createObject($this->formatter);
}
if (!$this->formatter instanceof Formatter) {
throw new InvalidConfigException('The "formatter" property must be either a Format object or a configuration array.');
}
} | php | public function init()
{
parent::init();
if ($this->formatter == null) {
$this->formatter = \Yii::$app->getFormatter();
} elseif (is_array($this->formatter)) {
$this->formatter = \Yii::createObject($this->formatter);
}
if (!$this->formatter instanceof Formatter) {
throw new InvalidConfigException('The "formatter" property must be either a Format object or a configuration array.');
}
} | [
"public",
"function",
"init",
"(",
")",
"{",
"parent",
"::",
"init",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"formatter",
"==",
"null",
")",
"{",
"$",
"this",
"->",
"formatter",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"getFormatter",
"(",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"this",
"->",
"formatter",
")",
")",
"{",
"$",
"this",
"->",
"formatter",
"=",
"\\",
"Yii",
"::",
"createObject",
"(",
"$",
"this",
"->",
"formatter",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"formatter",
"instanceof",
"Formatter",
")",
"{",
"throw",
"new",
"InvalidConfigException",
"(",
"'The \"formatter\" property must be either a Format object or a configuration array.'",
")",
";",
"}",
"}"
] | (non-PHPdoc)
@see \yii\base\Object::init() | [
"(",
"non",
"-",
"PHPdoc",
")"
] | train | https://github.com/moonlandsoft/yii2-phpexcel/blob/ccf28ff8ce2c665a7769dd6516098b4a35c8c309/Excel.php#L442-L453 |
moonlandsoft/yii2-phpexcel | Excel.php | Excel.executeColumns | public function executeColumns(&$activeSheet = null, $models, $columns = [], $headers = [])
{
if ($activeSheet == null) {
$activeSheet = $this->activeSheet;
}
$hasHeader = false;
$row = 1;
$char = 26;
foreach ($models as $model) {
if (empty($columns)) {
$columns = $model->attributes();
}
if ($this->setFirstTitle && !$hasHeader) {
$isPlus = false;
$colplus = 0;
$colnum = 1;
foreach ($columns as $key=>$column) {
$col = '';
if ($colnum > $char) {
$colplus += 1;
$colnum = 1;
$isPlus = true;
}
if ($isPlus) {
$col .= chr(64+$colplus);
}
$col .= chr(64+$colnum);
$header = '';
if (is_array($column)) {
if (isset($column['header'])) {
$header = $column['header'];
} elseif (isset($column['attribute']) && isset($headers[$column['attribute']])) {
$header = $headers[$column['attribute']];
} elseif (isset($column['attribute'])) {
$header = $model->getAttributeLabel($column['attribute']);
} elseif (isset($column['cellFormat']) && is_array($column['cellFormat'])) {
$activeSheet->getStyle($col.$row)->applyFromArray($column['cellFormat']);
}
} else {
if(isset($headers[$column])) {
$header = $headers[$column];
} else {
$header = $model->getAttributeLabel($column);
}
}
if (isset($column['width'])) {
$activeSheet->getColumnDimension(strtoupper($col))->setWidth($column['width']);
}
$activeSheet->setCellValue($col.$row,$header);
$colnum++;
}
$hasHeader=true;
$row++;
}
$isPlus = false;
$colplus = 0;
$colnum = 1;
foreach ($columns as $key=>$column) {
$col = '';
if ($colnum > $char) {
$colplus++;
$colnum = 1;
$isPlus = true;
}
if ($isPlus) {
$col .= chr(64+$colplus);
}
$col .= chr(64+$colnum);
if (is_array($column)) {
$column_value = $this->executeGetColumnData($model, $column);
if (isset($column['cellFormat']) && is_array($column['cellFormat'])) {
$activeSheet->getStyle($col.$row)->applyFromArray($column['cellFormat']);
}
} else {
$column_value = $this->executeGetColumnData($model, ['attribute' => $column]);
}
$activeSheet->setCellValue($col.$row,$column_value);
$colnum++;
}
$row++;
if($this->autoSize){
foreach (range(0, $colnum) as $col) {
$activeSheet->getColumnDimensionByColumn($col)->setAutoSize(true);
}
}
}
} | php | public function executeColumns(&$activeSheet = null, $models, $columns = [], $headers = [])
{
if ($activeSheet == null) {
$activeSheet = $this->activeSheet;
}
$hasHeader = false;
$row = 1;
$char = 26;
foreach ($models as $model) {
if (empty($columns)) {
$columns = $model->attributes();
}
if ($this->setFirstTitle && !$hasHeader) {
$isPlus = false;
$colplus = 0;
$colnum = 1;
foreach ($columns as $key=>$column) {
$col = '';
if ($colnum > $char) {
$colplus += 1;
$colnum = 1;
$isPlus = true;
}
if ($isPlus) {
$col .= chr(64+$colplus);
}
$col .= chr(64+$colnum);
$header = '';
if (is_array($column)) {
if (isset($column['header'])) {
$header = $column['header'];
} elseif (isset($column['attribute']) && isset($headers[$column['attribute']])) {
$header = $headers[$column['attribute']];
} elseif (isset($column['attribute'])) {
$header = $model->getAttributeLabel($column['attribute']);
} elseif (isset($column['cellFormat']) && is_array($column['cellFormat'])) {
$activeSheet->getStyle($col.$row)->applyFromArray($column['cellFormat']);
}
} else {
if(isset($headers[$column])) {
$header = $headers[$column];
} else {
$header = $model->getAttributeLabel($column);
}
}
if (isset($column['width'])) {
$activeSheet->getColumnDimension(strtoupper($col))->setWidth($column['width']);
}
$activeSheet->setCellValue($col.$row,$header);
$colnum++;
}
$hasHeader=true;
$row++;
}
$isPlus = false;
$colplus = 0;
$colnum = 1;
foreach ($columns as $key=>$column) {
$col = '';
if ($colnum > $char) {
$colplus++;
$colnum = 1;
$isPlus = true;
}
if ($isPlus) {
$col .= chr(64+$colplus);
}
$col .= chr(64+$colnum);
if (is_array($column)) {
$column_value = $this->executeGetColumnData($model, $column);
if (isset($column['cellFormat']) && is_array($column['cellFormat'])) {
$activeSheet->getStyle($col.$row)->applyFromArray($column['cellFormat']);
}
} else {
$column_value = $this->executeGetColumnData($model, ['attribute' => $column]);
}
$activeSheet->setCellValue($col.$row,$column_value);
$colnum++;
}
$row++;
if($this->autoSize){
foreach (range(0, $colnum) as $col) {
$activeSheet->getColumnDimensionByColumn($col)->setAutoSize(true);
}
}
}
} | [
"public",
"function",
"executeColumns",
"(",
"&",
"$",
"activeSheet",
"=",
"null",
",",
"$",
"models",
",",
"$",
"columns",
"=",
"[",
"]",
",",
"$",
"headers",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"activeSheet",
"==",
"null",
")",
"{",
"$",
"activeSheet",
"=",
"$",
"this",
"->",
"activeSheet",
";",
"}",
"$",
"hasHeader",
"=",
"false",
";",
"$",
"row",
"=",
"1",
";",
"$",
"char",
"=",
"26",
";",
"foreach",
"(",
"$",
"models",
"as",
"$",
"model",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"columns",
")",
")",
"{",
"$",
"columns",
"=",
"$",
"model",
"->",
"attributes",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"setFirstTitle",
"&&",
"!",
"$",
"hasHeader",
")",
"{",
"$",
"isPlus",
"=",
"false",
";",
"$",
"colplus",
"=",
"0",
";",
"$",
"colnum",
"=",
"1",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"key",
"=>",
"$",
"column",
")",
"{",
"$",
"col",
"=",
"''",
";",
"if",
"(",
"$",
"colnum",
">",
"$",
"char",
")",
"{",
"$",
"colplus",
"+=",
"1",
";",
"$",
"colnum",
"=",
"1",
";",
"$",
"isPlus",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"isPlus",
")",
"{",
"$",
"col",
".=",
"chr",
"(",
"64",
"+",
"$",
"colplus",
")",
";",
"}",
"$",
"col",
".=",
"chr",
"(",
"64",
"+",
"$",
"colnum",
")",
";",
"$",
"header",
"=",
"''",
";",
"if",
"(",
"is_array",
"(",
"$",
"column",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"column",
"[",
"'header'",
"]",
")",
")",
"{",
"$",
"header",
"=",
"$",
"column",
"[",
"'header'",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"column",
"[",
"'attribute'",
"]",
")",
"&&",
"isset",
"(",
"$",
"headers",
"[",
"$",
"column",
"[",
"'attribute'",
"]",
"]",
")",
")",
"{",
"$",
"header",
"=",
"$",
"headers",
"[",
"$",
"column",
"[",
"'attribute'",
"]",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"column",
"[",
"'attribute'",
"]",
")",
")",
"{",
"$",
"header",
"=",
"$",
"model",
"->",
"getAttributeLabel",
"(",
"$",
"column",
"[",
"'attribute'",
"]",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"column",
"[",
"'cellFormat'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"column",
"[",
"'cellFormat'",
"]",
")",
")",
"{",
"$",
"activeSheet",
"->",
"getStyle",
"(",
"$",
"col",
".",
"$",
"row",
")",
"->",
"applyFromArray",
"(",
"$",
"column",
"[",
"'cellFormat'",
"]",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"headers",
"[",
"$",
"column",
"]",
")",
")",
"{",
"$",
"header",
"=",
"$",
"headers",
"[",
"$",
"column",
"]",
";",
"}",
"else",
"{",
"$",
"header",
"=",
"$",
"model",
"->",
"getAttributeLabel",
"(",
"$",
"column",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"column",
"[",
"'width'",
"]",
")",
")",
"{",
"$",
"activeSheet",
"->",
"getColumnDimension",
"(",
"strtoupper",
"(",
"$",
"col",
")",
")",
"->",
"setWidth",
"(",
"$",
"column",
"[",
"'width'",
"]",
")",
";",
"}",
"$",
"activeSheet",
"->",
"setCellValue",
"(",
"$",
"col",
".",
"$",
"row",
",",
"$",
"header",
")",
";",
"$",
"colnum",
"++",
";",
"}",
"$",
"hasHeader",
"=",
"true",
";",
"$",
"row",
"++",
";",
"}",
"$",
"isPlus",
"=",
"false",
";",
"$",
"colplus",
"=",
"0",
";",
"$",
"colnum",
"=",
"1",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"key",
"=>",
"$",
"column",
")",
"{",
"$",
"col",
"=",
"''",
";",
"if",
"(",
"$",
"colnum",
">",
"$",
"char",
")",
"{",
"$",
"colplus",
"++",
";",
"$",
"colnum",
"=",
"1",
";",
"$",
"isPlus",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"isPlus",
")",
"{",
"$",
"col",
".=",
"chr",
"(",
"64",
"+",
"$",
"colplus",
")",
";",
"}",
"$",
"col",
".=",
"chr",
"(",
"64",
"+",
"$",
"colnum",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"column",
")",
")",
"{",
"$",
"column_value",
"=",
"$",
"this",
"->",
"executeGetColumnData",
"(",
"$",
"model",
",",
"$",
"column",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"column",
"[",
"'cellFormat'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"column",
"[",
"'cellFormat'",
"]",
")",
")",
"{",
"$",
"activeSheet",
"->",
"getStyle",
"(",
"$",
"col",
".",
"$",
"row",
")",
"->",
"applyFromArray",
"(",
"$",
"column",
"[",
"'cellFormat'",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"column_value",
"=",
"$",
"this",
"->",
"executeGetColumnData",
"(",
"$",
"model",
",",
"[",
"'attribute'",
"=>",
"$",
"column",
"]",
")",
";",
"}",
"$",
"activeSheet",
"->",
"setCellValue",
"(",
"$",
"col",
".",
"$",
"row",
",",
"$",
"column_value",
")",
";",
"$",
"colnum",
"++",
";",
"}",
"$",
"row",
"++",
";",
"if",
"(",
"$",
"this",
"->",
"autoSize",
")",
"{",
"foreach",
"(",
"range",
"(",
"0",
",",
"$",
"colnum",
")",
"as",
"$",
"col",
")",
"{",
"$",
"activeSheet",
"->",
"getColumnDimensionByColumn",
"(",
"$",
"col",
")",
"->",
"setAutoSize",
"(",
"true",
")",
";",
"}",
"}",
"}",
"}"
] | Setting data from models | [
"Setting",
"data",
"from",
"models"
] | train | https://github.com/moonlandsoft/yii2-phpexcel/blob/ccf28ff8ce2c665a7769dd6516098b4a35c8c309/Excel.php#L458-L545 |
moonlandsoft/yii2-phpexcel | Excel.php | Excel.executeArrayLabel | public function executeArrayLabel($sheetData)
{
$keys = ArrayHelper::remove($sheetData, '1');
$new_data = [];
foreach ($sheetData as $values)
{
$new_data[] = array_combine($keys, $values);
}
return $new_data;
} | php | public function executeArrayLabel($sheetData)
{
$keys = ArrayHelper::remove($sheetData, '1');
$new_data = [];
foreach ($sheetData as $values)
{
$new_data[] = array_combine($keys, $values);
}
return $new_data;
} | [
"public",
"function",
"executeArrayLabel",
"(",
"$",
"sheetData",
")",
"{",
"$",
"keys",
"=",
"ArrayHelper",
"::",
"remove",
"(",
"$",
"sheetData",
",",
"'1'",
")",
";",
"$",
"new_data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"sheetData",
"as",
"$",
"values",
")",
"{",
"$",
"new_data",
"[",
"]",
"=",
"array_combine",
"(",
"$",
"keys",
",",
"$",
"values",
")",
";",
"}",
"return",
"$",
"new_data",
";",
"}"
] | Setting label or keys on every record if setFirstRecordAsKeys is true.
@param array $sheetData
@return multitype:multitype:array | [
"Setting",
"label",
"or",
"keys",
"on",
"every",
"record",
"if",
"setFirstRecordAsKeys",
"is",
"true",
"."
] | train | https://github.com/moonlandsoft/yii2-phpexcel/blob/ccf28ff8ce2c665a7769dd6516098b4a35c8c309/Excel.php#L552-L564 |
moonlandsoft/yii2-phpexcel | Excel.php | Excel.executeLeaveRecords | public function executeLeaveRecords($sheetData = [], $index = [])
{
foreach ($sheetData as $key => $data)
{
if (in_array($key, $index))
{
unset($sheetData[$key]);
}
}
return $sheetData;
} | php | public function executeLeaveRecords($sheetData = [], $index = [])
{
foreach ($sheetData as $key => $data)
{
if (in_array($key, $index))
{
unset($sheetData[$key]);
}
}
return $sheetData;
} | [
"public",
"function",
"executeLeaveRecords",
"(",
"$",
"sheetData",
"=",
"[",
"]",
",",
"$",
"index",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"sheetData",
"as",
"$",
"key",
"=>",
"$",
"data",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"index",
")",
")",
"{",
"unset",
"(",
"$",
"sheetData",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"return",
"$",
"sheetData",
";",
"}"
] | Leave record with same index number.
@param array $sheetData
@param array $index
@return array | [
"Leave",
"record",
"with",
"same",
"index",
"number",
"."
] | train | https://github.com/moonlandsoft/yii2-phpexcel/blob/ccf28ff8ce2c665a7769dd6516098b4a35c8c309/Excel.php#L572-L582 |
moonlandsoft/yii2-phpexcel | Excel.php | Excel.executeGetOnlyRecords | public function executeGetOnlyRecords($sheetData = [], $index = [])
{
foreach ($sheetData as $key => $data)
{
if (!in_array($key, $index))
{
unset($sheetData[$key]);
}
}
return $sheetData;
} | php | public function executeGetOnlyRecords($sheetData = [], $index = [])
{
foreach ($sheetData as $key => $data)
{
if (!in_array($key, $index))
{
unset($sheetData[$key]);
}
}
return $sheetData;
} | [
"public",
"function",
"executeGetOnlyRecords",
"(",
"$",
"sheetData",
"=",
"[",
"]",
",",
"$",
"index",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"sheetData",
"as",
"$",
"key",
"=>",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"key",
",",
"$",
"index",
")",
")",
"{",
"unset",
"(",
"$",
"sheetData",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"return",
"$",
"sheetData",
";",
"}"
] | Read record with same index number.
@param array $sheetData
@param array $index
@return array | [
"Read",
"record",
"with",
"same",
"index",
"number",
"."
] | train | https://github.com/moonlandsoft/yii2-phpexcel/blob/ccf28ff8ce2c665a7769dd6516098b4a35c8c309/Excel.php#L590-L600 |
moonlandsoft/yii2-phpexcel | Excel.php | Excel.executeGetColumnData | public function executeGetColumnData($model, $params = [])
{
$value = null;
if (isset($params['value']) && $params['value'] !== null) {
if (is_string($params['value'])) {
$value = ArrayHelper::getValue($model, $params['value']);
} else {
$value = call_user_func($params['value'], $model, $this);
}
} elseif (isset($params['attribute']) && $params['attribute'] !== null) {
$value = ArrayHelper::getValue($model, $params['attribute']);
}
if (isset($params['format']) && $params['format'] != null)
$value = $this->formatter()->format($value, $params['format']);
return $value;
} | php | public function executeGetColumnData($model, $params = [])
{
$value = null;
if (isset($params['value']) && $params['value'] !== null) {
if (is_string($params['value'])) {
$value = ArrayHelper::getValue($model, $params['value']);
} else {
$value = call_user_func($params['value'], $model, $this);
}
} elseif (isset($params['attribute']) && $params['attribute'] !== null) {
$value = ArrayHelper::getValue($model, $params['attribute']);
}
if (isset($params['format']) && $params['format'] != null)
$value = $this->formatter()->format($value, $params['format']);
return $value;
} | [
"public",
"function",
"executeGetColumnData",
"(",
"$",
"model",
",",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"value",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'value'",
"]",
")",
"&&",
"$",
"params",
"[",
"'value'",
"]",
"!==",
"null",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"params",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"value",
"=",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"model",
",",
"$",
"params",
"[",
"'value'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"call_user_func",
"(",
"$",
"params",
"[",
"'value'",
"]",
",",
"$",
"model",
",",
"$",
"this",
")",
";",
"}",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"params",
"[",
"'attribute'",
"]",
")",
"&&",
"$",
"params",
"[",
"'attribute'",
"]",
"!==",
"null",
")",
"{",
"$",
"value",
"=",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"model",
",",
"$",
"params",
"[",
"'attribute'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'format'",
"]",
")",
"&&",
"$",
"params",
"[",
"'format'",
"]",
"!=",
"null",
")",
"$",
"value",
"=",
"$",
"this",
"->",
"formatter",
"(",
")",
"->",
"format",
"(",
"$",
"value",
",",
"$",
"params",
"[",
"'format'",
"]",
")",
";",
"return",
"$",
"value",
";",
"}"
] | Getting column value.
@param Model $model
@param array $params
@return Ambigous <NULL, string, mixed> | [
"Getting",
"column",
"value",
"."
] | train | https://github.com/moonlandsoft/yii2-phpexcel/blob/ccf28ff8ce2c665a7769dd6516098b4a35c8c309/Excel.php#L608-L625 |
moonlandsoft/yii2-phpexcel | Excel.php | Excel.populateColumns | public function populateColumns($columns = [])
{
$_columns = [];
foreach ($columns as $key => $value)
{
if (is_string($value))
{
$value_log = explode(':', $value);
$_columns[$key] = ['attribute' => $value_log[0]];
if (isset($value_log[1]) && $value_log[1] !== null) {
$_columns[$key]['format'] = $value_log[1];
}
if (isset($value_log[2]) && $value_log[2] !== null) {
$_columns[$key]['header'] = $value_log[2];
}
} elseif (is_array($value)) {
if (!isset($value['attribute']) && !isset($value['value'])) {
throw new \InvalidArgumentException('Attribute or Value must be defined.');
}
$_columns[$key] = $value;
}
}
return $_columns;
} | php | public function populateColumns($columns = [])
{
$_columns = [];
foreach ($columns as $key => $value)
{
if (is_string($value))
{
$value_log = explode(':', $value);
$_columns[$key] = ['attribute' => $value_log[0]];
if (isset($value_log[1]) && $value_log[1] !== null) {
$_columns[$key]['format'] = $value_log[1];
}
if (isset($value_log[2]) && $value_log[2] !== null) {
$_columns[$key]['header'] = $value_log[2];
}
} elseif (is_array($value)) {
if (!isset($value['attribute']) && !isset($value['value'])) {
throw new \InvalidArgumentException('Attribute or Value must be defined.');
}
$_columns[$key] = $value;
}
}
return $_columns;
} | [
"public",
"function",
"populateColumns",
"(",
"$",
"columns",
"=",
"[",
"]",
")",
"{",
"$",
"_columns",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value_log",
"=",
"explode",
"(",
"':'",
",",
"$",
"value",
")",
";",
"$",
"_columns",
"[",
"$",
"key",
"]",
"=",
"[",
"'attribute'",
"=>",
"$",
"value_log",
"[",
"0",
"]",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"value_log",
"[",
"1",
"]",
")",
"&&",
"$",
"value_log",
"[",
"1",
"]",
"!==",
"null",
")",
"{",
"$",
"_columns",
"[",
"$",
"key",
"]",
"[",
"'format'",
"]",
"=",
"$",
"value_log",
"[",
"1",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"value_log",
"[",
"2",
"]",
")",
"&&",
"$",
"value_log",
"[",
"2",
"]",
"!==",
"null",
")",
"{",
"$",
"_columns",
"[",
"$",
"key",
"]",
"[",
"'header'",
"]",
"=",
"$",
"value_log",
"[",
"2",
"]",
";",
"}",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"value",
"[",
"'attribute'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"value",
"[",
"'value'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Attribute or Value must be defined.'",
")",
";",
"}",
"$",
"_columns",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"_columns",
";",
"}"
] | Populating columns for checking the column is string or array. if is string this will be checking have a formatter or header.
@param array $columns
@throws InvalidParamException
@return multitype:multitype:array | [
"Populating",
"columns",
"for",
"checking",
"the",
"column",
"is",
"string",
"or",
"array",
".",
"if",
"is",
"string",
"this",
"will",
"be",
"checking",
"have",
"a",
"formatter",
"or",
"header",
"."
] | train | https://github.com/moonlandsoft/yii2-phpexcel/blob/ccf28ff8ce2c665a7769dd6516098b4a35c8c309/Excel.php#L633-L659 |
moonlandsoft/yii2-phpexcel | Excel.php | Excel.formatter | public function formatter()
{
if (!isset($this->formatter))
$this->formatter = \Yii::$app->getFormatter();
return $this->formatter;
} | php | public function formatter()
{
if (!isset($this->formatter))
$this->formatter = \Yii::$app->getFormatter();
return $this->formatter;
} | [
"public",
"function",
"formatter",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"formatter",
")",
")",
"$",
"this",
"->",
"formatter",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"getFormatter",
"(",
")",
";",
"return",
"$",
"this",
"->",
"formatter",
";",
"}"
] | Formatter for i18n.
@return Formatter | [
"Formatter",
"for",
"i18n",
"."
] | train | https://github.com/moonlandsoft/yii2-phpexcel/blob/ccf28ff8ce2c665a7769dd6516098b4a35c8c309/Excel.php#L665-L671 |
moonlandsoft/yii2-phpexcel | Excel.php | Excel.getFileName | public function getFileName()
{
$fileName = 'exports.xlsx';
if (isset($this->fileName)) {
$fileName = $this->fileName;
if (strpos($fileName, '.xlsx') === false)
$fileName .= '.xlsx';
}
return $fileName;
} | php | public function getFileName()
{
$fileName = 'exports.xlsx';
if (isset($this->fileName)) {
$fileName = $this->fileName;
if (strpos($fileName, '.xlsx') === false)
$fileName .= '.xlsx';
}
return $fileName;
} | [
"public",
"function",
"getFileName",
"(",
")",
"{",
"$",
"fileName",
"=",
"'exports.xlsx'",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"fileName",
")",
")",
"{",
"$",
"fileName",
"=",
"$",
"this",
"->",
"fileName",
";",
"if",
"(",
"strpos",
"(",
"$",
"fileName",
",",
"'.xlsx'",
")",
"===",
"false",
")",
"$",
"fileName",
".=",
"'.xlsx'",
";",
"}",
"return",
"$",
"fileName",
";",
"}"
] | Getting the file name of exporting xls file
@return string | [
"Getting",
"the",
"file",
"name",
"of",
"exporting",
"xls",
"file"
] | train | https://github.com/moonlandsoft/yii2-phpexcel/blob/ccf28ff8ce2c665a7769dd6516098b4a35c8c309/Excel.php#L687-L696 |
moonlandsoft/yii2-phpexcel | Excel.php | Excel.properties | public function properties(&$objectExcel, $properties = [])
{
foreach ($properties as $key => $value)
{
$keyname = "set" . ucfirst($key);
$objectExcel->getProperties()->{$keyname}($value);
}
} | php | public function properties(&$objectExcel, $properties = [])
{
foreach ($properties as $key => $value)
{
$keyname = "set" . ucfirst($key);
$objectExcel->getProperties()->{$keyname}($value);
}
} | [
"public",
"function",
"properties",
"(",
"&",
"$",
"objectExcel",
",",
"$",
"properties",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"keyname",
"=",
"\"set\"",
".",
"ucfirst",
"(",
"$",
"key",
")",
";",
"$",
"objectExcel",
"->",
"getProperties",
"(",
")",
"->",
"{",
"$",
"keyname",
"}",
"(",
"$",
"value",
")",
";",
"}",
"}"
] | Setting properties for excel file
@param PHPExcel $objectExcel
@param array $properties | [
"Setting",
"properties",
"for",
"excel",
"file"
] | train | https://github.com/moonlandsoft/yii2-phpexcel/blob/ccf28ff8ce2c665a7769dd6516098b4a35c8c309/Excel.php#L703-L710 |
moonlandsoft/yii2-phpexcel | Excel.php | Excel.writeFile | public function writeFile($sheet)
{
if (!isset($this->format))
$this->format = 'Xlsx';
$objectwriter = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($sheet, $this->format);
$path = 'php://output';
if (isset($this->savePath) && $this->savePath != null) {
$path = $this->savePath . '/' . $this->getFileName();
}
$objectwriter->setOffice2003Compatibility($this->compatibilityOffice2003);
$objectwriter->setPreCalculateFormulas($this->preCalculationFormula);
$objectwriter->save($path);
if ($path == 'php://output')
exit();
return true;
} | php | public function writeFile($sheet)
{
if (!isset($this->format))
$this->format = 'Xlsx';
$objectwriter = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($sheet, $this->format);
$path = 'php://output';
if (isset($this->savePath) && $this->savePath != null) {
$path = $this->savePath . '/' . $this->getFileName();
}
$objectwriter->setOffice2003Compatibility($this->compatibilityOffice2003);
$objectwriter->setPreCalculateFormulas($this->preCalculationFormula);
$objectwriter->save($path);
if ($path == 'php://output')
exit();
return true;
} | [
"public",
"function",
"writeFile",
"(",
"$",
"sheet",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"format",
")",
")",
"$",
"this",
"->",
"format",
"=",
"'Xlsx'",
";",
"$",
"objectwriter",
"=",
"\\",
"PhpOffice",
"\\",
"PhpSpreadsheet",
"\\",
"IOFactory",
"::",
"createWriter",
"(",
"$",
"sheet",
",",
"$",
"this",
"->",
"format",
")",
";",
"$",
"path",
"=",
"'php://output'",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"savePath",
")",
"&&",
"$",
"this",
"->",
"savePath",
"!=",
"null",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"savePath",
".",
"'/'",
".",
"$",
"this",
"->",
"getFileName",
"(",
")",
";",
"}",
"$",
"objectwriter",
"->",
"setOffice2003Compatibility",
"(",
"$",
"this",
"->",
"compatibilityOffice2003",
")",
";",
"$",
"objectwriter",
"->",
"setPreCalculateFormulas",
"(",
"$",
"this",
"->",
"preCalculationFormula",
")",
";",
"$",
"objectwriter",
"->",
"save",
"(",
"$",
"path",
")",
";",
"if",
"(",
"$",
"path",
"==",
"'php://output'",
")",
"exit",
"(",
")",
";",
"return",
"true",
";",
"}"
] | saving the xls file to download or to path | [
"saving",
"the",
"xls",
"file",
"to",
"download",
"or",
"to",
"path"
] | train | https://github.com/moonlandsoft/yii2-phpexcel/blob/ccf28ff8ce2c665a7769dd6516098b4a35c8c309/Excel.php#L715-L731 |
moonlandsoft/yii2-phpexcel | Excel.php | Excel.readFile | public function readFile($fileName)
{
if (!isset($this->format))
$this->format = \PhpOffice\PhpSpreadsheet\IOFactory::identify($fileName);
$objectreader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($this->format);
if ($this->format == "Csv") {
$objectreader->setDelimiter($this->CSVDelimiter);
$objectreader->setInputEncoding($this->CSVEncoding);
}
$objectPhpExcel = $objectreader->load($fileName);
$sheetCount = $objectPhpExcel->getSheetCount();
$sheetDatas = [];
if ($sheetCount > 1) {
foreach ($objectPhpExcel->getSheetNames() as $sheetIndex => $sheetName) {
if (isset($this->getOnlySheet) && $this->getOnlySheet != null) {
if(!$objectPhpExcel->getSheetByName($this->getOnlySheet)) {
return $sheetDatas;
}
$objectPhpExcel->setActiveSheetIndexByName($this->getOnlySheet);
$indexed = $this->getOnlySheet;
$sheetDatas[$indexed] = $objectPhpExcel->getActiveSheet()->toArray(null, true, true, true);
if ($this->setFirstRecordAsKeys) {
$sheetDatas[$indexed] = $this->executeArrayLabel($sheetDatas[$indexed]);
}
if (!empty($this->getOnlyRecordByIndex)) {
$sheetDatas[$indexed] = $this->executeGetOnlyRecords($sheetDatas[$indexed], $this->getOnlyRecordByIndex);
}
if (!empty($this->leaveRecordByIndex)) {
$sheetDatas[$indexed] = $this->executeLeaveRecords($sheetDatas[$indexed], $this->leaveRecordByIndex);
}
return $sheetDatas[$indexed];
} else {
$objectPhpExcel->setActiveSheetIndexByName($sheetName);
$indexed = $this->setIndexSheetByName==true ? $sheetName : $sheetIndex;
$sheetDatas[$indexed] = $objectPhpExcel->getActiveSheet()->toArray(null, true, true, true);
if ($this->setFirstRecordAsKeys) {
$sheetDatas[$indexed] = $this->executeArrayLabel($sheetDatas[$indexed]);
}
if (!empty($this->getOnlyRecordByIndex) && isset($this->getOnlyRecordByIndex[$indexed]) && is_array($this->getOnlyRecordByIndex[$indexed])) {
$sheetDatas = $this->executeGetOnlyRecords($sheetDatas, $this->getOnlyRecordByIndex[$indexed]);
}
if (!empty($this->leaveRecordByIndex) && isset($this->leaveRecordByIndex[$indexed]) && is_array($this->leaveRecordByIndex[$indexed])) {
$sheetDatas[$indexed] = $this->executeLeaveRecords($sheetDatas[$indexed], $this->leaveRecordByIndex[$indexed]);
}
}
}
} else {
$sheetDatas = $objectPhpExcel->getActiveSheet()->toArray(null, true, true, true);
if ($this->setFirstRecordAsKeys) {
$sheetDatas = $this->executeArrayLabel($sheetDatas);
}
if (!empty($this->getOnlyRecordByIndex)) {
$sheetDatas = $this->executeGetOnlyRecords($sheetDatas, $this->getOnlyRecordByIndex);
}
if (!empty($this->leaveRecordByIndex)) {
$sheetDatas = $this->executeLeaveRecords($sheetDatas, $this->leaveRecordByIndex);
}
}
return $sheetDatas;
} | php | public function readFile($fileName)
{
if (!isset($this->format))
$this->format = \PhpOffice\PhpSpreadsheet\IOFactory::identify($fileName);
$objectreader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($this->format);
if ($this->format == "Csv") {
$objectreader->setDelimiter($this->CSVDelimiter);
$objectreader->setInputEncoding($this->CSVEncoding);
}
$objectPhpExcel = $objectreader->load($fileName);
$sheetCount = $objectPhpExcel->getSheetCount();
$sheetDatas = [];
if ($sheetCount > 1) {
foreach ($objectPhpExcel->getSheetNames() as $sheetIndex => $sheetName) {
if (isset($this->getOnlySheet) && $this->getOnlySheet != null) {
if(!$objectPhpExcel->getSheetByName($this->getOnlySheet)) {
return $sheetDatas;
}
$objectPhpExcel->setActiveSheetIndexByName($this->getOnlySheet);
$indexed = $this->getOnlySheet;
$sheetDatas[$indexed] = $objectPhpExcel->getActiveSheet()->toArray(null, true, true, true);
if ($this->setFirstRecordAsKeys) {
$sheetDatas[$indexed] = $this->executeArrayLabel($sheetDatas[$indexed]);
}
if (!empty($this->getOnlyRecordByIndex)) {
$sheetDatas[$indexed] = $this->executeGetOnlyRecords($sheetDatas[$indexed], $this->getOnlyRecordByIndex);
}
if (!empty($this->leaveRecordByIndex)) {
$sheetDatas[$indexed] = $this->executeLeaveRecords($sheetDatas[$indexed], $this->leaveRecordByIndex);
}
return $sheetDatas[$indexed];
} else {
$objectPhpExcel->setActiveSheetIndexByName($sheetName);
$indexed = $this->setIndexSheetByName==true ? $sheetName : $sheetIndex;
$sheetDatas[$indexed] = $objectPhpExcel->getActiveSheet()->toArray(null, true, true, true);
if ($this->setFirstRecordAsKeys) {
$sheetDatas[$indexed] = $this->executeArrayLabel($sheetDatas[$indexed]);
}
if (!empty($this->getOnlyRecordByIndex) && isset($this->getOnlyRecordByIndex[$indexed]) && is_array($this->getOnlyRecordByIndex[$indexed])) {
$sheetDatas = $this->executeGetOnlyRecords($sheetDatas, $this->getOnlyRecordByIndex[$indexed]);
}
if (!empty($this->leaveRecordByIndex) && isset($this->leaveRecordByIndex[$indexed]) && is_array($this->leaveRecordByIndex[$indexed])) {
$sheetDatas[$indexed] = $this->executeLeaveRecords($sheetDatas[$indexed], $this->leaveRecordByIndex[$indexed]);
}
}
}
} else {
$sheetDatas = $objectPhpExcel->getActiveSheet()->toArray(null, true, true, true);
if ($this->setFirstRecordAsKeys) {
$sheetDatas = $this->executeArrayLabel($sheetDatas);
}
if (!empty($this->getOnlyRecordByIndex)) {
$sheetDatas = $this->executeGetOnlyRecords($sheetDatas, $this->getOnlyRecordByIndex);
}
if (!empty($this->leaveRecordByIndex)) {
$sheetDatas = $this->executeLeaveRecords($sheetDatas, $this->leaveRecordByIndex);
}
}
return $sheetDatas;
} | [
"public",
"function",
"readFile",
"(",
"$",
"fileName",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"format",
")",
")",
"$",
"this",
"->",
"format",
"=",
"\\",
"PhpOffice",
"\\",
"PhpSpreadsheet",
"\\",
"IOFactory",
"::",
"identify",
"(",
"$",
"fileName",
")",
";",
"$",
"objectreader",
"=",
"\\",
"PhpOffice",
"\\",
"PhpSpreadsheet",
"\\",
"IOFactory",
"::",
"createReader",
"(",
"$",
"this",
"->",
"format",
")",
";",
"if",
"(",
"$",
"this",
"->",
"format",
"==",
"\"Csv\"",
")",
"{",
"$",
"objectreader",
"->",
"setDelimiter",
"(",
"$",
"this",
"->",
"CSVDelimiter",
")",
";",
"$",
"objectreader",
"->",
"setInputEncoding",
"(",
"$",
"this",
"->",
"CSVEncoding",
")",
";",
"}",
"$",
"objectPhpExcel",
"=",
"$",
"objectreader",
"->",
"load",
"(",
"$",
"fileName",
")",
";",
"$",
"sheetCount",
"=",
"$",
"objectPhpExcel",
"->",
"getSheetCount",
"(",
")",
";",
"$",
"sheetDatas",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"sheetCount",
">",
"1",
")",
"{",
"foreach",
"(",
"$",
"objectPhpExcel",
"->",
"getSheetNames",
"(",
")",
"as",
"$",
"sheetIndex",
"=>",
"$",
"sheetName",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"getOnlySheet",
")",
"&&",
"$",
"this",
"->",
"getOnlySheet",
"!=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"objectPhpExcel",
"->",
"getSheetByName",
"(",
"$",
"this",
"->",
"getOnlySheet",
")",
")",
"{",
"return",
"$",
"sheetDatas",
";",
"}",
"$",
"objectPhpExcel",
"->",
"setActiveSheetIndexByName",
"(",
"$",
"this",
"->",
"getOnlySheet",
")",
";",
"$",
"indexed",
"=",
"$",
"this",
"->",
"getOnlySheet",
";",
"$",
"sheetDatas",
"[",
"$",
"indexed",
"]",
"=",
"$",
"objectPhpExcel",
"->",
"getActiveSheet",
"(",
")",
"->",
"toArray",
"(",
"null",
",",
"true",
",",
"true",
",",
"true",
")",
";",
"if",
"(",
"$",
"this",
"->",
"setFirstRecordAsKeys",
")",
"{",
"$",
"sheetDatas",
"[",
"$",
"indexed",
"]",
"=",
"$",
"this",
"->",
"executeArrayLabel",
"(",
"$",
"sheetDatas",
"[",
"$",
"indexed",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"getOnlyRecordByIndex",
")",
")",
"{",
"$",
"sheetDatas",
"[",
"$",
"indexed",
"]",
"=",
"$",
"this",
"->",
"executeGetOnlyRecords",
"(",
"$",
"sheetDatas",
"[",
"$",
"indexed",
"]",
",",
"$",
"this",
"->",
"getOnlyRecordByIndex",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"leaveRecordByIndex",
")",
")",
"{",
"$",
"sheetDatas",
"[",
"$",
"indexed",
"]",
"=",
"$",
"this",
"->",
"executeLeaveRecords",
"(",
"$",
"sheetDatas",
"[",
"$",
"indexed",
"]",
",",
"$",
"this",
"->",
"leaveRecordByIndex",
")",
";",
"}",
"return",
"$",
"sheetDatas",
"[",
"$",
"indexed",
"]",
";",
"}",
"else",
"{",
"$",
"objectPhpExcel",
"->",
"setActiveSheetIndexByName",
"(",
"$",
"sheetName",
")",
";",
"$",
"indexed",
"=",
"$",
"this",
"->",
"setIndexSheetByName",
"==",
"true",
"?",
"$",
"sheetName",
":",
"$",
"sheetIndex",
";",
"$",
"sheetDatas",
"[",
"$",
"indexed",
"]",
"=",
"$",
"objectPhpExcel",
"->",
"getActiveSheet",
"(",
")",
"->",
"toArray",
"(",
"null",
",",
"true",
",",
"true",
",",
"true",
")",
";",
"if",
"(",
"$",
"this",
"->",
"setFirstRecordAsKeys",
")",
"{",
"$",
"sheetDatas",
"[",
"$",
"indexed",
"]",
"=",
"$",
"this",
"->",
"executeArrayLabel",
"(",
"$",
"sheetDatas",
"[",
"$",
"indexed",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"getOnlyRecordByIndex",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"getOnlyRecordByIndex",
"[",
"$",
"indexed",
"]",
")",
"&&",
"is_array",
"(",
"$",
"this",
"->",
"getOnlyRecordByIndex",
"[",
"$",
"indexed",
"]",
")",
")",
"{",
"$",
"sheetDatas",
"=",
"$",
"this",
"->",
"executeGetOnlyRecords",
"(",
"$",
"sheetDatas",
",",
"$",
"this",
"->",
"getOnlyRecordByIndex",
"[",
"$",
"indexed",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"leaveRecordByIndex",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"leaveRecordByIndex",
"[",
"$",
"indexed",
"]",
")",
"&&",
"is_array",
"(",
"$",
"this",
"->",
"leaveRecordByIndex",
"[",
"$",
"indexed",
"]",
")",
")",
"{",
"$",
"sheetDatas",
"[",
"$",
"indexed",
"]",
"=",
"$",
"this",
"->",
"executeLeaveRecords",
"(",
"$",
"sheetDatas",
"[",
"$",
"indexed",
"]",
",",
"$",
"this",
"->",
"leaveRecordByIndex",
"[",
"$",
"indexed",
"]",
")",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"$",
"sheetDatas",
"=",
"$",
"objectPhpExcel",
"->",
"getActiveSheet",
"(",
")",
"->",
"toArray",
"(",
"null",
",",
"true",
",",
"true",
",",
"true",
")",
";",
"if",
"(",
"$",
"this",
"->",
"setFirstRecordAsKeys",
")",
"{",
"$",
"sheetDatas",
"=",
"$",
"this",
"->",
"executeArrayLabel",
"(",
"$",
"sheetDatas",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"getOnlyRecordByIndex",
")",
")",
"{",
"$",
"sheetDatas",
"=",
"$",
"this",
"->",
"executeGetOnlyRecords",
"(",
"$",
"sheetDatas",
",",
"$",
"this",
"->",
"getOnlyRecordByIndex",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"leaveRecordByIndex",
")",
")",
"{",
"$",
"sheetDatas",
"=",
"$",
"this",
"->",
"executeLeaveRecords",
"(",
"$",
"sheetDatas",
",",
"$",
"this",
"->",
"leaveRecordByIndex",
")",
";",
"}",
"}",
"return",
"$",
"sheetDatas",
";",
"}"
] | reading the xls file | [
"reading",
"the",
"xls",
"file"
] | train | https://github.com/moonlandsoft/yii2-phpexcel/blob/ccf28ff8ce2c665a7769dd6516098b4a35c8c309/Excel.php#L736-L799 |
moonlandsoft/yii2-phpexcel | Excel.php | Excel.run | public function run()
{
if ($this->mode == 'export')
{
$sheet = new Spreadsheet();
if (!isset($this->models))
throw new InvalidConfigException('Config models must be set');
if (isset($this->properties))
{
$this->properties($sheet, $this->properties);
}
if ($this->isMultipleSheet) {
$index = 0;
$worksheet = [];
foreach ($this->models as $title => $models) {
$sheet->createSheet($index);
$sheet->getSheet($index)->setTitle($title);
$worksheet[$index] = $sheet->getSheet($index);
$columns = isset($this->columns[$title]) ? $this->columns[$title] : [];
$headers = isset($this->headers[$title]) ? $this->headers[$title] : [];
$this->executeColumns($worksheet[$index], $models, $this->populateColumns($columns), $headers);
$index++;
}
} else {
$worksheet = $sheet->getActiveSheet();
$this->executeColumns($worksheet, $this->models, isset($this->columns) ? $this->populateColumns($this->columns) : [], isset($this->headers) ? $this->headers : []);
}
if ($this->asAttachment) {
$this->setHeaders();
}
$this->writeFile($sheet);
$sheet->disconnectWorksheets();
unset($sheet);
}
elseif ($this->mode == 'import')
{
if (is_array($this->fileName)) {
$datas = [];
foreach ($this->fileName as $key => $filename) {
$datas[$key] = $this->readFile($filename);
}
return $datas;
} else {
return $this->readFile($this->fileName);
}
}
} | php | public function run()
{
if ($this->mode == 'export')
{
$sheet = new Spreadsheet();
if (!isset($this->models))
throw new InvalidConfigException('Config models must be set');
if (isset($this->properties))
{
$this->properties($sheet, $this->properties);
}
if ($this->isMultipleSheet) {
$index = 0;
$worksheet = [];
foreach ($this->models as $title => $models) {
$sheet->createSheet($index);
$sheet->getSheet($index)->setTitle($title);
$worksheet[$index] = $sheet->getSheet($index);
$columns = isset($this->columns[$title]) ? $this->columns[$title] : [];
$headers = isset($this->headers[$title]) ? $this->headers[$title] : [];
$this->executeColumns($worksheet[$index], $models, $this->populateColumns($columns), $headers);
$index++;
}
} else {
$worksheet = $sheet->getActiveSheet();
$this->executeColumns($worksheet, $this->models, isset($this->columns) ? $this->populateColumns($this->columns) : [], isset($this->headers) ? $this->headers : []);
}
if ($this->asAttachment) {
$this->setHeaders();
}
$this->writeFile($sheet);
$sheet->disconnectWorksheets();
unset($sheet);
}
elseif ($this->mode == 'import')
{
if (is_array($this->fileName)) {
$datas = [];
foreach ($this->fileName as $key => $filename) {
$datas[$key] = $this->readFile($filename);
}
return $datas;
} else {
return $this->readFile($this->fileName);
}
}
} | [
"public",
"function",
"run",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"mode",
"==",
"'export'",
")",
"{",
"$",
"sheet",
"=",
"new",
"Spreadsheet",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"models",
")",
")",
"throw",
"new",
"InvalidConfigException",
"(",
"'Config models must be set'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"properties",
")",
")",
"{",
"$",
"this",
"->",
"properties",
"(",
"$",
"sheet",
",",
"$",
"this",
"->",
"properties",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isMultipleSheet",
")",
"{",
"$",
"index",
"=",
"0",
";",
"$",
"worksheet",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"models",
"as",
"$",
"title",
"=>",
"$",
"models",
")",
"{",
"$",
"sheet",
"->",
"createSheet",
"(",
"$",
"index",
")",
";",
"$",
"sheet",
"->",
"getSheet",
"(",
"$",
"index",
")",
"->",
"setTitle",
"(",
"$",
"title",
")",
";",
"$",
"worksheet",
"[",
"$",
"index",
"]",
"=",
"$",
"sheet",
"->",
"getSheet",
"(",
"$",
"index",
")",
";",
"$",
"columns",
"=",
"isset",
"(",
"$",
"this",
"->",
"columns",
"[",
"$",
"title",
"]",
")",
"?",
"$",
"this",
"->",
"columns",
"[",
"$",
"title",
"]",
":",
"[",
"]",
";",
"$",
"headers",
"=",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"$",
"title",
"]",
")",
"?",
"$",
"this",
"->",
"headers",
"[",
"$",
"title",
"]",
":",
"[",
"]",
";",
"$",
"this",
"->",
"executeColumns",
"(",
"$",
"worksheet",
"[",
"$",
"index",
"]",
",",
"$",
"models",
",",
"$",
"this",
"->",
"populateColumns",
"(",
"$",
"columns",
")",
",",
"$",
"headers",
")",
";",
"$",
"index",
"++",
";",
"}",
"}",
"else",
"{",
"$",
"worksheet",
"=",
"$",
"sheet",
"->",
"getActiveSheet",
"(",
")",
";",
"$",
"this",
"->",
"executeColumns",
"(",
"$",
"worksheet",
",",
"$",
"this",
"->",
"models",
",",
"isset",
"(",
"$",
"this",
"->",
"columns",
")",
"?",
"$",
"this",
"->",
"populateColumns",
"(",
"$",
"this",
"->",
"columns",
")",
":",
"[",
"]",
",",
"isset",
"(",
"$",
"this",
"->",
"headers",
")",
"?",
"$",
"this",
"->",
"headers",
":",
"[",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"asAttachment",
")",
"{",
"$",
"this",
"->",
"setHeaders",
"(",
")",
";",
"}",
"$",
"this",
"->",
"writeFile",
"(",
"$",
"sheet",
")",
";",
"$",
"sheet",
"->",
"disconnectWorksheets",
"(",
")",
";",
"unset",
"(",
"$",
"sheet",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"mode",
"==",
"'import'",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"fileName",
")",
")",
"{",
"$",
"datas",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"fileName",
"as",
"$",
"key",
"=>",
"$",
"filename",
")",
"{",
"$",
"datas",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"readFile",
"(",
"$",
"filename",
")",
";",
"}",
"return",
"$",
"datas",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"readFile",
"(",
"$",
"this",
"->",
"fileName",
")",
";",
"}",
"}",
"}"
] | (non-PHPdoc)
@see \yii\base\Widget::run() | [
"(",
"non",
"-",
"PHPdoc",
")"
] | train | https://github.com/moonlandsoft/yii2-phpexcel/blob/ccf28ff8ce2c665a7769dd6516098b4a35c8c309/Excel.php#L805-L855 |
moonlandsoft/yii2-phpexcel | Excel.php | Excel.import | public static function import($fileName, $config=[])
{
$config = ArrayHelper::merge(['mode' => 'import', 'fileName' => $fileName, 'asArray' => true], $config);
return self::widget($config);
} | php | public static function import($fileName, $config=[])
{
$config = ArrayHelper::merge(['mode' => 'import', 'fileName' => $fileName, 'asArray' => true], $config);
return self::widget($config);
} | [
"public",
"static",
"function",
"import",
"(",
"$",
"fileName",
",",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"config",
"=",
"ArrayHelper",
"::",
"merge",
"(",
"[",
"'mode'",
"=>",
"'import'",
",",
"'fileName'",
"=>",
"$",
"fileName",
",",
"'asArray'",
"=>",
"true",
"]",
",",
"$",
"config",
")",
";",
"return",
"self",
"::",
"widget",
"(",
"$",
"config",
")",
";",
"}"
] | Import file excel and return into an array.
~~~
$data = \moonland\phpexcel\Excel::import($fileName, ['setFirstRecordAsKeys' => true]);
~~~
@param string!array $fileName to load.
@param array $config is a more configuration.
@return string | [
"Import",
"file",
"excel",
"and",
"return",
"into",
"an",
"array",
"."
] | train | https://github.com/moonlandsoft/yii2-phpexcel/blob/ccf28ff8ce2c665a7769dd6516098b4a35c8c309/Excel.php#L926-L930 |
beyondcode/laravel-comments | src/Traits/HasComments.php | HasComments.commentAsUser | public function commentAsUser(?Model $user, string $comment)
{
$commentClass = config('comments.comment_class');
$comment = new $commentClass([
'comment' => $comment,
'is_approved' => ($user instanceof Commentator) ? ! $user->needsCommentApproval($this) : false,
'user_id' => is_null($user) ? null : $user->getKey(),
'commentable_id' => $this->getKey(),
'commentable_type' => get_class(),
]);
return $this->comments()->save($comment);
} | php | public function commentAsUser(?Model $user, string $comment)
{
$commentClass = config('comments.comment_class');
$comment = new $commentClass([
'comment' => $comment,
'is_approved' => ($user instanceof Commentator) ? ! $user->needsCommentApproval($this) : false,
'user_id' => is_null($user) ? null : $user->getKey(),
'commentable_id' => $this->getKey(),
'commentable_type' => get_class(),
]);
return $this->comments()->save($comment);
} | [
"public",
"function",
"commentAsUser",
"(",
"?",
"Model",
"$",
"user",
",",
"string",
"$",
"comment",
")",
"{",
"$",
"commentClass",
"=",
"config",
"(",
"'comments.comment_class'",
")",
";",
"$",
"comment",
"=",
"new",
"$",
"commentClass",
"(",
"[",
"'comment'",
"=>",
"$",
"comment",
",",
"'is_approved'",
"=>",
"(",
"$",
"user",
"instanceof",
"Commentator",
")",
"?",
"!",
"$",
"user",
"->",
"needsCommentApproval",
"(",
"$",
"this",
")",
":",
"false",
",",
"'user_id'",
"=>",
"is_null",
"(",
"$",
"user",
")",
"?",
"null",
":",
"$",
"user",
"->",
"getKey",
"(",
")",
",",
"'commentable_id'",
"=>",
"$",
"this",
"->",
"getKey",
"(",
")",
",",
"'commentable_type'",
"=>",
"get_class",
"(",
")",
",",
"]",
")",
";",
"return",
"$",
"this",
"->",
"comments",
"(",
")",
"->",
"save",
"(",
"$",
"comment",
")",
";",
"}"
] | Attach a comment to this model as a specific user.
@param Model|null $user
@param string $comment
@return \Illuminate\Database\Eloquent\Model | [
"Attach",
"a",
"comment",
"to",
"this",
"model",
"as",
"a",
"specific",
"user",
"."
] | train | https://github.com/beyondcode/laravel-comments/blob/c7d599349d6063860280dafb07e9757106428b76/src/Traits/HasComments.php#L40-L53 |
analogueorm/analogue | src/System/Proxies/ProxyFactory.php | ProxyFactory.makeEntityProxy | protected function makeEntityProxy($entity, $relation, $class)
{
$proxyPath = Manager::getInstance()->getProxyPath();
if ($proxyPath !== null) {
$proxyConfig = new Configuration();
$proxyConfig->setProxiesTargetDir($proxyPath);
$factory = new LazyLoadingValueHolderFactory($proxyConfig);
} else {
$factory = new LazyLoadingValueHolderFactory();
}
$initializer = function (&$wrappedObject, LazyLoadingInterface $proxy, $method, array $parameters, &$initializer) use ($entity, $relation) {
$entityMap = Manager::getMapper($entity)->getEntityMap();
$wrappedObject = $entityMap->$relation($entity)->getResults($relation);
$initializer = null; // disable initialization
return true; // confirm that initialization occurred correctly
};
return $factory->createProxy($class, $initializer);
} | php | protected function makeEntityProxy($entity, $relation, $class)
{
$proxyPath = Manager::getInstance()->getProxyPath();
if ($proxyPath !== null) {
$proxyConfig = new Configuration();
$proxyConfig->setProxiesTargetDir($proxyPath);
$factory = new LazyLoadingValueHolderFactory($proxyConfig);
} else {
$factory = new LazyLoadingValueHolderFactory();
}
$initializer = function (&$wrappedObject, LazyLoadingInterface $proxy, $method, array $parameters, &$initializer) use ($entity, $relation) {
$entityMap = Manager::getMapper($entity)->getEntityMap();
$wrappedObject = $entityMap->$relation($entity)->getResults($relation);
$initializer = null; // disable initialization
return true; // confirm that initialization occurred correctly
};
return $factory->createProxy($class, $initializer);
} | [
"protected",
"function",
"makeEntityProxy",
"(",
"$",
"entity",
",",
"$",
"relation",
",",
"$",
"class",
")",
"{",
"$",
"proxyPath",
"=",
"Manager",
"::",
"getInstance",
"(",
")",
"->",
"getProxyPath",
"(",
")",
";",
"if",
"(",
"$",
"proxyPath",
"!==",
"null",
")",
"{",
"$",
"proxyConfig",
"=",
"new",
"Configuration",
"(",
")",
";",
"$",
"proxyConfig",
"->",
"setProxiesTargetDir",
"(",
"$",
"proxyPath",
")",
";",
"$",
"factory",
"=",
"new",
"LazyLoadingValueHolderFactory",
"(",
"$",
"proxyConfig",
")",
";",
"}",
"else",
"{",
"$",
"factory",
"=",
"new",
"LazyLoadingValueHolderFactory",
"(",
")",
";",
"}",
"$",
"initializer",
"=",
"function",
"(",
"&",
"$",
"wrappedObject",
",",
"LazyLoadingInterface",
"$",
"proxy",
",",
"$",
"method",
",",
"array",
"$",
"parameters",
",",
"&",
"$",
"initializer",
")",
"use",
"(",
"$",
"entity",
",",
"$",
"relation",
")",
"{",
"$",
"entityMap",
"=",
"Manager",
"::",
"getMapper",
"(",
"$",
"entity",
")",
"->",
"getEntityMap",
"(",
")",
";",
"$",
"wrappedObject",
"=",
"$",
"entityMap",
"->",
"$",
"relation",
"(",
"$",
"entity",
")",
"->",
"getResults",
"(",
"$",
"relation",
")",
";",
"$",
"initializer",
"=",
"null",
";",
"// disable initialization",
"return",
"true",
";",
"// confirm that initialization occurred correctly",
"}",
";",
"return",
"$",
"factory",
"->",
"createProxy",
"(",
"$",
"class",
",",
"$",
"initializer",
")",
";",
"}"
] | Create an instance of a proxy object, extending the actual
related class.
@param mixed $entity parent object
@param string $relation the name of the relationship method
@param string $class the class name of the related object
@return mixed | [
"Create",
"an",
"instance",
"of",
"a",
"proxy",
"object",
"extending",
"the",
"actual",
"related",
"class",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Proxies/ProxyFactory.php#L46-L69 |
analogueorm/analogue | src/Plugins/SoftDeletes/SoftDeletingScope.php | SoftDeletingScope.apply | public function apply(Query $query)
{
$entityMap = $query->getMapper()->getEntityMap();
$query->whereNull($entityMap->getQualifiedDeletedAtColumn());
$this->extend($query);
} | php | public function apply(Query $query)
{
$entityMap = $query->getMapper()->getEntityMap();
$query->whereNull($entityMap->getQualifiedDeletedAtColumn());
$this->extend($query);
} | [
"public",
"function",
"apply",
"(",
"Query",
"$",
"query",
")",
"{",
"$",
"entityMap",
"=",
"$",
"query",
"->",
"getMapper",
"(",
")",
"->",
"getEntityMap",
"(",
")",
";",
"$",
"query",
"->",
"whereNull",
"(",
"$",
"entityMap",
"->",
"getQualifiedDeletedAtColumn",
"(",
")",
")",
";",
"$",
"this",
"->",
"extend",
"(",
"$",
"query",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Plugins/SoftDeletes/SoftDeletingScope.php#L23-L30 |
analogueorm/analogue | src/Plugins/SoftDeletes/SoftDeletingScope.php | SoftDeletingScope.remove | public function remove(Query $query)
{
$column = $query->getMapper()->getEntityMap()->getQualifiedDeletedAtColumn();
$query = $query->getQuery();
foreach ((array) $query->wheres as $key => $where) {
// If the where clause is a soft delete date constraint, we will remove it from
// the query and reset the keys on the wheres. This allows this developer to
// include deleted model in a relationship result set that is lazy loaded.
if ($this->isSoftDeleteConstraint($where, $column)) {
unset($query->wheres[$key]);
$query->wheres = array_values($query->wheres);
}
}
} | php | public function remove(Query $query)
{
$column = $query->getMapper()->getEntityMap()->getQualifiedDeletedAtColumn();
$query = $query->getQuery();
foreach ((array) $query->wheres as $key => $where) {
// If the where clause is a soft delete date constraint, we will remove it from
// the query and reset the keys on the wheres. This allows this developer to
// include deleted model in a relationship result set that is lazy loaded.
if ($this->isSoftDeleteConstraint($where, $column)) {
unset($query->wheres[$key]);
$query->wheres = array_values($query->wheres);
}
}
} | [
"public",
"function",
"remove",
"(",
"Query",
"$",
"query",
")",
"{",
"$",
"column",
"=",
"$",
"query",
"->",
"getMapper",
"(",
")",
"->",
"getEntityMap",
"(",
")",
"->",
"getQualifiedDeletedAtColumn",
"(",
")",
";",
"$",
"query",
"=",
"$",
"query",
"->",
"getQuery",
"(",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"query",
"->",
"wheres",
"as",
"$",
"key",
"=>",
"$",
"where",
")",
"{",
"// If the where clause is a soft delete date constraint, we will remove it from",
"// the query and reset the keys on the wheres. This allows this developer to",
"// include deleted model in a relationship result set that is lazy loaded.",
"if",
"(",
"$",
"this",
"->",
"isSoftDeleteConstraint",
"(",
"$",
"where",
",",
"$",
"column",
")",
")",
"{",
"unset",
"(",
"$",
"query",
"->",
"wheres",
"[",
"$",
"key",
"]",
")",
";",
"$",
"query",
"->",
"wheres",
"=",
"array_values",
"(",
"$",
"query",
"->",
"wheres",
")",
";",
"}",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Plugins/SoftDeletes/SoftDeletingScope.php#L35-L51 |
analogueorm/analogue | src/Plugins/SoftDeletes/SoftDeletingScope.php | SoftDeletingScope.addWithTrashed | protected function addWithTrashed(Query $query)
{
$query->macro('withTrashed', function (Query $query) {
$this->remove($query);
return $query;
});
} | php | protected function addWithTrashed(Query $query)
{
$query->macro('withTrashed', function (Query $query) {
$this->remove($query);
return $query;
});
} | [
"protected",
"function",
"addWithTrashed",
"(",
"Query",
"$",
"query",
")",
"{",
"$",
"query",
"->",
"macro",
"(",
"'withTrashed'",
",",
"function",
"(",
"Query",
"$",
"query",
")",
"{",
"$",
"this",
"->",
"remove",
"(",
"$",
"query",
")",
";",
"return",
"$",
"query",
";",
"}",
")",
";",
"}"
] | Add the with-trashed extension to the builder.
@param \Analogue\ORM\System\Query $query
@return void | [
"Add",
"the",
"with",
"-",
"trashed",
"extension",
"to",
"the",
"builder",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Plugins/SoftDeletes/SoftDeletingScope.php#L74-L81 |
analogueorm/analogue | src/Plugins/SoftDeletes/SoftDeletingScope.php | SoftDeletingScope.addOnlyTrashed | protected function addOnlyTrashed(Query $query)
{
$query->macro('onlyTrashed', function (Query $query) {
$this->remove($query);
$query->getQuery()->whereNotNull($query->getMapper()->getEntityMap()->getQualifiedDeletedAtColumn());
return $query;
});
} | php | protected function addOnlyTrashed(Query $query)
{
$query->macro('onlyTrashed', function (Query $query) {
$this->remove($query);
$query->getQuery()->whereNotNull($query->getMapper()->getEntityMap()->getQualifiedDeletedAtColumn());
return $query;
});
} | [
"protected",
"function",
"addOnlyTrashed",
"(",
"Query",
"$",
"query",
")",
"{",
"$",
"query",
"->",
"macro",
"(",
"'onlyTrashed'",
",",
"function",
"(",
"Query",
"$",
"query",
")",
"{",
"$",
"this",
"->",
"remove",
"(",
"$",
"query",
")",
";",
"$",
"query",
"->",
"getQuery",
"(",
")",
"->",
"whereNotNull",
"(",
"$",
"query",
"->",
"getMapper",
"(",
")",
"->",
"getEntityMap",
"(",
")",
"->",
"getQualifiedDeletedAtColumn",
"(",
")",
")",
";",
"return",
"$",
"query",
";",
"}",
")",
";",
"}"
] | Add the only-trashed extension to the builder.
@param \Analogue\ORM\System\Query $query
@return void | [
"Add",
"the",
"only",
"-",
"trashed",
"extension",
"to",
"the",
"builder",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Plugins/SoftDeletes/SoftDeletingScope.php#L90-L99 |
analogueorm/analogue | src/System/Wrappers/ObjectWrapper.php | ObjectWrapper.dehydrate | protected function dehydrate($entity): array
{
$properties = $this->hydrator->extract($entity);
$attributesName = $this->entityMap->getAttributesArrayName();
if (isset($properties[$attributesName])) {
$properties[$attributesName] = $this->entityMap->getColumnNamesFromAttributes($properties[$attributesName]);
} else {
$properties[$attributesName] = $this->entityMap->getColumnNamesFromAttributes($properties);
}
$this->properties = $properties;
$this->unmanagedProperties = array_except($properties, $this->getManagedProperties());
return $this->attributesFromProperties($properties);
} | php | protected function dehydrate($entity): array
{
$properties = $this->hydrator->extract($entity);
$attributesName = $this->entityMap->getAttributesArrayName();
if (isset($properties[$attributesName])) {
$properties[$attributesName] = $this->entityMap->getColumnNamesFromAttributes($properties[$attributesName]);
} else {
$properties[$attributesName] = $this->entityMap->getColumnNamesFromAttributes($properties);
}
$this->properties = $properties;
$this->unmanagedProperties = array_except($properties, $this->getManagedProperties());
return $this->attributesFromProperties($properties);
} | [
"protected",
"function",
"dehydrate",
"(",
"$",
"entity",
")",
":",
"array",
"{",
"$",
"properties",
"=",
"$",
"this",
"->",
"hydrator",
"->",
"extract",
"(",
"$",
"entity",
")",
";",
"$",
"attributesName",
"=",
"$",
"this",
"->",
"entityMap",
"->",
"getAttributesArrayName",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"properties",
"[",
"$",
"attributesName",
"]",
")",
")",
"{",
"$",
"properties",
"[",
"$",
"attributesName",
"]",
"=",
"$",
"this",
"->",
"entityMap",
"->",
"getColumnNamesFromAttributes",
"(",
"$",
"properties",
"[",
"$",
"attributesName",
"]",
")",
";",
"}",
"else",
"{",
"$",
"properties",
"[",
"$",
"attributesName",
"]",
"=",
"$",
"this",
"->",
"entityMap",
"->",
"getColumnNamesFromAttributes",
"(",
"$",
"properties",
")",
";",
"}",
"$",
"this",
"->",
"properties",
"=",
"$",
"properties",
";",
"$",
"this",
"->",
"unmanagedProperties",
"=",
"array_except",
"(",
"$",
"properties",
",",
"$",
"this",
"->",
"getManagedProperties",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"attributesFromProperties",
"(",
"$",
"properties",
")",
";",
"}"
] | Extract entity attributes / properties to an array of attributes.
@param mixed $entity
@throws MappingException
@return array | [
"Extract",
"entity",
"attributes",
"/",
"properties",
"to",
"an",
"array",
"of",
"attributes",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Wrappers/ObjectWrapper.php#L165-L182 |
analogueorm/analogue | src/System/Wrappers/ObjectWrapper.php | ObjectWrapper.hydrate | protected function hydrate()
{
$properties = $this->propertiesFromAttributes() + $this->unmanagedProperties;
$attributesName = $this->entityMap->getAttributesArrayName();
if (isset($properties[$attributesName])) {
$properties[$attributesName] = $this->entityMap->getAttributeNamesFromColumns($properties[$attributesName]);
} else {
$properties[$attributesName] = $this->entityMap->getAttributeNamesFromColumns($properties);
}
// In some case, attributes will miss some properties, so we'll just complete the hydration
// set with the original object properties
$missingProperties = array_diff_key($this->properties, $properties);
foreach (array_keys($missingProperties) as $missingKey) {
$properties[$missingKey] = $this->properties[$missingKey];
}
$this->hydrator->hydrate($properties, $this->entity);
$this->touched = false;
} | php | protected function hydrate()
{
$properties = $this->propertiesFromAttributes() + $this->unmanagedProperties;
$attributesName = $this->entityMap->getAttributesArrayName();
if (isset($properties[$attributesName])) {
$properties[$attributesName] = $this->entityMap->getAttributeNamesFromColumns($properties[$attributesName]);
} else {
$properties[$attributesName] = $this->entityMap->getAttributeNamesFromColumns($properties);
}
// In some case, attributes will miss some properties, so we'll just complete the hydration
// set with the original object properties
$missingProperties = array_diff_key($this->properties, $properties);
foreach (array_keys($missingProperties) as $missingKey) {
$properties[$missingKey] = $this->properties[$missingKey];
}
$this->hydrator->hydrate($properties, $this->entity);
$this->touched = false;
} | [
"protected",
"function",
"hydrate",
"(",
")",
"{",
"$",
"properties",
"=",
"$",
"this",
"->",
"propertiesFromAttributes",
"(",
")",
"+",
"$",
"this",
"->",
"unmanagedProperties",
";",
"$",
"attributesName",
"=",
"$",
"this",
"->",
"entityMap",
"->",
"getAttributesArrayName",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"properties",
"[",
"$",
"attributesName",
"]",
")",
")",
"{",
"$",
"properties",
"[",
"$",
"attributesName",
"]",
"=",
"$",
"this",
"->",
"entityMap",
"->",
"getAttributeNamesFromColumns",
"(",
"$",
"properties",
"[",
"$",
"attributesName",
"]",
")",
";",
"}",
"else",
"{",
"$",
"properties",
"[",
"$",
"attributesName",
"]",
"=",
"$",
"this",
"->",
"entityMap",
"->",
"getAttributeNamesFromColumns",
"(",
"$",
"properties",
")",
";",
"}",
"// In some case, attributes will miss some properties, so we'll just complete the hydration",
"// set with the original object properties",
"$",
"missingProperties",
"=",
"array_diff_key",
"(",
"$",
"this",
"->",
"properties",
",",
"$",
"properties",
")",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"missingProperties",
")",
"as",
"$",
"missingKey",
")",
"{",
"$",
"properties",
"[",
"$",
"missingKey",
"]",
"=",
"$",
"this",
"->",
"properties",
"[",
"$",
"missingKey",
"]",
";",
"}",
"$",
"this",
"->",
"hydrator",
"->",
"hydrate",
"(",
"$",
"properties",
",",
"$",
"this",
"->",
"entity",
")",
";",
"$",
"this",
"->",
"touched",
"=",
"false",
";",
"}"
] | Hydrate object's properties/attribute from the internal array representation.
@return void | [
"Hydrate",
"object",
"s",
"properties",
"/",
"attribute",
"from",
"the",
"internal",
"array",
"representation",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Wrappers/ObjectWrapper.php#L189-L212 |
analogueorm/analogue | src/System/Wrappers/ObjectWrapper.php | ObjectWrapper.getManagedProperties | protected function getManagedProperties(): array
{
$properties = $this->entityMap->getProperties();
$attributesName = $this->entityMap->getAttributesArrayName();
return $attributesName == null ? $properties : array_merge($properties, [$attributesName]);
} | php | protected function getManagedProperties(): array
{
$properties = $this->entityMap->getProperties();
$attributesName = $this->entityMap->getAttributesArrayName();
return $attributesName == null ? $properties : array_merge($properties, [$attributesName]);
} | [
"protected",
"function",
"getManagedProperties",
"(",
")",
":",
"array",
"{",
"$",
"properties",
"=",
"$",
"this",
"->",
"entityMap",
"->",
"getProperties",
"(",
")",
";",
"$",
"attributesName",
"=",
"$",
"this",
"->",
"entityMap",
"->",
"getAttributesArrayName",
"(",
")",
";",
"return",
"$",
"attributesName",
"==",
"null",
"?",
"$",
"properties",
":",
"array_merge",
"(",
"$",
"properties",
",",
"[",
"$",
"attributesName",
"]",
")",
";",
"}"
] | Return properties that will be extracted from the entity.
@return array | [
"Return",
"properties",
"that",
"will",
"be",
"extracted",
"from",
"the",
"entity",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Wrappers/ObjectWrapper.php#L219-L226 |
analogueorm/analogue | src/System/Wrappers/ObjectWrapper.php | ObjectWrapper.attributesFromProperties | protected function attributesFromProperties(array $properties): array
{
// First, we'll only keep the entities that are part of the Entity's
// attributes
$managedProperties = $this->getManagedProperties();
$properties = array_only($properties, $managedProperties);
// If the entity does not uses the attributes array to store
// part of its attributes, we'll directly return the properties
if (!$this->entityMap->usesAttributesArray()) {
return $properties;
}
$arrayName = $this->entityMap->getAttributesArrayName();
if (!array_key_exists($arrayName, $properties)) {
throw new MappingException("Property $arrayName not set on object of type ".$this->getEntityClass());
}
if (!is_array($properties[$arrayName])) {
throw new MappingException("Property $arrayName should be an array.");
}
$attributes = $properties[$arrayName];
unset($properties[$arrayName]);
return $properties + $attributes;
} | php | protected function attributesFromProperties(array $properties): array
{
// First, we'll only keep the entities that are part of the Entity's
// attributes
$managedProperties = $this->getManagedProperties();
$properties = array_only($properties, $managedProperties);
// If the entity does not uses the attributes array to store
// part of its attributes, we'll directly return the properties
if (!$this->entityMap->usesAttributesArray()) {
return $properties;
}
$arrayName = $this->entityMap->getAttributesArrayName();
if (!array_key_exists($arrayName, $properties)) {
throw new MappingException("Property $arrayName not set on object of type ".$this->getEntityClass());
}
if (!is_array($properties[$arrayName])) {
throw new MappingException("Property $arrayName should be an array.");
}
$attributes = $properties[$arrayName];
unset($properties[$arrayName]);
return $properties + $attributes;
} | [
"protected",
"function",
"attributesFromProperties",
"(",
"array",
"$",
"properties",
")",
":",
"array",
"{",
"// First, we'll only keep the entities that are part of the Entity's",
"// attributes",
"$",
"managedProperties",
"=",
"$",
"this",
"->",
"getManagedProperties",
"(",
")",
";",
"$",
"properties",
"=",
"array_only",
"(",
"$",
"properties",
",",
"$",
"managedProperties",
")",
";",
"// If the entity does not uses the attributes array to store",
"// part of its attributes, we'll directly return the properties",
"if",
"(",
"!",
"$",
"this",
"->",
"entityMap",
"->",
"usesAttributesArray",
"(",
")",
")",
"{",
"return",
"$",
"properties",
";",
"}",
"$",
"arrayName",
"=",
"$",
"this",
"->",
"entityMap",
"->",
"getAttributesArrayName",
"(",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"arrayName",
",",
"$",
"properties",
")",
")",
"{",
"throw",
"new",
"MappingException",
"(",
"\"Property $arrayName not set on object of type \"",
".",
"$",
"this",
"->",
"getEntityClass",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"properties",
"[",
"$",
"arrayName",
"]",
")",
")",
"{",
"throw",
"new",
"MappingException",
"(",
"\"Property $arrayName should be an array.\"",
")",
";",
"}",
"$",
"attributes",
"=",
"$",
"properties",
"[",
"$",
"arrayName",
"]",
";",
"unset",
"(",
"$",
"properties",
"[",
"$",
"arrayName",
"]",
")",
";",
"return",
"$",
"properties",
"+",
"$",
"attributes",
";",
"}"
] | Convert object's properties to analogue's internal attributes representation.
@param array $properties
@throws MappingException
@return array | [
"Convert",
"object",
"s",
"properties",
"to",
"analogue",
"s",
"internal",
"attributes",
"representation",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Wrappers/ObjectWrapper.php#L237-L266 |
analogueorm/analogue | src/System/Wrappers/ObjectWrapper.php | ObjectWrapper.propertiesFromAttributes | protected function propertiesFromAttributes(): array
{
// Get all managed properties
$propertyNames = $this->entityMap->getProperties();
$propertyAttributes = array_only($this->attributes, $propertyNames);
$attributesArray = array_except($this->attributes, $propertyNames);
$attributesArrayName = $this->entityMap->getAttributesArrayName();
if ($attributesArrayName) {
$propertyAttributes[$attributesArrayName] = $attributesArray;
}
return $propertyAttributes;
} | php | protected function propertiesFromAttributes(): array
{
// Get all managed properties
$propertyNames = $this->entityMap->getProperties();
$propertyAttributes = array_only($this->attributes, $propertyNames);
$attributesArray = array_except($this->attributes, $propertyNames);
$attributesArrayName = $this->entityMap->getAttributesArrayName();
if ($attributesArrayName) {
$propertyAttributes[$attributesArrayName] = $attributesArray;
}
return $propertyAttributes;
} | [
"protected",
"function",
"propertiesFromAttributes",
"(",
")",
":",
"array",
"{",
"// Get all managed properties",
"$",
"propertyNames",
"=",
"$",
"this",
"->",
"entityMap",
"->",
"getProperties",
"(",
")",
";",
"$",
"propertyAttributes",
"=",
"array_only",
"(",
"$",
"this",
"->",
"attributes",
",",
"$",
"propertyNames",
")",
";",
"$",
"attributesArray",
"=",
"array_except",
"(",
"$",
"this",
"->",
"attributes",
",",
"$",
"propertyNames",
")",
";",
"$",
"attributesArrayName",
"=",
"$",
"this",
"->",
"entityMap",
"->",
"getAttributesArrayName",
"(",
")",
";",
"if",
"(",
"$",
"attributesArrayName",
")",
"{",
"$",
"propertyAttributes",
"[",
"$",
"attributesArrayName",
"]",
"=",
"$",
"attributesArray",
";",
"}",
"return",
"$",
"propertyAttributes",
";",
"}"
] | Convert internal representation of attributes to an array of properties
that can hydrate the actual object.
@return array | [
"Convert",
"internal",
"representation",
"of",
"attributes",
"to",
"an",
"array",
"of",
"properties",
"that",
"can",
"hydrate",
"the",
"actual",
"object",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Wrappers/ObjectWrapper.php#L274-L289 |
analogueorm/analogue | src/System/Wrappers/ObjectWrapper.php | ObjectWrapper.setEntityAttribute | public function setEntityAttribute(string $key, $value)
{
$this->attributes[$key] = $value;
$this->touched = true;
$this->hydrate();
} | php | public function setEntityAttribute(string $key, $value)
{
$this->attributes[$key] = $value;
$this->touched = true;
$this->hydrate();
} | [
"public",
"function",
"setEntityAttribute",
"(",
"string",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"attributes",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"touched",
"=",
"true",
";",
"$",
"this",
"->",
"hydrate",
"(",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Wrappers/ObjectWrapper.php#L311-L318 |
analogueorm/analogue | src/System/Wrappers/ObjectWrapper.php | ObjectWrapper.setProxies | public function setProxies(array $relations = null)
{
$attributes = $this->getEntityAttributes();
$proxies = [];
$relations = $this->getRelationsToProxy();
// Before calling the relationship methods, we'll set the relationship
// method to null, to avoid hydration error on class properties
foreach ($relations as $relation) {
$this->setEntityAttribute($relation, null);
}
foreach ($relations as $relation) {
// First, we check that the relation has not been already
// set, in which case, we'll just pass.
if (array_key_exists($relation, $attributes) && !is_null($attributes[$relation])) {
continue;
}
// If the key is handled locally and we know it not to be set,
// we'll set the relationship to null value
if (!$this->relationNeedsProxy($relation, $attributes)) {
$proxies[$relation] = $this->entityMap->getEmptyValueForRelationship($relation);
} else {
$targetClass = $this->getClassToProxy($relation, $attributes);
$proxies[$relation] = $this->proxyFactory->make($this->getObject(), $relation, $targetClass);
}
}
foreach ($proxies as $key => $value) {
$this->setEntityAttribute($key, $value);
}
} | php | public function setProxies(array $relations = null)
{
$attributes = $this->getEntityAttributes();
$proxies = [];
$relations = $this->getRelationsToProxy();
// Before calling the relationship methods, we'll set the relationship
// method to null, to avoid hydration error on class properties
foreach ($relations as $relation) {
$this->setEntityAttribute($relation, null);
}
foreach ($relations as $relation) {
// First, we check that the relation has not been already
// set, in which case, we'll just pass.
if (array_key_exists($relation, $attributes) && !is_null($attributes[$relation])) {
continue;
}
// If the key is handled locally and we know it not to be set,
// we'll set the relationship to null value
if (!$this->relationNeedsProxy($relation, $attributes)) {
$proxies[$relation] = $this->entityMap->getEmptyValueForRelationship($relation);
} else {
$targetClass = $this->getClassToProxy($relation, $attributes);
$proxies[$relation] = $this->proxyFactory->make($this->getObject(), $relation, $targetClass);
}
}
foreach ($proxies as $key => $value) {
$this->setEntityAttribute($key, $value);
}
} | [
"public",
"function",
"setProxies",
"(",
"array",
"$",
"relations",
"=",
"null",
")",
"{",
"$",
"attributes",
"=",
"$",
"this",
"->",
"getEntityAttributes",
"(",
")",
";",
"$",
"proxies",
"=",
"[",
"]",
";",
"$",
"relations",
"=",
"$",
"this",
"->",
"getRelationsToProxy",
"(",
")",
";",
"// Before calling the relationship methods, we'll set the relationship",
"// method to null, to avoid hydration error on class properties",
"foreach",
"(",
"$",
"relations",
"as",
"$",
"relation",
")",
"{",
"$",
"this",
"->",
"setEntityAttribute",
"(",
"$",
"relation",
",",
"null",
")",
";",
"}",
"foreach",
"(",
"$",
"relations",
"as",
"$",
"relation",
")",
"{",
"// First, we check that the relation has not been already",
"// set, in which case, we'll just pass.",
"if",
"(",
"array_key_exists",
"(",
"$",
"relation",
",",
"$",
"attributes",
")",
"&&",
"!",
"is_null",
"(",
"$",
"attributes",
"[",
"$",
"relation",
"]",
")",
")",
"{",
"continue",
";",
"}",
"// If the key is handled locally and we know it not to be set,",
"// we'll set the relationship to null value",
"if",
"(",
"!",
"$",
"this",
"->",
"relationNeedsProxy",
"(",
"$",
"relation",
",",
"$",
"attributes",
")",
")",
"{",
"$",
"proxies",
"[",
"$",
"relation",
"]",
"=",
"$",
"this",
"->",
"entityMap",
"->",
"getEmptyValueForRelationship",
"(",
"$",
"relation",
")",
";",
"}",
"else",
"{",
"$",
"targetClass",
"=",
"$",
"this",
"->",
"getClassToProxy",
"(",
"$",
"relation",
",",
"$",
"attributes",
")",
";",
"$",
"proxies",
"[",
"$",
"relation",
"]",
"=",
"$",
"this",
"->",
"proxyFactory",
"->",
"make",
"(",
"$",
"this",
"->",
"getObject",
"(",
")",
",",
"$",
"relation",
",",
"$",
"targetClass",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"proxies",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setEntityAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}"
] | Set the lazy loading proxies on the wrapped entity objet.
@param array $relations list of relations to be lazy loaded
@return void | [
"Set",
"the",
"lazy",
"loading",
"proxies",
"on",
"the",
"wrapped",
"entity",
"objet",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Wrappers/ObjectWrapper.php#L345-L378 |
analogueorm/analogue | src/System/Wrappers/ObjectWrapper.php | ObjectWrapper.getClassToProxy | protected function getClassToProxy($relation, array $attributes)
{
if ($this->entityMap->isPolymorphic($relation)) {
$localTypeAttribute = $this->entityMap->getLocalKeys($relation)['type'];
return $attributes[$localTypeAttribute];
}
return $this->entityMap->getTargettedClass($relation);
} | php | protected function getClassToProxy($relation, array $attributes)
{
if ($this->entityMap->isPolymorphic($relation)) {
$localTypeAttribute = $this->entityMap->getLocalKeys($relation)['type'];
return $attributes[$localTypeAttribute];
}
return $this->entityMap->getTargettedClass($relation);
} | [
"protected",
"function",
"getClassToProxy",
"(",
"$",
"relation",
",",
"array",
"$",
"attributes",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"entityMap",
"->",
"isPolymorphic",
"(",
"$",
"relation",
")",
")",
"{",
"$",
"localTypeAttribute",
"=",
"$",
"this",
"->",
"entityMap",
"->",
"getLocalKeys",
"(",
"$",
"relation",
")",
"[",
"'type'",
"]",
";",
"return",
"$",
"attributes",
"[",
"$",
"localTypeAttribute",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"entityMap",
"->",
"getTargettedClass",
"(",
"$",
"relation",
")",
";",
"}"
] | Get Target class to proxy for a one to one.
@param string $relation
@param array $attributes
@return string | [
"Get",
"Target",
"class",
"to",
"proxy",
"for",
"a",
"one",
"to",
"one",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Wrappers/ObjectWrapper.php#L388-L397 |
analogueorm/analogue | src/System/Wrappers/ObjectWrapper.php | ObjectWrapper.getRelationsToProxy | protected function getRelationsToProxy()
{
$proxies = [];
$attributes = $this->getEntityAttributes();
foreach ($this->entityMap->getNonEmbeddedRelationships() as $relation) {
//foreach ($this->entityMap->getRelationships() as $relation) {
if (!array_key_exists($relation, $attributes) || is_null($attributes[$relation])) {
$proxies[] = $relation;
}
}
return $proxies;
} | php | protected function getRelationsToProxy()
{
$proxies = [];
$attributes = $this->getEntityAttributes();
foreach ($this->entityMap->getNonEmbeddedRelationships() as $relation) {
//foreach ($this->entityMap->getRelationships() as $relation) {
if (!array_key_exists($relation, $attributes) || is_null($attributes[$relation])) {
$proxies[] = $relation;
}
}
return $proxies;
} | [
"protected",
"function",
"getRelationsToProxy",
"(",
")",
"{",
"$",
"proxies",
"=",
"[",
"]",
";",
"$",
"attributes",
"=",
"$",
"this",
"->",
"getEntityAttributes",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"entityMap",
"->",
"getNonEmbeddedRelationships",
"(",
")",
"as",
"$",
"relation",
")",
"{",
"//foreach ($this->entityMap->getRelationships() as $relation) {",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"relation",
",",
"$",
"attributes",
")",
"||",
"is_null",
"(",
"$",
"attributes",
"[",
"$",
"relation",
"]",
")",
")",
"{",
"$",
"proxies",
"[",
"]",
"=",
"$",
"relation",
";",
"}",
"}",
"return",
"$",
"proxies",
";",
"}"
] | Determine which relations we have to build proxy for, by parsing
attributes and finding methods that aren't set.
@return array | [
"Determine",
"which",
"relations",
"we",
"have",
"to",
"build",
"proxy",
"for",
"by",
"parsing",
"attributes",
"and",
"finding",
"methods",
"that",
"aren",
"t",
"set",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Wrappers/ObjectWrapper.php#L405-L419 |
analogueorm/analogue | src/System/Wrappers/ObjectWrapper.php | ObjectWrapper.relationNeedsProxy | protected function relationNeedsProxy($relation, $attributes)
{
if (in_array($relation, $this->entityMap->getRelationshipsWithoutProxy())) {
return false;
}
$localKey = $this->entityMap->getLocalKeys($relation);
if (is_null($localKey)) {
return true;
}
if (is_array($localKey)) {
$localKey = $localKey['id'];
}
if (!isset($attributes[$localKey]) || is_null($attributes[$localKey])) {
return false;
}
return true;
} | php | protected function relationNeedsProxy($relation, $attributes)
{
if (in_array($relation, $this->entityMap->getRelationshipsWithoutProxy())) {
return false;
}
$localKey = $this->entityMap->getLocalKeys($relation);
if (is_null($localKey)) {
return true;
}
if (is_array($localKey)) {
$localKey = $localKey['id'];
}
if (!isset($attributes[$localKey]) || is_null($attributes[$localKey])) {
return false;
}
return true;
} | [
"protected",
"function",
"relationNeedsProxy",
"(",
"$",
"relation",
",",
"$",
"attributes",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"relation",
",",
"$",
"this",
"->",
"entityMap",
"->",
"getRelationshipsWithoutProxy",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"localKey",
"=",
"$",
"this",
"->",
"entityMap",
"->",
"getLocalKeys",
"(",
"$",
"relation",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"localKey",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"localKey",
")",
")",
"{",
"$",
"localKey",
"=",
"$",
"localKey",
"[",
"'id'",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"attributes",
"[",
"$",
"localKey",
"]",
")",
"||",
"is_null",
"(",
"$",
"attributes",
"[",
"$",
"localKey",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Determine if the relation needs a proxy or not.
@param string $relation
@param array $attributes
@return bool | [
"Determine",
"if",
"the",
"relation",
"needs",
"a",
"proxy",
"or",
"not",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Wrappers/ObjectWrapper.php#L429-L450 |
analogueorm/analogue | src/System/Query.php | Query.findMany | public function findMany($id, $columns = ['*'])
{
if (empty($id)) {
return new EntityCollection();
}
$this->query->whereIn($this->entityMap->getKeyName(), $id);
return $this->get($columns);
} | php | public function findMany($id, $columns = ['*'])
{
if (empty($id)) {
return new EntityCollection();
}
$this->query->whereIn($this->entityMap->getKeyName(), $id);
return $this->get($columns);
} | [
"public",
"function",
"findMany",
"(",
"$",
"id",
",",
"$",
"columns",
"=",
"[",
"'*'",
"]",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"return",
"new",
"EntityCollection",
"(",
")",
";",
"}",
"$",
"this",
"->",
"query",
"->",
"whereIn",
"(",
"$",
"this",
"->",
"entityMap",
"->",
"getKeyName",
"(",
")",
",",
"$",
"id",
")",
";",
"return",
"$",
"this",
"->",
"get",
"(",
"$",
"columns",
")",
";",
"}"
] | Find many entities by their primary keys.
@param array $id
@param array $columns
@return \Illuminate\Support\Collection | [
"Find",
"many",
"entities",
"by",
"their",
"primary",
"keys",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Query.php#L167-L176 |
analogueorm/analogue | src/System/Query.php | Query.findOrFail | public function findOrFail($id, $columns = ['*'])
{
if (!is_null($entity = $this->find($id, $columns))) {
return $entity;
}
throw (new EntityNotFoundException())->setEntity(get_class($this->entityMap));
} | php | public function findOrFail($id, $columns = ['*'])
{
if (!is_null($entity = $this->find($id, $columns))) {
return $entity;
}
throw (new EntityNotFoundException())->setEntity(get_class($this->entityMap));
} | [
"public",
"function",
"findOrFail",
"(",
"$",
"id",
",",
"$",
"columns",
"=",
"[",
"'*'",
"]",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"entity",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"id",
",",
"$",
"columns",
")",
")",
")",
"{",
"return",
"$",
"entity",
";",
"}",
"throw",
"(",
"new",
"EntityNotFoundException",
"(",
")",
")",
"->",
"setEntity",
"(",
"get_class",
"(",
"$",
"this",
"->",
"entityMap",
")",
")",
";",
"}"
] | Find a model by its primary key or throw an exception.
@param mixed $id
@param array $columns
@throws \Analogue\ORM\Exceptions\EntityNotFoundException
@return mixed|self | [
"Find",
"a",
"model",
"by",
"its",
"primary",
"key",
"or",
"throw",
"an",
"exception",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Query.php#L188-L195 |
analogueorm/analogue | src/System/Query.php | Query.firstOrFail | public function firstOrFail($columns = ['*'])
{
if (!is_null($entity = $this->first($columns))) {
return $entity;
}
throw (new EntityNotFoundException())->setEntity(get_class($this->entityMap));
} | php | public function firstOrFail($columns = ['*'])
{
if (!is_null($entity = $this->first($columns))) {
return $entity;
}
throw (new EntityNotFoundException())->setEntity(get_class($this->entityMap));
} | [
"public",
"function",
"firstOrFail",
"(",
"$",
"columns",
"=",
"[",
"'*'",
"]",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"entity",
"=",
"$",
"this",
"->",
"first",
"(",
"$",
"columns",
")",
")",
")",
"{",
"return",
"$",
"entity",
";",
"}",
"throw",
"(",
"new",
"EntityNotFoundException",
"(",
")",
")",
"->",
"setEntity",
"(",
"get_class",
"(",
"$",
"this",
"->",
"entityMap",
")",
")",
";",
"}"
] | Execute the query and get the first result or throw an exception.
@param array $columns
@throws EntityNotFoundException
@return \Analogue\ORM\Entity | [
"Execute",
"the",
"query",
"and",
"get",
"the",
"first",
"result",
"or",
"throw",
"an",
"exception",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Query.php#L218-L225 |
analogueorm/analogue | src/System/Query.php | Query.paginate | public function paginate($perPage = null, $columns = ['*'])
{
$total = $this->query->getCountForPagination();
$this->query->forPage(
$page = Paginator::resolveCurrentPage(),
$perPage = $perPage ?: $this->entityMap->getPerPage()
);
return new LengthAwareEntityPaginator($this->get($columns)->all(), $total, $perPage, $page, [
'path' => Paginator::resolveCurrentPath(),
]);
} | php | public function paginate($perPage = null, $columns = ['*'])
{
$total = $this->query->getCountForPagination();
$this->query->forPage(
$page = Paginator::resolveCurrentPage(),
$perPage = $perPage ?: $this->entityMap->getPerPage()
);
return new LengthAwareEntityPaginator($this->get($columns)->all(), $total, $perPage, $page, [
'path' => Paginator::resolveCurrentPath(),
]);
} | [
"public",
"function",
"paginate",
"(",
"$",
"perPage",
"=",
"null",
",",
"$",
"columns",
"=",
"[",
"'*'",
"]",
")",
"{",
"$",
"total",
"=",
"$",
"this",
"->",
"query",
"->",
"getCountForPagination",
"(",
")",
";",
"$",
"this",
"->",
"query",
"->",
"forPage",
"(",
"$",
"page",
"=",
"Paginator",
"::",
"resolveCurrentPage",
"(",
")",
",",
"$",
"perPage",
"=",
"$",
"perPage",
"?",
":",
"$",
"this",
"->",
"entityMap",
"->",
"getPerPage",
"(",
")",
")",
";",
"return",
"new",
"LengthAwareEntityPaginator",
"(",
"$",
"this",
"->",
"get",
"(",
"$",
"columns",
")",
"->",
"all",
"(",
")",
",",
"$",
"total",
",",
"$",
"perPage",
",",
"$",
"page",
",",
"[",
"'path'",
"=>",
"Paginator",
"::",
"resolveCurrentPath",
"(",
")",
",",
"]",
")",
";",
"}"
] | Get a paginator for the "select" statement.
@param int $perPage
@param array $columns
@return LengthAwareEntityPaginator | [
"Get",
"a",
"paginator",
"for",
"the",
"select",
"statement",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Query.php#L272-L284 |
analogueorm/analogue | src/System/Query.php | Query.ungroupedPaginate | protected function ungroupedPaginate($paginator, $perPage, $columns)
{
$total = $this->query->getPaginationCount();
// Once we have the paginator we need to set the limit and offset values for
// the query so we can get the properly paginated items. Once we have an
// array of items we can create the paginator instances for the items.
$page = $paginator->getCurrentPage($total);
$this->query->forPage($page, $perPage);
return $paginator->make($this->get($columns)->all(), $total, $perPage);
} | php | protected function ungroupedPaginate($paginator, $perPage, $columns)
{
$total = $this->query->getPaginationCount();
// Once we have the paginator we need to set the limit and offset values for
// the query so we can get the properly paginated items. Once we have an
// array of items we can create the paginator instances for the items.
$page = $paginator->getCurrentPage($total);
$this->query->forPage($page, $perPage);
return $paginator->make($this->get($columns)->all(), $total, $perPage);
} | [
"protected",
"function",
"ungroupedPaginate",
"(",
"$",
"paginator",
",",
"$",
"perPage",
",",
"$",
"columns",
")",
"{",
"$",
"total",
"=",
"$",
"this",
"->",
"query",
"->",
"getPaginationCount",
"(",
")",
";",
"// Once we have the paginator we need to set the limit and offset values for",
"// the query so we can get the properly paginated items. Once we have an",
"// array of items we can create the paginator instances for the items.",
"$",
"page",
"=",
"$",
"paginator",
"->",
"getCurrentPage",
"(",
"$",
"total",
")",
";",
"$",
"this",
"->",
"query",
"->",
"forPage",
"(",
"$",
"page",
",",
"$",
"perPage",
")",
";",
"return",
"$",
"paginator",
"->",
"make",
"(",
"$",
"this",
"->",
"get",
"(",
"$",
"columns",
")",
"->",
"all",
"(",
")",
",",
"$",
"total",
",",
"$",
"perPage",
")",
";",
"}"
] | Get a paginator for an ungrouped statement.
@param \Illuminate\Pagination\Factory $paginator
@param int $perPage
@param array $columns
@return \Illuminate\Pagination\Paginator | [
"Get",
"a",
"paginator",
"for",
"an",
"ungrouped",
"statement",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Query.php#L311-L323 |
analogueorm/analogue | src/System/Query.php | Query.simplePaginate | public function simplePaginate($perPage = null, $columns = ['*'])
{
$page = Paginator::resolveCurrentPage();
$perPage = $perPage ?: $this->entityMap->getPerPage();
$this->skip(($page - 1) * $perPage)->take($perPage + 1);
return new Paginator($this->get($columns)->all(), $perPage, $page, ['path' => Paginator::resolveCurrentPath()]);
} | php | public function simplePaginate($perPage = null, $columns = ['*'])
{
$page = Paginator::resolveCurrentPage();
$perPage = $perPage ?: $this->entityMap->getPerPage();
$this->skip(($page - 1) * $perPage)->take($perPage + 1);
return new Paginator($this->get($columns)->all(), $perPage, $page, ['path' => Paginator::resolveCurrentPath()]);
} | [
"public",
"function",
"simplePaginate",
"(",
"$",
"perPage",
"=",
"null",
",",
"$",
"columns",
"=",
"[",
"'*'",
"]",
")",
"{",
"$",
"page",
"=",
"Paginator",
"::",
"resolveCurrentPage",
"(",
")",
";",
"$",
"perPage",
"=",
"$",
"perPage",
"?",
":",
"$",
"this",
"->",
"entityMap",
"->",
"getPerPage",
"(",
")",
";",
"$",
"this",
"->",
"skip",
"(",
"(",
"$",
"page",
"-",
"1",
")",
"*",
"$",
"perPage",
")",
"->",
"take",
"(",
"$",
"perPage",
"+",
"1",
")",
";",
"return",
"new",
"Paginator",
"(",
"$",
"this",
"->",
"get",
"(",
"$",
"columns",
")",
"->",
"all",
"(",
")",
",",
"$",
"perPage",
",",
"$",
"page",
",",
"[",
"'path'",
"=>",
"Paginator",
"::",
"resolveCurrentPath",
"(",
")",
"]",
")",
";",
"}"
] | Paginate the given query into a simple paginator.
@param int $perPage
@param array $columns
@return \Illuminate\Contracts\Pagination\Paginator | [
"Paginate",
"the",
"given",
"query",
"into",
"a",
"simple",
"paginator",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Query.php#L333-L342 |
analogueorm/analogue | src/System/Query.php | Query.has | public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', $callback = null)
{
$entity = $this->mapper->newInstance();
$relation = $this->getHasRelationQuery($relation, $entity);
$query = $relation->getRelationCountQuery($relation->getRelatedMapper()->getQuery(), $this);
if ($callback) {
call_user_func($callback, $query);
}
return $this->addHasWhere($query, $relation, $operator, $count, $boolean);
} | php | public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', $callback = null)
{
$entity = $this->mapper->newInstance();
$relation = $this->getHasRelationQuery($relation, $entity);
$query = $relation->getRelationCountQuery($relation->getRelatedMapper()->getQuery(), $this);
if ($callback) {
call_user_func($callback, $query);
}
return $this->addHasWhere($query, $relation, $operator, $count, $boolean);
} | [
"public",
"function",
"has",
"(",
"$",
"relation",
",",
"$",
"operator",
"=",
"'>='",
",",
"$",
"count",
"=",
"1",
",",
"$",
"boolean",
"=",
"'and'",
",",
"$",
"callback",
"=",
"null",
")",
"{",
"$",
"entity",
"=",
"$",
"this",
"->",
"mapper",
"->",
"newInstance",
"(",
")",
";",
"$",
"relation",
"=",
"$",
"this",
"->",
"getHasRelationQuery",
"(",
"$",
"relation",
",",
"$",
"entity",
")",
";",
"$",
"query",
"=",
"$",
"relation",
"->",
"getRelationCountQuery",
"(",
"$",
"relation",
"->",
"getRelatedMapper",
"(",
")",
"->",
"getQuery",
"(",
")",
",",
"$",
"this",
")",
";",
"if",
"(",
"$",
"callback",
")",
"{",
"call_user_func",
"(",
"$",
"callback",
",",
"$",
"query",
")",
";",
"}",
"return",
"$",
"this",
"->",
"addHasWhere",
"(",
"$",
"query",
",",
"$",
"relation",
",",
"$",
"operator",
",",
"$",
"count",
",",
"$",
"boolean",
")",
";",
"}"
] | Add a relationship count condition to the query.
@param string $relation
@param string $operator
@param int $count
@param string $boolean
@param \Closure $callback
@return \Analogue\ORM\System\Query | [
"Add",
"a",
"relationship",
"count",
"condition",
"to",
"the",
"query",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Query.php#L394-L407 |
analogueorm/analogue | src/System/Query.php | Query.addHasWhere | protected function addHasWhere(self $hasQuery, Relationship $relation, $operator, $count, $boolean)
{
$this->mergeWheresToHas($hasQuery, $relation);
if (is_numeric($count)) {
$count = new Expression($count);
}
return $this->where(new Expression('('.$hasQuery->toSql().')'), $operator, $count, $boolean);
} | php | protected function addHasWhere(self $hasQuery, Relationship $relation, $operator, $count, $boolean)
{
$this->mergeWheresToHas($hasQuery, $relation);
if (is_numeric($count)) {
$count = new Expression($count);
}
return $this->where(new Expression('('.$hasQuery->toSql().')'), $operator, $count, $boolean);
} | [
"protected",
"function",
"addHasWhere",
"(",
"self",
"$",
"hasQuery",
",",
"Relationship",
"$",
"relation",
",",
"$",
"operator",
",",
"$",
"count",
",",
"$",
"boolean",
")",
"{",
"$",
"this",
"->",
"mergeWheresToHas",
"(",
"$",
"hasQuery",
",",
"$",
"relation",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"count",
")",
")",
"{",
"$",
"count",
"=",
"new",
"Expression",
"(",
"$",
"count",
")",
";",
"}",
"return",
"$",
"this",
"->",
"where",
"(",
"new",
"Expression",
"(",
"'('",
".",
"$",
"hasQuery",
"->",
"toSql",
"(",
")",
".",
"')'",
")",
",",
"$",
"operator",
",",
"$",
"count",
",",
"$",
"boolean",
")",
";",
"}"
] | Add the "has" condition where clause to the query.
@param \Analogue\ORM\System\Query $hasQuery
@param \Analogue\ORM\Relationships\Relationship $relation
@param string $operator
@param int $count
@param string $boolean
@return \Analogue\ORM\System\Query | [
"Add",
"the",
"has",
"condition",
"where",
"clause",
"to",
"the",
"query",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Query.php#L464-L473 |
analogueorm/analogue | src/System/Query.php | Query.mergeWheresToHas | protected function mergeWheresToHas(self $hasQuery, Relationship $relation)
{
// Here we have the "has" query and the original relation. We need to copy over any
// where clauses the developer may have put in the relationship function over to
// the has query, and then copy the bindings from the "has" query to the main.
$relationQuery = $relation->getBaseQuery();
$hasQuery->mergeWheres(
$relationQuery->wheres,
$relationQuery->getBindings()
);
$this->query->mergeBindings($hasQuery->getQuery());
} | php | protected function mergeWheresToHas(self $hasQuery, Relationship $relation)
{
// Here we have the "has" query and the original relation. We need to copy over any
// where clauses the developer may have put in the relationship function over to
// the has query, and then copy the bindings from the "has" query to the main.
$relationQuery = $relation->getBaseQuery();
$hasQuery->mergeWheres(
$relationQuery->wheres,
$relationQuery->getBindings()
);
$this->query->mergeBindings($hasQuery->getQuery());
} | [
"protected",
"function",
"mergeWheresToHas",
"(",
"self",
"$",
"hasQuery",
",",
"Relationship",
"$",
"relation",
")",
"{",
"// Here we have the \"has\" query and the original relation. We need to copy over any",
"// where clauses the developer may have put in the relationship function over to",
"// the has query, and then copy the bindings from the \"has\" query to the main.",
"$",
"relationQuery",
"=",
"$",
"relation",
"->",
"getBaseQuery",
"(",
")",
";",
"$",
"hasQuery",
"->",
"mergeWheres",
"(",
"$",
"relationQuery",
"->",
"wheres",
",",
"$",
"relationQuery",
"->",
"getBindings",
"(",
")",
")",
";",
"$",
"this",
"->",
"query",
"->",
"mergeBindings",
"(",
"$",
"hasQuery",
"->",
"getQuery",
"(",
")",
")",
";",
"}"
] | Merge the "wheres" from a relation query to a has query.
@param \Analogue\ORM\System\Query $hasQuery
@param \Analogue\ORM\Relationships\Relationship $relation
@return void | [
"Merge",
"the",
"wheres",
"from",
"a",
"relation",
"query",
"to",
"a",
"has",
"query",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Query.php#L483-L496 |
analogueorm/analogue | src/System/Query.php | Query.getHasRelationQuery | protected function getHasRelationQuery($relation, $entity)
{
return Relationship::noConstraints(function () use ($relation, $entity) {
return $this->entityMap->$relation($entity);
});
} | php | protected function getHasRelationQuery($relation, $entity)
{
return Relationship::noConstraints(function () use ($relation, $entity) {
return $this->entityMap->$relation($entity);
});
} | [
"protected",
"function",
"getHasRelationQuery",
"(",
"$",
"relation",
",",
"$",
"entity",
")",
"{",
"return",
"Relationship",
"::",
"noConstraints",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"relation",
",",
"$",
"entity",
")",
"{",
"return",
"$",
"this",
"->",
"entityMap",
"->",
"$",
"relation",
"(",
"$",
"entity",
")",
";",
"}",
")",
";",
"}"
] | Get the "has relation" base query instance.
@param string $relation
@param $entity
@return \Analogue\ORM\System\Query | [
"Get",
"the",
"has",
"relation",
"base",
"query",
"instance",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Query.php#L506-L511 |
analogueorm/analogue | src/System/Query.php | Query.enforceIdColumn | protected function enforceIdColumn($columns)
{
if (!in_array($this->entityMap->getKeyName(), $columns)) {
$columns[] = $this->entityMap->getKeyName();
}
return $columns;
} | php | protected function enforceIdColumn($columns)
{
if (!in_array($this->entityMap->getKeyName(), $columns)) {
$columns[] = $this->entityMap->getKeyName();
}
return $columns;
} | [
"protected",
"function",
"enforceIdColumn",
"(",
"$",
"columns",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"this",
"->",
"entityMap",
"->",
"getKeyName",
"(",
")",
",",
"$",
"columns",
")",
")",
"{",
"$",
"columns",
"[",
"]",
"=",
"$",
"this",
"->",
"entityMap",
"->",
"getKeyName",
"(",
")",
";",
"}",
"return",
"$",
"columns",
";",
"}"
] | Add the Entity primary key if not in requested columns.
@param array $columns
@return array | [
"Add",
"the",
"Entity",
"primary",
"key",
"if",
"not",
"in",
"requested",
"columns",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Query.php#L584-L591 |
analogueorm/analogue | src/System/Query.php | Query.getEntities | public function getEntities($columns = ['*'])
{
// As we need the primary key to feed the
// entity cache, we need it loaded on each
// request
if ($columns !== ['*']) {
$columns = $this->enforceIdColumn($columns);
}
// Run the query
$results = $this->query->get($columns);
// Pass result set to the mapper and return the EntityCollection
return $this->mapper->map($results, $this->getEagerLoads(), $this->useCache);
} | php | public function getEntities($columns = ['*'])
{
// As we need the primary key to feed the
// entity cache, we need it loaded on each
// request
if ($columns !== ['*']) {
$columns = $this->enforceIdColumn($columns);
}
// Run the query
$results = $this->query->get($columns);
// Pass result set to the mapper and return the EntityCollection
return $this->mapper->map($results, $this->getEagerLoads(), $this->useCache);
} | [
"public",
"function",
"getEntities",
"(",
"$",
"columns",
"=",
"[",
"'*'",
"]",
")",
"{",
"// As we need the primary key to feed the",
"// entity cache, we need it loaded on each",
"// request",
"if",
"(",
"$",
"columns",
"!==",
"[",
"'*'",
"]",
")",
"{",
"$",
"columns",
"=",
"$",
"this",
"->",
"enforceIdColumn",
"(",
"$",
"columns",
")",
";",
"}",
"// Run the query",
"$",
"results",
"=",
"$",
"this",
"->",
"query",
"->",
"get",
"(",
"$",
"columns",
")",
";",
"// Pass result set to the mapper and return the EntityCollection",
"return",
"$",
"this",
"->",
"mapper",
"->",
"map",
"(",
"$",
"results",
",",
"$",
"this",
"->",
"getEagerLoads",
"(",
")",
",",
"$",
"this",
"->",
"useCache",
")",
";",
"}"
] | Get the hydrated models without eager loading.
@param array $columns
@return \Illuminate\Support\Collection | [
"Get",
"the",
"hydrated",
"models",
"without",
"eager",
"loading",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Query.php#L600-L614 |
analogueorm/analogue | src/System/Query.php | Query.newQuery | public function newQuery()
{
$builder = new self($this->mapper, $this->adapter);
return $this->applyGlobalScopes($builder);
} | php | public function newQuery()
{
$builder = new self($this->mapper, $this->adapter);
return $this->applyGlobalScopes($builder);
} | [
"public",
"function",
"newQuery",
"(",
")",
"{",
"$",
"builder",
"=",
"new",
"self",
"(",
"$",
"this",
"->",
"mapper",
",",
"$",
"this",
"->",
"adapter",
")",
";",
"return",
"$",
"this",
"->",
"applyGlobalScopes",
"(",
"$",
"builder",
")",
";",
"}"
] | Get a new query builder for the model's table.
@return \Analogue\ORM\System\Query | [
"Get",
"a",
"new",
"query",
"builder",
"for",
"the",
"model",
"s",
"table",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Query.php#L646-L651 |
analogueorm/analogue | src/Relationships/EmbeddedRelationship.php | EmbeddedRelationship.getEmbeddedObjectAttributes | protected function getEmbeddedObjectAttributes() : array
{
$entityMap = $this->getRelatedMapper()->getEntityMap();
$attributes = $entityMap->getAttributes();
$properties = $entityMap->getProperties();
return array_merge($attributes, $properties);
} | php | protected function getEmbeddedObjectAttributes() : array
{
$entityMap = $this->getRelatedMapper()->getEntityMap();
$attributes = $entityMap->getAttributes();
$properties = $entityMap->getProperties();
return array_merge($attributes, $properties);
} | [
"protected",
"function",
"getEmbeddedObjectAttributes",
"(",
")",
":",
"array",
"{",
"$",
"entityMap",
"=",
"$",
"this",
"->",
"getRelatedMapper",
"(",
")",
"->",
"getEntityMap",
"(",
")",
";",
"$",
"attributes",
"=",
"$",
"entityMap",
"->",
"getAttributes",
"(",
")",
";",
"$",
"properties",
"=",
"$",
"entityMap",
"->",
"getProperties",
"(",
")",
";",
"return",
"array_merge",
"(",
"$",
"attributes",
",",
"$",
"properties",
")",
";",
"}"
] | Get the embedded object's attributes that will be
hydrated using parent's entity attributes.
@return array | [
"Get",
"the",
"embedded",
"object",
"s",
"attributes",
"that",
"will",
"be",
"hydrated",
"using",
"parent",
"s",
"entity",
"attributes",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/EmbeddedRelationship.php#L152-L160 |
analogueorm/analogue | src/Relationships/EmbeddedRelationship.php | EmbeddedRelationship.getMappedParentAttribute | protected function getMappedParentAttribute(string $key) : string
{
if (array_key_exists($key, $this->columnMap)) {
return $this->columnMap[$key];
} else {
return $key;
}
} | php | protected function getMappedParentAttribute(string $key) : string
{
if (array_key_exists($key, $this->columnMap)) {
return $this->columnMap[$key];
} else {
return $key;
}
} | [
"protected",
"function",
"getMappedParentAttribute",
"(",
"string",
"$",
"key",
")",
":",
"string",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"columnMap",
")",
")",
"{",
"return",
"$",
"this",
"->",
"columnMap",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"return",
"$",
"key",
";",
"}",
"}"
] | Get attribute name from the parent, if a map has been
defined.
@param string $key
@return string | [
"Get",
"attribute",
"name",
"from",
"the",
"parent",
"if",
"a",
"map",
"has",
"been",
"defined",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/EmbeddedRelationship.php#L182-L189 |
analogueorm/analogue | src/Relationships/EmbeddedRelationship.php | EmbeddedRelationship.buildEmbeddedObject | protected function buildEmbeddedObject(array $attributes)
{
$resultBuilder = new ResultBuilder($this->getRelatedMapper(), true);
// TODO : find a way to support eager load within an embedded
// object.
$eagerLoads = [];
return $resultBuilder->build([$attributes], $eagerLoads)[0];
} | php | protected function buildEmbeddedObject(array $attributes)
{
$resultBuilder = new ResultBuilder($this->getRelatedMapper(), true);
// TODO : find a way to support eager load within an embedded
// object.
$eagerLoads = [];
return $resultBuilder->build([$attributes], $eagerLoads)[0];
} | [
"protected",
"function",
"buildEmbeddedObject",
"(",
"array",
"$",
"attributes",
")",
"{",
"$",
"resultBuilder",
"=",
"new",
"ResultBuilder",
"(",
"$",
"this",
"->",
"getRelatedMapper",
"(",
")",
",",
"true",
")",
";",
"// TODO : find a way to support eager load within an embedded",
"// object.",
"$",
"eagerLoads",
"=",
"[",
"]",
";",
"return",
"$",
"resultBuilder",
"->",
"build",
"(",
"[",
"$",
"attributes",
"]",
",",
"$",
"eagerLoads",
")",
"[",
"0",
"]",
";",
"}"
] | Build an embedded object instance.
@param array $attributes
@return mixed | [
"Build",
"an",
"embedded",
"object",
"instance",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/EmbeddedRelationship.php#L218-L227 |
analogueorm/analogue | src/Plugins/SoftDeletes/Restore.php | Restore.execute | public function execute()
{
$aggregate = $this->aggregate;
$entity = $aggregate->getEntityObject();
$mapper = $aggregate->getMapper();
$entityMap = $mapper->getEntityMap();
if ($mapper->fireEvent('restoring', $entity) === false) {
return false;
}
$keyName = $entityMap->getKeyName();
$query = $this->query->where($keyName, '=', $aggregate->getEntityAttribute($keyName));
$deletedAtColumn = $entityMap->getQualifiedDeletedAtColumn();
$query->update([$deletedAtColumn => null]);
$aggregate->setEntityAttribute($deletedAtColumn, null);
$mapper->fireEvent('restored', $entity, false);
$mapper->getEntityCache()->refresh($aggregate);
return $entity;
} | php | public function execute()
{
$aggregate = $this->aggregate;
$entity = $aggregate->getEntityObject();
$mapper = $aggregate->getMapper();
$entityMap = $mapper->getEntityMap();
if ($mapper->fireEvent('restoring', $entity) === false) {
return false;
}
$keyName = $entityMap->getKeyName();
$query = $this->query->where($keyName, '=', $aggregate->getEntityAttribute($keyName));
$deletedAtColumn = $entityMap->getQualifiedDeletedAtColumn();
$query->update([$deletedAtColumn => null]);
$aggregate->setEntityAttribute($deletedAtColumn, null);
$mapper->fireEvent('restored', $entity, false);
$mapper->getEntityCache()->refresh($aggregate);
return $entity;
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"$",
"aggregate",
"=",
"$",
"this",
"->",
"aggregate",
";",
"$",
"entity",
"=",
"$",
"aggregate",
"->",
"getEntityObject",
"(",
")",
";",
"$",
"mapper",
"=",
"$",
"aggregate",
"->",
"getMapper",
"(",
")",
";",
"$",
"entityMap",
"=",
"$",
"mapper",
"->",
"getEntityMap",
"(",
")",
";",
"if",
"(",
"$",
"mapper",
"->",
"fireEvent",
"(",
"'restoring'",
",",
"$",
"entity",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"$",
"keyName",
"=",
"$",
"entityMap",
"->",
"getKeyName",
"(",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"query",
"->",
"where",
"(",
"$",
"keyName",
",",
"'='",
",",
"$",
"aggregate",
"->",
"getEntityAttribute",
"(",
"$",
"keyName",
")",
")",
";",
"$",
"deletedAtColumn",
"=",
"$",
"entityMap",
"->",
"getQualifiedDeletedAtColumn",
"(",
")",
";",
"$",
"query",
"->",
"update",
"(",
"[",
"$",
"deletedAtColumn",
"=>",
"null",
"]",
")",
";",
"$",
"aggregate",
"->",
"setEntityAttribute",
"(",
"$",
"deletedAtColumn",
",",
"null",
")",
";",
"$",
"mapper",
"->",
"fireEvent",
"(",
"'restored'",
",",
"$",
"entity",
",",
"false",
")",
";",
"$",
"mapper",
"->",
"getEntityCache",
"(",
")",
"->",
"refresh",
"(",
"$",
"aggregate",
")",
";",
"return",
"$",
"entity",
";",
"}"
] | @throws \InvalidArgumentException
@return false|mixed | [
"@throws",
"\\",
"InvalidArgumentException"
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Plugins/SoftDeletes/Restore.php#L14-L40 |
analogueorm/analogue | src/Relationships/MorphToMany.php | MorphToMany.setWhere | protected function setWhere()
{
parent::setWhere();
$this->query->where($this->table.'.'.$this->morphType, $this->morphClass);
return $this;
} | php | protected function setWhere()
{
parent::setWhere();
$this->query->where($this->table.'.'.$this->morphType, $this->morphClass);
return $this;
} | [
"protected",
"function",
"setWhere",
"(",
")",
"{",
"parent",
"::",
"setWhere",
"(",
")",
";",
"$",
"this",
"->",
"query",
"->",
"where",
"(",
"$",
"this",
"->",
"table",
".",
"'.'",
".",
"$",
"this",
"->",
"morphType",
",",
"$",
"this",
"->",
"morphClass",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the where clause for the relation query.
@return self | [
"Set",
"the",
"where",
"clause",
"for",
"the",
"relation",
"query",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/MorphToMany.php#L63-L70 |
analogueorm/analogue | src/Relationships/MorphToMany.php | MorphToMany.getRelationCountQuery | public function getRelationCountQuery(Query $query, Query $parent)
{
$query = parent::getRelationCountQuery($query, $parent);
return $query->where($this->table.'.'.$this->morphType, $this->morphClass);
} | php | public function getRelationCountQuery(Query $query, Query $parent)
{
$query = parent::getRelationCountQuery($query, $parent);
return $query->where($this->table.'.'.$this->morphType, $this->morphClass);
} | [
"public",
"function",
"getRelationCountQuery",
"(",
"Query",
"$",
"query",
",",
"Query",
"$",
"parent",
")",
"{",
"$",
"query",
"=",
"parent",
"::",
"getRelationCountQuery",
"(",
"$",
"query",
",",
"$",
"parent",
")",
";",
"return",
"$",
"query",
"->",
"where",
"(",
"$",
"this",
"->",
"table",
".",
"'.'",
".",
"$",
"this",
"->",
"morphType",
",",
"$",
"this",
"->",
"morphClass",
")",
";",
"}"
] | Add the constraints for a relationship count query.
@param Query $query
@param Query $parent
@return Query | [
"Add",
"the",
"constraints",
"for",
"a",
"relationship",
"count",
"query",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/MorphToMany.php#L80-L85 |
analogueorm/analogue | src/Relationships/MorphToMany.php | MorphToMany.createAttachRecord | protected function createAttachRecord($id, $timed)
{
$record = parent::createAttachRecord($id, $timed);
return array_add($record, $this->morphType, $this->morphClass);
} | php | protected function createAttachRecord($id, $timed)
{
$record = parent::createAttachRecord($id, $timed);
return array_add($record, $this->morphType, $this->morphClass);
} | [
"protected",
"function",
"createAttachRecord",
"(",
"$",
"id",
",",
"$",
"timed",
")",
"{",
"$",
"record",
"=",
"parent",
"::",
"createAttachRecord",
"(",
"$",
"id",
",",
"$",
"timed",
")",
";",
"return",
"array_add",
"(",
"$",
"record",
",",
"$",
"this",
"->",
"morphType",
",",
"$",
"this",
"->",
"morphClass",
")",
";",
"}"
] | Create a new pivot attachment record.
@param int $id
@param bool $timed
@return array | [
"Create",
"a",
"new",
"pivot",
"attachment",
"record",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/MorphToMany.php#L109-L114 |
analogueorm/analogue | src/Relationships/MorphToMany.php | MorphToMany.newPivotQuery | protected function newPivotQuery()
{
$query = parent::newPivotQuery();
return $query->where($this->morphType, $this->morphClass);
} | php | protected function newPivotQuery()
{
$query = parent::newPivotQuery();
return $query->where($this->morphType, $this->morphClass);
} | [
"protected",
"function",
"newPivotQuery",
"(",
")",
"{",
"$",
"query",
"=",
"parent",
"::",
"newPivotQuery",
"(",
")",
";",
"return",
"$",
"query",
"->",
"where",
"(",
"$",
"this",
"->",
"morphType",
",",
"$",
"this",
"->",
"morphClass",
")",
";",
"}"
] | Create a new query builder for the pivot table.
@throws \InvalidArgumentException
@return \Illuminate\Database\Query\Builder | [
"Create",
"a",
"new",
"query",
"builder",
"for",
"the",
"pivot",
"table",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/MorphToMany.php#L123-L128 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.