id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
---|---|---|---|---|---|---|---|---|---|---|---|
18,800 | ClanCats/Core | src/classes/CCImage.php | CCImage.create | public static function create( $file, $type = null )
{
// when no type is given use the file extension
if ( is_null( $type ) )
{
$type = CCStr::extension( $file );
// validate type
if ( !in_array( $type, static::$available_image_types ) )
{
$type = null;
}
}
$image_data = getimagesize( $file );
if ( $image_data === false )
{
return false;
}
$image = null;
switch( $image_data['mime'] )
{
case 'image/gif':
$image = imagecreatefromgif( $file );
break;
case 'image/jpeg';
$image = imagecreatefromjpeg( $file );
break;
case 'image/png':
$image = imagecreatefrompng( $file );
break;
default:
// we dont support other image types
return false;
break;
}
// when the image type is still null we are going to use
// the mime type of the image
if ( is_null( $type ) )
{
$type = CCStr::suffix( $image_data['mime'], '/' );
}
return new static( $image, $type );
} | php | public static function create( $file, $type = null )
{
// when no type is given use the file extension
if ( is_null( $type ) )
{
$type = CCStr::extension( $file );
// validate type
if ( !in_array( $type, static::$available_image_types ) )
{
$type = null;
}
}
$image_data = getimagesize( $file );
if ( $image_data === false )
{
return false;
}
$image = null;
switch( $image_data['mime'] )
{
case 'image/gif':
$image = imagecreatefromgif( $file );
break;
case 'image/jpeg';
$image = imagecreatefromjpeg( $file );
break;
case 'image/png':
$image = imagecreatefrompng( $file );
break;
default:
// we dont support other image types
return false;
break;
}
// when the image type is still null we are going to use
// the mime type of the image
if ( is_null( $type ) )
{
$type = CCStr::suffix( $image_data['mime'], '/' );
}
return new static( $image, $type );
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"file",
",",
"$",
"type",
"=",
"null",
")",
"{",
"// when no type is given use the file extension",
"if",
"(",
"is_null",
"(",
"$",
"type",
")",
")",
"{",
"$",
"type",
"=",
"CCStr",
"::",
"extension",
"(",
"$",
"file",
")",
";",
"// validate type",
"if",
"(",
"!",
"in_array",
"(",
"$",
"type",
",",
"static",
"::",
"$",
"available_image_types",
")",
")",
"{",
"$",
"type",
"=",
"null",
";",
"}",
"}",
"$",
"image_data",
"=",
"getimagesize",
"(",
"$",
"file",
")",
";",
"if",
"(",
"$",
"image_data",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"$",
"image",
"=",
"null",
";",
"switch",
"(",
"$",
"image_data",
"[",
"'mime'",
"]",
")",
"{",
"case",
"'image/gif'",
":",
"$",
"image",
"=",
"imagecreatefromgif",
"(",
"$",
"file",
")",
";",
"break",
";",
"case",
"'image/jpeg'",
";",
"$",
"image",
"=",
"imagecreatefromjpeg",
"(",
"$",
"file",
")",
";",
"break",
";",
"case",
"'image/png'",
":",
"$",
"image",
"=",
"imagecreatefrompng",
"(",
"$",
"file",
")",
";",
"break",
";",
"default",
":",
"// we dont support other image types",
"return",
"false",
";",
"break",
";",
"}",
"// when the image type is still null we are going to use ",
"// the mime type of the image ",
"if",
"(",
"is_null",
"(",
"$",
"type",
")",
")",
"{",
"$",
"type",
"=",
"CCStr",
"::",
"suffix",
"(",
"$",
"image_data",
"[",
"'mime'",
"]",
",",
"'/'",
")",
";",
"}",
"return",
"new",
"static",
"(",
"$",
"image",
",",
"$",
"type",
")",
";",
"}"
]
| Create a image from file
@param string $file
@param string $type jpg|png|gif
@return CCImage|false | [
"Create",
"a",
"image",
"from",
"file"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCImage.php#L57-L108 |
18,801 | ClanCats/Core | src/classes/CCImage.php | CCImage.string | public static function string( $string, $type = null )
{
$image = imagecreatefromstring( $string );
if ( $image !== false )
{
return new static( $image, $type );
}
return false;
} | php | public static function string( $string, $type = null )
{
$image = imagecreatefromstring( $string );
if ( $image !== false )
{
return new static( $image, $type );
}
return false;
} | [
"public",
"static",
"function",
"string",
"(",
"$",
"string",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"image",
"=",
"imagecreatefromstring",
"(",
"$",
"string",
")",
";",
"if",
"(",
"$",
"image",
"!==",
"false",
")",
"{",
"return",
"new",
"static",
"(",
"$",
"image",
",",
"$",
"type",
")",
";",
"}",
"return",
"false",
";",
"}"
]
| Create an image from string
@param string $string The image data string
@param string $type jpg|png|gif
@return CCImage|false | [
"Create",
"an",
"image",
"from",
"string"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCImage.php#L118-L128 |
18,802 | ClanCats/Core | src/classes/CCImage.php | CCImage.aspect_ratio | public static function aspect_ratio( $width, $height, $proper = false )
{
$ratio = $width / $height;
if ( !$proper )
{
return $ratio;
}
$tolerance = 1.e-6;
$h1=1; $h2=0;
$k1=0; $k2=1;
$b = 1/$ratio;
do {
$b = 1/$b;
$a = floor($b);
$aux = $h1; $h1 = $a*$h1+$h2; $h2 = $aux;
$aux = $k1; $k1 = $a*$k1+$k2; $k2 = $aux;
$b = $b-$a;
} while ( abs( $ratio-$h1 / $k1 ) > $ratio * $tolerance );
return $h1.":".$k1;
} | php | public static function aspect_ratio( $width, $height, $proper = false )
{
$ratio = $width / $height;
if ( !$proper )
{
return $ratio;
}
$tolerance = 1.e-6;
$h1=1; $h2=0;
$k1=0; $k2=1;
$b = 1/$ratio;
do {
$b = 1/$b;
$a = floor($b);
$aux = $h1; $h1 = $a*$h1+$h2; $h2 = $aux;
$aux = $k1; $k1 = $a*$k1+$k2; $k2 = $aux;
$b = $b-$a;
} while ( abs( $ratio-$h1 / $k1 ) > $ratio * $tolerance );
return $h1.":".$k1;
} | [
"public",
"static",
"function",
"aspect_ratio",
"(",
"$",
"width",
",",
"$",
"height",
",",
"$",
"proper",
"=",
"false",
")",
"{",
"$",
"ratio",
"=",
"$",
"width",
"/",
"$",
"height",
";",
"if",
"(",
"!",
"$",
"proper",
")",
"{",
"return",
"$",
"ratio",
";",
"}",
"$",
"tolerance",
"=",
"1.e-6",
";",
"$",
"h1",
"=",
"1",
";",
"$",
"h2",
"=",
"0",
";",
"$",
"k1",
"=",
"0",
";",
"$",
"k2",
"=",
"1",
";",
"$",
"b",
"=",
"1",
"/",
"$",
"ratio",
";",
"do",
"{",
"$",
"b",
"=",
"1",
"/",
"$",
"b",
";",
"$",
"a",
"=",
"floor",
"(",
"$",
"b",
")",
";",
"$",
"aux",
"=",
"$",
"h1",
";",
"$",
"h1",
"=",
"$",
"a",
"*",
"$",
"h1",
"+",
"$",
"h2",
";",
"$",
"h2",
"=",
"$",
"aux",
";",
"$",
"aux",
"=",
"$",
"k1",
";",
"$",
"k1",
"=",
"$",
"a",
"*",
"$",
"k1",
"+",
"$",
"k2",
";",
"$",
"k2",
"=",
"$",
"aux",
";",
"$",
"b",
"=",
"$",
"b",
"-",
"$",
"a",
";",
"}",
"while",
"(",
"abs",
"(",
"$",
"ratio",
"-",
"$",
"h1",
"/",
"$",
"k1",
")",
">",
"$",
"ratio",
"*",
"$",
"tolerance",
")",
";",
"return",
"$",
"h1",
".",
"\":\"",
".",
"$",
"k1",
";",
"}"
]
| Calculate the aspect ratio
@param int $width
@param int $height
@param bool $proper
@return string
@thanks to: http://jonisalonen.com/2012/converting-decimal-numbers-to-ratios/ | [
"Calculate",
"the",
"aspect",
"ratio"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCImage.php#L141-L165 |
18,803 | ClanCats/Core | src/classes/CCImage.php | CCImage.reload_context_info | protected function reload_context_info()
{
$this->width = imagesx( $this->image_context );
$this->height = imagesy( $this->image_context );
} | php | protected function reload_context_info()
{
$this->width = imagesx( $this->image_context );
$this->height = imagesy( $this->image_context );
} | [
"protected",
"function",
"reload_context_info",
"(",
")",
"{",
"$",
"this",
"->",
"width",
"=",
"imagesx",
"(",
"$",
"this",
"->",
"image_context",
")",
";",
"$",
"this",
"->",
"height",
"=",
"imagesy",
"(",
"$",
"this",
"->",
"image_context",
")",
";",
"}"
]
| Reload the image dimension etc.
@return void | [
"Reload",
"the",
"image",
"dimension",
"etc",
"."
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCImage.php#L221-L225 |
18,804 | ClanCats/Core | src/classes/CCImage.php | CCImage.set_type | protected function set_type( $type, $overwrite = true )
{
if ( !is_null( $type ) )
{
if ( !in_array( $type, static::$available_image_types ) )
{
throw new CCException( "CCImage - Invalid image type '".$type."'." );
}
// don't allow jpg, set to jpeg
if ( $type === 'jpg' )
{
$type = 'jpeg';
}
if ( $overwrite )
{
$this->type = $type;
}
}
return $type;
} | php | protected function set_type( $type, $overwrite = true )
{
if ( !is_null( $type ) )
{
if ( !in_array( $type, static::$available_image_types ) )
{
throw new CCException( "CCImage - Invalid image type '".$type."'." );
}
// don't allow jpg, set to jpeg
if ( $type === 'jpg' )
{
$type = 'jpeg';
}
if ( $overwrite )
{
$this->type = $type;
}
}
return $type;
} | [
"protected",
"function",
"set_type",
"(",
"$",
"type",
",",
"$",
"overwrite",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"type",
")",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"type",
",",
"static",
"::",
"$",
"available_image_types",
")",
")",
"{",
"throw",
"new",
"CCException",
"(",
"\"CCImage - Invalid image type '\"",
".",
"$",
"type",
".",
"\"'.\"",
")",
";",
"}",
"// don't allow jpg, set to jpeg",
"if",
"(",
"$",
"type",
"===",
"'jpg'",
")",
"{",
"$",
"type",
"=",
"'jpeg'",
";",
"}",
"if",
"(",
"$",
"overwrite",
")",
"{",
"$",
"this",
"->",
"type",
"=",
"$",
"type",
";",
"}",
"}",
"return",
"$",
"type",
";",
"}"
]
| Set the current image type
@param string $type The new image type
@param string $overwrite Should the image keep this type?
@return string | [
"Set",
"the",
"current",
"image",
"type"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCImage.php#L234-L256 |
18,805 | ClanCats/Core | src/classes/CCImage.php | CCImage.stream | public function stream( $quality = null, $type = null )
{
$this->save( null, $quality, $type );
} | php | public function stream( $quality = null, $type = null )
{
$this->save( null, $quality, $type );
} | [
"public",
"function",
"stream",
"(",
"$",
"quality",
"=",
"null",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"save",
"(",
"null",
",",
"$",
"quality",
",",
"$",
"type",
")",
";",
"}"
]
| Send the image to the output buffer
@param int $quality
@param string $type jpg|png|gif
@return void | [
"Send",
"the",
"image",
"to",
"the",
"output",
"buffer"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCImage.php#L325-L328 |
18,806 | ClanCats/Core | src/classes/CCImage.php | CCImage.stringify | public function stringify( $quality = null, $type = null )
{
ob_start(); $this->stream( $quality, $type ); return ob_get_clean();
} | php | public function stringify( $quality = null, $type = null )
{
ob_start(); $this->stream( $quality, $type ); return ob_get_clean();
} | [
"public",
"function",
"stringify",
"(",
"$",
"quality",
"=",
"null",
",",
"$",
"type",
"=",
"null",
")",
"{",
"ob_start",
"(",
")",
";",
"$",
"this",
"->",
"stream",
"(",
"$",
"quality",
",",
"$",
"type",
")",
";",
"return",
"ob_get_clean",
"(",
")",
";",
"}"
]
| Return the image data as string
@param int $quality
@param string $type jpg|png|gif
@return string | [
"Return",
"the",
"image",
"data",
"as",
"string"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCImage.php#L337-L340 |
18,807 | ClanCats/Core | src/classes/CCImage.php | CCImage.response | public function response( $quality = null, $type = null )
{
$response = CCResponse::create( $this->stringify( $quality, $type ) );
if ( !is_null( $this->type ) )
{
$response->header( 'Content-Type', 'image/'.$this->type );
}
return $response;
} | php | public function response( $quality = null, $type = null )
{
$response = CCResponse::create( $this->stringify( $quality, $type ) );
if ( !is_null( $this->type ) )
{
$response->header( 'Content-Type', 'image/'.$this->type );
}
return $response;
} | [
"public",
"function",
"response",
"(",
"$",
"quality",
"=",
"null",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"response",
"=",
"CCResponse",
"::",
"create",
"(",
"$",
"this",
"->",
"stringify",
"(",
"$",
"quality",
",",
"$",
"type",
")",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"type",
")",
")",
"{",
"$",
"response",
"->",
"header",
"(",
"'Content-Type'",
",",
"'image/'",
".",
"$",
"this",
"->",
"type",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
]
| Create a CCRespone of the image
@param string $quality The image quality
@param string $type jpg|png|gif
@return CCresponse | [
"Create",
"a",
"CCRespone",
"of",
"the",
"image"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCImage.php#L349-L359 |
18,808 | ClanCats/Core | src/classes/CCImage.php | CCImage.resize | public function resize( $width, $height, $mode = null )
{
// check for alternative syntax
if ( strpos( $width, 'x' ) !== false )
{
// mode is the secound param
$mode = $height;
$dimensions = explode( 'x', $width );
$width = $dimensions[0];
$height = $dimensions[1];
}
// default mode
if ( is_null( $mode ) )
{
$mode = 'strict';
}
// auto width
if ( $width == 'auto' )
{
$mode = 'portrait';
// in this case the $height is the first param
$width = $height;
}
// auto height
elseif ( $height == 'auto' )
{
$mode = 'landscape';
}
$method = 'resize_'.$mode;
if ( !method_exists( $this, $method ) )
{
throw new CCException( "CCImage::resize - Invalid resize method ".$mode."." );
}
return call_user_func_array( array( $this, $method ), array( $width, $height ) );
} | php | public function resize( $width, $height, $mode = null )
{
// check for alternative syntax
if ( strpos( $width, 'x' ) !== false )
{
// mode is the secound param
$mode = $height;
$dimensions = explode( 'x', $width );
$width = $dimensions[0];
$height = $dimensions[1];
}
// default mode
if ( is_null( $mode ) )
{
$mode = 'strict';
}
// auto width
if ( $width == 'auto' )
{
$mode = 'portrait';
// in this case the $height is the first param
$width = $height;
}
// auto height
elseif ( $height == 'auto' )
{
$mode = 'landscape';
}
$method = 'resize_'.$mode;
if ( !method_exists( $this, $method ) )
{
throw new CCException( "CCImage::resize - Invalid resize method ".$mode."." );
}
return call_user_func_array( array( $this, $method ), array( $width, $height ) );
} | [
"public",
"function",
"resize",
"(",
"$",
"width",
",",
"$",
"height",
",",
"$",
"mode",
"=",
"null",
")",
"{",
"// check for alternative syntax ",
"if",
"(",
"strpos",
"(",
"$",
"width",
",",
"'x'",
")",
"!==",
"false",
")",
"{",
"// mode is the secound param",
"$",
"mode",
"=",
"$",
"height",
";",
"$",
"dimensions",
"=",
"explode",
"(",
"'x'",
",",
"$",
"width",
")",
";",
"$",
"width",
"=",
"$",
"dimensions",
"[",
"0",
"]",
";",
"$",
"height",
"=",
"$",
"dimensions",
"[",
"1",
"]",
";",
"}",
"// default mode",
"if",
"(",
"is_null",
"(",
"$",
"mode",
")",
")",
"{",
"$",
"mode",
"=",
"'strict'",
";",
"}",
"// auto width",
"if",
"(",
"$",
"width",
"==",
"'auto'",
")",
"{",
"$",
"mode",
"=",
"'portrait'",
";",
"// in this case the $height is the first param",
"$",
"width",
"=",
"$",
"height",
";",
"}",
"// auto height",
"elseif",
"(",
"$",
"height",
"==",
"'auto'",
")",
"{",
"$",
"mode",
"=",
"'landscape'",
";",
"}",
"$",
"method",
"=",
"'resize_'",
".",
"$",
"mode",
";",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"throw",
"new",
"CCException",
"(",
"\"CCImage::resize - Invalid resize method \"",
".",
"$",
"mode",
".",
"\".\"",
")",
";",
"}",
"return",
"call_user_func_array",
"(",
"array",
"(",
"$",
"this",
",",
"$",
"method",
")",
",",
"array",
"(",
"$",
"width",
",",
"$",
"height",
")",
")",
";",
"}"
]
| Resize the image
Examples:
// simple resize
$image->resize( '200x150', 'fill' );
// does the same as
$image->resize( 200, 150, 'fill' );
// you can use auto values
$image->resize( 500, 'auto' );
@param int $width
@param int $height
@param string $mode
@return self | [
"Resize",
"the",
"image"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCImage.php#L378-L418 |
18,809 | ClanCats/Core | src/classes/CCImage.php | CCImage.resize_landscape | public function resize_landscape( $width, $ignore_me )
{
// calculate height
$height = $width * ( $this->height / $this->width );
return $this->resize_strict( $width, $height );
} | php | public function resize_landscape( $width, $ignore_me )
{
// calculate height
$height = $width * ( $this->height / $this->width );
return $this->resize_strict( $width, $height );
} | [
"public",
"function",
"resize_landscape",
"(",
"$",
"width",
",",
"$",
"ignore_me",
")",
"{",
"// calculate height",
"$",
"height",
"=",
"$",
"width",
"*",
"(",
"$",
"this",
"->",
"height",
"/",
"$",
"this",
"->",
"width",
")",
";",
"return",
"$",
"this",
"->",
"resize_strict",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"}"
]
| Resize the current image from width and keep aspect ratio
@param int $width
@param int $height
@return self | [
"Resize",
"the",
"current",
"image",
"from",
"width",
"and",
"keep",
"aspect",
"ratio"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCImage.php#L427-L433 |
18,810 | ClanCats/Core | src/classes/CCImage.php | CCImage.resize_portrait | public function resize_portrait( $height, $ignore_me )
{
// calculate width
$width = $height * ( $this->width / $this->height );
return $this->resize_strict( $width, $height );
} | php | public function resize_portrait( $height, $ignore_me )
{
// calculate width
$width = $height * ( $this->width / $this->height );
return $this->resize_strict( $width, $height );
} | [
"public",
"function",
"resize_portrait",
"(",
"$",
"height",
",",
"$",
"ignore_me",
")",
"{",
"// calculate width",
"$",
"width",
"=",
"$",
"height",
"*",
"(",
"$",
"this",
"->",
"width",
"/",
"$",
"this",
"->",
"height",
")",
";",
"return",
"$",
"this",
"->",
"resize_strict",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"}"
]
| Resize the current image from height and keep aspect ratio
@param int $width
@param int $height
@return self | [
"Resize",
"the",
"current",
"image",
"from",
"height",
"and",
"keep",
"aspect",
"ratio"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCImage.php#L442-L448 |
18,811 | ClanCats/Core | src/classes/CCImage.php | CCImage.resize_max | public function resize_max( $width, $height )
{
$new_width = $this->width;
$new_height = $this->height;
if ( $new_width > $width )
{
// set new with
$new_width = $width;
// calculate height
$new_height = $new_width * ( $this->height / $this->width );
}
if ( $new_height > $height )
{
// set new height
$new_height = $height;
// calculate width
$new_width = $new_height * ( $this->width / $this->height );
}
return $this->resize_strict( $new_width, $new_height );
} | php | public function resize_max( $width, $height )
{
$new_width = $this->width;
$new_height = $this->height;
if ( $new_width > $width )
{
// set new with
$new_width = $width;
// calculate height
$new_height = $new_width * ( $this->height / $this->width );
}
if ( $new_height > $height )
{
// set new height
$new_height = $height;
// calculate width
$new_width = $new_height * ( $this->width / $this->height );
}
return $this->resize_strict( $new_width, $new_height );
} | [
"public",
"function",
"resize_max",
"(",
"$",
"width",
",",
"$",
"height",
")",
"{",
"$",
"new_width",
"=",
"$",
"this",
"->",
"width",
";",
"$",
"new_height",
"=",
"$",
"this",
"->",
"height",
";",
"if",
"(",
"$",
"new_width",
">",
"$",
"width",
")",
"{",
"// set new with",
"$",
"new_width",
"=",
"$",
"width",
";",
"// calculate height",
"$",
"new_height",
"=",
"$",
"new_width",
"*",
"(",
"$",
"this",
"->",
"height",
"/",
"$",
"this",
"->",
"width",
")",
";",
"}",
"if",
"(",
"$",
"new_height",
">",
"$",
"height",
")",
"{",
"// set new height",
"$",
"new_height",
"=",
"$",
"height",
";",
"// calculate width",
"$",
"new_width",
"=",
"$",
"new_height",
"*",
"(",
"$",
"this",
"->",
"width",
"/",
"$",
"this",
"->",
"height",
")",
";",
"}",
"return",
"$",
"this",
"->",
"resize_strict",
"(",
"$",
"new_width",
",",
"$",
"new_height",
")",
";",
"}"
]
| Resize the image that it fits into a size doesn't crop and does not add a border
@param int $width
@param int $height
@return self | [
"Resize",
"the",
"image",
"that",
"it",
"fits",
"into",
"a",
"size",
"doesn",
"t",
"crop",
"and",
"does",
"not",
"add",
"a",
"border"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCImage.php#L457-L479 |
18,812 | ClanCats/Core | src/classes/CCImage.php | CCImage.resize_fit | public function resize_fit( $width, $height, $background_color = '#fff' )
{
$background = static::blank( $width, $height );
// make out actual image max size
static::resize_max( $width, $height );
// make background white
$background->fill_color( $background_color );
// add the layer
$background->add_layer( $this, 'center', 'middle' );
// overwrite the image context
$this->image_context = $background->image_context;
// update properties
$this->width = $width;
$this->height = $height;
// return self
return $this;
} | php | public function resize_fit( $width, $height, $background_color = '#fff' )
{
$background = static::blank( $width, $height );
// make out actual image max size
static::resize_max( $width, $height );
// make background white
$background->fill_color( $background_color );
// add the layer
$background->add_layer( $this, 'center', 'middle' );
// overwrite the image context
$this->image_context = $background->image_context;
// update properties
$this->width = $width;
$this->height = $height;
// return self
return $this;
} | [
"public",
"function",
"resize_fit",
"(",
"$",
"width",
",",
"$",
"height",
",",
"$",
"background_color",
"=",
"'#fff'",
")",
"{",
"$",
"background",
"=",
"static",
"::",
"blank",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"// make out actual image max size",
"static",
"::",
"resize_max",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"// make background white",
"$",
"background",
"->",
"fill_color",
"(",
"$",
"background_color",
")",
";",
"// add the layer",
"$",
"background",
"->",
"add_layer",
"(",
"$",
"this",
",",
"'center'",
",",
"'middle'",
")",
";",
"// overwrite the image context ",
"$",
"this",
"->",
"image_context",
"=",
"$",
"background",
"->",
"image_context",
";",
"// update properties",
"$",
"this",
"->",
"width",
"=",
"$",
"width",
";",
"$",
"this",
"->",
"height",
"=",
"$",
"height",
";",
"// return self",
"return",
"$",
"this",
";",
"}"
]
| Resize the image that it fits into a size doesn't crop adds a background layer
@param int $width
@param int $height
@return self | [
"Resize",
"the",
"image",
"that",
"it",
"fits",
"into",
"a",
"size",
"doesn",
"t",
"crop",
"adds",
"a",
"background",
"layer"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCImage.php#L488-L510 |
18,813 | ClanCats/Core | src/classes/CCImage.php | CCImage.resize_fill | public function resize_fill( $width, $height )
{
$original_aspect = $this->width / $this->height;
$thumb_aspect = $width / $height;
if ( $original_aspect >= $thumb_aspect )
{
$new_height = $height;
$new_width = $this->width / ($this->height / $height);
}
else
{
$new_width = $width;
$new_height = $this->height / ($this->width / $width);
}
$x = 0 - ( $new_width - $width ) / 2;
$y = 0 - ( $new_height - $height ) / 2;
$result = imagecreatetruecolor( $width, $height );
imagecopyresampled( $result, $this->image_context, $x, $y, 0, 0, $new_width, $new_height, $this->width, $this->height );
// overwrite the image context
$this->image_context = $result;
// update properties
$this->reload_context_info();
// return self
return $this;
} | php | public function resize_fill( $width, $height )
{
$original_aspect = $this->width / $this->height;
$thumb_aspect = $width / $height;
if ( $original_aspect >= $thumb_aspect )
{
$new_height = $height;
$new_width = $this->width / ($this->height / $height);
}
else
{
$new_width = $width;
$new_height = $this->height / ($this->width / $width);
}
$x = 0 - ( $new_width - $width ) / 2;
$y = 0 - ( $new_height - $height ) / 2;
$result = imagecreatetruecolor( $width, $height );
imagecopyresampled( $result, $this->image_context, $x, $y, 0, 0, $new_width, $new_height, $this->width, $this->height );
// overwrite the image context
$this->image_context = $result;
// update properties
$this->reload_context_info();
// return self
return $this;
} | [
"public",
"function",
"resize_fill",
"(",
"$",
"width",
",",
"$",
"height",
")",
"{",
"$",
"original_aspect",
"=",
"$",
"this",
"->",
"width",
"/",
"$",
"this",
"->",
"height",
";",
"$",
"thumb_aspect",
"=",
"$",
"width",
"/",
"$",
"height",
";",
"if",
"(",
"$",
"original_aspect",
">=",
"$",
"thumb_aspect",
")",
"{",
"$",
"new_height",
"=",
"$",
"height",
";",
"$",
"new_width",
"=",
"$",
"this",
"->",
"width",
"/",
"(",
"$",
"this",
"->",
"height",
"/",
"$",
"height",
")",
";",
"}",
"else",
"{",
"$",
"new_width",
"=",
"$",
"width",
";",
"$",
"new_height",
"=",
"$",
"this",
"->",
"height",
"/",
"(",
"$",
"this",
"->",
"width",
"/",
"$",
"width",
")",
";",
"}",
"$",
"x",
"=",
"0",
"-",
"(",
"$",
"new_width",
"-",
"$",
"width",
")",
"/",
"2",
";",
"$",
"y",
"=",
"0",
"-",
"(",
"$",
"new_height",
"-",
"$",
"height",
")",
"/",
"2",
";",
"$",
"result",
"=",
"imagecreatetruecolor",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"imagecopyresampled",
"(",
"$",
"result",
",",
"$",
"this",
"->",
"image_context",
",",
"$",
"x",
",",
"$",
"y",
",",
"0",
",",
"0",
",",
"$",
"new_width",
",",
"$",
"new_height",
",",
"$",
"this",
"->",
"width",
",",
"$",
"this",
"->",
"height",
")",
";",
"// overwrite the image context ",
"$",
"this",
"->",
"image_context",
"=",
"$",
"result",
";",
"// update properties",
"$",
"this",
"->",
"reload_context_info",
"(",
")",
";",
"// return self",
"return",
"$",
"this",
";",
"}"
]
| Resize the image to fill the new size. This will crop your image.
@param int $width
@param int $height
@return self
@thanks to: http://stackoverflow.com/questions/1855996/crop-image-in-php | [
"Resize",
"the",
"image",
"to",
"fill",
"the",
"new",
"size",
".",
"This",
"will",
"crop",
"your",
"image",
"."
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCImage.php#L521-L551 |
18,814 | ClanCats/Core | src/classes/CCImage.php | CCImage.resize_strict | public function resize_strict( $width, $height )
{
// check dimensions
if ( !( $width > 0 ) || !( $height > 0 ) )
{
throw new CCException( "CCImage::resize_strict - width and height can't be smaller then 1" );
}
$result = imagecreatetruecolor( $width, $height );
imagecopyresampled( $result, $this->image_context, 0, 0, 0, 0, $width, $height, $this->width, $this->height );
// overwrite the image context
$this->image_context = $result;
// update properties
$this->reload_context_info();
// return self
return $this;
} | php | public function resize_strict( $width, $height )
{
// check dimensions
if ( !( $width > 0 ) || !( $height > 0 ) )
{
throw new CCException( "CCImage::resize_strict - width and height can't be smaller then 1" );
}
$result = imagecreatetruecolor( $width, $height );
imagecopyresampled( $result, $this->image_context, 0, 0, 0, 0, $width, $height, $this->width, $this->height );
// overwrite the image context
$this->image_context = $result;
// update properties
$this->reload_context_info();
// return self
return $this;
} | [
"public",
"function",
"resize_strict",
"(",
"$",
"width",
",",
"$",
"height",
")",
"{",
"// check dimensions",
"if",
"(",
"!",
"(",
"$",
"width",
">",
"0",
")",
"||",
"!",
"(",
"$",
"height",
">",
"0",
")",
")",
"{",
"throw",
"new",
"CCException",
"(",
"\"CCImage::resize_strict - width and height can't be smaller then 1\"",
")",
";",
"}",
"$",
"result",
"=",
"imagecreatetruecolor",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"imagecopyresampled",
"(",
"$",
"result",
",",
"$",
"this",
"->",
"image_context",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"$",
"width",
",",
"$",
"height",
",",
"$",
"this",
"->",
"width",
",",
"$",
"this",
"->",
"height",
")",
";",
"// overwrite the image context ",
"$",
"this",
"->",
"image_context",
"=",
"$",
"result",
";",
"// update properties",
"$",
"this",
"->",
"reload_context_info",
"(",
")",
";",
"// return self",
"return",
"$",
"this",
";",
"}"
]
| Resize the current image to strict dimensions
@param int $width
@param int $height
@param string $mode
@return self | [
"Resize",
"the",
"current",
"image",
"to",
"strict",
"dimensions"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCImage.php#L562-L581 |
18,815 | ClanCats/Core | src/classes/CCImage.php | CCImage.crop | public function crop( $x, $y, $width, $height )
{
// check for auto
if ( $x == 'center' || $x == 'auto' )
{
$x = ( $this->width / 2 ) - ( $width / 2 );
}
if ( $y == 'middle' || $y == 'auto' )
{
$y = ( $this->height / 2 ) - ( $height / 2 );
}
$result = imagecreatetruecolor( $width, $height );
ImageCopyResampled( $result, $this->image_context, 0, 0, $x, $y, $width, $height, $width, $height );
$this->image_context = $result;
// update properties
$this->reload_context_info();
// return self
return $this;
} | php | public function crop( $x, $y, $width, $height )
{
// check for auto
if ( $x == 'center' || $x == 'auto' )
{
$x = ( $this->width / 2 ) - ( $width / 2 );
}
if ( $y == 'middle' || $y == 'auto' )
{
$y = ( $this->height / 2 ) - ( $height / 2 );
}
$result = imagecreatetruecolor( $width, $height );
ImageCopyResampled( $result, $this->image_context, 0, 0, $x, $y, $width, $height, $width, $height );
$this->image_context = $result;
// update properties
$this->reload_context_info();
// return self
return $this;
} | [
"public",
"function",
"crop",
"(",
"$",
"x",
",",
"$",
"y",
",",
"$",
"width",
",",
"$",
"height",
")",
"{",
"// check for auto",
"if",
"(",
"$",
"x",
"==",
"'center'",
"||",
"$",
"x",
"==",
"'auto'",
")",
"{",
"$",
"x",
"=",
"(",
"$",
"this",
"->",
"width",
"/",
"2",
")",
"-",
"(",
"$",
"width",
"/",
"2",
")",
";",
"}",
"if",
"(",
"$",
"y",
"==",
"'middle'",
"||",
"$",
"y",
"==",
"'auto'",
")",
"{",
"$",
"y",
"=",
"(",
"$",
"this",
"->",
"height",
"/",
"2",
")",
"-",
"(",
"$",
"height",
"/",
"2",
")",
";",
"}",
"$",
"result",
"=",
"imagecreatetruecolor",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"ImageCopyResampled",
"(",
"$",
"result",
",",
"$",
"this",
"->",
"image_context",
",",
"0",
",",
"0",
",",
"$",
"x",
",",
"$",
"y",
",",
"$",
"width",
",",
"$",
"height",
",",
"$",
"width",
",",
"$",
"height",
")",
";",
"$",
"this",
"->",
"image_context",
"=",
"$",
"result",
";",
"// update properties",
"$",
"this",
"->",
"reload_context_info",
"(",
")",
";",
"// return self",
"return",
"$",
"this",
";",
"}"
]
| Crop the current image
This is a simplefied crop.
@param int $x
@param int $y
@param int $width
@param int $height
@return self | [
"Crop",
"the",
"current",
"image"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCImage.php#L595-L618 |
18,816 | ClanCats/Core | src/classes/CCImage.php | CCImage.add_layer | public function add_layer( CCImage $image, $x = 0, $y = 0, $alpha = 100 )
{
// auto values
if ( $x == 'center' || $x == 'auto' )
{
$x = ( $this->width / 2 ) - ( $image->width / 2 );
}
elseif ( $x == 'left' )
{
$x = 0;
}
elseif ( $x == 'right' )
{
$x = $this->width - $image->width;
}
if ( $y == 'middle' || $y == 'auto' )
{
$y = ( $this->height / 2 ) - ( $image->height / 2 );
}
elseif ( $x == 'top' )
{
$x = 0;
}
elseif ( $x == 'bottom' )
{
$x = $this->height - $image->height;
}
// run image copy
imagecopymerge( $this->image_context, $image->image_context, $x, $y, 0, 0, $image->width, $image->height, $alpha );
return $this;
} | php | public function add_layer( CCImage $image, $x = 0, $y = 0, $alpha = 100 )
{
// auto values
if ( $x == 'center' || $x == 'auto' )
{
$x = ( $this->width / 2 ) - ( $image->width / 2 );
}
elseif ( $x == 'left' )
{
$x = 0;
}
elseif ( $x == 'right' )
{
$x = $this->width - $image->width;
}
if ( $y == 'middle' || $y == 'auto' )
{
$y = ( $this->height / 2 ) - ( $image->height / 2 );
}
elseif ( $x == 'top' )
{
$x = 0;
}
elseif ( $x == 'bottom' )
{
$x = $this->height - $image->height;
}
// run image copy
imagecopymerge( $this->image_context, $image->image_context, $x, $y, 0, 0, $image->width, $image->height, $alpha );
return $this;
} | [
"public",
"function",
"add_layer",
"(",
"CCImage",
"$",
"image",
",",
"$",
"x",
"=",
"0",
",",
"$",
"y",
"=",
"0",
",",
"$",
"alpha",
"=",
"100",
")",
"{",
"// auto values",
"if",
"(",
"$",
"x",
"==",
"'center'",
"||",
"$",
"x",
"==",
"'auto'",
")",
"{",
"$",
"x",
"=",
"(",
"$",
"this",
"->",
"width",
"/",
"2",
")",
"-",
"(",
"$",
"image",
"->",
"width",
"/",
"2",
")",
";",
"}",
"elseif",
"(",
"$",
"x",
"==",
"'left'",
")",
"{",
"$",
"x",
"=",
"0",
";",
"}",
"elseif",
"(",
"$",
"x",
"==",
"'right'",
")",
"{",
"$",
"x",
"=",
"$",
"this",
"->",
"width",
"-",
"$",
"image",
"->",
"width",
";",
"}",
"if",
"(",
"$",
"y",
"==",
"'middle'",
"||",
"$",
"y",
"==",
"'auto'",
")",
"{",
"$",
"y",
"=",
"(",
"$",
"this",
"->",
"height",
"/",
"2",
")",
"-",
"(",
"$",
"image",
"->",
"height",
"/",
"2",
")",
";",
"}",
"elseif",
"(",
"$",
"x",
"==",
"'top'",
")",
"{",
"$",
"x",
"=",
"0",
";",
"}",
"elseif",
"(",
"$",
"x",
"==",
"'bottom'",
")",
"{",
"$",
"x",
"=",
"$",
"this",
"->",
"height",
"-",
"$",
"image",
"->",
"height",
";",
"}",
"// run image copy",
"imagecopymerge",
"(",
"$",
"this",
"->",
"image_context",
",",
"$",
"image",
"->",
"image_context",
",",
"$",
"x",
",",
"$",
"y",
",",
"0",
",",
"0",
",",
"$",
"image",
"->",
"width",
",",
"$",
"image",
"->",
"height",
",",
"$",
"alpha",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| add an layer to the current image
@param CCImage $image
@param int $x
@param int $y
@return self | [
"add",
"an",
"layer",
"to",
"the",
"current",
"image"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCImage.php#L629-L662 |
18,817 | ClanCats/Core | src/classes/CCImage.php | CCImage.fill_color | public function fill_color( $color, $alpha = 1 )
{
$alpha = $alpha * 127;
// parse the color
$color = CCColor::create( $color );
$color = imagecolorallocatealpha( $this->image_context, $color->RGB[0], $color->RGB[1], $color->RGB[2], $alpha );
// run image fill
imagefill( $this->image_context, 0, 0, $color );
return $this;
} | php | public function fill_color( $color, $alpha = 1 )
{
$alpha = $alpha * 127;
// parse the color
$color = CCColor::create( $color );
$color = imagecolorallocatealpha( $this->image_context, $color->RGB[0], $color->RGB[1], $color->RGB[2], $alpha );
// run image fill
imagefill( $this->image_context, 0, 0, $color );
return $this;
} | [
"public",
"function",
"fill_color",
"(",
"$",
"color",
",",
"$",
"alpha",
"=",
"1",
")",
"{",
"$",
"alpha",
"=",
"$",
"alpha",
"*",
"127",
";",
"// parse the color",
"$",
"color",
"=",
"CCColor",
"::",
"create",
"(",
"$",
"color",
")",
";",
"$",
"color",
"=",
"imagecolorallocatealpha",
"(",
"$",
"this",
"->",
"image_context",
",",
"$",
"color",
"->",
"RGB",
"[",
"0",
"]",
",",
"$",
"color",
"->",
"RGB",
"[",
"1",
"]",
",",
"$",
"color",
"->",
"RGB",
"[",
"2",
"]",
",",
"$",
"alpha",
")",
";",
"// run image fill",
"imagefill",
"(",
"$",
"this",
"->",
"image_context",
",",
"0",
",",
"0",
",",
"$",
"color",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| fill the current image with an color
you can pass an array with rgb or hex string
@param mixed $color
@return self | [
"fill",
"the",
"current",
"image",
"with",
"an",
"color",
"you",
"can",
"pass",
"an",
"array",
"with",
"rgb",
"or",
"hex",
"string"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCImage.php#L671-L683 |
18,818 | ClanCats/Core | src/classes/CCImage.php | CCImage.blur | public function blur( $ratio = 5 )
{
for ($x=0; $x<$ratio; $x++)
{
imagefilter($this->image_context, IMG_FILTER_GAUSSIAN_BLUR);
//$gaussian = array(array(1.0, 2.0, 1.0), array(2.0, 1.0, 2.0), array(1.0, 2.0, 1.0));
//imageconvolution($this->image_context, $gaussian, 16, 0);
}
return $this;
} | php | public function blur( $ratio = 5 )
{
for ($x=0; $x<$ratio; $x++)
{
imagefilter($this->image_context, IMG_FILTER_GAUSSIAN_BLUR);
//$gaussian = array(array(1.0, 2.0, 1.0), array(2.0, 1.0, 2.0), array(1.0, 2.0, 1.0));
//imageconvolution($this->image_context, $gaussian, 16, 0);
}
return $this;
} | [
"public",
"function",
"blur",
"(",
"$",
"ratio",
"=",
"5",
")",
"{",
"for",
"(",
"$",
"x",
"=",
"0",
";",
"$",
"x",
"<",
"$",
"ratio",
";",
"$",
"x",
"++",
")",
"{",
"imagefilter",
"(",
"$",
"this",
"->",
"image_context",
",",
"IMG_FILTER_GAUSSIAN_BLUR",
")",
";",
"//$gaussian = array(array(1.0, 2.0, 1.0), array(2.0, 1.0, 2.0), array(1.0, 2.0, 1.0));",
"//imageconvolution($this->image_context, $gaussian, 16, 0);",
"}",
"return",
"$",
"this",
";",
"}"
]
| Blur the image using the gaussian blur.
@param int $ratio
@return self | [
"Blur",
"the",
"image",
"using",
"the",
"gaussian",
"blur",
"."
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCImage.php#L691-L701 |
18,819 | ClanCats/Core | src/classes/CCImage.php | CCImage.get_luminance | public function get_luminance( $num_samples = 10 )
{
$x_step = (int) $this->width / $num_samples;
$y_step = (int) $this->height / $num_samples;
$total_lum = 0;
$sample_no = 1;
for ( $x=0; $x<$this->width; $x+=$x_step )
{
for ( $y=0; $y<$this->height; $y+=$y_step )
{
$rgb = imagecolorat($this->image_context, $x, $y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
$lum = ($r+$r+$b+$g+$g+$g)/6;
$total_lum += $lum;
$sample_no++;
}
}
return (int) ( $total_lum / $sample_no );
} | php | public function get_luminance( $num_samples = 10 )
{
$x_step = (int) $this->width / $num_samples;
$y_step = (int) $this->height / $num_samples;
$total_lum = 0;
$sample_no = 1;
for ( $x=0; $x<$this->width; $x+=$x_step )
{
for ( $y=0; $y<$this->height; $y+=$y_step )
{
$rgb = imagecolorat($this->image_context, $x, $y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
$lum = ($r+$r+$b+$g+$g+$g)/6;
$total_lum += $lum;
$sample_no++;
}
}
return (int) ( $total_lum / $sample_no );
} | [
"public",
"function",
"get_luminance",
"(",
"$",
"num_samples",
"=",
"10",
")",
"{",
"$",
"x_step",
"=",
"(",
"int",
")",
"$",
"this",
"->",
"width",
"/",
"$",
"num_samples",
";",
"$",
"y_step",
"=",
"(",
"int",
")",
"$",
"this",
"->",
"height",
"/",
"$",
"num_samples",
";",
"$",
"total_lum",
"=",
"0",
";",
"$",
"sample_no",
"=",
"1",
";",
"for",
"(",
"$",
"x",
"=",
"0",
";",
"$",
"x",
"<",
"$",
"this",
"->",
"width",
";",
"$",
"x",
"+=",
"$",
"x_step",
")",
"{",
"for",
"(",
"$",
"y",
"=",
"0",
";",
"$",
"y",
"<",
"$",
"this",
"->",
"height",
";",
"$",
"y",
"+=",
"$",
"y_step",
")",
"{",
"$",
"rgb",
"=",
"imagecolorat",
"(",
"$",
"this",
"->",
"image_context",
",",
"$",
"x",
",",
"$",
"y",
")",
";",
"$",
"r",
"=",
"(",
"$",
"rgb",
">>",
"16",
")",
"&",
"0xFF",
";",
"$",
"g",
"=",
"(",
"$",
"rgb",
">>",
"8",
")",
"&",
"0xFF",
";",
"$",
"b",
"=",
"$",
"rgb",
"&",
"0xFF",
";",
"$",
"lum",
"=",
"(",
"$",
"r",
"+",
"$",
"r",
"+",
"$",
"b",
"+",
"$",
"g",
"+",
"$",
"g",
"+",
"$",
"g",
")",
"/",
"6",
";",
"$",
"total_lum",
"+=",
"$",
"lum",
";",
"$",
"sample_no",
"++",
";",
"}",
"}",
"return",
"(",
"int",
")",
"(",
"$",
"total_lum",
"/",
"$",
"sample_no",
")",
";",
"}"
]
| Get the average luminance of the image
@param int $num_samples
@return int ( 1-255 )
@thanks to: http://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color | [
"Get",
"the",
"average",
"luminance",
"of",
"the",
"image"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCImage.php#L711-L736 |
18,820 | ClanCats/Core | src/classes/CCImage.php | CCImage.flip | function flip( $mode )
{
$width = $this->width;
$height = $this->height;
$src_x = 0;
$src_y = 0;
$src_width = $width;
$src_height = $height;
switch ( $mode )
{
case 'vertical':
$src_y = $height -1;
$src_height = -$height;
break;
case 'horizontal':
$src_x = $width -1;
$src_width = -$width;
break;
case 'both':
$src_x = $width -1;
$src_y = $height -1;
$src_width = -$width;
$src_height = -$height;
break;
}
$imgdest = imagecreatetruecolor( $width, $height );
if ( imagecopyresampled( $imgdest, $this->image_context, 0, 0, $src_x, $src_y , $width, $height, $src_width, $src_height ) )
{
$this->image_context = $imgdest;
}
return $this->image_context;
} | php | function flip( $mode )
{
$width = $this->width;
$height = $this->height;
$src_x = 0;
$src_y = 0;
$src_width = $width;
$src_height = $height;
switch ( $mode )
{
case 'vertical':
$src_y = $height -1;
$src_height = -$height;
break;
case 'horizontal':
$src_x = $width -1;
$src_width = -$width;
break;
case 'both':
$src_x = $width -1;
$src_y = $height -1;
$src_width = -$width;
$src_height = -$height;
break;
}
$imgdest = imagecreatetruecolor( $width, $height );
if ( imagecopyresampled( $imgdest, $this->image_context, 0, 0, $src_x, $src_y , $width, $height, $src_width, $src_height ) )
{
$this->image_context = $imgdest;
}
return $this->image_context;
} | [
"function",
"flip",
"(",
"$",
"mode",
")",
"{",
"$",
"width",
"=",
"$",
"this",
"->",
"width",
";",
"$",
"height",
"=",
"$",
"this",
"->",
"height",
";",
"$",
"src_x",
"=",
"0",
";",
"$",
"src_y",
"=",
"0",
";",
"$",
"src_width",
"=",
"$",
"width",
";",
"$",
"src_height",
"=",
"$",
"height",
";",
"switch",
"(",
"$",
"mode",
")",
"{",
"case",
"'vertical'",
":",
"$",
"src_y",
"=",
"$",
"height",
"-",
"1",
";",
"$",
"src_height",
"=",
"-",
"$",
"height",
";",
"break",
";",
"case",
"'horizontal'",
":",
"$",
"src_x",
"=",
"$",
"width",
"-",
"1",
";",
"$",
"src_width",
"=",
"-",
"$",
"width",
";",
"break",
";",
"case",
"'both'",
":",
"$",
"src_x",
"=",
"$",
"width",
"-",
"1",
";",
"$",
"src_y",
"=",
"$",
"height",
"-",
"1",
";",
"$",
"src_width",
"=",
"-",
"$",
"width",
";",
"$",
"src_height",
"=",
"-",
"$",
"height",
";",
"break",
";",
"}",
"$",
"imgdest",
"=",
"imagecreatetruecolor",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"if",
"(",
"imagecopyresampled",
"(",
"$",
"imgdest",
",",
"$",
"this",
"->",
"image_context",
",",
"0",
",",
"0",
",",
"$",
"src_x",
",",
"$",
"src_y",
",",
"$",
"width",
",",
"$",
"height",
",",
"$",
"src_width",
",",
"$",
"src_height",
")",
")",
"{",
"$",
"this",
"->",
"image_context",
"=",
"$",
"imgdest",
";",
"}",
"return",
"$",
"this",
"->",
"image_context",
";",
"}"
]
| Flip an image
@param string $mode vertical, horizontal, both
@return self | [
"Flip",
"an",
"image"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCImage.php#L744-L783 |
18,821 | kattsoftware/phassets | src/Phassets/Phassets.php | Phassets.work | public function work($file, $customFilters = null, $customDeployer = null)
{
// Create the Asset instance
foreach ($this->assetsSource as $source) {
if (is_file($source . DIRECTORY_SEPARATOR . $file)) {
$asset = $this->objectsFactory->buildAsset($source . DIRECTORY_SEPARATOR . $file);
}
}
if (!isset($asset)) {
$asset = $this->objectsFactory->buildAsset($file);
}
// Assemble the $filters array of fully qualified filters class names
if (is_array($customFilters)) {
$filters = $customFilters;
} else {
$ext = $asset->getExtension();
$filters = isset($this->filters[$ext]) ? $this->filters[$ext] : array();
}
// Decide which deployer will be used.
if (is_string($customDeployer)) {
$deployer = $customDeployer;
} else {
$deployer = $this->loadedDeployer;
}
// Is previously cached?
$cacheKey = $this->computeCacheKey($asset->getFullPath(), $filters, $deployer);
$cacheValue = $this->loadedCacheAdapter->get($cacheKey);
if ($cacheValue !== false) {
$asset->setOutputUrl($cacheValue);
return $asset;
}
// If there is any different extension, then set it first
$this->applyFilterOutputExtension($filters, $asset);
// Is previously deployed?
if (isset($this->deployersInstances[$deployer]) && $this->deployersInstances[$deployer]->isPreviouslyDeployed($asset)) {
// Cache the result
$cacheValue = $asset->getOutputUrl();
$this->loadedCacheAdapter->save($cacheKey, $cacheValue, $this->cacheTtl);
return $asset;
}
// Pass the asset through all filters.
$this->filterAsset($filters, $asset);
// All set! Let's deploy now.
$this->deployAsset($deployer, $asset);
// Cache the result
$cacheValue = $asset->getOutputUrl();
$this->loadedCacheAdapter->save($cacheKey, $cacheValue, $this->cacheTtl);
return $asset;
} | php | public function work($file, $customFilters = null, $customDeployer = null)
{
// Create the Asset instance
foreach ($this->assetsSource as $source) {
if (is_file($source . DIRECTORY_SEPARATOR . $file)) {
$asset = $this->objectsFactory->buildAsset($source . DIRECTORY_SEPARATOR . $file);
}
}
if (!isset($asset)) {
$asset = $this->objectsFactory->buildAsset($file);
}
// Assemble the $filters array of fully qualified filters class names
if (is_array($customFilters)) {
$filters = $customFilters;
} else {
$ext = $asset->getExtension();
$filters = isset($this->filters[$ext]) ? $this->filters[$ext] : array();
}
// Decide which deployer will be used.
if (is_string($customDeployer)) {
$deployer = $customDeployer;
} else {
$deployer = $this->loadedDeployer;
}
// Is previously cached?
$cacheKey = $this->computeCacheKey($asset->getFullPath(), $filters, $deployer);
$cacheValue = $this->loadedCacheAdapter->get($cacheKey);
if ($cacheValue !== false) {
$asset->setOutputUrl($cacheValue);
return $asset;
}
// If there is any different extension, then set it first
$this->applyFilterOutputExtension($filters, $asset);
// Is previously deployed?
if (isset($this->deployersInstances[$deployer]) && $this->deployersInstances[$deployer]->isPreviouslyDeployed($asset)) {
// Cache the result
$cacheValue = $asset->getOutputUrl();
$this->loadedCacheAdapter->save($cacheKey, $cacheValue, $this->cacheTtl);
return $asset;
}
// Pass the asset through all filters.
$this->filterAsset($filters, $asset);
// All set! Let's deploy now.
$this->deployAsset($deployer, $asset);
// Cache the result
$cacheValue = $asset->getOutputUrl();
$this->loadedCacheAdapter->save($cacheKey, $cacheValue, $this->cacheTtl);
return $asset;
} | [
"public",
"function",
"work",
"(",
"$",
"file",
",",
"$",
"customFilters",
"=",
"null",
",",
"$",
"customDeployer",
"=",
"null",
")",
"{",
"// Create the Asset instance",
"foreach",
"(",
"$",
"this",
"->",
"assetsSource",
"as",
"$",
"source",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"source",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
")",
")",
"{",
"$",
"asset",
"=",
"$",
"this",
"->",
"objectsFactory",
"->",
"buildAsset",
"(",
"$",
"source",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
")",
";",
"}",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"asset",
")",
")",
"{",
"$",
"asset",
"=",
"$",
"this",
"->",
"objectsFactory",
"->",
"buildAsset",
"(",
"$",
"file",
")",
";",
"}",
"// Assemble the $filters array of fully qualified filters class names",
"if",
"(",
"is_array",
"(",
"$",
"customFilters",
")",
")",
"{",
"$",
"filters",
"=",
"$",
"customFilters",
";",
"}",
"else",
"{",
"$",
"ext",
"=",
"$",
"asset",
"->",
"getExtension",
"(",
")",
";",
"$",
"filters",
"=",
"isset",
"(",
"$",
"this",
"->",
"filters",
"[",
"$",
"ext",
"]",
")",
"?",
"$",
"this",
"->",
"filters",
"[",
"$",
"ext",
"]",
":",
"array",
"(",
")",
";",
"}",
"// Decide which deployer will be used.",
"if",
"(",
"is_string",
"(",
"$",
"customDeployer",
")",
")",
"{",
"$",
"deployer",
"=",
"$",
"customDeployer",
";",
"}",
"else",
"{",
"$",
"deployer",
"=",
"$",
"this",
"->",
"loadedDeployer",
";",
"}",
"// Is previously cached?",
"$",
"cacheKey",
"=",
"$",
"this",
"->",
"computeCacheKey",
"(",
"$",
"asset",
"->",
"getFullPath",
"(",
")",
",",
"$",
"filters",
",",
"$",
"deployer",
")",
";",
"$",
"cacheValue",
"=",
"$",
"this",
"->",
"loadedCacheAdapter",
"->",
"get",
"(",
"$",
"cacheKey",
")",
";",
"if",
"(",
"$",
"cacheValue",
"!==",
"false",
")",
"{",
"$",
"asset",
"->",
"setOutputUrl",
"(",
"$",
"cacheValue",
")",
";",
"return",
"$",
"asset",
";",
"}",
"// If there is any different extension, then set it first",
"$",
"this",
"->",
"applyFilterOutputExtension",
"(",
"$",
"filters",
",",
"$",
"asset",
")",
";",
"// Is previously deployed?",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"deployersInstances",
"[",
"$",
"deployer",
"]",
")",
"&&",
"$",
"this",
"->",
"deployersInstances",
"[",
"$",
"deployer",
"]",
"->",
"isPreviouslyDeployed",
"(",
"$",
"asset",
")",
")",
"{",
"// Cache the result",
"$",
"cacheValue",
"=",
"$",
"asset",
"->",
"getOutputUrl",
"(",
")",
";",
"$",
"this",
"->",
"loadedCacheAdapter",
"->",
"save",
"(",
"$",
"cacheKey",
",",
"$",
"cacheValue",
",",
"$",
"this",
"->",
"cacheTtl",
")",
";",
"return",
"$",
"asset",
";",
"}",
"// Pass the asset through all filters.",
"$",
"this",
"->",
"filterAsset",
"(",
"$",
"filters",
",",
"$",
"asset",
")",
";",
"// All set! Let's deploy now.",
"$",
"this",
"->",
"deployAsset",
"(",
"$",
"deployer",
",",
"$",
"asset",
")",
";",
"// Cache the result",
"$",
"cacheValue",
"=",
"$",
"asset",
"->",
"getOutputUrl",
"(",
")",
";",
"$",
"this",
"->",
"loadedCacheAdapter",
"->",
"save",
"(",
"$",
"cacheKey",
",",
"$",
"cacheValue",
",",
"$",
"this",
"->",
"cacheTtl",
")",
";",
"return",
"$",
"asset",
";",
"}"
]
| Processes and deploys an asset and returns an Asset instance
with modified properties, according to used filters and deployers.
@param string $file file name to be searched through "assets_source"
@param null|array $customFilters Overrides "filter" setting
@param null|string $customDeployer Overrides the loaded deployer
@return Asset The created Asset instance | [
"Processes",
"and",
"deploys",
"an",
"asset",
"and",
"returns",
"an",
"Asset",
"instance",
"with",
"modified",
"properties",
"according",
"to",
"used",
"filters",
"and",
"deployers",
"."
]
| cc982cf1941eb5776287d64f027218bd4835ed2b | https://github.com/kattsoftware/phassets/blob/cc982cf1941eb5776287d64f027218bd4835ed2b/src/Phassets/Phassets.php#L163-L224 |
18,822 | kattsoftware/phassets | src/Phassets/Phassets.php | Phassets.deployAsset | private function deployAsset($deploy, Asset $asset)
{
if ($this->loadDeployer($deploy)) {
try {
$this->deployersInstances[$deploy]->deploy($asset);
} catch (PhassetsInternalException $e) {
$this->loadedLogger->error('An error occurred while deploying the asset: ' . $e);
}
}
} | php | private function deployAsset($deploy, Asset $asset)
{
if ($this->loadDeployer($deploy)) {
try {
$this->deployersInstances[$deploy]->deploy($asset);
} catch (PhassetsInternalException $e) {
$this->loadedLogger->error('An error occurred while deploying the asset: ' . $e);
}
}
} | [
"private",
"function",
"deployAsset",
"(",
"$",
"deploy",
",",
"Asset",
"$",
"asset",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"loadDeployer",
"(",
"$",
"deploy",
")",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"deployersInstances",
"[",
"$",
"deploy",
"]",
"->",
"deploy",
"(",
"$",
"asset",
")",
";",
"}",
"catch",
"(",
"PhassetsInternalException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"loadedLogger",
"->",
"error",
"(",
"'An error occurred while deploying the asset: '",
".",
"$",
"e",
")",
";",
"}",
"}",
"}"
]
| Tries to load a deployer and passes the Asset instance through it.
@param string $deploy Deployer to load/use
@param Asset $asset | [
"Tries",
"to",
"load",
"a",
"deployer",
"and",
"passes",
"the",
"Asset",
"instance",
"through",
"it",
"."
]
| cc982cf1941eb5776287d64f027218bd4835ed2b | https://github.com/kattsoftware/phassets/blob/cc982cf1941eb5776287d64f027218bd4835ed2b/src/Phassets/Phassets.php#L275-L284 |
18,823 | kattsoftware/phassets | src/Phassets/Phassets.php | Phassets.loadFilter | private function loadFilter($class)
{
if (isset($this->filtersInstances[$class])) {
return true;
}
$filter = $this->objectsFactory->buildFilter($class, $this->loadedConfigurator);
if ($filter === false) {
$this->loadedLogger->warning('Could not load ' . $class . ' filter.');
return false;
}
$this->filtersInstances[$class] = $filter;
$this->loadedLogger->debug('Filter ' . $class . ' found & loaded.');
return true;
} | php | private function loadFilter($class)
{
if (isset($this->filtersInstances[$class])) {
return true;
}
$filter = $this->objectsFactory->buildFilter($class, $this->loadedConfigurator);
if ($filter === false) {
$this->loadedLogger->warning('Could not load ' . $class . ' filter.');
return false;
}
$this->filtersInstances[$class] = $filter;
$this->loadedLogger->debug('Filter ' . $class . ' found & loaded.');
return true;
} | [
"private",
"function",
"loadFilter",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"filtersInstances",
"[",
"$",
"class",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"filter",
"=",
"$",
"this",
"->",
"objectsFactory",
"->",
"buildFilter",
"(",
"$",
"class",
",",
"$",
"this",
"->",
"loadedConfigurator",
")",
";",
"if",
"(",
"$",
"filter",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"loadedLogger",
"->",
"warning",
"(",
"'Could not load '",
".",
"$",
"class",
".",
"' filter.'",
")",
";",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"filtersInstances",
"[",
"$",
"class",
"]",
"=",
"$",
"filter",
";",
"$",
"this",
"->",
"loadedLogger",
"->",
"debug",
"(",
"'Filter '",
".",
"$",
"class",
".",
"' found & loaded.'",
")",
";",
"return",
"true",
";",
"}"
]
| Try to create & load an instance of a given Filter class name.
@param string $class
@return bool Whether the loading succeeded or not | [
"Try",
"to",
"create",
"&",
"load",
"an",
"instance",
"of",
"a",
"given",
"Filter",
"class",
"name",
"."
]
| cc982cf1941eb5776287d64f027218bd4835ed2b | https://github.com/kattsoftware/phassets/blob/cc982cf1941eb5776287d64f027218bd4835ed2b/src/Phassets/Phassets.php#L345-L363 |
18,824 | kattsoftware/phassets | src/Phassets/Phassets.php | Phassets.loadDeployer | private function loadDeployer($class)
{
if (isset($this->deployersInstances[$class])) {
return true;
}
$deployer = $this->objectsFactory->buildDeployer($class, $this->loadedConfigurator, $this->loadedCacheAdapter);
if ($deployer === false) {
$this->loadedLogger->warning('Could not load ' . $class . ' deployer.');
return false;
}
try {
$deployer->isSupported();
} catch (PhassetsInternalException $e) {
$this->loadedLogger->warning($class . ' deployer is not supported: ' . $e);
}
$this->deployersInstances[$class] = $deployer;
$this->loadedLogger->debug('Deployer ' . $class . ' found & loaded.');
return true;
} | php | private function loadDeployer($class)
{
if (isset($this->deployersInstances[$class])) {
return true;
}
$deployer = $this->objectsFactory->buildDeployer($class, $this->loadedConfigurator, $this->loadedCacheAdapter);
if ($deployer === false) {
$this->loadedLogger->warning('Could not load ' . $class . ' deployer.');
return false;
}
try {
$deployer->isSupported();
} catch (PhassetsInternalException $e) {
$this->loadedLogger->warning($class . ' deployer is not supported: ' . $e);
}
$this->deployersInstances[$class] = $deployer;
$this->loadedLogger->debug('Deployer ' . $class . ' found & loaded.');
return true;
} | [
"private",
"function",
"loadDeployer",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"deployersInstances",
"[",
"$",
"class",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"deployer",
"=",
"$",
"this",
"->",
"objectsFactory",
"->",
"buildDeployer",
"(",
"$",
"class",
",",
"$",
"this",
"->",
"loadedConfigurator",
",",
"$",
"this",
"->",
"loadedCacheAdapter",
")",
";",
"if",
"(",
"$",
"deployer",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"loadedLogger",
"->",
"warning",
"(",
"'Could not load '",
".",
"$",
"class",
".",
"' deployer.'",
")",
";",
"return",
"false",
";",
"}",
"try",
"{",
"$",
"deployer",
"->",
"isSupported",
"(",
")",
";",
"}",
"catch",
"(",
"PhassetsInternalException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"loadedLogger",
"->",
"warning",
"(",
"$",
"class",
".",
"' deployer is not supported: '",
".",
"$",
"e",
")",
";",
"}",
"$",
"this",
"->",
"deployersInstances",
"[",
"$",
"class",
"]",
"=",
"$",
"deployer",
";",
"$",
"this",
"->",
"loadedLogger",
"->",
"debug",
"(",
"'Deployer '",
".",
"$",
"class",
".",
"' found & loaded.'",
")",
";",
"return",
"true",
";",
"}"
]
| Try to create & load an instance of a given Deployer class name.
@param string $class
@return bool Whether the loading succeeded or not | [
"Try",
"to",
"create",
"&",
"load",
"an",
"instance",
"of",
"a",
"given",
"Deployer",
"class",
"name",
"."
]
| cc982cf1941eb5776287d64f027218bd4835ed2b | https://github.com/kattsoftware/phassets/blob/cc982cf1941eb5776287d64f027218bd4835ed2b/src/Phassets/Phassets.php#L371-L395 |
18,825 | kattsoftware/phassets | src/Phassets/Phassets.php | Phassets.loadAssetsManager | private function loadAssetsManager($class)
{
if (isset($this->assetsMergerInstances[$class])) {
return true;
}
$merger = $this->objectsFactory->buildAssetsMerger($class, $this->loadedConfigurator);
if ($merger === false) {
$this->loadedLogger->warning('Could not load ' . $class . ' merger.');
return false;
}
$this->assetsMergerInstances[$class] = $merger;
$this->loadedLogger->debug('Assets merger ' . $class . ' found & loaded.');
return true;
} | php | private function loadAssetsManager($class)
{
if (isset($this->assetsMergerInstances[$class])) {
return true;
}
$merger = $this->objectsFactory->buildAssetsMerger($class, $this->loadedConfigurator);
if ($merger === false) {
$this->loadedLogger->warning('Could not load ' . $class . ' merger.');
return false;
}
$this->assetsMergerInstances[$class] = $merger;
$this->loadedLogger->debug('Assets merger ' . $class . ' found & loaded.');
return true;
} | [
"private",
"function",
"loadAssetsManager",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"assetsMergerInstances",
"[",
"$",
"class",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"merger",
"=",
"$",
"this",
"->",
"objectsFactory",
"->",
"buildAssetsMerger",
"(",
"$",
"class",
",",
"$",
"this",
"->",
"loadedConfigurator",
")",
";",
"if",
"(",
"$",
"merger",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"loadedLogger",
"->",
"warning",
"(",
"'Could not load '",
".",
"$",
"class",
".",
"' merger.'",
")",
";",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"assetsMergerInstances",
"[",
"$",
"class",
"]",
"=",
"$",
"merger",
";",
"$",
"this",
"->",
"loadedLogger",
"->",
"debug",
"(",
"'Assets merger '",
".",
"$",
"class",
".",
"' found & loaded.'",
")",
";",
"return",
"true",
";",
"}"
]
| Try to create & load an instance of a given AssetsMerger class name.
@param string $class Fully qualified class name
@return bool Whether the loading succeeded or not | [
"Try",
"to",
"create",
"&",
"load",
"an",
"instance",
"of",
"a",
"given",
"AssetsMerger",
"class",
"name",
"."
]
| cc982cf1941eb5776287d64f027218bd4835ed2b | https://github.com/kattsoftware/phassets/blob/cc982cf1941eb5776287d64f027218bd4835ed2b/src/Phassets/Phassets.php#L403-L421 |
18,826 | webtown-php/KunstmaanExtensionBundle | src/Configuration/SearchableEntityConfiguration.php | SearchableEntityConfiguration.populateIndex | public function populateIndex()
{
$this->buildDocumentsByManager($this->doctrine);
if ($this->mongo) {
$this->buildDocumentsByManager($this->mongo);
}
if (!empty($this->documents)) {
$response = $this->searchProvider->addDocuments($this->documents);
$this->documents = [];
}
} | php | public function populateIndex()
{
$this->buildDocumentsByManager($this->doctrine);
if ($this->mongo) {
$this->buildDocumentsByManager($this->mongo);
}
if (!empty($this->documents)) {
$response = $this->searchProvider->addDocuments($this->documents);
$this->documents = [];
}
} | [
"public",
"function",
"populateIndex",
"(",
")",
"{",
"$",
"this",
"->",
"buildDocumentsByManager",
"(",
"$",
"this",
"->",
"doctrine",
")",
";",
"if",
"(",
"$",
"this",
"->",
"mongo",
")",
"{",
"$",
"this",
"->",
"buildDocumentsByManager",
"(",
"$",
"this",
"->",
"mongo",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"documents",
")",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"searchProvider",
"->",
"addDocuments",
"(",
"$",
"this",
"->",
"documents",
")",
";",
"$",
"this",
"->",
"documents",
"=",
"[",
"]",
";",
"}",
"}"
]
| Populate the indexes | [
"Populate",
"the",
"indexes"
]
| 86c656c131295fe1f3f7694fd4da1e5e454076b9 | https://github.com/webtown-php/KunstmaanExtensionBundle/blob/86c656c131295fe1f3f7694fd4da1e5e454076b9/src/Configuration/SearchableEntityConfiguration.php#L99-L111 |
18,827 | antonmedv/silicone | src/Silicone/Controller.php | Controller.render | protected function render($view, array $parameters = array(), Response $response = null)
{
return $this->app->render($view, $parameters, $response);
} | php | protected function render($view, array $parameters = array(), Response $response = null)
{
return $this->app->render($view, $parameters, $response);
} | [
"protected",
"function",
"render",
"(",
"$",
"view",
",",
"array",
"$",
"parameters",
"=",
"array",
"(",
")",
",",
"Response",
"$",
"response",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"app",
"->",
"render",
"(",
"$",
"view",
",",
"$",
"parameters",
",",
"$",
"response",
")",
";",
"}"
]
| Render to response twig views.
@param $view
@param array $parameters
@param Response $response
@return Response | [
"Render",
"to",
"response",
"twig",
"views",
"."
]
| e4a67ed41f0f419984df642b303f2a491c9a3933 | https://github.com/antonmedv/silicone/blob/e4a67ed41f0f419984df642b303f2a491c9a3933/src/Silicone/Controller.php#L40-L43 |
18,828 | drupalwxt/pco_cities | modules/custom/pco_cities_ext/challenge_pages/src/EventSubscriber/ChallengePagesRedirectSubscriber.php | ChallengePagesRedirectSubscriber.redirectMyContentTypeNode | public function redirectMyContentTypeNode(GetResponseEvent $event) {
$request = $event->getRequest();
$language = $this->languageManager->getCurrentLanguage()->getId();
if ($request->attributes->get('_route') !== 'entity.node.canonical') {
return;
}
if ($request->attributes->get('node')->getType() !== 'challenge') {
return;
}
// $redirect_url = Url::fromUri('entity:node/123');.
$node = $request->attributes->get('node');
if ($language == 'fr') {
$redirect_url = '/fr/defis/' . $node->getTranslation('fr')->get('field_friendly_url')->getValue()[0]['value'];
}
else {
$redirect_url = '/en/challenges/' . $node->get('field_friendly_url')->getValue()[0]['value'];
}
$response = new RedirectResponse($redirect_url, 301);
$event->setResponse($response);
} | php | public function redirectMyContentTypeNode(GetResponseEvent $event) {
$request = $event->getRequest();
$language = $this->languageManager->getCurrentLanguage()->getId();
if ($request->attributes->get('_route') !== 'entity.node.canonical') {
return;
}
if ($request->attributes->get('node')->getType() !== 'challenge') {
return;
}
// $redirect_url = Url::fromUri('entity:node/123');.
$node = $request->attributes->get('node');
if ($language == 'fr') {
$redirect_url = '/fr/defis/' . $node->getTranslation('fr')->get('field_friendly_url')->getValue()[0]['value'];
}
else {
$redirect_url = '/en/challenges/' . $node->get('field_friendly_url')->getValue()[0]['value'];
}
$response = new RedirectResponse($redirect_url, 301);
$event->setResponse($response);
} | [
"public",
"function",
"redirectMyContentTypeNode",
"(",
"GetResponseEvent",
"$",
"event",
")",
"{",
"$",
"request",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
";",
"$",
"language",
"=",
"$",
"this",
"->",
"languageManager",
"->",
"getCurrentLanguage",
"(",
")",
"->",
"getId",
"(",
")",
";",
"if",
"(",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'_route'",
")",
"!==",
"'entity.node.canonical'",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'node'",
")",
"->",
"getType",
"(",
")",
"!==",
"'challenge'",
")",
"{",
"return",
";",
"}",
"// $redirect_url = Url::fromUri('entity:node/123');.",
"$",
"node",
"=",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'node'",
")",
";",
"if",
"(",
"$",
"language",
"==",
"'fr'",
")",
"{",
"$",
"redirect_url",
"=",
"'/fr/defis/'",
".",
"$",
"node",
"->",
"getTranslation",
"(",
"'fr'",
")",
"->",
"get",
"(",
"'field_friendly_url'",
")",
"->",
"getValue",
"(",
")",
"[",
"0",
"]",
"[",
"'value'",
"]",
";",
"}",
"else",
"{",
"$",
"redirect_url",
"=",
"'/en/challenges/'",
".",
"$",
"node",
"->",
"get",
"(",
"'field_friendly_url'",
")",
"->",
"getValue",
"(",
")",
"[",
"0",
"]",
"[",
"'value'",
"]",
";",
"}",
"$",
"response",
"=",
"new",
"RedirectResponse",
"(",
"$",
"redirect_url",
",",
"301",
")",
";",
"$",
"event",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"}"
]
| Redirect requests for challenge go to custom module controller route.
@param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event | [
"Redirect",
"requests",
"for",
"challenge",
"go",
"to",
"custom",
"module",
"controller",
"route",
"."
]
| 589651ac4478ce629dd9ad9cf2e15ad1a9de368a | https://github.com/drupalwxt/pco_cities/blob/589651ac4478ce629dd9ad9cf2e15ad1a9de368a/modules/custom/pco_cities_ext/challenge_pages/src/EventSubscriber/ChallengePagesRedirectSubscriber.php#L50-L73 |
18,829 | webforge-labs/psc-cms | lib/Psc/Net/HTTP/Request.php | Request.setBody | public function setBody($body) {
if (is_array($body) || is_object($body))
$this->body = (object) $body;
else
$this->body = $body;
return $this;
} | php | public function setBody($body) {
if (is_array($body) || is_object($body))
$this->body = (object) $body;
else
$this->body = $body;
return $this;
} | [
"public",
"function",
"setBody",
"(",
"$",
"body",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"body",
")",
"||",
"is_object",
"(",
"$",
"body",
")",
")",
"$",
"this",
"->",
"body",
"=",
"(",
"object",
")",
"$",
"body",
";",
"else",
"$",
"this",
"->",
"body",
"=",
"$",
"body",
";",
"return",
"$",
"this",
";",
"}"
]
| Setzt den RequestBody
wird intern als stdClass umgewandelt, wenn es object oder array ist | [
"Setzt",
"den",
"RequestBody"
]
| 467bfa2547e6b4fa487d2d7f35fa6cc618dbc763 | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Net/HTTP/Request.php#L266-L272 |
18,830 | digitalkaoz/versioneye-php | src/Output/Me.php | Me.profile | public function profile(OutputInterface $output, array $response)
{
$this->printList($output,
['Fullname', 'Username', 'Email', 'Admin', 'Notifications'],
['fullname', 'username', 'email', 'admin', 'notifications'],
$response,
function ($key, $value) {
if ('Notifications' !== $key) {
return $value;
}
return sprintf('%d / %d', $value['new'], $value['total']);
}
);
} | php | public function profile(OutputInterface $output, array $response)
{
$this->printList($output,
['Fullname', 'Username', 'Email', 'Admin', 'Notifications'],
['fullname', 'username', 'email', 'admin', 'notifications'],
$response,
function ($key, $value) {
if ('Notifications' !== $key) {
return $value;
}
return sprintf('%d / %d', $value['new'], $value['total']);
}
);
} | [
"public",
"function",
"profile",
"(",
"OutputInterface",
"$",
"output",
",",
"array",
"$",
"response",
")",
"{",
"$",
"this",
"->",
"printList",
"(",
"$",
"output",
",",
"[",
"'Fullname'",
",",
"'Username'",
",",
"'Email'",
",",
"'Admin'",
",",
"'Notifications'",
"]",
",",
"[",
"'fullname'",
",",
"'username'",
",",
"'email'",
",",
"'admin'",
",",
"'notifications'",
"]",
",",
"$",
"response",
",",
"function",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"'Notifications'",
"!==",
"$",
"key",
")",
"{",
"return",
"$",
"value",
";",
"}",
"return",
"sprintf",
"(",
"'%d / %d'",
",",
"$",
"value",
"[",
"'new'",
"]",
",",
"$",
"value",
"[",
"'total'",
"]",
")",
";",
"}",
")",
";",
"}"
]
| output for the profile api.
@param OutputInterface $output
@param array $response | [
"output",
"for",
"the",
"profile",
"api",
"."
]
| 7b8eb9cdc83e01138dda0e709c07e3beb6aad136 | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Output/Me.php#L20-L34 |
18,831 | digitalkaoz/versioneye-php | src/Output/Me.php | Me.comments | public function comments(OutputInterface $output, array $response)
{
$table = $this->createTable($output);
$table->setHeaders(['Name', 'Language', 'Version', 'Type', 'Date', 'Comment']);
foreach ($response['comments'] as $comment) {
$table->addRow([$comment['product']['name'], $comment['product']['language'], $comment['product']['version'], $comment['product']['prod_type'], $comment['created_at'], $comment['comment']]);
}
$table->render($output);
} | php | public function comments(OutputInterface $output, array $response)
{
$table = $this->createTable($output);
$table->setHeaders(['Name', 'Language', 'Version', 'Type', 'Date', 'Comment']);
foreach ($response['comments'] as $comment) {
$table->addRow([$comment['product']['name'], $comment['product']['language'], $comment['product']['version'], $comment['product']['prod_type'], $comment['created_at'], $comment['comment']]);
}
$table->render($output);
} | [
"public",
"function",
"comments",
"(",
"OutputInterface",
"$",
"output",
",",
"array",
"$",
"response",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"createTable",
"(",
"$",
"output",
")",
";",
"$",
"table",
"->",
"setHeaders",
"(",
"[",
"'Name'",
",",
"'Language'",
",",
"'Version'",
",",
"'Type'",
",",
"'Date'",
",",
"'Comment'",
"]",
")",
";",
"foreach",
"(",
"$",
"response",
"[",
"'comments'",
"]",
"as",
"$",
"comment",
")",
"{",
"$",
"table",
"->",
"addRow",
"(",
"[",
"$",
"comment",
"[",
"'product'",
"]",
"[",
"'name'",
"]",
",",
"$",
"comment",
"[",
"'product'",
"]",
"[",
"'language'",
"]",
",",
"$",
"comment",
"[",
"'product'",
"]",
"[",
"'version'",
"]",
",",
"$",
"comment",
"[",
"'product'",
"]",
"[",
"'prod_type'",
"]",
",",
"$",
"comment",
"[",
"'created_at'",
"]",
",",
"$",
"comment",
"[",
"'comment'",
"]",
"]",
")",
";",
"}",
"$",
"table",
"->",
"render",
"(",
"$",
"output",
")",
";",
"}"
]
| output for the comments api.
@param OutputInterface $output
@param array $response | [
"output",
"for",
"the",
"comments",
"api",
"."
]
| 7b8eb9cdc83e01138dda0e709c07e3beb6aad136 | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Output/Me.php#L64-L75 |
18,832 | webforge-labs/psc-cms | lib/Psc/HTML/Page.php | Page.setMeta | public function setMeta($name, $content = NULL, $httpEquiv = FALSE, $scheme = NULL) {
$meta = HTML::Tag('meta');
$meta->setOption('selfClosing',TRUE);
if ($content === NULL) {
/* löschen */
$this->removeMeta($name);
} else {
/* im W3C steht "may be used in place" ... d.h. man könnte auch name und http-equiv gleichzeitig benutzen
http://www.w3.org/TR/html4/struct/global.html#edef-META
*/
if (isset($name)) {
if (!$httpEquiv)
$meta->setAttribute('name',$name);
else
$meta->setAttribute('http-equiv',$name);
}
if (isset($scheme))
$meta->setAttribute('scheme',$scheme);
if ($content !== FALSE) {
$meta->setAttribute('content',$content);
}
/* meta tags liegen im head in der root ebene, d.h. wir suchen ob es dort schon ein meta tag gibt,
wenn es eins gibt ersetzen wir dies, ansonsten fügen wir es hinzu
*/
/* schlüssel des meta tags suchen (wenn vorhanden) */
$key = NULL;
foreach ($this->head->content as $itemKey => $item) {
if ($item instanceof Tag && $item->getTag() == 'meta' && ($item->getAttribute('name') == $name || $item->getAttribute('http-equiv') == $name)) {
$key = $itemKey;
break;
}
}
if ($key !== NULL) {
$this->head->content[$key] =& $meta;
} else {
$this->head->content[] =& $meta;
}
}
return $meta;
} | php | public function setMeta($name, $content = NULL, $httpEquiv = FALSE, $scheme = NULL) {
$meta = HTML::Tag('meta');
$meta->setOption('selfClosing',TRUE);
if ($content === NULL) {
/* löschen */
$this->removeMeta($name);
} else {
/* im W3C steht "may be used in place" ... d.h. man könnte auch name und http-equiv gleichzeitig benutzen
http://www.w3.org/TR/html4/struct/global.html#edef-META
*/
if (isset($name)) {
if (!$httpEquiv)
$meta->setAttribute('name',$name);
else
$meta->setAttribute('http-equiv',$name);
}
if (isset($scheme))
$meta->setAttribute('scheme',$scheme);
if ($content !== FALSE) {
$meta->setAttribute('content',$content);
}
/* meta tags liegen im head in der root ebene, d.h. wir suchen ob es dort schon ein meta tag gibt,
wenn es eins gibt ersetzen wir dies, ansonsten fügen wir es hinzu
*/
/* schlüssel des meta tags suchen (wenn vorhanden) */
$key = NULL;
foreach ($this->head->content as $itemKey => $item) {
if ($item instanceof Tag && $item->getTag() == 'meta' && ($item->getAttribute('name') == $name || $item->getAttribute('http-equiv') == $name)) {
$key = $itemKey;
break;
}
}
if ($key !== NULL) {
$this->head->content[$key] =& $meta;
} else {
$this->head->content[] =& $meta;
}
}
return $meta;
} | [
"public",
"function",
"setMeta",
"(",
"$",
"name",
",",
"$",
"content",
"=",
"NULL",
",",
"$",
"httpEquiv",
"=",
"FALSE",
",",
"$",
"scheme",
"=",
"NULL",
")",
"{",
"$",
"meta",
"=",
"HTML",
"::",
"Tag",
"(",
"'meta'",
")",
";",
"$",
"meta",
"->",
"setOption",
"(",
"'selfClosing'",
",",
"TRUE",
")",
";",
"if",
"(",
"$",
"content",
"===",
"NULL",
")",
"{",
"/* löschen */",
"$",
"this",
"->",
"removeMeta",
"(",
"$",
"name",
")",
";",
"}",
"else",
"{",
"/* im W3C steht \"may be used in place\" ... d.h. man könnte auch name und http-equiv gleichzeitig benutzen \n http://www.w3.org/TR/html4/struct/global.html#edef-META\n */",
"if",
"(",
"isset",
"(",
"$",
"name",
")",
")",
"{",
"if",
"(",
"!",
"$",
"httpEquiv",
")",
"$",
"meta",
"->",
"setAttribute",
"(",
"'name'",
",",
"$",
"name",
")",
";",
"else",
"$",
"meta",
"->",
"setAttribute",
"(",
"'http-equiv'",
",",
"$",
"name",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"scheme",
")",
")",
"$",
"meta",
"->",
"setAttribute",
"(",
"'scheme'",
",",
"$",
"scheme",
")",
";",
"if",
"(",
"$",
"content",
"!==",
"FALSE",
")",
"{",
"$",
"meta",
"->",
"setAttribute",
"(",
"'content'",
",",
"$",
"content",
")",
";",
"}",
"/* meta tags liegen im head in der root ebene, d.h. wir suchen ob es dort schon ein meta tag gibt,\n wenn es eins gibt ersetzen wir dies, ansonsten fügen wir es hinzu \n */",
"/* schlüssel des meta tags suchen (wenn vorhanden) */",
"$",
"key",
"=",
"NULL",
";",
"foreach",
"(",
"$",
"this",
"->",
"head",
"->",
"content",
"as",
"$",
"itemKey",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"instanceof",
"Tag",
"&&",
"$",
"item",
"->",
"getTag",
"(",
")",
"==",
"'meta'",
"&&",
"(",
"$",
"item",
"->",
"getAttribute",
"(",
"'name'",
")",
"==",
"$",
"name",
"||",
"$",
"item",
"->",
"getAttribute",
"(",
"'http-equiv'",
")",
"==",
"$",
"name",
")",
")",
"{",
"$",
"key",
"=",
"$",
"itemKey",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"key",
"!==",
"NULL",
")",
"{",
"$",
"this",
"->",
"head",
"->",
"content",
"[",
"$",
"key",
"]",
"=",
"&",
"$",
"meta",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"head",
"->",
"content",
"[",
"]",
"=",
"&",
"$",
"meta",
";",
"}",
"}",
"return",
"$",
"meta",
";",
"}"
]
| Setzt ein Meta Attribut
wird <var>$content</var> leer gelassen oder auf NULL gesetzt, wird das Meta Attribut gelöscht
@param string $name der Name des Meta Attributes
@param string $content der Wert des Meta Attributes
@return Tag<meta> | [
"Setzt",
"ein",
"Meta",
"Attribut"
]
| 467bfa2547e6b4fa487d2d7f35fa6cc618dbc763 | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/HTML/Page.php#L146-L192 |
18,833 | webforge-labs/psc-cms | lib/Psc/Form/StandardValidatorRule.php | StandardValidatorRule.validate | public function validate($data) {
if (isset($this->callback)) {
return $this->callback->call(array($data));
}
throw new \Psc\Exception('empty rule!');
} | php | public function validate($data) {
if (isset($this->callback)) {
return $this->callback->call(array($data));
}
throw new \Psc\Exception('empty rule!');
} | [
"public",
"function",
"validate",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"callback",
")",
")",
"{",
"return",
"$",
"this",
"->",
"callback",
"->",
"call",
"(",
"array",
"(",
"$",
"data",
")",
")",
";",
"}",
"throw",
"new",
"\\",
"Psc",
"\\",
"Exception",
"(",
"'empty rule!'",
")",
";",
"}"
]
| Validiert die gespeicherte Rule
Achtung! nicht bool zurückgeben, stattdessen irgendeine Exception schmeissen
@return $data | [
"Validiert",
"die",
"gespeicherte",
"Rule"
]
| 467bfa2547e6b4fa487d2d7f35fa6cc618dbc763 | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Form/StandardValidatorRule.php#L85-L91 |
18,834 | Lansoweb/LosBase | src/LosBase/Controller/ORM/AbstractCrudController.php | AbstractCrudController.getForm | public function getForm($entityClass = null)
{
if (null === $entityClass) {
$entityClass = $this->getEntityClass();
}
$builder = new AnnotationBuilder();
$form = $builder->createForm($entityClass);
$hasEntity = false;
foreach ($form->getElements() as $element) {
if (method_exists($element, 'setObjectManager')) {
$element->setObjectManager($this->getEntityManager());
$hasEntity = true;
} elseif (method_exists($element, 'getProxy')) {
$proxy = $element->getProxy();
if (method_exists($proxy, 'setObjectManager')) {
$proxy->setObjectManager($this->getEntityManager());
$hasEntity = true;
}
}
}
if ($hasEntity) {
$hydrator = new DoctrineHydrator($this->getEntityManager(), $entityClass);
$form->setHydrator($hydrator);
} else {
$form->setHydrator(new ClassMethods());
}
$form->add([
'type' => 'Zend\Form\Element\Csrf',
'name' => 'csrf',
'attributes' => [
'id' => 'csrf',
],
]);
$submitElement = new \Zend\Form\Element\Button('submit');
$submitElement->setAttributes([
'type' => 'submit',
'class' => 'btn btn-primary',
]);
$submitElement->setLabel('Salvar');
$form->add($submitElement, [
'priority' => -100,
]);
$cancelarElement = new \Zend\Form\Element\Button('cancelar');
$cancelarElement->setAttributes([
'type' => 'button',
'class' => 'btn btn-default',
'onclick' => 'top.location=\''.$this->url()
->fromRoute($this->getActionRoute('list')).'\'',
]);
$cancelarElement->setLabel('Cancelar');
$form->add($cancelarElement, [
'priority' => -100,
]);
return $form;
} | php | public function getForm($entityClass = null)
{
if (null === $entityClass) {
$entityClass = $this->getEntityClass();
}
$builder = new AnnotationBuilder();
$form = $builder->createForm($entityClass);
$hasEntity = false;
foreach ($form->getElements() as $element) {
if (method_exists($element, 'setObjectManager')) {
$element->setObjectManager($this->getEntityManager());
$hasEntity = true;
} elseif (method_exists($element, 'getProxy')) {
$proxy = $element->getProxy();
if (method_exists($proxy, 'setObjectManager')) {
$proxy->setObjectManager($this->getEntityManager());
$hasEntity = true;
}
}
}
if ($hasEntity) {
$hydrator = new DoctrineHydrator($this->getEntityManager(), $entityClass);
$form->setHydrator($hydrator);
} else {
$form->setHydrator(new ClassMethods());
}
$form->add([
'type' => 'Zend\Form\Element\Csrf',
'name' => 'csrf',
'attributes' => [
'id' => 'csrf',
],
]);
$submitElement = new \Zend\Form\Element\Button('submit');
$submitElement->setAttributes([
'type' => 'submit',
'class' => 'btn btn-primary',
]);
$submitElement->setLabel('Salvar');
$form->add($submitElement, [
'priority' => -100,
]);
$cancelarElement = new \Zend\Form\Element\Button('cancelar');
$cancelarElement->setAttributes([
'type' => 'button',
'class' => 'btn btn-default',
'onclick' => 'top.location=\''.$this->url()
->fromRoute($this->getActionRoute('list')).'\'',
]);
$cancelarElement->setLabel('Cancelar');
$form->add($cancelarElement, [
'priority' => -100,
]);
return $form;
} | [
"public",
"function",
"getForm",
"(",
"$",
"entityClass",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"entityClass",
")",
"{",
"$",
"entityClass",
"=",
"$",
"this",
"->",
"getEntityClass",
"(",
")",
";",
"}",
"$",
"builder",
"=",
"new",
"AnnotationBuilder",
"(",
")",
";",
"$",
"form",
"=",
"$",
"builder",
"->",
"createForm",
"(",
"$",
"entityClass",
")",
";",
"$",
"hasEntity",
"=",
"false",
";",
"foreach",
"(",
"$",
"form",
"->",
"getElements",
"(",
")",
"as",
"$",
"element",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"element",
",",
"'setObjectManager'",
")",
")",
"{",
"$",
"element",
"->",
"setObjectManager",
"(",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
")",
";",
"$",
"hasEntity",
"=",
"true",
";",
"}",
"elseif",
"(",
"method_exists",
"(",
"$",
"element",
",",
"'getProxy'",
")",
")",
"{",
"$",
"proxy",
"=",
"$",
"element",
"->",
"getProxy",
"(",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"proxy",
",",
"'setObjectManager'",
")",
")",
"{",
"$",
"proxy",
"->",
"setObjectManager",
"(",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
")",
";",
"$",
"hasEntity",
"=",
"true",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"hasEntity",
")",
"{",
"$",
"hydrator",
"=",
"new",
"DoctrineHydrator",
"(",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
",",
"$",
"entityClass",
")",
";",
"$",
"form",
"->",
"setHydrator",
"(",
"$",
"hydrator",
")",
";",
"}",
"else",
"{",
"$",
"form",
"->",
"setHydrator",
"(",
"new",
"ClassMethods",
"(",
")",
")",
";",
"}",
"$",
"form",
"->",
"add",
"(",
"[",
"'type'",
"=>",
"'Zend\\Form\\Element\\Csrf'",
",",
"'name'",
"=>",
"'csrf'",
",",
"'attributes'",
"=>",
"[",
"'id'",
"=>",
"'csrf'",
",",
"]",
",",
"]",
")",
";",
"$",
"submitElement",
"=",
"new",
"\\",
"Zend",
"\\",
"Form",
"\\",
"Element",
"\\",
"Button",
"(",
"'submit'",
")",
";",
"$",
"submitElement",
"->",
"setAttributes",
"(",
"[",
"'type'",
"=>",
"'submit'",
",",
"'class'",
"=>",
"'btn btn-primary'",
",",
"]",
")",
";",
"$",
"submitElement",
"->",
"setLabel",
"(",
"'Salvar'",
")",
";",
"$",
"form",
"->",
"add",
"(",
"$",
"submitElement",
",",
"[",
"'priority'",
"=>",
"-",
"100",
",",
"]",
")",
";",
"$",
"cancelarElement",
"=",
"new",
"\\",
"Zend",
"\\",
"Form",
"\\",
"Element",
"\\",
"Button",
"(",
"'cancelar'",
")",
";",
"$",
"cancelarElement",
"->",
"setAttributes",
"(",
"[",
"'type'",
"=>",
"'button'",
",",
"'class'",
"=>",
"'btn btn-default'",
",",
"'onclick'",
"=>",
"'top.location=\\''",
".",
"$",
"this",
"->",
"url",
"(",
")",
"->",
"fromRoute",
"(",
"$",
"this",
"->",
"getActionRoute",
"(",
"'list'",
")",
")",
".",
"'\\''",
",",
"]",
")",
";",
"$",
"cancelarElement",
"->",
"setLabel",
"(",
"'Cancelar'",
")",
";",
"$",
"form",
"->",
"add",
"(",
"$",
"cancelarElement",
",",
"[",
"'priority'",
"=>",
"-",
"100",
",",
"]",
")",
";",
"return",
"$",
"form",
";",
"}"
]
| Retorna a form para o cadastro da entidade. | [
"Retorna",
"a",
"form",
"para",
"o",
"cadastro",
"da",
"entidade",
"."
]
| 90e18a53d29c1bd841c149dca43aa365eecc656d | https://github.com/Lansoweb/LosBase/blob/90e18a53d29c1bd841c149dca43aa365eecc656d/src/LosBase/Controller/ORM/AbstractCrudController.php#L136-L197 |
18,835 | Sedona-Solutions/sedona-sbo | src/Sedona/SBORuntimeBundle/Datatable/Data/DatatableDataManager.php | DatatableDataManager.getQueryFrom | public function getQueryFrom(DatatableViewInterface $datatableView)
{
$twig = $datatableView->getTwig();
$type = $datatableView->getAjax()->getType();
$parameterBag = null;
if ('GET' === strtoupper($type)) {
$parameterBag = $this->request->query;
}
if ('POST' === strtoupper($type)) {
$parameterBag = $this->request->request;
}
$params = $parameterBag->all();
$query = new DatatableQuery(
$this->serializer,
$params,
$datatableView,
$this->configs,
$twig,
$this->imagineBundle,
$this->doctrineExtensions,
$this->locale
);
return $query;
} | php | public function getQueryFrom(DatatableViewInterface $datatableView)
{
$twig = $datatableView->getTwig();
$type = $datatableView->getAjax()->getType();
$parameterBag = null;
if ('GET' === strtoupper($type)) {
$parameterBag = $this->request->query;
}
if ('POST' === strtoupper($type)) {
$parameterBag = $this->request->request;
}
$params = $parameterBag->all();
$query = new DatatableQuery(
$this->serializer,
$params,
$datatableView,
$this->configs,
$twig,
$this->imagineBundle,
$this->doctrineExtensions,
$this->locale
);
return $query;
} | [
"public",
"function",
"getQueryFrom",
"(",
"DatatableViewInterface",
"$",
"datatableView",
")",
"{",
"$",
"twig",
"=",
"$",
"datatableView",
"->",
"getTwig",
"(",
")",
";",
"$",
"type",
"=",
"$",
"datatableView",
"->",
"getAjax",
"(",
")",
"->",
"getType",
"(",
")",
";",
"$",
"parameterBag",
"=",
"null",
";",
"if",
"(",
"'GET'",
"===",
"strtoupper",
"(",
"$",
"type",
")",
")",
"{",
"$",
"parameterBag",
"=",
"$",
"this",
"->",
"request",
"->",
"query",
";",
"}",
"if",
"(",
"'POST'",
"===",
"strtoupper",
"(",
"$",
"type",
")",
")",
"{",
"$",
"parameterBag",
"=",
"$",
"this",
"->",
"request",
"->",
"request",
";",
"}",
"$",
"params",
"=",
"$",
"parameterBag",
"->",
"all",
"(",
")",
";",
"$",
"query",
"=",
"new",
"DatatableQuery",
"(",
"$",
"this",
"->",
"serializer",
",",
"$",
"params",
",",
"$",
"datatableView",
",",
"$",
"this",
"->",
"configs",
",",
"$",
"twig",
",",
"$",
"this",
"->",
"imagineBundle",
",",
"$",
"this",
"->",
"doctrineExtensions",
",",
"$",
"this",
"->",
"locale",
")",
";",
"return",
"$",
"query",
";",
"}"
]
| Get query.
@param DatatableViewInterface $datatableView
@return DatatableQuery | [
"Get",
"query",
"."
]
| 8548be4170d191cb1a3e263577aaaab49f04d5ce | https://github.com/Sedona-Solutions/sedona-sbo/blob/8548be4170d191cb1a3e263577aaaab49f04d5ce/src/Sedona/SBORuntimeBundle/Datatable/Data/DatatableDataManager.php#L109-L137 |
18,836 | slashworks/control-bundle | src/Slashworks/AppBundle/Model/om/BaseUserCustomerRelationQuery.php | BaseUserCustomerRelationQuery.create | public static function create($modelAlias = null, $criteria = null)
{
if ($criteria instanceof UserCustomerRelationQuery) {
return $criteria;
}
$query = new UserCustomerRelationQuery(null, null, $modelAlias);
if ($criteria instanceof Criteria) {
$query->mergeWith($criteria);
}
return $query;
} | php | public static function create($modelAlias = null, $criteria = null)
{
if ($criteria instanceof UserCustomerRelationQuery) {
return $criteria;
}
$query = new UserCustomerRelationQuery(null, null, $modelAlias);
if ($criteria instanceof Criteria) {
$query->mergeWith($criteria);
}
return $query;
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"modelAlias",
"=",
"null",
",",
"$",
"criteria",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"criteria",
"instanceof",
"UserCustomerRelationQuery",
")",
"{",
"return",
"$",
"criteria",
";",
"}",
"$",
"query",
"=",
"new",
"UserCustomerRelationQuery",
"(",
"null",
",",
"null",
",",
"$",
"modelAlias",
")",
";",
"if",
"(",
"$",
"criteria",
"instanceof",
"Criteria",
")",
"{",
"$",
"query",
"->",
"mergeWith",
"(",
"$",
"criteria",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
]
| Returns a new UserCustomerRelationQuery object.
@param string $modelAlias The alias of a model in the query
@param UserCustomerRelationQuery|Criteria $criteria Optional Criteria to build the query from
@return UserCustomerRelationQuery | [
"Returns",
"a",
"new",
"UserCustomerRelationQuery",
"object",
"."
]
| 2ba86d96f1f41f9424e2229c4e2b13017e973f89 | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseUserCustomerRelationQuery.php#L80-L92 |
18,837 | slashworks/control-bundle | src/Slashworks/AppBundle/Model/om/BaseUserCustomerRelationQuery.php | BaseUserCustomerRelationQuery.filterByUser | public function filterByUser($user, $comparison = null)
{
if ($user instanceof User) {
return $this
->addUsingAlias(UserCustomerRelationPeer::USER_ID, $user->getId(), $comparison);
} elseif ($user instanceof PropelObjectCollection) {
if (null === $comparison) {
$comparison = Criteria::IN;
}
return $this
->addUsingAlias(UserCustomerRelationPeer::USER_ID, $user->toKeyValue('PrimaryKey', 'Id'), $comparison);
} else {
throw new PropelException('filterByUser() only accepts arguments of type User or PropelCollection');
}
} | php | public function filterByUser($user, $comparison = null)
{
if ($user instanceof User) {
return $this
->addUsingAlias(UserCustomerRelationPeer::USER_ID, $user->getId(), $comparison);
} elseif ($user instanceof PropelObjectCollection) {
if (null === $comparison) {
$comparison = Criteria::IN;
}
return $this
->addUsingAlias(UserCustomerRelationPeer::USER_ID, $user->toKeyValue('PrimaryKey', 'Id'), $comparison);
} else {
throw new PropelException('filterByUser() only accepts arguments of type User or PropelCollection');
}
} | [
"public",
"function",
"filterByUser",
"(",
"$",
"user",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"user",
"instanceof",
"User",
")",
"{",
"return",
"$",
"this",
"->",
"addUsingAlias",
"(",
"UserCustomerRelationPeer",
"::",
"USER_ID",
",",
"$",
"user",
"->",
"getId",
"(",
")",
",",
"$",
"comparison",
")",
";",
"}",
"elseif",
"(",
"$",
"user",
"instanceof",
"PropelObjectCollection",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"comparison",
")",
"{",
"$",
"comparison",
"=",
"Criteria",
"::",
"IN",
";",
"}",
"return",
"$",
"this",
"->",
"addUsingAlias",
"(",
"UserCustomerRelationPeer",
"::",
"USER_ID",
",",
"$",
"user",
"->",
"toKeyValue",
"(",
"'PrimaryKey'",
",",
"'Id'",
")",
",",
"$",
"comparison",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"PropelException",
"(",
"'filterByUser() only accepts arguments of type User or PropelCollection'",
")",
";",
"}",
"}"
]
| Filter the query by a related User object
@param User|PropelObjectCollection $user The related object(s) to use as filter
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return UserCustomerRelationQuery The current query, for fluid interface
@throws PropelException - if the provided filter is invalid. | [
"Filter",
"the",
"query",
"by",
"a",
"related",
"User",
"object"
]
| 2ba86d96f1f41f9424e2229c4e2b13017e973f89 | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseUserCustomerRelationQuery.php#L384-L399 |
18,838 | ClanCats/Core | src/bundles/UI/Alert.php | Alert.prepare | private static function prepare( $type, $message )
{
// to avoid typos and other mistakes we
// validate the alert type
$type = strtolower( $type );
if ( !in_array( $type, static::$_types ) )
{
throw new Exception( "UI\Alert - Unknown alert type '{$type}'!" );
}
// We always need to return an array
if ( !is_array( $message ) )
{
return array( $message );
}
return $message;
} | php | private static function prepare( $type, $message )
{
// to avoid typos and other mistakes we
// validate the alert type
$type = strtolower( $type );
if ( !in_array( $type, static::$_types ) )
{
throw new Exception( "UI\Alert - Unknown alert type '{$type}'!" );
}
// We always need to return an array
if ( !is_array( $message ) )
{
return array( $message );
}
return $message;
} | [
"private",
"static",
"function",
"prepare",
"(",
"$",
"type",
",",
"$",
"message",
")",
"{",
"// to avoid typos and other mistakes we ",
"// validate the alert type",
"$",
"type",
"=",
"strtolower",
"(",
"$",
"type",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"type",
",",
"static",
"::",
"$",
"_types",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"UI\\Alert - Unknown alert type '{$type}'!\"",
")",
";",
"}",
"// We always need to return an array",
"if",
"(",
"!",
"is_array",
"(",
"$",
"message",
")",
")",
"{",
"return",
"array",
"(",
"$",
"message",
")",
";",
"}",
"return",
"$",
"message",
";",
"}"
]
| Validate the alert type and format the message
@param string $type
@param string|array $message
@return array | [
"Validate",
"the",
"alert",
"type",
"and",
"format",
"the",
"message"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/UI/Alert.php#L53-L69 |
18,839 | aedart/laravel-helpers | src/Traits/Filesystem/CloudStorageTrait.php | CloudStorageTrait.getCloudStorage | public function getCloudStorage(): ?Cloud
{
if (!$this->hasCloudStorage()) {
$this->setCloudStorage($this->getDefaultCloudStorage());
}
return $this->cloudStorage;
} | php | public function getCloudStorage(): ?Cloud
{
if (!$this->hasCloudStorage()) {
$this->setCloudStorage($this->getDefaultCloudStorage());
}
return $this->cloudStorage;
} | [
"public",
"function",
"getCloudStorage",
"(",
")",
":",
"?",
"Cloud",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasCloudStorage",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setCloudStorage",
"(",
"$",
"this",
"->",
"getDefaultCloudStorage",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"cloudStorage",
";",
"}"
]
| Get cloud storage
If no cloud storage has been set, this method will
set and return a default cloud storage, if any such
value is available
@see getDefaultCloudStorage()
@return Cloud|null cloud storage or null if none cloud storage has been set | [
"Get",
"cloud",
"storage"
]
| 8b81a2d6658f3f8cb62b6be2c34773aaa2df219a | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Filesystem/CloudStorageTrait.php#L53-L59 |
18,840 | aedart/laravel-helpers | src/Traits/Filesystem/CloudStorageTrait.php | CloudStorageTrait.getDefaultCloudStorage | public function getDefaultCloudStorage(): ?Cloud
{
// By default, the Storage Facade does not return the
// any actual storage fisk, but rather an
// instance of \Illuminate\Filesystem\FilesystemManager.
// Therefore, we make sure only to obtain its
// "disk", to make sure that its the correct
// instance that we obtain.
$manager = Storage::getFacadeRoot();
if (isset($manager)) {
return $manager->disk();
}
return $manager;
} | php | public function getDefaultCloudStorage(): ?Cloud
{
// By default, the Storage Facade does not return the
// any actual storage fisk, but rather an
// instance of \Illuminate\Filesystem\FilesystemManager.
// Therefore, we make sure only to obtain its
// "disk", to make sure that its the correct
// instance that we obtain.
$manager = Storage::getFacadeRoot();
if (isset($manager)) {
return $manager->disk();
}
return $manager;
} | [
"public",
"function",
"getDefaultCloudStorage",
"(",
")",
":",
"?",
"Cloud",
"{",
"// By default, the Storage Facade does not return the",
"// any actual storage fisk, but rather an",
"// instance of \\Illuminate\\Filesystem\\FilesystemManager.",
"// Therefore, we make sure only to obtain its",
"// \"disk\", to make sure that its the correct",
"// instance that we obtain.",
"$",
"manager",
"=",
"Storage",
"::",
"getFacadeRoot",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"manager",
")",
")",
"{",
"return",
"$",
"manager",
"->",
"disk",
"(",
")",
";",
"}",
"return",
"$",
"manager",
";",
"}"
]
| Get a default cloud storage value, if any is available
@return Cloud|null A default cloud storage value or Null if no default value is available | [
"Get",
"a",
"default",
"cloud",
"storage",
"value",
"if",
"any",
"is",
"available"
]
| 8b81a2d6658f3f8cb62b6be2c34773aaa2df219a | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Filesystem/CloudStorageTrait.php#L76-L89 |
18,841 | onigoetz/imagecache | src/Transfer.php | Transfer.stream | public function stream()
{
if (ob_get_level()) {
ob_end_clean();
}
// Transfer file in 1024 byte chunks to save memory usage.
if ($fd = fopen($this->path, 'rb')) {
while (!feof($fd)) {
echo fread($fd, 1024);
}
fclose($fd);
}
} | php | public function stream()
{
if (ob_get_level()) {
ob_end_clean();
}
// Transfer file in 1024 byte chunks to save memory usage.
if ($fd = fopen($this->path, 'rb')) {
while (!feof($fd)) {
echo fread($fd, 1024);
}
fclose($fd);
}
} | [
"public",
"function",
"stream",
"(",
")",
"{",
"if",
"(",
"ob_get_level",
"(",
")",
")",
"{",
"ob_end_clean",
"(",
")",
";",
"}",
"// Transfer file in 1024 byte chunks to save memory usage.",
"if",
"(",
"$",
"fd",
"=",
"fopen",
"(",
"$",
"this",
"->",
"path",
",",
"'rb'",
")",
")",
"{",
"while",
"(",
"!",
"feof",
"(",
"$",
"fd",
")",
")",
"{",
"echo",
"fread",
"(",
"$",
"fd",
",",
"1024",
")",
";",
"}",
"fclose",
"(",
"$",
"fd",
")",
";",
"}",
"}"
]
| Transfer an image to the browser | [
"Transfer",
"an",
"image",
"to",
"the",
"browser"
]
| 8e22c11def1733819183e8296bab3c8a4ffc1d9c | https://github.com/onigoetz/imagecache/blob/8e22c11def1733819183e8296bab3c8a4ffc1d9c/src/Transfer.php#L67-L80 |
18,842 | onigoetz/imagecache | src/Transfer.php | Transfer.getCachingHeaders | protected function getCachingHeaders($fileinfo)
{
// Set default values:
$last_modified = gmdate('D, d M Y H:i:s', $fileinfo[9]) . ' GMT';
$etag = md5($last_modified);
// See if the client has provided the required HTTP headers:
$if_modified_since = $this->server_value('HTTP_IF_MODIFIED_SINCE', false);
$if_none_match = $this->server_value('HTTP_IF_NONE_MATCH', false);
if ($if_modified_since && $if_none_match && $if_none_match == $etag && $if_modified_since == $last_modified) {
$this->status = 304;
}
// Send appropriate response:
$this->headers['Last-Modified'] = $last_modified;
$this->headers['ETag'] = $etag;
} | php | protected function getCachingHeaders($fileinfo)
{
// Set default values:
$last_modified = gmdate('D, d M Y H:i:s', $fileinfo[9]) . ' GMT';
$etag = md5($last_modified);
// See if the client has provided the required HTTP headers:
$if_modified_since = $this->server_value('HTTP_IF_MODIFIED_SINCE', false);
$if_none_match = $this->server_value('HTTP_IF_NONE_MATCH', false);
if ($if_modified_since && $if_none_match && $if_none_match == $etag && $if_modified_since == $last_modified) {
$this->status = 304;
}
// Send appropriate response:
$this->headers['Last-Modified'] = $last_modified;
$this->headers['ETag'] = $etag;
} | [
"protected",
"function",
"getCachingHeaders",
"(",
"$",
"fileinfo",
")",
"{",
"// Set default values:",
"$",
"last_modified",
"=",
"gmdate",
"(",
"'D, d M Y H:i:s'",
",",
"$",
"fileinfo",
"[",
"9",
"]",
")",
".",
"' GMT'",
";",
"$",
"etag",
"=",
"md5",
"(",
"$",
"last_modified",
")",
";",
"// See if the client has provided the required HTTP headers:",
"$",
"if_modified_since",
"=",
"$",
"this",
"->",
"server_value",
"(",
"'HTTP_IF_MODIFIED_SINCE'",
",",
"false",
")",
";",
"$",
"if_none_match",
"=",
"$",
"this",
"->",
"server_value",
"(",
"'HTTP_IF_NONE_MATCH'",
",",
"false",
")",
";",
"if",
"(",
"$",
"if_modified_since",
"&&",
"$",
"if_none_match",
"&&",
"$",
"if_none_match",
"==",
"$",
"etag",
"&&",
"$",
"if_modified_since",
"==",
"$",
"last_modified",
")",
"{",
"$",
"this",
"->",
"status",
"=",
"304",
";",
"}",
"// Send appropriate response:",
"$",
"this",
"->",
"headers",
"[",
"'Last-Modified'",
"]",
"=",
"$",
"last_modified",
";",
"$",
"this",
"->",
"headers",
"[",
"'ETag'",
"]",
"=",
"$",
"etag",
";",
"}"
]
| Set file headers that handle "If-Modified-Since" correctly for the
given fileinfo.
@param array $fileinfo Array returned by stat(). | [
"Set",
"file",
"headers",
"that",
"handle",
"If",
"-",
"Modified",
"-",
"Since",
"correctly",
"for",
"the",
"given",
"fileinfo",
"."
]
| 8e22c11def1733819183e8296bab3c8a4ffc1d9c | https://github.com/onigoetz/imagecache/blob/8e22c11def1733819183e8296bab3c8a4ffc1d9c/src/Transfer.php#L88-L105 |
18,843 | npbtrac/yii2-enpii-cms | libs/override/db/NpMigration.php | NpMigration.addCode | public function addCode($tableName, $columnName = 'code')
{
$this->addColumn('{{%' . $tableName . '}}', $columnName,
$this->string(32)->comment('Code for this item, used identifying when needed. Another criteria to replace ID because ID is auto-increment'));
$this->createIndex($tableName . '_' . $columnName . '_idx', '{{%' . $tableName . '}}', $columnName);
} | php | public function addCode($tableName, $columnName = 'code')
{
$this->addColumn('{{%' . $tableName . '}}', $columnName,
$this->string(32)->comment('Code for this item, used identifying when needed. Another criteria to replace ID because ID is auto-increment'));
$this->createIndex($tableName . '_' . $columnName . '_idx', '{{%' . $tableName . '}}', $columnName);
} | [
"public",
"function",
"addCode",
"(",
"$",
"tableName",
",",
"$",
"columnName",
"=",
"'code'",
")",
"{",
"$",
"this",
"->",
"addColumn",
"(",
"'{{%'",
".",
"$",
"tableName",
".",
"'}}'",
",",
"$",
"columnName",
",",
"$",
"this",
"->",
"string",
"(",
"32",
")",
"->",
"comment",
"(",
"'Code for this item, used identifying when needed. Another criteria to replace ID because ID is auto-increment'",
")",
")",
";",
"$",
"this",
"->",
"createIndex",
"(",
"$",
"tableName",
".",
"'_'",
".",
"$",
"columnName",
".",
"'_idx'",
",",
"'{{%'",
".",
"$",
"tableName",
".",
"'}}'",
",",
"$",
"columnName",
")",
";",
"}"
]
| Add and put index to `code` column
Use if identity an item alternatively to ID
@param $tableName | [
"Add",
"and",
"put",
"index",
"to",
"code",
"column",
"Use",
"if",
"identity",
"an",
"item",
"alternatively",
"to",
"ID"
]
| 3495e697509a57a573983f552629ff9f707a63b9 | https://github.com/npbtrac/yii2-enpii-cms/blob/3495e697509a57a573983f552629ff9f707a63b9/libs/override/db/NpMigration.php#L36-L41 |
18,844 | npbtrac/yii2-enpii-cms | libs/override/db/NpMigration.php | NpMigration.addCreatorID | public function addCreatorID($tableName, $columnName = 'creator_id')
{
$this->addColumn('{{%' . $tableName . '}}', $columnName,
$this->bigInteger()->comment('ID of user who created this item'));
$this->createIndex($tableName . '_' . $columnName . '_idx', '{{%' . $tableName . '}}', $columnName);
} | php | public function addCreatorID($tableName, $columnName = 'creator_id')
{
$this->addColumn('{{%' . $tableName . '}}', $columnName,
$this->bigInteger()->comment('ID of user who created this item'));
$this->createIndex($tableName . '_' . $columnName . '_idx', '{{%' . $tableName . '}}', $columnName);
} | [
"public",
"function",
"addCreatorID",
"(",
"$",
"tableName",
",",
"$",
"columnName",
"=",
"'creator_id'",
")",
"{",
"$",
"this",
"->",
"addColumn",
"(",
"'{{%'",
".",
"$",
"tableName",
".",
"'}}'",
",",
"$",
"columnName",
",",
"$",
"this",
"->",
"bigInteger",
"(",
")",
"->",
"comment",
"(",
"'ID of user who created this item'",
")",
")",
";",
"$",
"this",
"->",
"createIndex",
"(",
"$",
"tableName",
".",
"'_'",
".",
"$",
"columnName",
".",
"'_idx'",
",",
"'{{%'",
".",
"$",
"tableName",
".",
"'}}'",
",",
"$",
"columnName",
")",
";",
"}"
]
| Add and put Index to creator_id column
Store id of user who create this record
@param $tableName | [
"Add",
"and",
"put",
"Index",
"to",
"creator_id",
"column",
"Store",
"id",
"of",
"user",
"who",
"create",
"this",
"record"
]
| 3495e697509a57a573983f552629ff9f707a63b9 | https://github.com/npbtrac/yii2-enpii-cms/blob/3495e697509a57a573983f552629ff9f707a63b9/libs/override/db/NpMigration.php#L88-L93 |
18,845 | webforge-labs/psc-cms | lib/Psc/UI/ComboBox2.php | ComboBox2.setAutoCompleteRequestMeta | public function setAutoCompleteRequestMeta(\Psc\CMS\AutoCompleteRequestMeta $autoCompleteRequestMeta) {
$this->acRequestMeta = $autoCompleteRequestMeta;
$this->avaibleItems = NULL;
return $this;
} | php | public function setAutoCompleteRequestMeta(\Psc\CMS\AutoCompleteRequestMeta $autoCompleteRequestMeta) {
$this->acRequestMeta = $autoCompleteRequestMeta;
$this->avaibleItems = NULL;
return $this;
} | [
"public",
"function",
"setAutoCompleteRequestMeta",
"(",
"\\",
"Psc",
"\\",
"CMS",
"\\",
"AutoCompleteRequestMeta",
"$",
"autoCompleteRequestMeta",
")",
"{",
"$",
"this",
"->",
"acRequestMeta",
"=",
"$",
"autoCompleteRequestMeta",
";",
"$",
"this",
"->",
"avaibleItems",
"=",
"NULL",
";",
"return",
"$",
"this",
";",
"}"
]
| Ist dies gesetzt wird avaibleItems ignoriert
@param Psc\CMS\AutoCompleteRequestMeta $autoCompleteRequestMeta
@chainable | [
"Ist",
"dies",
"gesetzt",
"wird",
"avaibleItems",
"ignoriert"
]
| 467bfa2547e6b4fa487d2d7f35fa6cc618dbc763 | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/UI/ComboBox2.php#L173-L177 |
18,846 | webforge-labs/psc-cms | lib/Psc/UI/Form.php | Form.attachLabel | public static function attachLabel($element, $label, $type = self::LABEL_TOP) {
Code::value($type, self::LABEL_TOP, self::LABEL_CHECKBOX);
if ($label != NULL) {
$element->templateContent->label = fHTML::label($label, $element)
->addClass('\Psc\label')
;
if ($type == self::LABEL_TOP) {
$element->templatePrepend('%label%'); // nicht überschreiben sondern prependen
}
if ($type == self::LABEL_CHECKBOX) {
$element->template = '%self% %label%';
$element->templateContent->label->addClass('checkbox-label');
}
}
return $element;
} | php | public static function attachLabel($element, $label, $type = self::LABEL_TOP) {
Code::value($type, self::LABEL_TOP, self::LABEL_CHECKBOX);
if ($label != NULL) {
$element->templateContent->label = fHTML::label($label, $element)
->addClass('\Psc\label')
;
if ($type == self::LABEL_TOP) {
$element->templatePrepend('%label%'); // nicht überschreiben sondern prependen
}
if ($type == self::LABEL_CHECKBOX) {
$element->template = '%self% %label%';
$element->templateContent->label->addClass('checkbox-label');
}
}
return $element;
} | [
"public",
"static",
"function",
"attachLabel",
"(",
"$",
"element",
",",
"$",
"label",
",",
"$",
"type",
"=",
"self",
"::",
"LABEL_TOP",
")",
"{",
"Code",
"::",
"value",
"(",
"$",
"type",
",",
"self",
"::",
"LABEL_TOP",
",",
"self",
"::",
"LABEL_CHECKBOX",
")",
";",
"if",
"(",
"$",
"label",
"!=",
"NULL",
")",
"{",
"$",
"element",
"->",
"templateContent",
"->",
"label",
"=",
"fHTML",
"::",
"label",
"(",
"$",
"label",
",",
"$",
"element",
")",
"->",
"addClass",
"(",
"'\\Psc\\label'",
")",
";",
"if",
"(",
"$",
"type",
"==",
"self",
"::",
"LABEL_TOP",
")",
"{",
"$",
"element",
"->",
"templatePrepend",
"(",
"'%label%'",
")",
";",
"// nicht überschreiben sondern prependen",
"}",
"if",
"(",
"$",
"type",
"==",
"self",
"::",
"LABEL_CHECKBOX",
")",
"{",
"$",
"element",
"->",
"template",
"=",
"'%self% %label%'",
";",
"$",
"element",
"->",
"templateContent",
"->",
"label",
"->",
"addClass",
"(",
"'checkbox-label'",
")",
";",
"}",
"}",
"return",
"$",
"element",
";",
"}"
]
| benutzt von dropBox2 | [
"benutzt",
"von",
"dropBox2"
]
| 467bfa2547e6b4fa487d2d7f35fa6cc618dbc763 | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/UI/Form.php#L232-L251 |
18,847 | Sedona-Solutions/sedona-sbo | src/Sedona/SBORuntimeBundle/ClassUtils.php | ClassUtils.hasTrait | public static function hasTrait($class, $traitName, $isRecursive = false)
{
if (is_string($class)) {
$class = new \ReflectionClass($class);
}
if (in_array($traitName, $class->getTraitNames(), true)) {
return true;
}
$parentClass = $class->getParentClass();
if ((false === $isRecursive) || (false === $parentClass) || (null === $parentClass)) {
return false;
}
return static::hasTrait($parentClass, $traitName, $isRecursive);
} | php | public static function hasTrait($class, $traitName, $isRecursive = false)
{
if (is_string($class)) {
$class = new \ReflectionClass($class);
}
if (in_array($traitName, $class->getTraitNames(), true)) {
return true;
}
$parentClass = $class->getParentClass();
if ((false === $isRecursive) || (false === $parentClass) || (null === $parentClass)) {
return false;
}
return static::hasTrait($parentClass, $traitName, $isRecursive);
} | [
"public",
"static",
"function",
"hasTrait",
"(",
"$",
"class",
",",
"$",
"traitName",
",",
"$",
"isRecursive",
"=",
"false",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"traitName",
",",
"$",
"class",
"->",
"getTraitNames",
"(",
")",
",",
"true",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"parentClass",
"=",
"$",
"class",
"->",
"getParentClass",
"(",
")",
";",
"if",
"(",
"(",
"false",
"===",
"$",
"isRecursive",
")",
"||",
"(",
"false",
"===",
"$",
"parentClass",
")",
"||",
"(",
"null",
"===",
"$",
"parentClass",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"static",
"::",
"hasTrait",
"(",
"$",
"parentClass",
",",
"$",
"traitName",
",",
"$",
"isRecursive",
")",
";",
"}"
]
| Return true if the given object use the given trait, FALSE if not.
@param \ReflectionClass|string $class
@param string $traitName
@param bool $isRecursive
@return bool | [
"Return",
"true",
"if",
"the",
"given",
"object",
"use",
"the",
"given",
"trait",
"FALSE",
"if",
"not",
"."
]
| 8548be4170d191cb1a3e263577aaaab49f04d5ce | https://github.com/Sedona-Solutions/sedona-sbo/blob/8548be4170d191cb1a3e263577aaaab49f04d5ce/src/Sedona/SBORuntimeBundle/ClassUtils.php#L28-L45 |
18,848 | xinix-technology/norm | src/Norm/Cursor.php | Cursor.sort | public function sort(array $sorts = array())
{
if (func_num_args() === 0) {
return $this->sorts;
}
$this->sorts = array();
foreach ($sorts as $key => $value) {
if ($key[0] === '$') {
$key[0] = '_';
}
$this->sorts[$key] = $value;
}
return $this;
} | php | public function sort(array $sorts = array())
{
if (func_num_args() === 0) {
return $this->sorts;
}
$this->sorts = array();
foreach ($sorts as $key => $value) {
if ($key[0] === '$') {
$key[0] = '_';
}
$this->sorts[$key] = $value;
}
return $this;
} | [
"public",
"function",
"sort",
"(",
"array",
"$",
"sorts",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"func_num_args",
"(",
")",
"===",
"0",
")",
"{",
"return",
"$",
"this",
"->",
"sorts",
";",
"}",
"$",
"this",
"->",
"sorts",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"sorts",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"key",
"[",
"0",
"]",
"===",
"'$'",
")",
"{",
"$",
"key",
"[",
"0",
"]",
"=",
"'_'",
";",
"}",
"$",
"this",
"->",
"sorts",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| When argument specified will set new sorts otherwise will return existing sorts
@param array $sorts
@return mixed When argument specified will return sorts otherwise return chainable object | [
"When",
"argument",
"specified",
"will",
"set",
"new",
"sorts",
"otherwise",
"will",
"return",
"existing",
"sorts"
]
| c357f7d3a75d05324dd84b8f6a968a094c53d603 | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Cursor.php#L167-L184 |
18,849 | xinix-technology/norm | src/Norm/Cursor.php | Cursor.match | public function match($q)
{
if (is_null($q)) {
return $this;
}
$orCriteria = array();
$schema = $this->collection->schema();
if (empty($schema)) {
throw new \Exception('[Norm\Cursor] Cannot use match for schemaless collection');
}
foreach ($schema as $key => $value) {
$orCriteria[] = array($key.'!like' => $q);
}
$this->criteria = $this->translateCriteria(array('!or' => $orCriteria));
return $this;
} | php | public function match($q)
{
if (is_null($q)) {
return $this;
}
$orCriteria = array();
$schema = $this->collection->schema();
if (empty($schema)) {
throw new \Exception('[Norm\Cursor] Cannot use match for schemaless collection');
}
foreach ($schema as $key => $value) {
$orCriteria[] = array($key.'!like' => $q);
}
$this->criteria = $this->translateCriteria(array('!or' => $orCriteria));
return $this;
} | [
"public",
"function",
"match",
"(",
"$",
"q",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"q",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"orCriteria",
"=",
"array",
"(",
")",
";",
"$",
"schema",
"=",
"$",
"this",
"->",
"collection",
"->",
"schema",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"schema",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'[Norm\\Cursor] Cannot use match for schemaless collection'",
")",
";",
"}",
"foreach",
"(",
"$",
"schema",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"orCriteria",
"[",
"]",
"=",
"array",
"(",
"$",
"key",
".",
"'!like'",
"=>",
"$",
"q",
")",
";",
"}",
"$",
"this",
"->",
"criteria",
"=",
"$",
"this",
"->",
"translateCriteria",
"(",
"array",
"(",
"'!or'",
"=>",
"$",
"orCriteria",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Set query to match on every field exists in schema. Beware this will override criteria
@param string $q String to query
@return \Norm\Cursor Chainable object | [
"Set",
"query",
"to",
"match",
"on",
"every",
"field",
"exists",
"in",
"schema",
".",
"Beware",
"this",
"will",
"override",
"criteria"
]
| c357f7d3a75d05324dd84b8f6a968a094c53d603 | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Cursor.php#L193-L214 |
18,850 | xinix-technology/norm | src/Norm/Cursor.php | Cursor.toArray | public function toArray($plain = false)
{
$result = array();
foreach ($this as $key => $value) {
if ($plain) {
$result[] = $value->toArray();
} else {
$result[] = $this->connection->unmarshall($value);
}
}
return $result;
} | php | public function toArray($plain = false)
{
$result = array();
foreach ($this as $key => $value) {
if ($plain) {
$result[] = $value->toArray();
} else {
$result[] = $this->connection->unmarshall($value);
}
}
return $result;
} | [
"public",
"function",
"toArray",
"(",
"$",
"plain",
"=",
"false",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"plain",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"value",
"->",
"toArray",
"(",
")",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"this",
"->",
"connection",
"->",
"unmarshall",
"(",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
]
| Extract data into array of models.
@param boolean $plain When true will return array of associative array.
@return array | [
"Extract",
"data",
"into",
"array",
"of",
"models",
"."
]
| c357f7d3a75d05324dd84b8f6a968a094c53d603 | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Cursor.php#L223-L236 |
18,851 | dafiti/datajet-client | src/Datajet/Resource/Product.php | Product.import | public function import(array $data)
{
$response = $this->client->post("{$this->uriImport}product/", [
'json' => $data,
'query' => [
'key' => $this->config['data']['key'],
],
]);
$response = json_decode($response->getBody(), true);
if (isset($response['affected']) && $response['affected'] > 0) {
return true;
}
return false;
} | php | public function import(array $data)
{
$response = $this->client->post("{$this->uriImport}product/", [
'json' => $data,
'query' => [
'key' => $this->config['data']['key'],
],
]);
$response = json_decode($response->getBody(), true);
if (isset($response['affected']) && $response['affected'] > 0) {
return true;
}
return false;
} | [
"public",
"function",
"import",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"post",
"(",
"\"{$this->uriImport}product/\"",
",",
"[",
"'json'",
"=>",
"$",
"data",
",",
"'query'",
"=>",
"[",
"'key'",
"=>",
"$",
"this",
"->",
"config",
"[",
"'data'",
"]",
"[",
"'key'",
"]",
",",
"]",
",",
"]",
")",
";",
"$",
"response",
"=",
"json_decode",
"(",
"$",
"response",
"->",
"getBody",
"(",
")",
",",
"true",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"response",
"[",
"'affected'",
"]",
")",
"&&",
"$",
"response",
"[",
"'affected'",
"]",
">",
"0",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Atomic product import.
@param array $data A list of product to import
@throws \GuzzleHttp\Exception\GuzzleException
@return bool | [
"Atomic",
"product",
"import",
"."
]
| c8555362521690b95451d2006d891b30facd8a46 | https://github.com/dafiti/datajet-client/blob/c8555362521690b95451d2006d891b30facd8a46/src/Datajet/Resource/Product.php#L65-L81 |
18,852 | dafiti/datajet-client | src/Datajet/Resource/Product.php | Product.search | public function search(array $data)
{
if (!isset($data['size'])) {
$data['size'] = 10;
}
$response = $this->client->post("{$this->uriSearch}search/", [
'json' => $data,
'query' => [
'key' => $this->config['search']['key'],
],
]);
$response = json_decode($response->getBody(), true);
return $response;
} | php | public function search(array $data)
{
if (!isset($data['size'])) {
$data['size'] = 10;
}
$response = $this->client->post("{$this->uriSearch}search/", [
'json' => $data,
'query' => [
'key' => $this->config['search']['key'],
],
]);
$response = json_decode($response->getBody(), true);
return $response;
} | [
"public",
"function",
"search",
"(",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'size'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'size'",
"]",
"=",
"10",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"post",
"(",
"\"{$this->uriSearch}search/\"",
",",
"[",
"'json'",
"=>",
"$",
"data",
",",
"'query'",
"=>",
"[",
"'key'",
"=>",
"$",
"this",
"->",
"config",
"[",
"'search'",
"]",
"[",
"'key'",
"]",
",",
"]",
",",
"]",
")",
";",
"$",
"response",
"=",
"json_decode",
"(",
"$",
"response",
"->",
"getBody",
"(",
")",
",",
"true",
")",
";",
"return",
"$",
"response",
";",
"}"
]
| Product Search.
@param array $data Search parameters
@throws \GuzzleHttp\Exception\GuzzleException
@return array | [
"Product",
"Search",
"."
]
| c8555362521690b95451d2006d891b30facd8a46 | https://github.com/dafiti/datajet-client/blob/c8555362521690b95451d2006d891b30facd8a46/src/Datajet/Resource/Product.php#L92-L108 |
18,853 | dafiti/datajet-client | src/Datajet/Resource/Product.php | Product.delete | public function delete($id)
{
$response = false;
if (empty($id)) {
throw new \InvalidArgumentException('ID Product cannot be empty');
}
try {
$apiResponse = $this->client->delete("{$this->uriImport}product/{$id}", [
'query' => [
'key' => $this->config['data']['key'],
],
]);
$apiResponse = json_decode($apiResponse->getBody(), true);
if (isset($apiResponse['affected']) && $apiResponse['affected'] > 0) {
$response = true;
}
} catch (ClientException $e) {
$response = false;
}
return $response;
} | php | public function delete($id)
{
$response = false;
if (empty($id)) {
throw new \InvalidArgumentException('ID Product cannot be empty');
}
try {
$apiResponse = $this->client->delete("{$this->uriImport}product/{$id}", [
'query' => [
'key' => $this->config['data']['key'],
],
]);
$apiResponse = json_decode($apiResponse->getBody(), true);
if (isset($apiResponse['affected']) && $apiResponse['affected'] > 0) {
$response = true;
}
} catch (ClientException $e) {
$response = false;
}
return $response;
} | [
"public",
"function",
"delete",
"(",
"$",
"id",
")",
"{",
"$",
"response",
"=",
"false",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'ID Product cannot be empty'",
")",
";",
"}",
"try",
"{",
"$",
"apiResponse",
"=",
"$",
"this",
"->",
"client",
"->",
"delete",
"(",
"\"{$this->uriImport}product/{$id}\"",
",",
"[",
"'query'",
"=>",
"[",
"'key'",
"=>",
"$",
"this",
"->",
"config",
"[",
"'data'",
"]",
"[",
"'key'",
"]",
",",
"]",
",",
"]",
")",
";",
"$",
"apiResponse",
"=",
"json_decode",
"(",
"$",
"apiResponse",
"->",
"getBody",
"(",
")",
",",
"true",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"apiResponse",
"[",
"'affected'",
"]",
")",
"&&",
"$",
"apiResponse",
"[",
"'affected'",
"]",
">",
"0",
")",
"{",
"$",
"response",
"=",
"true",
";",
"}",
"}",
"catch",
"(",
"ClientException",
"$",
"e",
")",
"{",
"$",
"response",
"=",
"false",
";",
"}",
"return",
"$",
"response",
";",
"}"
]
| Product Delete.
@param string $id
@return bool | [
"Product",
"Delete",
"."
]
| c8555362521690b95451d2006d891b30facd8a46 | https://github.com/dafiti/datajet-client/blob/c8555362521690b95451d2006d891b30facd8a46/src/Datajet/Resource/Product.php#L117-L141 |
18,854 | webforge-labs/psc-cms | lib/Psc/System/Deploy/ConfigureApacheTask.php | ConfigureApacheTask.addAlias | public function addAlias($location, $path) {
$this->setVar('aliases',
$this->getVar('aliases').
sprintf("\n Alias %s %s", $location , $this->replaceHelpers($path))
);
return $this;
} | php | public function addAlias($location, $path) {
$this->setVar('aliases',
$this->getVar('aliases').
sprintf("\n Alias %s %s", $location , $this->replaceHelpers($path))
);
return $this;
} | [
"public",
"function",
"addAlias",
"(",
"$",
"location",
",",
"$",
"path",
")",
"{",
"$",
"this",
"->",
"setVar",
"(",
"'aliases'",
",",
"$",
"this",
"->",
"getVar",
"(",
"'aliases'",
")",
".",
"sprintf",
"(",
"\"\\n Alias %s %s\"",
",",
"$",
"location",
",",
"$",
"this",
"->",
"replaceHelpers",
"(",
"$",
"path",
")",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Adds an Location alias
$this->addAlias('/images /var/local/banane'); | [
"Adds",
"an",
"Location",
"alias"
]
| 467bfa2547e6b4fa487d2d7f35fa6cc618dbc763 | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/System/Deploy/ConfigureApacheTask.php#L157-L163 |
18,855 | claroline/ForumBundle | Repository/ForumRepository.php | ForumRepository.findSubjects | public function findSubjects(Category $category, $getQuery = false)
{
$dql = "
SELECT s.id as id,
COUNT(m_count.id) AS count_messages,
MAX(m.creationDate) AS last_message_created,
s.id as subjectId,
s.title as title,
s.isSticked as isSticked,
s.author as subject_author,
subjectCreator.lastName as subject_creator_lastname,
subjectCreator.firstName as subject_creator_firstname,
subjectCreator.id as subject_creator_id,
lastUser.lastName as last_message_creator_lastname,
lastUser.firstName as last_message_creator_firstname,
s.creationDate as subject_created,
s.isClosed as is_closed
FROM Claroline\ForumBundle\Entity\Subject s
JOIN s.messages m_count
JOIN s.creator subjectCreator
JOIN s.category category
JOIN s.messages m
JOIN m.creator lastUser WITH lastUser.id =
(
SELECT lcu.id FROM Claroline\ForumBundle\Entity\Message m2
JOIN m2.subject s2
JOIN m2.creator lcu
JOIN s2.category c2
WHERE NOT EXISTS
(
SELECT m3 FROM Claroline\ForumBundle\Entity\Message m3
JOIN m3.subject s3
WHERE s2.id = s3.id
AND m2.id < m3.id
)
and c2.id = :categoryId
and m2.id = m.id
)
WHERE category.id = :categoryId
GROUP BY s.id, subjectCreator.lastName, subjectCreator.firstName, lastUser.lastName, lastUser.firstName
ORDER BY isSticked DESC, last_message_created DESC
";
$query = $this->_em->createQuery($dql);
$query->setParameter('categoryId', $category->getId());
return ($getQuery) ? $query: $query->getResult();
} | php | public function findSubjects(Category $category, $getQuery = false)
{
$dql = "
SELECT s.id as id,
COUNT(m_count.id) AS count_messages,
MAX(m.creationDate) AS last_message_created,
s.id as subjectId,
s.title as title,
s.isSticked as isSticked,
s.author as subject_author,
subjectCreator.lastName as subject_creator_lastname,
subjectCreator.firstName as subject_creator_firstname,
subjectCreator.id as subject_creator_id,
lastUser.lastName as last_message_creator_lastname,
lastUser.firstName as last_message_creator_firstname,
s.creationDate as subject_created,
s.isClosed as is_closed
FROM Claroline\ForumBundle\Entity\Subject s
JOIN s.messages m_count
JOIN s.creator subjectCreator
JOIN s.category category
JOIN s.messages m
JOIN m.creator lastUser WITH lastUser.id =
(
SELECT lcu.id FROM Claroline\ForumBundle\Entity\Message m2
JOIN m2.subject s2
JOIN m2.creator lcu
JOIN s2.category c2
WHERE NOT EXISTS
(
SELECT m3 FROM Claroline\ForumBundle\Entity\Message m3
JOIN m3.subject s3
WHERE s2.id = s3.id
AND m2.id < m3.id
)
and c2.id = :categoryId
and m2.id = m.id
)
WHERE category.id = :categoryId
GROUP BY s.id, subjectCreator.lastName, subjectCreator.firstName, lastUser.lastName, lastUser.firstName
ORDER BY isSticked DESC, last_message_created DESC
";
$query = $this->_em->createQuery($dql);
$query->setParameter('categoryId', $category->getId());
return ($getQuery) ? $query: $query->getResult();
} | [
"public",
"function",
"findSubjects",
"(",
"Category",
"$",
"category",
",",
"$",
"getQuery",
"=",
"false",
")",
"{",
"$",
"dql",
"=",
"\"\n SELECT s.id as id,\n COUNT(m_count.id) AS count_messages,\n MAX(m.creationDate) AS last_message_created,\n s.id as subjectId,\n s.title as title,\n s.isSticked as isSticked,\n s.author as subject_author,\n subjectCreator.lastName as subject_creator_lastname,\n subjectCreator.firstName as subject_creator_firstname,\n subjectCreator.id as subject_creator_id,\n lastUser.lastName as last_message_creator_lastname,\n lastUser.firstName as last_message_creator_firstname,\n s.creationDate as subject_created,\n s.isClosed as is_closed\n FROM Claroline\\ForumBundle\\Entity\\Subject s\n JOIN s.messages m_count\n JOIN s.creator subjectCreator\n JOIN s.category category\n JOIN s.messages m\n JOIN m.creator lastUser WITH lastUser.id =\n (\n SELECT lcu.id FROM Claroline\\ForumBundle\\Entity\\Message m2\n JOIN m2.subject s2\n JOIN m2.creator lcu\n JOIN s2.category c2\n WHERE NOT EXISTS\n (\n SELECT m3 FROM Claroline\\ForumBundle\\Entity\\Message m3\n JOIN m3.subject s3\n WHERE s2.id = s3.id\n AND m2.id < m3.id\n )\n and c2.id = :categoryId\n and m2.id = m.id\n )\n WHERE category.id = :categoryId\n GROUP BY s.id, subjectCreator.lastName, subjectCreator.firstName, lastUser.lastName, lastUser.firstName\n ORDER BY isSticked DESC, last_message_created DESC\n \"",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"_em",
"->",
"createQuery",
"(",
"$",
"dql",
")",
";",
"$",
"query",
"->",
"setParameter",
"(",
"'categoryId'",
",",
"$",
"category",
"->",
"getId",
"(",
")",
")",
";",
"return",
"(",
"$",
"getQuery",
")",
"?",
"$",
"query",
":",
"$",
"query",
"->",
"getResult",
"(",
")",
";",
"}"
]
| Deep magic goes here.
Gets a subject with some of its last messages datas.
@param ResourceInstance $forum
@return type | [
"Deep",
"magic",
"goes",
"here",
".",
"Gets",
"a",
"subject",
"with",
"some",
"of",
"its",
"last",
"messages",
"datas",
"."
]
| bd85dfd870cacee541ea94fec8e59744bf90eaf4 | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Repository/ForumRepository.php#L30-L76 |
18,856 | forxer/tao | src/Tao/Utilities.php | Utilities.getMemoryUsageData | public function getMemoryUsageData()
{
if (null === $this->memoryUsageData)
{
$memoryUsage = memory_get_usage();
$unit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
$this->memoryUsageData = [
round($memoryUsage/pow(1024, ($i=floor(log($memoryUsage, 1024))) ), 2),
$unit[$i]
];
}
return $this->memoryUsageData;
} | php | public function getMemoryUsageData()
{
if (null === $this->memoryUsageData)
{
$memoryUsage = memory_get_usage();
$unit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
$this->memoryUsageData = [
round($memoryUsage/pow(1024, ($i=floor(log($memoryUsage, 1024))) ), 2),
$unit[$i]
];
}
return $this->memoryUsageData;
} | [
"public",
"function",
"getMemoryUsageData",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"memoryUsageData",
")",
"{",
"$",
"memoryUsage",
"=",
"memory_get_usage",
"(",
")",
";",
"$",
"unit",
"=",
"[",
"'B'",
",",
"'KB'",
",",
"'MB'",
",",
"'GB'",
",",
"'TB'",
",",
"'PB'",
"]",
";",
"$",
"this",
"->",
"memoryUsageData",
"=",
"[",
"round",
"(",
"$",
"memoryUsage",
"/",
"pow",
"(",
"1024",
",",
"(",
"$",
"i",
"=",
"floor",
"(",
"log",
"(",
"$",
"memoryUsage",
",",
"1024",
")",
")",
")",
")",
",",
"2",
")",
",",
"$",
"unit",
"[",
"$",
"i",
"]",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"memoryUsageData",
";",
"}"
]
| Return the application memory usage data.
@return array | [
"Return",
"the",
"application",
"memory",
"usage",
"data",
"."
]
| b5e9109c244a29a72403ae6a58633ab96a67c660 | https://github.com/forxer/tao/blob/b5e9109c244a29a72403ae6a58633ab96a67c660/src/Tao/Utilities.php#L68-L83 |
18,857 | forxer/tao | src/Tao/Utilities.php | Utilities.setConfiguration | public function setConfiguration(array $config = [])
{
# Merge config with default values
$config = $config + $this->getDefaultConfiguration();
# If debug mode, store config data for debug purpose
if (!empty($config['debug'])) {
$this->config = $config;
}
return $config;
} | php | public function setConfiguration(array $config = [])
{
# Merge config with default values
$config = $config + $this->getDefaultConfiguration();
# If debug mode, store config data for debug purpose
if (!empty($config['debug'])) {
$this->config = $config;
}
return $config;
} | [
"public",
"function",
"setConfiguration",
"(",
"array",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"# Merge config with default values",
"$",
"config",
"=",
"$",
"config",
"+",
"$",
"this",
"->",
"getDefaultConfiguration",
"(",
")",
";",
"# If debug mode, store config data for debug purpose",
"if",
"(",
"!",
"empty",
"(",
"$",
"config",
"[",
"'debug'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"config",
"=",
"$",
"config",
";",
"}",
"return",
"$",
"config",
";",
"}"
]
| Return application configuration values.
@param array $config
@return array | [
"Return",
"application",
"configuration",
"values",
"."
]
| b5e9109c244a29a72403ae6a58633ab96a67c660 | https://github.com/forxer/tao/blob/b5e9109c244a29a72403ae6a58633ab96a67c660/src/Tao/Utilities.php#L156-L167 |
18,858 | ixocreate/application | src/Http/ErrorHandling/Response/NotFoundHandler.php | NotFoundHandler.generateNotFoundPlainResponse | private function generateNotFoundPlainResponse(ServerRequestInterface $request) : ResponseInterface
{
$response = ($this->responseFactory)()->withStatus(StatusCodeInterface::STATUS_NOT_FOUND);
$response->getBody()
->write(\sprintf(
"Encountered a 404 Error, %s doesn't exist",
(string) $request->getUri()
));
return $response;
} | php | private function generateNotFoundPlainResponse(ServerRequestInterface $request) : ResponseInterface
{
$response = ($this->responseFactory)()->withStatus(StatusCodeInterface::STATUS_NOT_FOUND);
$response->getBody()
->write(\sprintf(
"Encountered a 404 Error, %s doesn't exist",
(string) $request->getUri()
));
return $response;
} | [
"private",
"function",
"generateNotFoundPlainResponse",
"(",
"ServerRequestInterface",
"$",
"request",
")",
":",
"ResponseInterface",
"{",
"$",
"response",
"=",
"(",
"$",
"this",
"->",
"responseFactory",
")",
"(",
")",
"->",
"withStatus",
"(",
"StatusCodeInterface",
"::",
"STATUS_NOT_FOUND",
")",
";",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"write",
"(",
"\\",
"sprintf",
"(",
"\"Encountered a 404 Error, %s doesn't exist\"",
",",
"(",
"string",
")",
"$",
"request",
"->",
"getUri",
"(",
")",
")",
")",
";",
"return",
"$",
"response",
";",
"}"
]
| Generates a plain text response indicating the request method and URI.
@param ServerRequestInterface $request
@return ResponseInterface | [
"Generates",
"a",
"plain",
"text",
"response",
"indicating",
"the",
"request",
"method",
"and",
"URI",
"."
]
| 6b0ef355ecf96af63d0dd5b901b4c9a5a69daf05 | https://github.com/ixocreate/application/blob/6b0ef355ecf96af63d0dd5b901b4c9a5a69daf05/src/Http/ErrorHandling/Response/NotFoundHandler.php#L73-L83 |
18,859 | ixocreate/application | src/Http/ErrorHandling/Response/NotFoundHandler.php | NotFoundHandler.generateTemplateResponse | private function generateTemplateResponse(
Renderer $renderer,
ServerRequestInterface $request
) : ResponseInterface {
$response = ($this->responseFactory)()->withStatus(StatusCodeInterface::STATUS_NOT_FOUND);
$response->getBody()->write(
$renderer->render($this->template, ['request' => $request])
);
return $response;
} | php | private function generateTemplateResponse(
Renderer $renderer,
ServerRequestInterface $request
) : ResponseInterface {
$response = ($this->responseFactory)()->withStatus(StatusCodeInterface::STATUS_NOT_FOUND);
$response->getBody()->write(
$renderer->render($this->template, ['request' => $request])
);
return $response;
} | [
"private",
"function",
"generateTemplateResponse",
"(",
"Renderer",
"$",
"renderer",
",",
"ServerRequestInterface",
"$",
"request",
")",
":",
"ResponseInterface",
"{",
"$",
"response",
"=",
"(",
"$",
"this",
"->",
"responseFactory",
")",
"(",
")",
"->",
"withStatus",
"(",
"StatusCodeInterface",
"::",
"STATUS_NOT_FOUND",
")",
";",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"write",
"(",
"$",
"renderer",
"->",
"render",
"(",
"$",
"this",
"->",
"template",
",",
"[",
"'request'",
"=>",
"$",
"request",
"]",
")",
")",
";",
"return",
"$",
"response",
";",
"}"
]
| Generates a response using a template.
Template will receive the current request via the "request" variable.
@param Renderer $renderer
@param ServerRequestInterface $request
@return ResponseInterface | [
"Generates",
"a",
"response",
"using",
"a",
"template",
"."
]
| 6b0ef355ecf96af63d0dd5b901b4c9a5a69daf05 | https://github.com/ixocreate/application/blob/6b0ef355ecf96af63d0dd5b901b4c9a5a69daf05/src/Http/ErrorHandling/Response/NotFoundHandler.php#L93-L103 |
18,860 | ClanCats/Core | src/console/orbit.php | orbit.action_uninstall | public function action_uninstall( $params ) {
$path = $params[0];
if ( empty( $path ) ) {
CCCli::line( 'no ship path given.', 'red' ); return;
}
/*
* direct install if starting with /
*/
if ( substr( $path, 0, 1 ) == '/' ) {
// fix path
if ( substr( $path, -1 ) != '/' ) {
$path .= '/';
}
// is directory
if ( !is_dir( $path ) ) {
CCCli::line( 'could not find a ship at path: '.$path, 'red' ); return;
}
// are ya serius..
if ( !CCCli::confirm( "are you sure you want to uninstall this ship?", true ) ) {
return;
}
// run the uninstaller
try {
\CCOrbit::uninstall( $path );
}
catch ( \Exception $e ) {
CCCli::line( $e->getMessage(), 'red' );
CCCli::line( 'ship destroying failure.', 'red' ); return;
}
// also remove the direcoty?
if ( CCCli::confirm( "do you also wish to remove the ship files?", true ) ) {
\CCFile::delete( $path );
}
// we are done
CCCli::line( 'ship destroyed!', 'green' );
return;
}
// check if the module is in our orbit path
if ( is_dir( ORBITPATH.$path ) ) {
// there is a ship yay
CCCli::line( 'found ship at path: '.ORBITPATH.$path, 'green' );
return static::action_uninstall( array( ORBITPATH.$path ) );
}
// nothing to do here
CCCli::line( 'could not find a ship at this path or name.', 'red' ); return;
} | php | public function action_uninstall( $params ) {
$path = $params[0];
if ( empty( $path ) ) {
CCCli::line( 'no ship path given.', 'red' ); return;
}
/*
* direct install if starting with /
*/
if ( substr( $path, 0, 1 ) == '/' ) {
// fix path
if ( substr( $path, -1 ) != '/' ) {
$path .= '/';
}
// is directory
if ( !is_dir( $path ) ) {
CCCli::line( 'could not find a ship at path: '.$path, 'red' ); return;
}
// are ya serius..
if ( !CCCli::confirm( "are you sure you want to uninstall this ship?", true ) ) {
return;
}
// run the uninstaller
try {
\CCOrbit::uninstall( $path );
}
catch ( \Exception $e ) {
CCCli::line( $e->getMessage(), 'red' );
CCCli::line( 'ship destroying failure.', 'red' ); return;
}
// also remove the direcoty?
if ( CCCli::confirm( "do you also wish to remove the ship files?", true ) ) {
\CCFile::delete( $path );
}
// we are done
CCCli::line( 'ship destroyed!', 'green' );
return;
}
// check if the module is in our orbit path
if ( is_dir( ORBITPATH.$path ) ) {
// there is a ship yay
CCCli::line( 'found ship at path: '.ORBITPATH.$path, 'green' );
return static::action_uninstall( array( ORBITPATH.$path ) );
}
// nothing to do here
CCCli::line( 'could not find a ship at this path or name.', 'red' ); return;
} | [
"public",
"function",
"action_uninstall",
"(",
"$",
"params",
")",
"{",
"$",
"path",
"=",
"$",
"params",
"[",
"0",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"path",
")",
")",
"{",
"CCCli",
"::",
"line",
"(",
"'no ship path given.'",
",",
"'red'",
")",
";",
"return",
";",
"}",
"/*\n\t\t * direct install if starting with /\n\t\t */",
"if",
"(",
"substr",
"(",
"$",
"path",
",",
"0",
",",
"1",
")",
"==",
"'/'",
")",
"{",
"// fix path",
"if",
"(",
"substr",
"(",
"$",
"path",
",",
"-",
"1",
")",
"!=",
"'/'",
")",
"{",
"$",
"path",
".=",
"'/'",
";",
"}",
"// is directory",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"CCCli",
"::",
"line",
"(",
"'could not find a ship at path: '",
".",
"$",
"path",
",",
"'red'",
")",
";",
"return",
";",
"}",
"// are ya serius..",
"if",
"(",
"!",
"CCCli",
"::",
"confirm",
"(",
"\"are you sure you want to uninstall this ship?\"",
",",
"true",
")",
")",
"{",
"return",
";",
"}",
"// run the uninstaller",
"try",
"{",
"\\",
"CCOrbit",
"::",
"uninstall",
"(",
"$",
"path",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"CCCli",
"::",
"line",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"'red'",
")",
";",
"CCCli",
"::",
"line",
"(",
"'ship destroying failure.'",
",",
"'red'",
")",
";",
"return",
";",
"}",
"// also remove the direcoty?",
"if",
"(",
"CCCli",
"::",
"confirm",
"(",
"\"do you also wish to remove the ship files?\"",
",",
"true",
")",
")",
"{",
"\\",
"CCFile",
"::",
"delete",
"(",
"$",
"path",
")",
";",
"}",
"// we are done",
"CCCli",
"::",
"line",
"(",
"'ship destroyed!'",
",",
"'green'",
")",
";",
"return",
";",
"}",
"// check if the module is in our orbit path",
"if",
"(",
"is_dir",
"(",
"ORBITPATH",
".",
"$",
"path",
")",
")",
"{",
"// there is a ship yay",
"CCCli",
"::",
"line",
"(",
"'found ship at path: '",
".",
"ORBITPATH",
".",
"$",
"path",
",",
"'green'",
")",
";",
"return",
"static",
"::",
"action_uninstall",
"(",
"array",
"(",
"ORBITPATH",
".",
"$",
"path",
")",
")",
";",
"}",
"// nothing to do here",
"CCCli",
"::",
"line",
"(",
"'could not find a ship at this path or name.'",
",",
"'red'",
")",
";",
"return",
";",
"}"
]
| uninstall an orbit module
@param array $params | [
"uninstall",
"an",
"orbit",
"module"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/console/orbit.php#L123-L182 |
18,861 | left-right/center | src/CenterServiceProvider.php | CenterServiceProvider.config | private function config() {
$this->loadViewsFrom(__DIR__ . '/views', 'center');
$this->loadTranslationsFrom(__DIR__ . '/translations', 'center');
$this->publishes([
__DIR__ . '/../assets/public' => public_path('vendor/center'),
], 'public');
$this->publishes([
__DIR__ . '/config' => config_path('center'),
], 'config');
$this->publishes([
__DIR__ . '/translations/en/site.php' => app_path('../resources/lang/vendor/center/en/site.php'),
__DIR__ . '/translations/en/users.php' => app_path('../resources/lang/vendor/center/en/users.php'),
], 'lang');
//include __DIR__ . '/macros.php';
include __DIR__ . '/routes.php';
} | php | private function config() {
$this->loadViewsFrom(__DIR__ . '/views', 'center');
$this->loadTranslationsFrom(__DIR__ . '/translations', 'center');
$this->publishes([
__DIR__ . '/../assets/public' => public_path('vendor/center'),
], 'public');
$this->publishes([
__DIR__ . '/config' => config_path('center'),
], 'config');
$this->publishes([
__DIR__ . '/translations/en/site.php' => app_path('../resources/lang/vendor/center/en/site.php'),
__DIR__ . '/translations/en/users.php' => app_path('../resources/lang/vendor/center/en/users.php'),
], 'lang');
//include __DIR__ . '/macros.php';
include __DIR__ . '/routes.php';
} | [
"private",
"function",
"config",
"(",
")",
"{",
"$",
"this",
"->",
"loadViewsFrom",
"(",
"__DIR__",
".",
"'/views'",
",",
"'center'",
")",
";",
"$",
"this",
"->",
"loadTranslationsFrom",
"(",
"__DIR__",
".",
"'/translations'",
",",
"'center'",
")",
";",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/../assets/public'",
"=>",
"public_path",
"(",
"'vendor/center'",
")",
",",
"]",
",",
"'public'",
")",
";",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/config'",
"=>",
"config_path",
"(",
"'center'",
")",
",",
"]",
",",
"'config'",
")",
";",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/translations/en/site.php'",
"=>",
"app_path",
"(",
"'../resources/lang/vendor/center/en/site.php'",
")",
",",
"__DIR__",
".",
"'/translations/en/users.php'",
"=>",
"app_path",
"(",
"'../resources/lang/vendor/center/en/users.php'",
")",
",",
"]",
",",
"'lang'",
")",
";",
"//include __DIR__ . '/macros.php';",
"include",
"__DIR__",
".",
"'/routes.php'",
";",
"}"
]
| set up publishes paths and define config locations | [
"set",
"up",
"publishes",
"paths",
"and",
"define",
"config",
"locations"
]
| 47c225538475ca3e87fa49f31a323b6e6bd4eff2 | https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/CenterServiceProvider.php#L49-L64 |
18,862 | wikimedia/CLDRPluralRuleParser | src/Range.php | Range.isNumberIn | function isNumberIn( $number, $integerConstraint = true ) {
foreach ( $this->parts as $part ) {
if ( is_array( $part ) ) {
if ( ( !$integerConstraint || floor( $number ) === (float)$number )
&& $number >= $part[0] && $number <= $part[1]
) {
return true;
}
} else {
if ( $number == $part ) {
return true;
}
}
}
return false;
} | php | function isNumberIn( $number, $integerConstraint = true ) {
foreach ( $this->parts as $part ) {
if ( is_array( $part ) ) {
if ( ( !$integerConstraint || floor( $number ) === (float)$number )
&& $number >= $part[0] && $number <= $part[1]
) {
return true;
}
} else {
if ( $number == $part ) {
return true;
}
}
}
return false;
} | [
"function",
"isNumberIn",
"(",
"$",
"number",
",",
"$",
"integerConstraint",
"=",
"true",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"parts",
"as",
"$",
"part",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"part",
")",
")",
"{",
"if",
"(",
"(",
"!",
"$",
"integerConstraint",
"||",
"floor",
"(",
"$",
"number",
")",
"===",
"(",
"float",
")",
"$",
"number",
")",
"&&",
"$",
"number",
">=",
"$",
"part",
"[",
"0",
"]",
"&&",
"$",
"number",
"<=",
"$",
"part",
"[",
"1",
"]",
")",
"{",
"return",
"true",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"number",
"==",
"$",
"part",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
]
| Determine if the given number is inside the range.
@param int $number The number to check
@param bool $integerConstraint If true, also asserts the number is an integer;
otherwise, number simply has to be inside the range.
@return bool True if the number is inside the range; otherwise, false. | [
"Determine",
"if",
"the",
"given",
"number",
"is",
"inside",
"the",
"range",
"."
]
| 4c5d71a3fd62a75871da8562310ca2258647ee6d | https://github.com/wikimedia/CLDRPluralRuleParser/blob/4c5d71a3fd62a75871da8562310ca2258647ee6d/src/Range.php#L44-L60 |
18,863 | wikimedia/CLDRPluralRuleParser | src/Range.php | Range.add | function add( $other ) {
if ( $other instanceof self ) {
$this->parts = array_merge( $this->parts, $other->parts );
} else {
$this->parts[] = $other;
}
} | php | function add( $other ) {
if ( $other instanceof self ) {
$this->parts = array_merge( $this->parts, $other->parts );
} else {
$this->parts[] = $other;
}
} | [
"function",
"add",
"(",
"$",
"other",
")",
"{",
"if",
"(",
"$",
"other",
"instanceof",
"self",
")",
"{",
"$",
"this",
"->",
"parts",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"parts",
",",
"$",
"other",
"->",
"parts",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"parts",
"[",
"]",
"=",
"$",
"other",
";",
"}",
"}"
]
| Add another part to this range.
@param Range|int $other The part to add, either
a range object itself or a single number. | [
"Add",
"another",
"part",
"to",
"this",
"range",
"."
]
| 4c5d71a3fd62a75871da8562310ca2258647ee6d | https://github.com/wikimedia/CLDRPluralRuleParser/blob/4c5d71a3fd62a75871da8562310ca2258647ee6d/src/Range.php#L79-L85 |
18,864 | php-rise/rise | src/Translation.php | Translation.translate | public function translate($key, $defaultValue = '', $locale = null) {
if ($locale === null) {
$locale = $this->getlocale();
}
if (isset($this->translations[$locale][$key])) {
return $this->translations[$locale][$key];
}
return $defaultValue;
} | php | public function translate($key, $defaultValue = '', $locale = null) {
if ($locale === null) {
$locale = $this->getlocale();
}
if (isset($this->translations[$locale][$key])) {
return $this->translations[$locale][$key];
}
return $defaultValue;
} | [
"public",
"function",
"translate",
"(",
"$",
"key",
",",
"$",
"defaultValue",
"=",
"''",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"locale",
"===",
"null",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"getlocale",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"translations",
"[",
"$",
"locale",
"]",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"translations",
"[",
"$",
"locale",
"]",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"defaultValue",
";",
"}"
]
| Translate an identifier to specific value.
@param string $key Translation identifier.
@param string $defaultValue Optional.
@param string $locale Optional. Specify the locale of translation result.
@return string | [
"Translate",
"an",
"identifier",
"to",
"specific",
"value",
"."
]
| cd14ef9956f1b6875b7bcd642545dcef6a9152b7 | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Translation.php#L101-L111 |
18,865 | php-rise/rise | src/Translation.php | Translation.readConfig | protected function readConfig() {
$file = $this->path->getConfigPath() . '/translation.php';
if (file_exists($file)) {
$config = require($file);
if (isset($config['translations'])) {
$this->translations = $config['translations'];
}
if (isset($config['defaultLocale'])) {
$this->setDefaultLocale($config['defaultLocale']);
}
}
return $this;
} | php | protected function readConfig() {
$file = $this->path->getConfigPath() . '/translation.php';
if (file_exists($file)) {
$config = require($file);
if (isset($config['translations'])) {
$this->translations = $config['translations'];
}
if (isset($config['defaultLocale'])) {
$this->setDefaultLocale($config['defaultLocale']);
}
}
return $this;
} | [
"protected",
"function",
"readConfig",
"(",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"path",
"->",
"getConfigPath",
"(",
")",
".",
"'/translation.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"$",
"config",
"=",
"require",
"(",
"$",
"file",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'translations'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"translations",
"=",
"$",
"config",
"[",
"'translations'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'defaultLocale'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setDefaultLocale",
"(",
"$",
"config",
"[",
"'defaultLocale'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Read configurations.
@return self | [
"Read",
"configurations",
"."
]
| cd14ef9956f1b6875b7bcd642545dcef6a9152b7 | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Translation.php#L118-L130 |
18,866 | aedart/laravel-helpers | src/Traits/Cookie/QueueingCookieTrait.php | QueueingCookieTrait.getQueueingCookie | public function getQueueingCookie(): ?QueueingFactory
{
if (!$this->hasQueueingCookie()) {
$this->setQueueingCookie($this->getDefaultQueueingCookie());
}
return $this->queueingCookie;
} | php | public function getQueueingCookie(): ?QueueingFactory
{
if (!$this->hasQueueingCookie()) {
$this->setQueueingCookie($this->getDefaultQueueingCookie());
}
return $this->queueingCookie;
} | [
"public",
"function",
"getQueueingCookie",
"(",
")",
":",
"?",
"QueueingFactory",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasQueueingCookie",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setQueueingCookie",
"(",
"$",
"this",
"->",
"getDefaultQueueingCookie",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"queueingCookie",
";",
"}"
]
| Get queueing cookie
If no queueing cookie has been set, this method will
set and return a default queueing cookie, if any such
value is available
@see getDefaultQueueingCookie()
@return QueueingFactory|null queueing cookie or null if none queueing cookie has been set | [
"Get",
"queueing",
"cookie"
]
| 8b81a2d6658f3f8cb62b6be2c34773aaa2df219a | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Cookie/QueueingCookieTrait.php#L53-L59 |
18,867 | digitalkaoz/versioneye-php | src/Http/HttpPlugHttpAdapterClient.php | HttpPlugHttpAdapterClient.buildRequestError | private function buildRequestError(PlugException $e)
{
$data = $e->getResponse() ? json_decode($e->getResponse()->getBody(), true) : ['error' => $e->getMessage()];
$message = isset($data['error']) ? $data['error'] : 'Server Error';
$status = $e->getResponse() ? $e->getResponse()->getStatusCode() : 500;
return new CommunicationException(sprintf('%s : %s', $status, $message));
} | php | private function buildRequestError(PlugException $e)
{
$data = $e->getResponse() ? json_decode($e->getResponse()->getBody(), true) : ['error' => $e->getMessage()];
$message = isset($data['error']) ? $data['error'] : 'Server Error';
$status = $e->getResponse() ? $e->getResponse()->getStatusCode() : 500;
return new CommunicationException(sprintf('%s : %s', $status, $message));
} | [
"private",
"function",
"buildRequestError",
"(",
"PlugException",
"$",
"e",
")",
"{",
"$",
"data",
"=",
"$",
"e",
"->",
"getResponse",
"(",
")",
"?",
"json_decode",
"(",
"$",
"e",
"->",
"getResponse",
"(",
")",
"->",
"getBody",
"(",
")",
",",
"true",
")",
":",
"[",
"'error'",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
"]",
";",
"$",
"message",
"=",
"isset",
"(",
"$",
"data",
"[",
"'error'",
"]",
")",
"?",
"$",
"data",
"[",
"'error'",
"]",
":",
"'Server Error'",
";",
"$",
"status",
"=",
"$",
"e",
"->",
"getResponse",
"(",
")",
"?",
"$",
"e",
"->",
"getResponse",
"(",
")",
"->",
"getStatusCode",
"(",
")",
":",
"500",
";",
"return",
"new",
"CommunicationException",
"(",
"sprintf",
"(",
"'%s : %s'",
",",
"$",
"status",
",",
"$",
"message",
")",
")",
";",
"}"
]
| builds the error exception.
@param PlugException $e
@return CommunicationException | [
"builds",
"the",
"error",
"exception",
"."
]
| 7b8eb9cdc83e01138dda0e709c07e3beb6aad136 | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Http/HttpPlugHttpAdapterClient.php#L95-L102 |
18,868 | webforge-labs/psc-cms | lib/Psc/TPL/ContentStream/ContentStreamEntity.php | ContentStreamEntity.findNextEntry | public function findNextEntry(Entry $entry) {
$list = $this->findAfter($entry, 1);
if (count($list) === 1) {
return current($list);
}
return NULL;
} | php | public function findNextEntry(Entry $entry) {
$list = $this->findAfter($entry, 1);
if (count($list) === 1) {
return current($list);
}
return NULL;
} | [
"public",
"function",
"findNextEntry",
"(",
"Entry",
"$",
"entry",
")",
"{",
"$",
"list",
"=",
"$",
"this",
"->",
"findAfter",
"(",
"$",
"entry",
",",
"1",
")",
";",
"if",
"(",
"count",
"(",
"$",
"list",
")",
"===",
"1",
")",
"{",
"return",
"current",
"(",
"$",
"list",
")",
";",
"}",
"return",
"NULL",
";",
"}"
]
| Returns the element right after the given element
if no element is after this NULL will be returned
the $entry has to be in this contentstream otherwise an exception will thrown
@return Entry|NULL | [
"Returns",
"the",
"element",
"right",
"after",
"the",
"given",
"element"
]
| 467bfa2547e6b4fa487d2d7f35fa6cc618dbc763 | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/TPL/ContentStream/ContentStreamEntity.php#L162-L170 |
18,869 | php-rise/rise | src/Container.php | Container.has | public function has($class) {
if (isset($this->singletons[$class])) {
return true;
}
if (isset($this->aliases[$class])) {
$class = $this->aliases[$class];
}
try {
$this->getReflectionClass($class);
} catch (Exception $e) {
return false;
}
return true;
} | php | public function has($class) {
if (isset($this->singletons[$class])) {
return true;
}
if (isset($this->aliases[$class])) {
$class = $this->aliases[$class];
}
try {
$this->getReflectionClass($class);
} catch (Exception $e) {
return false;
}
return true;
} | [
"public",
"function",
"has",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"singletons",
"[",
"$",
"class",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"class",
"]",
")",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"aliases",
"[",
"$",
"class",
"]",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"getReflectionClass",
"(",
"$",
"class",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Check if the class is resolvable.
@param string $class
@return bool | [
"Check",
"if",
"the",
"class",
"is",
"resolvable",
"."
]
| cd14ef9956f1b6875b7bcd642545dcef6a9152b7 | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Container.php#L134-L150 |
18,870 | php-rise/rise | src/Container.php | Container.configMethod | public function configMethod($class, $method, $rules) {
foreach ($rules as $param => $rule) {
if (ctype_upper($param[0])
&& (!is_string($rule) && !($rule instanceof Closure))
) {
throw new InvalidRuleException("Type $param only allowed string or Closure as an extra rule.");
}
}
$this->rules[$class][$method] = $rules;
return $this;
} | php | public function configMethod($class, $method, $rules) {
foreach ($rules as $param => $rule) {
if (ctype_upper($param[0])
&& (!is_string($rule) && !($rule instanceof Closure))
) {
throw new InvalidRuleException("Type $param only allowed string or Closure as an extra rule.");
}
}
$this->rules[$class][$method] = $rules;
return $this;
} | [
"public",
"function",
"configMethod",
"(",
"$",
"class",
",",
"$",
"method",
",",
"$",
"rules",
")",
"{",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"param",
"=>",
"$",
"rule",
")",
"{",
"if",
"(",
"ctype_upper",
"(",
"$",
"param",
"[",
"0",
"]",
")",
"&&",
"(",
"!",
"is_string",
"(",
"$",
"rule",
")",
"&&",
"!",
"(",
"$",
"rule",
"instanceof",
"Closure",
")",
")",
")",
"{",
"throw",
"new",
"InvalidRuleException",
"(",
"\"Type $param only allowed string or Closure as an extra rule.\"",
")",
";",
"}",
"}",
"$",
"this",
"->",
"rules",
"[",
"$",
"class",
"]",
"[",
"$",
"method",
"]",
"=",
"$",
"rules",
";",
"return",
"$",
"this",
";",
"}"
]
| Configure method parameters of a class.
@param string $class Class name.
@param string $method Method name.
@param array $rules
@return self | [
"Configure",
"method",
"parameters",
"of",
"a",
"class",
"."
]
| cd14ef9956f1b6875b7bcd642545dcef6a9152b7 | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Container.php#L172-L182 |
18,871 | php-rise/rise | src/Container.php | Container.getMethod | public function getMethod($class, $method, $extraMappings = []) {
if (isset($this->aliases[$class])) {
$class = $this->aliases[$class];
}
return [
$this->getSingleton($class),
$this->resolveArgs($class, $method, " when resolving method $class::$method", $extraMappings)
];
} | php | public function getMethod($class, $method, $extraMappings = []) {
if (isset($this->aliases[$class])) {
$class = $this->aliases[$class];
}
return [
$this->getSingleton($class),
$this->resolveArgs($class, $method, " when resolving method $class::$method", $extraMappings)
];
} | [
"public",
"function",
"getMethod",
"(",
"$",
"class",
",",
"$",
"method",
",",
"$",
"extraMappings",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"class",
"]",
")",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"aliases",
"[",
"$",
"class",
"]",
";",
"}",
"return",
"[",
"$",
"this",
"->",
"getSingleton",
"(",
"$",
"class",
")",
",",
"$",
"this",
"->",
"resolveArgs",
"(",
"$",
"class",
",",
"$",
"method",
",",
"\" when resolving method $class::$method\"",
",",
"$",
"extraMappings",
")",
"]",
";",
"}"
]
| Resolve a method for method injection.
@param string $class
@param string $method
@param array $extraMappings Optional
@return array [$instance, (string)$method, (array)$args] | [
"Resolve",
"a",
"method",
"for",
"method",
"injection",
"."
]
| cd14ef9956f1b6875b7bcd642545dcef6a9152b7 | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Container.php#L220-L229 |
18,872 | php-rise/rise | src/Container.php | Container.getNewInstance | public function getNewInstance($class) {
if (isset($this->aliases[$class])) {
$class = $this->aliases[$class];
}
$args = $this->resolveArgs($class, '__construct', " when constructing $class");
if ($args) {
$instance = new $class(...$args);
} else {
$instance = new $class;
}
return $instance;
} | php | public function getNewInstance($class) {
if (isset($this->aliases[$class])) {
$class = $this->aliases[$class];
}
$args = $this->resolveArgs($class, '__construct', " when constructing $class");
if ($args) {
$instance = new $class(...$args);
} else {
$instance = new $class;
}
return $instance;
} | [
"public",
"function",
"getNewInstance",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"class",
"]",
")",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"aliases",
"[",
"$",
"class",
"]",
";",
"}",
"$",
"args",
"=",
"$",
"this",
"->",
"resolveArgs",
"(",
"$",
"class",
",",
"'__construct'",
",",
"\" when constructing $class\"",
")",
";",
"if",
"(",
"$",
"args",
")",
"{",
"$",
"instance",
"=",
"new",
"$",
"class",
"(",
"...",
"$",
"args",
")",
";",
"}",
"else",
"{",
"$",
"instance",
"=",
"new",
"$",
"class",
";",
"}",
"return",
"$",
"instance",
";",
"}"
]
| Construct an new instance of a class with its dependencies.
@param string $class
@return object | [
"Construct",
"an",
"new",
"instance",
"of",
"a",
"class",
"with",
"its",
"dependencies",
"."
]
| cd14ef9956f1b6875b7bcd642545dcef6a9152b7 | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Container.php#L237-L250 |
18,873 | php-rise/rise | src/Container.php | Container.getSingleton | protected function getSingleton($class) {
if (isset($this->singletons[$class])) {
return $this->singletons[$class];
}
$instance = $this->getNewInstance($class);
$this->singletons[$class] = $instance;
return $instance;
} | php | protected function getSingleton($class) {
if (isset($this->singletons[$class])) {
return $this->singletons[$class];
}
$instance = $this->getNewInstance($class);
$this->singletons[$class] = $instance;
return $instance;
} | [
"protected",
"function",
"getSingleton",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"singletons",
"[",
"$",
"class",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"singletons",
"[",
"$",
"class",
"]",
";",
"}",
"$",
"instance",
"=",
"$",
"this",
"->",
"getNewInstance",
"(",
"$",
"class",
")",
";",
"$",
"this",
"->",
"singletons",
"[",
"$",
"class",
"]",
"=",
"$",
"instance",
";",
"return",
"$",
"instance",
";",
"}"
]
| Get singleton of a class.
@param string $class
@param string $method Optional
@return object|array | [
"Get",
"singleton",
"of",
"a",
"class",
"."
]
| cd14ef9956f1b6875b7bcd642545dcef6a9152b7 | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Container.php#L259-L267 |
18,874 | php-rise/rise | src/Container.php | Container.getFactory | protected function getFactory($class) {
if (isset($this->factories[$class])) {
return $this->factories[$class];
}
$factory = new $class($this);
$this->factories[$class] = $factory;
return $factory;
} | php | protected function getFactory($class) {
if (isset($this->factories[$class])) {
return $this->factories[$class];
}
$factory = new $class($this);
$this->factories[$class] = $factory;
return $factory;
} | [
"protected",
"function",
"getFactory",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"factories",
"[",
"$",
"class",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"factories",
"[",
"$",
"class",
"]",
";",
"}",
"$",
"factory",
"=",
"new",
"$",
"class",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"factories",
"[",
"$",
"class",
"]",
"=",
"$",
"factory",
";",
"return",
"$",
"factory",
";",
"}"
]
| Construct a factory instance and inject this container to the instance.
@param string $class
@return object | [
"Construct",
"a",
"factory",
"instance",
"and",
"inject",
"this",
"container",
"to",
"the",
"instance",
"."
]
| cd14ef9956f1b6875b7bcd642545dcef6a9152b7 | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Container.php#L275-L283 |
18,875 | php-rise/rise | src/Container.php | Container.getReflectionClass | protected function getReflectionClass($className) {
if (isset($this->reflectionClasses[$className])) {
return $this->reflectionClasses[$className];
}
try {
$reflectionClass = new ReflectionClass($className);
} catch (ReflectionException $e) {
throw new NotFoundException("Class $className is not found");
}
if (!$reflectionClass->isInstantiable()) {
throw new NotInstantiableException("$className is not an instantiable class");
}
$this->reflectionClasses[$className] = $reflectionClass;
return $reflectionClass;
} | php | protected function getReflectionClass($className) {
if (isset($this->reflectionClasses[$className])) {
return $this->reflectionClasses[$className];
}
try {
$reflectionClass = new ReflectionClass($className);
} catch (ReflectionException $e) {
throw new NotFoundException("Class $className is not found");
}
if (!$reflectionClass->isInstantiable()) {
throw new NotInstantiableException("$className is not an instantiable class");
}
$this->reflectionClasses[$className] = $reflectionClass;
return $reflectionClass;
} | [
"protected",
"function",
"getReflectionClass",
"(",
"$",
"className",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"reflectionClasses",
"[",
"$",
"className",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"reflectionClasses",
"[",
"$",
"className",
"]",
";",
"}",
"try",
"{",
"$",
"reflectionClass",
"=",
"new",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"}",
"catch",
"(",
"ReflectionException",
"$",
"e",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"\"Class $className is not found\"",
")",
";",
"}",
"if",
"(",
"!",
"$",
"reflectionClass",
"->",
"isInstantiable",
"(",
")",
")",
"{",
"throw",
"new",
"NotInstantiableException",
"(",
"\"$className is not an instantiable class\"",
")",
";",
"}",
"$",
"this",
"->",
"reflectionClasses",
"[",
"$",
"className",
"]",
"=",
"$",
"reflectionClass",
";",
"return",
"$",
"reflectionClass",
";",
"}"
]
| Create and cache a ReflectionClass.
@param string $className
@return \ReflectionClass | [
"Create",
"and",
"cache",
"a",
"ReflectionClass",
"."
]
| cd14ef9956f1b6875b7bcd642545dcef6a9152b7 | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Container.php#L291-L309 |
18,876 | php-rise/rise | src/Container.php | Container.getReflectionMethod | protected function getReflectionMethod($className, $methodName = '__construct') {
if (isset($this->reflectionMethods[$className])
&& array_key_exists($methodName, $this->reflectionMethods[$className])
) {
return $this->reflectionMethods[$className][$methodName];
}
try {
$reflectionClass = $this->getReflectionClass($className);
if ($methodName === '__construct') {
$reflectionMethod = $reflectionClass->getConstructor();
} else {
$reflectionMethod = $reflectionClass->getMethod($methodName);
}
$this->reflectionMethods[$className][$methodName] = $reflectionMethod;
} catch (ReflectionException $e) {
throw new NotFoundException("Method $className::$methodName is not found");
}
return $reflectionMethod;
} | php | protected function getReflectionMethod($className, $methodName = '__construct') {
if (isset($this->reflectionMethods[$className])
&& array_key_exists($methodName, $this->reflectionMethods[$className])
) {
return $this->reflectionMethods[$className][$methodName];
}
try {
$reflectionClass = $this->getReflectionClass($className);
if ($methodName === '__construct') {
$reflectionMethod = $reflectionClass->getConstructor();
} else {
$reflectionMethod = $reflectionClass->getMethod($methodName);
}
$this->reflectionMethods[$className][$methodName] = $reflectionMethod;
} catch (ReflectionException $e) {
throw new NotFoundException("Method $className::$methodName is not found");
}
return $reflectionMethod;
} | [
"protected",
"function",
"getReflectionMethod",
"(",
"$",
"className",
",",
"$",
"methodName",
"=",
"'__construct'",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"reflectionMethods",
"[",
"$",
"className",
"]",
")",
"&&",
"array_key_exists",
"(",
"$",
"methodName",
",",
"$",
"this",
"->",
"reflectionMethods",
"[",
"$",
"className",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"reflectionMethods",
"[",
"$",
"className",
"]",
"[",
"$",
"methodName",
"]",
";",
"}",
"try",
"{",
"$",
"reflectionClass",
"=",
"$",
"this",
"->",
"getReflectionClass",
"(",
"$",
"className",
")",
";",
"if",
"(",
"$",
"methodName",
"===",
"'__construct'",
")",
"{",
"$",
"reflectionMethod",
"=",
"$",
"reflectionClass",
"->",
"getConstructor",
"(",
")",
";",
"}",
"else",
"{",
"$",
"reflectionMethod",
"=",
"$",
"reflectionClass",
"->",
"getMethod",
"(",
"$",
"methodName",
")",
";",
"}",
"$",
"this",
"->",
"reflectionMethods",
"[",
"$",
"className",
"]",
"[",
"$",
"methodName",
"]",
"=",
"$",
"reflectionMethod",
";",
"}",
"catch",
"(",
"ReflectionException",
"$",
"e",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"\"Method $className::$methodName is not found\"",
")",
";",
"}",
"return",
"$",
"reflectionMethod",
";",
"}"
]
| Create and cache a ReflectionMethod.
@param string $className
@param string $methodName
@return \ReflectionMethod | [
"Create",
"and",
"cache",
"a",
"ReflectionMethod",
"."
]
| cd14ef9956f1b6875b7bcd642545dcef6a9152b7 | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Container.php#L318-L338 |
18,877 | php-rise/rise | src/Container.php | Container.resolveArgs | protected function resolveArgs($className, $methodName, $errorMessageSuffix = '', $extraMappings = []) {
$reflectionMethod = $this->getReflectionMethod($className, $methodName);
if (is_null($reflectionMethod) && $methodName === '__construct') {
return [];
}
$extraMappings = (array)$extraMappings;
if (isset($this->rules[$className][$methodName])) {
$extraMappings += $this->rules[$className][$methodName];
}
$args = [];
try {
foreach ($reflectionMethod->getParameters() as $param) {
if ($extraMappings) {
$paramName = $param->getName();
// Add argument according to parameter name.
if (array_key_exists($paramName, $extraMappings)) {
$args[] = $extraMappings[$paramName];
continue;
}
}
$paramType = $param->getType();
// Disallow primitive types.
if ($paramType->isBuiltin()) {
throw new NotAllowedException("Parameter type \"$paramType\" is not allowed" . $errorMessageSuffix);
}
$paramClassName = $param->getClass()->getName();
// Resolve by class.
if (array_key_exists($paramClassName, $extraMappings)) {
if (is_string($extraMappings[$paramClassName])) {
$args[] = $this->get($extraMappings[$paramClassName]);
} else {
$args[] = $extraMappings[$paramClassName];
}
} else {
$args[] = $this->get($paramClassName);
}
}
} catch (ReflectionException $e) {
throw new NotFoundException("Parameter class $paramType is not found" . $errorMessageSuffix);
}
return $args;
} | php | protected function resolveArgs($className, $methodName, $errorMessageSuffix = '', $extraMappings = []) {
$reflectionMethod = $this->getReflectionMethod($className, $methodName);
if (is_null($reflectionMethod) && $methodName === '__construct') {
return [];
}
$extraMappings = (array)$extraMappings;
if (isset($this->rules[$className][$methodName])) {
$extraMappings += $this->rules[$className][$methodName];
}
$args = [];
try {
foreach ($reflectionMethod->getParameters() as $param) {
if ($extraMappings) {
$paramName = $param->getName();
// Add argument according to parameter name.
if (array_key_exists($paramName, $extraMappings)) {
$args[] = $extraMappings[$paramName];
continue;
}
}
$paramType = $param->getType();
// Disallow primitive types.
if ($paramType->isBuiltin()) {
throw new NotAllowedException("Parameter type \"$paramType\" is not allowed" . $errorMessageSuffix);
}
$paramClassName = $param->getClass()->getName();
// Resolve by class.
if (array_key_exists($paramClassName, $extraMappings)) {
if (is_string($extraMappings[$paramClassName])) {
$args[] = $this->get($extraMappings[$paramClassName]);
} else {
$args[] = $extraMappings[$paramClassName];
}
} else {
$args[] = $this->get($paramClassName);
}
}
} catch (ReflectionException $e) {
throw new NotFoundException("Parameter class $paramType is not found" . $errorMessageSuffix);
}
return $args;
} | [
"protected",
"function",
"resolveArgs",
"(",
"$",
"className",
",",
"$",
"methodName",
",",
"$",
"errorMessageSuffix",
"=",
"''",
",",
"$",
"extraMappings",
"=",
"[",
"]",
")",
"{",
"$",
"reflectionMethod",
"=",
"$",
"this",
"->",
"getReflectionMethod",
"(",
"$",
"className",
",",
"$",
"methodName",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"reflectionMethod",
")",
"&&",
"$",
"methodName",
"===",
"'__construct'",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"extraMappings",
"=",
"(",
"array",
")",
"$",
"extraMappings",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"rules",
"[",
"$",
"className",
"]",
"[",
"$",
"methodName",
"]",
")",
")",
"{",
"$",
"extraMappings",
"+=",
"$",
"this",
"->",
"rules",
"[",
"$",
"className",
"]",
"[",
"$",
"methodName",
"]",
";",
"}",
"$",
"args",
"=",
"[",
"]",
";",
"try",
"{",
"foreach",
"(",
"$",
"reflectionMethod",
"->",
"getParameters",
"(",
")",
"as",
"$",
"param",
")",
"{",
"if",
"(",
"$",
"extraMappings",
")",
"{",
"$",
"paramName",
"=",
"$",
"param",
"->",
"getName",
"(",
")",
";",
"// Add argument according to parameter name.",
"if",
"(",
"array_key_exists",
"(",
"$",
"paramName",
",",
"$",
"extraMappings",
")",
")",
"{",
"$",
"args",
"[",
"]",
"=",
"$",
"extraMappings",
"[",
"$",
"paramName",
"]",
";",
"continue",
";",
"}",
"}",
"$",
"paramType",
"=",
"$",
"param",
"->",
"getType",
"(",
")",
";",
"// Disallow primitive types.",
"if",
"(",
"$",
"paramType",
"->",
"isBuiltin",
"(",
")",
")",
"{",
"throw",
"new",
"NotAllowedException",
"(",
"\"Parameter type \\\"$paramType\\\" is not allowed\"",
".",
"$",
"errorMessageSuffix",
")",
";",
"}",
"$",
"paramClassName",
"=",
"$",
"param",
"->",
"getClass",
"(",
")",
"->",
"getName",
"(",
")",
";",
"// Resolve by class.",
"if",
"(",
"array_key_exists",
"(",
"$",
"paramClassName",
",",
"$",
"extraMappings",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"extraMappings",
"[",
"$",
"paramClassName",
"]",
")",
")",
"{",
"$",
"args",
"[",
"]",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"extraMappings",
"[",
"$",
"paramClassName",
"]",
")",
";",
"}",
"else",
"{",
"$",
"args",
"[",
"]",
"=",
"$",
"extraMappings",
"[",
"$",
"paramClassName",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"args",
"[",
"]",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"paramClassName",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"ReflectionException",
"$",
"e",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"\"Parameter class $paramType is not found\"",
".",
"$",
"errorMessageSuffix",
")",
";",
"}",
"return",
"$",
"args",
";",
"}"
]
| Resolve parameters of ReflectionMethod.
@param string $className
@param string $methodName
@param string $errorMessageSuffix Optional
@param array $extraMappings Optional
@return array | [
"Resolve",
"parameters",
"of",
"ReflectionMethod",
"."
]
| cd14ef9956f1b6875b7bcd642545dcef6a9152b7 | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Container.php#L348-L400 |
18,878 | kevintweber/phpunit-markup-validators | src/Kevintweber/PhpunitMarkupValidators/Connector/HTML5ValidatorNuConnector.php | HTML5ValidatorNuConnector.setInput | public function setInput($value)
{
if (stripos($value, 'html>') === false) {
$this->input = '<!DOCTYPE html><html><head><meta charset="utf-8" /><title>Title</title></head><body>'.
$value.'</body></html>';
} else {
$this->input = $value;
}
} | php | public function setInput($value)
{
if (stripos($value, 'html>') === false) {
$this->input = '<!DOCTYPE html><html><head><meta charset="utf-8" /><title>Title</title></head><body>'.
$value.'</body></html>';
} else {
$this->input = $value;
}
} | [
"public",
"function",
"setInput",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"stripos",
"(",
"$",
"value",
",",
"'html>'",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"input",
"=",
"'<!DOCTYPE html><html><head><meta charset=\"utf-8\" /><title>Title</title></head><body>'",
".",
"$",
"value",
".",
"'</body></html>'",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"input",
"=",
"$",
"value",
";",
"}",
"}"
]
| Ensure that HTML fragments are submitted as complete webpages.
@param string $value The HTML markup, either a fragment or a complete webpage. | [
"Ensure",
"that",
"HTML",
"fragments",
"are",
"submitted",
"as",
"complete",
"webpages",
"."
]
| bee48f48c7c1c9e811d1a4bedeca8f413d049cb3 | https://github.com/kevintweber/phpunit-markup-validators/blob/bee48f48c7c1c9e811d1a4bedeca8f413d049cb3/src/Kevintweber/PhpunitMarkupValidators/Connector/HTML5ValidatorNuConnector.php#L74-L82 |
18,879 | nicklaw5/larapi | src/ResponseTrait.php | ResponseTrait.setStatusMessage | public function setStatusMessage($message)
{
$message = (string) trim($message);
if ($message === '') {
$this->statusMessage = $this->getStatusMessage();
} else {
$this->statusMessage = $message;
}
return $this;
} | php | public function setStatusMessage($message)
{
$message = (string) trim($message);
if ($message === '') {
$this->statusMessage = $this->getStatusMessage();
} else {
$this->statusMessage = $message;
}
return $this;
} | [
"public",
"function",
"setStatusMessage",
"(",
"$",
"message",
")",
"{",
"$",
"message",
"=",
"(",
"string",
")",
"trim",
"(",
"$",
"message",
")",
";",
"if",
"(",
"$",
"message",
"===",
"''",
")",
"{",
"$",
"this",
"->",
"statusMessage",
"=",
"$",
"this",
"->",
"getStatusMessage",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"statusMessage",
"=",
"$",
"message",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Sets the HTTP response message
@param string $message
@return self | [
"Sets",
"the",
"HTTP",
"response",
"message"
]
| fb3493118bb9c6ce01567230c09e8402ac148d0e | https://github.com/nicklaw5/larapi/blob/fb3493118bb9c6ce01567230c09e8402ac148d0e/src/ResponseTrait.php#L95-L106 |
18,880 | nicklaw5/larapi | src/ResponseTrait.php | ResponseTrait.setErrorMessage | public function setErrorMessage($message)
{
switch (gettype($message)) {
case 'string':
$this->errorMessage = trim($message);
break;
case 'array':
$this->errorMessage = empty($message) ? '' : $message;
break;
default:
$this->errorMessage = '';
break;
}
return $this;
} | php | public function setErrorMessage($message)
{
switch (gettype($message)) {
case 'string':
$this->errorMessage = trim($message);
break;
case 'array':
$this->errorMessage = empty($message) ? '' : $message;
break;
default:
$this->errorMessage = '';
break;
}
return $this;
} | [
"public",
"function",
"setErrorMessage",
"(",
"$",
"message",
")",
"{",
"switch",
"(",
"gettype",
"(",
"$",
"message",
")",
")",
"{",
"case",
"'string'",
":",
"$",
"this",
"->",
"errorMessage",
"=",
"trim",
"(",
"$",
"message",
")",
";",
"break",
";",
"case",
"'array'",
":",
"$",
"this",
"->",
"errorMessage",
"=",
"empty",
"(",
"$",
"message",
")",
"?",
"''",
":",
"$",
"message",
";",
"break",
";",
"default",
":",
"$",
"this",
"->",
"errorMessage",
"=",
"''",
";",
"break",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Sets the error message
@param string|array $message
@return self | [
"Sets",
"the",
"error",
"message"
]
| fb3493118bb9c6ce01567230c09e8402ac148d0e | https://github.com/nicklaw5/larapi/blob/fb3493118bb9c6ce01567230c09e8402ac148d0e/src/ResponseTrait.php#L124-L139 |
18,881 | nicklaw5/larapi | src/ResponseTrait.php | ResponseTrait.setResponseHeaders | protected function setResponseHeaders(array $headers)
{
// reset headers
$this->headers = [];
// set response status header
$this->headers[] = 'HTTP/1.1 ' . $this->getStatusCode() . ' ' . $this->getStatusText();
// set content type header
$this->headers['Content-Type'] = 'application/json';
// set user supplied headers
foreach ($headers as $key => $value) {
$this->headers[$key] = $value;
}
} | php | protected function setResponseHeaders(array $headers)
{
// reset headers
$this->headers = [];
// set response status header
$this->headers[] = 'HTTP/1.1 ' . $this->getStatusCode() . ' ' . $this->getStatusText();
// set content type header
$this->headers['Content-Type'] = 'application/json';
// set user supplied headers
foreach ($headers as $key => $value) {
$this->headers[$key] = $value;
}
} | [
"protected",
"function",
"setResponseHeaders",
"(",
"array",
"$",
"headers",
")",
"{",
"// reset headers",
"$",
"this",
"->",
"headers",
"=",
"[",
"]",
";",
"// set response status header",
"$",
"this",
"->",
"headers",
"[",
"]",
"=",
"'HTTP/1.1 '",
".",
"$",
"this",
"->",
"getStatusCode",
"(",
")",
".",
"' '",
".",
"$",
"this",
"->",
"getStatusText",
"(",
")",
";",
"// set content type header",
"$",
"this",
"->",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"'application/json'",
";",
"// set user supplied headers",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"headers",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}"
]
| Sets the response headers
@param array $headers
@return void | [
"Sets",
"the",
"response",
"headers"
]
| fb3493118bb9c6ce01567230c09e8402ac148d0e | https://github.com/nicklaw5/larapi/blob/fb3493118bb9c6ce01567230c09e8402ac148d0e/src/ResponseTrait.php#L182-L197 |
18,882 | nicklaw5/larapi | src/ResponseTrait.php | ResponseTrait.getSuccessResponse | protected function getSuccessResponse($data, $statusText, $headers = [])
{
return $this->setStatusText($this->statusTexts[$statusText])
->setStatusCode($statusText)
->setStatusMessage(self::SUCCESS_TEXT)
->respondWithSuccessMessage($data, $headers);
} | php | protected function getSuccessResponse($data, $statusText, $headers = [])
{
return $this->setStatusText($this->statusTexts[$statusText])
->setStatusCode($statusText)
->setStatusMessage(self::SUCCESS_TEXT)
->respondWithSuccessMessage($data, $headers);
} | [
"protected",
"function",
"getSuccessResponse",
"(",
"$",
"data",
",",
"$",
"statusText",
",",
"$",
"headers",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"setStatusText",
"(",
"$",
"this",
"->",
"statusTexts",
"[",
"$",
"statusText",
"]",
")",
"->",
"setStatusCode",
"(",
"$",
"statusText",
")",
"->",
"setStatusMessage",
"(",
"self",
"::",
"SUCCESS_TEXT",
")",
"->",
"respondWithSuccessMessage",
"(",
"$",
"data",
",",
"$",
"headers",
")",
";",
"}"
]
| Gets the success response
@param array $data
@param string $statusText
@param array $headers
@return json | [
"Gets",
"the",
"success",
"response"
]
| fb3493118bb9c6ce01567230c09e8402ac148d0e | https://github.com/nicklaw5/larapi/blob/fb3493118bb9c6ce01567230c09e8402ac148d0e/src/ResponseTrait.php#L207-L213 |
18,883 | nicklaw5/larapi | src/ResponseTrait.php | ResponseTrait.getErrorResponse | protected function getErrorResponse($msg, $errorCode, $statusText, $headers = [])
{
return $this->setStatusText($this->statusTexts[$statusText])
->setStatusCode($statusText)
->setStatusMessage(self::ERROR_TEXT)
->setErrorCode($errorCode)
->setErrorMessage($msg)
->respondWithErrorMessage($headers);
} | php | protected function getErrorResponse($msg, $errorCode, $statusText, $headers = [])
{
return $this->setStatusText($this->statusTexts[$statusText])
->setStatusCode($statusText)
->setStatusMessage(self::ERROR_TEXT)
->setErrorCode($errorCode)
->setErrorMessage($msg)
->respondWithErrorMessage($headers);
} | [
"protected",
"function",
"getErrorResponse",
"(",
"$",
"msg",
",",
"$",
"errorCode",
",",
"$",
"statusText",
",",
"$",
"headers",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"setStatusText",
"(",
"$",
"this",
"->",
"statusTexts",
"[",
"$",
"statusText",
"]",
")",
"->",
"setStatusCode",
"(",
"$",
"statusText",
")",
"->",
"setStatusMessage",
"(",
"self",
"::",
"ERROR_TEXT",
")",
"->",
"setErrorCode",
"(",
"$",
"errorCode",
")",
"->",
"setErrorMessage",
"(",
"$",
"msg",
")",
"->",
"respondWithErrorMessage",
"(",
"$",
"headers",
")",
";",
"}"
]
| Gets the error response
@param string $msg
@param int $errorCode
@param string $statusText
@param array $headers
@return json | [
"Gets",
"the",
"error",
"response"
]
| fb3493118bb9c6ce01567230c09e8402ac148d0e | https://github.com/nicklaw5/larapi/blob/fb3493118bb9c6ce01567230c09e8402ac148d0e/src/ResponseTrait.php#L224-L232 |
18,884 | nicklaw5/larapi | src/ResponseTrait.php | ResponseTrait.respond | protected function respond($data, $headers = [])
{
$this->setResponseHeaders($headers);
return response()->json($data, $this->getStatusCode(), $this->getResponseHeaders());
} | php | protected function respond($data, $headers = [])
{
$this->setResponseHeaders($headers);
return response()->json($data, $this->getStatusCode(), $this->getResponseHeaders());
} | [
"protected",
"function",
"respond",
"(",
"$",
"data",
",",
"$",
"headers",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setResponseHeaders",
"(",
"$",
"headers",
")",
";",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"getStatusCode",
"(",
")",
",",
"$",
"this",
"->",
"getResponseHeaders",
"(",
")",
")",
";",
"}"
]
| Returns JSON Encoded HTTP Reponse
@param array $data
@param array $headers
@return json | [
"Returns",
"JSON",
"Encoded",
"HTTP",
"Reponse"
]
| fb3493118bb9c6ce01567230c09e8402ac148d0e | https://github.com/nicklaw5/larapi/blob/fb3493118bb9c6ce01567230c09e8402ac148d0e/src/ResponseTrait.php#L285-L290 |
18,885 | laraning/surveyor | src/Traits/AppliesScopes.php | AppliesScopes.bootAppliesScopes | public static function bootAppliesScopes()
{
if (SurveyorProvider::isActive()) {
$repository = SurveyorProvider::retrieve();
foreach ($repository['scopes'] as $model => $scopes) {
foreach ($scopes as $scope) {
if (get_called_class() == $model) {
static::addGlobalScope(new $scope());
}
}
}
} else {
if (Auth::user() != null) {
// Surveyor needs to be active. Throw exception.
throw RepositoryException::notInitialized();
}
}
} | php | public static function bootAppliesScopes()
{
if (SurveyorProvider::isActive()) {
$repository = SurveyorProvider::retrieve();
foreach ($repository['scopes'] as $model => $scopes) {
foreach ($scopes as $scope) {
if (get_called_class() == $model) {
static::addGlobalScope(new $scope());
}
}
}
} else {
if (Auth::user() != null) {
// Surveyor needs to be active. Throw exception.
throw RepositoryException::notInitialized();
}
}
} | [
"public",
"static",
"function",
"bootAppliesScopes",
"(",
")",
"{",
"if",
"(",
"SurveyorProvider",
"::",
"isActive",
"(",
")",
")",
"{",
"$",
"repository",
"=",
"SurveyorProvider",
"::",
"retrieve",
"(",
")",
";",
"foreach",
"(",
"$",
"repository",
"[",
"'scopes'",
"]",
"as",
"$",
"model",
"=>",
"$",
"scopes",
")",
"{",
"foreach",
"(",
"$",
"scopes",
"as",
"$",
"scope",
")",
"{",
"if",
"(",
"get_called_class",
"(",
")",
"==",
"$",
"model",
")",
"{",
"static",
"::",
"addGlobalScope",
"(",
"new",
"$",
"scope",
"(",
")",
")",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"Auth",
"::",
"user",
"(",
")",
"!=",
"null",
")",
"{",
"// Surveyor needs to be active. Throw exception.",
"throw",
"RepositoryException",
"::",
"notInitialized",
"(",
")",
";",
"}",
"}",
"}"
]
| Apply model global scopes given the current logged user profiles.
@return void | [
"Apply",
"model",
"global",
"scopes",
"given",
"the",
"current",
"logged",
"user",
"profiles",
"."
]
| d845b74d20f9a4a307991019502c1b14b1730e86 | https://github.com/laraning/surveyor/blob/d845b74d20f9a4a307991019502c1b14b1730e86/src/Traits/AppliesScopes.php#L16-L33 |
18,886 | 2amigos/yiifoundation | widgets/base/Widget.php | Widget.registerAssets | public function registerAssets()
{
// make sure core hasn't been registered previously
$dirs = array('css', 'js');
foreach ($this->assets as $key => $files) {
if (in_array($key, $dirs)) {
$files = is_array($files) ? $files : array($files);
foreach ($files as $file) {
$filePath = Foundation::getAssetsPath() . DIRECTORY_SEPARATOR . $key . DIRECTORY_SEPARATOR . $file;
if (file_exists($filePath) && is_file($filePath)) {
$method = strcasecmp($key, 'css') === 0 ? 'registerCssFile' : 'registerScriptFile';
call_user_func(
array(\Yii::app()->clientScript, "$method"),
Foundation::getAssetsUrl() . "/$key/$file"
);
}
}
}
}
} | php | public function registerAssets()
{
// make sure core hasn't been registered previously
$dirs = array('css', 'js');
foreach ($this->assets as $key => $files) {
if (in_array($key, $dirs)) {
$files = is_array($files) ? $files : array($files);
foreach ($files as $file) {
$filePath = Foundation::getAssetsPath() . DIRECTORY_SEPARATOR . $key . DIRECTORY_SEPARATOR . $file;
if (file_exists($filePath) && is_file($filePath)) {
$method = strcasecmp($key, 'css') === 0 ? 'registerCssFile' : 'registerScriptFile';
call_user_func(
array(\Yii::app()->clientScript, "$method"),
Foundation::getAssetsUrl() . "/$key/$file"
);
}
}
}
}
} | [
"public",
"function",
"registerAssets",
"(",
")",
"{",
"// make sure core hasn't been registered previously",
"$",
"dirs",
"=",
"array",
"(",
"'css'",
",",
"'js'",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"assets",
"as",
"$",
"key",
"=>",
"$",
"files",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"dirs",
")",
")",
"{",
"$",
"files",
"=",
"is_array",
"(",
"$",
"files",
")",
"?",
"$",
"files",
":",
"array",
"(",
"$",
"files",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"filePath",
"=",
"Foundation",
"::",
"getAssetsPath",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"key",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
";",
"if",
"(",
"file_exists",
"(",
"$",
"filePath",
")",
"&&",
"is_file",
"(",
"$",
"filePath",
")",
")",
"{",
"$",
"method",
"=",
"strcasecmp",
"(",
"$",
"key",
",",
"'css'",
")",
"===",
"0",
"?",
"'registerCssFile'",
":",
"'registerScriptFile'",
";",
"call_user_func",
"(",
"array",
"(",
"\\",
"Yii",
"::",
"app",
"(",
")",
"->",
"clientScript",
",",
"\"$method\"",
")",
",",
"Foundation",
"::",
"getAssetsUrl",
"(",
")",
".",
"\"/$key/$file\"",
")",
";",
"}",
"}",
"}",
"}",
"}"
]
| Registers the assets. Makes sure the assets pre-existed on the published folder prior registration. | [
"Registers",
"the",
"assets",
".",
"Makes",
"sure",
"the",
"assets",
"pre",
"-",
"existed",
"on",
"the",
"published",
"folder",
"prior",
"registration",
"."
]
| 49bed0d3ca1a9bac9299000e48a2661bdc8f9a29 | https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/widgets/base/Widget.php#L86-L107 |
18,887 | 2amigos/yiifoundation | widgets/base/Widget.php | Widget.display | public static function display($config = array())
{
ob_start();
ob_implicit_flush(false);
/** @var Widget $widget */
$config['class'] = get_called_class();
$widget = \Yii::createComponent($config);
$widget->init();
$widget->run();
return ob_get_clean();
} | php | public static function display($config = array())
{
ob_start();
ob_implicit_flush(false);
/** @var Widget $widget */
$config['class'] = get_called_class();
$widget = \Yii::createComponent($config);
$widget->init();
$widget->run();
return ob_get_clean();
} | [
"public",
"static",
"function",
"display",
"(",
"$",
"config",
"=",
"array",
"(",
")",
")",
"{",
"ob_start",
"(",
")",
";",
"ob_implicit_flush",
"(",
"false",
")",
";",
"/** @var Widget $widget */",
"$",
"config",
"[",
"'class'",
"]",
"=",
"get_called_class",
"(",
")",
";",
"$",
"widget",
"=",
"\\",
"Yii",
"::",
"createComponent",
"(",
"$",
"config",
")",
";",
"$",
"widget",
"->",
"init",
"(",
")",
";",
"$",
"widget",
"->",
"run",
"(",
")",
";",
"return",
"ob_get_clean",
"(",
")",
";",
"}"
]
| Ported from Yii2 widget's function. Creates a widget instance and runs it. We cannot use 'widget' name as it
conflicts with CBaseController component.
The widget rendering result is returned by this method.
@param array $config name-value pairs that will be used to initialize the object properties
@return string the rendering result of the widget. | [
"Ported",
"from",
"Yii2",
"widget",
"s",
"function",
".",
"Creates",
"a",
"widget",
"instance",
"and",
"runs",
"it",
".",
"We",
"cannot",
"use",
"widget",
"name",
"as",
"it",
"conflicts",
"with",
"CBaseController",
"component",
"."
]
| 49bed0d3ca1a9bac9299000e48a2661bdc8f9a29 | https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/widgets/base/Widget.php#L117-L127 |
18,888 | uthando-cms/uthando-dompdf | src/UthandoDomPdf/Mvc/Service/ViewPdfStrategyFactory.php | ViewPdfStrategyFactory.createService | public function createService(ServiceLocatorInterface $serviceLocator)
{
$pdfRenderer = $serviceLocator->get(PdfRenderer::class);
$pdfStrategy = new PdfStrategy($pdfRenderer);
return $pdfStrategy;
} | php | public function createService(ServiceLocatorInterface $serviceLocator)
{
$pdfRenderer = $serviceLocator->get(PdfRenderer::class);
$pdfStrategy = new PdfStrategy($pdfRenderer);
return $pdfStrategy;
} | [
"public",
"function",
"createService",
"(",
"ServiceLocatorInterface",
"$",
"serviceLocator",
")",
"{",
"$",
"pdfRenderer",
"=",
"$",
"serviceLocator",
"->",
"get",
"(",
"PdfRenderer",
"::",
"class",
")",
";",
"$",
"pdfStrategy",
"=",
"new",
"PdfStrategy",
"(",
"$",
"pdfRenderer",
")",
";",
"return",
"$",
"pdfStrategy",
";",
"}"
]
| Create and return the PDF view strategy
Retrieves the ViewPdfRenderer service from the service locator, and
injects it into the constructor for the PDF strategy.
@param ServiceLocatorInterface $serviceLocator
@return PdfStrategy | [
"Create",
"and",
"return",
"the",
"PDF",
"view",
"strategy"
]
| 60a750058c2db9ed167476192b20c7f544c32007 | https://github.com/uthando-cms/uthando-dompdf/blob/60a750058c2db9ed167476192b20c7f544c32007/src/UthandoDomPdf/Mvc/Service/ViewPdfStrategyFactory.php#L34-L40 |
18,889 | timiki/rpc-common | src/JsonResponse.php | JsonResponse.getArrayResponse | public function getArrayResponse()
{
$json = [];
$json['jsonrpc'] = '2.0';
if ($this->errorCode) {
$json['error'] = [];
$json['error']['code'] = $this->errorCode;
$json['error']['message'] = $this->errorMessage;
if (!empty($this->errorData)) {
$json['error']['data'] = $this->errorData;
}
} else {
$json['result'] = $this->result;
}
$json['id'] = !empty($this->id) ? $this->id : null;
return $json;
} | php | public function getArrayResponse()
{
$json = [];
$json['jsonrpc'] = '2.0';
if ($this->errorCode) {
$json['error'] = [];
$json['error']['code'] = $this->errorCode;
$json['error']['message'] = $this->errorMessage;
if (!empty($this->errorData)) {
$json['error']['data'] = $this->errorData;
}
} else {
$json['result'] = $this->result;
}
$json['id'] = !empty($this->id) ? $this->id : null;
return $json;
} | [
"public",
"function",
"getArrayResponse",
"(",
")",
"{",
"$",
"json",
"=",
"[",
"]",
";",
"$",
"json",
"[",
"'jsonrpc'",
"]",
"=",
"'2.0'",
";",
"if",
"(",
"$",
"this",
"->",
"errorCode",
")",
"{",
"$",
"json",
"[",
"'error'",
"]",
"=",
"[",
"]",
";",
"$",
"json",
"[",
"'error'",
"]",
"[",
"'code'",
"]",
"=",
"$",
"this",
"->",
"errorCode",
";",
"$",
"json",
"[",
"'error'",
"]",
"[",
"'message'",
"]",
"=",
"$",
"this",
"->",
"errorMessage",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"errorData",
")",
")",
"{",
"$",
"json",
"[",
"'error'",
"]",
"[",
"'data'",
"]",
"=",
"$",
"this",
"->",
"errorData",
";",
"}",
"}",
"else",
"{",
"$",
"json",
"[",
"'result'",
"]",
"=",
"$",
"this",
"->",
"result",
";",
"}",
"$",
"json",
"[",
"'id'",
"]",
"=",
"!",
"empty",
"(",
"$",
"this",
"->",
"id",
")",
"?",
"$",
"this",
"->",
"id",
":",
"null",
";",
"return",
"$",
"json",
";",
"}"
]
| Return array response.
@return array | [
"Return",
"array",
"response",
"."
]
| a20e8bc92b16aa3686c4405bf5182123a5cfc750 | https://github.com/timiki/rpc-common/blob/a20e8bc92b16aa3686c4405bf5182123a5cfc750/src/JsonResponse.php#L229-L251 |
18,890 | titon/db | src/Titon/Db/Driver/Schema.php | Schema.addColumn | public function addColumn($column, $options) {
if (is_string($options)) {
$options = ['type' => $options];
}
$options = $options + [
'field' => $column,
'type' => '',
'length' => '',
'default' => '',
'comment' => '',
'charset' => '',
'collate' => '',
'null' => true,
'ai' => false,
'index' => false, // KEY index (field[, field])
'primary' => false, // [CONSTRAINT symbol] PRIMARY KEY (field[, field])
'unique' => false, // [CONSTRAINT symbol] UNIQUE KEY index (field[, field])
'foreign' => false // [CONSTRAINT symbol] FOREIGN KEY (field) REFERENCES table(field) [ON DELETE CASCADE, etc]
];
// Force to NOT NULL for primary or auto increment columns
if ($options['primary'] || $options['ai']) {
$options['null'] = false;
}
// Filter out values so that type defaults can be inherited
$this->_columns[$column] = array_filter($options, function($value) {
return ($value !== '' && $value !== false);
});
if ($options['primary']) {
$this->addPrimary($column, $options['primary']);
} else if ($options['unique']) {
$this->addUnique($column, $options['unique']);
} else if ($options['foreign']) {
$this->addForeign($column, $options['foreign']);
}
if ($options['index']) {
$this->addIndex($column, $options['index']);
}
return $this;
} | php | public function addColumn($column, $options) {
if (is_string($options)) {
$options = ['type' => $options];
}
$options = $options + [
'field' => $column,
'type' => '',
'length' => '',
'default' => '',
'comment' => '',
'charset' => '',
'collate' => '',
'null' => true,
'ai' => false,
'index' => false, // KEY index (field[, field])
'primary' => false, // [CONSTRAINT symbol] PRIMARY KEY (field[, field])
'unique' => false, // [CONSTRAINT symbol] UNIQUE KEY index (field[, field])
'foreign' => false // [CONSTRAINT symbol] FOREIGN KEY (field) REFERENCES table(field) [ON DELETE CASCADE, etc]
];
// Force to NOT NULL for primary or auto increment columns
if ($options['primary'] || $options['ai']) {
$options['null'] = false;
}
// Filter out values so that type defaults can be inherited
$this->_columns[$column] = array_filter($options, function($value) {
return ($value !== '' && $value !== false);
});
if ($options['primary']) {
$this->addPrimary($column, $options['primary']);
} else if ($options['unique']) {
$this->addUnique($column, $options['unique']);
} else if ($options['foreign']) {
$this->addForeign($column, $options['foreign']);
}
if ($options['index']) {
$this->addIndex($column, $options['index']);
}
return $this;
} | [
"public",
"function",
"addColumn",
"(",
"$",
"column",
",",
"$",
"options",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"=",
"[",
"'type'",
"=>",
"$",
"options",
"]",
";",
"}",
"$",
"options",
"=",
"$",
"options",
"+",
"[",
"'field'",
"=>",
"$",
"column",
",",
"'type'",
"=>",
"''",
",",
"'length'",
"=>",
"''",
",",
"'default'",
"=>",
"''",
",",
"'comment'",
"=>",
"''",
",",
"'charset'",
"=>",
"''",
",",
"'collate'",
"=>",
"''",
",",
"'null'",
"=>",
"true",
",",
"'ai'",
"=>",
"false",
",",
"'index'",
"=>",
"false",
",",
"// KEY index (field[, field])",
"'primary'",
"=>",
"false",
",",
"// [CONSTRAINT symbol] PRIMARY KEY (field[, field])",
"'unique'",
"=>",
"false",
",",
"// [CONSTRAINT symbol] UNIQUE KEY index (field[, field])",
"'foreign'",
"=>",
"false",
"// [CONSTRAINT symbol] FOREIGN KEY (field) REFERENCES table(field) [ON DELETE CASCADE, etc]",
"]",
";",
"// Force to NOT NULL for primary or auto increment columns",
"if",
"(",
"$",
"options",
"[",
"'primary'",
"]",
"||",
"$",
"options",
"[",
"'ai'",
"]",
")",
"{",
"$",
"options",
"[",
"'null'",
"]",
"=",
"false",
";",
"}",
"// Filter out values so that type defaults can be inherited",
"$",
"this",
"->",
"_columns",
"[",
"$",
"column",
"]",
"=",
"array_filter",
"(",
"$",
"options",
",",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"(",
"$",
"value",
"!==",
"''",
"&&",
"$",
"value",
"!==",
"false",
")",
";",
"}",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'primary'",
"]",
")",
"{",
"$",
"this",
"->",
"addPrimary",
"(",
"$",
"column",
",",
"$",
"options",
"[",
"'primary'",
"]",
")",
";",
"}",
"else",
"if",
"(",
"$",
"options",
"[",
"'unique'",
"]",
")",
"{",
"$",
"this",
"->",
"addUnique",
"(",
"$",
"column",
",",
"$",
"options",
"[",
"'unique'",
"]",
")",
";",
"}",
"else",
"if",
"(",
"$",
"options",
"[",
"'foreign'",
"]",
")",
"{",
"$",
"this",
"->",
"addForeign",
"(",
"$",
"column",
",",
"$",
"options",
"[",
"'foreign'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'index'",
"]",
")",
"{",
"$",
"this",
"->",
"addIndex",
"(",
"$",
"column",
",",
"$",
"options",
"[",
"'index'",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Add a column to the table schema.
@param string $column
@param array $options {
@type string $type The column data type (one of Titon\Db\Driver\Type)
@type int $length The column data length
@type mixed $default The default value
@type string $comment The comment
@type string $charset The character set for encoding
@type string $collation The collation set
@type bool $null Does the column allow nulls
@type bool $ai Is this an auto incrementing column
@type mixed $index Is this an index
@type mixed $primary Is this a primary key
@type mixed $unique Is this a unique key
@type mixed $foreign Is this a foreign key
}
@return $this | [
"Add",
"a",
"column",
"to",
"the",
"table",
"schema",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Schema.php#L101-L147 |
18,891 | titon/db | src/Titon/Db/Driver/Schema.php | Schema.addColumns | public function addColumns(array $columns) {
foreach ($columns as $column => $options) {
$this->addColumn($column, $options);
}
return $this;
} | php | public function addColumns(array $columns) {
foreach ($columns as $column => $options) {
$this->addColumn($column, $options);
}
return $this;
} | [
"public",
"function",
"addColumns",
"(",
"array",
"$",
"columns",
")",
"{",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"column",
"=>",
"$",
"options",
")",
"{",
"$",
"this",
"->",
"addColumn",
"(",
"$",
"column",
",",
"$",
"options",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Add multiple columns. Index is the column name, the value is the array of options.
@param array $columns
@return $this | [
"Add",
"multiple",
"columns",
".",
"Index",
"is",
"the",
"column",
"name",
"the",
"value",
"is",
"the",
"array",
"of",
"options",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Schema.php#L155-L161 |
18,892 | titon/db | src/Titon/Db/Driver/Schema.php | Schema.addForeign | public function addForeign($column, $options = []) {
if (is_string($options)) {
$options = ['references' => $options];
}
if (empty($options['references'])) {
throw new InvalidArgumentException(sprintf('Foreign key for %s must reference an external table', $column));
}
$this->_foreignKeys[$column] = $options + [
'column' => $column,
'constraint' => ''
];
} | php | public function addForeign($column, $options = []) {
if (is_string($options)) {
$options = ['references' => $options];
}
if (empty($options['references'])) {
throw new InvalidArgumentException(sprintf('Foreign key for %s must reference an external table', $column));
}
$this->_foreignKeys[$column] = $options + [
'column' => $column,
'constraint' => ''
];
} | [
"public",
"function",
"addForeign",
"(",
"$",
"column",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"=",
"[",
"'references'",
"=>",
"$",
"options",
"]",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'references'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Foreign key for %s must reference an external table'",
",",
"$",
"column",
")",
")",
";",
"}",
"$",
"this",
"->",
"_foreignKeys",
"[",
"$",
"column",
"]",
"=",
"$",
"options",
"+",
"[",
"'column'",
"=>",
"$",
"column",
",",
"'constraint'",
"=>",
"''",
"]",
";",
"}"
]
| Add a foreign key for a column.
Multiple foreign keys can exist so group by column.
@param string $column
@param string|array $options {
@type string $references A table and field that the foreign key references, should be in a "user.id" format
@type string $onUpdate Action to use for ON UPDATE clauses
@type string $onDelete Action to use for ON DELETE clauses
}
@return $this
@throws \Titon\Db\Exception\InvalidArgumentException | [
"Add",
"a",
"foreign",
"key",
"for",
"a",
"column",
".",
"Multiple",
"foreign",
"keys",
"can",
"exist",
"so",
"group",
"by",
"column",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Schema.php#L176-L189 |
18,893 | titon/db | src/Titon/Db/Driver/Schema.php | Schema.addPrimary | public function addPrimary($column, $options = false) {
$symbol = is_string($options) ? $options : '';
if (empty($this->_primaryKey)) {
$this->_primaryKey = [
'constraint' => $symbol,
'columns' => [$column]
];
} else {
$this->_primaryKey['columns'][] = $column;
}
return $this;
} | php | public function addPrimary($column, $options = false) {
$symbol = is_string($options) ? $options : '';
if (empty($this->_primaryKey)) {
$this->_primaryKey = [
'constraint' => $symbol,
'columns' => [$column]
];
} else {
$this->_primaryKey['columns'][] = $column;
}
return $this;
} | [
"public",
"function",
"addPrimary",
"(",
"$",
"column",
",",
"$",
"options",
"=",
"false",
")",
"{",
"$",
"symbol",
"=",
"is_string",
"(",
"$",
"options",
")",
"?",
"$",
"options",
":",
"''",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_primaryKey",
")",
")",
"{",
"$",
"this",
"->",
"_primaryKey",
"=",
"[",
"'constraint'",
"=>",
"$",
"symbol",
",",
"'columns'",
"=>",
"[",
"$",
"column",
"]",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_primaryKey",
"[",
"'columns'",
"]",
"[",
"]",
"=",
"$",
"column",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Add a primary key for a column. Only one primary key can exist.
However, multiple columns can exist in a primary key.
@param string $column
@param string|bool $options Provide a name to reference the constraint by
@return $this | [
"Add",
"a",
"primary",
"key",
"for",
"a",
"column",
".",
"Only",
"one",
"primary",
"key",
"can",
"exist",
".",
"However",
"multiple",
"columns",
"can",
"exist",
"in",
"a",
"primary",
"key",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Schema.php#L241-L254 |
18,894 | titon/db | src/Titon/Db/Driver/Schema.php | Schema.addUnique | public function addUnique($column, $options = []) {
$symbol = '';
$index = $column;
if (is_array($options)) {
if (isset($options['constraint'])) {
$symbol = $options['constraint'];
}
if (isset($options['index'])) {
$index = $options['index'];
}
} else if (is_string($options)) {
$index = $options;
}
if (empty($this->_uniqueKeys[$index])) {
$this->_uniqueKeys[$index] = [
'index' => $index,
'constraint' => $symbol,
'columns' => [$column]
];
} else {
$this->_uniqueKeys[$index]['columns'][] = $column;
}
} | php | public function addUnique($column, $options = []) {
$symbol = '';
$index = $column;
if (is_array($options)) {
if (isset($options['constraint'])) {
$symbol = $options['constraint'];
}
if (isset($options['index'])) {
$index = $options['index'];
}
} else if (is_string($options)) {
$index = $options;
}
if (empty($this->_uniqueKeys[$index])) {
$this->_uniqueKeys[$index] = [
'index' => $index,
'constraint' => $symbol,
'columns' => [$column]
];
} else {
$this->_uniqueKeys[$index]['columns'][] = $column;
}
} | [
"public",
"function",
"addUnique",
"(",
"$",
"column",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"symbol",
"=",
"''",
";",
"$",
"index",
"=",
"$",
"column",
";",
"if",
"(",
"is_array",
"(",
"$",
"options",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'constraint'",
"]",
")",
")",
"{",
"$",
"symbol",
"=",
"$",
"options",
"[",
"'constraint'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'index'",
"]",
")",
")",
"{",
"$",
"index",
"=",
"$",
"options",
"[",
"'index'",
"]",
";",
"}",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"options",
")",
")",
"{",
"$",
"index",
"=",
"$",
"options",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_uniqueKeys",
"[",
"$",
"index",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_uniqueKeys",
"[",
"$",
"index",
"]",
"=",
"[",
"'index'",
"=>",
"$",
"index",
",",
"'constraint'",
"=>",
"$",
"symbol",
",",
"'columns'",
"=>",
"[",
"$",
"column",
"]",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_uniqueKeys",
"[",
"$",
"index",
"]",
"[",
"'columns'",
"]",
"[",
"]",
"=",
"$",
"column",
";",
"}",
"}"
]
| Add a unique key for a column.
Multiple unique keys can exist, so group by index.
@param string $column
@param string|array $options {
@type string $constraint Provide a name to reference the constraint by
@type string $index Custom name for the index key, defaults to the column name
}
@return $this | [
"Add",
"a",
"unique",
"key",
"for",
"a",
"column",
".",
"Multiple",
"unique",
"keys",
"can",
"exist",
"so",
"group",
"by",
"index",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Schema.php#L267-L292 |
18,895 | titon/db | src/Titon/Db/Driver/Schema.php | Schema.getColumn | public function getColumn($name) {
if ($this->hasColumn($name)) {
return $this->_columns[$name];
}
throw new MissingColumnException(sprintf('Repository column %s does not exist', $name));
} | php | public function getColumn($name) {
if ($this->hasColumn($name)) {
return $this->_columns[$name];
}
throw new MissingColumnException(sprintf('Repository column %s does not exist', $name));
} | [
"public",
"function",
"getColumn",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasColumn",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_columns",
"[",
"$",
"name",
"]",
";",
"}",
"throw",
"new",
"MissingColumnException",
"(",
"sprintf",
"(",
"'Repository column %s does not exist'",
",",
"$",
"name",
")",
")",
";",
"}"
]
| Return column options by name.
@param string $name
@return array
@throws \Titon\Db\Exception\MissingColumnException | [
"Return",
"column",
"options",
"by",
"name",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Schema.php#L301-L307 |
18,896 | forxer/tao | src/Tao/Application.php | Application.getModel | public function getModel($sModel)
{
$namespacedClass = $this['database.models_namespace'] . '\\' . $sModel;
if (!isset(static::$models[$sModel])) {
static::$models[$sModel] = new $namespacedClass($this);
}
return static::$models[$sModel];
} | php | public function getModel($sModel)
{
$namespacedClass = $this['database.models_namespace'] . '\\' . $sModel;
if (!isset(static::$models[$sModel])) {
static::$models[$sModel] = new $namespacedClass($this);
}
return static::$models[$sModel];
} | [
"public",
"function",
"getModel",
"(",
"$",
"sModel",
")",
"{",
"$",
"namespacedClass",
"=",
"$",
"this",
"[",
"'database.models_namespace'",
"]",
".",
"'\\\\'",
".",
"$",
"sModel",
";",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"models",
"[",
"$",
"sModel",
"]",
")",
")",
"{",
"static",
"::",
"$",
"models",
"[",
"$",
"sModel",
"]",
"=",
"new",
"$",
"namespacedClass",
"(",
"$",
"this",
")",
";",
"}",
"return",
"static",
"::",
"$",
"models",
"[",
"$",
"sModel",
"]",
";",
"}"
]
| Return the instance of specified model.
@param string $sModel
@return \Tao\Database\Model | [
"Return",
"the",
"instance",
"of",
"specified",
"model",
"."
]
| b5e9109c244a29a72403ae6a58633ab96a67c660 | https://github.com/forxer/tao/blob/b5e9109c244a29a72403ae6a58633ab96a67c660/src/Tao/Application.php#L173-L182 |
18,897 | hpkns/laravel-front-matter | src/Hpkns/FrontMatter/Parser.php | Parser.parse | public function parse($fm, array $default = [])
{
$pieces = [];
$parsed = [];
$regexp = '/^-{3}(?:\n|\r)(.+?)-{3}(.*)$/ms';
if(preg_match($regexp, $fm, $pieces) && $yaml = $pieces[1])
{
$parsed = $this->yaml->parse($yaml, true);
if(is_array($parsed))
{
$parsed['content'] = trim($pieces[2]);
return $this->fillDefault($parsed, $default);
}
}
throw new Exceptions\FrontMatterHeaderNotFoundException('Parser failed to find a proper Front Matter header');
} | php | public function parse($fm, array $default = [])
{
$pieces = [];
$parsed = [];
$regexp = '/^-{3}(?:\n|\r)(.+?)-{3}(.*)$/ms';
if(preg_match($regexp, $fm, $pieces) && $yaml = $pieces[1])
{
$parsed = $this->yaml->parse($yaml, true);
if(is_array($parsed))
{
$parsed['content'] = trim($pieces[2]);
return $this->fillDefault($parsed, $default);
}
}
throw new Exceptions\FrontMatterHeaderNotFoundException('Parser failed to find a proper Front Matter header');
} | [
"public",
"function",
"parse",
"(",
"$",
"fm",
",",
"array",
"$",
"default",
"=",
"[",
"]",
")",
"{",
"$",
"pieces",
"=",
"[",
"]",
";",
"$",
"parsed",
"=",
"[",
"]",
";",
"$",
"regexp",
"=",
"'/^-{3}(?:\\n|\\r)(.+?)-{3}(.*)$/ms'",
";",
"if",
"(",
"preg_match",
"(",
"$",
"regexp",
",",
"$",
"fm",
",",
"$",
"pieces",
")",
"&&",
"$",
"yaml",
"=",
"$",
"pieces",
"[",
"1",
"]",
")",
"{",
"$",
"parsed",
"=",
"$",
"this",
"->",
"yaml",
"->",
"parse",
"(",
"$",
"yaml",
",",
"true",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"parsed",
")",
")",
"{",
"$",
"parsed",
"[",
"'content'",
"]",
"=",
"trim",
"(",
"$",
"pieces",
"[",
"2",
"]",
")",
";",
"return",
"$",
"this",
"->",
"fillDefault",
"(",
"$",
"parsed",
",",
"$",
"default",
")",
";",
"}",
"}",
"throw",
"new",
"Exceptions",
"\\",
"FrontMatterHeaderNotFoundException",
"(",
"'Parser failed to find a proper Front Matter header'",
")",
";",
"}"
]
| Parse a front matter file and return an array with its content
@param string $fm
@param array $default
@return array | [
"Parse",
"a",
"front",
"matter",
"file",
"and",
"return",
"an",
"array",
"with",
"its",
"content"
]
| 3bcfb442f2d5b38cefdbf79a9841770e4d3a060f | https://github.com/hpkns/laravel-front-matter/blob/3bcfb442f2d5b38cefdbf79a9841770e4d3a060f/src/Hpkns/FrontMatter/Parser.php#L31-L49 |
18,898 | hpkns/laravel-front-matter | src/Hpkns/FrontMatter/Parser.php | Parser.fillDefault | protected function fillDefault(array $parsed, array $default = [])
{
foreach($default as $key => $value)
{
if( ! isset($parsed[$key]))
{
$parsed[$key] = $value;
}
}
return $parsed;
} | php | protected function fillDefault(array $parsed, array $default = [])
{
foreach($default as $key => $value)
{
if( ! isset($parsed[$key]))
{
$parsed[$key] = $value;
}
}
return $parsed;
} | [
"protected",
"function",
"fillDefault",
"(",
"array",
"$",
"parsed",
",",
"array",
"$",
"default",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"default",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"parsed",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"parsed",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"parsed",
";",
"}"
]
| Add default value to key that are not defined in the front matter
@param array $parsed
@param array $default
@return array | [
"Add",
"default",
"value",
"to",
"key",
"that",
"are",
"not",
"defined",
"in",
"the",
"front",
"matter"
]
| 3bcfb442f2d5b38cefdbf79a9841770e4d3a060f | https://github.com/hpkns/laravel-front-matter/blob/3bcfb442f2d5b38cefdbf79a9841770e4d3a060f/src/Hpkns/FrontMatter/Parser.php#L58-L69 |
18,899 | steeffeen/FancyManiaLinks | FML/Script/Features/EntrySubmit.php | EntrySubmit.setEntry | public function setEntry(Entry $entry)
{
$entry->setScriptEvents(true)
->checkId();
$this->entry = $entry;
return $this;
} | php | public function setEntry(Entry $entry)
{
$entry->setScriptEvents(true)
->checkId();
$this->entry = $entry;
return $this;
} | [
"public",
"function",
"setEntry",
"(",
"Entry",
"$",
"entry",
")",
"{",
"$",
"entry",
"->",
"setScriptEvents",
"(",
"true",
")",
"->",
"checkId",
"(",
")",
";",
"$",
"this",
"->",
"entry",
"=",
"$",
"entry",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the Entry
@api
@param Entry $entry Entry Control
@return static | [
"Set",
"the",
"Entry"
]
| 227b0759306f0a3c75873ba50276e4163a93bfa6 | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/EntrySubmit.php#L66-L72 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.