repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_OODB.batch | public function batch( $type, $ids ) {
if (!$ids) return array();
$collection = array();
try {
$rows = $this->writer->selectRecord($type,array('id'=>$ids));
}catch(RedBean_Exception_SQL $e) {
if (!$this->writer->sqlStateIn($e->getSQLState(),
array(
RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN,
RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_TABLE)
)) throw $e;
$rows = false;
}
$this->stash = array();
if (!$rows) return array();
foreach($rows as $row) {
$this->stash[$row['id']] = $row;
}
foreach($ids as $id) {
$collection[ $id ] = $this->load( $type, $id );
}
$this->stash = NULL;
return $collection;
} | php | public function batch( $type, $ids ) {
if (!$ids) return array();
$collection = array();
try {
$rows = $this->writer->selectRecord($type,array('id'=>$ids));
}catch(RedBean_Exception_SQL $e) {
if (!$this->writer->sqlStateIn($e->getSQLState(),
array(
RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN,
RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_TABLE)
)) throw $e;
$rows = false;
}
$this->stash = array();
if (!$rows) return array();
foreach($rows as $row) {
$this->stash[$row['id']] = $row;
}
foreach($ids as $id) {
$collection[ $id ] = $this->load( $type, $id );
}
$this->stash = NULL;
return $collection;
} | [
"public",
"function",
"batch",
"(",
"$",
"type",
",",
"$",
"ids",
")",
"{",
"if",
"(",
"!",
"$",
"ids",
")",
"return",
"array",
"(",
")",
";",
"$",
"collection",
"=",
"array",
"(",
")",
";",
"try",
"{",
"$",
"rows",
"=",
"$",
"this",
"->",
"w... | Returns an array of beans. Pass a type and a series of ids and
this method will bring you the correspondig beans.
important note: Because this method loads beans using the load()
function (but faster) it will return empty beans with ID 0 for
every bean that could not be located. The resulting beans will have the
passed IDs as their keys.
@param string $type type of beans
@param array $ids ids to load
@return array $beans resulting beans (may include empty ones) | [
"Returns",
"an",
"array",
"of",
"beans",
".",
"Pass",
"a",
"type",
"and",
"a",
"series",
"of",
"ids",
"and",
"this",
"method",
"will",
"bring",
"you",
"the",
"correspondig",
"beans",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L5761-L5785 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_OODB.count | public function count($type,$addSQL='',$params=array()) {
try {
return (int) $this->writer->count($type,$addSQL,$params);
}catch(RedBean_Exception_SQL $e) {
if (!$this->writer->sqlStateIn($e->getSQLState(),
array(RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_TABLE)
)) throw $e;
}
return 0;
} | php | public function count($type,$addSQL='',$params=array()) {
try {
return (int) $this->writer->count($type,$addSQL,$params);
}catch(RedBean_Exception_SQL $e) {
if (!$this->writer->sqlStateIn($e->getSQLState(),
array(RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_TABLE)
)) throw $e;
}
return 0;
} | [
"public",
"function",
"count",
"(",
"$",
"type",
",",
"$",
"addSQL",
"=",
"''",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"try",
"{",
"return",
"(",
"int",
")",
"$",
"this",
"->",
"writer",
"->",
"count",
"(",
"$",
"type",
",",
"$",... | Returns the number of beans we have in DB of a given type.
@param string $type type of bean we are looking for
@param string $addSQL additional SQL snippet
@param array $params parameters to bind to SQL
@return integer $num number of beans found | [
"Returns",
"the",
"number",
"of",
"beans",
"we",
"have",
"in",
"DB",
"of",
"a",
"given",
"type",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L5819-L5828 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_OODB.wipe | public function wipe($type) {
try {
$this->writer->wipe($type);
return true;
}catch(RedBean_Exception_SQL $e) {
if (!$this->writer->sqlStateIn($e->getSQLState(),
array(RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_TABLE)
)) throw $e;
return false;
}
} | php | public function wipe($type) {
try {
$this->writer->wipe($type);
return true;
}catch(RedBean_Exception_SQL $e) {
if (!$this->writer->sqlStateIn($e->getSQLState(),
array(RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_TABLE)
)) throw $e;
return false;
}
} | [
"public",
"function",
"wipe",
"(",
"$",
"type",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"writer",
"->",
"wipe",
"(",
"$",
"type",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"RedBean_Exception_SQL",
"$",
"e",
")",
"{",
"if",
"(",
"!",
"$... | Trash all beans of a given type.
@param string $type type
@return boolean $yesNo whether we actually did some work or not.. | [
"Trash",
"all",
"beans",
"of",
"a",
"given",
"type",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L5837-L5847 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_OODB.preload | public function preload($beans, $types) {
foreach($types as $key => $type) {
$map = array();
$field = (is_numeric($key)) ? $type : $key;
$ids = array();
foreach($beans as $bean) {
if($id = $bean->{$field.'_id'}){
$ids[$id] = $id;
if (!isset($map[$id])) $map[$id] = array();
$map[$id][] = $bean;
}
}
$parents = $this->batch($type,$ids);
foreach($parents as $parent) {
foreach($map[$parent->id] as $childBean) {
$childBean->setProperty($field,$parent);
}
}
}
} | php | public function preload($beans, $types) {
foreach($types as $key => $type) {
$map = array();
$field = (is_numeric($key)) ? $type : $key;
$ids = array();
foreach($beans as $bean) {
if($id = $bean->{$field.'_id'}){
$ids[$id] = $id;
if (!isset($map[$id])) $map[$id] = array();
$map[$id][] = $bean;
}
}
$parents = $this->batch($type,$ids);
foreach($parents as $parent) {
foreach($map[$parent->id] as $childBean) {
$childBean->setProperty($field,$parent);
}
}
}
} | [
"public",
"function",
"preload",
"(",
"$",
"beans",
",",
"$",
"types",
")",
"{",
"foreach",
"(",
"$",
"types",
"as",
"$",
"key",
"=>",
"$",
"type",
")",
"{",
"$",
"map",
"=",
"array",
"(",
")",
";",
"$",
"field",
"=",
"(",
"is_numeric",
"(",
"$... | Preloads certain properties for beans.
Understands aliases.
Usage: $redbean->preload($books,array('coauthor'=>'author'));
@param array $beans beans
@param array $types types to load | [
"Preloads",
"certain",
"properties",
"for",
"beans",
".",
"Understands",
"aliases",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L5911-L5930 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_AssociationManager.associate | public function associate($beans1, $beans2) {
$results = array();
if (!is_array($beans1)) $beans1 = array($beans1);
if (!is_array($beans2)) $beans2 = array($beans2);
foreach($beans1 as $bean1) {
foreach($beans2 as $bean2) {
$table = $this->getTable( array($bean1->getMeta('type') , $bean2->getMeta('type')) );
$bean = $this->oodb->dispense($table);
$results[] = $this->associateBeans( $bean1, $bean2, $bean );
}
}
return (count($results)>1) ? $results : reset($results);
} | php | public function associate($beans1, $beans2) {
$results = array();
if (!is_array($beans1)) $beans1 = array($beans1);
if (!is_array($beans2)) $beans2 = array($beans2);
foreach($beans1 as $bean1) {
foreach($beans2 as $bean2) {
$table = $this->getTable( array($bean1->getMeta('type') , $bean2->getMeta('type')) );
$bean = $this->oodb->dispense($table);
$results[] = $this->associateBeans( $bean1, $bean2, $bean );
}
}
return (count($results)>1) ? $results : reset($results);
} | [
"public",
"function",
"associate",
"(",
"$",
"beans1",
",",
"$",
"beans2",
")",
"{",
"$",
"results",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"beans1",
")",
")",
"$",
"beans1",
"=",
"array",
"(",
"$",
"beans1",
")",
";",... | Associates two beans with eachother using a many-to-many relation.
@param RedBean_OODBBean $bean1 bean1
@param RedBean_OODBBean $bean2 bean2 | [
"Associates",
"two",
"beans",
"with",
"eachother",
"using",
"a",
"many",
"-",
"to",
"-",
"many",
"relation",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L6103-L6115 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_AssociationManager.associateBeans | protected function associateBeans(RedBean_OODBBean $bean1, RedBean_OODBBean $bean2, RedBean_OODBBean $bean) {
$property1 = $bean1->getMeta('type') . '_id';
$property2 = $bean2->getMeta('type') . '_id';
if ($property1==$property2) $property2 = $bean2->getMeta('type').'2_id';
//add a build command for Unique Indexes
$bean->setMeta('buildcommand.unique' , array(array($property1, $property2)));
//add a build command for Single Column Index (to improve performance in case unqiue cant be used)
$indexName1 = 'index_for_'.$bean->getMeta('type').'_'.$property1;
$indexName2 = 'index_for_'.$bean->getMeta('type').'_'.$property2;
$bean->setMeta('buildcommand.indexes', array($property1=>$indexName1,$property2=>$indexName2));
$this->oodb->store($bean1);
$this->oodb->store($bean2);
$bean->setMeta("cast.$property1","id");
$bean->setMeta("cast.$property2","id");
$bean->$property1 = $bean1->id;
$bean->$property2 = $bean2->id;
try {
$id = $this->oodb->store( $bean );
//On creation, add constraints....
if (!$this->oodb->isFrozen() &&
$bean->getMeta('buildreport.flags.created')){
$bean->setMeta('buildreport.flags.created',0);
if (!$this->oodb->isFrozen())
$this->writer->addConstraint( $bean1, $bean2 );
}
$results[] = $id;
}
catch(RedBean_Exception_SQL $e) {
if (!$this->writer->sqlStateIn($e->getSQLState(),
array(
RedBean_QueryWriter::C_SQLSTATE_INTEGRITY_CONSTRAINT_VIOLATION
))) throw $e;
}
} | php | protected function associateBeans(RedBean_OODBBean $bean1, RedBean_OODBBean $bean2, RedBean_OODBBean $bean) {
$property1 = $bean1->getMeta('type') . '_id';
$property2 = $bean2->getMeta('type') . '_id';
if ($property1==$property2) $property2 = $bean2->getMeta('type').'2_id';
//add a build command for Unique Indexes
$bean->setMeta('buildcommand.unique' , array(array($property1, $property2)));
//add a build command for Single Column Index (to improve performance in case unqiue cant be used)
$indexName1 = 'index_for_'.$bean->getMeta('type').'_'.$property1;
$indexName2 = 'index_for_'.$bean->getMeta('type').'_'.$property2;
$bean->setMeta('buildcommand.indexes', array($property1=>$indexName1,$property2=>$indexName2));
$this->oodb->store($bean1);
$this->oodb->store($bean2);
$bean->setMeta("cast.$property1","id");
$bean->setMeta("cast.$property2","id");
$bean->$property1 = $bean1->id;
$bean->$property2 = $bean2->id;
try {
$id = $this->oodb->store( $bean );
//On creation, add constraints....
if (!$this->oodb->isFrozen() &&
$bean->getMeta('buildreport.flags.created')){
$bean->setMeta('buildreport.flags.created',0);
if (!$this->oodb->isFrozen())
$this->writer->addConstraint( $bean1, $bean2 );
}
$results[] = $id;
}
catch(RedBean_Exception_SQL $e) {
if (!$this->writer->sqlStateIn($e->getSQLState(),
array(
RedBean_QueryWriter::C_SQLSTATE_INTEGRITY_CONSTRAINT_VIOLATION
))) throw $e;
}
} | [
"protected",
"function",
"associateBeans",
"(",
"RedBean_OODBBean",
"$",
"bean1",
",",
"RedBean_OODBBean",
"$",
"bean2",
",",
"RedBean_OODBBean",
"$",
"bean",
")",
"{",
"$",
"property1",
"=",
"$",
"bean1",
"->",
"getMeta",
"(",
"'type'",
")",
".",
"'_id'",
"... | Associates a pair of beans. This method associates two beans, no matter
what types.Accepts a base bean that contains data for the linking record.
@param RedBean_OODBBean $bean1 first bean
@param RedBean_OODBBean $bean2 second bean
@param RedBean_OODBBean $bean base bean
@return mixed $id either the link ID or null | [
"Associates",
"a",
"pair",
"of",
"beans",
".",
"This",
"method",
"associates",
"two",
"beans",
"no",
"matter",
"what",
"types",
".",
"Accepts",
"a",
"base",
"bean",
"that",
"contains",
"data",
"for",
"the",
"linking",
"record",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L6128-L6163 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_AssociationManager.areRelated | public function areRelated(RedBean_OODBBean $bean1, RedBean_OODBBean $bean2) {
if (!$bean1->getID() || !$bean2->getID()) return false;
$table = $this->getTable( array($bean1->getMeta('type') , $bean2->getMeta('type')) );
$type = $bean1->getMeta('type');
if ($type==$bean2->getMeta('type')) {
$type .= '2';
$cross = 1;
}
else $cross = 0;
$property1 = $type.'_id';
$property2 = $bean2->getMeta('type').'_id';
$value1 = (int) $bean1->id;
$value2 = (int) $bean2->id;
try {
$rows = $this->writer->selectRecord($table,array(
$property1 => array($value1), $property2=>array($value2)),null
);
if ($cross) {
$rows2 = $this->writer->selectRecord($table,array(
$property2 => array($value1), $property1=>array($value2)),null
);
$rows = array_merge($rows,$rows2);
}
}catch(RedBean_Exception_SQL $e) {
if (!$this->writer->sqlStateIn($e->getSQLState(),
array(
RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN,
RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_TABLE)
)) throw $e;
return false;
}
return (count($rows)>0);
} | php | public function areRelated(RedBean_OODBBean $bean1, RedBean_OODBBean $bean2) {
if (!$bean1->getID() || !$bean2->getID()) return false;
$table = $this->getTable( array($bean1->getMeta('type') , $bean2->getMeta('type')) );
$type = $bean1->getMeta('type');
if ($type==$bean2->getMeta('type')) {
$type .= '2';
$cross = 1;
}
else $cross = 0;
$property1 = $type.'_id';
$property2 = $bean2->getMeta('type').'_id';
$value1 = (int) $bean1->id;
$value2 = (int) $bean2->id;
try {
$rows = $this->writer->selectRecord($table,array(
$property1 => array($value1), $property2=>array($value2)),null
);
if ($cross) {
$rows2 = $this->writer->selectRecord($table,array(
$property2 => array($value1), $property1=>array($value2)),null
);
$rows = array_merge($rows,$rows2);
}
}catch(RedBean_Exception_SQL $e) {
if (!$this->writer->sqlStateIn($e->getSQLState(),
array(
RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN,
RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_TABLE)
)) throw $e;
return false;
}
return (count($rows)>0);
} | [
"public",
"function",
"areRelated",
"(",
"RedBean_OODBBean",
"$",
"bean1",
",",
"RedBean_OODBBean",
"$",
"bean2",
")",
"{",
"if",
"(",
"!",
"$",
"bean1",
"->",
"getID",
"(",
")",
"||",
"!",
"$",
"bean2",
"->",
"getID",
"(",
")",
")",
"return",
"false",... | Given two beans this function returns TRUE if they are associated using a
many-to-many association, FALSE otherwise.
@throws RedBean_Exception_SQL
@param RedBean_OODBBean $bean1 bean
@param RedBean_OODBBean $bean2 bean
@return bool $related whether they are associated N-M | [
"Given",
"two",
"beans",
"this",
"function",
"returns",
"TRUE",
"if",
"they",
"are",
"associated",
"using",
"a",
"many",
"-",
"to",
"-",
"many",
"association",
"FALSE",
"otherwise",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L6350-L6382 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Setup.checkDSN | private static function checkDSN($dsn) {
$dsn = trim($dsn);
$dsn = strtolower($dsn);
if (
strpos($dsn, 'mysql:')!==0
&& strpos($dsn,'sqlite:')!==0
&& strpos($dsn,'pgsql:')!==0
&& strpos($dsn,'cubrid:')!==0
&& strpos($dsn,'oracle:')!==0
) {
trigger_error('Unsupported DSN');
}
else {
return true;
}
} | php | private static function checkDSN($dsn) {
$dsn = trim($dsn);
$dsn = strtolower($dsn);
if (
strpos($dsn, 'mysql:')!==0
&& strpos($dsn,'sqlite:')!==0
&& strpos($dsn,'pgsql:')!==0
&& strpos($dsn,'cubrid:')!==0
&& strpos($dsn,'oracle:')!==0
) {
trigger_error('Unsupported DSN');
}
else {
return true;
}
} | [
"private",
"static",
"function",
"checkDSN",
"(",
"$",
"dsn",
")",
"{",
"$",
"dsn",
"=",
"trim",
"(",
"$",
"dsn",
")",
";",
"$",
"dsn",
"=",
"strtolower",
"(",
"$",
"dsn",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"dsn",
",",
"'mysql:'",
")",
"!... | This method checks the DSN string. If the DSN string contains a
database name that is not supported by RedBean yet then it will
throw an exception RedBean_Exception_NotImplemented. In any other
case this method will just return boolean TRUE.
@throws RedBean_Exception_NotImplemented
@param string $dsn
@return boolean $true | [
"This",
"method",
"checks",
"the",
"DSN",
"string",
".",
"If",
"the",
"DSN",
"string",
"contains",
"a",
"database",
"name",
"that",
"is",
"not",
"supported",
"by",
"RedBean",
"yet",
"then",
"it",
"will",
"throw",
"an",
"exception",
"RedBean_Exception_NotImplem... | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L6443-L6458 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_ModelHelper.attachEventListeners | public function attachEventListeners( RedBean_Observable $observable ) {
$observable->addEventListener('update', $this );
$observable->addEventListener('open', $this );
$observable->addEventListener('delete', $this );
$observable->addEventListener('after_delete', $this );
$observable->addEventListener('after_update', $this );
$observable->addEventListener('dispense', $this );
} | php | public function attachEventListeners( RedBean_Observable $observable ) {
$observable->addEventListener('update', $this );
$observable->addEventListener('open', $this );
$observable->addEventListener('delete', $this );
$observable->addEventListener('after_delete', $this );
$observable->addEventListener('after_update', $this );
$observable->addEventListener('dispense', $this );
} | [
"public",
"function",
"attachEventListeners",
"(",
"RedBean_Observable",
"$",
"observable",
")",
"{",
"$",
"observable",
"->",
"addEventListener",
"(",
"'update'",
",",
"$",
"this",
")",
";",
"$",
"observable",
"->",
"addEventListener",
"(",
"'open'",
",",
"$",
... | Attaches the FUSE event listeners. Now the Model Helper will listen for
CRUD events. If a CRUD event occurs it will send a signal to the model
that belongs to the CRUD bean and this model will take over control from
there.
@param Observable $observable | [
"Attaches",
"the",
"FUSE",
"event",
"listeners",
".",
"Now",
"the",
"Model",
"Helper",
"will",
"listen",
"for",
"CRUD",
"events",
".",
"If",
"a",
"CRUD",
"event",
"occurs",
"it",
"will",
"send",
"a",
"signal",
"to",
"the",
"model",
"that",
"belongs",
"to... | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L6891-L6898 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_SQLHelper.get | public function get($what='') {
$what = 'get'.ucfirst($what);
$rs = $this->adapter->$what($this->sql,$this->params);
$this->clear();
return $rs;
} | php | public function get($what='') {
$what = 'get'.ucfirst($what);
$rs = $this->adapter->$what($this->sql,$this->params);
$this->clear();
return $rs;
} | [
"public",
"function",
"get",
"(",
"$",
"what",
"=",
"''",
")",
"{",
"$",
"what",
"=",
"'get'",
".",
"ucfirst",
"(",
"$",
"what",
")",
";",
"$",
"rs",
"=",
"$",
"this",
"->",
"adapter",
"->",
"$",
"what",
"(",
"$",
"this",
"->",
"sql",
",",
"$... | Executes query and returns result
@return mixed $result | [
"Executes",
"query",
"and",
"returns",
"result"
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L7011-L7016 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_TagManager.findTagByTitle | public function findTagByTitle($title) {
$beans = $this->redbean->find('tag',array('title'=>array($title)));
if ($beans) {
$bean = reset($beans);
return $bean;
}
return null;
} | php | public function findTagByTitle($title) {
$beans = $this->redbean->find('tag',array('title'=>array($title)));
if ($beans) {
$bean = reset($beans);
return $bean;
}
return null;
} | [
"public",
"function",
"findTagByTitle",
"(",
"$",
"title",
")",
"{",
"$",
"beans",
"=",
"$",
"this",
"->",
"redbean",
"->",
"find",
"(",
"'tag'",
",",
"array",
"(",
"'title'",
"=>",
"array",
"(",
"$",
"title",
")",
")",
")",
";",
"if",
"(",
"$",
... | Finds a tag bean by it's title.
@param string $title title
@return RedBean_OODBBean $bean | null | [
"Finds",
"a",
"tag",
"bean",
"by",
"it",
"s",
"title",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L7131-L7138 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_TagManager.untag | public function untag($bean,$tagList) {
if ($tagList!==false && !is_array($tagList)) $tags = explode( ",", (string)$tagList); else $tags=$tagList;
foreach($tags as $tag) {
if ($t = $this->findTagByTitle($tag)) {
$this->associationManager->unassociate( $bean, $t );
}
}
} | php | public function untag($bean,$tagList) {
if ($tagList!==false && !is_array($tagList)) $tags = explode( ",", (string)$tagList); else $tags=$tagList;
foreach($tags as $tag) {
if ($t = $this->findTagByTitle($tag)) {
$this->associationManager->unassociate( $bean, $t );
}
}
} | [
"public",
"function",
"untag",
"(",
"$",
"bean",
",",
"$",
"tagList",
")",
"{",
"if",
"(",
"$",
"tagList",
"!==",
"false",
"&&",
"!",
"is_array",
"(",
"$",
"tagList",
")",
")",
"$",
"tags",
"=",
"explode",
"(",
"\",\"",
",",
"(",
"string",
")",
"... | Part of RedBeanPHP Tagging API.
Removes all sepcified tags from the bean. The tags specified in
the second parameter will no longer be associated with the bean.
@param RedBean_OODBBean $bean tagged bean
@param array $tagList list of tags (names)
@return void | [
"Part",
"of",
"RedBeanPHP",
"Tagging",
"API",
".",
"Removes",
"all",
"sepcified",
"tags",
"from",
"the",
"bean",
".",
"The",
"tags",
"specified",
"in",
"the",
"second",
"parameter",
"will",
"no",
"longer",
"be",
"associated",
"with",
"the",
"bean",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L7176-L7183 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_TagManager.tagged | public function tagged( $beanType, $tagList ) {
if ($tagList!==false && !is_array($tagList)) $tags = explode( ",", (string)$tagList); else $tags=$tagList;
$collection = array();
$tags = $this->redbean->find('tag',array('title'=>$tags));
if (is_array($tags) && count($tags)>0) {
$collectionKeys = $this->associationManager->related($tags,$beanType);
if ($collectionKeys) {
$collection = $this->redbean->batch($beanType,$collectionKeys);
}
}
return $collection;
} | php | public function tagged( $beanType, $tagList ) {
if ($tagList!==false && !is_array($tagList)) $tags = explode( ",", (string)$tagList); else $tags=$tagList;
$collection = array();
$tags = $this->redbean->find('tag',array('title'=>$tags));
if (is_array($tags) && count($tags)>0) {
$collectionKeys = $this->associationManager->related($tags,$beanType);
if ($collectionKeys) {
$collection = $this->redbean->batch($beanType,$collectionKeys);
}
}
return $collection;
} | [
"public",
"function",
"tagged",
"(",
"$",
"beanType",
",",
"$",
"tagList",
")",
"{",
"if",
"(",
"$",
"tagList",
"!==",
"false",
"&&",
"!",
"is_array",
"(",
"$",
"tagList",
")",
")",
"$",
"tags",
"=",
"explode",
"(",
"\",\"",
",",
"(",
"string",
")"... | Part of RedBeanPHP Tagging API.
Returns all beans that have been tagged with one of the tags given.
@param $beanType type of bean you are looking for
@param $tagList list of tags to match
@return array | [
"Part",
"of",
"RedBeanPHP",
"Tagging",
"API",
".",
"Returns",
"all",
"beans",
"that",
"have",
"been",
"tagged",
"with",
"one",
"of",
"the",
"tags",
"given",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L7250-L7261 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_TagManager.taggedAll | public function taggedAll( $beanType, $tagList ) {
if ($tagList!==false && !is_array($tagList)) $tags = explode( ",", (string)$tagList); else $tags=$tagList;
$beans = array();
foreach($tags as $tag) {
$beans = $this->tagged($beanType,$tag);
if (isset($oldBeans)) $beans = array_intersect_assoc($beans,$oldBeans);
$oldBeans = $beans;
}
return $beans;
} | php | public function taggedAll( $beanType, $tagList ) {
if ($tagList!==false && !is_array($tagList)) $tags = explode( ",", (string)$tagList); else $tags=$tagList;
$beans = array();
foreach($tags as $tag) {
$beans = $this->tagged($beanType,$tag);
if (isset($oldBeans)) $beans = array_intersect_assoc($beans,$oldBeans);
$oldBeans = $beans;
}
return $beans;
} | [
"public",
"function",
"taggedAll",
"(",
"$",
"beanType",
",",
"$",
"tagList",
")",
"{",
"if",
"(",
"$",
"tagList",
"!==",
"false",
"&&",
"!",
"is_array",
"(",
"$",
"tagList",
")",
")",
"$",
"tags",
"=",
"explode",
"(",
"\",\"",
",",
"(",
"string",
... | Part of RedBeanPHP Tagging API.
Returns all beans that have been tagged with ALL of the tags given.
@param $beanType type of bean you are looking for
@param $tagList list of tags to match
@return array | [
"Part",
"of",
"RedBeanPHP",
"Tagging",
"API",
".",
"Returns",
"all",
"beans",
"that",
"have",
"been",
"tagged",
"with",
"ALL",
"of",
"the",
"tags",
"given",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L7272-L7281 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Facade.selectDatabase | public static function selectDatabase($key) {
if (self::$currentDB===$key) return false;
self::configureFacadeWithToolbox(self::$toolboxes[$key]);
self::$currentDB = $key;
return true;
} | php | public static function selectDatabase($key) {
if (self::$currentDB===$key) return false;
self::configureFacadeWithToolbox(self::$toolboxes[$key]);
self::$currentDB = $key;
return true;
} | [
"public",
"static",
"function",
"selectDatabase",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"currentDB",
"===",
"$",
"key",
")",
"return",
"false",
";",
"self",
"::",
"configureFacadeWithToolbox",
"(",
"self",
"::",
"$",
"toolboxes",
"[",
... | Selects a different database for the Facade to work with.
@param string $key Key of the database to select
@return int 1 | [
"Selects",
"a",
"different",
"database",
"for",
"the",
"Facade",
"to",
"work",
"with",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L7427-L7432 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Facade.debug | public static function debug( $tf = true, $logger = NULL ) {
if (!$logger) $logger = new RedBean_Logger_Default;
self::$adapter->getDatabase()->setDebugMode( $tf, $logger );
} | php | public static function debug( $tf = true, $logger = NULL ) {
if (!$logger) $logger = new RedBean_Logger_Default;
self::$adapter->getDatabase()->setDebugMode( $tf, $logger );
} | [
"public",
"static",
"function",
"debug",
"(",
"$",
"tf",
"=",
"true",
",",
"$",
"logger",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"$",
"logger",
")",
"$",
"logger",
"=",
"new",
"RedBean_Logger_Default",
";",
"self",
"::",
"$",
"adapter",
"->",
"getDat... | Toggles DEBUG mode.
In Debug mode all SQL that happens under the hood will
be printed to the screen or logged by provided logger.
@param boolean $tf
@param RedBean_Logger $logger | [
"Toggles",
"DEBUG",
"mode",
".",
"In",
"Debug",
"mode",
"all",
"SQL",
"that",
"happens",
"under",
"the",
"hood",
"will",
"be",
"printed",
"to",
"the",
"screen",
"or",
"logged",
"by",
"provided",
"logger",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L7443-L7446 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Facade.dispense | public static function dispense( $type, $num = 1 ) {
if (!preg_match('/^[a-z0-9]+$/',$type) && self::$strictType) throw new RedBean_Exception_Security('Invalid type: '.$type);
if ($num==1) {
return self::$redbean->dispense( $type );
}
else {
$beans = array();
for($v=0; $v<$num; $v++) $beans[] = self::$redbean->dispense( $type );
return $beans;
}
} | php | public static function dispense( $type, $num = 1 ) {
if (!preg_match('/^[a-z0-9]+$/',$type) && self::$strictType) throw new RedBean_Exception_Security('Invalid type: '.$type);
if ($num==1) {
return self::$redbean->dispense( $type );
}
else {
$beans = array();
for($v=0; $v<$num; $v++) $beans[] = self::$redbean->dispense( $type );
return $beans;
}
} | [
"public",
"static",
"function",
"dispense",
"(",
"$",
"type",
",",
"$",
"num",
"=",
"1",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"'/^[a-z0-9]+$/'",
",",
"$",
"type",
")",
"&&",
"self",
"::",
"$",
"strictType",
")",
"throw",
"new",
"RedBean_Excepti... | Dispenses a new RedBean OODB Bean for use with
the rest of the methods.
@param string $type type
@param integer $number number of beans to dispense
@return array $oneOrMoreBeans | [
"Dispenses",
"a",
"new",
"RedBean",
"OODB",
"Bean",
"for",
"use",
"with",
"the",
"rest",
"of",
"the",
"methods",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L7508-L7518 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Facade.findOrDispense | public static function findOrDispense( $type, $sql, $values ) {
$foundBeans = self::find($type,$sql,$values);
if (count($foundBeans)==0) return array(self::dispense($type)); else return $foundBeans;
} | php | public static function findOrDispense( $type, $sql, $values ) {
$foundBeans = self::find($type,$sql,$values);
if (count($foundBeans)==0) return array(self::dispense($type)); else return $foundBeans;
} | [
"public",
"static",
"function",
"findOrDispense",
"(",
"$",
"type",
",",
"$",
"sql",
",",
"$",
"values",
")",
"{",
"$",
"foundBeans",
"=",
"self",
"::",
"find",
"(",
"$",
"type",
",",
"$",
"sql",
",",
"$",
"values",
")",
";",
"if",
"(",
"count",
... | Convience method. Tries to find beans of a certain type,
if no beans are found, it dispenses a bean of that type.
@param string $type type of bean you are looking for
@param string $sql SQL code for finding the bean
@param array $values parameters to bind to SQL
@return array $beans Contains RedBean_OODBBean instances | [
"Convience",
"method",
".",
"Tries",
"to",
"find",
"beans",
"of",
"a",
"certain",
"type",
"if",
"no",
"beans",
"are",
"found",
"it",
"dispenses",
"a",
"bean",
"of",
"that",
"type",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L7541-L7544 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Facade.relatedOne | public static function relatedOne( RedBean_OODBBean $bean, $type, $sql=null, $values=array() ) {
$beans = self::related($bean, $type, $sql, $values);
if (count($beans)==0 || !is_array($beans)) return null;
return reset( $beans );
} | php | public static function relatedOne( RedBean_OODBBean $bean, $type, $sql=null, $values=array() ) {
$beans = self::related($bean, $type, $sql, $values);
if (count($beans)==0 || !is_array($beans)) return null;
return reset( $beans );
} | [
"public",
"static",
"function",
"relatedOne",
"(",
"RedBean_OODBBean",
"$",
"bean",
",",
"$",
"type",
",",
"$",
"sql",
"=",
"null",
",",
"$",
"values",
"=",
"array",
"(",
")",
")",
"{",
"$",
"beans",
"=",
"self",
"::",
"related",
"(",
"$",
"bean",
... | Returns only single associated bean.
@param RedBean_OODBBean $bean bean provided
@param string $type type of bean you are searching for
@param string $sql SQL for extra filtering
@param array $values values to be inserted in SQL slots
@return RedBean_OODBBean $bean | [
"Returns",
"only",
"single",
"associated",
"bean",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L7641-L7645 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Facade.query | private static function query($method,$sql,$values) {
if (!self::$redbean->isFrozen()) {
try {
$rs = RedBean_Facade::$adapter->$method( $sql, $values );
}catch(RedBean_Exception_SQL $e) {
if(self::$writer->sqlStateIn($e->getSQLState(),
array(
RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN,
RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_TABLE)
)) {
return array();
}
else {
throw $e;
}
}
return $rs;
}
else {
return RedBean_Facade::$adapter->$method( $sql, $values );
}
} | php | private static function query($method,$sql,$values) {
if (!self::$redbean->isFrozen()) {
try {
$rs = RedBean_Facade::$adapter->$method( $sql, $values );
}catch(RedBean_Exception_SQL $e) {
if(self::$writer->sqlStateIn($e->getSQLState(),
array(
RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN,
RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_TABLE)
)) {
return array();
}
else {
throw $e;
}
}
return $rs;
}
else {
return RedBean_Facade::$adapter->$method( $sql, $values );
}
} | [
"private",
"static",
"function",
"query",
"(",
"$",
"method",
",",
"$",
"sql",
",",
"$",
"values",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"redbean",
"->",
"isFrozen",
"(",
")",
")",
"{",
"try",
"{",
"$",
"rs",
"=",
"RedBean_Facade",
"::",
"... | Internal Query function, executes the desired query. Used by
all facade query functions. This keeps things DRY.
@throws RedBean_Exception_SQL
@param string $method desired query method (i.e. 'cell','col','exec' etc..)
@param string $sql the sql you want to execute
@param array $values array of values to be bound to query statement
@return array $results results of query | [
"Internal",
"Query",
"function",
"executes",
"the",
"desired",
"query",
".",
"Used",
"by",
"all",
"facade",
"query",
"functions",
".",
"This",
"keeps",
"things",
"DRY",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L7897-L7918 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Facade.configureFacadeWithToolbox | public static function configureFacadeWithToolbox( RedBean_ToolBox $tb ) {
$oldTools = self::$toolbox;
self::$toolbox = $tb;
self::$writer = self::$toolbox->getWriter();
self::$adapter = self::$toolbox->getDatabaseAdapter();
self::$redbean = self::$toolbox->getRedBean();
self::$associationManager = new RedBean_AssociationManager( self::$toolbox );
self::$redbean->setAssociationManager(self::$associationManager);
self::$extAssocManager = new RedBean_AssociationManager_ExtAssociationManager( self::$toolbox );
$helper = new RedBean_ModelHelper();
$helper->attachEventListeners(self::$redbean);
self::$associationManager->addEventListener('delete', $helper );
self::$duplicationManager = new RedBean_DuplicationManager(self::$toolbox);
self::$tagManager = new RedBean_TagManager( self::$toolbox );
self::$f = new RedBean_SQLHelper(self::$adapter);
return $oldTools;
} | php | public static function configureFacadeWithToolbox( RedBean_ToolBox $tb ) {
$oldTools = self::$toolbox;
self::$toolbox = $tb;
self::$writer = self::$toolbox->getWriter();
self::$adapter = self::$toolbox->getDatabaseAdapter();
self::$redbean = self::$toolbox->getRedBean();
self::$associationManager = new RedBean_AssociationManager( self::$toolbox );
self::$redbean->setAssociationManager(self::$associationManager);
self::$extAssocManager = new RedBean_AssociationManager_ExtAssociationManager( self::$toolbox );
$helper = new RedBean_ModelHelper();
$helper->attachEventListeners(self::$redbean);
self::$associationManager->addEventListener('delete', $helper );
self::$duplicationManager = new RedBean_DuplicationManager(self::$toolbox);
self::$tagManager = new RedBean_TagManager( self::$toolbox );
self::$f = new RedBean_SQLHelper(self::$adapter);
return $oldTools;
} | [
"public",
"static",
"function",
"configureFacadeWithToolbox",
"(",
"RedBean_ToolBox",
"$",
"tb",
")",
"{",
"$",
"oldTools",
"=",
"self",
"::",
"$",
"toolbox",
";",
"self",
"::",
"$",
"toolbox",
"=",
"$",
"tb",
";",
"self",
"::",
"$",
"writer",
"=",
"self... | Configures the facade, want to have a new Writer? A new Object Database or a new
Adapter and you want it on-the-fly? Use this method to hot-swap your facade with a new
toolbox.
@param RedBean_ToolBox $tb toolbox
@return RedBean_ToolBox $tb old, rusty, previously used toolbox | [
"Configures",
"the",
"facade",
"want",
"to",
"have",
"a",
"new",
"Writer?",
"A",
"new",
"Object",
"Database",
"or",
"a",
"new",
"Adapter",
"and",
"you",
"want",
"it",
"on",
"-",
"the",
"-",
"fly?",
"Use",
"this",
"method",
"to",
"hot",
"-",
"swap",
"... | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L8146-L8162 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Facade.dispenseLabels | public static function dispenseLabels($type,$labels) {
$labelBeans = array();
foreach($labels as $label) {
$labelBean = self::dispense($type);
$labelBean->name = $label;
$labelBeans[] = $labelBean;
}
return $labelBeans;
} | php | public static function dispenseLabels($type,$labels) {
$labelBeans = array();
foreach($labels as $label) {
$labelBean = self::dispense($type);
$labelBean->name = $label;
$labelBeans[] = $labelBean;
}
return $labelBeans;
} | [
"public",
"static",
"function",
"dispenseLabels",
"(",
"$",
"type",
",",
"$",
"labels",
")",
"{",
"$",
"labelBeans",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"labels",
"as",
"$",
"label",
")",
"{",
"$",
"labelBean",
"=",
"self",
"::",
"dispe... | A label is a bean with only an id, type and name property.
This function will dispense beans for all entries in the array. The
values of the array will be assigned to the name property of each
individual bean.
@param string $type type of beans you would like to have
@param array $labels list of labels, names for each bean
@return array $bean a list of beans with type and name property | [
"A",
"label",
"is",
"a",
"bean",
"with",
"only",
"an",
"id",
"type",
"and",
"name",
"property",
".",
"This",
"function",
"will",
"dispense",
"beans",
"for",
"all",
"entries",
"in",
"the",
"array",
".",
"The",
"values",
"of",
"the",
"array",
"will",
"be... | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L8302-L8310 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Plugin_Sync.syncSchema | public static function syncSchema($database1,$database2) {
if (!isset(RedBean_Facade::$toolboxes[$database1])) throw new RedBean_Exception_Security('No database for this key: '.$database1);
if (!isset(RedBean_Facade::$toolboxes[$database2])) throw new RedBean_Exception_Security('No database for this key: '.$database2);
$db1 = RedBean_Facade::$toolboxes[$database1];
$db2 = RedBean_Facade::$toolboxes[$database2];
$sync = new self;
$sync->doSync($db1, $db2);
} | php | public static function syncSchema($database1,$database2) {
if (!isset(RedBean_Facade::$toolboxes[$database1])) throw new RedBean_Exception_Security('No database for this key: '.$database1);
if (!isset(RedBean_Facade::$toolboxes[$database2])) throw new RedBean_Exception_Security('No database for this key: '.$database2);
$db1 = RedBean_Facade::$toolboxes[$database1];
$db2 = RedBean_Facade::$toolboxes[$database2];
$sync = new self;
$sync->doSync($db1, $db2);
} | [
"public",
"static",
"function",
"syncSchema",
"(",
"$",
"database1",
",",
"$",
"database2",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"RedBean_Facade",
"::",
"$",
"toolboxes",
"[",
"$",
"database1",
"]",
")",
")",
"throw",
"new",
"RedBean_Exception_Security",
... | Performs a database schema sync. For use with facade.
Instead of toolboxes this method accepts simply string keys and is static.
@param string $database1 the source database
@param string $database2 the target database | [
"Performs",
"a",
"database",
"schema",
"sync",
".",
"For",
"use",
"with",
"facade",
".",
"Instead",
"of",
"toolboxes",
"this",
"method",
"accepts",
"simply",
"string",
"keys",
"and",
"is",
"static",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L8571-L8578 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Plugin_BeanCan.handleRESTGetRequest | public function handleRESTGetRequest( $pathToResource ) {
if (!is_string($pathToResource)) return $this->resp(null,0,-32099,'IR');
$resourceInfo = explode('/',$pathToResource);
$type = $resourceInfo[0];
try {
if (count($resourceInfo) < 2) {
return $this->resp(RedBean_Facade::findAndExport($type));
}
else {
$id = (int) $resourceInfo[1];
return $this->resp(RedBean_Facade::load($type,$id)->export(),$id);
}
}
catch(Exception $e) {
return $this->resp(null,0,-32099);
}
} | php | public function handleRESTGetRequest( $pathToResource ) {
if (!is_string($pathToResource)) return $this->resp(null,0,-32099,'IR');
$resourceInfo = explode('/',$pathToResource);
$type = $resourceInfo[0];
try {
if (count($resourceInfo) < 2) {
return $this->resp(RedBean_Facade::findAndExport($type));
}
else {
$id = (int) $resourceInfo[1];
return $this->resp(RedBean_Facade::load($type,$id)->export(),$id);
}
}
catch(Exception $e) {
return $this->resp(null,0,-32099);
}
} | [
"public",
"function",
"handleRESTGetRequest",
"(",
"$",
"pathToResource",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"pathToResource",
")",
")",
"return",
"$",
"this",
"->",
"resp",
"(",
"null",
",",
"0",
",",
"-",
"32099",
",",
"'IR'",
")",
";",... | Support for RESTFul GET-requests.
Only supports very BASIC REST requests, for more functionality please use
the JSON-RPC 2 interface.
@param string $pathToResource RESTFul path to resource
@return string $json a JSON encoded response ready for sending to client | [
"Support",
"for",
"RESTFul",
"GET",
"-",
"requests",
".",
"Only",
"supports",
"very",
"BASIC",
"REST",
"requests",
"for",
"more",
"functionality",
"please",
"use",
"the",
"JSON",
"-",
"RPC",
"2",
"interface",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L8720-L8736 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Plugin_QueryLogger.grep | public function grep( $word ) {
$found = array();
foreach($this->logs as $log) {
if (strpos($log,$word)!==false) {
$found[] = $log;
}
}
return $found;
} | php | public function grep( $word ) {
$found = array();
foreach($this->logs as $log) {
if (strpos($log,$word)!==false) {
$found[] = $log;
}
}
return $found;
} | [
"public",
"function",
"grep",
"(",
"$",
"word",
")",
"{",
"$",
"found",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"logs",
"as",
"$",
"log",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"log",
",",
"$",
"word",
")",
"!==",
"f... | Searches the logs for the given word and returns the entries found in
the log container.
@param string $word word to look for
@return array $entries entries that contain the keyword | [
"Searches",
"the",
"logs",
"for",
"the",
"given",
"word",
"and",
"returns",
"the",
"entries",
"found",
"in",
"the",
"log",
"container",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L8807-L8815 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Plugin_Cache.load | public function load($type,$id) {
if (isset($this->cache[$type][$id])) {
$this->hits ++;
$bean = $this->cache[$type][$id];
}
else {
$this->misses ++;
$bean = parent::load($type,$id);
if ($bean->id) {
if (!isset($this->cache[$type])) $this->cache[$type]=array();
$this->cache[$type][$id] = $bean;
}
}
return $bean;
} | php | public function load($type,$id) {
if (isset($this->cache[$type][$id])) {
$this->hits ++;
$bean = $this->cache[$type][$id];
}
else {
$this->misses ++;
$bean = parent::load($type,$id);
if ($bean->id) {
if (!isset($this->cache[$type])) $this->cache[$type]=array();
$this->cache[$type][$id] = $bean;
}
}
return $bean;
} | [
"public",
"function",
"load",
"(",
"$",
"type",
",",
"$",
"id",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"cache",
"[",
"$",
"type",
"]",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"this",
"->",
"hits",
"++",
";",
"$",
"bean",
"="... | Loads a bean by type and id. If the bean cannot be found an
empty bean will be returned instead. This is a cached version
of the loader, if the bean has been cached it will be served
from cache, otherwise the bean will be retrieved from the database
as usual an a new cache entry will be added..
@param string $type type of bean you are looking for
@param integer $id identifier of the bean
@return RedBean_OODBBean $bean the bean object found | [
"Loads",
"a",
"bean",
"by",
"type",
"and",
"id",
".",
"If",
"the",
"bean",
"cannot",
"be",
"found",
"an",
"empty",
"bean",
"will",
"be",
"returned",
"instead",
".",
"This",
"is",
"a",
"cached",
"version",
"of",
"the",
"loader",
"if",
"the",
"bean",
"... | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L9113-L9127 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Plugin_Cache.store | public function store( $bean ) {
$id = parent::store($bean);
$type = $bean->getMeta('type');
if (!isset($this->cache[$type])) $this->cache[$type]=array();
$this->cache[$type][$id] = $bean;
return $id;
} | php | public function store( $bean ) {
$id = parent::store($bean);
$type = $bean->getMeta('type');
if (!isset($this->cache[$type])) $this->cache[$type]=array();
$this->cache[$type][$id] = $bean;
return $id;
} | [
"public",
"function",
"store",
"(",
"$",
"bean",
")",
"{",
"$",
"id",
"=",
"parent",
"::",
"store",
"(",
"$",
"bean",
")",
";",
"$",
"type",
"=",
"$",
"bean",
"->",
"getMeta",
"(",
"'type'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
... | Stores a RedBean OODBBean and caches it.
@param RedBean_OODBBean $bean the bean you want to store
@return integer $id | [
"Stores",
"a",
"RedBean",
"OODBBean",
"and",
"caches",
"it",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L9136-L9142 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Plugin_Cache.trash | public function trash( $bean ) {
$type = $bean->getMeta('type');
$id = $bean->id;
if (isset($this->cache[$type][$id])) unset($this->cache[$type][$id]);
return parent::trash($bean);
} | php | public function trash( $bean ) {
$type = $bean->getMeta('type');
$id = $bean->id;
if (isset($this->cache[$type][$id])) unset($this->cache[$type][$id]);
return parent::trash($bean);
} | [
"public",
"function",
"trash",
"(",
"$",
"bean",
")",
"{",
"$",
"type",
"=",
"$",
"bean",
"->",
"getMeta",
"(",
"'type'",
")",
";",
"$",
"id",
"=",
"$",
"bean",
"->",
"id",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"cache",
"[",
"$",
"... | Trashes a RedBean OODBBean and removes it from cache.
@param RedBean_OODBBean $bean bean
@return mixed | [
"Trashes",
"a",
"RedBean",
"OODBBean",
"and",
"removes",
"it",
"from",
"cache",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L9150-L9155 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_Plugin_Cache.flush | public function flush($type) {
if (isset($this->cache[$type])) $this->cache[$type]=array();
return $this;
} | php | public function flush($type) {
if (isset($this->cache[$type])) $this->cache[$type]=array();
return $this;
} | [
"public",
"function",
"flush",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"cache",
"[",
"$",
"type",
"]",
")",
")",
"$",
"this",
"->",
"cache",
"[",
"$",
"type",
"]",
"=",
"array",
"(",
")",
";",
"return",
"$",
"t... | Flushes the cache for a given type.
@param string $type
@return RedBean_Plugin_Cache | [
"Flushes",
"the",
"cache",
"for",
"a",
"given",
"type",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L9164-L9167 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_DuplicationManager.setTables | public function setTables($tables) {
foreach($tables as $key=>$value) {
if (is_numeric($key)) {
$this->tables[] = $value;
}
else {
$this->tables[] = $key;
$this->columns[$key] = $value;
}
}
$this->cacheTables = true;
} | php | public function setTables($tables) {
foreach($tables as $key=>$value) {
if (is_numeric($key)) {
$this->tables[] = $value;
}
else {
$this->tables[] = $key;
$this->columns[$key] = $value;
}
}
$this->cacheTables = true;
} | [
"public",
"function",
"setTables",
"(",
"$",
"tables",
")",
"{",
"foreach",
"(",
"$",
"tables",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"$",
"this",
"->",
"tables",
"[",
"]",
"=",
... | For better performance you can pass the tables in an array to this method.
If the tables are available the duplication manager will not query them so
this might be beneficial for performance.
@param array $tables | [
"For",
"better",
"performance",
"you",
"can",
"pass",
"the",
"tables",
"in",
"an",
"array",
"to",
"this",
"method",
".",
"If",
"the",
"tables",
"are",
"available",
"the",
"duplication",
"manager",
"will",
"not",
"query",
"them",
"so",
"this",
"might",
"be"... | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L9338-L9349 | train |
cloudinary/cloudinary_php | samples/PhotoAlbum/lib/rb.php | RedBean_DuplicationManager.hasSharedList | protected function hasSharedList($type,$target) {
$linkType = array($type,$target);
sort($linkType);
$linkType = implode('_',$linkType);
return (in_array($linkType,$this->tables));
} | php | protected function hasSharedList($type,$target) {
$linkType = array($type,$target);
sort($linkType);
$linkType = implode('_',$linkType);
return (in_array($linkType,$this->tables));
} | [
"protected",
"function",
"hasSharedList",
"(",
"$",
"type",
",",
"$",
"target",
")",
"{",
"$",
"linkType",
"=",
"array",
"(",
"$",
"type",
",",
"$",
"target",
")",
";",
"sort",
"(",
"$",
"linkType",
")",
";",
"$",
"linkType",
"=",
"implode",
"(",
"... | Determines whether the bea has a shared list based on
schema inspection from realtime schema or cache.
@param string $type bean type
@param string $target type of list you are looking for
@return boolean | [
"Determines",
"whether",
"the",
"bea",
"has",
"a",
"shared",
"list",
"based",
"on",
"schema",
"inspection",
"from",
"realtime",
"schema",
"or",
"cache",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/samples/PhotoAlbum/lib/rb.php#L9407-L9412 | train |
cloudinary/cloudinary_php | src/SignatureVerifier.php | SignatureVerifier.verifyNotificationSignature | public static function verifyNotificationSignature($body, $timestamp, $signature, $validFor = 7200)
{
$paramsArray = [
'body' => $body,
'timestamp' => $timestamp,
'signature' => $signature,
'validFor' => $validFor
];
self::validateParams($paramsArray, self::$NOTIFICATION_VALIDATOR_ALLOWED_TYPES);
if (time() - $timestamp > $validFor) {
return false;
}
$apiSecret = \Cloudinary::config_get('api_secret');
self::validateApiSecret($apiSecret);
$payloadToSign = $body . $timestamp;
$hmac = self::generateHmac($payloadToSign, $apiSecret);
if ($hmac !== $signature) {
return false;
}
return true;
} | php | public static function verifyNotificationSignature($body, $timestamp, $signature, $validFor = 7200)
{
$paramsArray = [
'body' => $body,
'timestamp' => $timestamp,
'signature' => $signature,
'validFor' => $validFor
];
self::validateParams($paramsArray, self::$NOTIFICATION_VALIDATOR_ALLOWED_TYPES);
if (time() - $timestamp > $validFor) {
return false;
}
$apiSecret = \Cloudinary::config_get('api_secret');
self::validateApiSecret($apiSecret);
$payloadToSign = $body . $timestamp;
$hmac = self::generateHmac($payloadToSign, $apiSecret);
if ($hmac !== $signature) {
return false;
}
return true;
} | [
"public",
"static",
"function",
"verifyNotificationSignature",
"(",
"$",
"body",
",",
"$",
"timestamp",
",",
"$",
"signature",
",",
"$",
"validFor",
"=",
"7200",
")",
"{",
"$",
"paramsArray",
"=",
"[",
"'body'",
"=>",
"$",
"body",
",",
"'timestamp'",
"=>",... | Verifies the authenticity of a notification signature
@param string $body Json of the request's body
@param int|string $timestamp Unix timestamp. Can be retrieved from the X-Cld-Timestamp header
@param string $signature Actual signature. Can be retrieved from the X-Cld-Signature header
@param int|string $validFor The desired time in seconds for considering the request valid
@return boolean
@throws \InvalidArgumentException In case a mandatory parameter is empty or of wrong type | [
"Verifies",
"the",
"authenticity",
"of",
"a",
"notification",
"signature"
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/src/SignatureVerifier.php#L42-L68 | train |
cloudinary/cloudinary_php | src/SignatureVerifier.php | SignatureVerifier.verifyApiResponseSignature | public static function verifyApiResponseSignature($publicId, $version, $signature)
{
$paramsArray = ['publicId' => $publicId, 'version' => $version, 'signature' => $signature];
self::validateParams($paramsArray, self::$API_RESPONSE_VALIDATOR_ALLOWED_TYPES);
$apiSecret = \Cloudinary::config_get('api_secret');
self::validateApiSecret($apiSecret);
$payloadToSign = 'public_id=' . $publicId . '&version=' . $version;
$hmac = self::generateHmac($payloadToSign, $apiSecret);
if ($hmac !== $signature) {
return false;
}
return true;
} | php | public static function verifyApiResponseSignature($publicId, $version, $signature)
{
$paramsArray = ['publicId' => $publicId, 'version' => $version, 'signature' => $signature];
self::validateParams($paramsArray, self::$API_RESPONSE_VALIDATOR_ALLOWED_TYPES);
$apiSecret = \Cloudinary::config_get('api_secret');
self::validateApiSecret($apiSecret);
$payloadToSign = 'public_id=' . $publicId . '&version=' . $version;
$hmac = self::generateHmac($payloadToSign, $apiSecret);
if ($hmac !== $signature) {
return false;
}
return true;
} | [
"public",
"static",
"function",
"verifyApiResponseSignature",
"(",
"$",
"publicId",
",",
"$",
"version",
",",
"$",
"signature",
")",
"{",
"$",
"paramsArray",
"=",
"[",
"'publicId'",
"=>",
"$",
"publicId",
",",
"'version'",
"=>",
"$",
"version",
",",
"'signat... | Verifies the authenticity of an API response signature
@param string $publicId The public id of the asset as returned in the API response
@param int|string $version The version of the asset as returned in the API response
@param string $signature Actual signature. Can be retrieved from the X-Cld-Signature header
@return boolean
@throws \InvalidArgumentException in case a mandatory parameter is empty or of wrong type | [
"Verifies",
"the",
"authenticity",
"of",
"an",
"API",
"response",
"signature"
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/src/SignatureVerifier.php#L81-L98 | train |
cloudinary/cloudinary_php | src/SignatureVerifier.php | SignatureVerifier.paramValidator | private static function paramValidator($param, $type)
{
$allowedTypes = explode('|', $type);
foreach ($allowedTypes as $allowedType) {
$validationFunction = 'is_' . $allowedType;
if ($validationFunction($param)) {
return true;
}
}
return false;
} | php | private static function paramValidator($param, $type)
{
$allowedTypes = explode('|', $type);
foreach ($allowedTypes as $allowedType) {
$validationFunction = 'is_' . $allowedType;
if ($validationFunction($param)) {
return true;
}
}
return false;
} | [
"private",
"static",
"function",
"paramValidator",
"(",
"$",
"param",
",",
"$",
"type",
")",
"{",
"$",
"allowedTypes",
"=",
"explode",
"(",
"'|'",
",",
"$",
"type",
")",
";",
"foreach",
"(",
"$",
"allowedTypes",
"as",
"$",
"allowedType",
")",
"{",
"$",... | Validates the type of a single parameter
@param mixed $param Parameter to validate
@param string $type The allowed type/s of the parameter. Pipe delimiter for multiple values
@return boolean | [
"Validates",
"the",
"type",
"of",
"a",
"single",
"parameter"
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/src/SignatureVerifier.php#L129-L141 | train |
cloudinary/cloudinary_php | src/Cache/ResponsiveBreakpointsCache.php | ResponsiveBreakpointsCache.setCacheAdapter | public function setCacheAdapter($cacheAdapter)
{
if (is_null($cacheAdapter) || ! $cacheAdapter instanceof CacheAdapter) {
return false;
}
$this->cacheAdapter = $cacheAdapter;
return true;
} | php | public function setCacheAdapter($cacheAdapter)
{
if (is_null($cacheAdapter) || ! $cacheAdapter instanceof CacheAdapter) {
return false;
}
$this->cacheAdapter = $cacheAdapter;
return true;
} | [
"public",
"function",
"setCacheAdapter",
"(",
"$",
"cacheAdapter",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"cacheAdapter",
")",
"||",
"!",
"$",
"cacheAdapter",
"instanceof",
"CacheAdapter",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"cache... | Assigns cache adapter
@param CacheAdapter $cacheAdapter The cache adapter used to store and retrieve values.
@return bool Returns true if the $cacheAdapter is valid | [
"Assigns",
"cache",
"adapter"
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/src/Cache/ResponsiveBreakpointsCache.php#L42-L51 | train |
cloudinary/cloudinary_php | src/Cache/ResponsiveBreakpointsCache.php | ResponsiveBreakpointsCache.optionsToParameters | private static function optionsToParameters($options)
{
$optionsCopy = \Cloudinary::array_copy($options);
$transformation = \Cloudinary::generate_transformation_string($optionsCopy);
$format = \Cloudinary::option_get($options, "format", "");
$type = \Cloudinary::option_get($options, "type", "upload");
$resourceType = \Cloudinary::option_get($options, "resource_type", "image");
return [$type, $resourceType, $transformation, $format];
} | php | private static function optionsToParameters($options)
{
$optionsCopy = \Cloudinary::array_copy($options);
$transformation = \Cloudinary::generate_transformation_string($optionsCopy);
$format = \Cloudinary::option_get($options, "format", "");
$type = \Cloudinary::option_get($options, "type", "upload");
$resourceType = \Cloudinary::option_get($options, "resource_type", "image");
return [$type, $resourceType, $transformation, $format];
} | [
"private",
"static",
"function",
"optionsToParameters",
"(",
"$",
"options",
")",
"{",
"$",
"optionsCopy",
"=",
"\\",
"Cloudinary",
"::",
"array_copy",
"(",
"$",
"options",
")",
";",
"$",
"transformation",
"=",
"\\",
"Cloudinary",
"::",
"generate_transformation_... | Extract the parameters required in order to calculate the key of the cache.
@param array $options Input options
@return array A list of values used to calculate the cache key. | [
"Extract",
"the",
"parameters",
"required",
"in",
"order",
"to",
"calculate",
"the",
"key",
"of",
"the",
"cache",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/src/Cache/ResponsiveBreakpointsCache.php#L70-L79 | train |
cloudinary/cloudinary_php | src/Cache/ResponsiveBreakpointsCache.php | ResponsiveBreakpointsCache.set | public function set($publicId, $options = [], $value = [])
{
if (!$this->enabled()) {
return false;
}
if (! is_array($value)) {
throw new InvalidArgumentException("An array of breakpoints is expected");
}
list($type, $resourceType, $transformation, $format) = self::optionsToParameters($options);
return $this->cacheAdapter->set($publicId, $type, $resourceType, $transformation, $format, $value);
} | php | public function set($publicId, $options = [], $value = [])
{
if (!$this->enabled()) {
return false;
}
if (! is_array($value)) {
throw new InvalidArgumentException("An array of breakpoints is expected");
}
list($type, $resourceType, $transformation, $format) = self::optionsToParameters($options);
return $this->cacheAdapter->set($publicId, $type, $resourceType, $transformation, $format, $value);
} | [
"public",
"function",
"set",
"(",
"$",
"publicId",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"value",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"enabled",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
... | Sets responsive breakpoints identified by public ID and options
@param string $publicId The public ID of the resource
@param array $options Additional options
@param array $value Array of responsive breakpoints to set
@return bool true on success or false on failure | [
"Sets",
"responsive",
"breakpoints",
"identified",
"by",
"public",
"ID",
"and",
"options"
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/src/Cache/ResponsiveBreakpointsCache.php#L109-L122 | train |
cloudinary/cloudinary_php | src/Cache/ResponsiveBreakpointsCache.php | ResponsiveBreakpointsCache.delete | public function delete($publicId, $options = [])
{
if (!$this->enabled()) {
return false;
}
list($type, $resourceType, $transformation, $format) = self::optionsToParameters($options);
return $this->cacheAdapter->delete($publicId, $type, $resourceType, $transformation, $format);
} | php | public function delete($publicId, $options = [])
{
if (!$this->enabled()) {
return false;
}
list($type, $resourceType, $transformation, $format) = self::optionsToParameters($options);
return $this->cacheAdapter->delete($publicId, $type, $resourceType, $transformation, $format);
} | [
"public",
"function",
"delete",
"(",
"$",
"publicId",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"enabled",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"list",
"(",
"$",
"type",
",",
"$",
"resourceType",... | Delete responsive breakpoints identified by public ID and options
@param string $publicId The public ID of the resource
@param array $options Additional options
@return bool true on success or false on failure | [
"Delete",
"responsive",
"breakpoints",
"identified",
"by",
"public",
"ID",
"and",
"options"
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/src/Cache/ResponsiveBreakpointsCache.php#L132-L141 | train |
cloudinary/cloudinary_php | src/HttpClient.php | HttpClient.getJSON | public function getJSON($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, \Cloudinary::userAgent());
$response = $this->execute($ch);
$curl_error = null;
if (curl_errno($ch)) {
$curl_error = curl_error($ch);
}
curl_close($ch);
if ($curl_error != null) {
throw new Error("Error in sending request to server - " . $curl_error);
}
if ($response->responseCode != 200) {
throw new Error("Server returned unexpected status code - {$response->responseCode} - {$response->body}");
}
return self::parseJSONResponse($response);
} | php | public function getJSON($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, \Cloudinary::userAgent());
$response = $this->execute($ch);
$curl_error = null;
if (curl_errno($ch)) {
$curl_error = curl_error($ch);
}
curl_close($ch);
if ($curl_error != null) {
throw new Error("Error in sending request to server - " . $curl_error);
}
if ($response->responseCode != 200) {
throw new Error("Server returned unexpected status code - {$response->responseCode} - {$response->body}");
}
return self::parseJSONResponse($response);
} | [
"public",
"function",
"getJSON",
"(",
"$",
"url",
")",
"{",
"$",
"ch",
"=",
"curl_init",
"(",
"$",
"url",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_HEADER",
",",
"false",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_CUSTOMREQUEST... | Get JSON as associative array from specified URL
@param string $url URL of the JSON
@return array Associative array that represents JSON object
@throws Error | [
"Get",
"JSON",
"as",
"associative",
"array",
"from",
"specified",
"URL"
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/src/HttpClient.php#L36-L64 | train |
cloudinary/cloudinary_php | src/HttpClient.php | HttpClient.execute | protected static function execute($ch)
{
$content = curl_exec($ch);
$result = new \stdClass;
$result->body = trim($content);
$result->responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return $result;
} | php | protected static function execute($ch)
{
$content = curl_exec($ch);
$result = new \stdClass;
$result->body = trim($content);
$result->responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return $result;
} | [
"protected",
"static",
"function",
"execute",
"(",
"$",
"ch",
")",
"{",
"$",
"content",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"$",
"result",
"=",
"new",
"\\",
"stdClass",
";",
"$",
"result",
"->",
"body",
"=",
"trim",
"(",
"$",
"content",
")"... | Executes HTTP request, parses response headers, leaves body as a string
Based on http://snipplr.com/view/17242/
@param resource $ch cURL handle
@return \stdClass Containing headers, body, responseCode properties | [
"Executes",
"HTTP",
"request",
"parses",
"response",
"headers",
"leaves",
"body",
"as",
"a",
"string"
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/src/HttpClient.php#L75-L83 | train |
cloudinary/cloudinary_php | src/HttpClient.php | HttpClient.parseJSONResponse | protected static function parseJSONResponse($response)
{
$result = json_decode($response->body, true);
if ($result == null) {
$error = json_last_error();
throw new Error(
"Error parsing server response ({$response->responseCode}) - {$response->body}. Got - {$error}"
);
}
return $result;
} | php | protected static function parseJSONResponse($response)
{
$result = json_decode($response->body, true);
if ($result == null) {
$error = json_last_error();
throw new Error(
"Error parsing server response ({$response->responseCode}) - {$response->body}. Got - {$error}"
);
}
return $result;
} | [
"protected",
"static",
"function",
"parseJSONResponse",
"(",
"$",
"response",
")",
"{",
"$",
"result",
"=",
"json_decode",
"(",
"$",
"response",
"->",
"body",
",",
"true",
")",
";",
"if",
"(",
"$",
"result",
"==",
"null",
")",
"{",
"$",
"error",
"=",
... | Parses JSON string from response body.
@param \stdClass $response Class representing response
@return mixed Decoded JSON object
@throws Error | [
"Parses",
"JSON",
"string",
"from",
"response",
"body",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/src/HttpClient.php#L94-L105 | train |
cloudinary/cloudinary_php | src/Cloudinary.php | Cloudinary.build_array_of_assoc_arrays | private static function build_array_of_assoc_arrays($value)
{
if (is_string($value)) {
$value = Cloudinary::json_decode_cb($value, 'Cloudinary::ensure_assoc');
if (is_null($value)) {
throw new InvalidArgumentException("Failed parsing JSON string value");
}
}
$value = Cloudinary::build_array($value);
if (!self::is_array_of_assoc($value)) {
throw new InvalidArgumentException("Expected an array of associative arrays");
}
return $value;
} | php | private static function build_array_of_assoc_arrays($value)
{
if (is_string($value)) {
$value = Cloudinary::json_decode_cb($value, 'Cloudinary::ensure_assoc');
if (is_null($value)) {
throw new InvalidArgumentException("Failed parsing JSON string value");
}
}
$value = Cloudinary::build_array($value);
if (!self::is_array_of_assoc($value)) {
throw new InvalidArgumentException("Expected an array of associative arrays");
}
return $value;
} | [
"private",
"static",
"function",
"build_array_of_assoc_arrays",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"Cloudinary",
"::",
"json_decode_cb",
"(",
"$",
"value",
",",
"'Cloudinary::ensure_assoc'"... | Converts a value that can be presented as an array of associative arrays.
In case top level item is not an array, it is wrapped with an array
@param array|string $value The value to be converted
Valid values examples:
- Valid assoc array: array("k" => "v", "k2"=> "v2")
- Array of assoc arrays: array(array("k" => "v"), array("k2" =>"v2"))
- JSON decodable string: '{"k": "v"}', or '[{"k": "v"}]'
Invalid values examples:
- array("not", "an", "assoc", "array")
- array(123, None),
- array(array("another", "array"))
@return array|mixed Converted(or original) array of associative arrays
@throws InvalidArgumentException in case value cannot be converted to an array of associative arrays | [
"Converts",
"a",
"value",
"that",
"can",
"be",
"presented",
"as",
"an",
"array",
"of",
"associative",
"arrays",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/src/Cloudinary.php#L225-L238 | train |
cloudinary/cloudinary_php | src/Cloudinary.php | Cloudinary.encode_array_to_json | public static function encode_array_to_json($value)
{
if (is_null($value)) {
return null;
}
$array = Cloudinary::build_array_of_assoc_arrays($value);
return Cloudinary::json_encode_cb($array, 'Cloudinary::encode_dates');
} | php | public static function encode_array_to_json($value)
{
if (is_null($value)) {
return null;
}
$array = Cloudinary::build_array_of_assoc_arrays($value);
return Cloudinary::json_encode_cb($array, 'Cloudinary::encode_dates');
} | [
"public",
"static",
"function",
"encode_array_to_json",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"array",
"=",
"Cloudinary",
"::",
"build_array_of_assoc_arrays",
"(",
"$",
"value"... | Wrapper for calling build_array_of_assoc_arrays and json_encode_array_of_assoc_arrays with null value handling.
@see Cloudinary::json_encode_array_of_assoc_arrays
@see Cloudinary::build_array_of_assoc_arrays
@param array|string $value The value to be converted
@return string Resulting JSON string
@throws InvalidArgumentException in case value cannot be converted and encoded | [
"Wrapper",
"for",
"calling",
"build_array_of_assoc_arrays",
"and",
"json_encode_array_of_assoc_arrays",
"with",
"null",
"value",
"handling",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/src/Cloudinary.php#L372-L379 | train |
cloudinary/cloudinary_php | src/Cloudinary.php | Cloudinary.array_copy | public static function array_copy($array)
{
if (!is_array($array)) {
return $array;
}
$result = array();
foreach ($array as $key => $val) {
if (is_array($val)) {
$result[$key] = self::array_copy($val);
} elseif (is_object($val)) {
$result[$key] = clone $val;
} else {
$result[$key] = $val;
}
}
return $result;
} | php | public static function array_copy($array)
{
if (!is_array($array)) {
return $array;
}
$result = array();
foreach ($array as $key => $val) {
if (is_array($val)) {
$result[$key] = self::array_copy($val);
} elseif (is_object($val)) {
$result[$key] = clone $val;
} else {
$result[$key] = $val;
}
}
return $result;
} | [
"public",
"static",
"function",
"array_copy",
"(",
"$",
"array",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"array",
")",
")",
"{",
"return",
"$",
"array",
";",
"}",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"... | Helper function for making a recursive array copy while cloning objects on the way.
@param array $array Source array
@return array Recursive copy of the source array | [
"Helper",
"function",
"for",
"making",
"a",
"recursive",
"array",
"copy",
"while",
"cloning",
"objects",
"on",
"the",
"way",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/src/Cloudinary.php#L436-L453 | train |
cloudinary/cloudinary_php | src/Cloudinary.php | Cloudinary.chain_transformations | public static function chain_transformations($options, $transformations)
{
$transformations = \Cloudinary::build_array($transformations);
// preserve url options
$url_options = self::array_subset($options, self::$URL_KEYS);
array_unshift($transformations, $options);
$url_options["transformation"] = $transformations;
return $url_options;
} | php | public static function chain_transformations($options, $transformations)
{
$transformations = \Cloudinary::build_array($transformations);
// preserve url options
$url_options = self::array_subset($options, self::$URL_KEYS);
array_unshift($transformations, $options);
$url_options["transformation"] = $transformations;
return $url_options;
} | [
"public",
"static",
"function",
"chain_transformations",
"(",
"$",
"options",
",",
"$",
"transformations",
")",
"{",
"$",
"transformations",
"=",
"\\",
"Cloudinary",
"::",
"build_array",
"(",
"$",
"transformations",
")",
";",
"// preserve url options",
"$",
"url_o... | Helper function, allows chaining transformations to the end of transformations list
The result of this function is an updated $options parameter
@param array $options Original options
@param array $transformations Transformations to chain at the end
@return array Resulting options | [
"Helper",
"function",
"allows",
"chaining",
"transformations",
"to",
"the",
"end",
"of",
"transformations",
"list"
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/src/Cloudinary.php#L711-L719 | train |
cloudinary/cloudinary_php | src/Cloudinary.php | Cloudinary.process_keyframe_interval | private static function process_keyframe_interval($keyframe_interval)
{
if (is_string($keyframe_interval) || $keyframe_interval == null) {
return $keyframe_interval;
}
if (!is_numeric($keyframe_interval)) {
throw new InvalidArgumentException("Keyframe interval should be a number or a string");
}
if ($keyframe_interval < 0) {
throw new InvalidArgumentException("Keyframe interval should be greater than zero");
}
if (is_int($keyframe_interval)) {
return $keyframe_interval . ".0";
}
return $keyframe_interval;
} | php | private static function process_keyframe_interval($keyframe_interval)
{
if (is_string($keyframe_interval) || $keyframe_interval == null) {
return $keyframe_interval;
}
if (!is_numeric($keyframe_interval)) {
throw new InvalidArgumentException("Keyframe interval should be a number or a string");
}
if ($keyframe_interval < 0) {
throw new InvalidArgumentException("Keyframe interval should be greater than zero");
}
if (is_int($keyframe_interval)) {
return $keyframe_interval . ".0";
}
return $keyframe_interval;
} | [
"private",
"static",
"function",
"process_keyframe_interval",
"(",
"$",
"keyframe_interval",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"keyframe_interval",
")",
"||",
"$",
"keyframe_interval",
"==",
"null",
")",
"{",
"return",
"$",
"keyframe_interval",
";",
"}... | Serializes keyframe_interval transformation parameter
@param float|int|string $keyframe_interval A positive number or a string
@return string | [
"Serializes",
"keyframe_interval",
"transformation",
"parameter"
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/src/Cloudinary.php#L1078-L1093 | train |
cloudinary/cloudinary_php | src/Cloudinary.php | Cloudinary.cloudinary_scaled_url | public static function cloudinary_scaled_url($source, $width, $transformation, $options)
{
if (!empty($transformation)) {
// Replace transformation parameters in $options with those in $transformation
if(is_string($transformation)){
$transformation = array("raw_transformation"=> $transformation);
}
$options = self::array_subset($options, self::$URL_KEYS);
$options = array_merge($options, $transformation);
}
$scale_transformation = ["crop" => "scale", "width" => $width];
self::check_cloudinary_field($source, $options);
self::patch_fetch_format($options);
$options = self::chain_transformations($options, $scale_transformation);
return cloudinary_url_internal($source, $options);
} | php | public static function cloudinary_scaled_url($source, $width, $transformation, $options)
{
if (!empty($transformation)) {
// Replace transformation parameters in $options with those in $transformation
if(is_string($transformation)){
$transformation = array("raw_transformation"=> $transformation);
}
$options = self::array_subset($options, self::$URL_KEYS);
$options = array_merge($options, $transformation);
}
$scale_transformation = ["crop" => "scale", "width" => $width];
self::check_cloudinary_field($source, $options);
self::patch_fetch_format($options);
$options = self::chain_transformations($options, $scale_transformation);
return cloudinary_url_internal($source, $options);
} | [
"public",
"static",
"function",
"cloudinary_scaled_url",
"(",
"$",
"source",
",",
"$",
"width",
",",
"$",
"transformation",
",",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"transformation",
")",
")",
"{",
"// Replace transformation parameters... | Generates a cloudinary url scaled to specified width.
In case transformation parameter is provided, it is used instead of transformations specified in $options
@param string $source Public ID of the resource
@param int $width Width in pixels of the srcset item
@param array|string $transformation Custom transformation that overrides transformations provided in $options
@param array $options Additional options
@return null|string | [
"Generates",
"a",
"cloudinary",
"url",
"scaled",
"to",
"specified",
"width",
"."
] | 0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd | https://github.com/cloudinary/cloudinary_php/blob/0047d3d2a97cd00c0e41fa3f8f59cab904e00bcd/src/Cloudinary.php#L1447-L1466 | train |
mollie/laravel-mollie | src/MollieConnectProvider.php | MollieConnectProvider.getRefreshTokenResponse | public function getRefreshTokenResponse($refresh_token)
{
$response = $this->getHttpClient()->post($this->getTokenUrl(), [
'headers' => ['Accept' => 'application/json'],
'form_params' => $this->getRefreshTokenFields($refresh_token),
]);
return json_decode($response->getBody(), true);
} | php | public function getRefreshTokenResponse($refresh_token)
{
$response = $this->getHttpClient()->post($this->getTokenUrl(), [
'headers' => ['Accept' => 'application/json'],
'form_params' => $this->getRefreshTokenFields($refresh_token),
]);
return json_decode($response->getBody(), true);
} | [
"public",
"function",
"getRefreshTokenResponse",
"(",
"$",
"refresh_token",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"getHttpClient",
"(",
")",
"->",
"post",
"(",
"$",
"this",
"->",
"getTokenUrl",
"(",
")",
",",
"[",
"'headers'",
"=>",
"[",
"'A... | Get the access token with a refresh token.
@param string $refresh_token
@return array | [
"Get",
"the",
"access",
"token",
"with",
"a",
"refresh",
"token",
"."
] | 15f91834c045d6139a29e833e48456345acb73a4 | https://github.com/mollie/laravel-mollie/blob/15f91834c045d6139a29e833e48456345acb73a4/src/MollieConnectProvider.php#L117-L124 | train |
mollie/laravel-mollie | src/MollieServiceProvider.php | MollieServiceProvider.extendSocialite | protected function extendSocialite()
{
if (interface_exists('Laravel\Socialite\Contracts\Factory')) {
$socialite = $this->app->make('Laravel\Socialite\Contracts\Factory');
$socialite->extend('mollie', function (Container $app) use ($socialite) {
$config = $app['config']['services.mollie'];
return $socialite->buildProvider(MollieConnectProvider::class, $config);
});
}
} | php | protected function extendSocialite()
{
if (interface_exists('Laravel\Socialite\Contracts\Factory')) {
$socialite = $this->app->make('Laravel\Socialite\Contracts\Factory');
$socialite->extend('mollie', function (Container $app) use ($socialite) {
$config = $app['config']['services.mollie'];
return $socialite->buildProvider(MollieConnectProvider::class, $config);
});
}
} | [
"protected",
"function",
"extendSocialite",
"(",
")",
"{",
"if",
"(",
"interface_exists",
"(",
"'Laravel\\Socialite\\Contracts\\Factory'",
")",
")",
"{",
"$",
"socialite",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'Laravel\\Socialite\\Contracts\\Factory'",
... | Extend the Laravel Socialite factory class, if available.
@return void | [
"Extend",
"the",
"Laravel",
"Socialite",
"factory",
"class",
"if",
"available",
"."
] | 15f91834c045d6139a29e833e48456345acb73a4 | https://github.com/mollie/laravel-mollie/blob/15f91834c045d6139a29e833e48456345acb73a4/src/MollieServiceProvider.php#L83-L94 | train |
mollie/laravel-mollie | src/MollieServiceProvider.php | MollieServiceProvider.registerApiAdapter | protected function registerApiAdapter()
{
$this->app->singleton('mollie.api', function (Container $app) {
$config = $app['config'];
return new MollieApiWrapper($config, $app['mollie.api.client']);
});
$this->app->alias('mollie.api', MollieApiWrapper::class);
} | php | protected function registerApiAdapter()
{
$this->app->singleton('mollie.api', function (Container $app) {
$config = $app['config'];
return new MollieApiWrapper($config, $app['mollie.api.client']);
});
$this->app->alias('mollie.api', MollieApiWrapper::class);
} | [
"protected",
"function",
"registerApiAdapter",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'mollie.api'",
",",
"function",
"(",
"Container",
"$",
"app",
")",
"{",
"$",
"config",
"=",
"$",
"app",
"[",
"'config'",
"]",
";",
"return",
... | Register the Mollie API adapter class.
@return void | [
"Register",
"the",
"Mollie",
"API",
"adapter",
"class",
"."
] | 15f91834c045d6139a29e833e48456345acb73a4 | https://github.com/mollie/laravel-mollie/blob/15f91834c045d6139a29e833e48456345acb73a4/src/MollieServiceProvider.php#L113-L122 | train |
mollie/laravel-mollie | src/MollieServiceProvider.php | MollieServiceProvider.registerApiClient | protected function registerApiClient()
{
$this->app->singleton('mollie.api.client', function () {
return (new MollieApiClient())->addVersionString('MollieLaravel/' . self::PACKAGE_VERSION);
});
$this->app->alias('mollie.api.client', MollieApiClient::class);
} | php | protected function registerApiClient()
{
$this->app->singleton('mollie.api.client', function () {
return (new MollieApiClient())->addVersionString('MollieLaravel/' . self::PACKAGE_VERSION);
});
$this->app->alias('mollie.api.client', MollieApiClient::class);
} | [
"protected",
"function",
"registerApiClient",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'mollie.api.client'",
",",
"function",
"(",
")",
"{",
"return",
"(",
"new",
"MollieApiClient",
"(",
")",
")",
"->",
"addVersionString",
"(",
"'Mol... | Register the Mollie API Client.
@return void | [
"Register",
"the",
"Mollie",
"API",
"Client",
"."
] | 15f91834c045d6139a29e833e48456345acb73a4 | https://github.com/mollie/laravel-mollie/blob/15f91834c045d6139a29e833e48456345acb73a4/src/MollieServiceProvider.php#L129-L136 | train |
FriendsOfDoctrine/dbal-clickhouse | src/Types/ArrayType.php | ArrayType.registerArrayTypes | public static function registerArrayTypes(AbstractPlatform $platform) : void
{
foreach (self::ARRAY_TYPES as $typeName => $className) {
if (self::hasType($typeName)) {
continue;
}
self::addType($typeName, $className);
foreach (Type::getType($typeName)->getMappedDatabaseTypes($platform) as $dbType) {
$platform->registerDoctrineTypeMapping($dbType, $typeName);
}
}
} | php | public static function registerArrayTypes(AbstractPlatform $platform) : void
{
foreach (self::ARRAY_TYPES as $typeName => $className) {
if (self::hasType($typeName)) {
continue;
}
self::addType($typeName, $className);
foreach (Type::getType($typeName)->getMappedDatabaseTypes($platform) as $dbType) {
$platform->registerDoctrineTypeMapping($dbType, $typeName);
}
}
} | [
"public",
"static",
"function",
"registerArrayTypes",
"(",
"AbstractPlatform",
"$",
"platform",
")",
":",
"void",
"{",
"foreach",
"(",
"self",
"::",
"ARRAY_TYPES",
"as",
"$",
"typeName",
"=>",
"$",
"className",
")",
"{",
"if",
"(",
"self",
"::",
"hasType",
... | Register Array types to the type map.
@throws DBALException | [
"Register",
"Array",
"types",
"to",
"the",
"type",
"map",
"."
] | e573327463091784c61b5a55212c9d29d5636457 | https://github.com/FriendsOfDoctrine/dbal-clickhouse/blob/e573327463091784c61b5a55212c9d29d5636457/src/Types/ArrayType.php#L50-L62 | train |
upwork/phystrix | library/Odesk/Phystrix/CircuitBreakerFactory.php | CircuitBreakerFactory.get | public function get($commandKey, Config $commandConfig, CommandMetrics $metrics)
{
if (!isset($this->circuitBreakersByCommand[$commandKey])) {
$circuitBreakerConfig = $commandConfig->get('circuitBreaker');
if ($circuitBreakerConfig->get('enabled')) {
$this->circuitBreakersByCommand[$commandKey] =
new CircuitBreaker($commandKey, $metrics, $commandConfig, $this->stateStorage);
} else {
$this->circuitBreakersByCommand[$commandKey] = new NoOpCircuitBreaker();
}
}
return $this->circuitBreakersByCommand[$commandKey];
} | php | public function get($commandKey, Config $commandConfig, CommandMetrics $metrics)
{
if (!isset($this->circuitBreakersByCommand[$commandKey])) {
$circuitBreakerConfig = $commandConfig->get('circuitBreaker');
if ($circuitBreakerConfig->get('enabled')) {
$this->circuitBreakersByCommand[$commandKey] =
new CircuitBreaker($commandKey, $metrics, $commandConfig, $this->stateStorage);
} else {
$this->circuitBreakersByCommand[$commandKey] = new NoOpCircuitBreaker();
}
}
return $this->circuitBreakersByCommand[$commandKey];
} | [
"public",
"function",
"get",
"(",
"$",
"commandKey",
",",
"Config",
"$",
"commandConfig",
",",
"CommandMetrics",
"$",
"metrics",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"circuitBreakersByCommand",
"[",
"$",
"commandKey",
"]",
")",
")",
... | Get circuit breaker instance by command key for given command config
@param string $commandKey
@param Config $commandConfig
@param CommandMetrics $metrics
@return CircuitBreakerInterface | [
"Get",
"circuit",
"breaker",
"instance",
"by",
"command",
"key",
"for",
"given",
"command",
"config"
] | 7085249748e89d0ea9e57b69513e765f507aceda | https://github.com/upwork/phystrix/blob/7085249748e89d0ea9e57b69513e765f507aceda/library/Odesk/Phystrix/CircuitBreakerFactory.php#L56-L69 | train |
upwork/phystrix | library/Odesk/Phystrix/CommandMetricsFactory.php | CommandMetricsFactory.get | public function get($commandKey, Config $commandConfig)
{
if (!isset($this->commandMetricsByCommand[$commandKey])) {
$metricsConfig = $commandConfig->get('metrics');
$statisticalWindow = $metricsConfig->get('rollingStatisticalWindowInMilliseconds');
$windowBuckets = $metricsConfig->get('rollingStatisticalWindowBuckets');
$snapshotInterval = $metricsConfig->get('healthSnapshotIntervalInMilliseconds');
$counter = new MetricsCounter($commandKey, $this->stateStorage, $statisticalWindow, $windowBuckets);
$this->commandMetricsByCommand[$commandKey] = new CommandMetrics($counter, $snapshotInterval);
}
return $this->commandMetricsByCommand[$commandKey];
} | php | public function get($commandKey, Config $commandConfig)
{
if (!isset($this->commandMetricsByCommand[$commandKey])) {
$metricsConfig = $commandConfig->get('metrics');
$statisticalWindow = $metricsConfig->get('rollingStatisticalWindowInMilliseconds');
$windowBuckets = $metricsConfig->get('rollingStatisticalWindowBuckets');
$snapshotInterval = $metricsConfig->get('healthSnapshotIntervalInMilliseconds');
$counter = new MetricsCounter($commandKey, $this->stateStorage, $statisticalWindow, $windowBuckets);
$this->commandMetricsByCommand[$commandKey] = new CommandMetrics($counter, $snapshotInterval);
}
return $this->commandMetricsByCommand[$commandKey];
} | [
"public",
"function",
"get",
"(",
"$",
"commandKey",
",",
"Config",
"$",
"commandConfig",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"commandMetricsByCommand",
"[",
"$",
"commandKey",
"]",
")",
")",
"{",
"$",
"metricsConfig",
"=",
"$",
... | Get command metrics instance by command key for given command config
@param string $commandKey
@param Config $commandConfig
@return CommandMetrics | [
"Get",
"command",
"metrics",
"instance",
"by",
"command",
"key",
"for",
"given",
"command",
"config"
] | 7085249748e89d0ea9e57b69513e765f507aceda | https://github.com/upwork/phystrix/blob/7085249748e89d0ea9e57b69513e765f507aceda/library/Odesk/Phystrix/CommandMetricsFactory.php#L55-L68 | train |
upwork/phystrix | library/Odesk/Phystrix/CommandFactory.php | CommandFactory.getCommand | public function getCommand($class)
{
$parameters = func_get_args();
array_shift($parameters);
$reflection = new ReflectionClass($class);
/** @var AbstractCommand $command */
$command = empty($parameters) ?
$reflection->newInstance() :
$reflection->newInstanceArgs($parameters);
$command->setCircuitBreakerFactory($this->circuitBreakerFactory);
$command->setCommandMetricsFactory($this->commandMetricsFactory);
$command->setServiceLocator($this->serviceLocator);
$command->initializeConfig($this->config);
if ($this->requestCache) {
$command->setRequestCache($this->requestCache);
}
if ($this->requestLog) {
$command->setRequestLog($this->requestLog);
}
return $command;
} | php | public function getCommand($class)
{
$parameters = func_get_args();
array_shift($parameters);
$reflection = new ReflectionClass($class);
/** @var AbstractCommand $command */
$command = empty($parameters) ?
$reflection->newInstance() :
$reflection->newInstanceArgs($parameters);
$command->setCircuitBreakerFactory($this->circuitBreakerFactory);
$command->setCommandMetricsFactory($this->commandMetricsFactory);
$command->setServiceLocator($this->serviceLocator);
$command->initializeConfig($this->config);
if ($this->requestCache) {
$command->setRequestCache($this->requestCache);
}
if ($this->requestLog) {
$command->setRequestLog($this->requestLog);
}
return $command;
} | [
"public",
"function",
"getCommand",
"(",
"$",
"class",
")",
"{",
"$",
"parameters",
"=",
"func_get_args",
"(",
")",
";",
"array_shift",
"(",
"$",
"parameters",
")",
";",
"$",
"reflection",
"=",
"new",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"/** ... | Instantiates and configures a command
@param string $class
@return AbstractCommand | [
"Instantiates",
"and",
"configures",
"a",
"command"
] | 7085249748e89d0ea9e57b69513e765f507aceda | https://github.com/upwork/phystrix/blob/7085249748e89d0ea9e57b69513e765f507aceda/library/Odesk/Phystrix/CommandFactory.php#L93-L118 | train |
upwork/phystrix | library/Odesk/Phystrix/MetricsCounter.php | MetricsCounter.add | public function add($type)
{
$this->stateStorage->incrementBucket($this->commandKey, $type, $this->getCurrentBucketIndex());
} | php | public function add($type)
{
$this->stateStorage->incrementBucket($this->commandKey, $type, $this->getCurrentBucketIndex());
} | [
"public",
"function",
"add",
"(",
"$",
"type",
")",
"{",
"$",
"this",
"->",
"stateStorage",
"->",
"incrementBucket",
"(",
"$",
"this",
"->",
"commandKey",
",",
"$",
"type",
",",
"$",
"this",
"->",
"getCurrentBucketIndex",
"(",
")",
")",
";",
"}"
] | Increase counter for given metric type
@param integer $type | [
"Increase",
"counter",
"for",
"given",
"metric",
"type"
] | 7085249748e89d0ea9e57b69513e765f507aceda | https://github.com/upwork/phystrix/blob/7085249748e89d0ea9e57b69513e765f507aceda/library/Odesk/Phystrix/MetricsCounter.php#L97-L100 | train |
upwork/phystrix | library/Odesk/Phystrix/MetricsCounter.php | MetricsCounter.get | public function get($type)
{
$sum = 0;
$now = $this->getTimeInMilliseconds();
for ($i = 0; $i < $this->rollingStatisticalWindowBuckets; $i++) {
$bucketIndex = $this->getBucketIndex($i, $now);
$sum += $this->stateStorage->getBucket($this->commandKey, $type, $bucketIndex);
}
return $sum;
} | php | public function get($type)
{
$sum = 0;
$now = $this->getTimeInMilliseconds();
for ($i = 0; $i < $this->rollingStatisticalWindowBuckets; $i++) {
$bucketIndex = $this->getBucketIndex($i, $now);
$sum += $this->stateStorage->getBucket($this->commandKey, $type, $bucketIndex);
}
return $sum;
} | [
"public",
"function",
"get",
"(",
"$",
"type",
")",
"{",
"$",
"sum",
"=",
"0",
";",
"$",
"now",
"=",
"$",
"this",
"->",
"getTimeInMilliseconds",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"rollingStati... | Calculates sum for given metric type within the statistical window
@param integer $type
@return integer | [
"Calculates",
"sum",
"for",
"given",
"metric",
"type",
"within",
"the",
"statistical",
"window"
] | 7085249748e89d0ea9e57b69513e765f507aceda | https://github.com/upwork/phystrix/blob/7085249748e89d0ea9e57b69513e765f507aceda/library/Odesk/Phystrix/MetricsCounter.php#L108-L119 | train |
upwork/phystrix | library/Odesk/Phystrix/MetricsCounter.php | MetricsCounter.getBucketIndex | private function getBucketIndex($bucketNumber, $time)
{
// Getting unique bucket index
return floor(($time - $bucketNumber * $this->bucketInMilliseconds) / $this->bucketInMilliseconds);
} | php | private function getBucketIndex($bucketNumber, $time)
{
// Getting unique bucket index
return floor(($time - $bucketNumber * $this->bucketInMilliseconds) / $this->bucketInMilliseconds);
} | [
"private",
"function",
"getBucketIndex",
"(",
"$",
"bucketNumber",
",",
"$",
"time",
")",
"{",
"// Getting unique bucket index",
"return",
"floor",
"(",
"(",
"$",
"time",
"-",
"$",
"bucketNumber",
"*",
"$",
"this",
"->",
"bucketInMilliseconds",
")",
"/",
"$",
... | Gets unique bucket index by current time and bucket sequential number in the statistical window
@param integer $bucketNumber
@param integer $time Current time in milliseconds
@return float | [
"Gets",
"unique",
"bucket",
"index",
"by",
"current",
"time",
"and",
"bucket",
"sequential",
"number",
"in",
"the",
"statistical",
"window"
] | 7085249748e89d0ea9e57b69513e765f507aceda | https://github.com/upwork/phystrix/blob/7085249748e89d0ea9e57b69513e765f507aceda/library/Odesk/Phystrix/MetricsCounter.php#L148-L152 | train |
upwork/phystrix | library/Odesk/Phystrix/MetricsCounter.php | MetricsCounter.reset | public function reset()
{
// For each type of metric, we attempt to set the counter to 0
foreach (array(self::SUCCESS, self::FAILURE, self::TIMEOUT, self::FALLBACK_SUCCESS,
self::FALLBACK_FAILURE, self::EXCEPTION_THROWN,
self::RESPONSE_FROM_CACHE) as $type) {
$now = $this->getTimeInMilliseconds();
for ($i = 0; $i < $this->rollingStatisticalWindowBuckets; $i++) {
$bucketIndex = $this->getBucketIndex($i, $now);
$this->stateStorage->resetBucket($this->commandKey, $type, $bucketIndex);
}
}
} | php | public function reset()
{
// For each type of metric, we attempt to set the counter to 0
foreach (array(self::SUCCESS, self::FAILURE, self::TIMEOUT, self::FALLBACK_SUCCESS,
self::FALLBACK_FAILURE, self::EXCEPTION_THROWN,
self::RESPONSE_FROM_CACHE) as $type) {
$now = $this->getTimeInMilliseconds();
for ($i = 0; $i < $this->rollingStatisticalWindowBuckets; $i++) {
$bucketIndex = $this->getBucketIndex($i, $now);
$this->stateStorage->resetBucket($this->commandKey, $type, $bucketIndex);
}
}
} | [
"public",
"function",
"reset",
"(",
")",
"{",
"// For each type of metric, we attempt to set the counter to 0",
"foreach",
"(",
"array",
"(",
"self",
"::",
"SUCCESS",
",",
"self",
"::",
"FAILURE",
",",
"self",
"::",
"TIMEOUT",
",",
"self",
"::",
"FALLBACK_SUCCESS",
... | Resets buckets for all metrics, within the statistical window.
This is needed for when the statistical window is larger than the sleep window (for allowSingleTest).
In such case, if we did not reset the buckets, we could possibly have bad statistics effective for the
following request, causing the circuit to open right after it was just closed.
May cause short-circuited stats to be removed from reporting, see http://goo.gl/dtHN34 | [
"Resets",
"buckets",
"for",
"all",
"metrics",
"within",
"the",
"statistical",
"window",
"."
] | 7085249748e89d0ea9e57b69513e765f507aceda | https://github.com/upwork/phystrix/blob/7085249748e89d0ea9e57b69513e765f507aceda/library/Odesk/Phystrix/MetricsCounter.php#L163-L175 | train |
upwork/phystrix | library/Odesk/Phystrix/CircuitBreaker.php | CircuitBreaker.isOpen | public function isOpen()
{
if ($this->stateStorage->isCircuitOpen($this->commandKey)) {
// if we're open we immediately return true and don't bother attempting to 'close' ourself
// as that is left to allowSingleTest and a subsequent successful test to close
return true;
}
$healthCounts = $this->metrics->getHealthCounts();
if ($healthCounts->getTotal() < $this->config->get('circuitBreaker')->get('requestVolumeThreshold')) {
// we are not past the minimum volume threshold for the statistical window
// so we'll return false immediately and not calculate anything
return false;
}
$allowedErrorPercentage = $this->config->get('circuitBreaker')->get('errorThresholdPercentage');
if ($healthCounts->getErrorPercentage() < $allowedErrorPercentage) {
return false;
} else {
$this->stateStorage->openCircuit(
$this->commandKey,
$this->config->get('circuitBreaker')->get('sleepWindowInMilliseconds')
);
return true;
}
} | php | public function isOpen()
{
if ($this->stateStorage->isCircuitOpen($this->commandKey)) {
// if we're open we immediately return true and don't bother attempting to 'close' ourself
// as that is left to allowSingleTest and a subsequent successful test to close
return true;
}
$healthCounts = $this->metrics->getHealthCounts();
if ($healthCounts->getTotal() < $this->config->get('circuitBreaker')->get('requestVolumeThreshold')) {
// we are not past the minimum volume threshold for the statistical window
// so we'll return false immediately and not calculate anything
return false;
}
$allowedErrorPercentage = $this->config->get('circuitBreaker')->get('errorThresholdPercentage');
if ($healthCounts->getErrorPercentage() < $allowedErrorPercentage) {
return false;
} else {
$this->stateStorage->openCircuit(
$this->commandKey,
$this->config->get('circuitBreaker')->get('sleepWindowInMilliseconds')
);
return true;
}
} | [
"public",
"function",
"isOpen",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"stateStorage",
"->",
"isCircuitOpen",
"(",
"$",
"this",
"->",
"commandKey",
")",
")",
"{",
"// if we're open we immediately return true and don't bother attempting to 'close' ourself",
"// as ... | Whether the circuit is open
@return boolean | [
"Whether",
"the",
"circuit",
"is",
"open"
] | 7085249748e89d0ea9e57b69513e765f507aceda | https://github.com/upwork/phystrix/blob/7085249748e89d0ea9e57b69513e765f507aceda/library/Odesk/Phystrix/CircuitBreaker.php#L81-L106 | train |
upwork/phystrix | library/Odesk/Phystrix/CircuitBreaker.php | CircuitBreaker.allowRequest | public function allowRequest()
{
if ($this->config->get('circuitBreaker')->get('forceOpen')) {
return false;
}
if ($this->config->get('circuitBreaker')->get('forceClosed')) {
return true;
}
return !$this->isOpen() || $this->allowSingleTest();
} | php | public function allowRequest()
{
if ($this->config->get('circuitBreaker')->get('forceOpen')) {
return false;
}
if ($this->config->get('circuitBreaker')->get('forceClosed')) {
return true;
}
return !$this->isOpen() || $this->allowSingleTest();
} | [
"public",
"function",
"allowRequest",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'circuitBreaker'",
")",
"->",
"get",
"(",
"'forceOpen'",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"config... | Whether the request is allowed
@return boolean | [
"Whether",
"the",
"request",
"is",
"allowed"
] | 7085249748e89d0ea9e57b69513e765f507aceda | https://github.com/upwork/phystrix/blob/7085249748e89d0ea9e57b69513e765f507aceda/library/Odesk/Phystrix/CircuitBreaker.php#L126-L136 | train |
upwork/phystrix | library/Odesk/Phystrix/CircuitBreaker.php | CircuitBreaker.markSuccess | public function markSuccess()
{
if ($this->stateStorage->isCircuitOpen($this->commandKey)) {
$this->stateStorage->closeCircuit($this->commandKey);
// may cause some stats to be removed from reporting, see http://goo.gl/dtHN34
$this->metrics->resetCounter();
}
} | php | public function markSuccess()
{
if ($this->stateStorage->isCircuitOpen($this->commandKey)) {
$this->stateStorage->closeCircuit($this->commandKey);
// may cause some stats to be removed from reporting, see http://goo.gl/dtHN34
$this->metrics->resetCounter();
}
} | [
"public",
"function",
"markSuccess",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"stateStorage",
"->",
"isCircuitOpen",
"(",
"$",
"this",
"->",
"commandKey",
")",
")",
"{",
"$",
"this",
"->",
"stateStorage",
"->",
"closeCircuit",
"(",
"$",
"this",
"->",... | Marks a successful request
@link http://goo.gl/dtHN34
@return void | [
"Marks",
"a",
"successful",
"request"
] | 7085249748e89d0ea9e57b69513e765f507aceda | https://github.com/upwork/phystrix/blob/7085249748e89d0ea9e57b69513e765f507aceda/library/Odesk/Phystrix/CircuitBreaker.php#L144-L151 | train |
upwork/phystrix | library/Odesk/Phystrix/RequestLog.php | RequestLog.getExecutedCommandsAsString | public function getExecutedCommandsAsString()
{
$output = "";
$executedCommands = $this->getExecutedCommands();
$aggregatedCommandsExecuted = array();
$aggregatedCommandExecutionTime = array();
/** @var AbstractCommand $executedCommand */
foreach ($executedCommands as $executedCommand) {
$outputForExecutedCommand = $this->getOutputForExecutedCommand($executedCommand);
if (!isset($aggregatedCommandsExecuted[$outputForExecutedCommand])) {
$aggregatedCommandsExecuted[$outputForExecutedCommand] = 0;
}
$aggregatedCommandsExecuted[$outputForExecutedCommand] = $aggregatedCommandsExecuted[$outputForExecutedCommand] + 1;
$executionTime = $executedCommand->getExecutionTimeInMilliseconds();
if ($executionTime < 0) {
$executionTime = 0;
}
if (isset($aggregatedCommandExecutionTime[$outputForExecutedCommand]) && $executionTime > 0) {
$aggregatedCommandExecutionTime[$outputForExecutedCommand] = $aggregatedCommandExecutionTime[$outputForExecutedCommand] + $executionTime;
} else {
$aggregatedCommandExecutionTime[$outputForExecutedCommand] = $executionTime;
}
}
foreach ($aggregatedCommandsExecuted as $outputForExecutedCommand => $count) {
if (!empty($output)) {
$output .= ", ";
}
$output .= "{$outputForExecutedCommand}";
$output .= "[" . $aggregatedCommandExecutionTime[$outputForExecutedCommand] . "ms]";
if ($count > 1) {
$output .= "x{$count}";
}
}
return $output;
} | php | public function getExecutedCommandsAsString()
{
$output = "";
$executedCommands = $this->getExecutedCommands();
$aggregatedCommandsExecuted = array();
$aggregatedCommandExecutionTime = array();
/** @var AbstractCommand $executedCommand */
foreach ($executedCommands as $executedCommand) {
$outputForExecutedCommand = $this->getOutputForExecutedCommand($executedCommand);
if (!isset($aggregatedCommandsExecuted[$outputForExecutedCommand])) {
$aggregatedCommandsExecuted[$outputForExecutedCommand] = 0;
}
$aggregatedCommandsExecuted[$outputForExecutedCommand] = $aggregatedCommandsExecuted[$outputForExecutedCommand] + 1;
$executionTime = $executedCommand->getExecutionTimeInMilliseconds();
if ($executionTime < 0) {
$executionTime = 0;
}
if (isset($aggregatedCommandExecutionTime[$outputForExecutedCommand]) && $executionTime > 0) {
$aggregatedCommandExecutionTime[$outputForExecutedCommand] = $aggregatedCommandExecutionTime[$outputForExecutedCommand] + $executionTime;
} else {
$aggregatedCommandExecutionTime[$outputForExecutedCommand] = $executionTime;
}
}
foreach ($aggregatedCommandsExecuted as $outputForExecutedCommand => $count) {
if (!empty($output)) {
$output .= ", ";
}
$output .= "{$outputForExecutedCommand}";
$output .= "[" . $aggregatedCommandExecutionTime[$outputForExecutedCommand] . "ms]";
if ($count > 1) {
$output .= "x{$count}";
}
}
return $output;
} | [
"public",
"function",
"getExecutedCommandsAsString",
"(",
")",
"{",
"$",
"output",
"=",
"\"\"",
";",
"$",
"executedCommands",
"=",
"$",
"this",
"->",
"getExecutedCommands",
"(",
")",
";",
"$",
"aggregatedCommandsExecuted",
"=",
"array",
"(",
")",
";",
"$",
"... | Formats the log of executed commands into a string usable for logging purposes.
Examples:
TestCommand[SUCCESS][1ms]
TestCommand[SUCCESS][1ms], TestCommand[SUCCESS, RESPONSE_FROM_CACHE][1ms]x4
TestCommand[TIMEOUT][1ms]
TestCommand[FAILURE][1ms]
TestCommand[THREAD_POOL_REJECTED][1ms]
TestCommand[THREAD_POOL_REJECTED, FALLBACK_SUCCESS][1ms]
TestCommand[FAILURE, FALLBACK_SUCCESS][1ms], TestCommand[FAILURE, FALLBACK_SUCCESS, RESPONSE_FROM_CACHE][1ms]x4
GetData[SUCCESS][1ms], PutData[SUCCESS][1ms], GetValues[SUCCESS][1ms], GetValues[SUCCESS, RESPONSE_FROM_CACHE][1ms], TestCommand[FAILURE, FALLBACK_FAILURE][1ms], TestCommand[FAILURE,
FALLBACK_FAILURE, RESPONSE_FROM_CACHE][1ms]
If a command has a multiplier such as <code>x4</code>, that means this command was executed 4 times with the same events. The time in milliseconds is the sum of the 4 executions.
For example, <code>TestCommand[SUCCESS][15ms]x4</code> represents TestCommand being executed 4 times and the sum of those 4 executions was 15ms. These 4 each executed the run() method since
<code>RESPONSE_FROM_CACHE</code> was not present as an event.
@return string request log | [
"Formats",
"the",
"log",
"of",
"executed",
"commands",
"into",
"a",
"string",
"usable",
"for",
"logging",
"purposes",
"."
] | 7085249748e89d0ea9e57b69513e765f507aceda | https://github.com/upwork/phystrix/blob/7085249748e89d0ea9e57b69513e765f507aceda/library/Odesk/Phystrix/RequestLog.php#L77-L122 | train |
upwork/phystrix | library/Odesk/Phystrix/AbstractCommand.php | AbstractCommand.initializeConfig | public function initializeConfig(Config $phystrixConfig)
{
$commandKey = $this->getCommandKey();
$config = new Config($phystrixConfig->get('default')->toArray(), true);
if ($phystrixConfig->__isset($commandKey)) {
$commandConfig = $phystrixConfig->get($commandKey);
$config->merge($commandConfig);
}
$this->config = $config;
} | php | public function initializeConfig(Config $phystrixConfig)
{
$commandKey = $this->getCommandKey();
$config = new Config($phystrixConfig->get('default')->toArray(), true);
if ($phystrixConfig->__isset($commandKey)) {
$commandConfig = $phystrixConfig->get($commandKey);
$config->merge($commandConfig);
}
$this->config = $config;
} | [
"public",
"function",
"initializeConfig",
"(",
"Config",
"$",
"phystrixConfig",
")",
"{",
"$",
"commandKey",
"=",
"$",
"this",
"->",
"getCommandKey",
"(",
")",
";",
"$",
"config",
"=",
"new",
"Config",
"(",
"$",
"phystrixConfig",
"->",
"get",
"(",
"'defaul... | Sets base command configuration from the global phystrix configuration
@param Config $phystrixConfig | [
"Sets",
"base",
"command",
"configuration",
"from",
"the",
"global",
"phystrix",
"configuration"
] | 7085249748e89d0ea9e57b69513e765f507aceda | https://github.com/upwork/phystrix/blob/7085249748e89d0ea9e57b69513e765f507aceda/library/Odesk/Phystrix/AbstractCommand.php#L169-L178 | train |
upwork/phystrix | library/Odesk/Phystrix/AbstractCommand.php | AbstractCommand.setConfig | public function setConfig(Config $config, $merge = true)
{
if ($this->config && $merge) {
$this->config->merge($config);
} else {
$this->config = $config;
}
} | php | public function setConfig(Config $config, $merge = true)
{
if ($this->config && $merge) {
$this->config->merge($config);
} else {
$this->config = $config;
}
} | [
"public",
"function",
"setConfig",
"(",
"Config",
"$",
"config",
",",
"$",
"merge",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"config",
"&&",
"$",
"merge",
")",
"{",
"$",
"this",
"->",
"config",
"->",
"merge",
"(",
"$",
"config",
")",
... | Sets configuration for the command, allows to override config in runtime
@param Config $config
@param bool $merge | [
"Sets",
"configuration",
"for",
"the",
"command",
"allows",
"to",
"override",
"config",
"in",
"runtime"
] | 7085249748e89d0ea9e57b69513e765f507aceda | https://github.com/upwork/phystrix/blob/7085249748e89d0ea9e57b69513e765f507aceda/library/Odesk/Phystrix/AbstractCommand.php#L186-L193 | train |
upwork/phystrix | library/Odesk/Phystrix/AbstractCommand.php | AbstractCommand.isRequestCacheEnabled | private function isRequestCacheEnabled()
{
if (!$this->requestCache) {
return false;
}
return $this->config->get('requestCache')->get('enabled') && $this->getCacheKey() !== null;
} | php | private function isRequestCacheEnabled()
{
if (!$this->requestCache) {
return false;
}
return $this->config->get('requestCache')->get('enabled') && $this->getCacheKey() !== null;
} | [
"private",
"function",
"isRequestCacheEnabled",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"requestCache",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'requestCache'",
")",
"->",
"get",
"(",
"... | Determines whether request caching is enabled for this command
@return bool | [
"Determines",
"whether",
"request",
"caching",
"is",
"enabled",
"for",
"this",
"command"
] | 7085249748e89d0ea9e57b69513e765f507aceda | https://github.com/upwork/phystrix/blob/7085249748e89d0ea9e57b69513e765f507aceda/library/Odesk/Phystrix/AbstractCommand.php#L200-L207 | train |
upwork/phystrix | library/Odesk/Phystrix/AbstractCommand.php | AbstractCommand.getCircuitBreaker | private function getCircuitBreaker()
{
return $this->circuitBreakerFactory->get($this->getCommandKey(), $this->config, $this->getMetrics());
} | php | private function getCircuitBreaker()
{
return $this->circuitBreakerFactory->get($this->getCommandKey(), $this->config, $this->getMetrics());
} | [
"private",
"function",
"getCircuitBreaker",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"circuitBreakerFactory",
"->",
"get",
"(",
"$",
"this",
"->",
"getCommandKey",
"(",
")",
",",
"$",
"this",
"->",
"config",
",",
"$",
"this",
"->",
"getMetrics",
"(",
... | Circuit breaker for this command key
@return CircuitBreaker | [
"Circuit",
"breaker",
"for",
"this",
"command",
"key"
] | 7085249748e89d0ea9e57b69513e765f507aceda | https://github.com/upwork/phystrix/blob/7085249748e89d0ea9e57b69513e765f507aceda/library/Odesk/Phystrix/AbstractCommand.php#L329-L332 | train |
upwork/phystrix | library/Odesk/Phystrix/AbstractCommand.php | AbstractCommand.getFallbackOrThrowException | private function getFallbackOrThrowException(Exception $originalException = null)
{
$metrics = $this->getMetrics();
$message = $originalException === null ? 'Short-circuited' : $originalException->getMessage();
try {
if ($this->config->get('fallback')->get('enabled')) {
try {
$executionResult = $this->getFallback();
$metrics->markFallbackSuccess();
$this->recordExecutionEvent(self::EVENT_FALLBACK_SUCCESS);
return $executionResult;
} catch (FallbackNotAvailableException $fallbackException) {
throw new RuntimeException(
$message . ' and no fallback available',
get_class($this),
$originalException
);
} catch (Exception $fallbackException) {
$metrics->markFallbackFailure();
$this->recordExecutionEvent(self::EVENT_FALLBACK_FAILURE);
throw new RuntimeException(
$message . ' and failed retrieving fallback',
get_class($this),
$originalException,
$fallbackException
);
}
} else {
throw new RuntimeException(
$message . ' and fallback disabled',
get_class($this),
$originalException
);
}
} catch (Exception $exception) {
// count that we are throwing an exception and re-throw it
$metrics->markExceptionThrown();
$this->recordExecutionEvent(self::EVENT_EXCEPTION_THROWN);
throw $exception;
}
} | php | private function getFallbackOrThrowException(Exception $originalException = null)
{
$metrics = $this->getMetrics();
$message = $originalException === null ? 'Short-circuited' : $originalException->getMessage();
try {
if ($this->config->get('fallback')->get('enabled')) {
try {
$executionResult = $this->getFallback();
$metrics->markFallbackSuccess();
$this->recordExecutionEvent(self::EVENT_FALLBACK_SUCCESS);
return $executionResult;
} catch (FallbackNotAvailableException $fallbackException) {
throw new RuntimeException(
$message . ' and no fallback available',
get_class($this),
$originalException
);
} catch (Exception $fallbackException) {
$metrics->markFallbackFailure();
$this->recordExecutionEvent(self::EVENT_FALLBACK_FAILURE);
throw new RuntimeException(
$message . ' and failed retrieving fallback',
get_class($this),
$originalException,
$fallbackException
);
}
} else {
throw new RuntimeException(
$message . ' and fallback disabled',
get_class($this),
$originalException
);
}
} catch (Exception $exception) {
// count that we are throwing an exception and re-throw it
$metrics->markExceptionThrown();
$this->recordExecutionEvent(self::EVENT_EXCEPTION_THROWN);
throw $exception;
}
} | [
"private",
"function",
"getFallbackOrThrowException",
"(",
"Exception",
"$",
"originalException",
"=",
"null",
")",
"{",
"$",
"metrics",
"=",
"$",
"this",
"->",
"getMetrics",
"(",
")",
";",
"$",
"message",
"=",
"$",
"originalException",
"===",
"null",
"?",
"... | Attempts to retrieve fallback by calling getFallback
@param Exception $originalException (Optional) If null, the request was short-circuited
@return mixed
@throws RuntimeException When fallback is disabled, not available for the command, or failed retrieving
@throws Exception | [
"Attempts",
"to",
"retrieve",
"fallback",
"by",
"calling",
"getFallback"
] | 7085249748e89d0ea9e57b69513e765f507aceda | https://github.com/upwork/phystrix/blob/7085249748e89d0ea9e57b69513e765f507aceda/library/Odesk/Phystrix/AbstractCommand.php#L342-L382 | train |
upwork/phystrix | library/Odesk/Phystrix/AbstractCommand.php | AbstractCommand.recordExecutedCommand | private function recordExecutedCommand()
{
if ($this->requestLog && $this->config->get('requestLog')->get('enabled')) {
$this->requestLog->addExecutedCommand($this);
}
} | php | private function recordExecutedCommand()
{
if ($this->requestLog && $this->config->get('requestLog')->get('enabled')) {
$this->requestLog->addExecutedCommand($this);
}
} | [
"private",
"function",
"recordExecutedCommand",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"requestLog",
"&&",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'requestLog'",
")",
"->",
"get",
"(",
"'enabled'",
")",
")",
"{",
"$",
"this",
"->",
"reque... | Adds reference to the command to the current request log | [
"Adds",
"reference",
"to",
"the",
"command",
"to",
"the",
"current",
"request",
"log"
] | 7085249748e89d0ea9e57b69513e765f507aceda | https://github.com/upwork/phystrix/blob/7085249748e89d0ea9e57b69513e765f507aceda/library/Odesk/Phystrix/AbstractCommand.php#L461-L466 | train |
upwork/phystrix | library/Odesk/Phystrix/RequestCache.php | RequestCache.clear | public function clear($commandKey, $cacheKey)
{
if ($this->exists($commandKey, $cacheKey)) {
unset($this->cachedResults[$commandKey][$cacheKey]);
}
} | php | public function clear($commandKey, $cacheKey)
{
if ($this->exists($commandKey, $cacheKey)) {
unset($this->cachedResults[$commandKey][$cacheKey]);
}
} | [
"public",
"function",
"clear",
"(",
"$",
"commandKey",
",",
"$",
"cacheKey",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"exists",
"(",
"$",
"commandKey",
",",
"$",
"cacheKey",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"cachedResults",
"[",
"$",
... | Clears the cache for a given cacheKey, for a given commandKey
@param string $commandKey
@param string $cacheKey | [
"Clears",
"the",
"cache",
"for",
"a",
"given",
"cacheKey",
"for",
"a",
"given",
"commandKey"
] | 7085249748e89d0ea9e57b69513e765f507aceda | https://github.com/upwork/phystrix/blob/7085249748e89d0ea9e57b69513e765f507aceda/library/Odesk/Phystrix/RequestCache.php#L51-L56 | train |
upwork/phystrix | library/Odesk/Phystrix/RequestCache.php | RequestCache.get | public function get($commandKey, $cacheKey)
{
if ($this->exists($commandKey, $cacheKey)) {
return $this->cachedResults[$commandKey][$cacheKey];
}
return null;
} | php | public function get($commandKey, $cacheKey)
{
if ($this->exists($commandKey, $cacheKey)) {
return $this->cachedResults[$commandKey][$cacheKey];
}
return null;
} | [
"public",
"function",
"get",
"(",
"$",
"commandKey",
",",
"$",
"cacheKey",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"exists",
"(",
"$",
"commandKey",
",",
"$",
"cacheKey",
")",
")",
"{",
"return",
"$",
"this",
"->",
"cachedResults",
"[",
"$",
"command... | Attempts to obtain cached result for a given command type
@param string $commandKey
@param string $cacheKey
@return mixed|null | [
"Attempts",
"to",
"obtain",
"cached",
"result",
"for",
"a",
"given",
"command",
"type"
] | 7085249748e89d0ea9e57b69513e765f507aceda | https://github.com/upwork/phystrix/blob/7085249748e89d0ea9e57b69513e765f507aceda/library/Odesk/Phystrix/RequestCache.php#L65-L72 | train |
upwork/phystrix | library/Odesk/Phystrix/RequestCache.php | RequestCache.exists | public function exists($commandKey, $cacheKey)
{
return array_key_exists($commandKey, $this->cachedResults)
&& array_key_exists($cacheKey, $this->cachedResults[$commandKey]);
} | php | public function exists($commandKey, $cacheKey)
{
return array_key_exists($commandKey, $this->cachedResults)
&& array_key_exists($cacheKey, $this->cachedResults[$commandKey]);
} | [
"public",
"function",
"exists",
"(",
"$",
"commandKey",
",",
"$",
"cacheKey",
")",
"{",
"return",
"array_key_exists",
"(",
"$",
"commandKey",
",",
"$",
"this",
"->",
"cachedResults",
")",
"&&",
"array_key_exists",
"(",
"$",
"cacheKey",
",",
"$",
"this",
"-... | Returns true, if specified cache key exists
@param string $commandKey
@param string $cacheKey
@return bool | [
"Returns",
"true",
"if",
"specified",
"cache",
"key",
"exists"
] | 7085249748e89d0ea9e57b69513e765f507aceda | https://github.com/upwork/phystrix/blob/7085249748e89d0ea9e57b69513e765f507aceda/library/Odesk/Phystrix/RequestCache.php#L93-L97 | train |
summerblue/generator | src/Makes/MakeView.php | MakeView.getSchemaArray | protected function getSchemaArray()
{
// ToDo - schema is required?
if($this->scaffoldCommandObj->option('schema') != null)
{
if ($schema = $this->scaffoldCommandObj->option('schema'))
{
return (new SchemaParser)->parse($schema);
}
}
return [];
} | php | protected function getSchemaArray()
{
// ToDo - schema is required?
if($this->scaffoldCommandObj->option('schema') != null)
{
if ($schema = $this->scaffoldCommandObj->option('schema'))
{
return (new SchemaParser)->parse($schema);
}
}
return [];
} | [
"protected",
"function",
"getSchemaArray",
"(",
")",
"{",
"// ToDo - schema is required?",
"if",
"(",
"$",
"this",
"->",
"scaffoldCommandObj",
"->",
"option",
"(",
"'schema'",
")",
"!=",
"null",
")",
"{",
"if",
"(",
"$",
"schema",
"=",
"$",
"this",
"->",
"... | Get all property of model
@return void | [
"Get",
"all",
"property",
"of",
"model"
] | 78ef029bfd33e70ce6029e4a6ae05b6983c51cd9 | https://github.com/summerblue/generator/blob/78ef029bfd33e70ce6029e4a6ae05b6983c51cd9/src/Makes/MakeView.php#L55-L67 | train |
summerblue/generator | src/Makes/MakeView.php | MakeView.start | private function start()
{
$this->scaffoldCommandObj->line("\n--- Views ---");
$viewsFiles = $this->getStubViews($this->scaffoldCommandObj->getMeta()['ui']);
$destination = $this->getDestinationViews($this->scaffoldCommandObj->getMeta()['models']);
$metas = $this->scaffoldCommandObj->getMeta();
$metas = array_merge_recursive
(
$metas,
[
'form_fields_fillable' => $this->getFields($metas['ui'], 'fillable'),
'form_fields_empty' => $this->getFields($metas['ui'], 'fillable'),
'form_fields_show' => $this->getFields($metas['ui'], 'show'),
'table_fields_header' => $this->getFields($metas['ui'], 'header'),
'table_fields_content' => $this->getFields($metas['ui'], 'content'),
]
);
foreach ($viewsFiles as $viewFileBaseName => $viewFile)
{
$viewFileName = str_replace('.stub', '', $viewFileBaseName);
$viewDestination = $destination . $viewFileName;
if ($this->files->exists($viewDestination))
{
$this->scaffoldCommandObj->comment(" x $viewFileName");
continue;
}
$stub = $this->files->get($viewFile);
$stub = $this->buildStub($metas, $stub);
$this->makeDirectory($viewDestination);
$this->files->put($viewDestination, $stub);
$this->scaffoldCommandObj->info(" + $viewFileName");
}
} | php | private function start()
{
$this->scaffoldCommandObj->line("\n--- Views ---");
$viewsFiles = $this->getStubViews($this->scaffoldCommandObj->getMeta()['ui']);
$destination = $this->getDestinationViews($this->scaffoldCommandObj->getMeta()['models']);
$metas = $this->scaffoldCommandObj->getMeta();
$metas = array_merge_recursive
(
$metas,
[
'form_fields_fillable' => $this->getFields($metas['ui'], 'fillable'),
'form_fields_empty' => $this->getFields($metas['ui'], 'fillable'),
'form_fields_show' => $this->getFields($metas['ui'], 'show'),
'table_fields_header' => $this->getFields($metas['ui'], 'header'),
'table_fields_content' => $this->getFields($metas['ui'], 'content'),
]
);
foreach ($viewsFiles as $viewFileBaseName => $viewFile)
{
$viewFileName = str_replace('.stub', '', $viewFileBaseName);
$viewDestination = $destination . $viewFileName;
if ($this->files->exists($viewDestination))
{
$this->scaffoldCommandObj->comment(" x $viewFileName");
continue;
}
$stub = $this->files->get($viewFile);
$stub = $this->buildStub($metas, $stub);
$this->makeDirectory($viewDestination);
$this->files->put($viewDestination, $stub);
$this->scaffoldCommandObj->info(" + $viewFileName");
}
} | [
"private",
"function",
"start",
"(",
")",
"{",
"$",
"this",
"->",
"scaffoldCommandObj",
"->",
"line",
"(",
"\"\\n--- Views ---\"",
")",
";",
"$",
"viewsFiles",
"=",
"$",
"this",
"->",
"getStubViews",
"(",
"$",
"this",
"->",
"scaffoldCommandObj",
"->",
"getMe... | Start make view.
@return void | [
"Start",
"make",
"view",
"."
] | 78ef029bfd33e70ce6029e4a6ae05b6983c51cd9 | https://github.com/summerblue/generator/blob/78ef029bfd33e70ce6029e4a6ae05b6983c51cd9/src/Makes/MakeView.php#L74-L112 | train |
summerblue/generator | src/Makes/MakeModel.php | MakeModel.buildFillable | protected function buildFillable(&$stub)
{
$schemaArray = [];
$schema = $this->scaffoldCommandObj->getMeta()['schema'];
if ($schema)
{
$items = (new SchemaParser)->parse($schema);
foreach($items as $item)
{
$schemaArray[] = "'{$item['name']}'";
}
$schemaArray = join(", ", $schemaArray);
}
$stub = str_replace('{{fillable}}', $schemaArray, $stub);
return $this;
} | php | protected function buildFillable(&$stub)
{
$schemaArray = [];
$schema = $this->scaffoldCommandObj->getMeta()['schema'];
if ($schema)
{
$items = (new SchemaParser)->parse($schema);
foreach($items as $item)
{
$schemaArray[] = "'{$item['name']}'";
}
$schemaArray = join(", ", $schemaArray);
}
$stub = str_replace('{{fillable}}', $schemaArray, $stub);
return $this;
} | [
"protected",
"function",
"buildFillable",
"(",
"&",
"$",
"stub",
")",
"{",
"$",
"schemaArray",
"=",
"[",
"]",
";",
"$",
"schema",
"=",
"$",
"this",
"->",
"scaffoldCommandObj",
"->",
"getMeta",
"(",
")",
"[",
"'schema'",
"]",
";",
"if",
"(",
"$",
"sch... | Build stub replacing the variable template.
@return string | [
"Build",
"stub",
"replacing",
"the",
"variable",
"template",
"."
] | 78ef029bfd33e70ce6029e4a6ae05b6983c51cd9 | https://github.com/summerblue/generator/blob/78ef029bfd33e70ce6029e4a6ae05b6983c51cd9/src/Makes/MakeModel.php#L77-L97 | train |
summerblue/generator | src/Makes/MakerTrait.php | MakerTrait.getStubFields | protected function getStubFields($ui, $type)
{
$stubsFieldsPath = $this->getStubPath() . join(DIRECTORY_SEPARATOR, ['views', $ui, 'fields', $type, '']);
if($this->existsDirectory($stubsFieldsPath))
{
$this->scaffoldCommandM->error('Stub not found');
return;
}
$stubsFieldsFiles = $this->getFilesRecursive($stubsFieldsPath);
$stubs = [];
foreach ($stubsFieldsFiles as $file)
{
$stubs[str_replace($stubsFieldsPath, '', $file)] = $this->getFile($file);
}
return $stubs;
} | php | protected function getStubFields($ui, $type)
{
$stubsFieldsPath = $this->getStubPath() . join(DIRECTORY_SEPARATOR, ['views', $ui, 'fields', $type, '']);
if($this->existsDirectory($stubsFieldsPath))
{
$this->scaffoldCommandM->error('Stub not found');
return;
}
$stubsFieldsFiles = $this->getFilesRecursive($stubsFieldsPath);
$stubs = [];
foreach ($stubsFieldsFiles as $file)
{
$stubs[str_replace($stubsFieldsPath, '', $file)] = $this->getFile($file);
}
return $stubs;
} | [
"protected",
"function",
"getStubFields",
"(",
"$",
"ui",
",",
"$",
"type",
")",
"{",
"$",
"stubsFieldsPath",
"=",
"$",
"this",
"->",
"getStubPath",
"(",
")",
".",
"join",
"(",
"DIRECTORY_SEPARATOR",
",",
"[",
"'views'",
",",
"$",
"ui",
",",
"'fields'",
... | Get fields stubs.
@return array fields | [
"Get",
"fields",
"stubs",
"."
] | 78ef029bfd33e70ce6029e4a6ae05b6983c51cd9 | https://github.com/summerblue/generator/blob/78ef029bfd33e70ce6029e4a6ae05b6983c51cd9/src/Makes/MakerTrait.php#L101-L121 | train |
summerblue/generator | src/Makes/MakerTrait.php | MakerTrait.getStubViews | protected function getStubViews($ui)
{
$viewsPath = $this->getStubPath() . join(DIRECTORY_SEPARATOR, ['views', $ui, 'pages', '']);
$files = $this->getFilesRecursive($viewsPath);
$viewFiles = [];
foreach ($files as $file)
{
$viewFiles[str_replace($viewsPath, '', $file)] = $file;
}
return $viewFiles;
} | php | protected function getStubViews($ui)
{
$viewsPath = $this->getStubPath() . join(DIRECTORY_SEPARATOR, ['views', $ui, 'pages', '']);
$files = $this->getFilesRecursive($viewsPath);
$viewFiles = [];
foreach ($files as $file)
{
$viewFiles[str_replace($viewsPath, '', $file)] = $file;
}
return $viewFiles;
} | [
"protected",
"function",
"getStubViews",
"(",
"$",
"ui",
")",
"{",
"$",
"viewsPath",
"=",
"$",
"this",
"->",
"getStubPath",
"(",
")",
".",
"join",
"(",
"DIRECTORY_SEPARATOR",
",",
"[",
"'views'",
",",
"$",
"ui",
",",
"'pages'",
",",
"''",
"]",
")",
"... | Get views stubs.
@return array views | [
"Get",
"views",
"stubs",
"."
] | 78ef029bfd33e70ce6029e4a6ae05b6983c51cd9 | https://github.com/summerblue/generator/blob/78ef029bfd33e70ce6029e4a6ae05b6983c51cd9/src/Makes/MakerTrait.php#L128-L140 | train |
summerblue/generator | src/Makes/MakerTrait.php | MakerTrait.buildStub | protected function buildStub(array $metas, &$template)
{
foreach($metas as $k => $v)
{
$template = str_replace("{{". $k ."}}", $v, $template);
}
return $template;
} | php | protected function buildStub(array $metas, &$template)
{
foreach($metas as $k => $v)
{
$template = str_replace("{{". $k ."}}", $v, $template);
}
return $template;
} | [
"protected",
"function",
"buildStub",
"(",
"array",
"$",
"metas",
",",
"&",
"$",
"template",
")",
"{",
"foreach",
"(",
"$",
"metas",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"template",
"=",
"str_replace",
"(",
"\"{{\"",
".",
"$",
"k",
".",
... | Build file replacing metas in template.
@param array $metas
@param string &$template
@return void | [
"Build",
"file",
"replacing",
"metas",
"in",
"template",
"."
] | 78ef029bfd33e70ce6029e4a6ae05b6983c51cd9 | https://github.com/summerblue/generator/blob/78ef029bfd33e70ce6029e4a6ae05b6983c51cd9/src/Makes/MakerTrait.php#L155-L163 | train |
summerblue/generator | src/Makes/MakeMigration.php | MakeMigration.start | protected function start(){
$name = 'create_'.str_plural(strtolower( $this->scaffoldCommandObj->argument('name') )).'_table';
$path = $this->getPath($name);
if ( ! $this->classExists($name))
{
$this->makeDirectory($path);
$this->files->put($path, $this->compileMigrationStub());
return $this->scaffoldCommandObj->info('+ ' . $path);
}
return $this->scaffoldCommandObj->comment('x ' . $path);
} | php | protected function start(){
$name = 'create_'.str_plural(strtolower( $this->scaffoldCommandObj->argument('name') )).'_table';
$path = $this->getPath($name);
if ( ! $this->classExists($name))
{
$this->makeDirectory($path);
$this->files->put($path, $this->compileMigrationStub());
return $this->scaffoldCommandObj->info('+ ' . $path);
}
return $this->scaffoldCommandObj->comment('x ' . $path);
} | [
"protected",
"function",
"start",
"(",
")",
"{",
"$",
"name",
"=",
"'create_'",
".",
"str_plural",
"(",
"strtolower",
"(",
"$",
"this",
"->",
"scaffoldCommandObj",
"->",
"argument",
"(",
"'name'",
")",
")",
")",
".",
"'_table'",
";",
"$",
"path",
"=",
... | Start make migration.
@return void | [
"Start",
"make",
"migration",
"."
] | 78ef029bfd33e70ce6029e4a6ae05b6983c51cd9 | https://github.com/summerblue/generator/blob/78ef029bfd33e70ce6029e4a6ae05b6983c51cd9/src/Makes/MakeMigration.php#L47-L58 | train |
summerblue/generator | src/Migrations/SyntaxBuilder.php | SyntaxBuilder.createSchemaForUpMethod | private function createSchemaForUpMethod($schema, $meta)
{
//dd($schema);
$fields = $this->constructSchema($schema);
if ($meta['action'] == 'create') {
return $this->insert($fields)->into($this->getCreateSchemaWrapper());
}
if ($meta['action'] == 'add') {
return $this->insert($fields)->into($this->getChangeSchemaWrapper());
}
if ($meta['action'] == 'remove') {
$fields = $this->constructSchema($schema, 'Drop');
return $this->insert($fields)->into($this->getChangeSchemaWrapper());
}
// Otherwise, we have no idea how to proceed.
throw new GeneratorException;
} | php | private function createSchemaForUpMethod($schema, $meta)
{
//dd($schema);
$fields = $this->constructSchema($schema);
if ($meta['action'] == 'create') {
return $this->insert($fields)->into($this->getCreateSchemaWrapper());
}
if ($meta['action'] == 'add') {
return $this->insert($fields)->into($this->getChangeSchemaWrapper());
}
if ($meta['action'] == 'remove') {
$fields = $this->constructSchema($schema, 'Drop');
return $this->insert($fields)->into($this->getChangeSchemaWrapper());
}
// Otherwise, we have no idea how to proceed.
throw new GeneratorException;
} | [
"private",
"function",
"createSchemaForUpMethod",
"(",
"$",
"schema",
",",
"$",
"meta",
")",
"{",
"//dd($schema);",
"$",
"fields",
"=",
"$",
"this",
"->",
"constructSchema",
"(",
"$",
"schema",
")",
";",
"if",
"(",
"$",
"meta",
"[",
"'action'",
"]",
"=="... | Create the schema for the "up" method.
@param string $schema
@param array $meta
@return string
@throws GeneratorException | [
"Create",
"the",
"schema",
"for",
"the",
"up",
"method",
"."
] | 78ef029bfd33e70ce6029e4a6ae05b6983c51cd9 | https://github.com/summerblue/generator/blob/78ef029bfd33e70ce6029e4a6ae05b6983c51cd9/src/Migrations/SyntaxBuilder.php#L103-L125 | train |
summerblue/generator | src/Migrations/SyntaxBuilder.php | SyntaxBuilder.createSchemaForDownMethod | private function createSchemaForDownMethod($schema, $meta)
{
// If the user created a table, then for the down
// method, we should drop it.
if ($meta['action'] == 'create') {
return sprintf("Schema::drop('%s');", $meta['table']);
}
// If the user added columns to a table, then for
// the down method, we should remove them.
if ($meta['action'] == 'add') {
$fields = $this->constructSchema($schema, 'Drop');
return $this->insert($fields)->into($this->getChangeSchemaWrapper());
}
// If the user removed columns from a table, then for
// the down method, we should add them back on.
if ($meta['action'] == 'remove') {
$fields = $this->constructSchema($schema);
return $this->insert($fields)->into($this->getChangeSchemaWrapper());
}
// Otherwise, we have no idea how to proceed.
throw new GeneratorException;
} | php | private function createSchemaForDownMethod($schema, $meta)
{
// If the user created a table, then for the down
// method, we should drop it.
if ($meta['action'] == 'create') {
return sprintf("Schema::drop('%s');", $meta['table']);
}
// If the user added columns to a table, then for
// the down method, we should remove them.
if ($meta['action'] == 'add') {
$fields = $this->constructSchema($schema, 'Drop');
return $this->insert($fields)->into($this->getChangeSchemaWrapper());
}
// If the user removed columns from a table, then for
// the down method, we should add them back on.
if ($meta['action'] == 'remove') {
$fields = $this->constructSchema($schema);
return $this->insert($fields)->into($this->getChangeSchemaWrapper());
}
// Otherwise, we have no idea how to proceed.
throw new GeneratorException;
} | [
"private",
"function",
"createSchemaForDownMethod",
"(",
"$",
"schema",
",",
"$",
"meta",
")",
"{",
"// If the user created a table, then for the down",
"// method, we should drop it.",
"if",
"(",
"$",
"meta",
"[",
"'action'",
"]",
"==",
"'create'",
")",
"{",
"return"... | Construct the syntax for a down field.
@param array $schema
@param array $meta
@return string
@throws GeneratorException | [
"Construct",
"the",
"syntax",
"for",
"a",
"down",
"field",
"."
] | 78ef029bfd33e70ce6029e4a6ae05b6983c51cd9 | https://github.com/summerblue/generator/blob/78ef029bfd33e70ce6029e4a6ae05b6983c51cd9/src/Migrations/SyntaxBuilder.php#L136-L162 | train |
summerblue/generator | src/Migrations/SyntaxBuilder.php | SyntaxBuilder.createSchemaForControllerMethod | private function createSchemaForControllerMethod($schema, $meta)
{
if (!$schema) return '';
$fields = array_map(function ($field) use ($meta) {
return $this->AddColumn($field, 'controller', $meta);
}, $schema);
return implode("\n" . str_repeat(' ', 8), $fields);
} | php | private function createSchemaForControllerMethod($schema, $meta)
{
if (!$schema) return '';
$fields = array_map(function ($field) use ($meta) {
return $this->AddColumn($field, 'controller', $meta);
}, $schema);
return implode("\n" . str_repeat(' ', 8), $fields);
} | [
"private",
"function",
"createSchemaForControllerMethod",
"(",
"$",
"schema",
",",
"$",
"meta",
")",
"{",
"if",
"(",
"!",
"$",
"schema",
")",
"return",
"''",
";",
"$",
"fields",
"=",
"array_map",
"(",
"function",
"(",
"$",
"field",
")",
"use",
"(",
"$"... | Construct the controller fields
@param $schema
@param $meta
@return string | [
"Construct",
"the",
"controller",
"fields"
] | 78ef029bfd33e70ce6029e4a6ae05b6983c51cd9 | https://github.com/summerblue/generator/blob/78ef029bfd33e70ce6029e4a6ae05b6983c51cd9/src/Migrations/SyntaxBuilder.php#L364-L376 | train |
summerblue/generator | src/Migrations/SyntaxBuilder.php | SyntaxBuilder.createSchemaForViewMethod | private function createSchemaForViewMethod($schema, $meta, $type = 'index-header')
{
if (!$schema) return '';
$fields = array_map(function ($field) use ($meta, $type) {
return $this->AddColumn($field, 'view-' . $type, $meta);
}, $schema);
// Format code
if ($type == 'index-header') {
return implode("\n" . str_repeat(' ', 24), $fields);
} else {
// index-content
return implode("\n" . str_repeat(' ', 20), $fields);
}
} | php | private function createSchemaForViewMethod($schema, $meta, $type = 'index-header')
{
if (!$schema) return '';
$fields = array_map(function ($field) use ($meta, $type) {
return $this->AddColumn($field, 'view-' . $type, $meta);
}, $schema);
// Format code
if ($type == 'index-header') {
return implode("\n" . str_repeat(' ', 24), $fields);
} else {
// index-content
return implode("\n" . str_repeat(' ', 20), $fields);
}
} | [
"private",
"function",
"createSchemaForViewMethod",
"(",
"$",
"schema",
",",
"$",
"meta",
",",
"$",
"type",
"=",
"'index-header'",
")",
"{",
"if",
"(",
"!",
"$",
"schema",
")",
"return",
"''",
";",
"$",
"fields",
"=",
"array_map",
"(",
"function",
"(",
... | Construct the view fields
@param $schema
@param $meta
@param string $type Params 'header' or 'content'
@return string | [
"Construct",
"the",
"view",
"fields"
] | 78ef029bfd33e70ce6029e4a6ae05b6983c51cd9 | https://github.com/summerblue/generator/blob/78ef029bfd33e70ce6029e4a6ae05b6983c51cd9/src/Migrations/SyntaxBuilder.php#L387-L406 | train |
summerblue/generator | src/Makes/MakeLocalization.php | MakeLocalization.start | protected function start()
{
$path = $this->getPath($this->language_code . '/'.$this->scaffoldCommandObj->getObjName('Name'), 'localization');
$this->makeDirectory($path);
if ($this->files->exists($path))
{
return $this->scaffoldCommandObj->comment('x ' . $path);
}
$this->files->put($path, $this->compileLocalizationStub());
$this->scaffoldCommandObj->info('+ ' . $path);
} | php | protected function start()
{
$path = $this->getPath($this->language_code . '/'.$this->scaffoldCommandObj->getObjName('Name'), 'localization');
$this->makeDirectory($path);
if ($this->files->exists($path))
{
return $this->scaffoldCommandObj->comment('x ' . $path);
}
$this->files->put($path, $this->compileLocalizationStub());
$this->scaffoldCommandObj->info('+ ' . $path);
} | [
"protected",
"function",
"start",
"(",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getPath",
"(",
"$",
"this",
"->",
"language_code",
".",
"'/'",
".",
"$",
"this",
"->",
"scaffoldCommandObj",
"->",
"getObjName",
"(",
"'Name'",
")",
",",
"'localizatio... | Start make seed.
@return void | [
"Start",
"make",
"seed",
"."
] | 78ef029bfd33e70ce6029e4a6ae05b6983c51cd9 | https://github.com/summerblue/generator/blob/78ef029bfd33e70ce6029e4a6ae05b6983c51cd9/src/Makes/MakeLocalization.php#L43-L56 | train |
scrivo/highlight.php | Highlight/Highlighter.php | Highlighter.registerLanguage | public static function registerLanguage($languageId, $filePath, $overwrite = false)
{
if (!isset(self::$classMap[$languageId]) || $overwrite) {
$lang = new Language($languageId, $filePath);
self::$classMap[$languageId] = $lang;
if (isset($lang->mode->aliases)) {
foreach ($lang->mode->aliases as $alias) {
self::$aliases[$alias] = $languageId;
}
}
}
return self::$classMap[$languageId];
} | php | public static function registerLanguage($languageId, $filePath, $overwrite = false)
{
if (!isset(self::$classMap[$languageId]) || $overwrite) {
$lang = new Language($languageId, $filePath);
self::$classMap[$languageId] = $lang;
if (isset($lang->mode->aliases)) {
foreach ($lang->mode->aliases as $alias) {
self::$aliases[$alias] = $languageId;
}
}
}
return self::$classMap[$languageId];
} | [
"public",
"static",
"function",
"registerLanguage",
"(",
"$",
"languageId",
",",
"$",
"filePath",
",",
"$",
"overwrite",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"classMap",
"[",
"$",
"languageId",
"]",
")",
"||",
"$",
... | Register a language definition with the Highlighter's internal language
storage. Languages are stored in a static variable, so they'll be available
across all instances. You only need to register a language once.
@param string $languageId The unique name of a language
@param string $filePath The file path to the language definition
@param bool $overwrite Overwrite language if it already exists
@return Language The object containing the definition for a language's markup | [
"Register",
"a",
"language",
"definition",
"with",
"the",
"Highlighter",
"s",
"internal",
"language",
"storage",
".",
"Languages",
"are",
"stored",
"in",
"a",
"static",
"variable",
"so",
"they",
"ll",
"be",
"available",
"across",
"all",
"instances",
".",
"You"... | 984fc9721c96bdcbae9329ae5879479878b9db4d | https://github.com/scrivo/highlight.php/blob/984fc9721c96bdcbae9329ae5879479878b9db4d/Highlight/Highlighter.php#L109-L123 | train |
scrivo/highlight.php | Highlight/Highlighter.php | Highlighter.replaceTabs | private function replaceTabs($code)
{
if ($this->options['tabReplace'] !== null) {
return str_replace("\t", $this->options['tabReplace'], $code);
}
return $code;
} | php | private function replaceTabs($code)
{
if ($this->options['tabReplace'] !== null) {
return str_replace("\t", $this->options['tabReplace'], $code);
}
return $code;
} | [
"private",
"function",
"replaceTabs",
"(",
"$",
"code",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'tabReplace'",
"]",
"!==",
"null",
")",
"{",
"return",
"str_replace",
"(",
"\"\\t\"",
",",
"$",
"this",
"->",
"options",
"[",
"'tabReplace'",... | Replace tabs for something more usable. | [
"Replace",
"tabs",
"for",
"something",
"more",
"usable",
"."
] | 984fc9721c96bdcbae9329ae5879479878b9db4d | https://github.com/scrivo/highlight.php/blob/984fc9721c96bdcbae9329ae5879479878b9db4d/Highlight/Highlighter.php#L378-L385 | train |
scrivo/highlight.php | Highlight/Highlighter.php | Highlighter.highlightAuto | public function highlightAuto($code, $languageSubset = null)
{
$res = new \stdClass();
$res->relevance = 0;
$res->value = $this->escape($code);
$res->language = "";
$scnd = clone $res;
$tmp = $languageSubset ? $languageSubset : $this->autodetectSet;
foreach ($tmp as $l) {
// don't fail if we run into a non-existent language
try {
// skip any languages that don't support auto detection
if (!$this->autoDetection($l)) {
continue;
}
$current = $this->highlight($l, $code, false);
} catch (\DomainException $e) {
continue;
}
if ($current->relevance > $scnd->relevance) {
$scnd = $current;
}
if ($current->relevance > $res->relevance) {
$scnd = $res;
$res = $current;
}
}
if ($scnd->language) {
$res->secondBest = $scnd;
}
return $res;
} | php | public function highlightAuto($code, $languageSubset = null)
{
$res = new \stdClass();
$res->relevance = 0;
$res->value = $this->escape($code);
$res->language = "";
$scnd = clone $res;
$tmp = $languageSubset ? $languageSubset : $this->autodetectSet;
foreach ($tmp as $l) {
// don't fail if we run into a non-existent language
try {
// skip any languages that don't support auto detection
if (!$this->autoDetection($l)) {
continue;
}
$current = $this->highlight($l, $code, false);
} catch (\DomainException $e) {
continue;
}
if ($current->relevance > $scnd->relevance) {
$scnd = $current;
}
if ($current->relevance > $res->relevance) {
$scnd = $res;
$res = $current;
}
}
if ($scnd->language) {
$res->secondBest = $scnd;
}
return $res;
} | [
"public",
"function",
"highlightAuto",
"(",
"$",
"code",
",",
"$",
"languageSubset",
"=",
"null",
")",
"{",
"$",
"res",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"res",
"->",
"relevance",
"=",
"0",
";",
"$",
"res",
"->",
"value",
"=",
"$",
... | Highlight the given code by highlighting the given code with each
registered language and then finding the match with highest accuracy.
@param string $code
@param string[]|null $languageSubset When set to null, this method will
attempt to highlight $code with each language (170+). Set this to
an array of languages of your choice to limit the amount of languages
to try.
@throws \DomainException if the attempted language to check does not exist
@throws \Exception if an invalid regex was given in a language file
@return \stdClass | [
"Highlight",
"the",
"given",
"code",
"by",
"highlighting",
"the",
"given",
"code",
"with",
"each",
"registered",
"language",
"and",
"then",
"finding",
"the",
"match",
"with",
"highest",
"accuracy",
"."
] | 984fc9721c96bdcbae9329ae5879479878b9db4d | https://github.com/scrivo/highlight.php/blob/984fc9721c96bdcbae9329ae5879479878b9db4d/Highlight/Highlighter.php#L559-L596 | train |
scrivo/highlight.php | Highlight/Highlighter.php | Highlighter.listLanguages | public function listLanguages($include_aliases = false)
{
if ($include_aliases === true) {
return array_merge(self::$languages, array_keys(self::$aliases));
}
return self::$languages;
} | php | public function listLanguages($include_aliases = false)
{
if ($include_aliases === true) {
return array_merge(self::$languages, array_keys(self::$aliases));
}
return self::$languages;
} | [
"public",
"function",
"listLanguages",
"(",
"$",
"include_aliases",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"include_aliases",
"===",
"true",
")",
"{",
"return",
"array_merge",
"(",
"self",
"::",
"$",
"languages",
",",
"array_keys",
"(",
"self",
"::",
"$",... | Return a list of all supported languages. Using this list in
setAutodetectLanguages will turn on autodetection for all supported
languages.
@param bool $include_aliases specify whether language aliases
should be included as well
@return string[] An array of language names | [
"Return",
"a",
"list",
"of",
"all",
"supported",
"languages",
".",
"Using",
"this",
"list",
"in",
"setAutodetectLanguages",
"will",
"turn",
"on",
"autodetection",
"for",
"all",
"supported",
"languages",
"."
] | 984fc9721c96bdcbae9329ae5879479878b9db4d | https://github.com/scrivo/highlight.php/blob/984fc9721c96bdcbae9329ae5879479878b9db4d/Highlight/Highlighter.php#L608-L615 | train |
scrivo/highlight.php | Highlight/Highlighter.php | Highlighter.getAliasesForLanguage | public function getAliasesForLanguage($language)
{
$language = self::getLanguage($language);
if ($language->aliases === null) {
return array($language->name);
}
return array_merge(array($language->name), $language->aliases);
} | php | public function getAliasesForLanguage($language)
{
$language = self::getLanguage($language);
if ($language->aliases === null) {
return array($language->name);
}
return array_merge(array($language->name), $language->aliases);
} | [
"public",
"function",
"getAliasesForLanguage",
"(",
"$",
"language",
")",
"{",
"$",
"language",
"=",
"self",
"::",
"getLanguage",
"(",
"$",
"language",
")",
";",
"if",
"(",
"$",
"language",
"->",
"aliases",
"===",
"null",
")",
"{",
"return",
"array",
"("... | Returns list of all available aliases for given language name.
@param string $language name or alias of language to look-up
@throws \DomainException if the requested language was not in this
Highlighter's language set
@return string[] An array of all aliases associated with the requested
language name language. Passed-in name is included as
well. | [
"Returns",
"list",
"of",
"all",
"available",
"aliases",
"for",
"given",
"language",
"name",
"."
] | 984fc9721c96bdcbae9329ae5879479878b9db4d | https://github.com/scrivo/highlight.php/blob/984fc9721c96bdcbae9329ae5879479878b9db4d/Highlight/Highlighter.php#L629-L638 | train |
scrivo/highlight.php | Highlight/Autoloader.php | Autoloader.load | public static function load($class)
{
if (substr($class, 0, 10) !== "Highlight\\") {
return false;
}
$c = str_replace("\\", "/", substr($class, 10)) . ".php";
$res = include __DIR__ . "/$c";
return $res == 1 ? true : false;
} | php | public static function load($class)
{
if (substr($class, 0, 10) !== "Highlight\\") {
return false;
}
$c = str_replace("\\", "/", substr($class, 10)) . ".php";
$res = include __DIR__ . "/$c";
return $res == 1 ? true : false;
} | [
"public",
"static",
"function",
"load",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"class",
",",
"0",
",",
"10",
")",
"!==",
"\"Highlight\\\\\"",
")",
"{",
"return",
"false",
";",
"}",
"$",
"c",
"=",
"str_replace",
"(",
"\"\\\\\"",
... | The method to include the source file for a given class to use in
the PHP spl_autoload_register function.
@param string a name of a Scrivo class
@return bool true if the source file was successfully included | [
"The",
"method",
"to",
"include",
"the",
"source",
"file",
"for",
"a",
"given",
"class",
"to",
"use",
"in",
"the",
"PHP",
"spl_autoload_register",
"function",
"."
] | 984fc9721c96bdcbae9329ae5879479878b9db4d | https://github.com/scrivo/highlight.php/blob/984fc9721c96bdcbae9329ae5879479878b9db4d/Highlight/Autoloader.php#L61-L71 | train |
scrivo/highlight.php | Highlight/JsonRef.php | JsonRef.getPaths | private function getPaths(&$s, $r = "#")
{
$this->paths[$r] = &$s;
if (is_array($s) || is_object($s)) {
foreach ($s as $k => &$v) {
if ($k !== "\$ref") {
$this->getPaths($v, $r == "#" ? "#{$k}" : "{$r}.{$k}");
}
}
}
} | php | private function getPaths(&$s, $r = "#")
{
$this->paths[$r] = &$s;
if (is_array($s) || is_object($s)) {
foreach ($s as $k => &$v) {
if ($k !== "\$ref") {
$this->getPaths($v, $r == "#" ? "#{$k}" : "{$r}.{$k}");
}
}
}
} | [
"private",
"function",
"getPaths",
"(",
"&",
"$",
"s",
",",
"$",
"r",
"=",
"\"#\"",
")",
"{",
"$",
"this",
"->",
"paths",
"[",
"$",
"r",
"]",
"=",
"&",
"$",
"s",
";",
"if",
"(",
"is_array",
"(",
"$",
"s",
")",
"||",
"is_object",
"(",
"$",
"... | Recurse through the data tree and fill an array of paths that reference
the nodes in the decoded JSON data structure.
@param mixed $s Decoded JSON data (decoded with json_decode)
@param string $r The current path key (for example: '#children.0'). | [
"Recurse",
"through",
"the",
"data",
"tree",
"and",
"fill",
"an",
"array",
"of",
"paths",
"that",
"reference",
"the",
"nodes",
"in",
"the",
"decoded",
"JSON",
"data",
"structure",
"."
] | 984fc9721c96bdcbae9329ae5879479878b9db4d | https://github.com/scrivo/highlight.php/blob/984fc9721c96bdcbae9329ae5879479878b9db4d/Highlight/JsonRef.php#L81-L91 | train |
scrivo/highlight.php | Highlight/JsonRef.php | JsonRef.resolvePathReferences | private function resolvePathReferences(&$s, $limit = 20, $depth = 1)
{
if ($depth >= $limit) {
return;
}
++$depth;
if (is_array($s) || is_object($s)) {
foreach ($s as $k => &$v) {
if ($k === "\$ref") {
$s = $this->paths[$v];
} else {
$this->resolvePathReferences($v, $limit, $depth);
}
}
}
} | php | private function resolvePathReferences(&$s, $limit = 20, $depth = 1)
{
if ($depth >= $limit) {
return;
}
++$depth;
if (is_array($s) || is_object($s)) {
foreach ($s as $k => &$v) {
if ($k === "\$ref") {
$s = $this->paths[$v];
} else {
$this->resolvePathReferences($v, $limit, $depth);
}
}
}
} | [
"private",
"function",
"resolvePathReferences",
"(",
"&",
"$",
"s",
",",
"$",
"limit",
"=",
"20",
",",
"$",
"depth",
"=",
"1",
")",
"{",
"if",
"(",
"$",
"depth",
">=",
"$",
"limit",
")",
"{",
"return",
";",
"}",
"++",
"$",
"depth",
";",
"if",
"... | Recurse through the data tree and resolve all path references.
@param mixed $s Decoded JSON data (decoded with json_decode) | [
"Recurse",
"through",
"the",
"data",
"tree",
"and",
"resolve",
"all",
"path",
"references",
"."
] | 984fc9721c96bdcbae9329ae5879479878b9db4d | https://github.com/scrivo/highlight.php/blob/984fc9721c96bdcbae9329ae5879479878b9db4d/Highlight/JsonRef.php#L98-L115 | train |
scrivo/highlight.php | Highlight/JsonRef.php | JsonRef.decode | public function decode($json)
{
// Clear the path array.
$this->paths = array();
// Decode the given JSON data if necessary.
$x = is_string($json) ? json_decode($json) : $json;
// Get all data paths.
$this->getPaths($x);
// Resolve all path references.
$this->resolvePathReferences($x);
// Return the data.
return $x;
} | php | public function decode($json)
{
// Clear the path array.
$this->paths = array();
// Decode the given JSON data if necessary.
$x = is_string($json) ? json_decode($json) : $json;
// Get all data paths.
$this->getPaths($x);
// Resolve all path references.
$this->resolvePathReferences($x);
// Return the data.
return $x;
} | [
"public",
"function",
"decode",
"(",
"$",
"json",
")",
"{",
"// Clear the path array.",
"$",
"this",
"->",
"paths",
"=",
"array",
"(",
")",
";",
"// Decode the given JSON data if necessary.",
"$",
"x",
"=",
"is_string",
"(",
"$",
"json",
")",
"?",
"json_decode... | Decode JSON data that may contain path based references.
@param string|object $json JSON data string or JSON data object
@return mixed The decoded JSON data | [
"Decode",
"JSON",
"data",
"that",
"may",
"contain",
"path",
"based",
"references",
"."
] | 984fc9721c96bdcbae9329ae5879479878b9db4d | https://github.com/scrivo/highlight.php/blob/984fc9721c96bdcbae9329ae5879479878b9db4d/Highlight/JsonRef.php#L124-L136 | train |
TomLingham/Laravel-Searchy | src/SearchyServiceProvider.php | SearchyServiceProvider.registerSearchBuilder | public function registerSearchBuilder()
{
$this->app->singleton('searchy', function (Container $app) {
$config = $app['config'];
return new SearchBuilder($config);
});
$this->app->alias('searchy', SearchBuilder::class);
} | php | public function registerSearchBuilder()
{
$this->app->singleton('searchy', function (Container $app) {
$config = $app['config'];
return new SearchBuilder($config);
});
$this->app->alias('searchy', SearchBuilder::class);
} | [
"public",
"function",
"registerSearchBuilder",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'searchy'",
",",
"function",
"(",
"Container",
"$",
"app",
")",
"{",
"$",
"config",
"=",
"$",
"app",
"[",
"'config'",
"]",
";",
"return",
"... | Register the search builder class.
@return void | [
"Register",
"the",
"search",
"builder",
"class",
"."
] | 0003a8cf15271319db132322c35eff7c17e2b942 | https://github.com/TomLingham/Laravel-Searchy/blob/0003a8cf15271319db132322c35eff7c17e2b942/src/SearchyServiceProvider.php#L61-L70 | train |
TomLingham/Laravel-Searchy | src/SearchDrivers/BaseSearchDriver.php | BaseSearchDriver.query | public function query($searchString)
{
$this->searchString = substr(\DB::connection()->getPdo()->quote($searchString), 1, -1);
return $this;
} | php | public function query($searchString)
{
$this->searchString = substr(\DB::connection()->getPdo()->quote($searchString), 1, -1);
return $this;
} | [
"public",
"function",
"query",
"(",
"$",
"searchString",
")",
"{",
"$",
"this",
"->",
"searchString",
"=",
"substr",
"(",
"\\",
"DB",
"::",
"connection",
"(",
")",
"->",
"getPdo",
"(",
")",
"->",
"quote",
"(",
"$",
"searchString",
")",
",",
"1",
",",... | Specify the string that is is being searched for.
@param $searchString
@return \Illuminate\Database\Query\Builder|mixed|static | [
"Specify",
"the",
"string",
"that",
"is",
"is",
"being",
"searched",
"for",
"."
] | 0003a8cf15271319db132322c35eff7c17e2b942 | https://github.com/TomLingham/Laravel-Searchy/blob/0003a8cf15271319db132322c35eff7c17e2b942/src/SearchDrivers/BaseSearchDriver.php#L73-L78 | train |
viacreative/sudo-su | src/SudoSu.php | SudoSu.loginAsUser | public function loginAsUser($userId, $originalUserId)
{
$this->session->put('sudosu.has_sudoed', true);
$this->session->put($this->sessionKey, $originalUserId);
$this->auth->loginUsingId($userId);
} | php | public function loginAsUser($userId, $originalUserId)
{
$this->session->put('sudosu.has_sudoed', true);
$this->session->put($this->sessionKey, $originalUserId);
$this->auth->loginUsingId($userId);
} | [
"public",
"function",
"loginAsUser",
"(",
"$",
"userId",
",",
"$",
"originalUserId",
")",
"{",
"$",
"this",
"->",
"session",
"->",
"put",
"(",
"'sudosu.has_sudoed'",
",",
"true",
")",
";",
"$",
"this",
"->",
"session",
"->",
"put",
"(",
"$",
"this",
"-... | Stores the ID of the current user in the session so we can return
back to the original account later, then logs the user in
as the user with the given ID.
@param integer $userId
@param integer $originalUserId
@return void | [
"Stores",
"the",
"ID",
"of",
"the",
"current",
"user",
"in",
"the",
"session",
"so",
"we",
"can",
"return",
"back",
"to",
"the",
"original",
"account",
"later",
"then",
"logs",
"the",
"user",
"in",
"as",
"the",
"user",
"with",
"the",
"given",
"ID",
"."... | 689dcb7e653b6bbd9ae7cb2a49fd50d742ccb96a | https://github.com/viacreative/sudo-su/blob/689dcb7e653b6bbd9ae7cb2a49fd50d742ccb96a/src/SudoSu.php#L35-L41 | train |
laravel-admin-extensions/helpers | src/Scaffold/MigrationCreator.php | MigrationCreator.populateStub | protected function populateStub($name, $stub, $table)
{
return str_replace(
['DummyClass', 'DummyTable', 'DummyStructure'],
[$this->getClassName($name), $table, $this->bluePrint],
$stub
);
} | php | protected function populateStub($name, $stub, $table)
{
return str_replace(
['DummyClass', 'DummyTable', 'DummyStructure'],
[$this->getClassName($name), $table, $this->bluePrint],
$stub
);
} | [
"protected",
"function",
"populateStub",
"(",
"$",
"name",
",",
"$",
"stub",
",",
"$",
"table",
")",
"{",
"return",
"str_replace",
"(",
"[",
"'DummyClass'",
",",
"'DummyTable'",
",",
"'DummyStructure'",
"]",
",",
"[",
"$",
"this",
"->",
"getClassName",
"("... | Populate stub.
@param string $name
@param string $stub
@param string $table
@return mixed | [
"Populate",
"stub",
"."
] | 67b2573029f90ca1873e1598a2d46ae8d9acca66 | https://github.com/laravel-admin-extensions/helpers/blob/67b2573029f90ca1873e1598a2d46ae8d9acca66/src/Scaffold/MigrationCreator.php#L48-L55 | train |
laravel-admin-extensions/helpers | src/Scaffold/ControllerCreator.php | ControllerCreator.getPath | public function getPath($name)
{
$segments = explode('\\', $name);
array_shift($segments);
return app_path(implode('/', $segments)).'.php';
} | php | public function getPath($name)
{
$segments = explode('\\', $name);
array_shift($segments);
return app_path(implode('/', $segments)).'.php';
} | [
"public",
"function",
"getPath",
"(",
"$",
"name",
")",
"{",
"$",
"segments",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"name",
")",
";",
"array_shift",
"(",
"$",
"segments",
")",
";",
"return",
"app_path",
"(",
"implode",
"(",
"'/'",
",",
"$",
"segme... | Get file path from giving controller name.
@param $name
@return string | [
"Get",
"file",
"path",
"from",
"giving",
"controller",
"name",
"."
] | 67b2573029f90ca1873e1598a2d46ae8d9acca66 | https://github.com/laravel-admin-extensions/helpers/blob/67b2573029f90ca1873e1598a2d46ae8d9acca66/src/Scaffold/ControllerCreator.php#L110-L117 | train |
laravel-admin-extensions/helpers | src/Scaffold/ModelCreator.php | ModelCreator.replaceClass | protected function replaceClass(&$stub, $name)
{
$class = str_replace($this->getNamespace($name).'\\', '', $name);
$stub = str_replace('DummyClass', $class, $stub);
return $this;
} | php | protected function replaceClass(&$stub, $name)
{
$class = str_replace($this->getNamespace($name).'\\', '', $name);
$stub = str_replace('DummyClass', $class, $stub);
return $this;
} | [
"protected",
"function",
"replaceClass",
"(",
"&",
"$",
"stub",
",",
"$",
"name",
")",
"{",
"$",
"class",
"=",
"str_replace",
"(",
"$",
"this",
"->",
"getNamespace",
"(",
"$",
"name",
")",
".",
"'\\\\'",
",",
"''",
",",
"$",
"name",
")",
";",
"$",
... | Replace class dummy.
@param string $stub
@param string $name
@return $this | [
"Replace",
"class",
"dummy",
"."
] | 67b2573029f90ca1873e1598a2d46ae8d9acca66 | https://github.com/laravel-admin-extensions/helpers/blob/67b2573029f90ca1873e1598a2d46ae8d9acca66/src/Scaffold/ModelCreator.php#L116-L123 | train |
laravel-admin-extensions/helpers | src/Scaffold/ModelCreator.php | ModelCreator.replaceSoftDeletes | protected function replaceSoftDeletes(&$stub, $softDeletes)
{
$import = $use = '';
if ($softDeletes) {
$import = "use Illuminate\\Database\\Eloquent\\SoftDeletes;\n";
$use = "use SoftDeletes;\n";
}
$stub = str_replace(['DummyImportSoftDeletesTrait', 'DummyUseSoftDeletesTrait'], [$import, $use], $stub);
return $this;
} | php | protected function replaceSoftDeletes(&$stub, $softDeletes)
{
$import = $use = '';
if ($softDeletes) {
$import = "use Illuminate\\Database\\Eloquent\\SoftDeletes;\n";
$use = "use SoftDeletes;\n";
}
$stub = str_replace(['DummyImportSoftDeletesTrait', 'DummyUseSoftDeletesTrait'], [$import, $use], $stub);
return $this;
} | [
"protected",
"function",
"replaceSoftDeletes",
"(",
"&",
"$",
"stub",
",",
"$",
"softDeletes",
")",
"{",
"$",
"import",
"=",
"$",
"use",
"=",
"''",
";",
"if",
"(",
"$",
"softDeletes",
")",
"{",
"$",
"import",
"=",
"\"use Illuminate\\\\Database\\\\Eloquent\\\... | Replace soft-deletes dummy.
@param string $stub
@param bool $softDeletes
@return $this | [
"Replace",
"soft",
"-",
"deletes",
"dummy",
"."
] | 67b2573029f90ca1873e1598a2d46ae8d9acca66 | https://github.com/laravel-admin-extensions/helpers/blob/67b2573029f90ca1873e1598a2d46ae8d9acca66/src/Scaffold/ModelCreator.php#L150-L162 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.