repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
listlengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
listlengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
ClanCats/Core | src/bundles/Database/Model.php | Model.__call_property | public function __call_property( $key )
{
$result = parent::__call_property( $key );
// when we recive a relation we execute it and save it
// to the data to avoid mutlitple queries
if ( $result instanceof Model_Relation )
{
return $this->_data_store[$key] = $result->run();
}
return $result;
} | php | public function __call_property( $key )
{
$result = parent::__call_property( $key );
// when we recive a relation we execute it and save it
// to the data to avoid mutlitple queries
if ( $result instanceof Model_Relation )
{
return $this->_data_store[$key] = $result->run();
}
return $result;
} | [
"public",
"function",
"__call_property",
"(",
"$",
"key",
")",
"{",
"$",
"result",
"=",
"parent",
"::",
"__call_property",
"(",
"$",
"key",
")",
";",
"// when we recive a relation we execute it and save it",
"// to the data to avoid mutlitple queries",
"if",
"(",
"$",
"result",
"instanceof",
"Model_Relation",
")",
"{",
"return",
"$",
"this",
"->",
"_data_store",
"[",
"$",
"key",
"]",
"=",
"$",
"result",
"->",
"run",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| Call a function as a property
@param string $key
@return mixed | [
"Call",
"a",
"function",
"as",
"a",
"property"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Model.php#L227-L239 |
ClanCats/Core | src/bundles/Database/Model.php | Model.has_one | protected function has_one( $model, $foreign_key = null, $local_key = null )
{
return new Model_Relation_HasOne( $this, $model, $foreign_key, $local_key );
} | php | protected function has_one( $model, $foreign_key = null, $local_key = null )
{
return new Model_Relation_HasOne( $this, $model, $foreign_key, $local_key );
} | [
"protected",
"function",
"has_one",
"(",
"$",
"model",
",",
"$",
"foreign_key",
"=",
"null",
",",
"$",
"local_key",
"=",
"null",
")",
"{",
"return",
"new",
"Model_Relation_HasOne",
"(",
"$",
"this",
",",
"$",
"model",
",",
"$",
"foreign_key",
",",
"$",
"local_key",
")",
";",
"}"
]
| Has one releationships
Model Car:
function engine()
{
return $this->has_one( 'Car_Engine', 'car_id', 'id' );
}
@param Model $model
@param mixed $foreign_key
@param mixed $key
@return array | [
"Has",
"one",
"releationships"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Model.php#L255-L258 |
ClanCats/Core | src/bundles/Database/Model.php | Model.has_many | protected function has_many( $model, $foreign_key = null, $local_key = null )
{
return new Model_Relation_HasMany( $this, $model, $foreign_key, $local_key );
} | php | protected function has_many( $model, $foreign_key = null, $local_key = null )
{
return new Model_Relation_HasMany( $this, $model, $foreign_key, $local_key );
} | [
"protected",
"function",
"has_many",
"(",
"$",
"model",
",",
"$",
"foreign_key",
"=",
"null",
",",
"$",
"local_key",
"=",
"null",
")",
"{",
"return",
"new",
"Model_Relation_HasMany",
"(",
"$",
"this",
",",
"$",
"model",
",",
"$",
"foreign_key",
",",
"$",
"local_key",
")",
";",
"}"
]
| Has many releationships
Model Car:
function wheels()
{
return $this->has_many( 'Car_Wheel', 'car_id', 'id' );
}
@param Model $model
@param mixed $foreign_key
@param mixed $key
@return array | [
"Has",
"many",
"releationships"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Model.php#L274-L277 |
ClanCats/Core | src/bundles/Database/Model.php | Model.belongs_to | protected function belongs_to( $model, $foreign_key = null, $local_key = null )
{
return new Model_Relation_BelongsTo( $this, $model, $foreign_key, $local_key );
} | php | protected function belongs_to( $model, $foreign_key = null, $local_key = null )
{
return new Model_Relation_BelongsTo( $this, $model, $foreign_key, $local_key );
} | [
"protected",
"function",
"belongs_to",
"(",
"$",
"model",
",",
"$",
"foreign_key",
"=",
"null",
",",
"$",
"local_key",
"=",
"null",
")",
"{",
"return",
"new",
"Model_Relation_BelongsTo",
"(",
"$",
"this",
",",
"$",
"model",
",",
"$",
"foreign_key",
",",
"$",
"local_key",
")",
";",
"}"
]
| Belongs To releationships
Model Car_Engine:
function car()
{
return $this->belongs_to( 'Car', 'id', 'car_id' );
}
@param Model $model
@param mixed $foreign_key
@param mixed $key
@return array | [
"Belongs",
"To",
"releationships"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Model.php#L293-L296 |
ClanCats/Core | src/bundles/Database/Model.php | Model.with | public static function with( $with, $callback = null )
{
if ( !is_array( $with ) )
{
$with = array( $with );
}
$settings = static::_model();
$query = DB::select( $settings['table'] );
// run the callback
if ( !is_null( $callback ) )
{
call_user_func_array( $callback, array( &$query ) );
}
// alway group the result and fetch assoc
$query->forward_key( $settings['primary_key'] );
$query->fetch_arguments = array( 'assoc' );
// get the main result set
$results = static::assign( $query->run() );
$singleton = false;
if ( !is_array( $results ) )
{
$results = array( $results );
$singleton = true;
}
$ref_object = reset( $results );
// we have to sort the relationships to make sure that
// select the relations in the right order.
asort( $with );
foreach( $with as $relation => $callback )
{
if ( is_int( $relation ) && is_string( $callback ) )
{
$relation = $callback;
$callback = null;
}
if ( strpos( $relation, '.' ) !== false )
{
$relation_layers = explode( '.', $relation );
$relation_name = array_pop( $relation_layers );
$relation_collection = array();
foreach( $results as $key => &$item )
{
$curr_item = $item;
foreach( $relation_layers as $layer )
{
$curr_item = $curr_item->raw( $layer );
}
$relation_collection[] = $curr_item;
}
$ref_object = reset( $relation_collection );
$relation_object = call_user_func( array( $ref_object, $relation_name ) );
if ( $relation_object instanceof Model_Relation )
{
$relation_object->collection_assign( $relation_name, $relation_collection, $callback );
}
}
else
{
$relation_object = call_user_func( array( $ref_object, $relation ) );
if ( $relation_object instanceof Model_Relation )
{
$relation_object->collection_assign( $relation, $results, $callback );
}
}
}
if ( $singleton )
{
return reset( $results );
}
// and assign
return $results;
} | php | public static function with( $with, $callback = null )
{
if ( !is_array( $with ) )
{
$with = array( $with );
}
$settings = static::_model();
$query = DB::select( $settings['table'] );
// run the callback
if ( !is_null( $callback ) )
{
call_user_func_array( $callback, array( &$query ) );
}
// alway group the result and fetch assoc
$query->forward_key( $settings['primary_key'] );
$query->fetch_arguments = array( 'assoc' );
// get the main result set
$results = static::assign( $query->run() );
$singleton = false;
if ( !is_array( $results ) )
{
$results = array( $results );
$singleton = true;
}
$ref_object = reset( $results );
// we have to sort the relationships to make sure that
// select the relations in the right order.
asort( $with );
foreach( $with as $relation => $callback )
{
if ( is_int( $relation ) && is_string( $callback ) )
{
$relation = $callback;
$callback = null;
}
if ( strpos( $relation, '.' ) !== false )
{
$relation_layers = explode( '.', $relation );
$relation_name = array_pop( $relation_layers );
$relation_collection = array();
foreach( $results as $key => &$item )
{
$curr_item = $item;
foreach( $relation_layers as $layer )
{
$curr_item = $curr_item->raw( $layer );
}
$relation_collection[] = $curr_item;
}
$ref_object = reset( $relation_collection );
$relation_object = call_user_func( array( $ref_object, $relation_name ) );
if ( $relation_object instanceof Model_Relation )
{
$relation_object->collection_assign( $relation_name, $relation_collection, $callback );
}
}
else
{
$relation_object = call_user_func( array( $ref_object, $relation ) );
if ( $relation_object instanceof Model_Relation )
{
$relation_object->collection_assign( $relation, $results, $callback );
}
}
}
if ( $singleton )
{
return reset( $results );
}
// and assign
return $results;
} | [
"public",
"static",
"function",
"with",
"(",
"$",
"with",
",",
"$",
"callback",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"with",
")",
")",
"{",
"$",
"with",
"=",
"array",
"(",
"$",
"with",
")",
";",
"}",
"$",
"settings",
"=",
"static",
"::",
"_model",
"(",
")",
";",
"$",
"query",
"=",
"DB",
"::",
"select",
"(",
"$",
"settings",
"[",
"'table'",
"]",
")",
";",
"// run the callback",
"if",
"(",
"!",
"is_null",
"(",
"$",
"callback",
")",
")",
"{",
"call_user_func_array",
"(",
"$",
"callback",
",",
"array",
"(",
"&",
"$",
"query",
")",
")",
";",
"}",
"// alway group the result and fetch assoc",
"$",
"query",
"->",
"forward_key",
"(",
"$",
"settings",
"[",
"'primary_key'",
"]",
")",
";",
"$",
"query",
"->",
"fetch_arguments",
"=",
"array",
"(",
"'assoc'",
")",
";",
"// get the main result set",
"$",
"results",
"=",
"static",
"::",
"assign",
"(",
"$",
"query",
"->",
"run",
"(",
")",
")",
";",
"$",
"singleton",
"=",
"false",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"results",
")",
")",
"{",
"$",
"results",
"=",
"array",
"(",
"$",
"results",
")",
";",
"$",
"singleton",
"=",
"true",
";",
"}",
"$",
"ref_object",
"=",
"reset",
"(",
"$",
"results",
")",
";",
"// we have to sort the relationships to make sure that",
"// select the relations in the right order.\t",
"asort",
"(",
"$",
"with",
")",
";",
"foreach",
"(",
"$",
"with",
"as",
"$",
"relation",
"=>",
"$",
"callback",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"relation",
")",
"&&",
"is_string",
"(",
"$",
"callback",
")",
")",
"{",
"$",
"relation",
"=",
"$",
"callback",
";",
"$",
"callback",
"=",
"null",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"relation",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"$",
"relation_layers",
"=",
"explode",
"(",
"'.'",
",",
"$",
"relation",
")",
";",
"$",
"relation_name",
"=",
"array_pop",
"(",
"$",
"relation_layers",
")",
";",
"$",
"relation_collection",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"results",
"as",
"$",
"key",
"=>",
"&",
"$",
"item",
")",
"{",
"$",
"curr_item",
"=",
"$",
"item",
";",
"foreach",
"(",
"$",
"relation_layers",
"as",
"$",
"layer",
")",
"{",
"$",
"curr_item",
"=",
"$",
"curr_item",
"->",
"raw",
"(",
"$",
"layer",
")",
";",
"}",
"$",
"relation_collection",
"[",
"]",
"=",
"$",
"curr_item",
";",
"}",
"$",
"ref_object",
"=",
"reset",
"(",
"$",
"relation_collection",
")",
";",
"$",
"relation_object",
"=",
"call_user_func",
"(",
"array",
"(",
"$",
"ref_object",
",",
"$",
"relation_name",
")",
")",
";",
"if",
"(",
"$",
"relation_object",
"instanceof",
"Model_Relation",
")",
"{",
"$",
"relation_object",
"->",
"collection_assign",
"(",
"$",
"relation_name",
",",
"$",
"relation_collection",
",",
"$",
"callback",
")",
";",
"}",
"}",
"else",
"{",
"$",
"relation_object",
"=",
"call_user_func",
"(",
"array",
"(",
"$",
"ref_object",
",",
"$",
"relation",
")",
")",
";",
"if",
"(",
"$",
"relation_object",
"instanceof",
"Model_Relation",
")",
"{",
"$",
"relation_object",
"->",
"collection_assign",
"(",
"$",
"relation",
",",
"$",
"results",
",",
"$",
"callback",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"singleton",
")",
"{",
"return",
"reset",
"(",
"$",
"results",
")",
";",
"}",
"// and assign",
"return",
"$",
"results",
";",
"}"
]
| find with an relationship
Person::with( 'cars' );
@param array|string $with
@param callback $callback
@return array | [
"find",
"with",
"an",
"relationship"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Model.php#L307-L398 |
ClanCats/Core | src/bundles/Database/Model.php | Model.save | public function save( $fields = null )
{
$settings = static::_model();
// check if we should save just some fields
if ( is_null( $fields ) )
{
$fields = array_keys( $settings['defaults'] );
}
elseif ( !is_array( $fields ) )
{
$fields = array( $fields );
}
$pkey = $this->_data_store[$settings['primary_key']];
$data = array();
// Now we have to filter the data to the save g
foreach( $fields as $field )
{
$data[$field] = $this->_data_store[$field];
}
// We have to remove the primary key from our data
if ( array_key_exists( $settings['primary_key'], $data ) )
{
unset( $data[$settings['primary_key']] );
}
// We pass the data trough the before save callback.
// This is a local callback for performence reasons.
$data = $this->_before_save( $data );
// after the before save event,
// do we have to to something with the data type?
foreach( $data as $key => $value )
{
if ( array_key_exists( $key, $settings['types'] ) )
{
$data[$key] = $this->_type_assignment_set( $settings['types'][$key], $value );
}
}
// check if we have to set the timestamps automatically
if ( $settings['timestamps'] === true )
{
if ( array_key_exists( 'created_at', $data ) )
{
// check if created_at should be set
if ( $data['created_at'] < 1 )
{
$this->_data_store['created_at'] = $data['created_at'] = time();
}
}
if ( array_key_exists( 'modified_at', $data ) )
{
$this->_data_store['modified_at'] =$data['modified_at'] = time();
}
}
// When we already have a primary key we are going to
// update our record instead of inserting a new one.
if ( !is_null( $pkey ) && $pkey > 0 )
{
$query = DB::update( $settings['table'], $data )
->where( $settings['primary_key'], $pkey );
}
// No primary key? Smells like an insert query.
else
{
$query = DB::insert( $settings['table'], $data );
}
// We check the query type to handle the response right
if ( $query instanceof Query_Insert )
{
$this->_data_store[$settings['primary_key']] = $query->run();
}
else
{
$query->run();
}
// after save hookt
$this->_after_save();
// return self
return $this;
} | php | public function save( $fields = null )
{
$settings = static::_model();
// check if we should save just some fields
if ( is_null( $fields ) )
{
$fields = array_keys( $settings['defaults'] );
}
elseif ( !is_array( $fields ) )
{
$fields = array( $fields );
}
$pkey = $this->_data_store[$settings['primary_key']];
$data = array();
// Now we have to filter the data to the save g
foreach( $fields as $field )
{
$data[$field] = $this->_data_store[$field];
}
// We have to remove the primary key from our data
if ( array_key_exists( $settings['primary_key'], $data ) )
{
unset( $data[$settings['primary_key']] );
}
// We pass the data trough the before save callback.
// This is a local callback for performence reasons.
$data = $this->_before_save( $data );
// after the before save event,
// do we have to to something with the data type?
foreach( $data as $key => $value )
{
if ( array_key_exists( $key, $settings['types'] ) )
{
$data[$key] = $this->_type_assignment_set( $settings['types'][$key], $value );
}
}
// check if we have to set the timestamps automatically
if ( $settings['timestamps'] === true )
{
if ( array_key_exists( 'created_at', $data ) )
{
// check if created_at should be set
if ( $data['created_at'] < 1 )
{
$this->_data_store['created_at'] = $data['created_at'] = time();
}
}
if ( array_key_exists( 'modified_at', $data ) )
{
$this->_data_store['modified_at'] =$data['modified_at'] = time();
}
}
// When we already have a primary key we are going to
// update our record instead of inserting a new one.
if ( !is_null( $pkey ) && $pkey > 0 )
{
$query = DB::update( $settings['table'], $data )
->where( $settings['primary_key'], $pkey );
}
// No primary key? Smells like an insert query.
else
{
$query = DB::insert( $settings['table'], $data );
}
// We check the query type to handle the response right
if ( $query instanceof Query_Insert )
{
$this->_data_store[$settings['primary_key']] = $query->run();
}
else
{
$query->run();
}
// after save hookt
$this->_after_save();
// return self
return $this;
} | [
"public",
"function",
"save",
"(",
"$",
"fields",
"=",
"null",
")",
"{",
"$",
"settings",
"=",
"static",
"::",
"_model",
"(",
")",
";",
"// check if we should save just some fields",
"if",
"(",
"is_null",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"fields",
"=",
"array_keys",
"(",
"$",
"settings",
"[",
"'defaults'",
"]",
")",
";",
"}",
"elseif",
"(",
"!",
"is_array",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"fields",
"=",
"array",
"(",
"$",
"fields",
")",
";",
"}",
"$",
"pkey",
"=",
"$",
"this",
"->",
"_data_store",
"[",
"$",
"settings",
"[",
"'primary_key'",
"]",
"]",
";",
"$",
"data",
"=",
"array",
"(",
")",
";",
"// Now we have to filter the data to the save g",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"data",
"[",
"$",
"field",
"]",
"=",
"$",
"this",
"->",
"_data_store",
"[",
"$",
"field",
"]",
";",
"}",
"// We have to remove the primary key from our data",
"if",
"(",
"array_key_exists",
"(",
"$",
"settings",
"[",
"'primary_key'",
"]",
",",
"$",
"data",
")",
")",
"{",
"unset",
"(",
"$",
"data",
"[",
"$",
"settings",
"[",
"'primary_key'",
"]",
"]",
")",
";",
"}",
"// We pass the data trough the before save callback.",
"// This is a local callback for performence reasons.",
"$",
"data",
"=",
"$",
"this",
"->",
"_before_save",
"(",
"$",
"data",
")",
";",
"// after the before save event,",
"// do we have to to something with the data type?",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"settings",
"[",
"'types'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"_type_assignment_set",
"(",
"$",
"settings",
"[",
"'types'",
"]",
"[",
"$",
"key",
"]",
",",
"$",
"value",
")",
";",
"}",
"}",
"// check if we have to set the timestamps automatically",
"if",
"(",
"$",
"settings",
"[",
"'timestamps'",
"]",
"===",
"true",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"'created_at'",
",",
"$",
"data",
")",
")",
"{",
"// check if created_at should be set",
"if",
"(",
"$",
"data",
"[",
"'created_at'",
"]",
"<",
"1",
")",
"{",
"$",
"this",
"->",
"_data_store",
"[",
"'created_at'",
"]",
"=",
"$",
"data",
"[",
"'created_at'",
"]",
"=",
"time",
"(",
")",
";",
"}",
"}",
"if",
"(",
"array_key_exists",
"(",
"'modified_at'",
",",
"$",
"data",
")",
")",
"{",
"$",
"this",
"->",
"_data_store",
"[",
"'modified_at'",
"]",
"=",
"$",
"data",
"[",
"'modified_at'",
"]",
"=",
"time",
"(",
")",
";",
"}",
"}",
"// When we already have a primary key we are going to ",
"// update our record instead of inserting a new one.",
"if",
"(",
"!",
"is_null",
"(",
"$",
"pkey",
")",
"&&",
"$",
"pkey",
">",
"0",
")",
"{",
"$",
"query",
"=",
"DB",
"::",
"update",
"(",
"$",
"settings",
"[",
"'table'",
"]",
",",
"$",
"data",
")",
"->",
"where",
"(",
"$",
"settings",
"[",
"'primary_key'",
"]",
",",
"$",
"pkey",
")",
";",
"}",
"// No primary key? Smells like an insert query. ",
"else",
"{",
"$",
"query",
"=",
"DB",
"::",
"insert",
"(",
"$",
"settings",
"[",
"'table'",
"]",
",",
"$",
"data",
")",
";",
"}",
"// We check the query type to handle the response right",
"if",
"(",
"$",
"query",
"instanceof",
"Query_Insert",
")",
"{",
"$",
"this",
"->",
"_data_store",
"[",
"$",
"settings",
"[",
"'primary_key'",
"]",
"]",
"=",
"$",
"query",
"->",
"run",
"(",
")",
";",
"}",
"else",
"{",
"$",
"query",
"->",
"run",
"(",
")",
";",
"}",
"// after save hookt",
"$",
"this",
"->",
"_after_save",
"(",
")",
";",
"// return self",
"return",
"$",
"this",
";",
"}"
]
| save an model
@param mixed $fields
@return self | [
"save",
"an",
"model"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Model.php#L406-L495 |
ClanCats/Core | src/bundles/Database/Model.php | Model.delete | public function delete()
{
$settings = static::_model();
$result = DB::delete( $settings['table'] )
->where( $settings['primary_key'], $this->_data_store[$settings['primary_key']] )
->limit(1)
->run( $settings['handler'] );
$this->_data_store[$cache['primary_key']] = null;
return $result;
} | php | public function delete()
{
$settings = static::_model();
$result = DB::delete( $settings['table'] )
->where( $settings['primary_key'], $this->_data_store[$settings['primary_key']] )
->limit(1)
->run( $settings['handler'] );
$this->_data_store[$cache['primary_key']] = null;
return $result;
} | [
"public",
"function",
"delete",
"(",
")",
"{",
"$",
"settings",
"=",
"static",
"::",
"_model",
"(",
")",
";",
"$",
"result",
"=",
"DB",
"::",
"delete",
"(",
"$",
"settings",
"[",
"'table'",
"]",
")",
"->",
"where",
"(",
"$",
"settings",
"[",
"'primary_key'",
"]",
",",
"$",
"this",
"->",
"_data_store",
"[",
"$",
"settings",
"[",
"'primary_key'",
"]",
"]",
")",
"->",
"limit",
"(",
"1",
")",
"->",
"run",
"(",
"$",
"settings",
"[",
"'handler'",
"]",
")",
";",
"$",
"this",
"->",
"_data_store",
"[",
"$",
"cache",
"[",
"'primary_key'",
"]",
"]",
"=",
"null",
";",
"return",
"$",
"result",
";",
"}"
]
| Delete the current model from the database
@return DB\Model | [
"Delete",
"the",
"current",
"model",
"from",
"the",
"database"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Model.php#L512-L524 |
aedart/laravel-helpers | src/Traits/Encryption/CryptTrait.php | CryptTrait.getCrypt | public function getCrypt(): ?Encrypter
{
if (!$this->hasCrypt()) {
$this->setCrypt($this->getDefaultCrypt());
}
return $this->crypt;
} | php | public function getCrypt(): ?Encrypter
{
if (!$this->hasCrypt()) {
$this->setCrypt($this->getDefaultCrypt());
}
return $this->crypt;
} | [
"public",
"function",
"getCrypt",
"(",
")",
":",
"?",
"Encrypter",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasCrypt",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setCrypt",
"(",
"$",
"this",
"->",
"getDefaultCrypt",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"crypt",
";",
"}"
]
| Get crypt
If no crypt has been set, this method will
set and return a default crypt, if any such
value is available
@see getDefaultCrypt()
@return Encrypter|null crypt or null if none crypt has been set | [
"Get",
"crypt"
]
| train | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Encryption/CryptTrait.php#L53-L59 |
slashworks/control-bundle | src/Slashworks/AppBundle/Model/ApiLog.php | ApiLog.create | public static function create($statuscode,$remote_app_id, $last_response){
$aLogs = ApiLogQuery::create()->findByRemoteAppId($remote_app_id);
foreach($aLogs as $oLog){
$oLog->delete();
}
$oApiLog = new ApiLog();
$oApiLog->setRemoteAppId($remote_app_id);
$oApiLog->setStatuscode($statuscode);
$oApiLog->setLastResponse($last_response);
$dt = new \DateTime();
$oApiLog->setDtCall($dt);
$oApiLog->save();
} | php | public static function create($statuscode,$remote_app_id, $last_response){
$aLogs = ApiLogQuery::create()->findByRemoteAppId($remote_app_id);
foreach($aLogs as $oLog){
$oLog->delete();
}
$oApiLog = new ApiLog();
$oApiLog->setRemoteAppId($remote_app_id);
$oApiLog->setStatuscode($statuscode);
$oApiLog->setLastResponse($last_response);
$dt = new \DateTime();
$oApiLog->setDtCall($dt);
$oApiLog->save();
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"statuscode",
",",
"$",
"remote_app_id",
",",
"$",
"last_response",
")",
"{",
"$",
"aLogs",
"=",
"ApiLogQuery",
"::",
"create",
"(",
")",
"->",
"findByRemoteAppId",
"(",
"$",
"remote_app_id",
")",
";",
"foreach",
"(",
"$",
"aLogs",
"as",
"$",
"oLog",
")",
"{",
"$",
"oLog",
"->",
"delete",
"(",
")",
";",
"}",
"$",
"oApiLog",
"=",
"new",
"ApiLog",
"(",
")",
";",
"$",
"oApiLog",
"->",
"setRemoteAppId",
"(",
"$",
"remote_app_id",
")",
";",
"$",
"oApiLog",
"->",
"setStatuscode",
"(",
"$",
"statuscode",
")",
";",
"$",
"oApiLog",
"->",
"setLastResponse",
"(",
"$",
"last_response",
")",
";",
"$",
"dt",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"oApiLog",
"->",
"setDtCall",
"(",
"$",
"dt",
")",
";",
"$",
"oApiLog",
"->",
"save",
"(",
")",
";",
"}"
]
| @param $statuscode
@param $remote_app_id
@param $last_response
@throws \Exception
@throws \PropelException | [
"@param",
"$statuscode",
"@param",
"$remote_app_id",
"@param",
"$last_response"
]
| train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/ApiLog.php#L23-L37 |
yuncms/framework | src/widgets/CssBlock.php | CssBlock.run | public function run()
{
$block = ob_get_clean();
if ($this->renderInPlace) {
throw new Exception("not implemented yet ! ");
}
$block = trim($block);
$cssBlockPattern = '|^<style[^>]*>(?P<blockContent>.+?)</style>$|is';
if (preg_match($cssBlockPattern, $block, $matches)) {
$block = $matches['blockContent'];
}
$this->view->registerCss($block, $this->options, $this->key);
} | php | public function run()
{
$block = ob_get_clean();
if ($this->renderInPlace) {
throw new Exception("not implemented yet ! ");
}
$block = trim($block);
$cssBlockPattern = '|^<style[^>]*>(?P<blockContent>.+?)</style>$|is';
if (preg_match($cssBlockPattern, $block, $matches)) {
$block = $matches['blockContent'];
}
$this->view->registerCss($block, $this->options, $this->key);
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"block",
"=",
"ob_get_clean",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"renderInPlace",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"not implemented yet ! \"",
")",
";",
"}",
"$",
"block",
"=",
"trim",
"(",
"$",
"block",
")",
";",
"$",
"cssBlockPattern",
"=",
"'|^<style[^>]*>(?P<blockContent>.+?)</style>$|is'",
";",
"if",
"(",
"preg_match",
"(",
"$",
"cssBlockPattern",
",",
"$",
"block",
",",
"$",
"matches",
")",
")",
"{",
"$",
"block",
"=",
"$",
"matches",
"[",
"'blockContent'",
"]",
";",
"}",
"$",
"this",
"->",
"view",
"->",
"registerCss",
"(",
"$",
"block",
",",
"$",
"this",
"->",
"options",
",",
"$",
"this",
"->",
"key",
")",
";",
"}"
]
| Ends recording a block.
This method stops output buffering and saves the rendering result as a named block in the view.
@throws Exception | [
"Ends",
"recording",
"a",
"block",
".",
"This",
"method",
"stops",
"output",
"buffering",
"and",
"saves",
"the",
"rendering",
"result",
"as",
"a",
"named",
"block",
"in",
"the",
"view",
"."
]
| train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/widgets/CssBlock.php#L39-L51 |
Ocramius/OcraDiCompiler | src/OcraDiCompiler/Mvc/Service/ViewHelperManagerFactory.php | ViewHelperManagerFactory.createService | public function createService(ServiceLocatorInterface $serviceLocator)
{
$pluginManagerClass = static::PLUGIN_MANAGER_CLASS;
$plugins = new $pluginManagerClass;
$plugins->setServiceLocator($serviceLocator);
$configuration = $serviceLocator->get('Config');
if (isset($configuration['di']) && $serviceLocator->has('Di')) {
$di = $serviceLocator->get('Di');
$plugins->addAbstractFactory(
new DiAbstractServiceFactory($di, DiAbstractServiceFactory::USE_SL_BEFORE_DI)
);
}
foreach ($this->defaultHelperMapClasses as $configClass) {
if (is_string($configClass) && class_exists($configClass)) {
$config = new $configClass;
}
if (!$config instanceof ConfigInterface) {
throw new Exception\RuntimeException(sprintf(
'Invalid service manager configuration class provided; received "%s", expected class implementing %s',
$configClass,
'Zend\ServiceManager\ConfigInterface'
));
}
$config->configureServiceManager($plugins);
}
// Configure URL view helper with router
$plugins->setFactory('url', function($sm) use($serviceLocator) {
$helper = new ViewHelper\Url;
$helper->setRouter($serviceLocator->get('Router'));
$match = $serviceLocator->get('application')
->getMvcEvent()
->getRouteMatch();
if ($match instanceof RouteMatch) {
$helper->setRouteMatch($match);
}
return $helper;
});
$plugins->setFactory('basepath', function($sm) use($serviceLocator) {
$config = $serviceLocator->get('Config');
$config = $config['view_manager'];
$basePathHelper = new ViewHelper\BasePath;
if (isset($config['base_path'])) {
$basePath = $config['base_path'];
} else {
$basePath = $serviceLocator->get('Request')->getBasePath();
}
$basePathHelper->setBasePath($basePath);
return $basePathHelper;
});
/**
* Configure doctype view helper with doctype from configuration, if available.
*
* Other view helpers depend on this to decide which spec to generate their tags
* based on. This is why it must be set early instead of later in the layout phtml.
*/
$plugins->setFactory('doctype', function($sm) use($serviceLocator) {
$config = $serviceLocator->get('Config');
$config = $config['view_manager'];
$doctypeHelper = new ViewHelper\Doctype;
if (isset($config['doctype'])) {
$doctypeHelper->setDoctype($config['doctype']);
}
return $doctypeHelper;
});
return $plugins;
} | php | public function createService(ServiceLocatorInterface $serviceLocator)
{
$pluginManagerClass = static::PLUGIN_MANAGER_CLASS;
$plugins = new $pluginManagerClass;
$plugins->setServiceLocator($serviceLocator);
$configuration = $serviceLocator->get('Config');
if (isset($configuration['di']) && $serviceLocator->has('Di')) {
$di = $serviceLocator->get('Di');
$plugins->addAbstractFactory(
new DiAbstractServiceFactory($di, DiAbstractServiceFactory::USE_SL_BEFORE_DI)
);
}
foreach ($this->defaultHelperMapClasses as $configClass) {
if (is_string($configClass) && class_exists($configClass)) {
$config = new $configClass;
}
if (!$config instanceof ConfigInterface) {
throw new Exception\RuntimeException(sprintf(
'Invalid service manager configuration class provided; received "%s", expected class implementing %s',
$configClass,
'Zend\ServiceManager\ConfigInterface'
));
}
$config->configureServiceManager($plugins);
}
// Configure URL view helper with router
$plugins->setFactory('url', function($sm) use($serviceLocator) {
$helper = new ViewHelper\Url;
$helper->setRouter($serviceLocator->get('Router'));
$match = $serviceLocator->get('application')
->getMvcEvent()
->getRouteMatch();
if ($match instanceof RouteMatch) {
$helper->setRouteMatch($match);
}
return $helper;
});
$plugins->setFactory('basepath', function($sm) use($serviceLocator) {
$config = $serviceLocator->get('Config');
$config = $config['view_manager'];
$basePathHelper = new ViewHelper\BasePath;
if (isset($config['base_path'])) {
$basePath = $config['base_path'];
} else {
$basePath = $serviceLocator->get('Request')->getBasePath();
}
$basePathHelper->setBasePath($basePath);
return $basePathHelper;
});
/**
* Configure doctype view helper with doctype from configuration, if available.
*
* Other view helpers depend on this to decide which spec to generate their tags
* based on. This is why it must be set early instead of later in the layout phtml.
*/
$plugins->setFactory('doctype', function($sm) use($serviceLocator) {
$config = $serviceLocator->get('Config');
$config = $config['view_manager'];
$doctypeHelper = new ViewHelper\Doctype;
if (isset($config['doctype'])) {
$doctypeHelper->setDoctype($config['doctype']);
}
return $doctypeHelper;
});
return $plugins;
} | [
"public",
"function",
"createService",
"(",
"ServiceLocatorInterface",
"$",
"serviceLocator",
")",
"{",
"$",
"pluginManagerClass",
"=",
"static",
"::",
"PLUGIN_MANAGER_CLASS",
";",
"$",
"plugins",
"=",
"new",
"$",
"pluginManagerClass",
";",
"$",
"plugins",
"->",
"setServiceLocator",
"(",
"$",
"serviceLocator",
")",
";",
"$",
"configuration",
"=",
"$",
"serviceLocator",
"->",
"get",
"(",
"'Config'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"configuration",
"[",
"'di'",
"]",
")",
"&&",
"$",
"serviceLocator",
"->",
"has",
"(",
"'Di'",
")",
")",
"{",
"$",
"di",
"=",
"$",
"serviceLocator",
"->",
"get",
"(",
"'Di'",
")",
";",
"$",
"plugins",
"->",
"addAbstractFactory",
"(",
"new",
"DiAbstractServiceFactory",
"(",
"$",
"di",
",",
"DiAbstractServiceFactory",
"::",
"USE_SL_BEFORE_DI",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"defaultHelperMapClasses",
"as",
"$",
"configClass",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"configClass",
")",
"&&",
"class_exists",
"(",
"$",
"configClass",
")",
")",
"{",
"$",
"config",
"=",
"new",
"$",
"configClass",
";",
"}",
"if",
"(",
"!",
"$",
"config",
"instanceof",
"ConfigInterface",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Invalid service manager configuration class provided; received \"%s\", expected class implementing %s'",
",",
"$",
"configClass",
",",
"'Zend\\ServiceManager\\ConfigInterface'",
")",
")",
";",
"}",
"$",
"config",
"->",
"configureServiceManager",
"(",
"$",
"plugins",
")",
";",
"}",
"// Configure URL view helper with router",
"$",
"plugins",
"->",
"setFactory",
"(",
"'url'",
",",
"function",
"(",
"$",
"sm",
")",
"use",
"(",
"$",
"serviceLocator",
")",
"{",
"$",
"helper",
"=",
"new",
"ViewHelper",
"\\",
"Url",
";",
"$",
"helper",
"->",
"setRouter",
"(",
"$",
"serviceLocator",
"->",
"get",
"(",
"'Router'",
")",
")",
";",
"$",
"match",
"=",
"$",
"serviceLocator",
"->",
"get",
"(",
"'application'",
")",
"->",
"getMvcEvent",
"(",
")",
"->",
"getRouteMatch",
"(",
")",
";",
"if",
"(",
"$",
"match",
"instanceof",
"RouteMatch",
")",
"{",
"$",
"helper",
"->",
"setRouteMatch",
"(",
"$",
"match",
")",
";",
"}",
"return",
"$",
"helper",
";",
"}",
")",
";",
"$",
"plugins",
"->",
"setFactory",
"(",
"'basepath'",
",",
"function",
"(",
"$",
"sm",
")",
"use",
"(",
"$",
"serviceLocator",
")",
"{",
"$",
"config",
"=",
"$",
"serviceLocator",
"->",
"get",
"(",
"'Config'",
")",
";",
"$",
"config",
"=",
"$",
"config",
"[",
"'view_manager'",
"]",
";",
"$",
"basePathHelper",
"=",
"new",
"ViewHelper",
"\\",
"BasePath",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'base_path'",
"]",
")",
")",
"{",
"$",
"basePath",
"=",
"$",
"config",
"[",
"'base_path'",
"]",
";",
"}",
"else",
"{",
"$",
"basePath",
"=",
"$",
"serviceLocator",
"->",
"get",
"(",
"'Request'",
")",
"->",
"getBasePath",
"(",
")",
";",
"}",
"$",
"basePathHelper",
"->",
"setBasePath",
"(",
"$",
"basePath",
")",
";",
"return",
"$",
"basePathHelper",
";",
"}",
")",
";",
"/**\n * Configure doctype view helper with doctype from configuration, if available.\n *\n * Other view helpers depend on this to decide which spec to generate their tags\n * based on. This is why it must be set early instead of later in the layout phtml.\n */",
"$",
"plugins",
"->",
"setFactory",
"(",
"'doctype'",
",",
"function",
"(",
"$",
"sm",
")",
"use",
"(",
"$",
"serviceLocator",
")",
"{",
"$",
"config",
"=",
"$",
"serviceLocator",
"->",
"get",
"(",
"'Config'",
")",
";",
"$",
"config",
"=",
"$",
"config",
"[",
"'view_manager'",
"]",
";",
"$",
"doctypeHelper",
"=",
"new",
"ViewHelper",
"\\",
"Doctype",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'doctype'",
"]",
")",
")",
"{",
"$",
"doctypeHelper",
"->",
"setDoctype",
"(",
"$",
"config",
"[",
"'doctype'",
"]",
")",
";",
"}",
"return",
"$",
"doctypeHelper",
";",
"}",
")",
";",
"return",
"$",
"plugins",
";",
"}"
]
| Create and return the view helper manager
@param ServiceLocatorInterface $serviceLocator
@return ViewHelperInterface
@throws Exception\RuntimeException | [
"Create",
"and",
"return",
"the",
"view",
"helper",
"manager"
]
| train | https://github.com/Ocramius/OcraDiCompiler/blob/667f4b24771f27fb9c8d6c38ffaf72d9cd55ca4a/src/OcraDiCompiler/Mvc/Service/ViewHelperManagerFactory.php#L60-L138 |
GrahamDeprecated/CMS-Core | src/Providers/PageProvider.php | PageProvider.navigation | public function navigation()
{
// caching logic
if ($this->validCache($this->nav)) {
// get the value from the class cache
$value = $this->nav;
} else {
// pull from the cache
$value = $this->getCache();
// check if the value is valid
if (!$this->validCache($value)) {
// if is invalid, do the work
$value = $this->sendGet();
// add the value from the work to the cache
$this->setCache($value);
}
}
// cache the value in the class
$this->nav = $value;
// spit out the value
return $value;
} | php | public function navigation()
{
// caching logic
if ($this->validCache($this->nav)) {
// get the value from the class cache
$value = $this->nav;
} else {
// pull from the cache
$value = $this->getCache();
// check if the value is valid
if (!$this->validCache($value)) {
// if is invalid, do the work
$value = $this->sendGet();
// add the value from the work to the cache
$this->setCache($value);
}
}
// cache the value in the class
$this->nav = $value;
// spit out the value
return $value;
} | [
"public",
"function",
"navigation",
"(",
")",
"{",
"// caching logic",
"if",
"(",
"$",
"this",
"->",
"validCache",
"(",
"$",
"this",
"->",
"nav",
")",
")",
"{",
"// get the value from the class cache",
"$",
"value",
"=",
"$",
"this",
"->",
"nav",
";",
"}",
"else",
"{",
"// pull from the cache",
"$",
"value",
"=",
"$",
"this",
"->",
"getCache",
"(",
")",
";",
"// check if the value is valid",
"if",
"(",
"!",
"$",
"this",
"->",
"validCache",
"(",
"$",
"value",
")",
")",
"{",
"// if is invalid, do the work",
"$",
"value",
"=",
"$",
"this",
"->",
"sendGet",
"(",
")",
";",
"// add the value from the work to the cache",
"$",
"this",
"->",
"setCache",
"(",
"$",
"value",
")",
";",
"}",
"}",
"// cache the value in the class",
"$",
"this",
"->",
"nav",
"=",
"$",
"value",
";",
"// spit out the value",
"return",
"$",
"value",
";",
"}"
]
| Get the page navigation.
@return array | [
"Get",
"the",
"page",
"navigation",
"."
]
| train | https://github.com/GrahamDeprecated/CMS-Core/blob/5603e2bfa2fac6cf46ca3ed62d21518f2f653675/src/Providers/PageProvider.php#L51-L74 |
GrahamDeprecated/CMS-Core | src/Providers/PageProvider.php | PageProvider.validCache | protected function validCache($value)
{
if (is_null($value) || !is_array($value) || empty($value)) {
return false;
}
return true;
} | php | protected function validCache($value)
{
if (is_null($value) || !is_array($value) || empty($value)) {
return false;
}
return true;
} | [
"protected",
"function",
"validCache",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
"||",
"!",
"is_array",
"(",
"$",
"value",
")",
"||",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Check of the nav var is not corrupt.
@param array $value
@return bool | [
"Check",
"of",
"the",
"nav",
"var",
"is",
"not",
"corrupt",
"."
]
| train | https://github.com/GrahamDeprecated/CMS-Core/blob/5603e2bfa2fac6cf46ca3ed62d21518f2f653675/src/Providers/PageProvider.php#L138-L145 |
liugene/framework | src/Env.php | Env.get | public static function get($name, $default = null)
{
$result = getenv(ENV_PREFIX . strtoupper(str_replace('.', '_', $name)));
if (false !== $result) {
if ('false' === $result) {
$result = false;
} elseif ('true' === $result) {
$result = true;
}
return $result;
}
return $default;
} | php | public static function get($name, $default = null)
{
$result = getenv(ENV_PREFIX . strtoupper(str_replace('.', '_', $name)));
if (false !== $result) {
if ('false' === $result) {
$result = false;
} elseif ('true' === $result) {
$result = true;
}
return $result;
}
return $default;
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"name",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"getenv",
"(",
"ENV_PREFIX",
".",
"strtoupper",
"(",
"str_replace",
"(",
"'.'",
",",
"'_'",
",",
"$",
"name",
")",
")",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"result",
")",
"{",
"if",
"(",
"'false'",
"===",
"$",
"result",
")",
"{",
"$",
"result",
"=",
"false",
";",
"}",
"elseif",
"(",
"'true'",
"===",
"$",
"result",
")",
"{",
"$",
"result",
"=",
"true",
";",
"}",
"return",
"$",
"result",
";",
"}",
"return",
"$",
"default",
";",
"}"
]
| 获取环境变量值
@access public
@param string $name 环境变量名(支持二级 . 号分割)
@param string $default 默认值
@return mixed | [
"获取环境变量值"
]
| train | https://github.com/liugene/framework/blob/450642242442c5884d47552a588a2639923e7289/src/Env.php#L24-L39 |
koriym/Koriym.QueryLocator | src/ApcQueryLocator.php | ApcQueryLocator.get | public function get(string $queryName) : string
{
$sqlId = $this->nameSpace . $queryName;
$sql = apcu_fetch($sqlId);
if (\is_string($sql)) {
return $sql;
}
$sql = $this->query->get($queryName);
apcu_store($sqlId, $sql);
return $sql;
} | php | public function get(string $queryName) : string
{
$sqlId = $this->nameSpace . $queryName;
$sql = apcu_fetch($sqlId);
if (\is_string($sql)) {
return $sql;
}
$sql = $this->query->get($queryName);
apcu_store($sqlId, $sql);
return $sql;
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"queryName",
")",
":",
"string",
"{",
"$",
"sqlId",
"=",
"$",
"this",
"->",
"nameSpace",
".",
"$",
"queryName",
";",
"$",
"sql",
"=",
"apcu_fetch",
"(",
"$",
"sqlId",
")",
";",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"sql",
")",
")",
"{",
"return",
"$",
"sql",
";",
"}",
"$",
"sql",
"=",
"$",
"this",
"->",
"query",
"->",
"get",
"(",
"$",
"queryName",
")",
";",
"apcu_store",
"(",
"$",
"sqlId",
",",
"$",
"sql",
")",
";",
"return",
"$",
"sql",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/koriym/Koriym.QueryLocator/blob/4e9b9ecfdd99c4850e39e88204a597af503c3823/src/ApcQueryLocator.php#L40-L51 |
Ocramius/OcraDiCompiler | src/OcraDiCompiler/Di/CompiledInstantiatorsDi.php | CompiledInstantiatorsDi.newInstance | public function newInstance($name, array $params = array(), $isShared = true)
{
if (empty($params) && isset($this->compiledInstantiators[$name])) {
$cb = $this->compiledInstantiators[$name];
return $cb($this, $isShared);
}
return parent::newInstance($name, $params, $isShared);
} | php | public function newInstance($name, array $params = array(), $isShared = true)
{
if (empty($params) && isset($this->compiledInstantiators[$name])) {
$cb = $this->compiledInstantiators[$name];
return $cb($this, $isShared);
}
return parent::newInstance($name, $params, $isShared);
} | [
"public",
"function",
"newInstance",
"(",
"$",
"name",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
",",
"$",
"isShared",
"=",
"true",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"params",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"compiledInstantiators",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"cb",
"=",
"$",
"this",
"->",
"compiledInstantiators",
"[",
"$",
"name",
"]",
";",
"return",
"$",
"cb",
"(",
"$",
"this",
",",
"$",
"isShared",
")",
";",
"}",
"return",
"parent",
"::",
"newInstance",
"(",
"$",
"name",
",",
"$",
"params",
",",
"$",
"isShared",
")",
";",
"}"
]
| {@inheritDoc} | [
"{"
]
| train | https://github.com/Ocramius/OcraDiCompiler/blob/667f4b24771f27fb9c8d6c38ffaf72d9cd55ca4a/src/OcraDiCompiler/Di/CompiledInstantiatorsDi.php#L57-L66 |
shrink0r/workflux | src/Transition/Transition.php | Transition.isActivatedBy | public function isActivatedBy(InputInterface $input, OutputInterface $output): bool
{
foreach ($this->constraints as $constraint) {
if (!$constraint->accepts($input, $output)) {
return false;
}
}
return true;
} | php | public function isActivatedBy(InputInterface $input, OutputInterface $output): bool
{
foreach ($this->constraints as $constraint) {
if (!$constraint->accepts($input, $output)) {
return false;
}
}
return true;
} | [
"public",
"function",
"isActivatedBy",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"this",
"->",
"constraints",
"as",
"$",
"constraint",
")",
"{",
"if",
"(",
"!",
"$",
"constraint",
"->",
"accepts",
"(",
"$",
"input",
",",
"$",
"output",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
]
| @param InputInterface $input
@param OutputInterface $output
@return bool | [
"@param",
"InputInterface",
"$input",
"@param",
"OutputInterface",
"$output"
]
| train | https://github.com/shrink0r/workflux/blob/008f45c64f52b1f795ab7f6ddbfc1a55580254d9/src/Transition/Transition.php#L60-L68 |
neos/doctools | Classes/Command/CommandReferenceCommandController.php | CommandReferenceCommandController.renderCommand | public function renderCommand($reference = null)
{
$references = $reference !== null ? [$reference] : array_keys($this->settings['commandReferences']);
$this->renderReferences($references);
} | php | public function renderCommand($reference = null)
{
$references = $reference !== null ? [$reference] : array_keys($this->settings['commandReferences']);
$this->renderReferences($references);
} | [
"public",
"function",
"renderCommand",
"(",
"$",
"reference",
"=",
"null",
")",
"{",
"$",
"references",
"=",
"$",
"reference",
"!==",
"null",
"?",
"[",
"$",
"reference",
"]",
":",
"array_keys",
"(",
"$",
"this",
"->",
"settings",
"[",
"'commandReferences'",
"]",
")",
";",
"$",
"this",
"->",
"renderReferences",
"(",
"$",
"references",
")",
";",
"}"
]
| Renders command reference documentation from source code.
@param string $reference to render. If not specified all configured references will be rendered
@return void
@throws \Neos\Flow\Mvc\Exception\StopActionException
@throws \Neos\FluidAdaptor\Exception | [
"Renders",
"command",
"reference",
"documentation",
"from",
"source",
"code",
"."
]
| train | https://github.com/neos/doctools/blob/726981245a8d59319ee594a582f80a30256df98b/Classes/Command/CommandReferenceCommandController.php#L48-L52 |
neos/doctools | Classes/Command/CommandReferenceCommandController.php | CommandReferenceCommandController.renderReferences | protected function renderReferences($references)
{
foreach ($references as $reference) {
$this->outputLine('Rendering Reference "%s"', [$reference]);
$this->renderReference($reference);
}
} | php | protected function renderReferences($references)
{
foreach ($references as $reference) {
$this->outputLine('Rendering Reference "%s"', [$reference]);
$this->renderReference($reference);
}
} | [
"protected",
"function",
"renderReferences",
"(",
"$",
"references",
")",
"{",
"foreach",
"(",
"$",
"references",
"as",
"$",
"reference",
")",
"{",
"$",
"this",
"->",
"outputLine",
"(",
"'Rendering Reference \"%s\"'",
",",
"[",
"$",
"reference",
"]",
")",
";",
"$",
"this",
"->",
"renderReference",
"(",
"$",
"reference",
")",
";",
"}",
"}"
]
| Render a set of CLI command references to reStructuredText.
@param array $references to render.
@return void
@throws \Neos\Flow\Mvc\Exception\StopActionException
@throws \Neos\FluidAdaptor\Exception | [
"Render",
"a",
"set",
"of",
"CLI",
"command",
"references",
"to",
"reStructuredText",
"."
]
| train | https://github.com/neos/doctools/blob/726981245a8d59319ee594a582f80a30256df98b/Classes/Command/CommandReferenceCommandController.php#L84-L90 |
neos/doctools | Classes/Command/CommandReferenceCommandController.php | CommandReferenceCommandController.renderReference | protected function renderReference($reference)
{
if (!isset($this->settings['commandReferences'][$reference])) {
$this->outputLine('Command reference "%s" is not configured', [$reference]);
$this->quit(1);
}
$referenceConfiguration = $this->settings['commandReferences'][$reference];
$packageKeysToRender = $referenceConfiguration['packageKeys'];
array_walk($packageKeysToRender, function (&$packageKey) {
$packageKey = strtolower($packageKey);
});
$availableCommands = $this->commandManager->getAvailableCommands();
$commandsByPackagesAndControllers = $this->buildCommandsIndex($availableCommands);
$allCommandsByPackageKey = [];
foreach ($commandsByPackagesAndControllers as $packageKey => $commandControllers) {
if (!in_array($packageKey, $packageKeysToRender)) {
$this->outputLine('Skipping package "%s"', [$packageKey]);
continue;
}
$allCommands = [];
foreach ($commandControllers as $commands) {
foreach ($commands as $command) {
$argumentDescriptions = [];
$optionDescriptions = [];
foreach ($command->getArgumentDefinitions() as $commandArgumentDefinition) {
$argumentDescription = $commandArgumentDefinition->getDescription();
if ($commandArgumentDefinition->isRequired()) {
$argumentDescriptions[$commandArgumentDefinition->getDashedName()] = $argumentDescription;
} else {
$optionDescriptions[$commandArgumentDefinition->getDashedName()] = $argumentDescription;
}
}
$relatedCommands = [];
$relatedCommandIdentifiers = $command->getRelatedCommandIdentifiers();
foreach ($relatedCommandIdentifiers as $relatedCommandIdentifier) {
try {
$relatedCommand = $this->commandManager->getCommandByIdentifier($relatedCommandIdentifier);
$relatedCommands[$relatedCommandIdentifier] = $relatedCommand->getShortDescription();
} catch (\Neos\Flow\Mvc\Exception\CommandException $exception) {
$relatedCommands[$relatedCommandIdentifier] = '*Command not available*';
}
}
$allCommands[$command->getCommandIdentifier()] = [
'identifier' => $command->getCommandIdentifier(),
'shortDescription' => $command->getShortDescription(),
'description' => $this->transformMarkup($command->getDescription()),
'options' => $optionDescriptions,
'arguments' => $argumentDescriptions,
'relatedCommands' => $relatedCommands
];
}
}
ksort($allCommands);
$allCommandsByPackageKey[strtoupper($packageKey)] = $allCommands;
}
ksort($allCommandsByPackageKey);
$standaloneView = new \Neos\FluidAdaptor\View\StandaloneView();
$templatePathAndFilename = isset($settings['templatePathAndFilename']) ? $this->settings['commandReference']['templatePathAndFilename'] : 'resource://Neos.DocTools/Private/Templates/CommandReferenceTemplate.txt';
$standaloneView->setTemplatePathAndFilename($templatePathAndFilename);
$standaloneView->assign('title', isset($referenceConfiguration['title']) ? $referenceConfiguration['title'] : $reference);
$standaloneView->assign('allCommandsByPackageKey', $allCommandsByPackageKey);
file_put_contents($referenceConfiguration['savePathAndFilename'], $standaloneView->render());
$this->outputLine('DONE.');
} | php | protected function renderReference($reference)
{
if (!isset($this->settings['commandReferences'][$reference])) {
$this->outputLine('Command reference "%s" is not configured', [$reference]);
$this->quit(1);
}
$referenceConfiguration = $this->settings['commandReferences'][$reference];
$packageKeysToRender = $referenceConfiguration['packageKeys'];
array_walk($packageKeysToRender, function (&$packageKey) {
$packageKey = strtolower($packageKey);
});
$availableCommands = $this->commandManager->getAvailableCommands();
$commandsByPackagesAndControllers = $this->buildCommandsIndex($availableCommands);
$allCommandsByPackageKey = [];
foreach ($commandsByPackagesAndControllers as $packageKey => $commandControllers) {
if (!in_array($packageKey, $packageKeysToRender)) {
$this->outputLine('Skipping package "%s"', [$packageKey]);
continue;
}
$allCommands = [];
foreach ($commandControllers as $commands) {
foreach ($commands as $command) {
$argumentDescriptions = [];
$optionDescriptions = [];
foreach ($command->getArgumentDefinitions() as $commandArgumentDefinition) {
$argumentDescription = $commandArgumentDefinition->getDescription();
if ($commandArgumentDefinition->isRequired()) {
$argumentDescriptions[$commandArgumentDefinition->getDashedName()] = $argumentDescription;
} else {
$optionDescriptions[$commandArgumentDefinition->getDashedName()] = $argumentDescription;
}
}
$relatedCommands = [];
$relatedCommandIdentifiers = $command->getRelatedCommandIdentifiers();
foreach ($relatedCommandIdentifiers as $relatedCommandIdentifier) {
try {
$relatedCommand = $this->commandManager->getCommandByIdentifier($relatedCommandIdentifier);
$relatedCommands[$relatedCommandIdentifier] = $relatedCommand->getShortDescription();
} catch (\Neos\Flow\Mvc\Exception\CommandException $exception) {
$relatedCommands[$relatedCommandIdentifier] = '*Command not available*';
}
}
$allCommands[$command->getCommandIdentifier()] = [
'identifier' => $command->getCommandIdentifier(),
'shortDescription' => $command->getShortDescription(),
'description' => $this->transformMarkup($command->getDescription()),
'options' => $optionDescriptions,
'arguments' => $argumentDescriptions,
'relatedCommands' => $relatedCommands
];
}
}
ksort($allCommands);
$allCommandsByPackageKey[strtoupper($packageKey)] = $allCommands;
}
ksort($allCommandsByPackageKey);
$standaloneView = new \Neos\FluidAdaptor\View\StandaloneView();
$templatePathAndFilename = isset($settings['templatePathAndFilename']) ? $this->settings['commandReference']['templatePathAndFilename'] : 'resource://Neos.DocTools/Private/Templates/CommandReferenceTemplate.txt';
$standaloneView->setTemplatePathAndFilename($templatePathAndFilename);
$standaloneView->assign('title', isset($referenceConfiguration['title']) ? $referenceConfiguration['title'] : $reference);
$standaloneView->assign('allCommandsByPackageKey', $allCommandsByPackageKey);
file_put_contents($referenceConfiguration['savePathAndFilename'], $standaloneView->render());
$this->outputLine('DONE.');
} | [
"protected",
"function",
"renderReference",
"(",
"$",
"reference",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"settings",
"[",
"'commandReferences'",
"]",
"[",
"$",
"reference",
"]",
")",
")",
"{",
"$",
"this",
"->",
"outputLine",
"(",
"'Command reference \"%s\" is not configured'",
",",
"[",
"$",
"reference",
"]",
")",
";",
"$",
"this",
"->",
"quit",
"(",
"1",
")",
";",
"}",
"$",
"referenceConfiguration",
"=",
"$",
"this",
"->",
"settings",
"[",
"'commandReferences'",
"]",
"[",
"$",
"reference",
"]",
";",
"$",
"packageKeysToRender",
"=",
"$",
"referenceConfiguration",
"[",
"'packageKeys'",
"]",
";",
"array_walk",
"(",
"$",
"packageKeysToRender",
",",
"function",
"(",
"&",
"$",
"packageKey",
")",
"{",
"$",
"packageKey",
"=",
"strtolower",
"(",
"$",
"packageKey",
")",
";",
"}",
")",
";",
"$",
"availableCommands",
"=",
"$",
"this",
"->",
"commandManager",
"->",
"getAvailableCommands",
"(",
")",
";",
"$",
"commandsByPackagesAndControllers",
"=",
"$",
"this",
"->",
"buildCommandsIndex",
"(",
"$",
"availableCommands",
")",
";",
"$",
"allCommandsByPackageKey",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"commandsByPackagesAndControllers",
"as",
"$",
"packageKey",
"=>",
"$",
"commandControllers",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"packageKey",
",",
"$",
"packageKeysToRender",
")",
")",
"{",
"$",
"this",
"->",
"outputLine",
"(",
"'Skipping package \"%s\"'",
",",
"[",
"$",
"packageKey",
"]",
")",
";",
"continue",
";",
"}",
"$",
"allCommands",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"commandControllers",
"as",
"$",
"commands",
")",
"{",
"foreach",
"(",
"$",
"commands",
"as",
"$",
"command",
")",
"{",
"$",
"argumentDescriptions",
"=",
"[",
"]",
";",
"$",
"optionDescriptions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"command",
"->",
"getArgumentDefinitions",
"(",
")",
"as",
"$",
"commandArgumentDefinition",
")",
"{",
"$",
"argumentDescription",
"=",
"$",
"commandArgumentDefinition",
"->",
"getDescription",
"(",
")",
";",
"if",
"(",
"$",
"commandArgumentDefinition",
"->",
"isRequired",
"(",
")",
")",
"{",
"$",
"argumentDescriptions",
"[",
"$",
"commandArgumentDefinition",
"->",
"getDashedName",
"(",
")",
"]",
"=",
"$",
"argumentDescription",
";",
"}",
"else",
"{",
"$",
"optionDescriptions",
"[",
"$",
"commandArgumentDefinition",
"->",
"getDashedName",
"(",
")",
"]",
"=",
"$",
"argumentDescription",
";",
"}",
"}",
"$",
"relatedCommands",
"=",
"[",
"]",
";",
"$",
"relatedCommandIdentifiers",
"=",
"$",
"command",
"->",
"getRelatedCommandIdentifiers",
"(",
")",
";",
"foreach",
"(",
"$",
"relatedCommandIdentifiers",
"as",
"$",
"relatedCommandIdentifier",
")",
"{",
"try",
"{",
"$",
"relatedCommand",
"=",
"$",
"this",
"->",
"commandManager",
"->",
"getCommandByIdentifier",
"(",
"$",
"relatedCommandIdentifier",
")",
";",
"$",
"relatedCommands",
"[",
"$",
"relatedCommandIdentifier",
"]",
"=",
"$",
"relatedCommand",
"->",
"getShortDescription",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Neos",
"\\",
"Flow",
"\\",
"Mvc",
"\\",
"Exception",
"\\",
"CommandException",
"$",
"exception",
")",
"{",
"$",
"relatedCommands",
"[",
"$",
"relatedCommandIdentifier",
"]",
"=",
"'*Command not available*'",
";",
"}",
"}",
"$",
"allCommands",
"[",
"$",
"command",
"->",
"getCommandIdentifier",
"(",
")",
"]",
"=",
"[",
"'identifier'",
"=>",
"$",
"command",
"->",
"getCommandIdentifier",
"(",
")",
",",
"'shortDescription'",
"=>",
"$",
"command",
"->",
"getShortDescription",
"(",
")",
",",
"'description'",
"=>",
"$",
"this",
"->",
"transformMarkup",
"(",
"$",
"command",
"->",
"getDescription",
"(",
")",
")",
",",
"'options'",
"=>",
"$",
"optionDescriptions",
",",
"'arguments'",
"=>",
"$",
"argumentDescriptions",
",",
"'relatedCommands'",
"=>",
"$",
"relatedCommands",
"]",
";",
"}",
"}",
"ksort",
"(",
"$",
"allCommands",
")",
";",
"$",
"allCommandsByPackageKey",
"[",
"strtoupper",
"(",
"$",
"packageKey",
")",
"]",
"=",
"$",
"allCommands",
";",
"}",
"ksort",
"(",
"$",
"allCommandsByPackageKey",
")",
";",
"$",
"standaloneView",
"=",
"new",
"\\",
"Neos",
"\\",
"FluidAdaptor",
"\\",
"View",
"\\",
"StandaloneView",
"(",
")",
";",
"$",
"templatePathAndFilename",
"=",
"isset",
"(",
"$",
"settings",
"[",
"'templatePathAndFilename'",
"]",
")",
"?",
"$",
"this",
"->",
"settings",
"[",
"'commandReference'",
"]",
"[",
"'templatePathAndFilename'",
"]",
":",
"'resource://Neos.DocTools/Private/Templates/CommandReferenceTemplate.txt'",
";",
"$",
"standaloneView",
"->",
"setTemplatePathAndFilename",
"(",
"$",
"templatePathAndFilename",
")",
";",
"$",
"standaloneView",
"->",
"assign",
"(",
"'title'",
",",
"isset",
"(",
"$",
"referenceConfiguration",
"[",
"'title'",
"]",
")",
"?",
"$",
"referenceConfiguration",
"[",
"'title'",
"]",
":",
"$",
"reference",
")",
";",
"$",
"standaloneView",
"->",
"assign",
"(",
"'allCommandsByPackageKey'",
",",
"$",
"allCommandsByPackageKey",
")",
";",
"file_put_contents",
"(",
"$",
"referenceConfiguration",
"[",
"'savePathAndFilename'",
"]",
",",
"$",
"standaloneView",
"->",
"render",
"(",
")",
")",
";",
"$",
"this",
"->",
"outputLine",
"(",
"'DONE.'",
")",
";",
"}"
]
| Render a CLI command reference to reStructuredText.
@param string $reference
@return void
@throws \Neos\Flow\Mvc\Exception\StopActionException
@throws \Neos\FluidAdaptor\Exception | [
"Render",
"a",
"CLI",
"command",
"reference",
"to",
"reStructuredText",
"."
]
| train | https://github.com/neos/doctools/blob/726981245a8d59319ee594a582f80a30256df98b/Classes/Command/CommandReferenceCommandController.php#L100-L170 |
netgen/ngopengraph | classes/ngopengraphobjectrelationlist.php | ngOpenGraphObjectRelationList.getData | public function getData()
{
$return = array();
$relations = $this->ContentObjectAttribute->attribute( 'content' );
foreach ( $relations['relation_list'] as $relation )
{
$object = eZContentObject::fetch( $relation['contentobject_id'] );
if ( $object instanceof eZContentObject )
{
$return[] = $object->attribute( 'name' );
}
}
return implode( ', ', $return );
} | php | public function getData()
{
$return = array();
$relations = $this->ContentObjectAttribute->attribute( 'content' );
foreach ( $relations['relation_list'] as $relation )
{
$object = eZContentObject::fetch( $relation['contentobject_id'] );
if ( $object instanceof eZContentObject )
{
$return[] = $object->attribute( 'name' );
}
}
return implode( ', ', $return );
} | [
"public",
"function",
"getData",
"(",
")",
"{",
"$",
"return",
"=",
"array",
"(",
")",
";",
"$",
"relations",
"=",
"$",
"this",
"->",
"ContentObjectAttribute",
"->",
"attribute",
"(",
"'content'",
")",
";",
"foreach",
"(",
"$",
"relations",
"[",
"'relation_list'",
"]",
"as",
"$",
"relation",
")",
"{",
"$",
"object",
"=",
"eZContentObject",
"::",
"fetch",
"(",
"$",
"relation",
"[",
"'contentobject_id'",
"]",
")",
";",
"if",
"(",
"$",
"object",
"instanceof",
"eZContentObject",
")",
"{",
"$",
"return",
"[",
"]",
"=",
"$",
"object",
"->",
"attribute",
"(",
"'name'",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"', '",
",",
"$",
"return",
")",
";",
"}"
]
| Returns data for the attribute
@return string | [
"Returns",
"data",
"for",
"the",
"attribute"
]
| train | https://github.com/netgen/ngopengraph/blob/68a99862f240ee74174ea9b888a9a33743142e27/classes/ngopengraphobjectrelationlist.php#L10-L24 |
netgen/ngopengraph | classes/ngopengraphobjectrelationlist.php | ngOpenGraphObjectRelationList.getDataMember | public function getDataMember( $dataMember )
{
if( $dataMember === 'related_images' )
{
$images = array();
$relations = $this->ContentObjectAttribute->attribute( 'content' );
foreach ( $relations['relation_list'] as $relation )
{
$object = eZContentObject::fetch( $relation['contentobject_id'] );
if( $object instanceof eZContentObject )
{
$dataMap = $object->attribute( 'data_map' );
foreach ( $dataMap as $attribute )
{
/** @var eZContentObjectAttribute $attribute */
if ( $attribute->attribute( 'data_type_string' ) !== eZImageType::DATA_TYPE_STRING )
{
continue;
}
if ( $attribute->hasContent() )
{
$imageAliasHandler = $attribute->attribute( 'content' );
$imageAlias = $imageAliasHandler->imageAlias( 'opengraph' );
if( $imageAlias['is_valid'] == 1 )
{
$images[] = eZSys::serverURL() . '/' . $imageAlias['full_path'];
}
}
}
}
}
if ( empty( $images ) )
{
$images[] = eZSys::serverURL() . eZURLOperator::eZImage( null, 'opengraph_default_image.png', '' );
}
return $images;
}
return $this->getData();
} | php | public function getDataMember( $dataMember )
{
if( $dataMember === 'related_images' )
{
$images = array();
$relations = $this->ContentObjectAttribute->attribute( 'content' );
foreach ( $relations['relation_list'] as $relation )
{
$object = eZContentObject::fetch( $relation['contentobject_id'] );
if( $object instanceof eZContentObject )
{
$dataMap = $object->attribute( 'data_map' );
foreach ( $dataMap as $attribute )
{
/** @var eZContentObjectAttribute $attribute */
if ( $attribute->attribute( 'data_type_string' ) !== eZImageType::DATA_TYPE_STRING )
{
continue;
}
if ( $attribute->hasContent() )
{
$imageAliasHandler = $attribute->attribute( 'content' );
$imageAlias = $imageAliasHandler->imageAlias( 'opengraph' );
if( $imageAlias['is_valid'] == 1 )
{
$images[] = eZSys::serverURL() . '/' . $imageAlias['full_path'];
}
}
}
}
}
if ( empty( $images ) )
{
$images[] = eZSys::serverURL() . eZURLOperator::eZImage( null, 'opengraph_default_image.png', '' );
}
return $images;
}
return $this->getData();
} | [
"public",
"function",
"getDataMember",
"(",
"$",
"dataMember",
")",
"{",
"if",
"(",
"$",
"dataMember",
"===",
"'related_images'",
")",
"{",
"$",
"images",
"=",
"array",
"(",
")",
";",
"$",
"relations",
"=",
"$",
"this",
"->",
"ContentObjectAttribute",
"->",
"attribute",
"(",
"'content'",
")",
";",
"foreach",
"(",
"$",
"relations",
"[",
"'relation_list'",
"]",
"as",
"$",
"relation",
")",
"{",
"$",
"object",
"=",
"eZContentObject",
"::",
"fetch",
"(",
"$",
"relation",
"[",
"'contentobject_id'",
"]",
")",
";",
"if",
"(",
"$",
"object",
"instanceof",
"eZContentObject",
")",
"{",
"$",
"dataMap",
"=",
"$",
"object",
"->",
"attribute",
"(",
"'data_map'",
")",
";",
"foreach",
"(",
"$",
"dataMap",
"as",
"$",
"attribute",
")",
"{",
"/** @var eZContentObjectAttribute $attribute */",
"if",
"(",
"$",
"attribute",
"->",
"attribute",
"(",
"'data_type_string'",
")",
"!==",
"eZImageType",
"::",
"DATA_TYPE_STRING",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"attribute",
"->",
"hasContent",
"(",
")",
")",
"{",
"$",
"imageAliasHandler",
"=",
"$",
"attribute",
"->",
"attribute",
"(",
"'content'",
")",
";",
"$",
"imageAlias",
"=",
"$",
"imageAliasHandler",
"->",
"imageAlias",
"(",
"'opengraph'",
")",
";",
"if",
"(",
"$",
"imageAlias",
"[",
"'is_valid'",
"]",
"==",
"1",
")",
"{",
"$",
"images",
"[",
"]",
"=",
"eZSys",
"::",
"serverURL",
"(",
")",
".",
"'/'",
".",
"$",
"imageAlias",
"[",
"'full_path'",
"]",
";",
"}",
"}",
"}",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"images",
")",
")",
"{",
"$",
"images",
"[",
"]",
"=",
"eZSys",
"::",
"serverURL",
"(",
")",
".",
"eZURLOperator",
"::",
"eZImage",
"(",
"null",
",",
"'opengraph_default_image.png'",
",",
"''",
")",
";",
"}",
"return",
"$",
"images",
";",
"}",
"return",
"$",
"this",
"->",
"getData",
"(",
")",
";",
"}"
]
| Returns part of the data for the attribute
@param string $dataMember
@return string | [
"Returns",
"part",
"of",
"the",
"data",
"for",
"the",
"attribute"
]
| train | https://github.com/netgen/ngopengraph/blob/68a99862f240ee74174ea9b888a9a33743142e27/classes/ngopengraphobjectrelationlist.php#L33-L75 |
webforge-labs/psc-cms | lib/Psc/CMS/Roles/NavigationNodeEntity.php | NavigationNodeEntity.onPrePersist | public function onPrePersist() {
$this->generateSlugs();
if (!isset($this->created)) {
$this->created = \Psc\DateTime\DateTime::now();
}
$this->updated = \Psc\DateTime\DateTime::now();
return $this;
} | php | public function onPrePersist() {
$this->generateSlugs();
if (!isset($this->created)) {
$this->created = \Psc\DateTime\DateTime::now();
}
$this->updated = \Psc\DateTime\DateTime::now();
return $this;
} | [
"public",
"function",
"onPrePersist",
"(",
")",
"{",
"$",
"this",
"->",
"generateSlugs",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"created",
")",
")",
"{",
"$",
"this",
"->",
"created",
"=",
"\\",
"Psc",
"\\",
"DateTime",
"\\",
"DateTime",
"::",
"now",
"(",
")",
";",
"}",
"$",
"this",
"->",
"updated",
"=",
"\\",
"Psc",
"\\",
"DateTime",
"\\",
"DateTime",
"::",
"now",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| (at)ORM\PrePersist
(at)ORM\PreUpdate | [
"(",
"at",
")",
"ORM",
"\\",
"PrePersist",
"(",
"at",
")",
"ORM",
"\\",
"PreUpdate"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/CMS/Roles/NavigationNodeEntity.php#L47-L56 |
xinix-technology/norm | src/Norm/Provider/NormProvider.php | NormProvider.initialize | public function initialize()
{
$app = $this->app;
$include = $app->request->get('!include');
if (!empty($include)) {
Norm::options('include', true);
}
$tz = $app->request->get('!tz');
if (!empty($tz)) {
Norm::options('tz', $tz);
}
if (!isset($this->options['datasources'])) {
$this->options['datasources'] = $this->app->config('norm.datasources');
}
// DEPRECATED: norm.databases deprecated
if (!isset($this->options['datasources'])) {
$this->options['datasources'] = $this->app->config('norm.databases');
}
if (!isset($this->options['datasources'])) {
throw new \Exception('[Norm] No data source configuration. Append "norm.datasources" bono configuration!');
}
if (!isset($this->options['collections'])) {
$this->options['collections'] = $this->app->config('norm.collections');
}
Norm::init($this->options['datasources'], $this->options['collections']);
$controllerConfig = $this->app->config('bono.controllers');
if (!isset($controllerConfig['default'])) {
$controllerConfig['default'] = 'Norm\\Controller\\NormController';
}
$this->app->config('bono.controllers', $controllerConfig);
if (! class_exists('Norm')) {
class_alias('Norm\\Norm', 'Norm');
}
$d = explode(DIRECTORY_SEPARATOR.'src', __DIR__);
$this->app->theme->addBaseDirectory($d[0], 10);
} | php | public function initialize()
{
$app = $this->app;
$include = $app->request->get('!include');
if (!empty($include)) {
Norm::options('include', true);
}
$tz = $app->request->get('!tz');
if (!empty($tz)) {
Norm::options('tz', $tz);
}
if (!isset($this->options['datasources'])) {
$this->options['datasources'] = $this->app->config('norm.datasources');
}
// DEPRECATED: norm.databases deprecated
if (!isset($this->options['datasources'])) {
$this->options['datasources'] = $this->app->config('norm.databases');
}
if (!isset($this->options['datasources'])) {
throw new \Exception('[Norm] No data source configuration. Append "norm.datasources" bono configuration!');
}
if (!isset($this->options['collections'])) {
$this->options['collections'] = $this->app->config('norm.collections');
}
Norm::init($this->options['datasources'], $this->options['collections']);
$controllerConfig = $this->app->config('bono.controllers');
if (!isset($controllerConfig['default'])) {
$controllerConfig['default'] = 'Norm\\Controller\\NormController';
}
$this->app->config('bono.controllers', $controllerConfig);
if (! class_exists('Norm')) {
class_alias('Norm\\Norm', 'Norm');
}
$d = explode(DIRECTORY_SEPARATOR.'src', __DIR__);
$this->app->theme->addBaseDirectory($d[0], 10);
} | [
"public",
"function",
"initialize",
"(",
")",
"{",
"$",
"app",
"=",
"$",
"this",
"->",
"app",
";",
"$",
"include",
"=",
"$",
"app",
"->",
"request",
"->",
"get",
"(",
"'!include'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"include",
")",
")",
"{",
"Norm",
"::",
"options",
"(",
"'include'",
",",
"true",
")",
";",
"}",
"$",
"tz",
"=",
"$",
"app",
"->",
"request",
"->",
"get",
"(",
"'!tz'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"tz",
")",
")",
"{",
"Norm",
"::",
"options",
"(",
"'tz'",
",",
"$",
"tz",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'datasources'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"options",
"[",
"'datasources'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"config",
"(",
"'norm.datasources'",
")",
";",
"}",
"// DEPRECATED: norm.databases deprecated",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'datasources'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"options",
"[",
"'datasources'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"config",
"(",
"'norm.databases'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'datasources'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'[Norm] No data source configuration. Append \"norm.datasources\" bono configuration!'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'collections'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"options",
"[",
"'collections'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"config",
"(",
"'norm.collections'",
")",
";",
"}",
"Norm",
"::",
"init",
"(",
"$",
"this",
"->",
"options",
"[",
"'datasources'",
"]",
",",
"$",
"this",
"->",
"options",
"[",
"'collections'",
"]",
")",
";",
"$",
"controllerConfig",
"=",
"$",
"this",
"->",
"app",
"->",
"config",
"(",
"'bono.controllers'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"controllerConfig",
"[",
"'default'",
"]",
")",
")",
"{",
"$",
"controllerConfig",
"[",
"'default'",
"]",
"=",
"'Norm\\\\Controller\\\\NormController'",
";",
"}",
"$",
"this",
"->",
"app",
"->",
"config",
"(",
"'bono.controllers'",
",",
"$",
"controllerConfig",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"'Norm'",
")",
")",
"{",
"class_alias",
"(",
"'Norm\\\\Norm'",
",",
"'Norm'",
")",
";",
"}",
"$",
"d",
"=",
"explode",
"(",
"DIRECTORY_SEPARATOR",
".",
"'src'",
",",
"__DIR__",
")",
";",
"$",
"this",
"->",
"app",
"->",
"theme",
"->",
"addBaseDirectory",
"(",
"$",
"d",
"[",
"0",
"]",
",",
"10",
")",
";",
"}"
]
| Initialize the provider | [
"Initialize",
"the",
"provider"
]
| train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Provider/NormProvider.php#L94-L139 |
Chill-project/Main | Controller/ScopeController.php | ScopeController.createCreateForm | private function createCreateForm(Scope $scope)
{
$form = $this->createForm(new ScopeType(), $scope, array(
'action' => $this->generateUrl('admin_scope_create'),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
} | php | private function createCreateForm(Scope $scope)
{
$form = $this->createForm(new ScopeType(), $scope, array(
'action' => $this->generateUrl('admin_scope_create'),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
} | [
"private",
"function",
"createCreateForm",
"(",
"Scope",
"$",
"scope",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"ScopeType",
"(",
")",
",",
"$",
"scope",
",",
"array",
"(",
"'action'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'admin_scope_create'",
")",
",",
"'method'",
"=>",
"'POST'",
",",
")",
")",
";",
"$",
"form",
"->",
"add",
"(",
"'submit'",
",",
"'submit'",
",",
"array",
"(",
"'label'",
"=>",
"'Create'",
")",
")",
";",
"return",
"$",
"form",
";",
"}"
]
| Creates a form to create a Scope entity.
@param Scope $scope The entity
@return \Symfony\Component\Form\Form The form | [
"Creates",
"a",
"form",
"to",
"create",
"a",
"Scope",
"entity",
"."
]
| train | https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Controller/ScopeController.php#L63-L73 |
Chill-project/Main | Controller/ScopeController.php | ScopeController.newAction | public function newAction()
{
$scope = new Scope();
$form = $this->createCreateForm($scope);
return $this->render('ChillMainBundle:Scope:new.html.twig', array(
'entity' => $scope,
'form' => $form->createView(),
));
} | php | public function newAction()
{
$scope = new Scope();
$form = $this->createCreateForm($scope);
return $this->render('ChillMainBundle:Scope:new.html.twig', array(
'entity' => $scope,
'form' => $form->createView(),
));
} | [
"public",
"function",
"newAction",
"(",
")",
"{",
"$",
"scope",
"=",
"new",
"Scope",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createCreateForm",
"(",
"$",
"scope",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'ChillMainBundle:Scope:new.html.twig'",
",",
"array",
"(",
"'entity'",
"=>",
"$",
"scope",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
")",
")",
";",
"}"
]
| Displays a form to create a new Scope entity. | [
"Displays",
"a",
"form",
"to",
"create",
"a",
"new",
"Scope",
"entity",
"."
]
| train | https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Controller/ScopeController.php#L79-L88 |
Chill-project/Main | Controller/ScopeController.php | ScopeController.createEditForm | private function createEditForm(Scope $scope)
{
$form = $this->createForm(new ScopeType(), $scope, array(
'action' => $this->generateUrl('admin_scope_update', array('id' => $scope->getId())),
'method' => 'PUT',
));
$form->add('submit', 'submit', array('label' => 'Update'));
return $form;
} | php | private function createEditForm(Scope $scope)
{
$form = $this->createForm(new ScopeType(), $scope, array(
'action' => $this->generateUrl('admin_scope_update', array('id' => $scope->getId())),
'method' => 'PUT',
));
$form->add('submit', 'submit', array('label' => 'Update'));
return $form;
} | [
"private",
"function",
"createEditForm",
"(",
"Scope",
"$",
"scope",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"ScopeType",
"(",
")",
",",
"$",
"scope",
",",
"array",
"(",
"'action'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'admin_scope_update'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"scope",
"->",
"getId",
"(",
")",
")",
")",
",",
"'method'",
"=>",
"'PUT'",
",",
")",
")",
";",
"$",
"form",
"->",
"add",
"(",
"'submit'",
",",
"'submit'",
",",
"array",
"(",
"'label'",
"=>",
"'Update'",
")",
")",
";",
"return",
"$",
"form",
";",
"}"
]
| Creates a form to edit a Scope entity.
@param Scope $scope The entity
@return \Symfony\Component\Form\Form The form | [
"Creates",
"a",
"form",
"to",
"edit",
"a",
"Scope",
"entity",
"."
]
| train | https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Controller/ScopeController.php#L138-L148 |
djgadd/themosis-illuminate | src/Config/ConfigFinder.php | ConfigFinder.addPath | protected function addPath($key, $path)
{
// Iterate through the extensions looking for files in the path
foreach ($this->extensions as $extension) {
// Find all matching files for this extension
foreach (Finder::create()->files()->name("*.{$extension}")->in($path) as $file) {
// Skip if the file belongs to a more specific extension
if ($this->fileMatchesMoreSpecificExtension(basename($file->getRealPath()), $extension)) {
continue;
}
// Work out the files key
$key = $this->getNestedDirectoryDots($path, $file->getPath()).basename($file->getRealPath(), ".{$extension}");
// We already have a matching file so we need to merge the config
if (array_key_exists($key, $this->files)) {
$this->files[$key][] = $file->getRealPath();
$items = $this->mergeConfigs(app('config')->get($key), require $file->getRealPath());
}
// Otherwise we can just require the config in
else {
$this->files[$key] = [$file->getRealPath()];
$items = require $file->getRealPath();
}
app('config')->set($key, $items);
}
}
return parent::addPath($key, $path);
} | php | protected function addPath($key, $path)
{
// Iterate through the extensions looking for files in the path
foreach ($this->extensions as $extension) {
// Find all matching files for this extension
foreach (Finder::create()->files()->name("*.{$extension}")->in($path) as $file) {
// Skip if the file belongs to a more specific extension
if ($this->fileMatchesMoreSpecificExtension(basename($file->getRealPath()), $extension)) {
continue;
}
// Work out the files key
$key = $this->getNestedDirectoryDots($path, $file->getPath()).basename($file->getRealPath(), ".{$extension}");
// We already have a matching file so we need to merge the config
if (array_key_exists($key, $this->files)) {
$this->files[$key][] = $file->getRealPath();
$items = $this->mergeConfigs(app('config')->get($key), require $file->getRealPath());
}
// Otherwise we can just require the config in
else {
$this->files[$key] = [$file->getRealPath()];
$items = require $file->getRealPath();
}
app('config')->set($key, $items);
}
}
return parent::addPath($key, $path);
} | [
"protected",
"function",
"addPath",
"(",
"$",
"key",
",",
"$",
"path",
")",
"{",
"// Iterate through the extensions looking for files in the path",
"foreach",
"(",
"$",
"this",
"->",
"extensions",
"as",
"$",
"extension",
")",
"{",
"// Find all matching files for this extension",
"foreach",
"(",
"Finder",
"::",
"create",
"(",
")",
"->",
"files",
"(",
")",
"->",
"name",
"(",
"\"*.{$extension}\"",
")",
"->",
"in",
"(",
"$",
"path",
")",
"as",
"$",
"file",
")",
"{",
"// Skip if the file belongs to a more specific extension",
"if",
"(",
"$",
"this",
"->",
"fileMatchesMoreSpecificExtension",
"(",
"basename",
"(",
"$",
"file",
"->",
"getRealPath",
"(",
")",
")",
",",
"$",
"extension",
")",
")",
"{",
"continue",
";",
"}",
"// Work out the files key",
"$",
"key",
"=",
"$",
"this",
"->",
"getNestedDirectoryDots",
"(",
"$",
"path",
",",
"$",
"file",
"->",
"getPath",
"(",
")",
")",
".",
"basename",
"(",
"$",
"file",
"->",
"getRealPath",
"(",
")",
",",
"\".{$extension}\"",
")",
";",
"// We already have a matching file so we need to merge the config",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"files",
")",
")",
"{",
"$",
"this",
"->",
"files",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"file",
"->",
"getRealPath",
"(",
")",
";",
"$",
"items",
"=",
"$",
"this",
"->",
"mergeConfigs",
"(",
"app",
"(",
"'config'",
")",
"->",
"get",
"(",
"$",
"key",
")",
",",
"require",
"$",
"file",
"->",
"getRealPath",
"(",
")",
")",
";",
"}",
"// Otherwise we can just require the config in",
"else",
"{",
"$",
"this",
"->",
"files",
"[",
"$",
"key",
"]",
"=",
"[",
"$",
"file",
"->",
"getRealPath",
"(",
")",
"]",
";",
"$",
"items",
"=",
"require",
"$",
"file",
"->",
"getRealPath",
"(",
")",
";",
"}",
"app",
"(",
"'config'",
")",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"items",
")",
";",
"}",
"}",
"return",
"parent",
"::",
"addPath",
"(",
"$",
"key",
",",
"$",
"path",
")",
";",
"}"
]
| When a path is registered any matching files are read in and added to the
config Repository. Calls parent::addPath once finished
@param string $key The file URL if defined or numeric index.
@param string $path
@return $this | [
"When",
"a",
"path",
"is",
"registered",
"any",
"matching",
"files",
"are",
"read",
"in",
"and",
"added",
"to",
"the",
"config",
"Repository",
".",
"Calls",
"parent",
"::",
"addPath",
"once",
"finished"
]
| train | https://github.com/djgadd/themosis-illuminate/blob/13ee4c3413cddd85a2f262ac361f35c81da0c53c/src/Config/ConfigFinder.php#L28-L58 |
djgadd/themosis-illuminate | src/Config/ConfigFinder.php | ConfigFinder.fileMatchesMoreSpecificExtension | protected function fileMatchesMoreSpecificExtension(string $filename, string $extension) : bool
{
return array_reduce($this->extensions, function ($match, $compare) use ($filename, $extension) {
if ($match || $compare === $extension || strlen($compare) < strlen($extension)) {
return $match;
}
return $filename === basename($filename, ".{$compare}").".{$compare}";
}, false);
} | php | protected function fileMatchesMoreSpecificExtension(string $filename, string $extension) : bool
{
return array_reduce($this->extensions, function ($match, $compare) use ($filename, $extension) {
if ($match || $compare === $extension || strlen($compare) < strlen($extension)) {
return $match;
}
return $filename === basename($filename, ".{$compare}").".{$compare}";
}, false);
} | [
"protected",
"function",
"fileMatchesMoreSpecificExtension",
"(",
"string",
"$",
"filename",
",",
"string",
"$",
"extension",
")",
":",
"bool",
"{",
"return",
"array_reduce",
"(",
"$",
"this",
"->",
"extensions",
",",
"function",
"(",
"$",
"match",
",",
"$",
"compare",
")",
"use",
"(",
"$",
"filename",
",",
"$",
"extension",
")",
"{",
"if",
"(",
"$",
"match",
"||",
"$",
"compare",
"===",
"$",
"extension",
"||",
"strlen",
"(",
"$",
"compare",
")",
"<",
"strlen",
"(",
"$",
"extension",
")",
")",
"{",
"return",
"$",
"match",
";",
"}",
"return",
"$",
"filename",
"===",
"basename",
"(",
"$",
"filename",
",",
"\".{$compare}\"",
")",
".",
"\".{$compare}\"",
";",
"}",
",",
"false",
")",
";",
"}"
]
| Determines if a file matches another more specific extension
@param string $filename
@param string $extension
@return bool | [
"Determines",
"if",
"a",
"file",
"matches",
"another",
"more",
"specific",
"extension"
]
| train | https://github.com/djgadd/themosis-illuminate/blob/13ee4c3413cddd85a2f262ac361f35c81da0c53c/src/Config/ConfigFinder.php#L67-L76 |
djgadd/themosis-illuminate | src/Config/ConfigFinder.php | ConfigFinder.getNestedDirectoryDots | protected function getNestedDirectoryDots(string $path, string $filePath) : string
{
if (substr($filePath, -1) !== DIRECTORY_SEPARATOR) {
$filePath = $filePath . DIRECTORY_SEPARATOR;
}
// Generate dots if it's a nested file
if ($nested = trim(str_replace($path, '', $filePath), DIRECTORY_SEPARATOR)) {
$nested = str_replace(DIRECTORY_SEPARATOR, '.', $nested).'.';
}
return $nested;
} | php | protected function getNestedDirectoryDots(string $path, string $filePath) : string
{
if (substr($filePath, -1) !== DIRECTORY_SEPARATOR) {
$filePath = $filePath . DIRECTORY_SEPARATOR;
}
// Generate dots if it's a nested file
if ($nested = trim(str_replace($path, '', $filePath), DIRECTORY_SEPARATOR)) {
$nested = str_replace(DIRECTORY_SEPARATOR, '.', $nested).'.';
}
return $nested;
} | [
"protected",
"function",
"getNestedDirectoryDots",
"(",
"string",
"$",
"path",
",",
"string",
"$",
"filePath",
")",
":",
"string",
"{",
"if",
"(",
"substr",
"(",
"$",
"filePath",
",",
"-",
"1",
")",
"!==",
"DIRECTORY_SEPARATOR",
")",
"{",
"$",
"filePath",
"=",
"$",
"filePath",
".",
"DIRECTORY_SEPARATOR",
";",
"}",
"// Generate dots if it's a nested file",
"if",
"(",
"$",
"nested",
"=",
"trim",
"(",
"str_replace",
"(",
"$",
"path",
",",
"''",
",",
"$",
"filePath",
")",
",",
"DIRECTORY_SEPARATOR",
")",
")",
"{",
"$",
"nested",
"=",
"str_replace",
"(",
"DIRECTORY_SEPARATOR",
",",
"'.'",
",",
"$",
"nested",
")",
".",
"'.'",
";",
"}",
"return",
"$",
"nested",
";",
"}"
]
| Generates dots for files in $filePath nested in $path
@param string $path
@param string $filePath
@return string | [
"Generates",
"dots",
"for",
"files",
"in",
"$filePath",
"nested",
"in",
"$path"
]
| train | https://github.com/djgadd/themosis-illuminate/blob/13ee4c3413cddd85a2f262ac361f35c81da0c53c/src/Config/ConfigFinder.php#L85-L97 |
djgadd/themosis-illuminate | src/Config/ConfigFinder.php | ConfigFinder.mergeConfigs | protected function mergeConfigs(array $old, array $new) : array
{
foreach ($new as $key => $val) {
if (!array_key_exists($key, $old) || !is_array($old[$key]) || !is_array($val)) {
$old[$key] = $val;
continue;
}
if (is_int($key)) {
$old[] = $val;
continue;
}
$old[$key] = $this->mergeConfigs($old[$key], $val);
}
return $old;
} | php | protected function mergeConfigs(array $old, array $new) : array
{
foreach ($new as $key => $val) {
if (!array_key_exists($key, $old) || !is_array($old[$key]) || !is_array($val)) {
$old[$key] = $val;
continue;
}
if (is_int($key)) {
$old[] = $val;
continue;
}
$old[$key] = $this->mergeConfigs($old[$key], $val);
}
return $old;
} | [
"protected",
"function",
"mergeConfigs",
"(",
"array",
"$",
"old",
",",
"array",
"$",
"new",
")",
":",
"array",
"{",
"foreach",
"(",
"$",
"new",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"old",
")",
"||",
"!",
"is_array",
"(",
"$",
"old",
"[",
"$",
"key",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"val",
")",
")",
"{",
"$",
"old",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"continue",
";",
"}",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"$",
"old",
"[",
"]",
"=",
"$",
"val",
";",
"continue",
";",
"}",
"$",
"old",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"mergeConfigs",
"(",
"$",
"old",
"[",
"$",
"key",
"]",
",",
"$",
"val",
")",
";",
"}",
"return",
"$",
"old",
";",
"}"
]
| Recusively merges configs together
@param array $old
@param array $new
@return array | [
"Recusively",
"merges",
"configs",
"together"
]
| train | https://github.com/djgadd/themosis-illuminate/blob/13ee4c3413cddd85a2f262ac361f35c81da0c53c/src/Config/ConfigFinder.php#L106-L123 |
lmammino/e-foundation | src/Common/Doctrine/MappingLocator.php | MappingLocator.getMappings | public static function getMappings()
{
$basePath = self::getBasePath();
return array(
realpath($basePath.'Address/Resources/config/doctrine/model') => 'LMammino\EFoundation\Address\Model',
realpath($basePath.'Attribute/Resources/config/doctrine/model') =>
'LMammino\EFoundation\Attribute\Model',
realpath($basePath.'Cart/Resources/config/doctrine/model') => 'LMammino\EFoundation\Cart\Model',
realpath($basePath.'Order/Resources/config/doctrine/model') => 'LMammino\EFoundation\Order\Model',
realpath($basePath.'Price/Resources/config/doctrine/model') => 'LMammino\EFoundation\Price\Model',
realpath($basePath.'Product/Resources/config/doctrine/model') => 'LMammino\EFoundation\Product\Model',
realpath($basePath.'Variation/Resources/config/doctrine/model') =>
'LMammino\EFoundation\Variation\Model',
);
} | php | public static function getMappings()
{
$basePath = self::getBasePath();
return array(
realpath($basePath.'Address/Resources/config/doctrine/model') => 'LMammino\EFoundation\Address\Model',
realpath($basePath.'Attribute/Resources/config/doctrine/model') =>
'LMammino\EFoundation\Attribute\Model',
realpath($basePath.'Cart/Resources/config/doctrine/model') => 'LMammino\EFoundation\Cart\Model',
realpath($basePath.'Order/Resources/config/doctrine/model') => 'LMammino\EFoundation\Order\Model',
realpath($basePath.'Price/Resources/config/doctrine/model') => 'LMammino\EFoundation\Price\Model',
realpath($basePath.'Product/Resources/config/doctrine/model') => 'LMammino\EFoundation\Product\Model',
realpath($basePath.'Variation/Resources/config/doctrine/model') =>
'LMammino\EFoundation\Variation\Model',
);
} | [
"public",
"static",
"function",
"getMappings",
"(",
")",
"{",
"$",
"basePath",
"=",
"self",
"::",
"getBasePath",
"(",
")",
";",
"return",
"array",
"(",
"realpath",
"(",
"$",
"basePath",
".",
"'Address/Resources/config/doctrine/model'",
")",
"=>",
"'LMammino\\EFoundation\\Address\\Model'",
",",
"realpath",
"(",
"$",
"basePath",
".",
"'Attribute/Resources/config/doctrine/model'",
")",
"=>",
"'LMammino\\EFoundation\\Attribute\\Model'",
",",
"realpath",
"(",
"$",
"basePath",
".",
"'Cart/Resources/config/doctrine/model'",
")",
"=>",
"'LMammino\\EFoundation\\Cart\\Model'",
",",
"realpath",
"(",
"$",
"basePath",
".",
"'Order/Resources/config/doctrine/model'",
")",
"=>",
"'LMammino\\EFoundation\\Order\\Model'",
",",
"realpath",
"(",
"$",
"basePath",
".",
"'Price/Resources/config/doctrine/model'",
")",
"=>",
"'LMammino\\EFoundation\\Price\\Model'",
",",
"realpath",
"(",
"$",
"basePath",
".",
"'Product/Resources/config/doctrine/model'",
")",
"=>",
"'LMammino\\EFoundation\\Product\\Model'",
",",
"realpath",
"(",
"$",
"basePath",
".",
"'Variation/Resources/config/doctrine/model'",
")",
"=>",
"'LMammino\\EFoundation\\Variation\\Model'",
",",
")",
";",
"}"
]
| Get the mapping
@return array | [
"Get",
"the",
"mapping"
]
| train | https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Common/Doctrine/MappingLocator.php#L17-L32 |
titon/db | src/Titon/Db/Driver/Type/DateType.php | DateType.to | public function to($value) {
if (is_array($value)) {
$hour = isset($value['hour']) ? $value['hour'] : 0;
if (isset($value['meridiem']) && strtolower($value['meridiem']) === 'pm') {
$hour += 12;
}
$timestamp = mktime(
$hour,
isset($value['minute']) ? $value['minute'] : 0,
isset($value['second']) ? $value['second'] : 0,
isset($value['month']) ? $value['month'] : date('m'),
isset($value['day']) ? $value['day'] : date('d'),
isset($value['year']) ? $value['year'] : date('Y'));
$value = Time::factory(date('Y-m-d H:i:s', $timestamp), isset($value['timezone']) ? $value['timezone'] : null);
}
if ($value instanceof DateTime) {
return $value->format($this->format);
}
return date($this->format, Time::toUnix($value));
} | php | public function to($value) {
if (is_array($value)) {
$hour = isset($value['hour']) ? $value['hour'] : 0;
if (isset($value['meridiem']) && strtolower($value['meridiem']) === 'pm') {
$hour += 12;
}
$timestamp = mktime(
$hour,
isset($value['minute']) ? $value['minute'] : 0,
isset($value['second']) ? $value['second'] : 0,
isset($value['month']) ? $value['month'] : date('m'),
isset($value['day']) ? $value['day'] : date('d'),
isset($value['year']) ? $value['year'] : date('Y'));
$value = Time::factory(date('Y-m-d H:i:s', $timestamp), isset($value['timezone']) ? $value['timezone'] : null);
}
if ($value instanceof DateTime) {
return $value->format($this->format);
}
return date($this->format, Time::toUnix($value));
} | [
"public",
"function",
"to",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"hour",
"=",
"isset",
"(",
"$",
"value",
"[",
"'hour'",
"]",
")",
"?",
"$",
"value",
"[",
"'hour'",
"]",
":",
"0",
";",
"if",
"(",
"isset",
"(",
"$",
"value",
"[",
"'meridiem'",
"]",
")",
"&&",
"strtolower",
"(",
"$",
"value",
"[",
"'meridiem'",
"]",
")",
"===",
"'pm'",
")",
"{",
"$",
"hour",
"+=",
"12",
";",
"}",
"$",
"timestamp",
"=",
"mktime",
"(",
"$",
"hour",
",",
"isset",
"(",
"$",
"value",
"[",
"'minute'",
"]",
")",
"?",
"$",
"value",
"[",
"'minute'",
"]",
":",
"0",
",",
"isset",
"(",
"$",
"value",
"[",
"'second'",
"]",
")",
"?",
"$",
"value",
"[",
"'second'",
"]",
":",
"0",
",",
"isset",
"(",
"$",
"value",
"[",
"'month'",
"]",
")",
"?",
"$",
"value",
"[",
"'month'",
"]",
":",
"date",
"(",
"'m'",
")",
",",
"isset",
"(",
"$",
"value",
"[",
"'day'",
"]",
")",
"?",
"$",
"value",
"[",
"'day'",
"]",
":",
"date",
"(",
"'d'",
")",
",",
"isset",
"(",
"$",
"value",
"[",
"'year'",
"]",
")",
"?",
"$",
"value",
"[",
"'year'",
"]",
":",
"date",
"(",
"'Y'",
")",
")",
";",
"$",
"value",
"=",
"Time",
"::",
"factory",
"(",
"date",
"(",
"'Y-m-d H:i:s'",
",",
"$",
"timestamp",
")",
",",
"isset",
"(",
"$",
"value",
"[",
"'timezone'",
"]",
")",
"?",
"$",
"value",
"[",
"'timezone'",
"]",
":",
"null",
")",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"DateTime",
")",
"{",
"return",
"$",
"value",
"->",
"format",
"(",
"$",
"this",
"->",
"format",
")",
";",
"}",
"return",
"date",
"(",
"$",
"this",
"->",
"format",
",",
"Time",
"::",
"toUnix",
"(",
"$",
"value",
")",
")",
";",
"}"
]
| {@inheritdoc}
@uses Titon\Utility\Time | [
"{",
"@inheritdoc",
"}"
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Type/DateType.php#L46-L70 |
nyeholt/silverstripe-external-content | code/forms/ExternalTreeDropdownField.php | ExternalTreeDropdownField.objectForKey | protected function objectForKey($key) {
if ($this->keyField == 'ID') {
return ExternalContent::getDataObjectFor($key);
} else {
return DataObject::get_one($this->sourceObject, "\"{$this->keyField}\" = '" . Convert::raw2sql($key) . "'");
}
} | php | protected function objectForKey($key) {
if ($this->keyField == 'ID') {
return ExternalContent::getDataObjectFor($key);
} else {
return DataObject::get_one($this->sourceObject, "\"{$this->keyField}\" = '" . Convert::raw2sql($key) . "'");
}
} | [
"protected",
"function",
"objectForKey",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"keyField",
"==",
"'ID'",
")",
"{",
"return",
"ExternalContent",
"::",
"getDataObjectFor",
"(",
"$",
"key",
")",
";",
"}",
"else",
"{",
"return",
"DataObject",
"::",
"get_one",
"(",
"$",
"this",
"->",
"sourceObject",
",",
"\"\\\"{$this->keyField}\\\" = '\"",
".",
"Convert",
"::",
"raw2sql",
"(",
"$",
"key",
")",
".",
"\"'\"",
")",
";",
"}",
"}"
]
| Get the object where the $keyField is equal to a certain value
@param string|int $key
@return DataObject | [
"Get",
"the",
"object",
"where",
"the",
"$keyField",
"is",
"equal",
"to",
"a",
"certain",
"value"
]
| train | https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/code/forms/ExternalTreeDropdownField.php#L40-L46 |
silvercommerce/catalogue-frontend | src/extensions/CategoryExtension.php | CategoryExtension.PrimaryImage | public function PrimaryImage()
{
// If we have associated an image, return it
$image = $this->owner->Image();
if ($image->exists()) {
return $image;
}
// Next try and get a child product image
$product = $this->owner->AllProducts()->first();
if (!empty($product)) {
return $product->PrimaryImage();
}
// Finally generate our no product image
return Helper::generate_no_image();
} | php | public function PrimaryImage()
{
// If we have associated an image, return it
$image = $this->owner->Image();
if ($image->exists()) {
return $image;
}
// Next try and get a child product image
$product = $this->owner->AllProducts()->first();
if (!empty($product)) {
return $product->PrimaryImage();
}
// Finally generate our no product image
return Helper::generate_no_image();
} | [
"public",
"function",
"PrimaryImage",
"(",
")",
"{",
"// If we have associated an image, return it",
"$",
"image",
"=",
"$",
"this",
"->",
"owner",
"->",
"Image",
"(",
")",
";",
"if",
"(",
"$",
"image",
"->",
"exists",
"(",
")",
")",
"{",
"return",
"$",
"image",
";",
"}",
"// Next try and get a child product image",
"$",
"product",
"=",
"$",
"this",
"->",
"owner",
"->",
"AllProducts",
"(",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"product",
")",
")",
"{",
"return",
"$",
"product",
"->",
"PrimaryImage",
"(",
")",
";",
"}",
"// Finally generate our no product image",
"return",
"Helper",
"::",
"generate_no_image",
"(",
")",
";",
"}"
]
| Gets the main image to use for this category, this
can either be the selected image, an image from the
first product or the default "no-product" image.
@return Image | [
"Gets",
"the",
"main",
"image",
"to",
"use",
"for",
"this",
"category",
"this",
"can",
"either",
"be",
"the",
"selected",
"image",
"an",
"image",
"from",
"the",
"first",
"product",
"or",
"the",
"default",
"no",
"-",
"product",
"image",
"."
]
| train | https://github.com/silvercommerce/catalogue-frontend/blob/671f1e32bf6bc6eb193c6608ae904cd055540cc4/src/extensions/CategoryExtension.php#L35-L53 |
anexia-it/anexia-laravel-encryption | src/DatabaseEncryptionServiceProvider.php | DatabaseEncryptionServiceProvider.boot | public function boot()
{
Builder::macro('whereDecrypted', function($attribute, $operator = null, $value = null, $decryptKey = null){
list($value, $operator, $decryptKey) = $this->query->prepareDecryptionValueOperatorAndDecryptKey(
$value, $operator, $decryptKey, func_num_args() == 3
);
$model = $this->getModel();
$encryptedFields = $model::getEncryptedFields();
if (in_array($attribute, $encryptedFields)) {
$encryptionService = $model::getEncryptionService();
$this->whereRaw($encryptionService->getDecryptExpression($attribute, $decryptKey) . " " . $operator . " ?", [$value]);
} else {
$this->where($attribute, $operator, $value);
}
return $this;
});
Builder::macro('orWhereDecrypted', function($attribute, $operator = null, $value = null, $decryptKey = null){
list($value, $operator, $decryptKey) = $this->query->prepareDecryptionValueOperatorAndDecryptKey(
$value, $operator, $decryptKey, func_num_args() == 3
);
$model = $this->getModel();
$encryptedFields = $model::getEncryptedFields();
if (in_array($attribute, $encryptedFields)) {
$encryptionService = $model::getEncryptionService();
$this->orWhereRaw($encryptionService->getDecryptExpression($attribute, $decryptKey) . " " . $operator . " ?", [$value]);
} else {
$this->orWhere($attribute, $operator, $value);
}
return $this;
});
Builder::macro('orderByDecrypted', function($attribute, $direction = 'asc', $decryptKey = null){
$model = $this->getModel();
$encryptedFields = $model::getEncryptedFields();
if (in_array($attribute, $encryptedFields)) {
$encryptionService = $model::getEncryptionService();
$this->orderByRaw($encryptionService->getDecryptExpression($attribute, $decryptKey) . " " . $direction);
} else {
$this->orderBy($attribute, $direction);
}
return $this;
});
} | php | public function boot()
{
Builder::macro('whereDecrypted', function($attribute, $operator = null, $value = null, $decryptKey = null){
list($value, $operator, $decryptKey) = $this->query->prepareDecryptionValueOperatorAndDecryptKey(
$value, $operator, $decryptKey, func_num_args() == 3
);
$model = $this->getModel();
$encryptedFields = $model::getEncryptedFields();
if (in_array($attribute, $encryptedFields)) {
$encryptionService = $model::getEncryptionService();
$this->whereRaw($encryptionService->getDecryptExpression($attribute, $decryptKey) . " " . $operator . " ?", [$value]);
} else {
$this->where($attribute, $operator, $value);
}
return $this;
});
Builder::macro('orWhereDecrypted', function($attribute, $operator = null, $value = null, $decryptKey = null){
list($value, $operator, $decryptKey) = $this->query->prepareDecryptionValueOperatorAndDecryptKey(
$value, $operator, $decryptKey, func_num_args() == 3
);
$model = $this->getModel();
$encryptedFields = $model::getEncryptedFields();
if (in_array($attribute, $encryptedFields)) {
$encryptionService = $model::getEncryptionService();
$this->orWhereRaw($encryptionService->getDecryptExpression($attribute, $decryptKey) . " " . $operator . " ?", [$value]);
} else {
$this->orWhere($attribute, $operator, $value);
}
return $this;
});
Builder::macro('orderByDecrypted', function($attribute, $direction = 'asc', $decryptKey = null){
$model = $this->getModel();
$encryptedFields = $model::getEncryptedFields();
if (in_array($attribute, $encryptedFields)) {
$encryptionService = $model::getEncryptionService();
$this->orderByRaw($encryptionService->getDecryptExpression($attribute, $decryptKey) . " " . $direction);
} else {
$this->orderBy($attribute, $direction);
}
return $this;
});
} | [
"public",
"function",
"boot",
"(",
")",
"{",
"Builder",
"::",
"macro",
"(",
"'whereDecrypted'",
",",
"function",
"(",
"$",
"attribute",
",",
"$",
"operator",
"=",
"null",
",",
"$",
"value",
"=",
"null",
",",
"$",
"decryptKey",
"=",
"null",
")",
"{",
"list",
"(",
"$",
"value",
",",
"$",
"operator",
",",
"$",
"decryptKey",
")",
"=",
"$",
"this",
"->",
"query",
"->",
"prepareDecryptionValueOperatorAndDecryptKey",
"(",
"$",
"value",
",",
"$",
"operator",
",",
"$",
"decryptKey",
",",
"func_num_args",
"(",
")",
"==",
"3",
")",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"getModel",
"(",
")",
";",
"$",
"encryptedFields",
"=",
"$",
"model",
"::",
"getEncryptedFields",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"attribute",
",",
"$",
"encryptedFields",
")",
")",
"{",
"$",
"encryptionService",
"=",
"$",
"model",
"::",
"getEncryptionService",
"(",
")",
";",
"$",
"this",
"->",
"whereRaw",
"(",
"$",
"encryptionService",
"->",
"getDecryptExpression",
"(",
"$",
"attribute",
",",
"$",
"decryptKey",
")",
".",
"\" \"",
".",
"$",
"operator",
".",
"\" ?\"",
",",
"[",
"$",
"value",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"where",
"(",
"$",
"attribute",
",",
"$",
"operator",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}",
")",
";",
"Builder",
"::",
"macro",
"(",
"'orWhereDecrypted'",
",",
"function",
"(",
"$",
"attribute",
",",
"$",
"operator",
"=",
"null",
",",
"$",
"value",
"=",
"null",
",",
"$",
"decryptKey",
"=",
"null",
")",
"{",
"list",
"(",
"$",
"value",
",",
"$",
"operator",
",",
"$",
"decryptKey",
")",
"=",
"$",
"this",
"->",
"query",
"->",
"prepareDecryptionValueOperatorAndDecryptKey",
"(",
"$",
"value",
",",
"$",
"operator",
",",
"$",
"decryptKey",
",",
"func_num_args",
"(",
")",
"==",
"3",
")",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"getModel",
"(",
")",
";",
"$",
"encryptedFields",
"=",
"$",
"model",
"::",
"getEncryptedFields",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"attribute",
",",
"$",
"encryptedFields",
")",
")",
"{",
"$",
"encryptionService",
"=",
"$",
"model",
"::",
"getEncryptionService",
"(",
")",
";",
"$",
"this",
"->",
"orWhereRaw",
"(",
"$",
"encryptionService",
"->",
"getDecryptExpression",
"(",
"$",
"attribute",
",",
"$",
"decryptKey",
")",
".",
"\" \"",
".",
"$",
"operator",
".",
"\" ?\"",
",",
"[",
"$",
"value",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"orWhere",
"(",
"$",
"attribute",
",",
"$",
"operator",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}",
")",
";",
"Builder",
"::",
"macro",
"(",
"'orderByDecrypted'",
",",
"function",
"(",
"$",
"attribute",
",",
"$",
"direction",
"=",
"'asc'",
",",
"$",
"decryptKey",
"=",
"null",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"getModel",
"(",
")",
";",
"$",
"encryptedFields",
"=",
"$",
"model",
"::",
"getEncryptedFields",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"attribute",
",",
"$",
"encryptedFields",
")",
")",
"{",
"$",
"encryptionService",
"=",
"$",
"model",
"::",
"getEncryptionService",
"(",
")",
";",
"$",
"this",
"->",
"orderByRaw",
"(",
"$",
"encryptionService",
"->",
"getDecryptExpression",
"(",
"$",
"attribute",
",",
"$",
"decryptKey",
")",
".",
"\" \"",
".",
"$",
"direction",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"orderBy",
"(",
"$",
"attribute",
",",
"$",
"direction",
")",
";",
"}",
"return",
"$",
"this",
";",
"}",
")",
";",
"}"
]
| Bootstrap the application services.
@return void | [
"Bootstrap",
"the",
"application",
"services",
"."
]
| train | https://github.com/anexia-it/anexia-laravel-encryption/blob/b7c72d99916ebca2d2cf2dbab1d4c0f84e383081/src/DatabaseEncryptionServiceProvider.php#L15-L60 |
helthe/Chronos | Field/DayOfMonthField.php | DayOfMonthField.matches | public function matches(\DateTime $date)
{
if ('?' === $this->value) {
return true;
}
$found = parent::matches($date);
if (!$found) {
$values = $this->getValueArray();
foreach ($values as $value) {
if ($found) {
break;
}
if ('L' === $value) {
$found = $date->format('t') == $date->format('d');
} elseif (strpos($value, 'W') !== false) {
$found = $this->matchesNearestWeekday($value, $date);
}
}
}
return $found;
} | php | public function matches(\DateTime $date)
{
if ('?' === $this->value) {
return true;
}
$found = parent::matches($date);
if (!$found) {
$values = $this->getValueArray();
foreach ($values as $value) {
if ($found) {
break;
}
if ('L' === $value) {
$found = $date->format('t') == $date->format('d');
} elseif (strpos($value, 'W') !== false) {
$found = $this->matchesNearestWeekday($value, $date);
}
}
}
return $found;
} | [
"public",
"function",
"matches",
"(",
"\\",
"DateTime",
"$",
"date",
")",
"{",
"if",
"(",
"'?'",
"===",
"$",
"this",
"->",
"value",
")",
"{",
"return",
"true",
";",
"}",
"$",
"found",
"=",
"parent",
"::",
"matches",
"(",
"$",
"date",
")",
";",
"if",
"(",
"!",
"$",
"found",
")",
"{",
"$",
"values",
"=",
"$",
"this",
"->",
"getValueArray",
"(",
")",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"found",
")",
"{",
"break",
";",
"}",
"if",
"(",
"'L'",
"===",
"$",
"value",
")",
"{",
"$",
"found",
"=",
"$",
"date",
"->",
"format",
"(",
"'t'",
")",
"==",
"$",
"date",
"->",
"format",
"(",
"'d'",
")",
";",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"value",
",",
"'W'",
")",
"!==",
"false",
")",
"{",
"$",
"found",
"=",
"$",
"this",
"->",
"matchesNearestWeekday",
"(",
"$",
"value",
",",
"$",
"date",
")",
";",
"}",
"}",
"}",
"return",
"$",
"found",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/helthe/Chronos/blob/6c783c55c32b323550fc6f21cd644c2be82720b0/Field/DayOfMonthField.php#L24-L49 |
helthe/Chronos | Field/DayOfMonthField.php | DayOfMonthField.matchesNearestWeekday | private function matchesNearestWeekday($day, \DateTime $date)
{
$day = new \DateTime($date->format('F') . ' ' . substr($day, 0, -1) . ' ' . $date->format('Y'));
$weekday = $day->format('w');
if ($day->format('d') == $date->format('d') && $weekday !== '0' && $weekday !== '6') {
return true;
} elseif ($weekday == '0'
&& $day->format('d') != $day->format('t')
&& $this->getModifiedDateTime($day, 'next day')->format('d') == $date->format('d')
) {
return true;
} elseif ($weekday == '6'
&& $day->format('d') != '1'
&& $this->getModifiedDateTime($day, 'previous day')->format('d') == $date->format('d')
) {
return true;
}
return false;
} | php | private function matchesNearestWeekday($day, \DateTime $date)
{
$day = new \DateTime($date->format('F') . ' ' . substr($day, 0, -1) . ' ' . $date->format('Y'));
$weekday = $day->format('w');
if ($day->format('d') == $date->format('d') && $weekday !== '0' && $weekday !== '6') {
return true;
} elseif ($weekday == '0'
&& $day->format('d') != $day->format('t')
&& $this->getModifiedDateTime($day, 'next day')->format('d') == $date->format('d')
) {
return true;
} elseif ($weekday == '6'
&& $day->format('d') != '1'
&& $this->getModifiedDateTime($day, 'previous day')->format('d') == $date->format('d')
) {
return true;
}
return false;
} | [
"private",
"function",
"matchesNearestWeekday",
"(",
"$",
"day",
",",
"\\",
"DateTime",
"$",
"date",
")",
"{",
"$",
"day",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"date",
"->",
"format",
"(",
"'F'",
")",
".",
"' '",
".",
"substr",
"(",
"$",
"day",
",",
"0",
",",
"-",
"1",
")",
".",
"' '",
".",
"$",
"date",
"->",
"format",
"(",
"'Y'",
")",
")",
";",
"$",
"weekday",
"=",
"$",
"day",
"->",
"format",
"(",
"'w'",
")",
";",
"if",
"(",
"$",
"day",
"->",
"format",
"(",
"'d'",
")",
"==",
"$",
"date",
"->",
"format",
"(",
"'d'",
")",
"&&",
"$",
"weekday",
"!==",
"'0'",
"&&",
"$",
"weekday",
"!==",
"'6'",
")",
"{",
"return",
"true",
";",
"}",
"elseif",
"(",
"$",
"weekday",
"==",
"'0'",
"&&",
"$",
"day",
"->",
"format",
"(",
"'d'",
")",
"!=",
"$",
"day",
"->",
"format",
"(",
"'t'",
")",
"&&",
"$",
"this",
"->",
"getModifiedDateTime",
"(",
"$",
"day",
",",
"'next day'",
")",
"->",
"format",
"(",
"'d'",
")",
"==",
"$",
"date",
"->",
"format",
"(",
"'d'",
")",
")",
"{",
"return",
"true",
";",
"}",
"elseif",
"(",
"$",
"weekday",
"==",
"'6'",
"&&",
"$",
"day",
"->",
"format",
"(",
"'d'",
")",
"!=",
"'1'",
"&&",
"$",
"this",
"->",
"getModifiedDateTime",
"(",
"$",
"day",
",",
"'previous day'",
")",
"->",
"format",
"(",
"'d'",
")",
"==",
"$",
"date",
"->",
"format",
"(",
"'d'",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Checks if the given last day matches the given date.
@param string $day
@param \DateTime $date
@return Boolean | [
"Checks",
"if",
"the",
"given",
"last",
"day",
"matches",
"the",
"given",
"date",
"."
]
| train | https://github.com/helthe/Chronos/blob/6c783c55c32b323550fc6f21cd644c2be82720b0/Field/DayOfMonthField.php#L102-L122 |
dms-org/package.blog | src/Domain/Entities/BlogArticle.php | BlogArticle.defineEntity | protected function defineEntity(ClassDefinition $class)
{
$class->property($this->author)->asObject(BlogAuthor::class);
$class->property($this->category)->nullable()->asObject(BlogCategory::class);
$class->property($this->title)->asString();
$class->property($this->subTitle)->asString();
$class->property($this->slug)->asString();
$class->property($this->extract)->asString();
$class->property($this->featuredImage)->nullable()->asObject(Image::class);
$class->property($this->date)->asObject(Date::class);
$class->property($this->articleContent)->asObject(Html::class);
$class->property($this->comments)->asType(BlogArticleComment::collectionType());
$class->property($this->allowSharing)->asBool();
$class->property($this->allowCommenting)->asBool();
$class->property($this->published)->asBool();
$class->property($this->createdAt)->asObject(DateTime::class);
$class->property($this->updatedAt)->asObject(DateTime::class);
$this->defineMetadata($class);
} | php | protected function defineEntity(ClassDefinition $class)
{
$class->property($this->author)->asObject(BlogAuthor::class);
$class->property($this->category)->nullable()->asObject(BlogCategory::class);
$class->property($this->title)->asString();
$class->property($this->subTitle)->asString();
$class->property($this->slug)->asString();
$class->property($this->extract)->asString();
$class->property($this->featuredImage)->nullable()->asObject(Image::class);
$class->property($this->date)->asObject(Date::class);
$class->property($this->articleContent)->asObject(Html::class);
$class->property($this->comments)->asType(BlogArticleComment::collectionType());
$class->property($this->allowSharing)->asBool();
$class->property($this->allowCommenting)->asBool();
$class->property($this->published)->asBool();
$class->property($this->createdAt)->asObject(DateTime::class);
$class->property($this->updatedAt)->asObject(DateTime::class);
$this->defineMetadata($class);
} | [
"protected",
"function",
"defineEntity",
"(",
"ClassDefinition",
"$",
"class",
")",
"{",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"author",
")",
"->",
"asObject",
"(",
"BlogAuthor",
"::",
"class",
")",
";",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"category",
")",
"->",
"nullable",
"(",
")",
"->",
"asObject",
"(",
"BlogCategory",
"::",
"class",
")",
";",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"title",
")",
"->",
"asString",
"(",
")",
";",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"subTitle",
")",
"->",
"asString",
"(",
")",
";",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"slug",
")",
"->",
"asString",
"(",
")",
";",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"extract",
")",
"->",
"asString",
"(",
")",
";",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"featuredImage",
")",
"->",
"nullable",
"(",
")",
"->",
"asObject",
"(",
"Image",
"::",
"class",
")",
";",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"date",
")",
"->",
"asObject",
"(",
"Date",
"::",
"class",
")",
";",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"articleContent",
")",
"->",
"asObject",
"(",
"Html",
"::",
"class",
")",
";",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"comments",
")",
"->",
"asType",
"(",
"BlogArticleComment",
"::",
"collectionType",
"(",
")",
")",
";",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"allowSharing",
")",
"->",
"asBool",
"(",
")",
";",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"allowCommenting",
")",
"->",
"asBool",
"(",
")",
";",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"published",
")",
"->",
"asBool",
"(",
")",
";",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"createdAt",
")",
"->",
"asObject",
"(",
"DateTime",
"::",
"class",
")",
";",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"updatedAt",
")",
"->",
"asObject",
"(",
"DateTime",
"::",
"class",
")",
";",
"$",
"this",
"->",
"defineMetadata",
"(",
"$",
"class",
")",
";",
"}"
]
| Defines the structure of this entity.
@param ClassDefinition $class | [
"Defines",
"the",
"structure",
"of",
"this",
"entity",
"."
]
| train | https://github.com/dms-org/package.blog/blob/1500f6fad20d81289a0dfa617fc1c54699f01e16/src/Domain/Entities/BlogArticle.php#L176-L209 |
dms-org/package.blog | src/Domain/Entities/BlogArticle.php | BlogArticle.postComment | public function postComment(string $authorName, EmailAddress $authorEmail, string $content, IClock $clock): BlogArticleComment
{
InvalidOperationException::verify($this->published, 'This blog article is not published');
InvalidOperationException::verify($this->allowCommenting, 'This blog article does not allow comments');
$comment = new BlogArticleComment(
$this,
$authorName,
$authorEmail,
$content,
$clock
);
$this->comments[] = $comment;
return $comment;
} | php | public function postComment(string $authorName, EmailAddress $authorEmail, string $content, IClock $clock): BlogArticleComment
{
InvalidOperationException::verify($this->published, 'This blog article is not published');
InvalidOperationException::verify($this->allowCommenting, 'This blog article does not allow comments');
$comment = new BlogArticleComment(
$this,
$authorName,
$authorEmail,
$content,
$clock
);
$this->comments[] = $comment;
return $comment;
} | [
"public",
"function",
"postComment",
"(",
"string",
"$",
"authorName",
",",
"EmailAddress",
"$",
"authorEmail",
",",
"string",
"$",
"content",
",",
"IClock",
"$",
"clock",
")",
":",
"BlogArticleComment",
"{",
"InvalidOperationException",
"::",
"verify",
"(",
"$",
"this",
"->",
"published",
",",
"'This blog article is not published'",
")",
";",
"InvalidOperationException",
"::",
"verify",
"(",
"$",
"this",
"->",
"allowCommenting",
",",
"'This blog article does not allow comments'",
")",
";",
"$",
"comment",
"=",
"new",
"BlogArticleComment",
"(",
"$",
"this",
",",
"$",
"authorName",
",",
"$",
"authorEmail",
",",
"$",
"content",
",",
"$",
"clock",
")",
";",
"$",
"this",
"->",
"comments",
"[",
"]",
"=",
"$",
"comment",
";",
"return",
"$",
"comment",
";",
"}"
]
| @param string $authorName
@param EmailAddress $authorEmail
@param string $content
@param IClock $clock
@return BlogArticleComment | [
"@param",
"string",
"$authorName",
"@param",
"EmailAddress",
"$authorEmail",
"@param",
"string",
"$content",
"@param",
"IClock",
"$clock"
]
| train | https://github.com/dms-org/package.blog/blob/1500f6fad20d81289a0dfa617fc1c54699f01e16/src/Domain/Entities/BlogArticle.php#L219-L235 |
webforge-labs/psc-cms | lib/PHPWord/PHPWord/Writer/Word2007/ContentTypes.php | PHPWord_Writer_Word2007_ContentTypes._getImageMimeType | private function _getImageMimeType($pFile = '') {
if(PHPWord_Shared_File::file_exists($pFile)) {
$image = getimagesize($pFile);
return image_type_to_mime_type($image[2]);
} else {
throw new Exception("File $pFile does not exist");
}
} | php | private function _getImageMimeType($pFile = '') {
if(PHPWord_Shared_File::file_exists($pFile)) {
$image = getimagesize($pFile);
return image_type_to_mime_type($image[2]);
} else {
throw new Exception("File $pFile does not exist");
}
} | [
"private",
"function",
"_getImageMimeType",
"(",
"$",
"pFile",
"=",
"''",
")",
"{",
"if",
"(",
"PHPWord_Shared_File",
"::",
"file_exists",
"(",
"$",
"pFile",
")",
")",
"{",
"$",
"image",
"=",
"getimagesize",
"(",
"$",
"pFile",
")",
";",
"return",
"image_type_to_mime_type",
"(",
"$",
"image",
"[",
"2",
"]",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"\"File $pFile does not exist\"",
")",
";",
"}",
"}"
]
| Get image mime type
@param string $pFile Filename
@return string Mime Type
@throws Exception | [
"Get",
"image",
"mime",
"type"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Writer/Word2007/ContentTypes.php#L137-L144 |
webforge-labs/psc-cms | lib/PHPWord/PHPWord/Writer/Word2007/ContentTypes.php | PHPWord_Writer_Word2007_ContentTypes._writeDefaultContentType | private function _writeDefaultContentType(PHPWord_Shared_XMLWriter $objWriter = null, $pPartname = '', $pContentType = '') {
if($pPartname != '' && $pContentType != '') {
// Write content type
$objWriter->startElement('Default');
$objWriter->writeAttribute('Extension', $pPartname);
$objWriter->writeAttribute('ContentType', $pContentType);
$objWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
} | php | private function _writeDefaultContentType(PHPWord_Shared_XMLWriter $objWriter = null, $pPartname = '', $pContentType = '') {
if($pPartname != '' && $pContentType != '') {
// Write content type
$objWriter->startElement('Default');
$objWriter->writeAttribute('Extension', $pPartname);
$objWriter->writeAttribute('ContentType', $pContentType);
$objWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
} | [
"private",
"function",
"_writeDefaultContentType",
"(",
"PHPWord_Shared_XMLWriter",
"$",
"objWriter",
"=",
"null",
",",
"$",
"pPartname",
"=",
"''",
",",
"$",
"pContentType",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"pPartname",
"!=",
"''",
"&&",
"$",
"pContentType",
"!=",
"''",
")",
"{",
"// Write content type\r",
"$",
"objWriter",
"->",
"startElement",
"(",
"'Default'",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'Extension'",
",",
"$",
"pPartname",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'ContentType'",
",",
"$",
"pContentType",
")",
";",
"$",
"objWriter",
"->",
"endElement",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"\"Invalid parameters passed.\"",
")",
";",
"}",
"}"
]
| Write Default content type
@param PHPWord_Shared_XMLWriter $objWriter XML Writer
@param string $pPartname Part name
@param string $pContentType Content type
@throws Exception | [
"Write",
"Default",
"content",
"type"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Writer/Word2007/ContentTypes.php#L154-L164 |
AydinHassan/cli-md-renderer | src/CliRenderer.php | CliRenderer.renderInlines | public function renderInlines(array $inlines)
{
return implode(
"",
array_map(
function (AbstractInline $inline) {
$renderer = $this->getInlineRendererForClass(get_class($inline));
if (!$renderer) {
throw new RuntimeException(
sprintf('Unable to find corresponding renderer for inline type: "%s"', get_class($inline))
);
}
return $renderer->render($inline, $this);
},
$inlines
)
);
} | php | public function renderInlines(array $inlines)
{
return implode(
"",
array_map(
function (AbstractInline $inline) {
$renderer = $this->getInlineRendererForClass(get_class($inline));
if (!$renderer) {
throw new RuntimeException(
sprintf('Unable to find corresponding renderer for inline type: "%s"', get_class($inline))
);
}
return $renderer->render($inline, $this);
},
$inlines
)
);
} | [
"public",
"function",
"renderInlines",
"(",
"array",
"$",
"inlines",
")",
"{",
"return",
"implode",
"(",
"\"\"",
",",
"array_map",
"(",
"function",
"(",
"AbstractInline",
"$",
"inline",
")",
"{",
"$",
"renderer",
"=",
"$",
"this",
"->",
"getInlineRendererForClass",
"(",
"get_class",
"(",
"$",
"inline",
")",
")",
";",
"if",
"(",
"!",
"$",
"renderer",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Unable to find corresponding renderer for inline type: \"%s\"'",
",",
"get_class",
"(",
"$",
"inline",
")",
")",
")",
";",
"}",
"return",
"$",
"renderer",
"->",
"render",
"(",
"$",
"inline",
",",
"$",
"this",
")",
";",
"}",
",",
"$",
"inlines",
")",
")",
";",
"}"
]
| @param AbstractInline[] $inlines
@return string | [
"@param",
"AbstractInline",
"[]",
"$inlines"
]
| train | https://github.com/AydinHassan/cli-md-renderer/blob/521f9ace2aeadd58bf8a3910704be8360f5bd7b2/src/CliRenderer.php#L73-L91 |
AydinHassan/cli-md-renderer | src/CliRenderer.php | CliRenderer.renderBlock | public function renderBlock(AbstractBlock $block)
{
$renderer = $this->getBlockRendererForClass(get_class($block));
if (!$renderer) {
throw new RuntimeException(
sprintf('Unable to find corresponding renderer for block type: "%s"', get_class($block))
);
}
return $renderer->render($block, $this);
} | php | public function renderBlock(AbstractBlock $block)
{
$renderer = $this->getBlockRendererForClass(get_class($block));
if (!$renderer) {
throw new RuntimeException(
sprintf('Unable to find corresponding renderer for block type: "%s"', get_class($block))
);
}
return $renderer->render($block, $this);
} | [
"public",
"function",
"renderBlock",
"(",
"AbstractBlock",
"$",
"block",
")",
"{",
"$",
"renderer",
"=",
"$",
"this",
"->",
"getBlockRendererForClass",
"(",
"get_class",
"(",
"$",
"block",
")",
")",
";",
"if",
"(",
"!",
"$",
"renderer",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Unable to find corresponding renderer for block type: \"%s\"'",
",",
"get_class",
"(",
"$",
"block",
")",
")",
")",
";",
"}",
"return",
"$",
"renderer",
"->",
"render",
"(",
"$",
"block",
",",
"$",
"this",
")",
";",
"}"
]
| @param AbstractBlock $block
@throws RuntimeException
@return string | [
"@param",
"AbstractBlock",
"$block"
]
| train | https://github.com/AydinHassan/cli-md-renderer/blob/521f9ace2aeadd58bf8a3910704be8360f5bd7b2/src/CliRenderer.php#L100-L110 |
AydinHassan/cli-md-renderer | src/CliRenderer.php | CliRenderer.renderBlocks | public function renderBlocks(array $blocks)
{
return implode(
"\n",
array_map(
function (AbstractBlock $block) {
return $this->renderBlock($block);
},
$blocks
)
);
} | php | public function renderBlocks(array $blocks)
{
return implode(
"\n",
array_map(
function (AbstractBlock $block) {
return $this->renderBlock($block);
},
$blocks
)
);
} | [
"public",
"function",
"renderBlocks",
"(",
"array",
"$",
"blocks",
")",
"{",
"return",
"implode",
"(",
"\"\\n\"",
",",
"array_map",
"(",
"function",
"(",
"AbstractBlock",
"$",
"block",
")",
"{",
"return",
"$",
"this",
"->",
"renderBlock",
"(",
"$",
"block",
")",
";",
"}",
",",
"$",
"blocks",
")",
")",
";",
"}"
]
| @param AbstractBlock[] $blocks
@return string | [
"@param",
"AbstractBlock",
"[]",
"$blocks"
]
| train | https://github.com/AydinHassan/cli-md-renderer/blob/521f9ace2aeadd58bf8a3910704be8360f5bd7b2/src/CliRenderer.php#L117-L128 |
AydinHassan/cli-md-renderer | src/CliRenderer.php | CliRenderer.getInlineRendererForClass | private function getInlineRendererForClass($inlineBlockClass)
{
if (!isset($this->inlineRenderers[$inlineBlockClass])) {
return null;
}
return $this->inlineRenderers[$inlineBlockClass];
} | php | private function getInlineRendererForClass($inlineBlockClass)
{
if (!isset($this->inlineRenderers[$inlineBlockClass])) {
return null;
}
return $this->inlineRenderers[$inlineBlockClass];
} | [
"private",
"function",
"getInlineRendererForClass",
"(",
"$",
"inlineBlockClass",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"inlineRenderers",
"[",
"$",
"inlineBlockClass",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"inlineRenderers",
"[",
"$",
"inlineBlockClass",
"]",
";",
"}"
]
| @param string $inlineBlockClass
@return null|CliInlineRendererInterface | [
"@param",
"string",
"$inlineBlockClass"
]
| train | https://github.com/AydinHassan/cli-md-renderer/blob/521f9ace2aeadd58bf8a3910704be8360f5bd7b2/src/CliRenderer.php#L135-L142 |
AydinHassan/cli-md-renderer | src/CliRenderer.php | CliRenderer.getBlockRendererForClass | private function getBlockRendererForClass($blockClass)
{
if (!isset($this->renderers[$blockClass])) {
return null;
}
return $this->renderers[$blockClass];
} | php | private function getBlockRendererForClass($blockClass)
{
if (!isset($this->renderers[$blockClass])) {
return null;
}
return $this->renderers[$blockClass];
} | [
"private",
"function",
"getBlockRendererForClass",
"(",
"$",
"blockClass",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"renderers",
"[",
"$",
"blockClass",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"renderers",
"[",
"$",
"blockClass",
"]",
";",
"}"
]
| @param string $blockClass
@return null|CliBlockRendererInterface | [
"@param",
"string",
"$blockClass"
]
| train | https://github.com/AydinHassan/cli-md-renderer/blob/521f9ace2aeadd58bf8a3910704be8360f5bd7b2/src/CliRenderer.php#L149-L156 |
PeekAndPoke/psi | src/Operation/FullSet/FlattenOperation.php | FlattenOperation.apply | public function apply(\Iterator $set)
{
$result = new \ArrayIterator();
$this->flatten($result, $set);
return $result;
} | php | public function apply(\Iterator $set)
{
$result = new \ArrayIterator();
$this->flatten($result, $set);
return $result;
} | [
"public",
"function",
"apply",
"(",
"\\",
"Iterator",
"$",
"set",
")",
"{",
"$",
"result",
"=",
"new",
"\\",
"ArrayIterator",
"(",
")",
";",
"$",
"this",
"->",
"flatten",
"(",
"$",
"result",
",",
"$",
"set",
")",
";",
"return",
"$",
"result",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/PeekAndPoke/psi/blob/cfd45d995d3a2c2ea6ba5b1ce7b5fcc71179456f/src/Operation/FullSet/FlattenOperation.php#L22-L29 |
helthe/Chronos | Job/AbstractJob.php | AbstractJob.isDue | public function isDue($date = 'now')
{
if (!$date instanceof \DateTime) {
$date = new \DateTime($date);
}
return $this->expression->matches($date);
} | php | public function isDue($date = 'now')
{
if (!$date instanceof \DateTime) {
$date = new \DateTime($date);
}
return $this->expression->matches($date);
} | [
"public",
"function",
"isDue",
"(",
"$",
"date",
"=",
"'now'",
")",
"{",
"if",
"(",
"!",
"$",
"date",
"instanceof",
"\\",
"DateTime",
")",
"{",
"$",
"date",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"date",
")",
";",
"}",
"return",
"$",
"this",
"->",
"expression",
"->",
"matches",
"(",
"$",
"date",
")",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/helthe/Chronos/blob/6c783c55c32b323550fc6f21cd644c2be82720b0/Job/AbstractJob.php#L53-L60 |
devmobgroup/postcodes | src/Util/Json.php | Json.decode | public static function decode(ResponseInterface $response): array
{
$contents = $response->getBody()->getContents();
$decoded = json_decode($contents, true);
$response->getBody()->rewind();
if (json_last_error() !== JSON_ERROR_NONE || ! is_array($decoded)) {
throw new JsonException(json_last_error_msg());
}
return $decoded;
} | php | public static function decode(ResponseInterface $response): array
{
$contents = $response->getBody()->getContents();
$decoded = json_decode($contents, true);
$response->getBody()->rewind();
if (json_last_error() !== JSON_ERROR_NONE || ! is_array($decoded)) {
throw new JsonException(json_last_error_msg());
}
return $decoded;
} | [
"public",
"static",
"function",
"decode",
"(",
"ResponseInterface",
"$",
"response",
")",
":",
"array",
"{",
"$",
"contents",
"=",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"getContents",
"(",
")",
";",
"$",
"decoded",
"=",
"json_decode",
"(",
"$",
"contents",
",",
"true",
")",
";",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"rewind",
"(",
")",
";",
"if",
"(",
"json_last_error",
"(",
")",
"!==",
"JSON_ERROR_NONE",
"||",
"!",
"is_array",
"(",
"$",
"decoded",
")",
")",
"{",
"throw",
"new",
"JsonException",
"(",
"json_last_error_msg",
"(",
")",
")",
";",
"}",
"return",
"$",
"decoded",
";",
"}"
]
| Json decode an http response.
@param \Psr\Http\Message\ResponseInterface $response
@return array
@throws \DevMob\Postcodes\Exceptions\JsonException | [
"Json",
"decode",
"an",
"http",
"response",
"."
]
| train | https://github.com/devmobgroup/postcodes/blob/1a8438fd960a8f50ec28d61af94560892b529f12/src/Util/Json.php#L17-L28 |
Nozemi/SlickBoard-Library | lib/SBLib/Database/DBUtil.php | DBUtil.addQuery | public function addQuery(DBUtilQuery $query) {
if($query->getName() !== null) {
$this->_queryQueue[$query->getName()] = $query;
} else {
$this->_queryQueue[] = $query;
}
new Logger('Query added to the queue.', Logger::DEBUG, __CLASS__, __LINE__);
return $this;
} | php | public function addQuery(DBUtilQuery $query) {
if($query->getName() !== null) {
$this->_queryQueue[$query->getName()] = $query;
} else {
$this->_queryQueue[] = $query;
}
new Logger('Query added to the queue.', Logger::DEBUG, __CLASS__, __LINE__);
return $this;
} | [
"public",
"function",
"addQuery",
"(",
"DBUtilQuery",
"$",
"query",
")",
"{",
"if",
"(",
"$",
"query",
"->",
"getName",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"_queryQueue",
"[",
"$",
"query",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"query",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_queryQueue",
"[",
"]",
"=",
"$",
"query",
";",
"}",
"new",
"Logger",
"(",
"'Query added to the queue.'",
",",
"Logger",
"::",
"DEBUG",
",",
"__CLASS__",
",",
"__LINE__",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Adds a query with it's parameters to the query queue.
@param DBUtilQuery $query
@return $this | [
"Adds",
"a",
"query",
"with",
"it",
"s",
"parameters",
"to",
"the",
"query",
"queue",
"."
]
| train | https://github.com/Nozemi/SlickBoard-Library/blob/c9f0a26a30f8127c997f75d7232eac170972418d/lib/SBLib/Database/DBUtil.php#L123-L132 |
Nozemi/SlickBoard-Library | lib/SBLib/Database/DBUtil.php | DBUtil.addQueries | public function addQueries($queries) {
if(is_array($queries)) {
foreach($queries as $query) {
$this->addQuery($query);
}
new Logger('Queries added to the queue.', Logger::DEBUG, __CLASS__, __LINE__);
return $this;
}
new Logger('Failed to add to the queue.', Logger::ERROR, __CLASS__, __LINE__);
return $this;
} | php | public function addQueries($queries) {
if(is_array($queries)) {
foreach($queries as $query) {
$this->addQuery($query);
}
new Logger('Queries added to the queue.', Logger::DEBUG, __CLASS__, __LINE__);
return $this;
}
new Logger('Failed to add to the queue.', Logger::ERROR, __CLASS__, __LINE__);
return $this;
} | [
"public",
"function",
"addQueries",
"(",
"$",
"queries",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"queries",
")",
")",
"{",
"foreach",
"(",
"$",
"queries",
"as",
"$",
"query",
")",
"{",
"$",
"this",
"->",
"addQuery",
"(",
"$",
"query",
")",
";",
"}",
"new",
"Logger",
"(",
"'Queries added to the queue.'",
",",
"Logger",
"::",
"DEBUG",
",",
"__CLASS__",
",",
"__LINE__",
")",
";",
"return",
"$",
"this",
";",
"}",
"new",
"Logger",
"(",
"'Failed to add to the queue.'",
",",
"Logger",
"::",
"ERROR",
",",
"__CLASS__",
",",
"__LINE__",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Add an array of "DBUtilQuery"s to the query_queue.
@param $queries
@return $this | [
"Add",
"an",
"array",
"of",
"DBUtilQuery",
"s",
"to",
"the",
"query_queue",
"."
]
| train | https://github.com/Nozemi/SlickBoard-Library/blob/c9f0a26a30f8127c997f75d7232eac170972418d/lib/SBLib/Database/DBUtil.php#L140-L152 |
yuncms/framework | src/rest/models/UploaderAudioForm.php | UploaderAudioForm.save | public function save()
{
if ($this->validate() && $this->file instanceof UploadedFile) {
try {
if (($uploader = $this->file->save()) != false) {
$this->file = $uploader->getUrl();
return true;
} else {
$this->addError('file', Yii::t('yuncms', 'Audio file storage failed.'));
}
} catch (FileExistsException $e) {
$this->addError('file', $e->getMessage());
} catch (ErrorException $e) {
$this->addError('file', $e->getMessage());
} catch (InvalidConfigException $e) {
$this->addError('file', $e->getMessage());
}
}
return false;
} | php | public function save()
{
if ($this->validate() && $this->file instanceof UploadedFile) {
try {
if (($uploader = $this->file->save()) != false) {
$this->file = $uploader->getUrl();
return true;
} else {
$this->addError('file', Yii::t('yuncms', 'Audio file storage failed.'));
}
} catch (FileExistsException $e) {
$this->addError('file', $e->getMessage());
} catch (ErrorException $e) {
$this->addError('file', $e->getMessage());
} catch (InvalidConfigException $e) {
$this->addError('file', $e->getMessage());
}
}
return false;
} | [
"public",
"function",
"save",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"validate",
"(",
")",
"&&",
"$",
"this",
"->",
"file",
"instanceof",
"UploadedFile",
")",
"{",
"try",
"{",
"if",
"(",
"(",
"$",
"uploader",
"=",
"$",
"this",
"->",
"file",
"->",
"save",
"(",
")",
")",
"!=",
"false",
")",
"{",
"$",
"this",
"->",
"file",
"=",
"$",
"uploader",
"->",
"getUrl",
"(",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addError",
"(",
"'file'",
",",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Audio file storage failed.'",
")",
")",
";",
"}",
"}",
"catch",
"(",
"FileExistsException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"'file'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"catch",
"(",
"ErrorException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"'file'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"catch",
"(",
"InvalidConfigException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"'file'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| 保存图片
@return boolean
@throws \Exception | [
"保存图片"
]
| train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/rest/models/UploaderAudioForm.php#L53-L72 |
ClanCats/Core | src/classes/CCValidator.php | CCValidator.errors | public function errors( $key = null )
{
if ( !is_null( $key ) )
{
if ( isset( $this->errors[$key] ) )
{
return $this->errors[$key];
}
return array();
}
$errors = array();
foreach( $this->errors as $error_array )
{
$errors = array_merge( $errors, $error_array );
}
return $errors;
} | php | public function errors( $key = null )
{
if ( !is_null( $key ) )
{
if ( isset( $this->errors[$key] ) )
{
return $this->errors[$key];
}
return array();
}
$errors = array();
foreach( $this->errors as $error_array )
{
$errors = array_merge( $errors, $error_array );
}
return $errors;
} | [
"public",
"function",
"errors",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"key",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"array",
"(",
")",
";",
"}",
"$",
"errors",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"errors",
"as",
"$",
"error_array",
")",
"{",
"$",
"errors",
"=",
"array_merge",
"(",
"$",
"errors",
",",
"$",
"error_array",
")",
";",
"}",
"return",
"$",
"errors",
";",
"}"
]
| Return the error messages
@return array | [
"Return",
"the",
"error",
"messages"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCValidator.php#L137-L156 |
ClanCats/Core | src/classes/CCValidator.php | CCValidator.add_error | public function add_error( $key, $message )
{
$this->success = false;
$this->errors[$key][] = $message;
} | php | public function add_error( $key, $message )
{
$this->success = false;
$this->errors[$key][] = $message;
} | [
"public",
"function",
"add_error",
"(",
"$",
"key",
",",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"success",
"=",
"false",
";",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"message",
";",
"}"
]
| Add an error to validator
@param string $key
@param string $message
@return void | [
"Add",
"an",
"error",
"to",
"validator"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCValidator.php#L165-L169 |
ClanCats/Core | src/classes/CCValidator.php | CCValidator.label | public function label( $data, $value = null )
{
if ( !is_null( $value ) && !is_array( $data ) )
{
$data = array( $data => $value );
}
if ( !is_array( $data ) )
{
throw new \InvalidArgumentException( 'CCValidator::label - invalid label data given' );
}
$this->labels = array_merge( $this->labels, $data );
} | php | public function label( $data, $value = null )
{
if ( !is_null( $value ) && !is_array( $data ) )
{
$data = array( $data => $value );
}
if ( !is_array( $data ) )
{
throw new \InvalidArgumentException( 'CCValidator::label - invalid label data given' );
}
$this->labels = array_merge( $this->labels, $data );
} | [
"public",
"function",
"label",
"(",
"$",
"data",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"value",
")",
"&&",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"array",
"(",
"$",
"data",
"=>",
"$",
"value",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'CCValidator::label - invalid label data given'",
")",
";",
"}",
"$",
"this",
"->",
"labels",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"labels",
",",
"$",
"data",
")",
";",
"}"
]
| Set a data value
@param string $data
@param mixed $value
@return void | [
"Set",
"a",
"data",
"value"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCValidator.php#L190-L203 |
ClanCats/Core | src/classes/CCValidator.php | CCValidator.rules | public function rules()
{
$args = func_get_args();
$key = array_shift( $args );
if ( !is_array( reset( $args ) ) )
{
$rules = $args;
}
else
{
$rules = array_shift( $args );
}
$success = true;
foreach( $rules as $rule )
{
$rule = explode( ':', $rule );
$params = array();
if ( array_key_exists( 1, $rule ) )
{
$params = explode( ',', $rule[1] );
}
$rule = reset( $rule );
array_unshift( $params, $key );
if ( !call_user_func_array( array( $this, $rule ), $params ) )
{
$success = false;
}
}
return $success;
} | php | public function rules()
{
$args = func_get_args();
$key = array_shift( $args );
if ( !is_array( reset( $args ) ) )
{
$rules = $args;
}
else
{
$rules = array_shift( $args );
}
$success = true;
foreach( $rules as $rule )
{
$rule = explode( ':', $rule );
$params = array();
if ( array_key_exists( 1, $rule ) )
{
$params = explode( ',', $rule[1] );
}
$rule = reset( $rule );
array_unshift( $params, $key );
if ( !call_user_func_array( array( $this, $rule ), $params ) )
{
$success = false;
}
}
return $success;
} | [
"public",
"function",
"rules",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"key",
"=",
"array_shift",
"(",
"$",
"args",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"reset",
"(",
"$",
"args",
")",
")",
")",
"{",
"$",
"rules",
"=",
"$",
"args",
";",
"}",
"else",
"{",
"$",
"rules",
"=",
"array_shift",
"(",
"$",
"args",
")",
";",
"}",
"$",
"success",
"=",
"true",
";",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"rule",
")",
"{",
"$",
"rule",
"=",
"explode",
"(",
"':'",
",",
"$",
"rule",
")",
";",
"$",
"params",
"=",
"array",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"1",
",",
"$",
"rule",
")",
")",
"{",
"$",
"params",
"=",
"explode",
"(",
"','",
",",
"$",
"rule",
"[",
"1",
"]",
")",
";",
"}",
"$",
"rule",
"=",
"reset",
"(",
"$",
"rule",
")",
";",
"array_unshift",
"(",
"$",
"params",
",",
"$",
"key",
")",
";",
"if",
"(",
"!",
"call_user_func_array",
"(",
"array",
"(",
"$",
"this",
",",
"$",
"rule",
")",
",",
"$",
"params",
")",
")",
"{",
"$",
"success",
"=",
"false",
";",
"}",
"}",
"return",
"$",
"success",
";",
"}"
]
| Apply multiple rules to one attribute
@param ...string
@return bool | [
"Apply",
"multiple",
"rules",
"to",
"one",
"attribute"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCValidator.php#L231-L269 |
ClanCats/Core | src/classes/CCValidator.php | CCValidator.message | public function message()
{
$params = func_get_args();
$message = array_shift( $params );
$method = array_shift( $params );
if ( !$result = $this->validate( $method, $params ) )
{
$key = array_shift( $params );
$params = $this->get_error_message_params( $key, $params );
// replace the params inside the line
foreach ( $params as $param => $value )
{
$message = str_replace( ':'.$param, $value, $message );
}
$this->errors[$key][] = $message;
}
return $result;
} | php | public function message()
{
$params = func_get_args();
$message = array_shift( $params );
$method = array_shift( $params );
if ( !$result = $this->validate( $method, $params ) )
{
$key = array_shift( $params );
$params = $this->get_error_message_params( $key, $params );
// replace the params inside the line
foreach ( $params as $param => $value )
{
$message = str_replace( ':'.$param, $value, $message );
}
$this->errors[$key][] = $message;
}
return $result;
} | [
"public",
"function",
"message",
"(",
")",
"{",
"$",
"params",
"=",
"func_get_args",
"(",
")",
";",
"$",
"message",
"=",
"array_shift",
"(",
"$",
"params",
")",
";",
"$",
"method",
"=",
"array_shift",
"(",
"$",
"params",
")",
";",
"if",
"(",
"!",
"$",
"result",
"=",
"$",
"this",
"->",
"validate",
"(",
"$",
"method",
",",
"$",
"params",
")",
")",
"{",
"$",
"key",
"=",
"array_shift",
"(",
"$",
"params",
")",
";",
"$",
"params",
"=",
"$",
"this",
"->",
"get_error_message_params",
"(",
"$",
"key",
",",
"$",
"params",
")",
";",
"// replace the params inside the line",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
"=>",
"$",
"value",
")",
"{",
"$",
"message",
"=",
"str_replace",
"(",
"':'",
".",
"$",
"param",
",",
"$",
"value",
",",
"$",
"message",
")",
";",
"}",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"message",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| Run the validation with a custom message
@param mixed...
@return bool | [
"Run",
"the",
"validation",
"with",
"a",
"custom",
"message"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCValidator.php#L296-L319 |
ClanCats/Core | src/classes/CCValidator.php | CCValidator.validate | protected function validate( $method, $params )
{
$reverse = false;
// when the method starts with not we assume that we
// have to reverse the validation means only accepting the opposite
if ( substr( $method, 0, 4 ) === 'not_' )
{
$reverse = true; $method = substr( $method, 4 );
}
if ( array_key_exists( $method, static::$rules ) )
{
return $this->apply_rule( $method, static::$rules[$method], $params, $reverse );
}
if ( method_exists( $this, 'rule_'.$method ) )
{
return $this->apply_rule( $method, array( $this, 'rule_'.$method ), $params, $reverse );
}
throw new \BadMethodCallException( "CCValidator - Invalid rule or method '".$method."'." );
} | php | protected function validate( $method, $params )
{
$reverse = false;
// when the method starts with not we assume that we
// have to reverse the validation means only accepting the opposite
if ( substr( $method, 0, 4 ) === 'not_' )
{
$reverse = true; $method = substr( $method, 4 );
}
if ( array_key_exists( $method, static::$rules ) )
{
return $this->apply_rule( $method, static::$rules[$method], $params, $reverse );
}
if ( method_exists( $this, 'rule_'.$method ) )
{
return $this->apply_rule( $method, array( $this, 'rule_'.$method ), $params, $reverse );
}
throw new \BadMethodCallException( "CCValidator - Invalid rule or method '".$method."'." );
} | [
"protected",
"function",
"validate",
"(",
"$",
"method",
",",
"$",
"params",
")",
"{",
"$",
"reverse",
"=",
"false",
";",
"// when the method starts with not we assume that we ",
"// have to reverse the validation means only accepting the opposite",
"if",
"(",
"substr",
"(",
"$",
"method",
",",
"0",
",",
"4",
")",
"===",
"'not_'",
")",
"{",
"$",
"reverse",
"=",
"true",
";",
"$",
"method",
"=",
"substr",
"(",
"$",
"method",
",",
"4",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"method",
",",
"static",
"::",
"$",
"rules",
")",
")",
"{",
"return",
"$",
"this",
"->",
"apply_rule",
"(",
"$",
"method",
",",
"static",
"::",
"$",
"rules",
"[",
"$",
"method",
"]",
",",
"$",
"params",
",",
"$",
"reverse",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'rule_'",
".",
"$",
"method",
")",
")",
"{",
"return",
"$",
"this",
"->",
"apply_rule",
"(",
"$",
"method",
",",
"array",
"(",
"$",
"this",
",",
"'rule_'",
".",
"$",
"method",
")",
",",
"$",
"params",
",",
"$",
"reverse",
")",
";",
"}",
"throw",
"new",
"\\",
"BadMethodCallException",
"(",
"\"CCValidator - Invalid rule or method '\"",
".",
"$",
"method",
".",
"\"'.\"",
")",
";",
"}"
]
| Run an validation call
@param string $rule
@param array $params
@return bool | [
"Run",
"an",
"validation",
"call"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCValidator.php#L328-L350 |
ClanCats/Core | src/classes/CCValidator.php | CCValidator.proof_result | protected function proof_result( $rule, $key, $result )
{
if ( $result === false )
{
$this->failed[$key][] = $rule;
}
if ( $this->success === true )
{
return $this->success = $result;
}
return $result;
} | php | protected function proof_result( $rule, $key, $result )
{
if ( $result === false )
{
$this->failed[$key][] = $rule;
}
if ( $this->success === true )
{
return $this->success = $result;
}
return $result;
} | [
"protected",
"function",
"proof_result",
"(",
"$",
"rule",
",",
"$",
"key",
",",
"$",
"result",
")",
"{",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"failed",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"rule",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"success",
"===",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"success",
"=",
"$",
"result",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| Proof a single result and update the success property
@param string $rule
@param string $key
@param array $result
@return bool | [
"Proof",
"a",
"single",
"result",
"and",
"update",
"the",
"success",
"property"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCValidator.php#L360-L373 |
ClanCats/Core | src/classes/CCValidator.php | CCValidator.apply_rule | protected function apply_rule( $rule, $callback, $params, $reverse )
{
$data_key = array_shift( $params );
// In case of that the requested data set does not exist
// we always set the test as failure.
if ( !array_key_exists( $data_key, $this->data ) )
{
return $this->proof_result( $rule, $data_key, ( $reverse ? true : false ) );
}
$call_arguments = array( $data_key, $this->data[$data_key] );
// add the other params to our call parameters
$call_arguments = array_merge( $call_arguments, $params );
$result = (bool) call_user_func_array( $callback, $call_arguments );
if ( $reverse )
{
$result = !$result;
}
return $this->proof_result( $rule, $data_key, $result );
} | php | protected function apply_rule( $rule, $callback, $params, $reverse )
{
$data_key = array_shift( $params );
// In case of that the requested data set does not exist
// we always set the test as failure.
if ( !array_key_exists( $data_key, $this->data ) )
{
return $this->proof_result( $rule, $data_key, ( $reverse ? true : false ) );
}
$call_arguments = array( $data_key, $this->data[$data_key] );
// add the other params to our call parameters
$call_arguments = array_merge( $call_arguments, $params );
$result = (bool) call_user_func_array( $callback, $call_arguments );
if ( $reverse )
{
$result = !$result;
}
return $this->proof_result( $rule, $data_key, $result );
} | [
"protected",
"function",
"apply_rule",
"(",
"$",
"rule",
",",
"$",
"callback",
",",
"$",
"params",
",",
"$",
"reverse",
")",
"{",
"$",
"data_key",
"=",
"array_shift",
"(",
"$",
"params",
")",
";",
"// In case of that the requested data set does not exist",
"// we always set the test as failure.",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"data_key",
",",
"$",
"this",
"->",
"data",
")",
")",
"{",
"return",
"$",
"this",
"->",
"proof_result",
"(",
"$",
"rule",
",",
"$",
"data_key",
",",
"(",
"$",
"reverse",
"?",
"true",
":",
"false",
")",
")",
";",
"}",
"$",
"call_arguments",
"=",
"array",
"(",
"$",
"data_key",
",",
"$",
"this",
"->",
"data",
"[",
"$",
"data_key",
"]",
")",
";",
"// add the other params to our call parameters",
"$",
"call_arguments",
"=",
"array_merge",
"(",
"$",
"call_arguments",
",",
"$",
"params",
")",
";",
"$",
"result",
"=",
"(",
"bool",
")",
"call_user_func_array",
"(",
"$",
"callback",
",",
"$",
"call_arguments",
")",
";",
"if",
"(",
"$",
"reverse",
")",
"{",
"$",
"result",
"=",
"!",
"$",
"result",
";",
"}",
"return",
"$",
"this",
"->",
"proof_result",
"(",
"$",
"rule",
",",
"$",
"data_key",
",",
"$",
"result",
")",
";",
"}"
]
| Apply an rule executes the rule and runs the result proof
@param string $rule
@param callback $callback
@param array $params
@return bool | [
"Apply",
"an",
"rule",
"executes",
"the",
"rule",
"and",
"runs",
"the",
"result",
"proof"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCValidator.php#L383-L407 |
ClanCats/Core | src/classes/CCValidator.php | CCValidator.get_error_message_params | protected function get_error_message_params( $key, $params )
{
// do we have a label to replace the key?
if ( isset( $this->labels[$key] ) )
{
$field = $this->labels[$key];
} else {
$field = ucfirst( str_replace( array( '_', '-' ), ' ', $key ) );
}
return array_merge( array( 'field' => $field ), $params );
} | php | protected function get_error_message_params( $key, $params )
{
// do we have a label to replace the key?
if ( isset( $this->labels[$key] ) )
{
$field = $this->labels[$key];
} else {
$field = ucfirst( str_replace( array( '_', '-' ), ' ', $key ) );
}
return array_merge( array( 'field' => $field ), $params );
} | [
"protected",
"function",
"get_error_message_params",
"(",
"$",
"key",
",",
"$",
"params",
")",
"{",
"// do we have a label to replace the key?",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"labels",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"field",
"=",
"$",
"this",
"->",
"labels",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"$",
"field",
"=",
"ucfirst",
"(",
"str_replace",
"(",
"array",
"(",
"'_'",
",",
"'-'",
")",
",",
"' '",
",",
"$",
"key",
")",
")",
";",
"}",
"return",
"array_merge",
"(",
"array",
"(",
"'field'",
"=>",
"$",
"field",
")",
",",
"$",
"params",
")",
";",
"}"
]
| Get the parameter array for the error messages
@param string $key
@param array $params
@return array | [
"Get",
"the",
"parameter",
"array",
"for",
"the",
"error",
"messages"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCValidator.php#L416-L427 |
ClanCats/Core | src/classes/CCValidator.php | CCValidator.generate_error_message | protected function generate_error_message( $rule, $key, $params )
{
$params = $this->get_error_message_params( $key, $params );
return __( ClanCats::$config->get( 'validation.language_prefix' ).'.'.$rule, $params );
} | php | protected function generate_error_message( $rule, $key, $params )
{
$params = $this->get_error_message_params( $key, $params );
return __( ClanCats::$config->get( 'validation.language_prefix' ).'.'.$rule, $params );
} | [
"protected",
"function",
"generate_error_message",
"(",
"$",
"rule",
",",
"$",
"key",
",",
"$",
"params",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"get_error_message_params",
"(",
"$",
"key",
",",
"$",
"params",
")",
";",
"return",
"__",
"(",
"ClanCats",
"::",
"$",
"config",
"->",
"get",
"(",
"'validation.language_prefix'",
")",
".",
"'.'",
".",
"$",
"rule",
",",
"$",
"params",
")",
";",
"}"
]
| Generate the error message for an rule
@param string $rule
@param string $key
@param array $params
@return string | [
"Generate",
"the",
"error",
"message",
"for",
"an",
"rule"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCValidator.php#L437-L441 |
ClanCats/Core | src/classes/CCValidator.php | CCValidator.rule_required | public function rule_required( $key, $value )
{
if ( is_null( $value ) )
{
return false;
}
elseif ( is_string( $value ) && trim( $value ) == '' )
{
return false;
}
return true;
} | php | public function rule_required( $key, $value )
{
if ( is_null( $value ) )
{
return false;
}
elseif ( is_string( $value ) && trim( $value ) == '' )
{
return false;
}
return true;
} | [
"public",
"function",
"rule_required",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"value",
")",
"&&",
"trim",
"(",
"$",
"value",
")",
"==",
"''",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Check if the field is set an not empty
@param string $key
@param string $value
@return bool | [
"Check",
"if",
"the",
"field",
"is",
"set",
"an",
"not",
"empty"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCValidator.php#L454-L465 |
ClanCats/Core | src/classes/CCValidator.php | CCValidator.rule_between_num | public function rule_between_num( $key, $value, $min, $max )
{
if ( !$this->rule_min_num( $key, $value, $min ) )
{
return false;
}
if ( !$this->rule_max_num( $key, $value, $max ) )
{
return false;
}
return true;
} | php | public function rule_between_num( $key, $value, $min, $max )
{
if ( !$this->rule_min_num( $key, $value, $min ) )
{
return false;
}
if ( !$this->rule_max_num( $key, $value, $max ) )
{
return false;
}
return true;
} | [
"public",
"function",
"rule_between_num",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"min",
",",
"$",
"max",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"rule_min_num",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"min",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"rule_max_num",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"max",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Is the given number between min and max
@param string $key
@param string $value
@return bool | [
"Is",
"the",
"given",
"number",
"between",
"min",
"and",
"max"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCValidator.php#L518-L529 |
ClanCats/Core | src/classes/CCValidator.php | CCValidator.rule_min | public function rule_min( $key, $value, $min )
{
return $this->rule_min_num( $key, strlen( $value ), $min );
} | php | public function rule_min( $key, $value, $min )
{
return $this->rule_min_num( $key, strlen( $value ), $min );
} | [
"public",
"function",
"rule_min",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"min",
")",
"{",
"return",
"$",
"this",
"->",
"rule_min_num",
"(",
"$",
"key",
",",
"strlen",
"(",
"$",
"value",
")",
",",
"$",
"min",
")",
";",
"}"
]
| Is the given string at least some size
@param string $key
@param string $value
@return bool | [
"Is",
"the",
"given",
"string",
"at",
"least",
"some",
"size"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCValidator.php#L538-L541 |
ClanCats/Core | src/classes/CCValidator.php | CCValidator.rule_max | public function rule_max( $key, $value, $max )
{
return $this->rule_max_num( $key, strlen( $value ), $max );
} | php | public function rule_max( $key, $value, $max )
{
return $this->rule_max_num( $key, strlen( $value ), $max );
} | [
"public",
"function",
"rule_max",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"max",
")",
"{",
"return",
"$",
"this",
"->",
"rule_max_num",
"(",
"$",
"key",
",",
"strlen",
"(",
"$",
"value",
")",
",",
"$",
"max",
")",
";",
"}"
]
| Is the given string max some size
@param string $key
@param string $value
@return bool | [
"Is",
"the",
"given",
"string",
"max",
"some",
"size"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCValidator.php#L550-L553 |
ClanCats/Core | src/classes/CCValidator.php | CCValidator.rule_between | public function rule_between( $key, $value, $min, $max )
{
return $this->rule_between_num( $key, strlen( $value ), $min, $max );
} | php | public function rule_between( $key, $value, $min, $max )
{
return $this->rule_between_num( $key, strlen( $value ), $min, $max );
} | [
"public",
"function",
"rule_between",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"min",
",",
"$",
"max",
")",
"{",
"return",
"$",
"this",
"->",
"rule_between_num",
"(",
"$",
"key",
",",
"strlen",
"(",
"$",
"value",
")",
",",
"$",
"min",
",",
"$",
"max",
")",
";",
"}"
]
| Is the given string between min and max
@param string $key
@param string $value
@return bool | [
"Is",
"the",
"given",
"string",
"between",
"min",
"and",
"max"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCValidator.php#L562-L565 |
ClanCats/Core | src/classes/CCValidator.php | CCValidator.rule_date_format | public function rule_date_format( $key, $value, $format = 'd/m/Y' )
{
return date( $format, strtotime( trim( $value ) ) ) == trim( $value );
} | php | public function rule_date_format( $key, $value, $format = 'd/m/Y' )
{
return date( $format, strtotime( trim( $value ) ) ) == trim( $value );
} | [
"public",
"function",
"rule_date_format",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"format",
"=",
"'d/m/Y'",
")",
"{",
"return",
"date",
"(",
"$",
"format",
",",
"strtotime",
"(",
"trim",
"(",
"$",
"value",
")",
")",
")",
"==",
"trim",
"(",
"$",
"value",
")",
";",
"}"
]
| Check if valid date format
@param string $key
@param string $value
@param string $format
@param bool | [
"Check",
"if",
"valid",
"date",
"format"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCValidator.php#L711-L714 |
devmobgroup/postcodes | src/Traits/AccessesProperties.php | AccessesProperties.get | protected function get($data, string $key)
{
$dot = $data instanceof Dot ? $data : new Dot($data);
if (isset($dot[$key])) {
return $dot[$key];
}
throw new UnexpectedResponseException(sprintf('Missing key \'%s\' in data'));
} | php | protected function get($data, string $key)
{
$dot = $data instanceof Dot ? $data : new Dot($data);
if (isset($dot[$key])) {
return $dot[$key];
}
throw new UnexpectedResponseException(sprintf('Missing key \'%s\' in data'));
} | [
"protected",
"function",
"get",
"(",
"$",
"data",
",",
"string",
"$",
"key",
")",
"{",
"$",
"dot",
"=",
"$",
"data",
"instanceof",
"Dot",
"?",
"$",
"data",
":",
"new",
"Dot",
"(",
"$",
"data",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"dot",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"dot",
"[",
"$",
"key",
"]",
";",
"}",
"throw",
"new",
"UnexpectedResponseException",
"(",
"sprintf",
"(",
"'Missing key \\'%s\\' in data'",
")",
")",
";",
"}"
]
| Extract data from an array using dot notation.
Throws an exception when the provided key does not exist.
@param array|\Adbar\Dot $data
@param string $key Supports dot notation {@see https://github.com/adbario/php-dot-notation}
@return mixed
@throws \DevMob\Postcodes\Exceptions\UnexpectedResponseException | [
"Extract",
"data",
"from",
"an",
"array",
"using",
"dot",
"notation",
".",
"Throws",
"an",
"exception",
"when",
"the",
"provided",
"key",
"does",
"not",
"exist",
"."
]
| train | https://github.com/devmobgroup/postcodes/blob/1a8438fd960a8f50ec28d61af94560892b529f12/src/Traits/AccessesProperties.php#L19-L28 |
maximebf/events | src/Events/Notifier.php | Notifier.createEvent | public function createEvent($eventName, array $params = array())
{
$class = $this->eventClass;
return new $class($this->sender, $this->prefix . $eventName, $params);
} | php | public function createEvent($eventName, array $params = array())
{
$class = $this->eventClass;
return new $class($this->sender, $this->prefix . $eventName, $params);
} | [
"public",
"function",
"createEvent",
"(",
"$",
"eventName",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"eventClass",
";",
"return",
"new",
"$",
"class",
"(",
"$",
"this",
"->",
"sender",
",",
"$",
"this",
"->",
"prefix",
".",
"$",
"eventName",
",",
"$",
"params",
")",
";",
"}"
]
| Creates an event object
@param string $eventName
@param array $params
@return Event | [
"Creates",
"an",
"event",
"object"
]
| train | https://github.com/maximebf/events/blob/b9861c260ee9eaabb9aa986bab76a2e039eb871f/src/Events/Notifier.php#L125-L129 |
maximebf/events | src/Events/Notifier.php | Notifier.notify | public function notify($eventName, array $params = array())
{
$this->dispatcher->notify($e = $this->createEvent($eventName, $params));
return $e;
} | php | public function notify($eventName, array $params = array())
{
$this->dispatcher->notify($e = $this->createEvent($eventName, $params));
return $e;
} | [
"public",
"function",
"notify",
"(",
"$",
"eventName",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"dispatcher",
"->",
"notify",
"(",
"$",
"e",
"=",
"$",
"this",
"->",
"createEvent",
"(",
"$",
"eventName",
",",
"$",
"params",
")",
")",
";",
"return",
"$",
"e",
";",
"}"
]
| Creates and dispatches an event
@see EventDispatcher::notify()
@param string $eventName
@param array $params
@return Event | [
"Creates",
"and",
"dispatches",
"an",
"event"
]
| train | https://github.com/maximebf/events/blob/b9861c260ee9eaabb9aa986bab76a2e039eb871f/src/Events/Notifier.php#L139-L143 |
maximebf/events | src/Events/Notifier.php | Notifier.notifyUntil | public function notifyUntil($eventName, array $params = array(), $callback = null)
{
$this->dispatcher->notifyUntil($e = $this->createEvent($eventName, $params), $callback);
return $e;
} | php | public function notifyUntil($eventName, array $params = array(), $callback = null)
{
$this->dispatcher->notifyUntil($e = $this->createEvent($eventName, $params), $callback);
return $e;
} | [
"public",
"function",
"notifyUntil",
"(",
"$",
"eventName",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
",",
"$",
"callback",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"dispatcher",
"->",
"notifyUntil",
"(",
"$",
"e",
"=",
"$",
"this",
"->",
"createEvent",
"(",
"$",
"eventName",
",",
"$",
"params",
")",
",",
"$",
"callback",
")",
";",
"return",
"$",
"e",
";",
"}"
]
| Creates and dispatches an event until it has been processed.
@see EventDispatcher::notifyUntil()
@param string $eventName
@param array $params
@param callback $callback
@return Event | [
"Creates",
"and",
"dispatches",
"an",
"event",
"until",
"it",
"has",
"been",
"processed",
"."
]
| train | https://github.com/maximebf/events/blob/b9861c260ee9eaabb9aa986bab76a2e039eb871f/src/Events/Notifier.php#L154-L158 |
nyeholt/silverstripe-external-content | thirdparty/Zend/Validate/Float.php | Zend_Validate_Float.isValid | public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
try {
if (!Zend_Locale_Format::isFloat($value, array('locale' => $this->_locale))) {
$this->_error();
return false;
}
} catch (Zend_Locale_Exception $e) {
$this->_error();
return false;
}
return true;
} | php | public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
try {
if (!Zend_Locale_Format::isFloat($value, array('locale' => $this->_locale))) {
$this->_error();
return false;
}
} catch (Zend_Locale_Exception $e) {
$this->_error();
return false;
}
return true;
} | [
"public",
"function",
"isValid",
"(",
"$",
"value",
")",
"{",
"$",
"valueString",
"=",
"(",
"string",
")",
"$",
"value",
";",
"$",
"this",
"->",
"_setValue",
"(",
"$",
"valueString",
")",
";",
"try",
"{",
"if",
"(",
"!",
"Zend_Locale_Format",
"::",
"isFloat",
"(",
"$",
"value",
",",
"array",
"(",
"'locale'",
"=>",
"$",
"this",
"->",
"_locale",
")",
")",
")",
"{",
"$",
"this",
"->",
"_error",
"(",
")",
";",
"return",
"false",
";",
"}",
"}",
"catch",
"(",
"Zend_Locale_Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"_error",
"(",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Defined by Zend_Validate_Interface
Returns true if and only if $value is a floating-point value
@param string $value
@return boolean | [
"Defined",
"by",
"Zend_Validate_Interface"
]
| train | https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Validate/Float.php#L90-L107 |
Sedona-Solutions/sedona-sbo | src/Sedona/SBORuntimeBundle/Form/Type/CollectionSelect2Type.php | CollectionSelect2Type.buildView | public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['attr']['autocomplete'] = 'off';
if (array_key_exists('searchRouteName', $options)) {
$view->vars['attr']['data-source'] = $this->router->generate($options['searchRouteName']).'?property='.$options['property'];
}
$collection = $form->getData();
if ($collection != null && (is_array($collection) || $collection instanceof \Traversable)) {
$getterI = 'get'.ucfirst($options['primaryKey']);
$getterP = 'get'.ucfirst($options['property']);
$result = [];
foreach ($collection as $object) {
if ($object instanceof $options['class'] && method_exists($object, $getterI) && method_exists($object, $getterP)) {
$result[] = ['id' => $object->$getterI(), 'text' => $object->$getterP()];
}
}
$view->vars['attr']['data-initSelection'] = json_encode($result);
}
foreach ($this->copyProperty as $optionProperty => $attrProperty) {
if (array_key_exists($optionProperty, $options) && empty($options[$optionProperty]) == false) {
$view->vars['attr'][$attrProperty] = $options[$optionProperty];
}
}
parent::buildView($view, $form, $options);
} | php | public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['attr']['autocomplete'] = 'off';
if (array_key_exists('searchRouteName', $options)) {
$view->vars['attr']['data-source'] = $this->router->generate($options['searchRouteName']).'?property='.$options['property'];
}
$collection = $form->getData();
if ($collection != null && (is_array($collection) || $collection instanceof \Traversable)) {
$getterI = 'get'.ucfirst($options['primaryKey']);
$getterP = 'get'.ucfirst($options['property']);
$result = [];
foreach ($collection as $object) {
if ($object instanceof $options['class'] && method_exists($object, $getterI) && method_exists($object, $getterP)) {
$result[] = ['id' => $object->$getterI(), 'text' => $object->$getterP()];
}
}
$view->vars['attr']['data-initSelection'] = json_encode($result);
}
foreach ($this->copyProperty as $optionProperty => $attrProperty) {
if (array_key_exists($optionProperty, $options) && empty($options[$optionProperty]) == false) {
$view->vars['attr'][$attrProperty] = $options[$optionProperty];
}
}
parent::buildView($view, $form, $options);
} | [
"public",
"function",
"buildView",
"(",
"FormView",
"$",
"view",
",",
"FormInterface",
"$",
"form",
",",
"array",
"$",
"options",
")",
"{",
"$",
"view",
"->",
"vars",
"[",
"'attr'",
"]",
"[",
"'autocomplete'",
"]",
"=",
"'off'",
";",
"if",
"(",
"array_key_exists",
"(",
"'searchRouteName'",
",",
"$",
"options",
")",
")",
"{",
"$",
"view",
"->",
"vars",
"[",
"'attr'",
"]",
"[",
"'data-source'",
"]",
"=",
"$",
"this",
"->",
"router",
"->",
"generate",
"(",
"$",
"options",
"[",
"'searchRouteName'",
"]",
")",
".",
"'?property='",
".",
"$",
"options",
"[",
"'property'",
"]",
";",
"}",
"$",
"collection",
"=",
"$",
"form",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"$",
"collection",
"!=",
"null",
"&&",
"(",
"is_array",
"(",
"$",
"collection",
")",
"||",
"$",
"collection",
"instanceof",
"\\",
"Traversable",
")",
")",
"{",
"$",
"getterI",
"=",
"'get'",
".",
"ucfirst",
"(",
"$",
"options",
"[",
"'primaryKey'",
"]",
")",
";",
"$",
"getterP",
"=",
"'get'",
".",
"ucfirst",
"(",
"$",
"options",
"[",
"'property'",
"]",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"object",
")",
"{",
"if",
"(",
"$",
"object",
"instanceof",
"$",
"options",
"[",
"'class'",
"]",
"&&",
"method_exists",
"(",
"$",
"object",
",",
"$",
"getterI",
")",
"&&",
"method_exists",
"(",
"$",
"object",
",",
"$",
"getterP",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"object",
"->",
"$",
"getterI",
"(",
")",
",",
"'text'",
"=>",
"$",
"object",
"->",
"$",
"getterP",
"(",
")",
"]",
";",
"}",
"}",
"$",
"view",
"->",
"vars",
"[",
"'attr'",
"]",
"[",
"'data-initSelection'",
"]",
"=",
"json_encode",
"(",
"$",
"result",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"copyProperty",
"as",
"$",
"optionProperty",
"=>",
"$",
"attrProperty",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"optionProperty",
",",
"$",
"options",
")",
"&&",
"empty",
"(",
"$",
"options",
"[",
"$",
"optionProperty",
"]",
")",
"==",
"false",
")",
"{",
"$",
"view",
"->",
"vars",
"[",
"'attr'",
"]",
"[",
"$",
"attrProperty",
"]",
"=",
"$",
"options",
"[",
"$",
"optionProperty",
"]",
";",
"}",
"}",
"parent",
"::",
"buildView",
"(",
"$",
"view",
",",
"$",
"form",
",",
"$",
"options",
")",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/Sedona-Solutions/sedona-sbo/blob/8548be4170d191cb1a3e263577aaaab49f04d5ce/src/Sedona/SBORuntimeBundle/Form/Type/CollectionSelect2Type.php#L80-L108 |
webforge-labs/psc-cms | lib/Psc/PHPUnit/InvokedAtMethodGroupIndexMatcher.php | InvokedAtMethodGroupIndexMatcher.verify | public function verify()
{
if ($this->groupIndex < $this->sequenceIndex) {
throw new PHPUnit_Framework_ExpectationFailedException(
sprintf(
"The expected invocation at method '%s' group-index %d was never reached.",
$this->method,
$this->sequenceIndex
)
);
}
} | php | public function verify()
{
if ($this->groupIndex < $this->sequenceIndex) {
throw new PHPUnit_Framework_ExpectationFailedException(
sprintf(
"The expected invocation at method '%s' group-index %d was never reached.",
$this->method,
$this->sequenceIndex
)
);
}
} | [
"public",
"function",
"verify",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"groupIndex",
"<",
"$",
"this",
"->",
"sequenceIndex",
")",
"{",
"throw",
"new",
"PHPUnit_Framework_ExpectationFailedException",
"(",
"sprintf",
"(",
"\"The expected invocation at method '%s' group-index %d was never reached.\"",
",",
"$",
"this",
"->",
"method",
",",
"$",
"this",
"->",
"sequenceIndex",
")",
")",
";",
"}",
"}"
]
| Verifies that the current expectation is valid. If everything is OK the
code should just return, if not it must throw an exception.
@throws PHPUnit_Framework_ExpectationFailedException | [
"Verifies",
"that",
"the",
"current",
"expectation",
"is",
"valid",
".",
"If",
"everything",
"is",
"OK",
"the",
"code",
"should",
"just",
"return",
"if",
"not",
"it",
"must",
"throw",
"an",
"exception",
"."
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/PHPUnit/InvokedAtMethodGroupIndexMatcher.php#L135-L147 |
crypto-markets/common | src/Common/Endpoint.php | Endpoint.make | public static function make(Client $httpClient, array $params = [])
{
$instance = new static($httpClient);
$instance->configure($params);
return $instance;
} | php | public static function make(Client $httpClient, array $params = [])
{
$instance = new static($httpClient);
$instance->configure($params);
return $instance;
} | [
"public",
"static",
"function",
"make",
"(",
"Client",
"$",
"httpClient",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"instance",
"=",
"new",
"static",
"(",
"$",
"httpClient",
")",
";",
"$",
"instance",
"->",
"configure",
"(",
"$",
"params",
")",
";",
"return",
"$",
"instance",
";",
"}"
]
| Create a new resource instance.
@param \CryptoMarkets\Common\Client $httpClient
@param array $params
@return static | [
"Create",
"a",
"new",
"resource",
"instance",
"."
]
| train | https://github.com/crypto-markets/common/blob/206b1d9b88502d3fb73cef1323cd086156d3e633/src/Common/Endpoint.php#L48-L55 |
crypto-markets/common | src/Common/Endpoint.php | Endpoint.send | public function send()
{
$request = $this->createRequest();
$response = $this->httpClient->sendRequest($request);
return $this->mapResponse((array) $this->parseResponse($response));
} | php | public function send()
{
$request = $this->createRequest();
$response = $this->httpClient->sendRequest($request);
return $this->mapResponse((array) $this->parseResponse($response));
} | [
"public",
"function",
"send",
"(",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"createRequest",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpClient",
"->",
"sendRequest",
"(",
"$",
"request",
")",
";",
"return",
"$",
"this",
"->",
"mapResponse",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"parseResponse",
"(",
"$",
"response",
")",
")",
";",
"}"
]
| Send a new request.
@return array | [
"Send",
"a",
"new",
"request",
"."
]
| train | https://github.com/crypto-markets/common/blob/206b1d9b88502d3fb73cef1323cd086156d3e633/src/Common/Endpoint.php#L75-L82 |
crypto-markets/common | src/Common/Endpoint.php | Endpoint.createRequest | public function createRequest()
{
return $this->httpClient->createRequest(
$this->getMethod(),
$this->getUrl(),
$this->getPreparedHeaders(),
$this->getPreparedData()
);
} | php | public function createRequest()
{
return $this->httpClient->createRequest(
$this->getMethod(),
$this->getUrl(),
$this->getPreparedHeaders(),
$this->getPreparedData()
);
} | [
"public",
"function",
"createRequest",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"httpClient",
"->",
"createRequest",
"(",
"$",
"this",
"->",
"getMethod",
"(",
")",
",",
"$",
"this",
"->",
"getUrl",
"(",
")",
",",
"$",
"this",
"->",
"getPreparedHeaders",
"(",
")",
",",
"$",
"this",
"->",
"getPreparedData",
"(",
")",
")",
";",
"}"
]
| Create a new request object.
@return \GuzzleHttp\Psr7\Request | [
"Create",
"a",
"new",
"request",
"object",
"."
]
| train | https://github.com/crypto-markets/common/blob/206b1d9b88502d3fb73cef1323cd086156d3e633/src/Common/Endpoint.php#L89-L97 |
crypto-markets/common | src/Common/Endpoint.php | Endpoint.getPreparedData | public function getPreparedData()
{
$params = $this->getData();
if ($this->authorize) {
$params = array_merge($params, $this->authenticationData($params));
}
return $params;
} | php | public function getPreparedData()
{
$params = $this->getData();
if ($this->authorize) {
$params = array_merge($params, $this->authenticationData($params));
}
return $params;
} | [
"public",
"function",
"getPreparedData",
"(",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"authorize",
")",
"{",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"params",
",",
"$",
"this",
"->",
"authenticationData",
"(",
"$",
"params",
")",
")",
";",
"}",
"return",
"$",
"params",
";",
"}"
]
| Get the request data for authorized or not.
@return string | [
"Get",
"the",
"request",
"data",
"for",
"authorized",
"or",
"not",
"."
]
| train | https://github.com/crypto-markets/common/blob/206b1d9b88502d3fb73cef1323cd086156d3e633/src/Common/Endpoint.php#L141-L150 |
webforge-labs/psc-cms | lib/Psc/Environment.php | Environment.addIncludePath | public function addIncludePath($path, $type = 'prepend') {
if (!$this->hasIncludePath($path)) {
if ($type == 'append') {
$ret = set_include_path(rtrim(get_include_path(),PATH_SEPARATOR).PATH_SEPARATOR.$path);
} else {
$ret = set_include_path($path.PATH_SEPARATOR.ltrim(get_include_path(),PATH_SEPARATOR));
}
if ($ret === FALSE) {
throw new \Psc\Exception('cannot set include path!. Vielleicht ist php_admin_value (statt php_value) auf include_path inder apache.conf gesetzt?');
}
}
return $this;
} | php | public function addIncludePath($path, $type = 'prepend') {
if (!$this->hasIncludePath($path)) {
if ($type == 'append') {
$ret = set_include_path(rtrim(get_include_path(),PATH_SEPARATOR).PATH_SEPARATOR.$path);
} else {
$ret = set_include_path($path.PATH_SEPARATOR.ltrim(get_include_path(),PATH_SEPARATOR));
}
if ($ret === FALSE) {
throw new \Psc\Exception('cannot set include path!. Vielleicht ist php_admin_value (statt php_value) auf include_path inder apache.conf gesetzt?');
}
}
return $this;
} | [
"public",
"function",
"addIncludePath",
"(",
"$",
"path",
",",
"$",
"type",
"=",
"'prepend'",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasIncludePath",
"(",
"$",
"path",
")",
")",
"{",
"if",
"(",
"$",
"type",
"==",
"'append'",
")",
"{",
"$",
"ret",
"=",
"set_include_path",
"(",
"rtrim",
"(",
"get_include_path",
"(",
")",
",",
"PATH_SEPARATOR",
")",
".",
"PATH_SEPARATOR",
".",
"$",
"path",
")",
";",
"}",
"else",
"{",
"$",
"ret",
"=",
"set_include_path",
"(",
"$",
"path",
".",
"PATH_SEPARATOR",
".",
"ltrim",
"(",
"get_include_path",
"(",
")",
",",
"PATH_SEPARATOR",
")",
")",
";",
"}",
"if",
"(",
"$",
"ret",
"===",
"FALSE",
")",
"{",
"throw",
"new",
"\\",
"Psc",
"\\",
"Exception",
"(",
"'cannot set include path!. Vielleicht ist php_admin_value (statt php_value) auf include_path inder apache.conf gesetzt?'",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Fügt dem Include Path einen neuen Pfad hinzu
@param string $path der Pfad zum Verzeichnis als String
@param string $type append|prepend der Default ist prepend
@return Description | [
"Fügt",
"dem",
"Include",
"Path",
"einen",
"neuen",
"Pfad",
"hinzu"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Environment.php#L109-L121 |
webforge-labs/psc-cms | lib/Psc/Environment.php | Environment.getRequestPath | public function getRequestPath() {
$uri = $this->getRequestURI();
if (\Webforge\Common\String::startsWith($uri, '/index.php'))
$uri = mb_substr($uri,mb_strlen('index.php'));
if (empty($uri) || $uri == '/') return array();
$uri = ltrim($uri,'/');
$parts = explode('/',$uri);
return array_filter($parts, function ($p) {
return (trim($p) != '');
});
} | php | public function getRequestPath() {
$uri = $this->getRequestURI();
if (\Webforge\Common\String::startsWith($uri, '/index.php'))
$uri = mb_substr($uri,mb_strlen('index.php'));
if (empty($uri) || $uri == '/') return array();
$uri = ltrim($uri,'/');
$parts = explode('/',$uri);
return array_filter($parts, function ($p) {
return (trim($p) != '');
});
} | [
"public",
"function",
"getRequestPath",
"(",
")",
"{",
"$",
"uri",
"=",
"$",
"this",
"->",
"getRequestURI",
"(",
")",
";",
"if",
"(",
"\\",
"Webforge",
"\\",
"Common",
"\\",
"String",
"::",
"startsWith",
"(",
"$",
"uri",
",",
"'/index.php'",
")",
")",
"$",
"uri",
"=",
"mb_substr",
"(",
"$",
"uri",
",",
"mb_strlen",
"(",
"'index.php'",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"uri",
")",
"||",
"$",
"uri",
"==",
"'/'",
")",
"return",
"array",
"(",
")",
";",
"$",
"uri",
"=",
"ltrim",
"(",
"$",
"uri",
",",
"'/'",
")",
";",
"$",
"parts",
"=",
"explode",
"(",
"'/'",
",",
"$",
"uri",
")",
";",
"return",
"array_filter",
"(",
"$",
"parts",
",",
"function",
"(",
"$",
"p",
")",
"{",
"return",
"(",
"trim",
"(",
"$",
"p",
")",
"!=",
"''",
")",
";",
"}",
")",
";",
"}"
]
| return array | [
"return",
"array"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Environment.php#L149-L162 |
yuncms/framework | src/base/Module.php | Module.getSettings | public function getSettings($key, $default = null)
{
return Yii::$app->settings->get($key, $this->id, $default);
} | php | public function getSettings($key, $default = null)
{
return Yii::$app->settings->get($key, $this->id, $default);
} | [
"public",
"function",
"getSettings",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"return",
"Yii",
"::",
"$",
"app",
"->",
"settings",
"->",
"get",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"id",
",",
"$",
"default",
")",
";",
"}"
]
| 获取模块配置
@param string $key
@param mixed $default
@return mixed | [
"获取模块配置"
]
| train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/base/Module.php#L26-L29 |
yuncms/framework | src/base/Module.php | Module.setSettings | public function setSettings($key, $value, $type = null)
{
return Yii::$app->settings->set($key, $value, $this->id, $type);
} | php | public function setSettings($key, $value, $type = null)
{
return Yii::$app->settings->set($key, $value, $this->id, $type);
} | [
"public",
"function",
"setSettings",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"type",
"=",
"null",
")",
"{",
"return",
"Yii",
"::",
"$",
"app",
"->",
"settings",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"this",
"->",
"id",
",",
"$",
"type",
")",
";",
"}"
]
| 设置模块配置
@param string $key
@param mixed $value
@param null $type
@return bool
@throws \yii\base\InvalidConfigException | [
"设置模块配置"
]
| train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/base/Module.php#L39-L42 |
chubbyphp/chubbyphp-mock | src/Call.php | Call.create | public static function create(string $method): self
{
$self = new self();
$self->method = $method;
return $self;
} | php | public static function create(string $method): self
{
$self = new self();
$self->method = $method;
return $self;
} | [
"public",
"static",
"function",
"create",
"(",
"string",
"$",
"method",
")",
":",
"self",
"{",
"$",
"self",
"=",
"new",
"self",
"(",
")",
";",
"$",
"self",
"->",
"method",
"=",
"$",
"method",
";",
"return",
"$",
"self",
";",
"}"
]
| @param string $method
@return self | [
"@param",
"string",
"$method"
]
| train | https://github.com/chubbyphp/chubbyphp-mock/blob/4c58095b26eba579a2d707cf15cdab275e679041/src/Call.php#L63-L69 |
chubbyphp/chubbyphp-mock | src/Call.php | Call.with | public function with(...$with): self
{
$this->hasWith = true;
$this->with = $with;
return $this;
} | php | public function with(...$with): self
{
$this->hasWith = true;
$this->with = $with;
return $this;
} | [
"public",
"function",
"with",
"(",
"...",
"$",
"with",
")",
":",
"self",
"{",
"$",
"this",
"->",
"hasWith",
"=",
"true",
";",
"$",
"this",
"->",
"with",
"=",
"$",
"with",
";",
"return",
"$",
"this",
";",
"}"
]
| @param mixed ...$with
@return self | [
"@param",
"mixed",
"...",
"$with"
]
| train | https://github.com/chubbyphp/chubbyphp-mock/blob/4c58095b26eba579a2d707cf15cdab275e679041/src/Call.php#L76-L82 |
chubbyphp/chubbyphp-mock | src/Call.php | Call.willThrowException | public function willThrowException(\Throwable $exception): self
{
if ($this->hasReturnSelf) {
throw new \InvalidArgumentException(sprintf('%s: There is already a return self', __METHOD__));
}
if ($this->hasReturn) {
throw new \InvalidArgumentException(sprintf('%s: There is already a return', __METHOD__));
}
if ($this->hasReturnCallback) {
throw new \InvalidArgumentException(sprintf('%s: There is already a return callback', __METHOD__));
}
$this->exception = $exception;
return $this;
} | php | public function willThrowException(\Throwable $exception): self
{
if ($this->hasReturnSelf) {
throw new \InvalidArgumentException(sprintf('%s: There is already a return self', __METHOD__));
}
if ($this->hasReturn) {
throw new \InvalidArgumentException(sprintf('%s: There is already a return', __METHOD__));
}
if ($this->hasReturnCallback) {
throw new \InvalidArgumentException(sprintf('%s: There is already a return callback', __METHOD__));
}
$this->exception = $exception;
return $this;
} | [
"public",
"function",
"willThrowException",
"(",
"\\",
"Throwable",
"$",
"exception",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"hasReturnSelf",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'%s: There is already a return self'",
",",
"__METHOD__",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hasReturn",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'%s: There is already a return'",
",",
"__METHOD__",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hasReturnCallback",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'%s: There is already a return callback'",
",",
"__METHOD__",
")",
")",
";",
"}",
"$",
"this",
"->",
"exception",
"=",
"$",
"exception",
";",
"return",
"$",
"this",
";",
"}"
]
| @param \Throwable $exception
@return self | [
"@param",
"\\",
"Throwable",
"$exception"
]
| train | https://github.com/chubbyphp/chubbyphp-mock/blob/4c58095b26eba579a2d707cf15cdab275e679041/src/Call.php#L89-L106 |
shinjin/freezer | src/LazyProxy.php | LazyProxy.getObject | public function getObject()
{
if ($this->thawedObject === null) {
$this->thawedObject = $this->storage->fetch($this->id);
}
return $this->thawedObject;
} | php | public function getObject()
{
if ($this->thawedObject === null) {
$this->thawedObject = $this->storage->fetch($this->id);
}
return $this->thawedObject;
} | [
"public",
"function",
"getObject",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"thawedObject",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"thawedObject",
"=",
"$",
"this",
"->",
"storage",
"->",
"fetch",
"(",
"$",
"this",
"->",
"id",
")",
";",
"}",
"return",
"$",
"this",
"->",
"thawedObject",
";",
"}"
]
| Returns the real object.
@return object | [
"Returns",
"the",
"real",
"object",
"."
]
| train | https://github.com/shinjin/freezer/blob/f5955fb5476fa8ac456e27c0edafaae331d02cd3/src/LazyProxy.php#L39-L46 |
shinjin/freezer | src/LazyProxy.php | LazyProxy.__isset | public function __isset($name)
{
if ($this->thawedObject === null) {
if ($name === $this->storage->getFreezer()->getIdProperty()) {
return true;
}
}
return isset($this->replaceProxy(2)->{$name});
} | php | public function __isset($name)
{
if ($this->thawedObject === null) {
if ($name === $this->storage->getFreezer()->getIdProperty()) {
return true;
}
}
return isset($this->replaceProxy(2)->{$name});
} | [
"public",
"function",
"__isset",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"thawedObject",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"name",
"===",
"$",
"this",
"->",
"storage",
"->",
"getFreezer",
"(",
")",
"->",
"getIdProperty",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"replaceProxy",
"(",
"2",
")",
"->",
"{",
"$",
"name",
"}",
")",
";",
"}"
]
| Delegates the property isset check to the real object and
tries to replace the lazy proxy object with it.
@param string $name
@return mixed | [
"Delegates",
"the",
"property",
"isset",
"check",
"to",
"the",
"real",
"object",
"and",
"tries",
"to",
"replace",
"the",
"lazy",
"proxy",
"object",
"with",
"it",
"."
]
| train | https://github.com/shinjin/freezer/blob/f5955fb5476fa8ac456e27c0edafaae331d02cd3/src/LazyProxy.php#L119-L128 |
shinjin/freezer | src/LazyProxy.php | LazyProxy.replaceProxy | protected function replaceProxy($offset)
{
$object = $this->getObject();
/**
* 0: LazyProxy::replaceProxy()
* 1: LazyProxy::__get($name) / LazyProxy::__set($name, $value)
* 2: Frame that accesses $name
* 1: LazyProxy::__call($method, $arguments)
* 2: LazyProxy::$method()
* 3: Frame that invokes $method
*/
$trace = debug_backtrace();
if (isset($trace[$offset]['object'])) {
$reflector = new \ReflectionObject($trace[$offset]['object']);
foreach ($reflector->getProperties() as $property) {
$property->setAccessible(true);
if ($property->getValue($trace[$offset]['object']) === $this) {
$property->setValue($trace[$offset]['object'], $object);
break;
}
}
}
return $object;
} | php | protected function replaceProxy($offset)
{
$object = $this->getObject();
/**
* 0: LazyProxy::replaceProxy()
* 1: LazyProxy::__get($name) / LazyProxy::__set($name, $value)
* 2: Frame that accesses $name
* 1: LazyProxy::__call($method, $arguments)
* 2: LazyProxy::$method()
* 3: Frame that invokes $method
*/
$trace = debug_backtrace();
if (isset($trace[$offset]['object'])) {
$reflector = new \ReflectionObject($trace[$offset]['object']);
foreach ($reflector->getProperties() as $property) {
$property->setAccessible(true);
if ($property->getValue($trace[$offset]['object']) === $this) {
$property->setValue($trace[$offset]['object'], $object);
break;
}
}
}
return $object;
} | [
"protected",
"function",
"replaceProxy",
"(",
"$",
"offset",
")",
"{",
"$",
"object",
"=",
"$",
"this",
"->",
"getObject",
"(",
")",
";",
"/**\n * 0: LazyProxy::replaceProxy()\n * 1: LazyProxy::__get($name) / LazyProxy::__set($name, $value)\n * 2: Frame that accesses $name\n * 1: LazyProxy::__call($method, $arguments)\n * 2: LazyProxy::$method()\n * 3: Frame that invokes $method\n */",
"$",
"trace",
"=",
"debug_backtrace",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"trace",
"[",
"$",
"offset",
"]",
"[",
"'object'",
"]",
")",
")",
"{",
"$",
"reflector",
"=",
"new",
"\\",
"ReflectionObject",
"(",
"$",
"trace",
"[",
"$",
"offset",
"]",
"[",
"'object'",
"]",
")",
";",
"foreach",
"(",
"$",
"reflector",
"->",
"getProperties",
"(",
")",
"as",
"$",
"property",
")",
"{",
"$",
"property",
"->",
"setAccessible",
"(",
"true",
")",
";",
"if",
"(",
"$",
"property",
"->",
"getValue",
"(",
"$",
"trace",
"[",
"$",
"offset",
"]",
"[",
"'object'",
"]",
")",
"===",
"$",
"this",
")",
"{",
"$",
"property",
"->",
"setValue",
"(",
"$",
"trace",
"[",
"$",
"offset",
"]",
"[",
"'object'",
"]",
",",
"$",
"object",
")",
";",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"object",
";",
"}"
]
| Tries to replace the lazy proxy object with the real object.
@param integer $offset
@return object | [
"Tries",
"to",
"replace",
"the",
"lazy",
"proxy",
"object",
"with",
"the",
"real",
"object",
"."
]
| train | https://github.com/shinjin/freezer/blob/f5955fb5476fa8ac456e27c0edafaae331d02cd3/src/LazyProxy.php#L136-L164 |
OpenClassrooms/ServiceProxy | src/Proxy/Strategy/ServiceProxyCacheStrategy.php | ServiceProxyCacheStrategy.execute | public function execute(ServiceProxyStrategyRequestInterface $request)
{
return $this->serviceProxyStrategyResponseBuilder
->create()
->withPreSource($this->generatePreSource($request))
->withPostSource($this->generatePostSource($request->getAnnotation()))
->withExceptionSource('')
->withProperties($this->generateProperties())
->withMethods($this->generateMethods())
->build();
} | php | public function execute(ServiceProxyStrategyRequestInterface $request)
{
return $this->serviceProxyStrategyResponseBuilder
->create()
->withPreSource($this->generatePreSource($request))
->withPostSource($this->generatePostSource($request->getAnnotation()))
->withExceptionSource('')
->withProperties($this->generateProperties())
->withMethods($this->generateMethods())
->build();
} | [
"public",
"function",
"execute",
"(",
"ServiceProxyStrategyRequestInterface",
"$",
"request",
")",
"{",
"return",
"$",
"this",
"->",
"serviceProxyStrategyResponseBuilder",
"->",
"create",
"(",
")",
"->",
"withPreSource",
"(",
"$",
"this",
"->",
"generatePreSource",
"(",
"$",
"request",
")",
")",
"->",
"withPostSource",
"(",
"$",
"this",
"->",
"generatePostSource",
"(",
"$",
"request",
"->",
"getAnnotation",
"(",
")",
")",
")",
"->",
"withExceptionSource",
"(",
"''",
")",
"->",
"withProperties",
"(",
"$",
"this",
"->",
"generateProperties",
"(",
")",
")",
"->",
"withMethods",
"(",
"$",
"this",
"->",
"generateMethods",
"(",
")",
")",
"->",
"build",
"(",
")",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/OpenClassrooms/ServiceProxy/blob/31f9f8be8f064b4ca36873df83fc3833f53da438/src/Proxy/Strategy/ServiceProxyCacheStrategy.php#L24-L34 |
dburkart/scurvy | expression.php | Expression.evaluate | public function evaluate(&$registry=null, $recurse=false) {
// Back ourself up; this expression may need to be called more than
// once.
if ( !$recurse ) {
$this->eval = null;
$this->atomListBackup = $this->atomList;
}
// Get the next atom
$next = array_pop($this->atomList);
if (is_null($this->eval) || $recurse) {
switch($next->type) {
case EXPR_VAR:
if (is_numeric($next->val)) {
$this->eval = $next->val;
if ($recurse)
return $this->eval;
} else if (preg_match('/\'([a-zA-Z0-9_-]*)\'/', $next->val, $matches)) {
$this->eval = $matches[1];
if ($recurse)
return $this->eval;
} else if ($next->val == 'true' || $next->val == 'false') {
$this->eval = (bool)$next->val;
if ($recurse)
return $this->eval;
} else if (isset($registry[$next->val])) {
$this->eval = $registry[$next->val];
if ($recurse)
return $this->eval;
} else {
$this->eval = 0;
if ($recurse)
return $this->eval;
}
break;
case EXPR_NOT:
$this->eval = !($this->evaluate($registry, true));
if ($recurse)
return $this->eval;
break;
case EXPR_MUL:
$b = $this->evaluate($registry, true);
$this->eval = $this->evaluate($registry, true) * $b;
if ($recurse)
return $this->eval;
break;
case EXPR_DIV:
$b = $this->evaluate($registry, true);
$this->eval = (int)floor($this->evaluate($registry, true) / $b);
if ($recurse)
return $this->eval;
break;
case EXPR_MOD:
$b = $this->evaluate($registry, true);
$this->eval = $this->evaluate($registry, true) % $b;
if ($recurse)
return $this->eval;
break;
case EXPR_POS:
$this->eval = $this->evaluate($registry, true) + $this->evaluate($registry, true);
if ($recurse)
return $this->eval;
break;
case EXPR_NEG:
$b = $this->evaluate($registry, true);
$this->eval = $this->evaluate($registry, true) - $b;
if ($recurse)
return $this->eval;
break;
case EXPR_AND:
$b = $this->evaluate($registry, true);
$this->eval = ($this->evaluate($registry, true) && $b);
if ($recurse)
return $this->eval;
break;
case EXPR_OR:
$b = $this->evaluate($registry, true);
$this->eval = ($this->evaluate($registry, true) || $b);
if ($recurse)
return $this->eval;
break;
case EXPR_EQU:
$this->eval = ($this->evaluate($registry, true) == $this->evaluate($registry, true));
break;
case EXPR_NEQ:
$this->eval = ($this->evaluate($registry, true) != $this->evaluate($registry, true));
break;
case EXPR_LES:
$this->eval = ($this->evaluate($registry, true) > $this->evaluate($registry, true));
break;
case EXPR_GRE:
$this->eval = ($this->evaluate($registry, true) < $this->evaluate($registry, true));
break;
case EXPR_LEQ:
$this->eval = ($this->evaluate($registry, true) >= $this->evaluate($registry, true));
break;
case EXPR_GEQ:
$this->eval = ($this->evaluate($registry, true) <= $this->evaluate($registry, true));
break;
}
// Restore our stack
$this->atomList = $this->atomListBackup;
return $this->eval;
} else {
return $this->eval;
}
} | php | public function evaluate(&$registry=null, $recurse=false) {
// Back ourself up; this expression may need to be called more than
// once.
if ( !$recurse ) {
$this->eval = null;
$this->atomListBackup = $this->atomList;
}
// Get the next atom
$next = array_pop($this->atomList);
if (is_null($this->eval) || $recurse) {
switch($next->type) {
case EXPR_VAR:
if (is_numeric($next->val)) {
$this->eval = $next->val;
if ($recurse)
return $this->eval;
} else if (preg_match('/\'([a-zA-Z0-9_-]*)\'/', $next->val, $matches)) {
$this->eval = $matches[1];
if ($recurse)
return $this->eval;
} else if ($next->val == 'true' || $next->val == 'false') {
$this->eval = (bool)$next->val;
if ($recurse)
return $this->eval;
} else if (isset($registry[$next->val])) {
$this->eval = $registry[$next->val];
if ($recurse)
return $this->eval;
} else {
$this->eval = 0;
if ($recurse)
return $this->eval;
}
break;
case EXPR_NOT:
$this->eval = !($this->evaluate($registry, true));
if ($recurse)
return $this->eval;
break;
case EXPR_MUL:
$b = $this->evaluate($registry, true);
$this->eval = $this->evaluate($registry, true) * $b;
if ($recurse)
return $this->eval;
break;
case EXPR_DIV:
$b = $this->evaluate($registry, true);
$this->eval = (int)floor($this->evaluate($registry, true) / $b);
if ($recurse)
return $this->eval;
break;
case EXPR_MOD:
$b = $this->evaluate($registry, true);
$this->eval = $this->evaluate($registry, true) % $b;
if ($recurse)
return $this->eval;
break;
case EXPR_POS:
$this->eval = $this->evaluate($registry, true) + $this->evaluate($registry, true);
if ($recurse)
return $this->eval;
break;
case EXPR_NEG:
$b = $this->evaluate($registry, true);
$this->eval = $this->evaluate($registry, true) - $b;
if ($recurse)
return $this->eval;
break;
case EXPR_AND:
$b = $this->evaluate($registry, true);
$this->eval = ($this->evaluate($registry, true) && $b);
if ($recurse)
return $this->eval;
break;
case EXPR_OR:
$b = $this->evaluate($registry, true);
$this->eval = ($this->evaluate($registry, true) || $b);
if ($recurse)
return $this->eval;
break;
case EXPR_EQU:
$this->eval = ($this->evaluate($registry, true) == $this->evaluate($registry, true));
break;
case EXPR_NEQ:
$this->eval = ($this->evaluate($registry, true) != $this->evaluate($registry, true));
break;
case EXPR_LES:
$this->eval = ($this->evaluate($registry, true) > $this->evaluate($registry, true));
break;
case EXPR_GRE:
$this->eval = ($this->evaluate($registry, true) < $this->evaluate($registry, true));
break;
case EXPR_LEQ:
$this->eval = ($this->evaluate($registry, true) >= $this->evaluate($registry, true));
break;
case EXPR_GEQ:
$this->eval = ($this->evaluate($registry, true) <= $this->evaluate($registry, true));
break;
}
// Restore our stack
$this->atomList = $this->atomListBackup;
return $this->eval;
} else {
return $this->eval;
}
} | [
"public",
"function",
"evaluate",
"(",
"&",
"$",
"registry",
"=",
"null",
",",
"$",
"recurse",
"=",
"false",
")",
"{",
"// Back ourself up; this expression may need to be called more than",
"// once.",
"if",
"(",
"!",
"$",
"recurse",
")",
"{",
"$",
"this",
"->",
"eval",
"=",
"null",
";",
"$",
"this",
"->",
"atomListBackup",
"=",
"$",
"this",
"->",
"atomList",
";",
"}",
"// Get the next atom",
"$",
"next",
"=",
"array_pop",
"(",
"$",
"this",
"->",
"atomList",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"eval",
")",
"||",
"$",
"recurse",
")",
"{",
"switch",
"(",
"$",
"next",
"->",
"type",
")",
"{",
"case",
"EXPR_VAR",
":",
"if",
"(",
"is_numeric",
"(",
"$",
"next",
"->",
"val",
")",
")",
"{",
"$",
"this",
"->",
"eval",
"=",
"$",
"next",
"->",
"val",
";",
"if",
"(",
"$",
"recurse",
")",
"return",
"$",
"this",
"->",
"eval",
";",
"}",
"else",
"if",
"(",
"preg_match",
"(",
"'/\\'([a-zA-Z0-9_-]*)\\'/'",
",",
"$",
"next",
"->",
"val",
",",
"$",
"matches",
")",
")",
"{",
"$",
"this",
"->",
"eval",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"if",
"(",
"$",
"recurse",
")",
"return",
"$",
"this",
"->",
"eval",
";",
"}",
"else",
"if",
"(",
"$",
"next",
"->",
"val",
"==",
"'true'",
"||",
"$",
"next",
"->",
"val",
"==",
"'false'",
")",
"{",
"$",
"this",
"->",
"eval",
"=",
"(",
"bool",
")",
"$",
"next",
"->",
"val",
";",
"if",
"(",
"$",
"recurse",
")",
"return",
"$",
"this",
"->",
"eval",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"registry",
"[",
"$",
"next",
"->",
"val",
"]",
")",
")",
"{",
"$",
"this",
"->",
"eval",
"=",
"$",
"registry",
"[",
"$",
"next",
"->",
"val",
"]",
";",
"if",
"(",
"$",
"recurse",
")",
"return",
"$",
"this",
"->",
"eval",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"eval",
"=",
"0",
";",
"if",
"(",
"$",
"recurse",
")",
"return",
"$",
"this",
"->",
"eval",
";",
"}",
"break",
";",
"case",
"EXPR_NOT",
":",
"$",
"this",
"->",
"eval",
"=",
"!",
"(",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
")",
";",
"if",
"(",
"$",
"recurse",
")",
"return",
"$",
"this",
"->",
"eval",
";",
"break",
";",
"case",
"EXPR_MUL",
":",
"$",
"b",
"=",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
";",
"$",
"this",
"->",
"eval",
"=",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
"*",
"$",
"b",
";",
"if",
"(",
"$",
"recurse",
")",
"return",
"$",
"this",
"->",
"eval",
";",
"break",
";",
"case",
"EXPR_DIV",
":",
"$",
"b",
"=",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
";",
"$",
"this",
"->",
"eval",
"=",
"(",
"int",
")",
"floor",
"(",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
"/",
"$",
"b",
")",
";",
"if",
"(",
"$",
"recurse",
")",
"return",
"$",
"this",
"->",
"eval",
";",
"break",
";",
"case",
"EXPR_MOD",
":",
"$",
"b",
"=",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
";",
"$",
"this",
"->",
"eval",
"=",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
"%",
"$",
"b",
";",
"if",
"(",
"$",
"recurse",
")",
"return",
"$",
"this",
"->",
"eval",
";",
"break",
";",
"case",
"EXPR_POS",
":",
"$",
"this",
"->",
"eval",
"=",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
"+",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
";",
"if",
"(",
"$",
"recurse",
")",
"return",
"$",
"this",
"->",
"eval",
";",
"break",
";",
"case",
"EXPR_NEG",
":",
"$",
"b",
"=",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
";",
"$",
"this",
"->",
"eval",
"=",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
"-",
"$",
"b",
";",
"if",
"(",
"$",
"recurse",
")",
"return",
"$",
"this",
"->",
"eval",
";",
"break",
";",
"case",
"EXPR_AND",
":",
"$",
"b",
"=",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
";",
"$",
"this",
"->",
"eval",
"=",
"(",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
"&&",
"$",
"b",
")",
";",
"if",
"(",
"$",
"recurse",
")",
"return",
"$",
"this",
"->",
"eval",
";",
"break",
";",
"case",
"EXPR_OR",
":",
"$",
"b",
"=",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
";",
"$",
"this",
"->",
"eval",
"=",
"(",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
"||",
"$",
"b",
")",
";",
"if",
"(",
"$",
"recurse",
")",
"return",
"$",
"this",
"->",
"eval",
";",
"break",
";",
"case",
"EXPR_EQU",
":",
"$",
"this",
"->",
"eval",
"=",
"(",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
"==",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
")",
";",
"break",
";",
"case",
"EXPR_NEQ",
":",
"$",
"this",
"->",
"eval",
"=",
"(",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
"!=",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
")",
";",
"break",
";",
"case",
"EXPR_LES",
":",
"$",
"this",
"->",
"eval",
"=",
"(",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
">",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
")",
";",
"break",
";",
"case",
"EXPR_GRE",
":",
"$",
"this",
"->",
"eval",
"=",
"(",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
"<",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
")",
";",
"break",
";",
"case",
"EXPR_LEQ",
":",
"$",
"this",
"->",
"eval",
"=",
"(",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
">=",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
")",
";",
"break",
";",
"case",
"EXPR_GEQ",
":",
"$",
"this",
"->",
"eval",
"=",
"(",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
"<=",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"registry",
",",
"true",
")",
")",
";",
"break",
";",
"}",
"// Restore our stack",
"$",
"this",
"->",
"atomList",
"=",
"$",
"this",
"->",
"atomListBackup",
";",
"return",
"$",
"this",
"->",
"eval",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"eval",
";",
"}",
"}"
]
| Evaluates the decomposed expression contained in $this->atomList.
@param registry an associative array containing relevant variables
@return the result of the evaluation. | [
"Evaluates",
"the",
"decomposed",
"expression",
"contained",
"in",
"$this",
"-",
">",
"atomList",
"."
]
| train | https://github.com/dburkart/scurvy/blob/990a7c4f0517298de304438cf9cd95a303a231fb/expression.php#L87-L209 |
dburkart/scurvy | expression.php | Expression.decompose | public function decompose($expr) {
$buffer = '';
$atomList = array();
$stack = array();
$count = strlen($expr);
$i = 0;
while ($i < $count) {
switch ($expr[$i]) {
case '<':
$this->pushVar($buffer, $atomList);
$a = EXPR_LES;
if ($expr[$i+1] == '=') {
$a = EXPR_LEQ;
$i += 1;
}
$this->addOperator( $atomList, $stack, $a );
break;
case '>':
$this->pushVar($buffer, $atomList);
$a = EXPR_GRE;
if ($expr[$i+1] == '=') {
$a = EXPR_GEQ;
$i += 1;
}
$this->addOperator( $atomList, $stack, $a );
break;
case '!':
$this->pushVar($buffer, $atomList);
$a = EXPR_NOT;
if ($expr[$i+1] == '=') {
$a = EXPR_NEQ;
$i += 1;
}
$this->addOperator( $atomList, $stack, $a );
break;
case '&':
$this->pushVar($buffer, $atomList);
$a = EXPR_AND;
if ($expr[$i+1] == '&') {
$i += 1;
}
$this->addOperator( $atomList, $stack, $a );
break;
case '|':
$this->pushVar($buffer, $atomList);
$a = EXPR_OR;
if ($expr[$i+1] == '|') {
$i += 1;
}
$this->addOperator( $atomList, $stack, $a );
break;
case ')':
$this->pushVar($buffer, $atomList);
$top = array_pop($stack);
while($top->type != EXPR_PAR && $top != NULL) {
$atomList[] = $top;
$top = array_pop($stack);
}
break;
case '(':
$this->pushVar($buffer, $atomList);
array_push($stack, new Atom(EXPR_PAR));
break;
case '=':
$this->pushVar($buffer, $atomList);
$this->addOperator( $atomList, $stack, EXPR_EQU );
break;
case '*':
$this->pushVar($buffer, $atomList);
$this->addOperator( $atomList, $stack, EXPR_MUL );
break;
case '/':
$this->pushVar($buffer, $atomList);
$this->addOperator( $atomList, $stack, EXPR_DIV );
break;
case '%':
$this->pushVar($buffer, $atomList);
$this->addOperator( $atomList, $stack, EXPR_MOD );
break;
case '+':
$this->pushVar($buffer, $atomList);
$this->addOperator( $atomList, $stack, EXPR_POS );
break;
case '-':
$this->pushVar($buffer, $atomList);
$this->addOperator( $atomList, $stack, EXPR_NEG );
break;
default:
$buffer = $buffer . $expr[$i];
break;
}
$i++;
}
$this->pushVar($buffer, $atomList);
while (($top = array_pop($stack)) == true) {
$atomList[] = $top;
}
$this->atomList = $atomList;
return $this->atomList;
} | php | public function decompose($expr) {
$buffer = '';
$atomList = array();
$stack = array();
$count = strlen($expr);
$i = 0;
while ($i < $count) {
switch ($expr[$i]) {
case '<':
$this->pushVar($buffer, $atomList);
$a = EXPR_LES;
if ($expr[$i+1] == '=') {
$a = EXPR_LEQ;
$i += 1;
}
$this->addOperator( $atomList, $stack, $a );
break;
case '>':
$this->pushVar($buffer, $atomList);
$a = EXPR_GRE;
if ($expr[$i+1] == '=') {
$a = EXPR_GEQ;
$i += 1;
}
$this->addOperator( $atomList, $stack, $a );
break;
case '!':
$this->pushVar($buffer, $atomList);
$a = EXPR_NOT;
if ($expr[$i+1] == '=') {
$a = EXPR_NEQ;
$i += 1;
}
$this->addOperator( $atomList, $stack, $a );
break;
case '&':
$this->pushVar($buffer, $atomList);
$a = EXPR_AND;
if ($expr[$i+1] == '&') {
$i += 1;
}
$this->addOperator( $atomList, $stack, $a );
break;
case '|':
$this->pushVar($buffer, $atomList);
$a = EXPR_OR;
if ($expr[$i+1] == '|') {
$i += 1;
}
$this->addOperator( $atomList, $stack, $a );
break;
case ')':
$this->pushVar($buffer, $atomList);
$top = array_pop($stack);
while($top->type != EXPR_PAR && $top != NULL) {
$atomList[] = $top;
$top = array_pop($stack);
}
break;
case '(':
$this->pushVar($buffer, $atomList);
array_push($stack, new Atom(EXPR_PAR));
break;
case '=':
$this->pushVar($buffer, $atomList);
$this->addOperator( $atomList, $stack, EXPR_EQU );
break;
case '*':
$this->pushVar($buffer, $atomList);
$this->addOperator( $atomList, $stack, EXPR_MUL );
break;
case '/':
$this->pushVar($buffer, $atomList);
$this->addOperator( $atomList, $stack, EXPR_DIV );
break;
case '%':
$this->pushVar($buffer, $atomList);
$this->addOperator( $atomList, $stack, EXPR_MOD );
break;
case '+':
$this->pushVar($buffer, $atomList);
$this->addOperator( $atomList, $stack, EXPR_POS );
break;
case '-':
$this->pushVar($buffer, $atomList);
$this->addOperator( $atomList, $stack, EXPR_NEG );
break;
default:
$buffer = $buffer . $expr[$i];
break;
}
$i++;
}
$this->pushVar($buffer, $atomList);
while (($top = array_pop($stack)) == true) {
$atomList[] = $top;
}
$this->atomList = $atomList;
return $this->atomList;
} | [
"public",
"function",
"decompose",
"(",
"$",
"expr",
")",
"{",
"$",
"buffer",
"=",
"''",
";",
"$",
"atomList",
"=",
"array",
"(",
")",
";",
"$",
"stack",
"=",
"array",
"(",
")",
";",
"$",
"count",
"=",
"strlen",
"(",
"$",
"expr",
")",
";",
"$",
"i",
"=",
"0",
";",
"while",
"(",
"$",
"i",
"<",
"$",
"count",
")",
"{",
"switch",
"(",
"$",
"expr",
"[",
"$",
"i",
"]",
")",
"{",
"case",
"'<'",
":",
"$",
"this",
"->",
"pushVar",
"(",
"$",
"buffer",
",",
"$",
"atomList",
")",
";",
"$",
"a",
"=",
"EXPR_LES",
";",
"if",
"(",
"$",
"expr",
"[",
"$",
"i",
"+",
"1",
"]",
"==",
"'='",
")",
"{",
"$",
"a",
"=",
"EXPR_LEQ",
";",
"$",
"i",
"+=",
"1",
";",
"}",
"$",
"this",
"->",
"addOperator",
"(",
"$",
"atomList",
",",
"$",
"stack",
",",
"$",
"a",
")",
";",
"break",
";",
"case",
"'>'",
":",
"$",
"this",
"->",
"pushVar",
"(",
"$",
"buffer",
",",
"$",
"atomList",
")",
";",
"$",
"a",
"=",
"EXPR_GRE",
";",
"if",
"(",
"$",
"expr",
"[",
"$",
"i",
"+",
"1",
"]",
"==",
"'='",
")",
"{",
"$",
"a",
"=",
"EXPR_GEQ",
";",
"$",
"i",
"+=",
"1",
";",
"}",
"$",
"this",
"->",
"addOperator",
"(",
"$",
"atomList",
",",
"$",
"stack",
",",
"$",
"a",
")",
";",
"break",
";",
"case",
"'!'",
":",
"$",
"this",
"->",
"pushVar",
"(",
"$",
"buffer",
",",
"$",
"atomList",
")",
";",
"$",
"a",
"=",
"EXPR_NOT",
";",
"if",
"(",
"$",
"expr",
"[",
"$",
"i",
"+",
"1",
"]",
"==",
"'='",
")",
"{",
"$",
"a",
"=",
"EXPR_NEQ",
";",
"$",
"i",
"+=",
"1",
";",
"}",
"$",
"this",
"->",
"addOperator",
"(",
"$",
"atomList",
",",
"$",
"stack",
",",
"$",
"a",
")",
";",
"break",
";",
"case",
"'&'",
":",
"$",
"this",
"->",
"pushVar",
"(",
"$",
"buffer",
",",
"$",
"atomList",
")",
";",
"$",
"a",
"=",
"EXPR_AND",
";",
"if",
"(",
"$",
"expr",
"[",
"$",
"i",
"+",
"1",
"]",
"==",
"'&'",
")",
"{",
"$",
"i",
"+=",
"1",
";",
"}",
"$",
"this",
"->",
"addOperator",
"(",
"$",
"atomList",
",",
"$",
"stack",
",",
"$",
"a",
")",
";",
"break",
";",
"case",
"'|'",
":",
"$",
"this",
"->",
"pushVar",
"(",
"$",
"buffer",
",",
"$",
"atomList",
")",
";",
"$",
"a",
"=",
"EXPR_OR",
";",
"if",
"(",
"$",
"expr",
"[",
"$",
"i",
"+",
"1",
"]",
"==",
"'|'",
")",
"{",
"$",
"i",
"+=",
"1",
";",
"}",
"$",
"this",
"->",
"addOperator",
"(",
"$",
"atomList",
",",
"$",
"stack",
",",
"$",
"a",
")",
";",
"break",
";",
"case",
"')'",
":",
"$",
"this",
"->",
"pushVar",
"(",
"$",
"buffer",
",",
"$",
"atomList",
")",
";",
"$",
"top",
"=",
"array_pop",
"(",
"$",
"stack",
")",
";",
"while",
"(",
"$",
"top",
"->",
"type",
"!=",
"EXPR_PAR",
"&&",
"$",
"top",
"!=",
"NULL",
")",
"{",
"$",
"atomList",
"[",
"]",
"=",
"$",
"top",
";",
"$",
"top",
"=",
"array_pop",
"(",
"$",
"stack",
")",
";",
"}",
"break",
";",
"case",
"'('",
":",
"$",
"this",
"->",
"pushVar",
"(",
"$",
"buffer",
",",
"$",
"atomList",
")",
";",
"array_push",
"(",
"$",
"stack",
",",
"new",
"Atom",
"(",
"EXPR_PAR",
")",
")",
";",
"break",
";",
"case",
"'='",
":",
"$",
"this",
"->",
"pushVar",
"(",
"$",
"buffer",
",",
"$",
"atomList",
")",
";",
"$",
"this",
"->",
"addOperator",
"(",
"$",
"atomList",
",",
"$",
"stack",
",",
"EXPR_EQU",
")",
";",
"break",
";",
"case",
"'*'",
":",
"$",
"this",
"->",
"pushVar",
"(",
"$",
"buffer",
",",
"$",
"atomList",
")",
";",
"$",
"this",
"->",
"addOperator",
"(",
"$",
"atomList",
",",
"$",
"stack",
",",
"EXPR_MUL",
")",
";",
"break",
";",
"case",
"'/'",
":",
"$",
"this",
"->",
"pushVar",
"(",
"$",
"buffer",
",",
"$",
"atomList",
")",
";",
"$",
"this",
"->",
"addOperator",
"(",
"$",
"atomList",
",",
"$",
"stack",
",",
"EXPR_DIV",
")",
";",
"break",
";",
"case",
"'%'",
":",
"$",
"this",
"->",
"pushVar",
"(",
"$",
"buffer",
",",
"$",
"atomList",
")",
";",
"$",
"this",
"->",
"addOperator",
"(",
"$",
"atomList",
",",
"$",
"stack",
",",
"EXPR_MOD",
")",
";",
"break",
";",
"case",
"'+'",
":",
"$",
"this",
"->",
"pushVar",
"(",
"$",
"buffer",
",",
"$",
"atomList",
")",
";",
"$",
"this",
"->",
"addOperator",
"(",
"$",
"atomList",
",",
"$",
"stack",
",",
"EXPR_POS",
")",
";",
"break",
";",
"case",
"'-'",
":",
"$",
"this",
"->",
"pushVar",
"(",
"$",
"buffer",
",",
"$",
"atomList",
")",
";",
"$",
"this",
"->",
"addOperator",
"(",
"$",
"atomList",
",",
"$",
"stack",
",",
"EXPR_NEG",
")",
";",
"break",
";",
"default",
":",
"$",
"buffer",
"=",
"$",
"buffer",
".",
"$",
"expr",
"[",
"$",
"i",
"]",
";",
"break",
";",
"}",
"$",
"i",
"++",
";",
"}",
"$",
"this",
"->",
"pushVar",
"(",
"$",
"buffer",
",",
"$",
"atomList",
")",
";",
"while",
"(",
"(",
"$",
"top",
"=",
"array_pop",
"(",
"$",
"stack",
")",
")",
"==",
"true",
")",
"{",
"$",
"atomList",
"[",
"]",
"=",
"$",
"top",
";",
"}",
"$",
"this",
"->",
"atomList",
"=",
"$",
"atomList",
";",
"return",
"$",
"this",
"->",
"atomList",
";",
"}"
]
| decompose() checks for an equal sign, and if found, decomposes each side
using decomposeE(), and then pushes the equality operator onto the stack.
If there is no equal sign, then decomposeE() is called on the entire
expression.
@param expr the expression to decompose | [
"decompose",
"()",
"checks",
"for",
"an",
"equal",
"sign",
"and",
"if",
"found",
"decomposes",
"each",
"side",
"using",
"decomposeE",
"()",
"and",
"then",
"pushes",
"the",
"equality",
"operator",
"onto",
"the",
"stack",
".",
"If",
"there",
"is",
"no",
"equal",
"sign",
"then",
"decomposeE",
"()",
"is",
"called",
"on",
"the",
"entire",
"expression",
"."
]
| train | https://github.com/dburkart/scurvy/blob/990a7c4f0517298de304438cf9cd95a303a231fb/expression.php#L219-L334 |
dburkart/scurvy | expression.php | Expression.newVar | public function newVar($str) {
$str = trim($str);
// Try to make it a variable
if (preg_match('/^[a-zA-Z0-9\'_][a-zA-Z0-9\'_-]*$/', $str))
return new Atom(EXPR_VAR, $str);
else {
return false;
}
} | php | public function newVar($str) {
$str = trim($str);
// Try to make it a variable
if (preg_match('/^[a-zA-Z0-9\'_][a-zA-Z0-9\'_-]*$/', $str))
return new Atom(EXPR_VAR, $str);
else {
return false;
}
} | [
"public",
"function",
"newVar",
"(",
"$",
"str",
")",
"{",
"$",
"str",
"=",
"trim",
"(",
"$",
"str",
")",
";",
"// Try to make it a variable",
"if",
"(",
"preg_match",
"(",
"'/^[a-zA-Z0-9\\'_][a-zA-Z0-9\\'_-]*$/'",
",",
"$",
"str",
")",
")",
"return",
"new",
"Atom",
"(",
"EXPR_VAR",
",",
"$",
"str",
")",
";",
"else",
"{",
"return",
"false",
";",
"}",
"}"
]
| Creates a new variable atom, subsequent to validating that the string
is correct for a variable
@param str the name of the variable
@return the newly created atom | [
"Creates",
"a",
"new",
"variable",
"atom",
"subsequent",
"to",
"validating",
"that",
"the",
"string",
"is",
"correct",
"for",
"a",
"variable"
]
| train | https://github.com/dburkart/scurvy/blob/990a7c4f0517298de304438cf9cd95a303a231fb/expression.php#L343-L352 |
fubhy/graphql-php | src/Executor/Executor.php | Executor.execute | public static function execute(Schema $schema, $root, Document $ast, $operation = NULL, array $args = NULL)
{
if (!self::$UNDEFINED) {
self::$UNDEFINED = new \stdClass();
}
try {
$errors = new \ArrayObject();
$context = self::buildExecutionContext($schema, $root, $ast, $operation, $args, $errors);
$data = self::executeOperation($context, $root, $context->operation);
} catch (\Exception $e) {
$errors[] = $e;
}
$result = ['data' => isset($data) ? $data : NULL];
if (count($errors) > 0) {
$result['errors'] = $errors->getArrayCopy();
}
return $result;
} | php | public static function execute(Schema $schema, $root, Document $ast, $operation = NULL, array $args = NULL)
{
if (!self::$UNDEFINED) {
self::$UNDEFINED = new \stdClass();
}
try {
$errors = new \ArrayObject();
$context = self::buildExecutionContext($schema, $root, $ast, $operation, $args, $errors);
$data = self::executeOperation($context, $root, $context->operation);
} catch (\Exception $e) {
$errors[] = $e;
}
$result = ['data' => isset($data) ? $data : NULL];
if (count($errors) > 0) {
$result['errors'] = $errors->getArrayCopy();
}
return $result;
} | [
"public",
"static",
"function",
"execute",
"(",
"Schema",
"$",
"schema",
",",
"$",
"root",
",",
"Document",
"$",
"ast",
",",
"$",
"operation",
"=",
"NULL",
",",
"array",
"$",
"args",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"UNDEFINED",
")",
"{",
"self",
"::",
"$",
"UNDEFINED",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"}",
"try",
"{",
"$",
"errors",
"=",
"new",
"\\",
"ArrayObject",
"(",
")",
";",
"$",
"context",
"=",
"self",
"::",
"buildExecutionContext",
"(",
"$",
"schema",
",",
"$",
"root",
",",
"$",
"ast",
",",
"$",
"operation",
",",
"$",
"args",
",",
"$",
"errors",
")",
";",
"$",
"data",
"=",
"self",
"::",
"executeOperation",
"(",
"$",
"context",
",",
"$",
"root",
",",
"$",
"context",
"->",
"operation",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"$",
"e",
";",
"}",
"$",
"result",
"=",
"[",
"'data'",
"=>",
"isset",
"(",
"$",
"data",
")",
"?",
"$",
"data",
":",
"NULL",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"errors",
")",
">",
"0",
")",
"{",
"$",
"result",
"[",
"'errors'",
"]",
"=",
"$",
"errors",
"->",
"getArrayCopy",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| @param \Fubhy\GraphQL\Schema $schema
@param $root
@param \Fubhy\GraphQL\Language\Node\Document $ast
@param string|null $operation
@param array|null $args
@return array | [
"@param",
"\\",
"Fubhy",
"\\",
"GraphQL",
"\\",
"Schema",
"$schema",
"@param",
"$root",
"@param",
"\\",
"Fubhy",
"\\",
"GraphQL",
"\\",
"Language",
"\\",
"Node",
"\\",
"Document",
"$ast",
"@param",
"string|null",
"$operation",
"@param",
"array|null",
"$args"
]
| train | https://github.com/fubhy/graphql-php/blob/c1de2233c731ca29e5c5db4c43f3b9db36478c83/src/Executor/Executor.php#L57-L77 |
fubhy/graphql-php | src/Executor/Executor.php | Executor.buildExecutionContext | protected static function buildExecutionContext(Schema $schema, $root, Document $ast, $operationName = NULL, array $args = NULL, &$errors)
{
$operations = [];
$fragments = [];
foreach ($ast->get('definitions') as $statement) {
switch ($statement::KIND) {
case Node::KIND_OPERATION_DEFINITION:
$operations[$statement->get('name') ? $statement->get('name')->get('value') : ''] = $statement;
break;
case Node::KIND_FRAGMENT_DEFINITION:
$fragments[$statement->get('name')->get('value')] = $statement;
break;
}
}
if (!$operationName && count($operations) !== 1) {
throw new \Exception('Must provide operation name if query contains multiple operations');
}
$name = $operationName ?: key($operations);
if (!isset($operations[$name])) {
throw new \Exception('Unknown operation name: ' . $name);
}
$operation = $operations[$name];
$variables = Values::getVariableValues($schema, $operation->get('variableDefinitions') ?: [], $args ?: []);
$context = new ExecutionContext($schema, $fragments, $root, $operation, $variables, $errors);
return $context;
} | php | protected static function buildExecutionContext(Schema $schema, $root, Document $ast, $operationName = NULL, array $args = NULL, &$errors)
{
$operations = [];
$fragments = [];
foreach ($ast->get('definitions') as $statement) {
switch ($statement::KIND) {
case Node::KIND_OPERATION_DEFINITION:
$operations[$statement->get('name') ? $statement->get('name')->get('value') : ''] = $statement;
break;
case Node::KIND_FRAGMENT_DEFINITION:
$fragments[$statement->get('name')->get('value')] = $statement;
break;
}
}
if (!$operationName && count($operations) !== 1) {
throw new \Exception('Must provide operation name if query contains multiple operations');
}
$name = $operationName ?: key($operations);
if (!isset($operations[$name])) {
throw new \Exception('Unknown operation name: ' . $name);
}
$operation = $operations[$name];
$variables = Values::getVariableValues($schema, $operation->get('variableDefinitions') ?: [], $args ?: []);
$context = new ExecutionContext($schema, $fragments, $root, $operation, $variables, $errors);
return $context;
} | [
"protected",
"static",
"function",
"buildExecutionContext",
"(",
"Schema",
"$",
"schema",
",",
"$",
"root",
",",
"Document",
"$",
"ast",
",",
"$",
"operationName",
"=",
"NULL",
",",
"array",
"$",
"args",
"=",
"NULL",
",",
"&",
"$",
"errors",
")",
"{",
"$",
"operations",
"=",
"[",
"]",
";",
"$",
"fragments",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"ast",
"->",
"get",
"(",
"'definitions'",
")",
"as",
"$",
"statement",
")",
"{",
"switch",
"(",
"$",
"statement",
"::",
"KIND",
")",
"{",
"case",
"Node",
"::",
"KIND_OPERATION_DEFINITION",
":",
"$",
"operations",
"[",
"$",
"statement",
"->",
"get",
"(",
"'name'",
")",
"?",
"$",
"statement",
"->",
"get",
"(",
"'name'",
")",
"->",
"get",
"(",
"'value'",
")",
":",
"''",
"]",
"=",
"$",
"statement",
";",
"break",
";",
"case",
"Node",
"::",
"KIND_FRAGMENT_DEFINITION",
":",
"$",
"fragments",
"[",
"$",
"statement",
"->",
"get",
"(",
"'name'",
")",
"->",
"get",
"(",
"'value'",
")",
"]",
"=",
"$",
"statement",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"operationName",
"&&",
"count",
"(",
"$",
"operations",
")",
"!==",
"1",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Must provide operation name if query contains multiple operations'",
")",
";",
"}",
"$",
"name",
"=",
"$",
"operationName",
"?",
":",
"key",
"(",
"$",
"operations",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"operations",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Unknown operation name: '",
".",
"$",
"name",
")",
";",
"}",
"$",
"operation",
"=",
"$",
"operations",
"[",
"$",
"name",
"]",
";",
"$",
"variables",
"=",
"Values",
"::",
"getVariableValues",
"(",
"$",
"schema",
",",
"$",
"operation",
"->",
"get",
"(",
"'variableDefinitions'",
")",
"?",
":",
"[",
"]",
",",
"$",
"args",
"?",
":",
"[",
"]",
")",
";",
"$",
"context",
"=",
"new",
"ExecutionContext",
"(",
"$",
"schema",
",",
"$",
"fragments",
",",
"$",
"root",
",",
"$",
"operation",
",",
"$",
"variables",
",",
"$",
"errors",
")",
";",
"return",
"$",
"context",
";",
"}"
]
| Constructs a ExecutionContext object from the arguments passed to
execute, which we will pass throughout the other execution methods.
@param Schema $schema
@param $root
@param Document $ast
@param string|null $operationName
@param array $args
@param $errors
@return ExecutionContext
@throws \Exception | [
"Constructs",
"a",
"ExecutionContext",
"object",
"from",
"the",
"arguments",
"passed",
"to",
"execute",
"which",
"we",
"will",
"pass",
"throughout",
"the",
"other",
"execution",
"methods",
"."
]
| train | https://github.com/fubhy/graphql-php/blob/c1de2233c731ca29e5c5db4c43f3b9db36478c83/src/Executor/Executor.php#L94-L125 |
fubhy/graphql-php | src/Executor/Executor.php | Executor.executeOperation | protected static function executeOperation(ExecutionContext $context, $root, OperationDefinition $operation)
{
$type = self::getOperationRootType($context->schema, $operation);
$fields = self::collectFields($context, $type, $operation->get('selectionSet'), new \ArrayObject(), new \ArrayObject());
if ($operation->get('operation') === 'mutation') {
return self::executeFieldsSerially($context, $type, $root, $fields->getArrayCopy());
}
return self::executeFields($context, $type, $root, $fields);
} | php | protected static function executeOperation(ExecutionContext $context, $root, OperationDefinition $operation)
{
$type = self::getOperationRootType($context->schema, $operation);
$fields = self::collectFields($context, $type, $operation->get('selectionSet'), new \ArrayObject(), new \ArrayObject());
if ($operation->get('operation') === 'mutation') {
return self::executeFieldsSerially($context, $type, $root, $fields->getArrayCopy());
}
return self::executeFields($context, $type, $root, $fields);
} | [
"protected",
"static",
"function",
"executeOperation",
"(",
"ExecutionContext",
"$",
"context",
",",
"$",
"root",
",",
"OperationDefinition",
"$",
"operation",
")",
"{",
"$",
"type",
"=",
"self",
"::",
"getOperationRootType",
"(",
"$",
"context",
"->",
"schema",
",",
"$",
"operation",
")",
";",
"$",
"fields",
"=",
"self",
"::",
"collectFields",
"(",
"$",
"context",
",",
"$",
"type",
",",
"$",
"operation",
"->",
"get",
"(",
"'selectionSet'",
")",
",",
"new",
"\\",
"ArrayObject",
"(",
")",
",",
"new",
"\\",
"ArrayObject",
"(",
")",
")",
";",
"if",
"(",
"$",
"operation",
"->",
"get",
"(",
"'operation'",
")",
"===",
"'mutation'",
")",
"{",
"return",
"self",
"::",
"executeFieldsSerially",
"(",
"$",
"context",
",",
"$",
"type",
",",
"$",
"root",
",",
"$",
"fields",
"->",
"getArrayCopy",
"(",
")",
")",
";",
"}",
"return",
"self",
"::",
"executeFields",
"(",
"$",
"context",
",",
"$",
"type",
",",
"$",
"root",
",",
"$",
"fields",
")",
";",
"}"
]
| Implements the "Evaluating operations" section of the spec. | [
"Implements",
"the",
"Evaluating",
"operations",
"section",
"of",
"the",
"spec",
"."
]
| train | https://github.com/fubhy/graphql-php/blob/c1de2233c731ca29e5c5db4c43f3b9db36478c83/src/Executor/Executor.php#L130-L139 |
fubhy/graphql-php | src/Executor/Executor.php | Executor.getOperationRootType | protected static function getOperationRootType(Schema $schema, OperationDefinition $operation)
{
switch ($operation->get('operation')) {
case 'query':
return $schema->getQueryType();
case 'mutation':
$mutationType = $schema->getMutationType();
if (!$mutationType) {
throw new \Exception('Schema is not configured for mutations.');
}
return $mutationType;
}
throw new \Exception('Can only execute queries and mutations.');
} | php | protected static function getOperationRootType(Schema $schema, OperationDefinition $operation)
{
switch ($operation->get('operation')) {
case 'query':
return $schema->getQueryType();
case 'mutation':
$mutationType = $schema->getMutationType();
if (!$mutationType) {
throw new \Exception('Schema is not configured for mutations.');
}
return $mutationType;
}
throw new \Exception('Can only execute queries and mutations.');
} | [
"protected",
"static",
"function",
"getOperationRootType",
"(",
"Schema",
"$",
"schema",
",",
"OperationDefinition",
"$",
"operation",
")",
"{",
"switch",
"(",
"$",
"operation",
"->",
"get",
"(",
"'operation'",
")",
")",
"{",
"case",
"'query'",
":",
"return",
"$",
"schema",
"->",
"getQueryType",
"(",
")",
";",
"case",
"'mutation'",
":",
"$",
"mutationType",
"=",
"$",
"schema",
"->",
"getMutationType",
"(",
")",
";",
"if",
"(",
"!",
"$",
"mutationType",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Schema is not configured for mutations.'",
")",
";",
"}",
"return",
"$",
"mutationType",
";",
"}",
"throw",
"new",
"\\",
"Exception",
"(",
"'Can only execute queries and mutations.'",
")",
";",
"}"
]
| Extracts the root type of the operation from the schema.
@param Schema $schema
@param OperationDefinition $operation
@return ObjectType
@throws \Exception | [
"Extracts",
"the",
"root",
"type",
"of",
"the",
"operation",
"from",
"the",
"schema",
"."
]
| train | https://github.com/fubhy/graphql-php/blob/c1de2233c731ca29e5c5db4c43f3b9db36478c83/src/Executor/Executor.php#L152-L167 |
fubhy/graphql-php | src/Executor/Executor.php | Executor.executeFieldsSerially | protected static function executeFieldsSerially(ExecutionContext $context, ObjectType $parent, $source, $fields)
{
$results = [];
foreach ($fields as $response => $asts) {
$result = self::resolveField($context, $parent, $source, $asts);
if ($result !== self::$UNDEFINED) {
// Undefined means that field is not defined in schema.
$results[$response] = $result;
}
}
return $results;
} | php | protected static function executeFieldsSerially(ExecutionContext $context, ObjectType $parent, $source, $fields)
{
$results = [];
foreach ($fields as $response => $asts) {
$result = self::resolveField($context, $parent, $source, $asts);
if ($result !== self::$UNDEFINED) {
// Undefined means that field is not defined in schema.
$results[$response] = $result;
}
}
return $results;
} | [
"protected",
"static",
"function",
"executeFieldsSerially",
"(",
"ExecutionContext",
"$",
"context",
",",
"ObjectType",
"$",
"parent",
",",
"$",
"source",
",",
"$",
"fields",
")",
"{",
"$",
"results",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"response",
"=>",
"$",
"asts",
")",
"{",
"$",
"result",
"=",
"self",
"::",
"resolveField",
"(",
"$",
"context",
",",
"$",
"parent",
",",
"$",
"source",
",",
"$",
"asts",
")",
";",
"if",
"(",
"$",
"result",
"!==",
"self",
"::",
"$",
"UNDEFINED",
")",
"{",
"// Undefined means that field is not defined in schema.",
"$",
"results",
"[",
"$",
"response",
"]",
"=",
"$",
"result",
";",
"}",
"}",
"return",
"$",
"results",
";",
"}"
]
| Implements the "Evaluating selection sets" section of the spec for "write" mode. | [
"Implements",
"the",
"Evaluating",
"selection",
"sets",
"section",
"of",
"the",
"spec",
"for",
"write",
"mode",
"."
]
| train | https://github.com/fubhy/graphql-php/blob/c1de2233c731ca29e5c5db4c43f3b9db36478c83/src/Executor/Executor.php#L172-L185 |
fubhy/graphql-php | src/Executor/Executor.php | Executor.executeFields | protected static function executeFields(ExecutionContext $context, ObjectType $parent, $source, $fields)
{
return self::executeFieldsSerially($context, $parent, $source, $fields);
} | php | protected static function executeFields(ExecutionContext $context, ObjectType $parent, $source, $fields)
{
return self::executeFieldsSerially($context, $parent, $source, $fields);
} | [
"protected",
"static",
"function",
"executeFields",
"(",
"ExecutionContext",
"$",
"context",
",",
"ObjectType",
"$",
"parent",
",",
"$",
"source",
",",
"$",
"fields",
")",
"{",
"return",
"self",
"::",
"executeFieldsSerially",
"(",
"$",
"context",
",",
"$",
"parent",
",",
"$",
"source",
",",
"$",
"fields",
")",
";",
"}"
]
| Implements the "Evaluating selection sets" section of the spec for "read" mode.
@param ExecutionContext $context
@param ObjectType $parent
@param $source
@param $fields
@return array | [
"Implements",
"the",
"Evaluating",
"selection",
"sets",
"section",
"of",
"the",
"spec",
"for",
"read",
"mode",
"."
]
| train | https://github.com/fubhy/graphql-php/blob/c1de2233c731ca29e5c5db4c43f3b9db36478c83/src/Executor/Executor.php#L197-L200 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.