id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
---|---|---|---|---|---|---|---|---|---|---|---|
16,000 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Comparator/Native.php | Native.intFloatCompare | protected function intFloatCompare(NI $a, NI $b)
{
return $this->rationalCompare(
RationalTypeFactory::fromFloat($a->asFloatType()),
RationalTypeFactory::fromFloat($b->asFloatType())
);
} | php | protected function intFloatCompare(NI $a, NI $b)
{
return $this->rationalCompare(
RationalTypeFactory::fromFloat($a->asFloatType()),
RationalTypeFactory::fromFloat($b->asFloatType())
);
} | [
"protected",
"function",
"intFloatCompare",
"(",
"NI",
"$",
"a",
",",
"NI",
"$",
"b",
")",
"{",
"return",
"$",
"this",
"->",
"rationalCompare",
"(",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"$",
"a",
"->",
"asFloatType",
"(",
")",
")",
",",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"$",
"b",
"->",
"asFloatType",
"(",
")",
")",
")",
";",
"}"
]
| Compare int and float types
@param NI $a
@param NI $b
@return int | [
"Compare",
"int",
"and",
"float",
"types"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Comparator/Native.php#L75-L81 |
16,001 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Comparator/Native.php | Native.rationalCompare | protected function rationalCompare(RationalType $a, RationalType $b)
{
$res = $this->calculator->rationalSub($a, $b);
if ($res->numerator()->get() == 0) {
return 0;
}
if ($res->numerator()->get() < 0) {
return -1;
}
return 1;
} | php | protected function rationalCompare(RationalType $a, RationalType $b)
{
$res = $this->calculator->rationalSub($a, $b);
if ($res->numerator()->get() == 0) {
return 0;
}
if ($res->numerator()->get() < 0) {
return -1;
}
return 1;
} | [
"protected",
"function",
"rationalCompare",
"(",
"RationalType",
"$",
"a",
",",
"RationalType",
"$",
"b",
")",
"{",
"$",
"res",
"=",
"$",
"this",
"->",
"calculator",
"->",
"rationalSub",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"if",
"(",
"$",
"res",
"->",
"numerator",
"(",
")",
"->",
"get",
"(",
")",
"==",
"0",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"$",
"res",
"->",
"numerator",
"(",
")",
"->",
"get",
"(",
")",
"<",
"0",
")",
"{",
"return",
"-",
"1",
";",
"}",
"return",
"1",
";",
"}"
]
| Compare two rationals
@param RationalType $a
@param RationalType $b
@return int | [
"Compare",
"two",
"rationals"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Comparator/Native.php#L90-L101 |
16,002 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Comparator/Native.php | Native.complexCompare | protected function complexCompare(ComplexType $a, ComplexType $b)
{
if ($a->isReal() && $b->isReal()) {
return $this->rationalCompare($a->r(), $b->r());
}
//hack to get around native php integer limitations
//what we should be doing here is to return $this->rationalCompare($a->modulus(), $b->modulus())
//but this blows up because of the big rationals it produces
$am = $a->modulus()->asFloatType()->get();
$bm = $b->modulus()->asFloatType()->get();
if ($am == $bm) {
return 0;
}
if ($am < $bm) {
return -1;
}
return 1;
} | php | protected function complexCompare(ComplexType $a, ComplexType $b)
{
if ($a->isReal() && $b->isReal()) {
return $this->rationalCompare($a->r(), $b->r());
}
//hack to get around native php integer limitations
//what we should be doing here is to return $this->rationalCompare($a->modulus(), $b->modulus())
//but this blows up because of the big rationals it produces
$am = $a->modulus()->asFloatType()->get();
$bm = $b->modulus()->asFloatType()->get();
if ($am == $bm) {
return 0;
}
if ($am < $bm) {
return -1;
}
return 1;
} | [
"protected",
"function",
"complexCompare",
"(",
"ComplexType",
"$",
"a",
",",
"ComplexType",
"$",
"b",
")",
"{",
"if",
"(",
"$",
"a",
"->",
"isReal",
"(",
")",
"&&",
"$",
"b",
"->",
"isReal",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"rationalCompare",
"(",
"$",
"a",
"->",
"r",
"(",
")",
",",
"$",
"b",
"->",
"r",
"(",
")",
")",
";",
"}",
"//hack to get around native php integer limitations",
"//what we should be doing here is to return $this->rationalCompare($a->modulus(), $b->modulus())",
"//but this blows up because of the big rationals it produces",
"$",
"am",
"=",
"$",
"a",
"->",
"modulus",
"(",
")",
"->",
"asFloatType",
"(",
")",
"->",
"get",
"(",
")",
";",
"$",
"bm",
"=",
"$",
"b",
"->",
"modulus",
"(",
")",
"->",
"asFloatType",
"(",
")",
"->",
"get",
"(",
")",
";",
"if",
"(",
"$",
"am",
"==",
"$",
"bm",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"$",
"am",
"<",
"$",
"bm",
")",
"{",
"return",
"-",
"1",
";",
"}",
"return",
"1",
";",
"}"
]
| Compare complex numbers.
If both operands are real then compare the real parts
else compare the modulii of the two numbers
@param ComplexType $a
@param ComplexType $b
@return boolean | [
"Compare",
"complex",
"numbers",
".",
"If",
"both",
"operands",
"are",
"real",
"then",
"compare",
"the",
"real",
"parts",
"else",
"compare",
"the",
"modulii",
"of",
"the",
"two",
"numbers"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Comparator/Native.php#L113-L132 |
16,003 | acasademont/wurfl | WURFL/Handlers/CatchAllMozillaHandler.php | WURFL_Handlers_CatchAllMozillaHandler.applyConclusiveMatch | public function applyConclusiveMatch($userAgent)
{
if (WURFL_Configuration_ConfigHolder::getWURFLConfig()->isHighPerformance()) {
//High performance mode
$tolerance = WURFL_Handlers_Utils::firstCloseParen($userAgent);
return $this->getDeviceIDFromRIS($userAgent, $tolerance);
} else {
//High accuracy mode
return $this->getDeviceIDFromLD($userAgent, 5);
}
} | php | public function applyConclusiveMatch($userAgent)
{
if (WURFL_Configuration_ConfigHolder::getWURFLConfig()->isHighPerformance()) {
//High performance mode
$tolerance = WURFL_Handlers_Utils::firstCloseParen($userAgent);
return $this->getDeviceIDFromRIS($userAgent, $tolerance);
} else {
//High accuracy mode
return $this->getDeviceIDFromLD($userAgent, 5);
}
} | [
"public",
"function",
"applyConclusiveMatch",
"(",
"$",
"userAgent",
")",
"{",
"if",
"(",
"WURFL_Configuration_ConfigHolder",
"::",
"getWURFLConfig",
"(",
")",
"->",
"isHighPerformance",
"(",
")",
")",
"{",
"//High performance mode",
"$",
"tolerance",
"=",
"WURFL_Handlers_Utils",
"::",
"firstCloseParen",
"(",
"$",
"userAgent",
")",
";",
"return",
"$",
"this",
"->",
"getDeviceIDFromRIS",
"(",
"$",
"userAgent",
",",
"$",
"tolerance",
")",
";",
"}",
"else",
"{",
"//High accuracy mode",
"return",
"$",
"this",
"->",
"getDeviceIDFromLD",
"(",
"$",
"userAgent",
",",
"5",
")",
";",
"}",
"}"
]
| If UA starts with Mozilla, apply LD with tolerance 5.
@param string $userAgent
@return string | [
"If",
"UA",
"starts",
"with",
"Mozilla",
"apply",
"LD",
"with",
"tolerance",
"5",
"."
]
| 0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2 | https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/Handlers/CatchAllMozillaHandler.php#L51-L61 |
16,004 | dreamfactorysoftware/df-azure | src/Components/DocumentDBConnection.php | DocumentDBConnection.listCollections | public function listCollections(array $options = [])
{
$this->setOptions($options);
$coll = new Collection($this->client, $this->database);
$coll->setHeaders($this->getHeaders());
$rs = $coll->getAll();
$this->checkResponse($rs);
$colls = array_get($rs, 'DocumentCollections');
$list = [];
if (!empty($colls)) {
foreach ($colls as $coll) {
$list[] = array_get($coll, 'id');
}
}
return $list;
} | php | public function listCollections(array $options = [])
{
$this->setOptions($options);
$coll = new Collection($this->client, $this->database);
$coll->setHeaders($this->getHeaders());
$rs = $coll->getAll();
$this->checkResponse($rs);
$colls = array_get($rs, 'DocumentCollections');
$list = [];
if (!empty($colls)) {
foreach ($colls as $coll) {
$list[] = array_get($coll, 'id');
}
}
return $list;
} | [
"public",
"function",
"listCollections",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"$",
"coll",
"=",
"new",
"Collection",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"this",
"->",
"database",
")",
";",
"$",
"coll",
"->",
"setHeaders",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"rs",
"=",
"$",
"coll",
"->",
"getAll",
"(",
")",
";",
"$",
"this",
"->",
"checkResponse",
"(",
"$",
"rs",
")",
";",
"$",
"colls",
"=",
"array_get",
"(",
"$",
"rs",
",",
"'DocumentCollections'",
")",
";",
"$",
"list",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"colls",
")",
")",
"{",
"foreach",
"(",
"$",
"colls",
"as",
"$",
"coll",
")",
"{",
"$",
"list",
"[",
"]",
"=",
"array_get",
"(",
"$",
"coll",
",",
"'id'",
")",
";",
"}",
"}",
"return",
"$",
"list",
";",
"}"
]
| List all collections in a Database.
@param array $options Operation options
@return array | [
"List",
"all",
"collections",
"in",
"a",
"Database",
"."
]
| 48dff2796dc544344c0c7badaaa6917f1bcd623f | https://github.com/dreamfactorysoftware/df-azure/blob/48dff2796dc544344c0c7badaaa6917f1bcd623f/src/Components/DocumentDBConnection.php#L87-L103 |
16,005 | dreamfactorysoftware/df-azure | src/Components/DocumentDBConnection.php | DocumentDBConnection.getCollection | public function getCollection($id, array $options = [])
{
$this->setOptions($options);
$coll = new Collection($this->client, $this->database);
$coll->setHeaders($this->getHeaders());
$rs = $coll->get($id);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
} | php | public function getCollection($id, array $options = [])
{
$this->setOptions($options);
$coll = new Collection($this->client, $this->database);
$coll->setHeaders($this->getHeaders());
$rs = $coll->get($id);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
} | [
"public",
"function",
"getCollection",
"(",
"$",
"id",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"$",
"coll",
"=",
"new",
"Collection",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"this",
"->",
"database",
")",
";",
"$",
"coll",
"->",
"setHeaders",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"rs",
"=",
"$",
"coll",
"->",
"get",
"(",
"$",
"id",
")",
";",
"$",
"this",
"->",
"checkResponse",
"(",
"$",
"rs",
")",
";",
"unset",
"(",
"$",
"rs",
"[",
"'_curl_info'",
"]",
")",
";",
"return",
"$",
"rs",
";",
"}"
]
| Retrieves a collection information.
@param string $id Collection ID
@param array $options Operation options
@return array | [
"Retrieves",
"a",
"collection",
"information",
"."
]
| 48dff2796dc544344c0c7badaaa6917f1bcd623f | https://github.com/dreamfactorysoftware/df-azure/blob/48dff2796dc544344c0c7badaaa6917f1bcd623f/src/Components/DocumentDBConnection.php#L113-L123 |
16,006 | dreamfactorysoftware/df-azure | src/Components/DocumentDBConnection.php | DocumentDBConnection.replaceCollection | public function replaceCollection(array $data, $id, array $options = [])
{
$this->setOptions($options);
$coll = new Collection($this->client, $this->database);
$coll->setHeaders($this->getHeaders());
$rs = $coll->replace($data, $id);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
} | php | public function replaceCollection(array $data, $id, array $options = [])
{
$this->setOptions($options);
$coll = new Collection($this->client, $this->database);
$coll->setHeaders($this->getHeaders());
$rs = $coll->replace($data, $id);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
} | [
"public",
"function",
"replaceCollection",
"(",
"array",
"$",
"data",
",",
"$",
"id",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"$",
"coll",
"=",
"new",
"Collection",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"this",
"->",
"database",
")",
";",
"$",
"coll",
"->",
"setHeaders",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"rs",
"=",
"$",
"coll",
"->",
"replace",
"(",
"$",
"data",
",",
"$",
"id",
")",
";",
"$",
"this",
"->",
"checkResponse",
"(",
"$",
"rs",
")",
";",
"unset",
"(",
"$",
"rs",
"[",
"'_curl_info'",
"]",
")",
";",
"return",
"$",
"rs",
";",
"}"
]
| Replaces a collection.
@param array $data Collection data
@param string $id
@param array $options Operation options
@return array | [
"Replaces",
"a",
"collection",
"."
]
| 48dff2796dc544344c0c7badaaa6917f1bcd623f | https://github.com/dreamfactorysoftware/df-azure/blob/48dff2796dc544344c0c7badaaa6917f1bcd623f/src/Components/DocumentDBConnection.php#L154-L164 |
16,007 | dreamfactorysoftware/df-azure | src/Components/DocumentDBConnection.php | DocumentDBConnection.listDocuments | public function listDocuments($collection, array $options = [])
{
$this->setOptions($options);
$doc = new Document($this->client, $this->database, $collection);
$doc->setHeaders($this->getHeaders());
$rs = $doc->getAll();
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
} | php | public function listDocuments($collection, array $options = [])
{
$this->setOptions($options);
$doc = new Document($this->client, $this->database, $collection);
$doc->setHeaders($this->getHeaders());
$rs = $doc->getAll();
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
} | [
"public",
"function",
"listDocuments",
"(",
"$",
"collection",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"$",
"doc",
"=",
"new",
"Document",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"this",
"->",
"database",
",",
"$",
"collection",
")",
";",
"$",
"doc",
"->",
"setHeaders",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"rs",
"=",
"$",
"doc",
"->",
"getAll",
"(",
")",
";",
"$",
"this",
"->",
"checkResponse",
"(",
"$",
"rs",
")",
";",
"unset",
"(",
"$",
"rs",
"[",
"'_curl_info'",
"]",
")",
";",
"return",
"$",
"rs",
";",
"}"
]
| List all documents in a collection.
@param string $collection Collection to list documents from
@param array $options Operation options
@return array | [
"List",
"all",
"documents",
"in",
"a",
"collection",
"."
]
| 48dff2796dc544344c0c7badaaa6917f1bcd623f | https://github.com/dreamfactorysoftware/df-azure/blob/48dff2796dc544344c0c7badaaa6917f1bcd623f/src/Components/DocumentDBConnection.php#L198-L208 |
16,008 | dreamfactorysoftware/df-azure | src/Components/DocumentDBConnection.php | DocumentDBConnection.getDocument | public function getDocument($collection, $id, array $options = [])
{
$this->setOptions($options);
$doc = new Document($this->client, $this->database, $collection);
$doc->setHeaders($this->getHeaders());
$rs = $doc->get($id);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
} | php | public function getDocument($collection, $id, array $options = [])
{
$this->setOptions($options);
$doc = new Document($this->client, $this->database, $collection);
$doc->setHeaders($this->getHeaders());
$rs = $doc->get($id);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
} | [
"public",
"function",
"getDocument",
"(",
"$",
"collection",
",",
"$",
"id",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"$",
"doc",
"=",
"new",
"Document",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"this",
"->",
"database",
",",
"$",
"collection",
")",
";",
"$",
"doc",
"->",
"setHeaders",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"rs",
"=",
"$",
"doc",
"->",
"get",
"(",
"$",
"id",
")",
";",
"$",
"this",
"->",
"checkResponse",
"(",
"$",
"rs",
")",
";",
"unset",
"(",
"$",
"rs",
"[",
"'_curl_info'",
"]",
")",
";",
"return",
"$",
"rs",
";",
"}"
]
| Retrieves a document.
@param string $collection Collection to list document from
@param string $id ID of the document to retrieve
@param array $options Operation options
@return array | [
"Retrieves",
"a",
"document",
"."
]
| 48dff2796dc544344c0c7badaaa6917f1bcd623f | https://github.com/dreamfactorysoftware/df-azure/blob/48dff2796dc544344c0c7badaaa6917f1bcd623f/src/Components/DocumentDBConnection.php#L219-L229 |
16,009 | dreamfactorysoftware/df-azure | src/Components/DocumentDBConnection.php | DocumentDBConnection.createDocument | public function createDocument($collection, array $data, array $options = [])
{
$this->setOptions($options);
$doc = new Document($this->client, $this->database, $collection);
$doc->setHeaders($this->getHeaders());
$rs = $doc->create($data);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
} | php | public function createDocument($collection, array $data, array $options = [])
{
$this->setOptions($options);
$doc = new Document($this->client, $this->database, $collection);
$doc->setHeaders($this->getHeaders());
$rs = $doc->create($data);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
} | [
"public",
"function",
"createDocument",
"(",
"$",
"collection",
",",
"array",
"$",
"data",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"$",
"doc",
"=",
"new",
"Document",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"this",
"->",
"database",
",",
"$",
"collection",
")",
";",
"$",
"doc",
"->",
"setHeaders",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"rs",
"=",
"$",
"doc",
"->",
"create",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"checkResponse",
"(",
"$",
"rs",
")",
";",
"unset",
"(",
"$",
"rs",
"[",
"'_curl_info'",
"]",
")",
";",
"return",
"$",
"rs",
";",
"}"
]
| Creates a document.
@param string $collection Collection to create a document in
@param array $data Document data
@param array $options Operation options
@return array | [
"Creates",
"a",
"document",
"."
]
| 48dff2796dc544344c0c7badaaa6917f1bcd623f | https://github.com/dreamfactorysoftware/df-azure/blob/48dff2796dc544344c0c7badaaa6917f1bcd623f/src/Components/DocumentDBConnection.php#L240-L250 |
16,010 | dreamfactorysoftware/df-azure | src/Components/DocumentDBConnection.php | DocumentDBConnection.replaceDocument | public function replaceDocument($collection, array $data, $id, array $options = [])
{
$this->setOptions($options);
$doc = new Document($this->client, $this->database, $collection);
$doc->setHeaders($this->getHeaders());
$rs = $doc->replace($data, $id);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
} | php | public function replaceDocument($collection, array $data, $id, array $options = [])
{
$this->setOptions($options);
$doc = new Document($this->client, $this->database, $collection);
$doc->setHeaders($this->getHeaders());
$rs = $doc->replace($data, $id);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
} | [
"public",
"function",
"replaceDocument",
"(",
"$",
"collection",
",",
"array",
"$",
"data",
",",
"$",
"id",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"$",
"doc",
"=",
"new",
"Document",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"this",
"->",
"database",
",",
"$",
"collection",
")",
";",
"$",
"doc",
"->",
"setHeaders",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"rs",
"=",
"$",
"doc",
"->",
"replace",
"(",
"$",
"data",
",",
"$",
"id",
")",
";",
"$",
"this",
"->",
"checkResponse",
"(",
"$",
"rs",
")",
";",
"unset",
"(",
"$",
"rs",
"[",
"'_curl_info'",
"]",
")",
";",
"return",
"$",
"rs",
";",
"}"
]
| Replaces a document.
@param string $collection Collection to replace a document in
@param array $data Document data
@param string $id ID of the document being replaced
@param array $options Operation options
@return array | [
"Replaces",
"a",
"document",
"."
]
| 48dff2796dc544344c0c7badaaa6917f1bcd623f | https://github.com/dreamfactorysoftware/df-azure/blob/48dff2796dc544344c0c7badaaa6917f1bcd623f/src/Components/DocumentDBConnection.php#L262-L272 |
16,011 | dreamfactorysoftware/df-azure | src/Components/DocumentDBConnection.php | DocumentDBConnection.queryDocument | public function queryDocument($collection, $sql, array $params = [], array $options = [])
{
$this->setOptions($options);
$doc = new Document($this->client, $this->database, $collection);
$doc->setHeaders($this->getHeaders());
$rs = $doc->query($sql, $params);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
} | php | public function queryDocument($collection, $sql, array $params = [], array $options = [])
{
$this->setOptions($options);
$doc = new Document($this->client, $this->database, $collection);
$doc->setHeaders($this->getHeaders());
$rs = $doc->query($sql, $params);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
} | [
"public",
"function",
"queryDocument",
"(",
"$",
"collection",
",",
"$",
"sql",
",",
"array",
"$",
"params",
"=",
"[",
"]",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"$",
"doc",
"=",
"new",
"Document",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"this",
"->",
"database",
",",
"$",
"collection",
")",
";",
"$",
"doc",
"->",
"setHeaders",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"rs",
"=",
"$",
"doc",
"->",
"query",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"checkResponse",
"(",
"$",
"rs",
")",
";",
"unset",
"(",
"$",
"rs",
"[",
"'_curl_info'",
"]",
")",
";",
"return",
"$",
"rs",
";",
"}"
]
| Queries a collection for documents.
@param string $collection Collection to perform the query on
@param string $sql SQL query string
@param array $params Query parameters
@param array $options Operation options
@return array | [
"Queries",
"a",
"collection",
"for",
"documents",
"."
]
| 48dff2796dc544344c0c7badaaa6917f1bcd623f | https://github.com/dreamfactorysoftware/df-azure/blob/48dff2796dc544344c0c7badaaa6917f1bcd623f/src/Components/DocumentDBConnection.php#L305-L315 |
16,012 | dreamfactorysoftware/df-azure | src/Components/DocumentDBConnection.php | DocumentDBConnection.checkResponse | protected function checkResponse(array $response)
{
$responseCode = intval(array_get($response, '_curl_info.http_code'));
$message = array_get($response, 'message');
if ($responseCode >= 400) {
$context = ['response_headers' => array_get($response, '_curl_info.response_headers')];
throw new RestException($responseCode, $message, null, null, $context);
}
} | php | protected function checkResponse(array $response)
{
$responseCode = intval(array_get($response, '_curl_info.http_code'));
$message = array_get($response, 'message');
if ($responseCode >= 400) {
$context = ['response_headers' => array_get($response, '_curl_info.response_headers')];
throw new RestException($responseCode, $message, null, null, $context);
}
} | [
"protected",
"function",
"checkResponse",
"(",
"array",
"$",
"response",
")",
"{",
"$",
"responseCode",
"=",
"intval",
"(",
"array_get",
"(",
"$",
"response",
",",
"'_curl_info.http_code'",
")",
")",
";",
"$",
"message",
"=",
"array_get",
"(",
"$",
"response",
",",
"'message'",
")",
";",
"if",
"(",
"$",
"responseCode",
">=",
"400",
")",
"{",
"$",
"context",
"=",
"[",
"'response_headers'",
"=>",
"array_get",
"(",
"$",
"response",
",",
"'_curl_info.response_headers'",
")",
"]",
";",
"throw",
"new",
"RestException",
"(",
"$",
"responseCode",
",",
"$",
"message",
",",
"null",
",",
"null",
",",
"$",
"context",
")",
";",
"}",
"}"
]
| Checks response status code for exceptions.
@param array $response
@throws \DreamFactory\Core\Exceptions\RestException | [
"Checks",
"response",
"status",
"code",
"for",
"exceptions",
"."
]
| 48dff2796dc544344c0c7badaaa6917f1bcd623f | https://github.com/dreamfactorysoftware/df-azure/blob/48dff2796dc544344c0c7badaaa6917f1bcd623f/src/Components/DocumentDBConnection.php#L324-L333 |
16,013 | vincentchalamon/VinceCmsSonataAdminBundle | Admin/Entity/MenuAdmin.php | MenuAdmin.createQuery | public function createQuery($context = 'list')
{
$query = parent::createQuery($context);
$query->leftJoin($query->getRootAlias().'.article', 'article')->addSelect('article')
->leftJoin($query->getRootAlias().'.parent', 'parent')->addSelect('parent')
->leftJoin($query->getRootAlias().'.children', 'children')->addSelect('children')
->orderBy($query->getRootAlias().'.root, '.$query->getRootAlias().'.lft', 'ASC');
return $query;
} | php | public function createQuery($context = 'list')
{
$query = parent::createQuery($context);
$query->leftJoin($query->getRootAlias().'.article', 'article')->addSelect('article')
->leftJoin($query->getRootAlias().'.parent', 'parent')->addSelect('parent')
->leftJoin($query->getRootAlias().'.children', 'children')->addSelect('children')
->orderBy($query->getRootAlias().'.root, '.$query->getRootAlias().'.lft', 'ASC');
return $query;
} | [
"public",
"function",
"createQuery",
"(",
"$",
"context",
"=",
"'list'",
")",
"{",
"$",
"query",
"=",
"parent",
"::",
"createQuery",
"(",
"$",
"context",
")",
";",
"$",
"query",
"->",
"leftJoin",
"(",
"$",
"query",
"->",
"getRootAlias",
"(",
")",
".",
"'.article'",
",",
"'article'",
")",
"->",
"addSelect",
"(",
"'article'",
")",
"->",
"leftJoin",
"(",
"$",
"query",
"->",
"getRootAlias",
"(",
")",
".",
"'.parent'",
",",
"'parent'",
")",
"->",
"addSelect",
"(",
"'parent'",
")",
"->",
"leftJoin",
"(",
"$",
"query",
"->",
"getRootAlias",
"(",
")",
".",
"'.children'",
",",
"'children'",
")",
"->",
"addSelect",
"(",
"'children'",
")",
"->",
"orderBy",
"(",
"$",
"query",
"->",
"getRootAlias",
"(",
")",
".",
"'.root, '",
".",
"$",
"query",
"->",
"getRootAlias",
"(",
")",
".",
"'.lft'",
",",
"'ASC'",
")",
";",
"return",
"$",
"query",
";",
"}"
]
| Need to override createQuery method because of list order & joins
{@inheritdoc} | [
"Need",
"to",
"override",
"createQuery",
"method",
"because",
"of",
"list",
"order",
"&",
"joins"
]
| edc768061734a92ba116488dd7b61ad40af21ceb | https://github.com/vincentchalamon/VinceCmsSonataAdminBundle/blob/edc768061734a92ba116488dd7b61ad40af21ceb/Admin/Entity/MenuAdmin.php#L130-L139 |
16,014 | gugglegum/mb-str-pad | src/MbString.php | MbString.mb_fill_string | private static function mb_fill_string(string $pattern, $length, $encoding = 'UTF-8'): string
{
$pattern_length = mb_strlen($pattern, $encoding);
$str = '';
$i = 0;
while ($i < $length) {
if ($length - $i >= $pattern_length) {
$str .= $pattern;
$i += $pattern_length;
} else {
$str .= mb_substr($pattern, 0, $length - $i, $encoding);
break;
}
}
return $str;
} | php | private static function mb_fill_string(string $pattern, $length, $encoding = 'UTF-8'): string
{
$pattern_length = mb_strlen($pattern, $encoding);
$str = '';
$i = 0;
while ($i < $length) {
if ($length - $i >= $pattern_length) {
$str .= $pattern;
$i += $pattern_length;
} else {
$str .= mb_substr($pattern, 0, $length - $i, $encoding);
break;
}
}
return $str;
} | [
"private",
"static",
"function",
"mb_fill_string",
"(",
"string",
"$",
"pattern",
",",
"$",
"length",
",",
"$",
"encoding",
"=",
"'UTF-8'",
")",
":",
"string",
"{",
"$",
"pattern_length",
"=",
"mb_strlen",
"(",
"$",
"pattern",
",",
"$",
"encoding",
")",
";",
"$",
"str",
"=",
"''",
";",
"$",
"i",
"=",
"0",
";",
"while",
"(",
"$",
"i",
"<",
"$",
"length",
")",
"{",
"if",
"(",
"$",
"length",
"-",
"$",
"i",
">=",
"$",
"pattern_length",
")",
"{",
"$",
"str",
".=",
"$",
"pattern",
";",
"$",
"i",
"+=",
"$",
"pattern_length",
";",
"}",
"else",
"{",
"$",
"str",
".=",
"mb_substr",
"(",
"$",
"pattern",
",",
"0",
",",
"$",
"length",
"-",
"$",
"i",
",",
"$",
"encoding",
")",
";",
"break",
";",
"}",
"}",
"return",
"$",
"str",
";",
"}"
]
| Returns a string of given length filled with some pattern substring
@param string $pattern
@param $length
@param string $encoding
@return string | [
"Returns",
"a",
"string",
"of",
"given",
"length",
"filled",
"with",
"some",
"pattern",
"substring"
]
| 18fefbdf543dd35b2c25e26d6aab1e3d61cde9f1 | https://github.com/gugglegum/mb-str-pad/blob/18fefbdf543dd35b2c25e26d6aab1e3d61cde9f1/src/MbString.php#L44-L59 |
16,015 | stubbles/stubbles-webapp-core | src/main/php/htmlpassthrough/HtmlFilePassThrough.php | HtmlFilePassThrough.resolve | public function resolve(Request $request, Response $response, UriPath $uriPath)
{
$routeName = $uriPath->remaining('index.html');
if (!file_exists($this->routePath . $routeName)) {
return $response->notFound();
}
return $this->modifyContent(
$request,
$response,
file_get_contents($this->routePath . $routeName),
$routeName
);
} | php | public function resolve(Request $request, Response $response, UriPath $uriPath)
{
$routeName = $uriPath->remaining('index.html');
if (!file_exists($this->routePath . $routeName)) {
return $response->notFound();
}
return $this->modifyContent(
$request,
$response,
file_get_contents($this->routePath . $routeName),
$routeName
);
} | [
"public",
"function",
"resolve",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
",",
"UriPath",
"$",
"uriPath",
")",
"{",
"$",
"routeName",
"=",
"$",
"uriPath",
"->",
"remaining",
"(",
"'index.html'",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"routePath",
".",
"$",
"routeName",
")",
")",
"{",
"return",
"$",
"response",
"->",
"notFound",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"modifyContent",
"(",
"$",
"request",
",",
"$",
"response",
",",
"file_get_contents",
"(",
"$",
"this",
"->",
"routePath",
".",
"$",
"routeName",
")",
",",
"$",
"routeName",
")",
";",
"}"
]
| processes the request
@param \stubbles\webapp\Request $request current request
@param \stubbles\webapp\Response $response response to send
@param \stubbles\webapp\UriPath $uriPath information about called uri path
@return string|\stubbles\webapp\response\Error | [
"processes",
"the",
"request"
]
| 7705f129011a81d5cc3c76b4b150fab3dadac6a3 | https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/htmlpassthrough/HtmlFilePassThrough.php#L49-L62 |
16,016 | eloquent/liberator | src/LiberatorObject.php | LiberatorObject.__isset | public function __isset($property)
{
if ($propertyReflector = $this->liberatorPropertyReflector($property)) {
return null !== $propertyReflector->getValue($this->popsValue());
}
return parent::__isset($property);
} | php | public function __isset($property)
{
if ($propertyReflector = $this->liberatorPropertyReflector($property)) {
return null !== $propertyReflector->getValue($this->popsValue());
}
return parent::__isset($property);
} | [
"public",
"function",
"__isset",
"(",
"$",
"property",
")",
"{",
"if",
"(",
"$",
"propertyReflector",
"=",
"$",
"this",
"->",
"liberatorPropertyReflector",
"(",
"$",
"property",
")",
")",
"{",
"return",
"null",
"!==",
"$",
"propertyReflector",
"->",
"getValue",
"(",
"$",
"this",
"->",
"popsValue",
"(",
")",
")",
";",
"}",
"return",
"parent",
"::",
"__isset",
"(",
"$",
"property",
")",
";",
"}"
]
| Returns true if the property exists on the wrapped object.
@param string $property The name of the property to search for.
@return boolean True if the property exists. | [
"Returns",
"true",
"if",
"the",
"property",
"exists",
"on",
"the",
"wrapped",
"object",
"."
]
| d90c159e0067f7f3e376c8e4b1b72d502f7aa0aa | https://github.com/eloquent/liberator/blob/d90c159e0067f7f3e376c8e4b1b72d502f7aa0aa/src/LiberatorObject.php#L116-L123 |
16,017 | WellCommerce/CoreBundle | Form/AbstractFormBuilder.php | AbstractFormBuilder.initService | protected function initService(string $type, string $alias, array $options)
{
$id = $this->resolverFactory->resolve($type, $alias);
$service = $this->get($id);
$service->setOptions($options);
return $service;
} | php | protected function initService(string $type, string $alias, array $options)
{
$id = $this->resolverFactory->resolve($type, $alias);
$service = $this->get($id);
$service->setOptions($options);
return $service;
} | [
"protected",
"function",
"initService",
"(",
"string",
"$",
"type",
",",
"string",
"$",
"alias",
",",
"array",
"$",
"options",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"resolverFactory",
"->",
"resolve",
"(",
"$",
"type",
",",
"$",
"alias",
")",
";",
"$",
"service",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"id",
")",
";",
"$",
"service",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"return",
"$",
"service",
";",
"}"
]
| Initializes a service by its type
@param string $type
@param string $alias
@param array $options
@return object | [
"Initializes",
"a",
"service",
"by",
"its",
"type"
]
| 984fbd544d4b10cf11e54e0f3c304d100deb6842 | https://github.com/WellCommerce/CoreBundle/blob/984fbd544d4b10cf11e54e0f3c304d100deb6842/Form/AbstractFormBuilder.php#L129-L137 |
16,018 | hamjoint/mustard-auctions | src/lib/Http/Controllers/ItemController.php | ItemController.getBid | public function getBid($itemId)
{
$item = Item::findOrFail($itemId);
if (!$item->auction) {
return redirect($item->url)->withErrors([
'This item is not an auction, so cannot be bid on.',
]);
}
$bids = $item->getBidHistory();
$highest_bid = $bids->first() ?: new Bid();
if ($bids->isEmpty()) {
$minimum_bid = $item->startPrice;
} elseif ($highest_bid->bidder == Auth::user()) {
$minimum_bid = BidIncrement::getMinimumNextBid($highest_bid->amount);
} else {
$minimum_bid = BidIncrement::getMinimumNextBid($item->biddingPrice);
}
return view('mustard::item.bid', [
'item' => $item,
'bids' => $bids,
'highest_bid' => $highest_bid,
'minimum_bid' => $minimum_bid,
]);
} | php | public function getBid($itemId)
{
$item = Item::findOrFail($itemId);
if (!$item->auction) {
return redirect($item->url)->withErrors([
'This item is not an auction, so cannot be bid on.',
]);
}
$bids = $item->getBidHistory();
$highest_bid = $bids->first() ?: new Bid();
if ($bids->isEmpty()) {
$minimum_bid = $item->startPrice;
} elseif ($highest_bid->bidder == Auth::user()) {
$minimum_bid = BidIncrement::getMinimumNextBid($highest_bid->amount);
} else {
$minimum_bid = BidIncrement::getMinimumNextBid($item->biddingPrice);
}
return view('mustard::item.bid', [
'item' => $item,
'bids' => $bids,
'highest_bid' => $highest_bid,
'minimum_bid' => $minimum_bid,
]);
} | [
"public",
"function",
"getBid",
"(",
"$",
"itemId",
")",
"{",
"$",
"item",
"=",
"Item",
"::",
"findOrFail",
"(",
"$",
"itemId",
")",
";",
"if",
"(",
"!",
"$",
"item",
"->",
"auction",
")",
"{",
"return",
"redirect",
"(",
"$",
"item",
"->",
"url",
")",
"->",
"withErrors",
"(",
"[",
"'This item is not an auction, so cannot be bid on.'",
",",
"]",
")",
";",
"}",
"$",
"bids",
"=",
"$",
"item",
"->",
"getBidHistory",
"(",
")",
";",
"$",
"highest_bid",
"=",
"$",
"bids",
"->",
"first",
"(",
")",
"?",
":",
"new",
"Bid",
"(",
")",
";",
"if",
"(",
"$",
"bids",
"->",
"isEmpty",
"(",
")",
")",
"{",
"$",
"minimum_bid",
"=",
"$",
"item",
"->",
"startPrice",
";",
"}",
"elseif",
"(",
"$",
"highest_bid",
"->",
"bidder",
"==",
"Auth",
"::",
"user",
"(",
")",
")",
"{",
"$",
"minimum_bid",
"=",
"BidIncrement",
"::",
"getMinimumNextBid",
"(",
"$",
"highest_bid",
"->",
"amount",
")",
";",
"}",
"else",
"{",
"$",
"minimum_bid",
"=",
"BidIncrement",
"::",
"getMinimumNextBid",
"(",
"$",
"item",
"->",
"biddingPrice",
")",
";",
"}",
"return",
"view",
"(",
"'mustard::item.bid'",
",",
"[",
"'item'",
"=>",
"$",
"item",
",",
"'bids'",
"=>",
"$",
"bids",
",",
"'highest_bid'",
"=>",
"$",
"highest_bid",
",",
"'minimum_bid'",
"=>",
"$",
"minimum_bid",
",",
"]",
")",
";",
"}"
]
| Return the item bid view.
@param int $itemId
@return \Illuminate\View\View | [
"Return",
"the",
"item",
"bid",
"view",
"."
]
| 66c8723d8681466e280263ad100f3fdc5895480d | https://github.com/hamjoint/mustard-auctions/blob/66c8723d8681466e280263ad100f3fdc5895480d/src/lib/Http/Controllers/ItemController.php#L40-L68 |
16,019 | 27cm/password-generator | src/Generator.php | Generator.generate | public function generate($lenght = 4, $separator = ' ')
{
$length = count($this->lists);
$words = [];
$randomArray = static::getRandomArray($lenght);
foreach ($randomArray as $index => $random) {
$list = $this->lists[$index % $length];
$words[] = $list->get($random);
}
return implode($separator, $words);
} | php | public function generate($lenght = 4, $separator = ' ')
{
$length = count($this->lists);
$words = [];
$randomArray = static::getRandomArray($lenght);
foreach ($randomArray as $index => $random) {
$list = $this->lists[$index % $length];
$words[] = $list->get($random);
}
return implode($separator, $words);
} | [
"public",
"function",
"generate",
"(",
"$",
"lenght",
"=",
"4",
",",
"$",
"separator",
"=",
"' '",
")",
"{",
"$",
"length",
"=",
"count",
"(",
"$",
"this",
"->",
"lists",
")",
";",
"$",
"words",
"=",
"[",
"]",
";",
"$",
"randomArray",
"=",
"static",
"::",
"getRandomArray",
"(",
"$",
"lenght",
")",
";",
"foreach",
"(",
"$",
"randomArray",
"as",
"$",
"index",
"=>",
"$",
"random",
")",
"{",
"$",
"list",
"=",
"$",
"this",
"->",
"lists",
"[",
"$",
"index",
"%",
"$",
"length",
"]",
";",
"$",
"words",
"[",
"]",
"=",
"$",
"list",
"->",
"get",
"(",
"$",
"random",
")",
";",
"}",
"return",
"implode",
"(",
"$",
"separator",
",",
"$",
"words",
")",
";",
"}"
]
| Generate password from word lists.
@param int $lenght Password length in words.
@param string $separator Word separator.
@return string Generated password. | [
"Generate",
"password",
"from",
"word",
"lists",
"."
]
| c7f835f3bc302a91497bf5f659e404e750fb03bf | https://github.com/27cm/password-generator/blob/c7f835f3bc302a91497bf5f659e404e750fb03bf/src/Generator.php#L41-L53 |
16,020 | 27cm/password-generator | src/Generator.php | Generator.generateRu | public static function generateRu($lenght = 4, $separator = ' ')
{
$list = new WordList\Ru();
return (new static($list))->generate($lenght, $separator);
} | php | public static function generateRu($lenght = 4, $separator = ' ')
{
$list = new WordList\Ru();
return (new static($list))->generate($lenght, $separator);
} | [
"public",
"static",
"function",
"generateRu",
"(",
"$",
"lenght",
"=",
"4",
",",
"$",
"separator",
"=",
"' '",
")",
"{",
"$",
"list",
"=",
"new",
"WordList",
"\\",
"Ru",
"(",
")",
";",
"return",
"(",
"new",
"static",
"(",
"$",
"list",
")",
")",
"->",
"generate",
"(",
"$",
"lenght",
",",
"$",
"separator",
")",
";",
"}"
]
| Static function generates Russian phrase password.
@param int $lenght Password length in words.
@param string $separator Word separator.
@return string Generated password. | [
"Static",
"function",
"generates",
"Russian",
"phrase",
"password",
"."
]
| c7f835f3bc302a91497bf5f659e404e750fb03bf | https://github.com/27cm/password-generator/blob/c7f835f3bc302a91497bf5f659e404e750fb03bf/src/Generator.php#L63-L67 |
16,021 | 27cm/password-generator | src/Generator.php | Generator.generateEn | public static function generateEn($lenght = 4, $separator = ' ')
{
$list = new WordList\En();
return (new static($list))->generate($lenght, $separator);
} | php | public static function generateEn($lenght = 4, $separator = ' ')
{
$list = new WordList\En();
return (new static($list))->generate($lenght, $separator);
} | [
"public",
"static",
"function",
"generateEn",
"(",
"$",
"lenght",
"=",
"4",
",",
"$",
"separator",
"=",
"' '",
")",
"{",
"$",
"list",
"=",
"new",
"WordList",
"\\",
"En",
"(",
")",
";",
"return",
"(",
"new",
"static",
"(",
"$",
"list",
")",
")",
"->",
"generate",
"(",
"$",
"lenght",
",",
"$",
"separator",
")",
";",
"}"
]
| Static function generates English phrase password.
@param int $lenght Password length in words.
@param string $separator Word separator.
@return string Generated password. | [
"Static",
"function",
"generates",
"English",
"phrase",
"password",
"."
]
| c7f835f3bc302a91497bf5f659e404e750fb03bf | https://github.com/27cm/password-generator/blob/c7f835f3bc302a91497bf5f659e404e750fb03bf/src/Generator.php#L77-L81 |
16,022 | 27cm/password-generator | src/Generator.php | Generator.generateDe | public static function generateDe($lenght = 4, $separator = ' ')
{
$list = new WordList\De();
return (new static($list))->generate($lenght, $separator);
} | php | public static function generateDe($lenght = 4, $separator = ' ')
{
$list = new WordList\De();
return (new static($list))->generate($lenght, $separator);
} | [
"public",
"static",
"function",
"generateDe",
"(",
"$",
"lenght",
"=",
"4",
",",
"$",
"separator",
"=",
"' '",
")",
"{",
"$",
"list",
"=",
"new",
"WordList",
"\\",
"De",
"(",
")",
";",
"return",
"(",
"new",
"static",
"(",
"$",
"list",
")",
")",
"->",
"generate",
"(",
"$",
"lenght",
",",
"$",
"separator",
")",
";",
"}"
]
| Static function generates German phrase password.
@param int $lenght Password length in words.
@param string $separator Word separator.
@return string Generated password. | [
"Static",
"function",
"generates",
"German",
"phrase",
"password",
"."
]
| c7f835f3bc302a91497bf5f659e404e750fb03bf | https://github.com/27cm/password-generator/blob/c7f835f3bc302a91497bf5f659e404e750fb03bf/src/Generator.php#L91-L95 |
16,023 | 27cm/password-generator | src/Generator.php | Generator.generateRuTranslit | public static function generateRuTranslit($lenght = 4, $separator = ' ')
{
$list = new WordList\RuTranslit();
return (new static($list))->generate($lenght, $separator);
} | php | public static function generateRuTranslit($lenght = 4, $separator = ' ')
{
$list = new WordList\RuTranslit();
return (new static($list))->generate($lenght, $separator);
} | [
"public",
"static",
"function",
"generateRuTranslit",
"(",
"$",
"lenght",
"=",
"4",
",",
"$",
"separator",
"=",
"' '",
")",
"{",
"$",
"list",
"=",
"new",
"WordList",
"\\",
"RuTranslit",
"(",
")",
";",
"return",
"(",
"new",
"static",
"(",
"$",
"list",
")",
")",
"->",
"generate",
"(",
"$",
"lenght",
",",
"$",
"separator",
")",
";",
"}"
]
| Static function generates transliterated Russian phrase password
@param int $lenght Password length in words.
@param string $separator Word separator.
@return string Generated password. | [
"Static",
"function",
"generates",
"transliterated",
"Russian",
"phrase",
"password"
]
| c7f835f3bc302a91497bf5f659e404e750fb03bf | https://github.com/27cm/password-generator/blob/c7f835f3bc302a91497bf5f659e404e750fb03bf/src/Generator.php#L105-L109 |
16,024 | 27cm/password-generator | src/Generator.php | Generator.getRandomArray | protected static function getRandomArray($length)
{
$bytes = random_bytes($length * 2);
$result = [];
foreach (unpack('S*', $bytes) as $long) {
$result[] = $long / 0xFFFF;
}
return $result;
} | php | protected static function getRandomArray($length)
{
$bytes = random_bytes($length * 2);
$result = [];
foreach (unpack('S*', $bytes) as $long) {
$result[] = $long / 0xFFFF;
}
return $result;
} | [
"protected",
"static",
"function",
"getRandomArray",
"(",
"$",
"length",
")",
"{",
"$",
"bytes",
"=",
"random_bytes",
"(",
"$",
"length",
"*",
"2",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"unpack",
"(",
"'S*'",
",",
"$",
"bytes",
")",
"as",
"$",
"long",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"long",
"/",
"0xFFFF",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| Get array of random numbers between 0.0 - 1.0.
@param int $length Array length.
@return float[] Array of random values 0.0 - 1.0. | [
"Get",
"array",
"of",
"random",
"numbers",
"between",
"0",
".",
"0",
"-",
"1",
".",
"0",
"."
]
| c7f835f3bc302a91497bf5f659e404e750fb03bf | https://github.com/27cm/password-generator/blob/c7f835f3bc302a91497bf5f659e404e750fb03bf/src/Generator.php#L118-L126 |
16,025 | axelitus/php-base | src/Bool.php | Bool.extIs | public static function extIs($value)
{
if (static::is($value)) {
return true;
}
if (is_string($value)) {
// This function should be case insensitive so let's compare to the lower-cased input string.
$value = strtolower($value);
return (static::isTrueStrExt($value) || static::isFalseStrExt($value));
}
return false;
} | php | public static function extIs($value)
{
if (static::is($value)) {
return true;
}
if (is_string($value)) {
// This function should be case insensitive so let's compare to the lower-cased input string.
$value = strtolower($value);
return (static::isTrueStrExt($value) || static::isFalseStrExt($value));
}
return false;
} | [
"public",
"static",
"function",
"extIs",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"static",
"::",
"is",
"(",
"$",
"value",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"// This function should be case insensitive so let's compare to the lower-cased input string.",
"$",
"value",
"=",
"strtolower",
"(",
"$",
"value",
")",
";",
"return",
"(",
"static",
"::",
"isTrueStrExt",
"(",
"$",
"value",
")",
"||",
"static",
"::",
"isFalseStrExt",
"(",
"$",
"value",
")",
")",
";",
"}",
"return",
"false",
";",
"}"
]
| Tests if the given value is a bool or not.
This function considers also the strings 'true', 'false', 'on', 'off', 'yes', 'no', 'y', 'n', '1', '0'
to be booleans. The function is NOT case sensitive.
@param mixed $value The value to test.
@return bool Returns true if the value is a bool or 0 or 1, false otherwise. | [
"Tests",
"if",
"the",
"given",
"value",
"is",
"a",
"bool",
"or",
"not",
"."
]
| c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075 | https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Bool.php#L52-L65 |
16,026 | axelitus/php-base | src/Bool.php | Bool.compare | public static function compare($bool1, $bool2)
{
if (!static::is($bool1) || !static::is($bool2)) {
throw new \InvalidArgumentException(
"The \$bool1 and \$bool2 parameters must be of type bool."
);
}
return ((int)$bool1 - (int)$bool2);
} | php | public static function compare($bool1, $bool2)
{
if (!static::is($bool1) || !static::is($bool2)) {
throw new \InvalidArgumentException(
"The \$bool1 and \$bool2 parameters must be of type bool."
);
}
return ((int)$bool1 - (int)$bool2);
} | [
"public",
"static",
"function",
"compare",
"(",
"$",
"bool1",
",",
"$",
"bool2",
")",
"{",
"if",
"(",
"!",
"static",
"::",
"is",
"(",
"$",
"bool1",
")",
"||",
"!",
"static",
"::",
"is",
"(",
"$",
"bool2",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"The \\$bool1 and \\$bool2 parameters must be of type bool.\"",
")",
";",
"}",
"return",
"(",
"(",
"int",
")",
"$",
"bool1",
"-",
"(",
"int",
")",
"$",
"bool2",
")",
";",
"}"
]
| Compares two bool values.
The returning value contains the actual value difference.
@param bool $bool1 The left operand.
@param bool $bool2 The right operand.
@return int Returns -1 if $bool1=false and $bool2=true, =0 if $bool1 == $bool2, 1 if $bool1=true and $bool2=false
@throws \InvalidArgumentException | [
"Compares",
"two",
"bool",
"values",
"."
]
| c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075 | https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Bool.php#L130-L139 |
16,027 | tonicospinelli/class-generation | src/ClassGeneration/PropertyCollection.php | PropertyCollection.add | public function add($property)
{
if (!$property instanceof PropertyInterface) {
throw new \InvalidArgumentException(
'This Property must be a instance of \ClassGeneration\PropertyInterface'
);
}
if ($property->getName() === null) {
$property->setName('property' . ($this->count() + 1));
}
parent::set($property->getName(), $property);
return true;
} | php | public function add($property)
{
if (!$property instanceof PropertyInterface) {
throw new \InvalidArgumentException(
'This Property must be a instance of \ClassGeneration\PropertyInterface'
);
}
if ($property->getName() === null) {
$property->setName('property' . ($this->count() + 1));
}
parent::set($property->getName(), $property);
return true;
} | [
"public",
"function",
"add",
"(",
"$",
"property",
")",
"{",
"if",
"(",
"!",
"$",
"property",
"instanceof",
"PropertyInterface",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'This Property must be a instance of \\ClassGeneration\\PropertyInterface'",
")",
";",
"}",
"if",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
"===",
"null",
")",
"{",
"$",
"property",
"->",
"setName",
"(",
"'property'",
".",
"(",
"$",
"this",
"->",
"count",
"(",
")",
"+",
"1",
")",
")",
";",
"}",
"parent",
"::",
"set",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
",",
"$",
"property",
")",
";",
"return",
"true",
";",
"}"
]
| Adds a new Property on the collection.
@param PropertyInterface $property
@return bool
@throws \InvalidArgumentException | [
"Adds",
"a",
"new",
"Property",
"on",
"the",
"collection",
"."
]
| eee63bdb68c066b25b885b57b23656e809381a76 | https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/PropertyCollection.php#L31-L45 |
16,028 | tonicospinelli/class-generation | src/ClassGeneration/PropertyCollection.php | PropertyCollection.toString | public function toString()
{
$string = '';
$properties = $this->getIterator();
foreach ($properties as $property) {
$string .= $property->toString();
}
return $string;
} | php | public function toString()
{
$string = '';
$properties = $this->getIterator();
foreach ($properties as $property) {
$string .= $property->toString();
}
return $string;
} | [
"public",
"function",
"toString",
"(",
")",
"{",
"$",
"string",
"=",
"''",
";",
"$",
"properties",
"=",
"$",
"this",
"->",
"getIterator",
"(",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
")",
"{",
"$",
"string",
".=",
"$",
"property",
"->",
"toString",
"(",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
]
| Parse the Property Collection to string.
@return string | [
"Parse",
"the",
"Property",
"Collection",
"to",
"string",
"."
]
| eee63bdb68c066b25b885b57b23656e809381a76 | https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/PropertyCollection.php#L69-L78 |
16,029 | tonicospinelli/class-generation | src/ClassGeneration/PropertyCollection.php | PropertyCollection.getByName | public function getByName($propertyName)
{
$foundList = new self();
$list = $this->getIterator();
foreach ($list as $property) {
if ((is_array($propertyName) && in_array($property->getName(), $propertyName))
|| ($property->getName() === $propertyName)
) {
$foundList->add($property);
}
}
return $foundList;
} | php | public function getByName($propertyName)
{
$foundList = new self();
$list = $this->getIterator();
foreach ($list as $property) {
if ((is_array($propertyName) && in_array($property->getName(), $propertyName))
|| ($property->getName() === $propertyName)
) {
$foundList->add($property);
}
}
return $foundList;
} | [
"public",
"function",
"getByName",
"(",
"$",
"propertyName",
")",
"{",
"$",
"foundList",
"=",
"new",
"self",
"(",
")",
";",
"$",
"list",
"=",
"$",
"this",
"->",
"getIterator",
"(",
")",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"(",
"is_array",
"(",
"$",
"propertyName",
")",
"&&",
"in_array",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
",",
"$",
"propertyName",
")",
")",
"||",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
"===",
"$",
"propertyName",
")",
")",
"{",
"$",
"foundList",
"->",
"add",
"(",
"$",
"property",
")",
";",
"}",
"}",
"return",
"$",
"foundList",
";",
"}"
]
| Find the properties by name.
@param string $propertyName
@return PropertyCollection | [
"Find",
"the",
"properties",
"by",
"name",
"."
]
| eee63bdb68c066b25b885b57b23656e809381a76 | https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/PropertyCollection.php#L87-L100 |
16,030 | edmondscommerce/behat-faker-context | src/FakerContext.php | FakerContext.fillForm | protected function fillForm(Element\NodeElement $form)
{
$inputs = $form->findAll('css', 'input[type="text"]');
foreach ($inputs as $i)
{
/** @var Element\NodeElement $i */
if ($i->isVisible())
{
if ($i->hasAttribute('name'))
{
$name = $i->getAttribute('name');
$value = $this->getFakerValue($name);
}
else
{
$value = $this->faker()->text();
}
$i->setValue($value);
}
}
$passwords = $form->findAll('css', 'input[type="password"]');
$password = $this->faker()->password;
foreach ($passwords as $p)
{
if ($p->isVisible())
{
$p->setValue($password);
}
}
$selects = $form->findAll('css', 'select');
foreach ($selects as $s)
{
/** @var Element\NodeElement $s */
if ($s->isVisible())
{
$s->selectOption($s->find('css', 'option')->getAttribute('name'));
}
}
$checkboxes = $form->findAll('css', 'checkbox');
foreach ($checkboxes as $c)
{
/** @var Element\NodeElement $c */
if ($c->isVisible())
{
$c->check();
}
}
$radios = $form->findAll('css', 'input[type="radio"]');
$radio_names = array();
foreach ($radios as $r)
{
/** @var Element\NodeElement $r */
if ($r->isVisible())
{
if ($r->hasAttribute('name'))
{
$name = $r->getAttribute('name');
if (!isset($radio_names[$name]))
{
$radio_names[$name] = true;
$r->click();
}
}
}
}
} | php | protected function fillForm(Element\NodeElement $form)
{
$inputs = $form->findAll('css', 'input[type="text"]');
foreach ($inputs as $i)
{
/** @var Element\NodeElement $i */
if ($i->isVisible())
{
if ($i->hasAttribute('name'))
{
$name = $i->getAttribute('name');
$value = $this->getFakerValue($name);
}
else
{
$value = $this->faker()->text();
}
$i->setValue($value);
}
}
$passwords = $form->findAll('css', 'input[type="password"]');
$password = $this->faker()->password;
foreach ($passwords as $p)
{
if ($p->isVisible())
{
$p->setValue($password);
}
}
$selects = $form->findAll('css', 'select');
foreach ($selects as $s)
{
/** @var Element\NodeElement $s */
if ($s->isVisible())
{
$s->selectOption($s->find('css', 'option')->getAttribute('name'));
}
}
$checkboxes = $form->findAll('css', 'checkbox');
foreach ($checkboxes as $c)
{
/** @var Element\NodeElement $c */
if ($c->isVisible())
{
$c->check();
}
}
$radios = $form->findAll('css', 'input[type="radio"]');
$radio_names = array();
foreach ($radios as $r)
{
/** @var Element\NodeElement $r */
if ($r->isVisible())
{
if ($r->hasAttribute('name'))
{
$name = $r->getAttribute('name');
if (!isset($radio_names[$name]))
{
$radio_names[$name] = true;
$r->click();
}
}
}
}
} | [
"protected",
"function",
"fillForm",
"(",
"Element",
"\\",
"NodeElement",
"$",
"form",
")",
"{",
"$",
"inputs",
"=",
"$",
"form",
"->",
"findAll",
"(",
"'css'",
",",
"'input[type=\"text\"]'",
")",
";",
"foreach",
"(",
"$",
"inputs",
"as",
"$",
"i",
")",
"{",
"/** @var Element\\NodeElement $i */",
"if",
"(",
"$",
"i",
"->",
"isVisible",
"(",
")",
")",
"{",
"if",
"(",
"$",
"i",
"->",
"hasAttribute",
"(",
"'name'",
")",
")",
"{",
"$",
"name",
"=",
"$",
"i",
"->",
"getAttribute",
"(",
"'name'",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"getFakerValue",
"(",
"$",
"name",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"faker",
"(",
")",
"->",
"text",
"(",
")",
";",
"}",
"$",
"i",
"->",
"setValue",
"(",
"$",
"value",
")",
";",
"}",
"}",
"$",
"passwords",
"=",
"$",
"form",
"->",
"findAll",
"(",
"'css'",
",",
"'input[type=\"password\"]'",
")",
";",
"$",
"password",
"=",
"$",
"this",
"->",
"faker",
"(",
")",
"->",
"password",
";",
"foreach",
"(",
"$",
"passwords",
"as",
"$",
"p",
")",
"{",
"if",
"(",
"$",
"p",
"->",
"isVisible",
"(",
")",
")",
"{",
"$",
"p",
"->",
"setValue",
"(",
"$",
"password",
")",
";",
"}",
"}",
"$",
"selects",
"=",
"$",
"form",
"->",
"findAll",
"(",
"'css'",
",",
"'select'",
")",
";",
"foreach",
"(",
"$",
"selects",
"as",
"$",
"s",
")",
"{",
"/** @var Element\\NodeElement $s */",
"if",
"(",
"$",
"s",
"->",
"isVisible",
"(",
")",
")",
"{",
"$",
"s",
"->",
"selectOption",
"(",
"$",
"s",
"->",
"find",
"(",
"'css'",
",",
"'option'",
")",
"->",
"getAttribute",
"(",
"'name'",
")",
")",
";",
"}",
"}",
"$",
"checkboxes",
"=",
"$",
"form",
"->",
"findAll",
"(",
"'css'",
",",
"'checkbox'",
")",
";",
"foreach",
"(",
"$",
"checkboxes",
"as",
"$",
"c",
")",
"{",
"/** @var Element\\NodeElement $c */",
"if",
"(",
"$",
"c",
"->",
"isVisible",
"(",
")",
")",
"{",
"$",
"c",
"->",
"check",
"(",
")",
";",
"}",
"}",
"$",
"radios",
"=",
"$",
"form",
"->",
"findAll",
"(",
"'css'",
",",
"'input[type=\"radio\"]'",
")",
";",
"$",
"radio_names",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"radios",
"as",
"$",
"r",
")",
"{",
"/** @var Element\\NodeElement $r */",
"if",
"(",
"$",
"r",
"->",
"isVisible",
"(",
")",
")",
"{",
"if",
"(",
"$",
"r",
"->",
"hasAttribute",
"(",
"'name'",
")",
")",
"{",
"$",
"name",
"=",
"$",
"r",
"->",
"getAttribute",
"(",
"'name'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"radio_names",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"radio_names",
"[",
"$",
"name",
"]",
"=",
"true",
";",
"$",
"r",
"->",
"click",
"(",
")",
";",
"}",
"}",
"}",
"}",
"}"
]
| Fuzz fill all form fields with random data
@param Element\NodeElement $form | [
"Fuzz",
"fill",
"all",
"form",
"fields",
"with",
"random",
"data"
]
| 7c616daf7a8bab9093a1b8a3c608d644a929f715 | https://github.com/edmondscommerce/behat-faker-context/blob/7c616daf7a8bab9093a1b8a3c608d644a929f715/src/FakerContext.php#L63-L135 |
16,031 | Srokap/code_review | classes/CodeReview/CodeFixer.php | CodeFixer.getBasicFunctionRenames | public function getBasicFunctionRenames($maxVersion = '') {
$data = array(
'1.7' => array(
'elgg_validate_action_url' => 'elgg_add_action_tokens_to_url',
'menu_item' => 'make_register_object',
'extend_view' => 'elgg_extend_view',
'get_views' => 'elgg_get_views',
),
'1.8' => array(
'register_elgg_event_handler' => 'elgg_register_event_handler',
'unregister_elgg_event_handler' => 'elgg_unregister_event_handler',
'trigger_elgg_event' => 'elgg_trigger_event',
'register_plugin_hook' => 'elgg_register_plugin_hook_handler',
'unregister_plugin_hook' => 'elgg_unregister_plugin_hook_handler',
'trigger_plugin_hook' => 'elgg_trigger_plugin_hook',
'friendly_title' => 'elgg_get_friendly_title',
'friendly_time' => 'elgg_view_friendly_time',
'page_owner' => 'elgg_get_page_owner_guid',
'page_owner_entity' => 'elgg_get_page_owner_entity',
'set_page_owner' => 'elgg_set_page_owner_guid',
'set_context' => 'elgg_set_context',
'get_context' => 'elgg_get_context',
'get_plugin_name' => 'elgg_get_calling_plugin_id',
'is_plugin_enabled' => 'elgg_is_active_plugin',
'set_user_validation_status' => 'elgg_set_user_validation_status',
'get_loggedin_user' => 'elgg_get_logged_in_user_entity',
'get_loggedin_userid' => 'elgg_get_logged_in_user_guid',
'isloggedin' => 'elgg_is_logged_in',
'isadminloggedin' => 'elgg_is_admin_logged_in',
'load_plugins' => '_elgg_load_plugins',
'set_plugin_usersetting' => 'elgg_set_plugin_user_setting',
'clear_plugin_usersetting' => 'elgg_unset_plugin_user_setting',
'get_plugin_usersetting' => 'elgg_get_plugin_user_setting',
'set_plugin_setting' => 'elgg_set_plugin_setting',
'get_plugin_setting' => 'elgg_get_plugin_setting',
'clear_plugin_setting' => 'elgg_unset_plugin_setting',
'clear_all_plugin_settings' => 'elgg_unset_all_plugin_settings',
'set_view_location' => 'elgg_set_view_location',
'get_metadata' => 'elgg_get_metadata_from_id',
'get_annotation' => 'elgg_get_annotation_from_id',
'register_page_handler' => 'elgg_register_page_handler',
'unregister_page_handler' => 'elgg_unregister_page_handler',
'register_entity_type' => 'elgg_register_entity_type',
'elgg_view_register_simplecache' => 'elgg_register_simplecache_view',
'elgg_view_regenerate_simplecache' => 'elgg_regenerate_simplecache',
'elgg_view_enable_simplecache' => 'elgg_enable_simplecache',
'elgg_view_disable_simplecache' => 'elgg_disable_simplecache',
'remove_widget_type' => 'elgg_unregister_widget_type',
'widget_type_exists' => 'elgg_is_widget_type',
'get_widget_types' => 'elgg_get_widget_types',
'display_widget' => 'elgg_view_entity',
'invalidate_cache_for_entity' => '_elgg_invalidate_cache_for_entity',
'cache_entity' => '_elgg_cache_entity',
'retrieve_cached_entity' => '_elgg_retrieve_cached_entity',
),
'1.9' => array(
'setup_db_connections' => '_elgg_services()->db->setupConnections',
'get_db_link' => '_elgg_services()->db->getLink',
'get_db_error' => 'mysql_error',
'execute_delayed_query' => '_elgg_services()->db->registerDelayedQuery',
'elgg_regenerate_simplecache' => 'elgg_invalidate_simplecache',
'elgg_get_filepath_cache' => 'elgg_get_system_cache',
'elgg_filepath_cache_reset' => 'elgg_reset_system_cache',
'elgg_filepath_cache_save' => 'elgg_save_system_cache',
'elgg_filepath_cache_load' => 'elgg_load_system_cache',
'elgg_enable_filepath_cache' => 'elgg_enable_system_cache',
'elgg_disable_filepath_cache' => 'elgg_disable_system_cache',
'unregister_entity_type' => 'elgg_unregister_entity_type',
'autop' => 'elgg_autop',
'xml_to_object' => 'new ElggXMLElement',
'unregister_notification_handler' => 'elgg_unregister_notification_method',
),
'1.10' => array(
'file_get_general_file_type' => 'elgg_get_file_simple_type',
'file_get_simple_type' => 'elgg_get_file_simple_type',
),
);
$result = array();
foreach ($data as $version => $rows) {
if (!$maxVersion || version_compare($version, $maxVersion, '<=')) {
$result = array_merge($result, $rows);
}
}
return $result;
} | php | public function getBasicFunctionRenames($maxVersion = '') {
$data = array(
'1.7' => array(
'elgg_validate_action_url' => 'elgg_add_action_tokens_to_url',
'menu_item' => 'make_register_object',
'extend_view' => 'elgg_extend_view',
'get_views' => 'elgg_get_views',
),
'1.8' => array(
'register_elgg_event_handler' => 'elgg_register_event_handler',
'unregister_elgg_event_handler' => 'elgg_unregister_event_handler',
'trigger_elgg_event' => 'elgg_trigger_event',
'register_plugin_hook' => 'elgg_register_plugin_hook_handler',
'unregister_plugin_hook' => 'elgg_unregister_plugin_hook_handler',
'trigger_plugin_hook' => 'elgg_trigger_plugin_hook',
'friendly_title' => 'elgg_get_friendly_title',
'friendly_time' => 'elgg_view_friendly_time',
'page_owner' => 'elgg_get_page_owner_guid',
'page_owner_entity' => 'elgg_get_page_owner_entity',
'set_page_owner' => 'elgg_set_page_owner_guid',
'set_context' => 'elgg_set_context',
'get_context' => 'elgg_get_context',
'get_plugin_name' => 'elgg_get_calling_plugin_id',
'is_plugin_enabled' => 'elgg_is_active_plugin',
'set_user_validation_status' => 'elgg_set_user_validation_status',
'get_loggedin_user' => 'elgg_get_logged_in_user_entity',
'get_loggedin_userid' => 'elgg_get_logged_in_user_guid',
'isloggedin' => 'elgg_is_logged_in',
'isadminloggedin' => 'elgg_is_admin_logged_in',
'load_plugins' => '_elgg_load_plugins',
'set_plugin_usersetting' => 'elgg_set_plugin_user_setting',
'clear_plugin_usersetting' => 'elgg_unset_plugin_user_setting',
'get_plugin_usersetting' => 'elgg_get_plugin_user_setting',
'set_plugin_setting' => 'elgg_set_plugin_setting',
'get_plugin_setting' => 'elgg_get_plugin_setting',
'clear_plugin_setting' => 'elgg_unset_plugin_setting',
'clear_all_plugin_settings' => 'elgg_unset_all_plugin_settings',
'set_view_location' => 'elgg_set_view_location',
'get_metadata' => 'elgg_get_metadata_from_id',
'get_annotation' => 'elgg_get_annotation_from_id',
'register_page_handler' => 'elgg_register_page_handler',
'unregister_page_handler' => 'elgg_unregister_page_handler',
'register_entity_type' => 'elgg_register_entity_type',
'elgg_view_register_simplecache' => 'elgg_register_simplecache_view',
'elgg_view_regenerate_simplecache' => 'elgg_regenerate_simplecache',
'elgg_view_enable_simplecache' => 'elgg_enable_simplecache',
'elgg_view_disable_simplecache' => 'elgg_disable_simplecache',
'remove_widget_type' => 'elgg_unregister_widget_type',
'widget_type_exists' => 'elgg_is_widget_type',
'get_widget_types' => 'elgg_get_widget_types',
'display_widget' => 'elgg_view_entity',
'invalidate_cache_for_entity' => '_elgg_invalidate_cache_for_entity',
'cache_entity' => '_elgg_cache_entity',
'retrieve_cached_entity' => '_elgg_retrieve_cached_entity',
),
'1.9' => array(
'setup_db_connections' => '_elgg_services()->db->setupConnections',
'get_db_link' => '_elgg_services()->db->getLink',
'get_db_error' => 'mysql_error',
'execute_delayed_query' => '_elgg_services()->db->registerDelayedQuery',
'elgg_regenerate_simplecache' => 'elgg_invalidate_simplecache',
'elgg_get_filepath_cache' => 'elgg_get_system_cache',
'elgg_filepath_cache_reset' => 'elgg_reset_system_cache',
'elgg_filepath_cache_save' => 'elgg_save_system_cache',
'elgg_filepath_cache_load' => 'elgg_load_system_cache',
'elgg_enable_filepath_cache' => 'elgg_enable_system_cache',
'elgg_disable_filepath_cache' => 'elgg_disable_system_cache',
'unregister_entity_type' => 'elgg_unregister_entity_type',
'autop' => 'elgg_autop',
'xml_to_object' => 'new ElggXMLElement',
'unregister_notification_handler' => 'elgg_unregister_notification_method',
),
'1.10' => array(
'file_get_general_file_type' => 'elgg_get_file_simple_type',
'file_get_simple_type' => 'elgg_get_file_simple_type',
),
);
$result = array();
foreach ($data as $version => $rows) {
if (!$maxVersion || version_compare($version, $maxVersion, '<=')) {
$result = array_merge($result, $rows);
}
}
return $result;
} | [
"public",
"function",
"getBasicFunctionRenames",
"(",
"$",
"maxVersion",
"=",
"''",
")",
"{",
"$",
"data",
"=",
"array",
"(",
"'1.7'",
"=>",
"array",
"(",
"'elgg_validate_action_url'",
"=>",
"'elgg_add_action_tokens_to_url'",
",",
"'menu_item'",
"=>",
"'make_register_object'",
",",
"'extend_view'",
"=>",
"'elgg_extend_view'",
",",
"'get_views'",
"=>",
"'elgg_get_views'",
",",
")",
",",
"'1.8'",
"=>",
"array",
"(",
"'register_elgg_event_handler'",
"=>",
"'elgg_register_event_handler'",
",",
"'unregister_elgg_event_handler'",
"=>",
"'elgg_unregister_event_handler'",
",",
"'trigger_elgg_event'",
"=>",
"'elgg_trigger_event'",
",",
"'register_plugin_hook'",
"=>",
"'elgg_register_plugin_hook_handler'",
",",
"'unregister_plugin_hook'",
"=>",
"'elgg_unregister_plugin_hook_handler'",
",",
"'trigger_plugin_hook'",
"=>",
"'elgg_trigger_plugin_hook'",
",",
"'friendly_title'",
"=>",
"'elgg_get_friendly_title'",
",",
"'friendly_time'",
"=>",
"'elgg_view_friendly_time'",
",",
"'page_owner'",
"=>",
"'elgg_get_page_owner_guid'",
",",
"'page_owner_entity'",
"=>",
"'elgg_get_page_owner_entity'",
",",
"'set_page_owner'",
"=>",
"'elgg_set_page_owner_guid'",
",",
"'set_context'",
"=>",
"'elgg_set_context'",
",",
"'get_context'",
"=>",
"'elgg_get_context'",
",",
"'get_plugin_name'",
"=>",
"'elgg_get_calling_plugin_id'",
",",
"'is_plugin_enabled'",
"=>",
"'elgg_is_active_plugin'",
",",
"'set_user_validation_status'",
"=>",
"'elgg_set_user_validation_status'",
",",
"'get_loggedin_user'",
"=>",
"'elgg_get_logged_in_user_entity'",
",",
"'get_loggedin_userid'",
"=>",
"'elgg_get_logged_in_user_guid'",
",",
"'isloggedin'",
"=>",
"'elgg_is_logged_in'",
",",
"'isadminloggedin'",
"=>",
"'elgg_is_admin_logged_in'",
",",
"'load_plugins'",
"=>",
"'_elgg_load_plugins'",
",",
"'set_plugin_usersetting'",
"=>",
"'elgg_set_plugin_user_setting'",
",",
"'clear_plugin_usersetting'",
"=>",
"'elgg_unset_plugin_user_setting'",
",",
"'get_plugin_usersetting'",
"=>",
"'elgg_get_plugin_user_setting'",
",",
"'set_plugin_setting'",
"=>",
"'elgg_set_plugin_setting'",
",",
"'get_plugin_setting'",
"=>",
"'elgg_get_plugin_setting'",
",",
"'clear_plugin_setting'",
"=>",
"'elgg_unset_plugin_setting'",
",",
"'clear_all_plugin_settings'",
"=>",
"'elgg_unset_all_plugin_settings'",
",",
"'set_view_location'",
"=>",
"'elgg_set_view_location'",
",",
"'get_metadata'",
"=>",
"'elgg_get_metadata_from_id'",
",",
"'get_annotation'",
"=>",
"'elgg_get_annotation_from_id'",
",",
"'register_page_handler'",
"=>",
"'elgg_register_page_handler'",
",",
"'unregister_page_handler'",
"=>",
"'elgg_unregister_page_handler'",
",",
"'register_entity_type'",
"=>",
"'elgg_register_entity_type'",
",",
"'elgg_view_register_simplecache'",
"=>",
"'elgg_register_simplecache_view'",
",",
"'elgg_view_regenerate_simplecache'",
"=>",
"'elgg_regenerate_simplecache'",
",",
"'elgg_view_enable_simplecache'",
"=>",
"'elgg_enable_simplecache'",
",",
"'elgg_view_disable_simplecache'",
"=>",
"'elgg_disable_simplecache'",
",",
"'remove_widget_type'",
"=>",
"'elgg_unregister_widget_type'",
",",
"'widget_type_exists'",
"=>",
"'elgg_is_widget_type'",
",",
"'get_widget_types'",
"=>",
"'elgg_get_widget_types'",
",",
"'display_widget'",
"=>",
"'elgg_view_entity'",
",",
"'invalidate_cache_for_entity'",
"=>",
"'_elgg_invalidate_cache_for_entity'",
",",
"'cache_entity'",
"=>",
"'_elgg_cache_entity'",
",",
"'retrieve_cached_entity'",
"=>",
"'_elgg_retrieve_cached_entity'",
",",
")",
",",
"'1.9'",
"=>",
"array",
"(",
"'setup_db_connections'",
"=>",
"'_elgg_services()->db->setupConnections'",
",",
"'get_db_link'",
"=>",
"'_elgg_services()->db->getLink'",
",",
"'get_db_error'",
"=>",
"'mysql_error'",
",",
"'execute_delayed_query'",
"=>",
"'_elgg_services()->db->registerDelayedQuery'",
",",
"'elgg_regenerate_simplecache'",
"=>",
"'elgg_invalidate_simplecache'",
",",
"'elgg_get_filepath_cache'",
"=>",
"'elgg_get_system_cache'",
",",
"'elgg_filepath_cache_reset'",
"=>",
"'elgg_reset_system_cache'",
",",
"'elgg_filepath_cache_save'",
"=>",
"'elgg_save_system_cache'",
",",
"'elgg_filepath_cache_load'",
"=>",
"'elgg_load_system_cache'",
",",
"'elgg_enable_filepath_cache'",
"=>",
"'elgg_enable_system_cache'",
",",
"'elgg_disable_filepath_cache'",
"=>",
"'elgg_disable_system_cache'",
",",
"'unregister_entity_type'",
"=>",
"'elgg_unregister_entity_type'",
",",
"'autop'",
"=>",
"'elgg_autop'",
",",
"'xml_to_object'",
"=>",
"'new ElggXMLElement'",
",",
"'unregister_notification_handler'",
"=>",
"'elgg_unregister_notification_method'",
",",
")",
",",
"'1.10'",
"=>",
"array",
"(",
"'file_get_general_file_type'",
"=>",
"'elgg_get_file_simple_type'",
",",
"'file_get_simple_type'",
"=>",
"'elgg_get_file_simple_type'",
",",
")",
",",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"version",
"=>",
"$",
"rows",
")",
"{",
"if",
"(",
"!",
"$",
"maxVersion",
"||",
"version_compare",
"(",
"$",
"version",
",",
"$",
"maxVersion",
",",
"'<='",
")",
")",
"{",
"$",
"result",
"=",
"array_merge",
"(",
"$",
"result",
",",
"$",
"rows",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
]
| Just basic function renames from A to B
@param string $maxVersion Maximum Elgg version to support
@return array | [
"Just",
"basic",
"function",
"renames",
"from",
"A",
"to",
"B"
]
| c79c619f99279cf15713b118ae19b0ef017db362 | https://github.com/Srokap/code_review/blob/c79c619f99279cf15713b118ae19b0ef017db362/classes/CodeReview/CodeFixer.php#L12-L97 |
16,032 | stubbles/stubbles-webapp-core | src/main/php/auth/TokenAwareUser.php | TokenAwareUser.createToken | public function createToken(string $tokenSalt): Token
{
$this->setToken(Token::create($this, $tokenSalt));
return $this->token();
} | php | public function createToken(string $tokenSalt): Token
{
$this->setToken(Token::create($this, $tokenSalt));
return $this->token();
} | [
"public",
"function",
"createToken",
"(",
"string",
"$",
"tokenSalt",
")",
":",
"Token",
"{",
"$",
"this",
"->",
"setToken",
"(",
"Token",
"::",
"create",
"(",
"$",
"this",
",",
"$",
"tokenSalt",
")",
")",
";",
"return",
"$",
"this",
"->",
"token",
"(",
")",
";",
"}"
]
| creates new token for the user with given token salt
The token is already stored in the user afterwards, any further request
to token() will yield the same token.
@param string $tokenSalt
@return \stubbles\webapp\auth\Token | [
"creates",
"new",
"token",
"for",
"the",
"user",
"with",
"given",
"token",
"salt"
]
| 7705f129011a81d5cc3c76b4b150fab3dadac6a3 | https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/auth/TokenAwareUser.php#L47-L51 |
16,033 | drpdigital/json-api-parser | src/ResourceResolver.php | ResourceResolver.bindFetcher | public function bindFetcher($fetcherKey, $relationshipName, $callback = null)
{
if ($callback !== null) {
$this->fetcherRelationships[$fetcherKey][] = $relationshipName;
}
$callback = $callback ?: $relationshipName;
$this->fetchers[$fetcherKey] = $callback;
} | php | public function bindFetcher($fetcherKey, $relationshipName, $callback = null)
{
if ($callback !== null) {
$this->fetcherRelationships[$fetcherKey][] = $relationshipName;
}
$callback = $callback ?: $relationshipName;
$this->fetchers[$fetcherKey] = $callback;
} | [
"public",
"function",
"bindFetcher",
"(",
"$",
"fetcherKey",
",",
"$",
"relationshipName",
",",
"$",
"callback",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"callback",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"fetcherRelationships",
"[",
"$",
"fetcherKey",
"]",
"[",
"]",
"=",
"$",
"relationshipName",
";",
"}",
"$",
"callback",
"=",
"$",
"callback",
"?",
":",
"$",
"relationshipName",
";",
"$",
"this",
"->",
"fetchers",
"[",
"$",
"fetcherKey",
"]",
"=",
"$",
"callback",
";",
"}"
]
| Adds the callback to fetch a resolved relationship for a parameter on a resolver.
@param string $fetcherKey
@param string|callable $relationshipName
@param callable|string $callback
@return void | [
"Adds",
"the",
"callback",
"to",
"fetch",
"a",
"resolved",
"relationship",
"for",
"a",
"parameter",
"on",
"a",
"resolver",
"."
]
| b1ceefc0c19ec326129126253114c121e97ca943 | https://github.com/drpdigital/json-api-parser/blob/b1ceefc0c19ec326129126253114c121e97ca943/src/ResourceResolver.php#L109-L118 |
16,034 | drpdigital/json-api-parser | src/ResourceResolver.php | ResourceResolver.buildParametersForResolver | protected function buildParametersForResolver($resolver, array $parents, array $defaultParameters)
{
$reflector = $this->getCallReflector($resolver);
$parameters = $reflector->getParameters();
$defaultParameters = array_reverse($defaultParameters);
return array_map(function (\ReflectionParameter $parameter) use (&$defaultParameters, $parents) {
$parameterClass = $parameter->getClass();
// If the parameter doesn't have a class then it isn't type hinted
// and thus no need for dependency injection.
if ($parameterClass === null) {
return array_pop($defaultParameters);
}
$fetched = $this->findFetchedResource($parameter, $parameterClass);
if ($fetched !== null) {
return $fetched;
}
// If the parameter asks for a dependency then check parents first
// and then fallback to the application IOC
$parent = $this->findParent($parameterClass, $parents);
if ($parent !== null) {
return $parent;
}
foreach ($this->customParameterResolvers as $parameterResolver) {
$resolved = $this->callResolver(
$parameterResolver,
[
$parameter,
Arr::get($this->resource, 'id'),
Arr::get($this->resource, 'type'),
]
);
if ($resolved !== null) {
return $resolved;
}
}
if ($this->container->has($parameterClass->getName())) {
return $this->container->get($parameterClass->getName());
}
return null;
}, $parameters);
} | php | protected function buildParametersForResolver($resolver, array $parents, array $defaultParameters)
{
$reflector = $this->getCallReflector($resolver);
$parameters = $reflector->getParameters();
$defaultParameters = array_reverse($defaultParameters);
return array_map(function (\ReflectionParameter $parameter) use (&$defaultParameters, $parents) {
$parameterClass = $parameter->getClass();
// If the parameter doesn't have a class then it isn't type hinted
// and thus no need for dependency injection.
if ($parameterClass === null) {
return array_pop($defaultParameters);
}
$fetched = $this->findFetchedResource($parameter, $parameterClass);
if ($fetched !== null) {
return $fetched;
}
// If the parameter asks for a dependency then check parents first
// and then fallback to the application IOC
$parent = $this->findParent($parameterClass, $parents);
if ($parent !== null) {
return $parent;
}
foreach ($this->customParameterResolvers as $parameterResolver) {
$resolved = $this->callResolver(
$parameterResolver,
[
$parameter,
Arr::get($this->resource, 'id'),
Arr::get($this->resource, 'type'),
]
);
if ($resolved !== null) {
return $resolved;
}
}
if ($this->container->has($parameterClass->getName())) {
return $this->container->get($parameterClass->getName());
}
return null;
}, $parameters);
} | [
"protected",
"function",
"buildParametersForResolver",
"(",
"$",
"resolver",
",",
"array",
"$",
"parents",
",",
"array",
"$",
"defaultParameters",
")",
"{",
"$",
"reflector",
"=",
"$",
"this",
"->",
"getCallReflector",
"(",
"$",
"resolver",
")",
";",
"$",
"parameters",
"=",
"$",
"reflector",
"->",
"getParameters",
"(",
")",
";",
"$",
"defaultParameters",
"=",
"array_reverse",
"(",
"$",
"defaultParameters",
")",
";",
"return",
"array_map",
"(",
"function",
"(",
"\\",
"ReflectionParameter",
"$",
"parameter",
")",
"use",
"(",
"&",
"$",
"defaultParameters",
",",
"$",
"parents",
")",
"{",
"$",
"parameterClass",
"=",
"$",
"parameter",
"->",
"getClass",
"(",
")",
";",
"// If the parameter doesn't have a class then it isn't type hinted",
"// and thus no need for dependency injection.",
"if",
"(",
"$",
"parameterClass",
"===",
"null",
")",
"{",
"return",
"array_pop",
"(",
"$",
"defaultParameters",
")",
";",
"}",
"$",
"fetched",
"=",
"$",
"this",
"->",
"findFetchedResource",
"(",
"$",
"parameter",
",",
"$",
"parameterClass",
")",
";",
"if",
"(",
"$",
"fetched",
"!==",
"null",
")",
"{",
"return",
"$",
"fetched",
";",
"}",
"// If the parameter asks for a dependency then check parents first",
"// and then fallback to the application IOC",
"$",
"parent",
"=",
"$",
"this",
"->",
"findParent",
"(",
"$",
"parameterClass",
",",
"$",
"parents",
")",
";",
"if",
"(",
"$",
"parent",
"!==",
"null",
")",
"{",
"return",
"$",
"parent",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"customParameterResolvers",
"as",
"$",
"parameterResolver",
")",
"{",
"$",
"resolved",
"=",
"$",
"this",
"->",
"callResolver",
"(",
"$",
"parameterResolver",
",",
"[",
"$",
"parameter",
",",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"resource",
",",
"'id'",
")",
",",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"resource",
",",
"'type'",
")",
",",
"]",
")",
";",
"if",
"(",
"$",
"resolved",
"!==",
"null",
")",
"{",
"return",
"$",
"resolved",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"container",
"->",
"has",
"(",
"$",
"parameterClass",
"->",
"getName",
"(",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"parameterClass",
"->",
"getName",
"(",
")",
")",
";",
"}",
"return",
"null",
";",
"}",
",",
"$",
"parameters",
")",
";",
"}"
]
| Build the parameters needed for the function given
@param callable|string $resolver
@param array $parents
@param array $defaultParameters
@return array
@throws \Psr\Container\NotFoundExceptionInterface
@throws \Psr\Container\ContainerExceptionInterface
@throws \ReflectionException | [
"Build",
"the",
"parameters",
"needed",
"for",
"the",
"function",
"given"
]
| b1ceefc0c19ec326129126253114c121e97ca943 | https://github.com/drpdigital/json-api-parser/blob/b1ceefc0c19ec326129126253114c121e97ca943/src/ResourceResolver.php#L205-L256 |
16,035 | drpdigital/json-api-parser | src/ResourceResolver.php | ResourceResolver.findParent | protected function findParent(\ReflectionClass $class, $parents)
{
$parents = array_reverse($parents);
foreach (array_reverse($parents) as $parent) {
if ($class->getName() === get_class($parent)) {
return $parent;
}
}
foreach (array_reverse($parents) as $parent) {
if ($class->isInstance($parent)) {
return $parent;
}
}
return null;
} | php | protected function findParent(\ReflectionClass $class, $parents)
{
$parents = array_reverse($parents);
foreach (array_reverse($parents) as $parent) {
if ($class->getName() === get_class($parent)) {
return $parent;
}
}
foreach (array_reverse($parents) as $parent) {
if ($class->isInstance($parent)) {
return $parent;
}
}
return null;
} | [
"protected",
"function",
"findParent",
"(",
"\\",
"ReflectionClass",
"$",
"class",
",",
"$",
"parents",
")",
"{",
"$",
"parents",
"=",
"array_reverse",
"(",
"$",
"parents",
")",
";",
"foreach",
"(",
"array_reverse",
"(",
"$",
"parents",
")",
"as",
"$",
"parent",
")",
"{",
"if",
"(",
"$",
"class",
"->",
"getName",
"(",
")",
"===",
"get_class",
"(",
"$",
"parent",
")",
")",
"{",
"return",
"$",
"parent",
";",
"}",
"}",
"foreach",
"(",
"array_reverse",
"(",
"$",
"parents",
")",
"as",
"$",
"parent",
")",
"{",
"if",
"(",
"$",
"class",
"->",
"isInstance",
"(",
"$",
"parent",
")",
")",
"{",
"return",
"$",
"parent",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| Try to find a parent that matches the class
@param \ReflectionClass $class
@param array $parents
@return mixed|null | [
"Try",
"to",
"find",
"a",
"parent",
"that",
"matches",
"the",
"class"
]
| b1ceefc0c19ec326129126253114c121e97ca943 | https://github.com/drpdigital/json-api-parser/blob/b1ceefc0c19ec326129126253114c121e97ca943/src/ResourceResolver.php#L285-L302 |
16,036 | drpdigital/json-api-parser | src/ResourceResolver.php | ResourceResolver.getResolverForType | private function getResolverForType($type)
{
$resolver = Arr::get($this->resolvers, $type);
if ($resolver !== null) {
return $resolver;
}
$parts = explode('.', $type);
if (count($parts) > 1) {
array_shift($parts);
return $this->getResolverForType(implode('.', $parts));
}
return null;
} | php | private function getResolverForType($type)
{
$resolver = Arr::get($this->resolvers, $type);
if ($resolver !== null) {
return $resolver;
}
$parts = explode('.', $type);
if (count($parts) > 1) {
array_shift($parts);
return $this->getResolverForType(implode('.', $parts));
}
return null;
} | [
"private",
"function",
"getResolverForType",
"(",
"$",
"type",
")",
"{",
"$",
"resolver",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"resolvers",
",",
"$",
"type",
")",
";",
"if",
"(",
"$",
"resolver",
"!==",
"null",
")",
"{",
"return",
"$",
"resolver",
";",
"}",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"type",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
">",
"1",
")",
"{",
"array_shift",
"(",
"$",
"parts",
")",
";",
"return",
"$",
"this",
"->",
"getResolverForType",
"(",
"implode",
"(",
"'.'",
",",
"$",
"parts",
")",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Find the resolver for the type given
Fallback the specificity of the type until we find a match. For example
if a type of customer.products.customer_product is passed we first check
for that, then products.customer_product and then customer_product.
@param string $type
@return mixed | [
"Find",
"the",
"resolver",
"for",
"the",
"type",
"given"
]
| b1ceefc0c19ec326129126253114c121e97ca943 | https://github.com/drpdigital/json-api-parser/blob/b1ceefc0c19ec326129126253114c121e97ca943/src/ResourceResolver.php#L314-L330 |
16,037 | drpdigital/json-api-parser | src/ResourceResolver.php | ResourceResolver.callResolver | protected function callResolver($resolver, $parameters)
{
if (is_string($resolver)) {
return call_user_func_array($resolver, $parameters);
}
if (count($parameters) === 0) {
return $resolver();
}
if (count($parameters) === 1) {
return $resolver($parameters[0]);
}
if (count($parameters) === 2) {
return $resolver($parameters[0], $parameters[1]);
}
if (count($parameters) === 3) {
return $resolver($parameters[0], $parameters[1], $parameters[2]);
}
if (count($parameters) === 4) {
return $resolver($parameters[0], $parameters[1], $parameters[2], $parameters[3]);
}
return call_user_func_array($resolver, $parameters);
} | php | protected function callResolver($resolver, $parameters)
{
if (is_string($resolver)) {
return call_user_func_array($resolver, $parameters);
}
if (count($parameters) === 0) {
return $resolver();
}
if (count($parameters) === 1) {
return $resolver($parameters[0]);
}
if (count($parameters) === 2) {
return $resolver($parameters[0], $parameters[1]);
}
if (count($parameters) === 3) {
return $resolver($parameters[0], $parameters[1], $parameters[2]);
}
if (count($parameters) === 4) {
return $resolver($parameters[0], $parameters[1], $parameters[2], $parameters[3]);
}
return call_user_func_array($resolver, $parameters);
} | [
"protected",
"function",
"callResolver",
"(",
"$",
"resolver",
",",
"$",
"parameters",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"resolver",
")",
")",
"{",
"return",
"call_user_func_array",
"(",
"$",
"resolver",
",",
"$",
"parameters",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"parameters",
")",
"===",
"0",
")",
"{",
"return",
"$",
"resolver",
"(",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"parameters",
")",
"===",
"1",
")",
"{",
"return",
"$",
"resolver",
"(",
"$",
"parameters",
"[",
"0",
"]",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"parameters",
")",
"===",
"2",
")",
"{",
"return",
"$",
"resolver",
"(",
"$",
"parameters",
"[",
"0",
"]",
",",
"$",
"parameters",
"[",
"1",
"]",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"parameters",
")",
"===",
"3",
")",
"{",
"return",
"$",
"resolver",
"(",
"$",
"parameters",
"[",
"0",
"]",
",",
"$",
"parameters",
"[",
"1",
"]",
",",
"$",
"parameters",
"[",
"2",
"]",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"parameters",
")",
"===",
"4",
")",
"{",
"return",
"$",
"resolver",
"(",
"$",
"parameters",
"[",
"0",
"]",
",",
"$",
"parameters",
"[",
"1",
"]",
",",
"$",
"parameters",
"[",
"2",
"]",
",",
"$",
"parameters",
"[",
"3",
"]",
")",
";",
"}",
"return",
"call_user_func_array",
"(",
"$",
"resolver",
",",
"$",
"parameters",
")",
";",
"}"
]
| Call the resolver with the given parameters.
@param callable $resolver
@param array $parameters
@return mixed | [
"Call",
"the",
"resolver",
"with",
"the",
"given",
"parameters",
"."
]
| b1ceefc0c19ec326129126253114c121e97ca943 | https://github.com/drpdigital/json-api-parser/blob/b1ceefc0c19ec326129126253114c121e97ca943/src/ResourceResolver.php#L354-L381 |
16,038 | drpdigital/json-api-parser | src/ResourceResolver.php | ResourceResolver.recordFetchedRelationship | protected function recordFetchedRelationship(RelationshipResource $relationship)
{
$this->fetchedRelationships[] = $this->resource['type'] .
'.' . $relationship->getName() .
'.' . $relationship->getType();
} | php | protected function recordFetchedRelationship(RelationshipResource $relationship)
{
$this->fetchedRelationships[] = $this->resource['type'] .
'.' . $relationship->getName() .
'.' . $relationship->getType();
} | [
"protected",
"function",
"recordFetchedRelationship",
"(",
"RelationshipResource",
"$",
"relationship",
")",
"{",
"$",
"this",
"->",
"fetchedRelationships",
"[",
"]",
"=",
"$",
"this",
"->",
"resource",
"[",
"'type'",
"]",
".",
"'.'",
".",
"$",
"relationship",
"->",
"getName",
"(",
")",
".",
"'.'",
".",
"$",
"relationship",
"->",
"getType",
"(",
")",
";",
"}"
]
| Save that a resource has been fetched.
@param \Drp\JsonApiParser\RelationshipResource $relationship
@return void | [
"Save",
"that",
"a",
"resource",
"has",
"been",
"fetched",
"."
]
| b1ceefc0c19ec326129126253114c121e97ca943 | https://github.com/drpdigital/json-api-parser/blob/b1ceefc0c19ec326129126253114c121e97ca943/src/ResourceResolver.php#L447-L452 |
16,039 | mayoturis/properties-ini | src/Repository.php | Repository.set | public function set($key, $value) {
$this->loadIfNeeded();
$this->array[$key] = $value;
$this->saver->save($this->fileName, $this->array, $this->fileMap);
} | php | public function set($key, $value) {
$this->loadIfNeeded();
$this->array[$key] = $value;
$this->saver->save($this->fileName, $this->array, $this->fileMap);
} | [
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"loadIfNeeded",
"(",
")",
";",
"$",
"this",
"->",
"array",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"saver",
"->",
"save",
"(",
"$",
"this",
"->",
"fileName",
",",
"$",
"this",
"->",
"array",
",",
"$",
"this",
"->",
"fileMap",
")",
";",
"}"
]
| Set a given configuration value and save file
@param string $key
@param mixed $value
@return void | [
"Set",
"a",
"given",
"configuration",
"value",
"and",
"save",
"file"
]
| 79d56d8174637b1124eb90a41ffa3dca4c4a4e93 | https://github.com/mayoturis/properties-ini/blob/79d56d8174637b1124eb90a41ffa3dca4c4a4e93/src/Repository.php#L44-L50 |
16,040 | mayoturis/properties-ini | src/Repository.php | Repository.setAll | public function setAll($array) {
$this->array = $array;
$this->fileMap = null;
$this->saver->save($this->fileName, $this->array, $this->fileMap);
} | php | public function setAll($array) {
$this->array = $array;
$this->fileMap = null;
$this->saver->save($this->fileName, $this->array, $this->fileMap);
} | [
"public",
"function",
"setAll",
"(",
"$",
"array",
")",
"{",
"$",
"this",
"->",
"array",
"=",
"$",
"array",
";",
"$",
"this",
"->",
"fileMap",
"=",
"null",
";",
"$",
"this",
"->",
"saver",
"->",
"save",
"(",
"$",
"this",
"->",
"fileName",
",",
"$",
"this",
"->",
"array",
",",
"$",
"this",
"->",
"fileMap",
")",
";",
"}"
]
| Change all configuration values and save file
@param array $array Associative array with key and value
@return void | [
"Change",
"all",
"configuration",
"values",
"and",
"save",
"file"
]
| 79d56d8174637b1124eb90a41ffa3dca4c4a4e93 | https://github.com/mayoturis/properties-ini/blob/79d56d8174637b1124eb90a41ffa3dca4c4a4e93/src/Repository.php#L58-L63 |
16,041 | tonicospinelli/class-generation | src/ClassGeneration/ArgumentCollection.php | ArgumentCollection.toString | public function toString()
{
$arguments = $this->getIterator();
$params = array();
$optionals = array();
foreach ($arguments as $argument) {
if ($argument->isOptional()) {
$optionals[] = $argument->toString();
} else {
$params[] = $argument->toString();
}
}
return implode(', ', array_merge($params, $optionals));
} | php | public function toString()
{
$arguments = $this->getIterator();
$params = array();
$optionals = array();
foreach ($arguments as $argument) {
if ($argument->isOptional()) {
$optionals[] = $argument->toString();
} else {
$params[] = $argument->toString();
}
}
return implode(', ', array_merge($params, $optionals));
} | [
"public",
"function",
"toString",
"(",
")",
"{",
"$",
"arguments",
"=",
"$",
"this",
"->",
"getIterator",
"(",
")",
";",
"$",
"params",
"=",
"array",
"(",
")",
";",
"$",
"optionals",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"arguments",
"as",
"$",
"argument",
")",
"{",
"if",
"(",
"$",
"argument",
"->",
"isOptional",
"(",
")",
")",
"{",
"$",
"optionals",
"[",
"]",
"=",
"$",
"argument",
"->",
"toString",
"(",
")",
";",
"}",
"else",
"{",
"$",
"params",
"[",
"]",
"=",
"$",
"argument",
"->",
"toString",
"(",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"', '",
",",
"array_merge",
"(",
"$",
"params",
",",
"$",
"optionals",
")",
")",
";",
"}"
]
| Returns the arguments in string.
@return string | [
"Returns",
"the",
"arguments",
"in",
"string",
"."
]
| eee63bdb68c066b25b885b57b23656e809381a76 | https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/ArgumentCollection.php#L62-L76 |
16,042 | acasademont/wurfl | WURFL/CapabilitiesHolder.php | WURFL_CapabilitiesHolder.getCapability | public function getCapability($capabilityName)
{
if (isset($this->_device->capabilities[$capabilityName])) {
return $this->_device->capabilities[$capabilityName];
}
$key = $this->_device->id . "_" . $capabilityName;
$capabilityValue = $this->_cacheProvider->get($key);
if (empty($capabilityValue)) {
$capabilityValue = $this->_deviceRepository->getCapabilityForDevice($this->_device->fallBack, $capabilityName);
// save it in cache
$this->_cacheProvider->put($key, $capabilityValue);
}
// prevent useless gets when retrieving the same capability from this device again
//$this->_device->capabilities[$capabilityName] = $capabilityValue;
return $capabilityValue;
} | php | public function getCapability($capabilityName)
{
if (isset($this->_device->capabilities[$capabilityName])) {
return $this->_device->capabilities[$capabilityName];
}
$key = $this->_device->id . "_" . $capabilityName;
$capabilityValue = $this->_cacheProvider->get($key);
if (empty($capabilityValue)) {
$capabilityValue = $this->_deviceRepository->getCapabilityForDevice($this->_device->fallBack, $capabilityName);
// save it in cache
$this->_cacheProvider->put($key, $capabilityValue);
}
// prevent useless gets when retrieving the same capability from this device again
//$this->_device->capabilities[$capabilityName] = $capabilityValue;
return $capabilityValue;
} | [
"public",
"function",
"getCapability",
"(",
"$",
"capabilityName",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_device",
"->",
"capabilities",
"[",
"$",
"capabilityName",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_device",
"->",
"capabilities",
"[",
"$",
"capabilityName",
"]",
";",
"}",
"$",
"key",
"=",
"$",
"this",
"->",
"_device",
"->",
"id",
".",
"\"_\"",
".",
"$",
"capabilityName",
";",
"$",
"capabilityValue",
"=",
"$",
"this",
"->",
"_cacheProvider",
"->",
"get",
"(",
"$",
"key",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"capabilityValue",
")",
")",
"{",
"$",
"capabilityValue",
"=",
"$",
"this",
"->",
"_deviceRepository",
"->",
"getCapabilityForDevice",
"(",
"$",
"this",
"->",
"_device",
"->",
"fallBack",
",",
"$",
"capabilityName",
")",
";",
"// save it in cache",
"$",
"this",
"->",
"_cacheProvider",
"->",
"put",
"(",
"$",
"key",
",",
"$",
"capabilityValue",
")",
";",
"}",
"// prevent useless gets when retrieving the same capability from this device again",
"//$this->_device->capabilities[$capabilityName] = $capabilityValue;",
"return",
"$",
"capabilityValue",
";",
"}"
]
| Returns the value of a given capability name
@param string $capabilityName
@return string Capability value
@throws WURFLException if the value of the $capability name is illegal | [
"Returns",
"the",
"value",
"of",
"a",
"given",
"capability",
"name"
]
| 0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2 | https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/CapabilitiesHolder.php#L56-L74 |
16,043 | datasift/datasift-php | lib/DataSift/Account/Identity/Limit.php | DataSift_Account_Identity_Limit.getAll | public function getAll($service, $page = 1, $perPage = 25)
{
$params = array(
'page' => $page,
'per_page' => $perPage
);
return $this->_user->get('account/identity/limit/' . $service, $params);
} | php | public function getAll($service, $page = 1, $perPage = 25)
{
$params = array(
'page' => $page,
'per_page' => $perPage
);
return $this->_user->get('account/identity/limit/' . $service, $params);
} | [
"public",
"function",
"getAll",
"(",
"$",
"service",
",",
"$",
"page",
"=",
"1",
",",
"$",
"perPage",
"=",
"25",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'page'",
"=>",
"$",
"page",
",",
"'per_page'",
"=>",
"$",
"perPage",
")",
";",
"return",
"$",
"this",
"->",
"_user",
"->",
"get",
"(",
"'account/identity/limit/'",
".",
"$",
"service",
",",
"$",
"params",
")",
";",
"}"
]
| Get all the limits for a service
@param string $service
@param integer $page
@param integer $per_page
@return mixed | [
"Get",
"all",
"the",
"limits",
"for",
"a",
"service"
]
| 35282461ad3e54880e5940bb5afce26c75dc4bb9 | https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Account/Identity/Limit.php#L50-L58 |
16,044 | datasift/datasift-php | lib/DataSift/Account/Identity/Limit.php | DataSift_Account_Identity_Limit.create | public function create($identity, $service, $total_allowance = false, $analyze_queries = false)
{
$params = array(
'service' => $service,
);
if ($total_allowance) {
$params['total_allowance'] = $total_allowance;
}
if ($analyze_queries) {
$params['analyze_queries'] = $analyze_queries;
}
return $this->_user->post('account/identity/' . $identity . '/limit', $params);
} | php | public function create($identity, $service, $total_allowance = false, $analyze_queries = false)
{
$params = array(
'service' => $service,
);
if ($total_allowance) {
$params['total_allowance'] = $total_allowance;
}
if ($analyze_queries) {
$params['analyze_queries'] = $analyze_queries;
}
return $this->_user->post('account/identity/' . $identity . '/limit', $params);
} | [
"public",
"function",
"create",
"(",
"$",
"identity",
",",
"$",
"service",
",",
"$",
"total_allowance",
"=",
"false",
",",
"$",
"analyze_queries",
"=",
"false",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'service'",
"=>",
"$",
"service",
",",
")",
";",
"if",
"(",
"$",
"total_allowance",
")",
"{",
"$",
"params",
"[",
"'total_allowance'",
"]",
"=",
"$",
"total_allowance",
";",
"}",
"if",
"(",
"$",
"analyze_queries",
")",
"{",
"$",
"params",
"[",
"'analyze_queries'",
"]",
"=",
"$",
"analyze_queries",
";",
"}",
"return",
"$",
"this",
"->",
"_user",
"->",
"post",
"(",
"'account/identity/'",
".",
"$",
"identity",
".",
"'/limit'",
",",
"$",
"params",
")",
";",
"}"
]
| Create a limit for a service
@param string $identity
@param string $service
@param integer $total_allowance
@param integer $analyze_queries
@return mixed | [
"Create",
"a",
"limit",
"for",
"a",
"service"
]
| 35282461ad3e54880e5940bb5afce26c75dc4bb9 | https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Account/Identity/Limit.php#L70-L85 |
16,045 | datasift/datasift-php | lib/DataSift/Account/Identity/Limit.php | DataSift_Account_Identity_Limit.update | public function update($identity, $service, $total_allowance = false, $analyze_queries = false)
{
$params = array();
if ($total_allowance) {
$params['total_allowance'] = $total_allowance;
}
if ($analyze_queries) {
$params['analyze_queries'] = $analyze_queries;
}
return $response = $this->_user->put('account/identity/' . $identity . '/limit/' . $service, $params);
} | php | public function update($identity, $service, $total_allowance = false, $analyze_queries = false)
{
$params = array();
if ($total_allowance) {
$params['total_allowance'] = $total_allowance;
}
if ($analyze_queries) {
$params['analyze_queries'] = $analyze_queries;
}
return $response = $this->_user->put('account/identity/' . $identity . '/limit/' . $service, $params);
} | [
"public",
"function",
"update",
"(",
"$",
"identity",
",",
"$",
"service",
",",
"$",
"total_allowance",
"=",
"false",
",",
"$",
"analyze_queries",
"=",
"false",
")",
"{",
"$",
"params",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"total_allowance",
")",
"{",
"$",
"params",
"[",
"'total_allowance'",
"]",
"=",
"$",
"total_allowance",
";",
"}",
"if",
"(",
"$",
"analyze_queries",
")",
"{",
"$",
"params",
"[",
"'analyze_queries'",
"]",
"=",
"$",
"analyze_queries",
";",
"}",
"return",
"$",
"response",
"=",
"$",
"this",
"->",
"_user",
"->",
"put",
"(",
"'account/identity/'",
".",
"$",
"identity",
".",
"'/limit/'",
".",
"$",
"service",
",",
"$",
"params",
")",
";",
"}"
]
| Update the limit for an service
@param string $identity
@param string $service
@param integer $total_allowance
@param integer $analyze_queries
@return mixed | [
"Update",
"the",
"limit",
"for",
"an",
"service"
]
| 35282461ad3e54880e5940bb5afce26c75dc4bb9 | https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Account/Identity/Limit.php#L97-L109 |
16,046 | datasift/datasift-php | lib/DataSift/Account/Identity.php | DataSift_Account_Identity.getAll | public function getAll($label = null, $page = 1, $perPage = 25)
{
$params = array(
'page' => $page,
'per_page' => $perPage
);
if ($label !== null) {
$params['label'] = $label;
}
return $this->_user->get('account/identity', $params);
} | php | public function getAll($label = null, $page = 1, $perPage = 25)
{
$params = array(
'page' => $page,
'per_page' => $perPage
);
if ($label !== null) {
$params['label'] = $label;
}
return $this->_user->get('account/identity', $params);
} | [
"public",
"function",
"getAll",
"(",
"$",
"label",
"=",
"null",
",",
"$",
"page",
"=",
"1",
",",
"$",
"perPage",
"=",
"25",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'page'",
"=>",
"$",
"page",
",",
"'per_page'",
"=>",
"$",
"perPage",
")",
";",
"if",
"(",
"$",
"label",
"!==",
"null",
")",
"{",
"$",
"params",
"[",
"'label'",
"]",
"=",
"$",
"label",
";",
"}",
"return",
"$",
"this",
"->",
"_user",
"->",
"get",
"(",
"'account/identity'",
",",
"$",
"params",
")",
";",
"}"
]
| Gets all the identities
@param string $label
@param integer $page
@param integer $perPage
@return mixed | [
"Gets",
"all",
"the",
"identities"
]
| 35282461ad3e54880e5940bb5afce26c75dc4bb9 | https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Account/Identity.php#L49-L61 |
16,047 | datasift/datasift-php | lib/DataSift/Account/Identity.php | DataSift_Account_Identity.create | public function create($label, $master = false, $status = 'active')
{
$params = array(
'label' => $label,
'master' => $master,
'status' => $status
);
return $this->_user->post('account/identity', $params);
} | php | public function create($label, $master = false, $status = 'active')
{
$params = array(
'label' => $label,
'master' => $master,
'status' => $status
);
return $this->_user->post('account/identity', $params);
} | [
"public",
"function",
"create",
"(",
"$",
"label",
",",
"$",
"master",
"=",
"false",
",",
"$",
"status",
"=",
"'active'",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'label'",
"=>",
"$",
"label",
",",
"'master'",
"=>",
"$",
"master",
",",
"'status'",
"=>",
"$",
"status",
")",
";",
"return",
"$",
"this",
"->",
"_user",
"->",
"post",
"(",
"'account/identity'",
",",
"$",
"params",
")",
";",
"}"
]
| Creates an identity
@param string $label
@param string $master
@param string $status
@return mixed | [
"Creates",
"an",
"identity"
]
| 35282461ad3e54880e5940bb5afce26c75dc4bb9 | https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Account/Identity.php#L72-L82 |
16,048 | datasift/datasift-php | lib/DataSift/Account/Identity.php | DataSift_Account_Identity.update | public function update($identity, $label = null, $master = null, $status = null)
{
$params = array();
if (! is_null($label)) {
$params['label'] = $label;
}
if (! is_null($master)) {
$params['master'] = $master;
}
if (! is_null($status)) {
$params['status'] = $status;
}
return $this->_user->put('account/identity/' . $identity, $params);
} | php | public function update($identity, $label = null, $master = null, $status = null)
{
$params = array();
if (! is_null($label)) {
$params['label'] = $label;
}
if (! is_null($master)) {
$params['master'] = $master;
}
if (! is_null($status)) {
$params['status'] = $status;
}
return $this->_user->put('account/identity/' . $identity, $params);
} | [
"public",
"function",
"update",
"(",
"$",
"identity",
",",
"$",
"label",
"=",
"null",
",",
"$",
"master",
"=",
"null",
",",
"$",
"status",
"=",
"null",
")",
"{",
"$",
"params",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"label",
")",
")",
"{",
"$",
"params",
"[",
"'label'",
"]",
"=",
"$",
"label",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"master",
")",
")",
"{",
"$",
"params",
"[",
"'master'",
"]",
"=",
"$",
"master",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"status",
")",
")",
"{",
"$",
"params",
"[",
"'status'",
"]",
"=",
"$",
"status",
";",
"}",
"return",
"$",
"this",
"->",
"_user",
"->",
"put",
"(",
"'account/identity/'",
".",
"$",
"identity",
",",
"$",
"params",
")",
";",
"}"
]
| Updates an identity
@param string $identity
@param string $master
@param string $label
@param string $status
@return mixed | [
"Updates",
"an",
"identity"
]
| 35282461ad3e54880e5940bb5afce26c75dc4bb9 | https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/Account/Identity.php#L94-L109 |
16,049 | tonicospinelli/class-generation | src/ClassGeneration/Argument.php | Argument.createFromProperty | public static function createFromProperty(PropertyInterface $property)
{
$argument = new self();
$argument
->setName($property->getName())
->setType($property->getType());
return $argument;
} | php | public static function createFromProperty(PropertyInterface $property)
{
$argument = new self();
$argument
->setName($property->getName())
->setType($property->getType());
return $argument;
} | [
"public",
"static",
"function",
"createFromProperty",
"(",
"PropertyInterface",
"$",
"property",
")",
"{",
"$",
"argument",
"=",
"new",
"self",
"(",
")",
";",
"$",
"argument",
"->",
"setName",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
")",
"->",
"setType",
"(",
"$",
"property",
"->",
"getType",
"(",
")",
")",
";",
"return",
"$",
"argument",
";",
"}"
]
| Creates Argument from Property Object.
@param PropertyInterface $property
@return Argument | [
"Creates",
"Argument",
"from",
"Property",
"Object",
"."
]
| eee63bdb68c066b25b885b57b23656e809381a76 | https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/Argument.php#L213-L221 |
16,050 | crossjoin/Css | src/Crossjoin/Css/Reader/HtmlString.php | HtmlString.getCssContent | protected function getCssContent()
{
$styleString = "";
if (class_exists("\\DOMDocument")) {
$doc = new \DOMDocument();
$doc->loadHTML($this->getHtmlContent());
// Extract styles from the HTML file
foreach($doc->getElementsByTagName('style') as $styleNode) {
$styleString .= $styleNode->nodeValue . "\r\n";
}
} else {
throw new \RuntimeException("Required extension 'dom' seems to be missing.");
}
return $styleString;
} | php | protected function getCssContent()
{
$styleString = "";
if (class_exists("\\DOMDocument")) {
$doc = new \DOMDocument();
$doc->loadHTML($this->getHtmlContent());
// Extract styles from the HTML file
foreach($doc->getElementsByTagName('style') as $styleNode) {
$styleString .= $styleNode->nodeValue . "\r\n";
}
} else {
throw new \RuntimeException("Required extension 'dom' seems to be missing.");
}
return $styleString;
} | [
"protected",
"function",
"getCssContent",
"(",
")",
"{",
"$",
"styleString",
"=",
"\"\"",
";",
"if",
"(",
"class_exists",
"(",
"\"\\\\DOMDocument\"",
")",
")",
"{",
"$",
"doc",
"=",
"new",
"\\",
"DOMDocument",
"(",
")",
";",
"$",
"doc",
"->",
"loadHTML",
"(",
"$",
"this",
"->",
"getHtmlContent",
"(",
")",
")",
";",
"// Extract styles from the HTML file",
"foreach",
"(",
"$",
"doc",
"->",
"getElementsByTagName",
"(",
"'style'",
")",
"as",
"$",
"styleNode",
")",
"{",
"$",
"styleString",
".=",
"$",
"styleNode",
"->",
"nodeValue",
".",
"\"\\r\\n\"",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Required extension 'dom' seems to be missing.\"",
")",
";",
"}",
"return",
"$",
"styleString",
";",
"}"
]
| Gets the CSS content extracted from the HTML source content.
@return string | [
"Gets",
"the",
"CSS",
"content",
"extracted",
"from",
"the",
"HTML",
"source",
"content",
"."
]
| 7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3 | https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Reader/HtmlString.php#L54-L71 |
16,051 | rozdol/bi | src/Utils/Crypt.php | Crypt.create_hash | function create_hash($password)
{
// format: algorithm:iterations:salt:hash
//$salt = base64_encode(mcrypt_create_iv(PBKDF2_SALT_BYTES, MCRYPT_DEV_URANDOM));
$encrypt_method = "AES-256-CBC";
$key = hash('sha256', $secret_key);
$iv = substr(hash('sha256', $secret_iv), 0, 16);
$salt = base64_encode(openssl_encrypt($string, $encrypt_method, $key, 0, $iv));
return PBKDF2_HASH_ALGORITHM . ":" . PBKDF2_ITERATIONS . ":" . $salt . ":" .
base64_encode($this->pbkdf2(
PBKDF2_HASH_ALGORITHM,
$password,
$salt,
PBKDF2_ITERATIONS,
PBKDF2_HASH_BYTES,
true
));
} | php | function create_hash($password)
{
// format: algorithm:iterations:salt:hash
//$salt = base64_encode(mcrypt_create_iv(PBKDF2_SALT_BYTES, MCRYPT_DEV_URANDOM));
$encrypt_method = "AES-256-CBC";
$key = hash('sha256', $secret_key);
$iv = substr(hash('sha256', $secret_iv), 0, 16);
$salt = base64_encode(openssl_encrypt($string, $encrypt_method, $key, 0, $iv));
return PBKDF2_HASH_ALGORITHM . ":" . PBKDF2_ITERATIONS . ":" . $salt . ":" .
base64_encode($this->pbkdf2(
PBKDF2_HASH_ALGORITHM,
$password,
$salt,
PBKDF2_ITERATIONS,
PBKDF2_HASH_BYTES,
true
));
} | [
"function",
"create_hash",
"(",
"$",
"password",
")",
"{",
"// format: algorithm:iterations:salt:hash",
"//$salt = base64_encode(mcrypt_create_iv(PBKDF2_SALT_BYTES, MCRYPT_DEV_URANDOM));",
"$",
"encrypt_method",
"=",
"\"AES-256-CBC\"",
";",
"$",
"key",
"=",
"hash",
"(",
"'sha256'",
",",
"$",
"secret_key",
")",
";",
"$",
"iv",
"=",
"substr",
"(",
"hash",
"(",
"'sha256'",
",",
"$",
"secret_iv",
")",
",",
"0",
",",
"16",
")",
";",
"$",
"salt",
"=",
"base64_encode",
"(",
"openssl_encrypt",
"(",
"$",
"string",
",",
"$",
"encrypt_method",
",",
"$",
"key",
",",
"0",
",",
"$",
"iv",
")",
")",
";",
"return",
"PBKDF2_HASH_ALGORITHM",
".",
"\":\"",
".",
"PBKDF2_ITERATIONS",
".",
"\":\"",
".",
"$",
"salt",
".",
"\":\"",
".",
"base64_encode",
"(",
"$",
"this",
"->",
"pbkdf2",
"(",
"PBKDF2_HASH_ALGORITHM",
",",
"$",
"password",
",",
"$",
"salt",
",",
"PBKDF2_ITERATIONS",
",",
"PBKDF2_HASH_BYTES",
",",
"true",
")",
")",
";",
"}"
]
| These constants may be changed without breaking existing hashes. | [
"These",
"constants",
"may",
"be",
"changed",
"without",
"breaking",
"existing",
"hashes",
"."
]
| f63d6b219cc4a7bb25b1865905a2a888ce6ce855 | https://github.com/rozdol/bi/blob/f63d6b219cc4a7bb25b1865905a2a888ce6ce855/src/Utils/Crypt.php#L43-L63 |
16,052 | cronario/cronario | src/Facade.php | Facade.addProducer | public static function addProducer(Producer $producer)
{
$appId = $producer->getAppId();
if (array_key_exists($appId, static::$producers)) {
throw new Exception\FacadeException("Producer with {$appId} already exists!");
}
static::$producers[$appId] = $producer;
return true;
} | php | public static function addProducer(Producer $producer)
{
$appId = $producer->getAppId();
if (array_key_exists($appId, static::$producers)) {
throw new Exception\FacadeException("Producer with {$appId} already exists!");
}
static::$producers[$appId] = $producer;
return true;
} | [
"public",
"static",
"function",
"addProducer",
"(",
"Producer",
"$",
"producer",
")",
"{",
"$",
"appId",
"=",
"$",
"producer",
"->",
"getAppId",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"appId",
",",
"static",
"::",
"$",
"producers",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"FacadeException",
"(",
"\"Producer with {$appId} already exists!\"",
")",
";",
"}",
"static",
"::",
"$",
"producers",
"[",
"$",
"appId",
"]",
"=",
"$",
"producer",
";",
"return",
"true",
";",
"}"
]
| Add producer to facade
@param Producer $producer
@return boolean
@throws Exception\FacadeException | [
"Add",
"producer",
"to",
"facade"
]
| 954df60e95efd3085269331d435e8ce6f4980441 | https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Facade.php#L34-L45 |
16,053 | cronario/cronario | src/Facade.php | Facade.addBuilder | public static function addBuilder($appId, $builderFunction)
{
if (array_key_exists($appId, static::$builders)) {
throw new Exception\FacadeException("Builder with {$appId} already exists!");
}
if (!is_callable($builderFunction)) {
throw new Exception\FacadeException("Builder function for {$appId} is not callable!");
}
static::$builders[$appId] = $builderFunction;
return true;
} | php | public static function addBuilder($appId, $builderFunction)
{
if (array_key_exists($appId, static::$builders)) {
throw new Exception\FacadeException("Builder with {$appId} already exists!");
}
if (!is_callable($builderFunction)) {
throw new Exception\FacadeException("Builder function for {$appId} is not callable!");
}
static::$builders[$appId] = $builderFunction;
return true;
} | [
"public",
"static",
"function",
"addBuilder",
"(",
"$",
"appId",
",",
"$",
"builderFunction",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"appId",
",",
"static",
"::",
"$",
"builders",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"FacadeException",
"(",
"\"Builder with {$appId} already exists!\"",
")",
";",
"}",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"builderFunction",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"FacadeException",
"(",
"\"Builder function for {$appId} is not callable!\"",
")",
";",
"}",
"static",
"::",
"$",
"builders",
"[",
"$",
"appId",
"]",
"=",
"$",
"builderFunction",
";",
"return",
"true",
";",
"}"
]
| Add Builder to facade builder scope
@param $appId
@param $builderFunction
@return boolean
@throws Exception\FacadeException | [
"Add",
"Builder",
"to",
"facade",
"builder",
"scope"
]
| 954df60e95efd3085269331d435e8ce6f4980441 | https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Facade.php#L56-L69 |
16,054 | cronario/cronario | src/Facade.php | Facade.getProducer | public static function getProducer($appId = Producer::DEFAULT_APP_ID)
{
if (null === $appId) {
$appId = Producer::DEFAULT_APP_ID;
}
if (!array_key_exists($appId, static::$producers)) {
if (array_key_exists($appId, static::$builders)) {
$func = static::$builders[$appId];
static::addProducer($func($appId));
unset(static::$builders[$appId]);
return static::getProducer($appId);
}
throw new Exception\FacadeException("Producer with appId: '{$appId}' not exists yet!");
}
return static::$producers[$appId];
} | php | public static function getProducer($appId = Producer::DEFAULT_APP_ID)
{
if (null === $appId) {
$appId = Producer::DEFAULT_APP_ID;
}
if (!array_key_exists($appId, static::$producers)) {
if (array_key_exists($appId, static::$builders)) {
$func = static::$builders[$appId];
static::addProducer($func($appId));
unset(static::$builders[$appId]);
return static::getProducer($appId);
}
throw new Exception\FacadeException("Producer with appId: '{$appId}' not exists yet!");
}
return static::$producers[$appId];
} | [
"public",
"static",
"function",
"getProducer",
"(",
"$",
"appId",
"=",
"Producer",
"::",
"DEFAULT_APP_ID",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"appId",
")",
"{",
"$",
"appId",
"=",
"Producer",
"::",
"DEFAULT_APP_ID",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"appId",
",",
"static",
"::",
"$",
"producers",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"appId",
",",
"static",
"::",
"$",
"builders",
")",
")",
"{",
"$",
"func",
"=",
"static",
"::",
"$",
"builders",
"[",
"$",
"appId",
"]",
";",
"static",
"::",
"addProducer",
"(",
"$",
"func",
"(",
"$",
"appId",
")",
")",
";",
"unset",
"(",
"static",
"::",
"$",
"builders",
"[",
"$",
"appId",
"]",
")",
";",
"return",
"static",
"::",
"getProducer",
"(",
"$",
"appId",
")",
";",
"}",
"throw",
"new",
"Exception",
"\\",
"FacadeException",
"(",
"\"Producer with appId: '{$appId}' not exists yet!\"",
")",
";",
"}",
"return",
"static",
"::",
"$",
"producers",
"[",
"$",
"appId",
"]",
";",
"}"
]
| Get producer by id
@param string $appId
@return Producer|null
@throws Exception\FacadeException | [
"Get",
"producer",
"by",
"id"
]
| 954df60e95efd3085269331d435e8ce6f4980441 | https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Facade.php#L79-L99 |
16,055 | cronario/cronario | src/Facade.php | Facade.getProducersStats | public static function getProducersStats()
{
$producersStats = [];
foreach (static::$producers as $appId => $producer) {
/** @var $producer Producer */
$producersStats[$appId] = $producer->getStats();
}
return $producersStats;
} | php | public static function getProducersStats()
{
$producersStats = [];
foreach (static::$producers as $appId => $producer) {
/** @var $producer Producer */
$producersStats[$appId] = $producer->getStats();
}
return $producersStats;
} | [
"public",
"static",
"function",
"getProducersStats",
"(",
")",
"{",
"$",
"producersStats",
"=",
"[",
"]",
";",
"foreach",
"(",
"static",
"::",
"$",
"producers",
"as",
"$",
"appId",
"=>",
"$",
"producer",
")",
"{",
"/** @var $producer Producer */",
"$",
"producersStats",
"[",
"$",
"appId",
"]",
"=",
"$",
"producer",
"->",
"getStats",
"(",
")",
";",
"}",
"return",
"$",
"producersStats",
";",
"}"
]
| Get producer statistic
@return array | [
"Get",
"producer",
"statistic"
]
| 954df60e95efd3085269331d435e8ce6f4980441 | https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Facade.php#L134-L143 |
16,056 | cronario/cronario | src/Facade.php | Facade.getQueuesStats | public static function getQueuesStats()
{
$queuesStats = [];
foreach (static::$producers as $appId => $producer) {
/** @var $producer Producer */
$queuesStats[$appId] = $producer->getQueue()->getStats();
}
return $queuesStats;
} | php | public static function getQueuesStats()
{
$queuesStats = [];
foreach (static::$producers as $appId => $producer) {
/** @var $producer Producer */
$queuesStats[$appId] = $producer->getQueue()->getStats();
}
return $queuesStats;
} | [
"public",
"static",
"function",
"getQueuesStats",
"(",
")",
"{",
"$",
"queuesStats",
"=",
"[",
"]",
";",
"foreach",
"(",
"static",
"::",
"$",
"producers",
"as",
"$",
"appId",
"=>",
"$",
"producer",
")",
"{",
"/** @var $producer Producer */",
"$",
"queuesStats",
"[",
"$",
"appId",
"]",
"=",
"$",
"producer",
"->",
"getQueue",
"(",
")",
"->",
"getStats",
"(",
")",
";",
"}",
"return",
"$",
"queuesStats",
";",
"}"
]
| Get queues statistic
@return array | [
"Get",
"queues",
"statistic"
]
| 954df60e95efd3085269331d435e8ce6f4980441 | https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Facade.php#L150-L159 |
16,057 | cronario/cronario | src/Facade.php | Facade.getJobsReserved | public static function getJobsReserved()
{
$jobsReserved = [];
foreach (static::$producers as $appId => $producer) {
/** @var $producer Producer */
$jobsReserved[$appId] = $producer->getQueue()->getJobReserved();
}
return $jobsReserved;
} | php | public static function getJobsReserved()
{
$jobsReserved = [];
foreach (static::$producers as $appId => $producer) {
/** @var $producer Producer */
$jobsReserved[$appId] = $producer->getQueue()->getJobReserved();
}
return $jobsReserved;
} | [
"public",
"static",
"function",
"getJobsReserved",
"(",
")",
"{",
"$",
"jobsReserved",
"=",
"[",
"]",
";",
"foreach",
"(",
"static",
"::",
"$",
"producers",
"as",
"$",
"appId",
"=>",
"$",
"producer",
")",
"{",
"/** @var $producer Producer */",
"$",
"jobsReserved",
"[",
"$",
"appId",
"]",
"=",
"$",
"producer",
"->",
"getQueue",
"(",
")",
"->",
"getJobReserved",
"(",
")",
";",
"}",
"return",
"$",
"jobsReserved",
";",
"}"
]
| Get all reserved jobs
@return array | [
"Get",
"all",
"reserved",
"jobs"
]
| 954df60e95efd3085269331d435e8ce6f4980441 | https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Facade.php#L166-L175 |
16,058 | cronario/cronario | src/Facade.php | Facade.getManagersStats | public static function getManagersStats()
{
$managersStats = [];
foreach (static::$producers as $appId => $producer) {
/** @var $producer Producer */
$redis = $producer->getRedis();
$keys = [
'stat' => $redis->keys(Manager::REDIS_NS_STATS . '*'),
'live' => $redis->keys(Manager::REDIS_NS_LIVE . '*')
];
foreach ($keys as $type => $statsKeys) {
foreach ($statsKeys as $statsKey) {
$parse = Manager::parseManagerStatKey($statsKey);
if ($appId != $parse['appId']) {
continue;
}
$statsItemData = $redis->hgetall($statsKey);
$statsItemData['workerClass'] = $parse['workerClass'];
$statsItemData['appId'] = $parse['appId'];
$managersStats[$parse['appId']][$type][] = $statsItemData;
}
}
}
return $managersStats;
} | php | public static function getManagersStats()
{
$managersStats = [];
foreach (static::$producers as $appId => $producer) {
/** @var $producer Producer */
$redis = $producer->getRedis();
$keys = [
'stat' => $redis->keys(Manager::REDIS_NS_STATS . '*'),
'live' => $redis->keys(Manager::REDIS_NS_LIVE . '*')
];
foreach ($keys as $type => $statsKeys) {
foreach ($statsKeys as $statsKey) {
$parse = Manager::parseManagerStatKey($statsKey);
if ($appId != $parse['appId']) {
continue;
}
$statsItemData = $redis->hgetall($statsKey);
$statsItemData['workerClass'] = $parse['workerClass'];
$statsItemData['appId'] = $parse['appId'];
$managersStats[$parse['appId']][$type][] = $statsItemData;
}
}
}
return $managersStats;
} | [
"public",
"static",
"function",
"getManagersStats",
"(",
")",
"{",
"$",
"managersStats",
"=",
"[",
"]",
";",
"foreach",
"(",
"static",
"::",
"$",
"producers",
"as",
"$",
"appId",
"=>",
"$",
"producer",
")",
"{",
"/** @var $producer Producer */",
"$",
"redis",
"=",
"$",
"producer",
"->",
"getRedis",
"(",
")",
";",
"$",
"keys",
"=",
"[",
"'stat'",
"=>",
"$",
"redis",
"->",
"keys",
"(",
"Manager",
"::",
"REDIS_NS_STATS",
".",
"'*'",
")",
",",
"'live'",
"=>",
"$",
"redis",
"->",
"keys",
"(",
"Manager",
"::",
"REDIS_NS_LIVE",
".",
"'*'",
")",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"type",
"=>",
"$",
"statsKeys",
")",
"{",
"foreach",
"(",
"$",
"statsKeys",
"as",
"$",
"statsKey",
")",
"{",
"$",
"parse",
"=",
"Manager",
"::",
"parseManagerStatKey",
"(",
"$",
"statsKey",
")",
";",
"if",
"(",
"$",
"appId",
"!=",
"$",
"parse",
"[",
"'appId'",
"]",
")",
"{",
"continue",
";",
"}",
"$",
"statsItemData",
"=",
"$",
"redis",
"->",
"hgetall",
"(",
"$",
"statsKey",
")",
";",
"$",
"statsItemData",
"[",
"'workerClass'",
"]",
"=",
"$",
"parse",
"[",
"'workerClass'",
"]",
";",
"$",
"statsItemData",
"[",
"'appId'",
"]",
"=",
"$",
"parse",
"[",
"'appId'",
"]",
";",
"$",
"managersStats",
"[",
"$",
"parse",
"[",
"'appId'",
"]",
"]",
"[",
"$",
"type",
"]",
"[",
"]",
"=",
"$",
"statsItemData",
";",
"}",
"}",
"}",
"return",
"$",
"managersStats",
";",
"}"
]
| Get all managers statistic
@return array | [
"Get",
"all",
"managers",
"statistic"
]
| 954df60e95efd3085269331d435e8ce6f4980441 | https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/Facade.php#L183-L213 |
16,059 | FrenchFrogs/framework | src/Form/Renderer/Bootstrap.php | Bootstrap.link | public function link(Form\Element\Link $element)
{
$html = '<label>' . $element->getLabel() . '</label>';
$html .= '<p>' . html('a', ['href' => $element->getValue(), 'target' => '_blank'], $element->getValue()) . '</p>';
$class = Style::FORM_GROUP_CLASS;
$html = html('div', compact('class'), $html);
return $html;
} | php | public function link(Form\Element\Link $element)
{
$html = '<label>' . $element->getLabel() . '</label>';
$html .= '<p>' . html('a', ['href' => $element->getValue(), 'target' => '_blank'], $element->getValue()) . '</p>';
$class = Style::FORM_GROUP_CLASS;
$html = html('div', compact('class'), $html);
return $html;
} | [
"public",
"function",
"link",
"(",
"Form",
"\\",
"Element",
"\\",
"Link",
"$",
"element",
")",
"{",
"$",
"html",
"=",
"'<label>'",
".",
"$",
"element",
"->",
"getLabel",
"(",
")",
".",
"'</label>'",
";",
"$",
"html",
".=",
"'<p>'",
".",
"html",
"(",
"'a'",
",",
"[",
"'href'",
"=>",
"$",
"element",
"->",
"getValue",
"(",
")",
",",
"'target'",
"=>",
"'_blank'",
"]",
",",
"$",
"element",
"->",
"getValue",
"(",
")",
")",
".",
"'</p>'",
";",
"$",
"class",
"=",
"Style",
"::",
"FORM_GROUP_CLASS",
";",
"$",
"html",
"=",
"html",
"(",
"'div'",
",",
"compact",
"(",
"'class'",
")",
",",
"$",
"html",
")",
";",
"return",
"$",
"html",
";",
"}"
]
| Render a link element
@param \FrenchFrogs\Form\Element\Link $element
@return string | [
"Render",
"a",
"link",
"element"
]
| a4838c698a5600437e87dac6d35ba8ebe32c4395 | https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Renderer/Bootstrap.php#L274-L284 |
16,060 | FrenchFrogs/framework | src/Form/Renderer/Bootstrap.php | Bootstrap.date | public function date(Form\Element\Date $element)
{
// Error
if($hasError = !$element->getValidator()->isValid()){
$element->removeAttribute('data-trigger');//Si il y avait un popoover au départ on le surcharge par un tooltip
if(empty($element->getAttribute('data-placement'))){$element->addAttribute('data-placement','bottom');}
$message = '';
foreach($element->getValidator()->getErrors() as $error){
$message .= $error . ' ';
}
$element->addAttribute('data-original-title',$message);
$element->addAttribute('data-toggle', 'tooltip');
}
$element->addClass('date-picker');
// rendu principal
$element->addClass(Style::FORM_ELEMENT_CONTROL);
$label = '';
$element->addAttribute('value', $element->getDisplayValue());
if ($element->getForm()->hasLabel()) {
$label = '<label for="' . $element->getName() . '">' . $element->getLabel() . ($element->hasRule('required') ? ' *' : '') . '</label>';
}
$html = $label . html('input', $element->getAttributes());
$class = Style::FORM_GROUP_CLASS;
if ($hasError) {
$class .= ' ' .Style::FORM_GROUP_ERROR;
}
$html = html('div', compact('class'), $html);
return $html;
} | php | public function date(Form\Element\Date $element)
{
// Error
if($hasError = !$element->getValidator()->isValid()){
$element->removeAttribute('data-trigger');//Si il y avait un popoover au départ on le surcharge par un tooltip
if(empty($element->getAttribute('data-placement'))){$element->addAttribute('data-placement','bottom');}
$message = '';
foreach($element->getValidator()->getErrors() as $error){
$message .= $error . ' ';
}
$element->addAttribute('data-original-title',$message);
$element->addAttribute('data-toggle', 'tooltip');
}
$element->addClass('date-picker');
// rendu principal
$element->addClass(Style::FORM_ELEMENT_CONTROL);
$label = '';
$element->addAttribute('value', $element->getDisplayValue());
if ($element->getForm()->hasLabel()) {
$label = '<label for="' . $element->getName() . '">' . $element->getLabel() . ($element->hasRule('required') ? ' *' : '') . '</label>';
}
$html = $label . html('input', $element->getAttributes());
$class = Style::FORM_GROUP_CLASS;
if ($hasError) {
$class .= ' ' .Style::FORM_GROUP_ERROR;
}
$html = html('div', compact('class'), $html);
return $html;
} | [
"public",
"function",
"date",
"(",
"Form",
"\\",
"Element",
"\\",
"Date",
"$",
"element",
")",
"{",
"// Error",
"if",
"(",
"$",
"hasError",
"=",
"!",
"$",
"element",
"->",
"getValidator",
"(",
")",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"element",
"->",
"removeAttribute",
"(",
"'data-trigger'",
")",
";",
"//Si il y avait un popoover au départ on le surcharge par un tooltip",
"if",
"(",
"empty",
"(",
"$",
"element",
"->",
"getAttribute",
"(",
"'data-placement'",
")",
")",
")",
"{",
"$",
"element",
"->",
"addAttribute",
"(",
"'data-placement'",
",",
"'bottom'",
")",
";",
"}",
"$",
"message",
"=",
"''",
";",
"foreach",
"(",
"$",
"element",
"->",
"getValidator",
"(",
")",
"->",
"getErrors",
"(",
")",
"as",
"$",
"error",
")",
"{",
"$",
"message",
".=",
"$",
"error",
".",
"' '",
";",
"}",
"$",
"element",
"->",
"addAttribute",
"(",
"'data-original-title'",
",",
"$",
"message",
")",
";",
"$",
"element",
"->",
"addAttribute",
"(",
"'data-toggle'",
",",
"'tooltip'",
")",
";",
"}",
"$",
"element",
"->",
"addClass",
"(",
"'date-picker'",
")",
";",
"// rendu principal",
"$",
"element",
"->",
"addClass",
"(",
"Style",
"::",
"FORM_ELEMENT_CONTROL",
")",
";",
"$",
"label",
"=",
"''",
";",
"$",
"element",
"->",
"addAttribute",
"(",
"'value'",
",",
"$",
"element",
"->",
"getDisplayValue",
"(",
")",
")",
";",
"if",
"(",
"$",
"element",
"->",
"getForm",
"(",
")",
"->",
"hasLabel",
"(",
")",
")",
"{",
"$",
"label",
"=",
"'<label for=\"'",
".",
"$",
"element",
"->",
"getName",
"(",
")",
".",
"'\">'",
".",
"$",
"element",
"->",
"getLabel",
"(",
")",
".",
"(",
"$",
"element",
"->",
"hasRule",
"(",
"'required'",
")",
"?",
"' *'",
":",
"''",
")",
".",
"'</label>'",
";",
"}",
"$",
"html",
"=",
"$",
"label",
".",
"html",
"(",
"'input'",
",",
"$",
"element",
"->",
"getAttributes",
"(",
")",
")",
";",
"$",
"class",
"=",
"Style",
"::",
"FORM_GROUP_CLASS",
";",
"if",
"(",
"$",
"hasError",
")",
"{",
"$",
"class",
".=",
"' '",
".",
"Style",
"::",
"FORM_GROUP_ERROR",
";",
"}",
"$",
"html",
"=",
"html",
"(",
"'div'",
",",
"compact",
"(",
"'class'",
")",
",",
"$",
"html",
")",
";",
"return",
"$",
"html",
";",
"}"
]
| Render a date element
@param \FrenchFrogs\Form\Element\Date $element
@return string | [
"Render",
"a",
"date",
"element"
]
| a4838c698a5600437e87dac6d35ba8ebe32c4395 | https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Renderer/Bootstrap.php#L465-L499 |
16,061 | dengyongbin/loopeer-lib | src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/utils.php | PushUtils.getDayTimestamp | public static function getDayTimestamp($now = null, $offset = 8) {
$now = $now === null ? time() : $now;
$gtm0 = $now - ($now % 86400); // GTM 0
$dayline = ($now - $gtm0) / 3600;
// 时差跨天
if ($dayline + $offset > 23) {
return $gtm0 + 86400 + $offset * 3600 * - 1;
} else {
return $gtm0 + $offset * 3600 * - 1;
}
} | php | public static function getDayTimestamp($now = null, $offset = 8) {
$now = $now === null ? time() : $now;
$gtm0 = $now - ($now % 86400); // GTM 0
$dayline = ($now - $gtm0) / 3600;
// 时差跨天
if ($dayline + $offset > 23) {
return $gtm0 + 86400 + $offset * 3600 * - 1;
} else {
return $gtm0 + $offset * 3600 * - 1;
}
} | [
"public",
"static",
"function",
"getDayTimestamp",
"(",
"$",
"now",
"=",
"null",
",",
"$",
"offset",
"=",
"8",
")",
"{",
"$",
"now",
"=",
"$",
"now",
"===",
"null",
"?",
"time",
"(",
")",
":",
"$",
"now",
";",
"$",
"gtm0",
"=",
"$",
"now",
"-",
"(",
"$",
"now",
"%",
"86400",
")",
";",
"// GTM 0",
"$",
"dayline",
"=",
"(",
"$",
"now",
"-",
"$",
"gtm0",
")",
"/",
"3600",
";",
"// 时差跨天",
"if",
"(",
"$",
"dayline",
"+",
"$",
"offset",
">",
"23",
")",
"{",
"return",
"$",
"gtm0",
"+",
"86400",
"+",
"$",
"offset",
"*",
"3600",
"*",
"-",
"1",
";",
"}",
"else",
"{",
"return",
"$",
"gtm0",
"+",
"$",
"offset",
"*",
"3600",
"*",
"-",
"1",
";",
"}",
"}"
]
| get the timestamp at current dat start
NOTE: the result start at the timezone (GTM +8) 00:00:00, not the GTM 0.
@param
{number} offset, offset of timezone;
@return number | [
"get",
"the",
"timestamp",
"at",
"current",
"dat",
"start"
]
| 4609338f6a48666ca96ee380509a5b5cb066808f | https://github.com/dengyongbin/loopeer-lib/blob/4609338f6a48666ca96ee380509a5b5cb066808f/src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/utils.php#L29-L42 |
16,062 | dengyongbin/loopeer-lib | src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/utils.php | PushUtils.getHourTimestamp | public static function getHourTimestamp($now = null) {
$now = $now === null ? time() : $now;
$diff = $now % 3600; // 1 * 60 * 60;
return $now - $diff;
} | php | public static function getHourTimestamp($now = null) {
$now = $now === null ? time() : $now;
$diff = $now % 3600; // 1 * 60 * 60;
return $now - $diff;
} | [
"public",
"static",
"function",
"getHourTimestamp",
"(",
"$",
"now",
"=",
"null",
")",
"{",
"$",
"now",
"=",
"$",
"now",
"===",
"null",
"?",
"time",
"(",
")",
":",
"$",
"now",
";",
"$",
"diff",
"=",
"$",
"now",
"%",
"3600",
";",
"// 1 * 60 * 60;",
"return",
"$",
"now",
"-",
"$",
"diff",
";",
"}"
]
| get the timestamp at current hour start
@param int $num 指定时间
@return number | [
"get",
"the",
"timestamp",
"at",
"current",
"hour",
"start"
]
| 4609338f6a48666ca96ee380509a5b5cb066808f | https://github.com/dengyongbin/loopeer-lib/blob/4609338f6a48666ca96ee380509a5b5cb066808f/src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/utils.php#L48-L52 |
16,063 | dengyongbin/loopeer-lib | src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/utils.php | PushUtils.getMinuteTimestamp | public static function getMinuteTimestamp($now = null) {
$now = $now === null ? time() : $now;
$diff = $now % 60;
return $now - $diff;
} | php | public static function getMinuteTimestamp($now = null) {
$now = $now === null ? time() : $now;
$diff = $now % 60;
return $now - $diff;
} | [
"public",
"static",
"function",
"getMinuteTimestamp",
"(",
"$",
"now",
"=",
"null",
")",
"{",
"$",
"now",
"=",
"$",
"now",
"===",
"null",
"?",
"time",
"(",
")",
":",
"$",
"now",
";",
"$",
"diff",
"=",
"$",
"now",
"%",
"60",
";",
"return",
"$",
"now",
"-",
"$",
"diff",
";",
"}"
]
| get the timestamp at current minute start
@param int $num 指定时间
@return number | [
"get",
"the",
"timestamp",
"at",
"current",
"minute",
"start"
]
| 4609338f6a48666ca96ee380509a5b5cb066808f | https://github.com/dengyongbin/loopeer-lib/blob/4609338f6a48666ca96ee380509a5b5cb066808f/src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/utils.php#L58-L62 |
16,064 | bfitech/zapcore | src/Common.php | Common.exec | final public static function exec(string $cmd, array $args=[]) {
foreach ($args as $key => $val)
$args[$key] = escapeshellarg($val);
$cmd = vsprintf($cmd, $args);
exec($cmd, $output, $retcode);
if ($retcode !== 0)
return false;
return $output;
} | php | final public static function exec(string $cmd, array $args=[]) {
foreach ($args as $key => $val)
$args[$key] = escapeshellarg($val);
$cmd = vsprintf($cmd, $args);
exec($cmd, $output, $retcode);
if ($retcode !== 0)
return false;
return $output;
} | [
"final",
"public",
"static",
"function",
"exec",
"(",
"string",
"$",
"cmd",
",",
"array",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"args",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"$",
"args",
"[",
"$",
"key",
"]",
"=",
"escapeshellarg",
"(",
"$",
"val",
")",
";",
"$",
"cmd",
"=",
"vsprintf",
"(",
"$",
"cmd",
",",
"$",
"args",
")",
";",
"exec",
"(",
"$",
"cmd",
",",
"$",
"output",
",",
"$",
"retcode",
")",
";",
"if",
"(",
"$",
"retcode",
"!==",
"0",
")",
"return",
"false",
";",
"return",
"$",
"output",
";",
"}"
]
| Execute arbitrary shell commands. Use with care.
@param string $cmd Command with '%s' as parameter placeholders.
@param array $args List of parameters to replace the
placeholders in command.
@return bool|array False on failure, stdout lines otherwise. | [
"Execute",
"arbitrary",
"shell",
"commands",
".",
"Use",
"with",
"care",
"."
]
| 0ae4cb9370876ab3583556bf272063685ec57948 | https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/src/Common.php#L28-L36 |
16,065 | bfitech/zapcore | src/Common.php | Common.get_mimetype | final public static function get_mimetype(
string $fname, string $path_to_file=null
) {
if (null === $mime = self::_mime_extension($fname))
return self::_mime_magic($fname, $path_to_file);
return $mime;
} | php | final public static function get_mimetype(
string $fname, string $path_to_file=null
) {
if (null === $mime = self::_mime_extension($fname))
return self::_mime_magic($fname, $path_to_file);
return $mime;
} | [
"final",
"public",
"static",
"function",
"get_mimetype",
"(",
"string",
"$",
"fname",
",",
"string",
"$",
"path_to_file",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"mime",
"=",
"self",
"::",
"_mime_extension",
"(",
"$",
"fname",
")",
")",
"return",
"self",
"::",
"_mime_magic",
"(",
"$",
"fname",
",",
"$",
"path_to_file",
")",
";",
"return",
"$",
"mime",
";",
"}"
]
| Find a mime type.
@param string $fname The file name.
@param string $path_to_file Path to `file`. Useful if
you have it outside PATH.
@return string The MIME type or application/octet-stream. | [
"Find",
"a",
"mime",
"type",
"."
]
| 0ae4cb9370876ab3583556bf272063685ec57948 | https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/src/Common.php#L46-L53 |
16,066 | bfitech/zapcore | src/Common.php | Common._mime_extension | private static function _mime_extension(string $fname) {
$pinfo = pathinfo($fname);
// @codeCoverageIgnoreStart
if (!isset($pinfo['extension']))
return null;
// @codeCoverageIgnoreEnd
# Because these things are magically ambiguous, we'll
# resort to extension.
switch (strtolower($pinfo['extension'])) {
case 'css':
return 'text/css';
case 'js':
return 'application/javascript';
case 'json':
return 'application/json';
case 'htm':
case 'html':
# always assume UTF-8
return 'text/html; charset=utf-8';
}
return null;
} | php | private static function _mime_extension(string $fname) {
$pinfo = pathinfo($fname);
// @codeCoverageIgnoreStart
if (!isset($pinfo['extension']))
return null;
// @codeCoverageIgnoreEnd
# Because these things are magically ambiguous, we'll
# resort to extension.
switch (strtolower($pinfo['extension'])) {
case 'css':
return 'text/css';
case 'js':
return 'application/javascript';
case 'json':
return 'application/json';
case 'htm':
case 'html':
# always assume UTF-8
return 'text/html; charset=utf-8';
}
return null;
} | [
"private",
"static",
"function",
"_mime_extension",
"(",
"string",
"$",
"fname",
")",
"{",
"$",
"pinfo",
"=",
"pathinfo",
"(",
"$",
"fname",
")",
";",
"// @codeCoverageIgnoreStart",
"if",
"(",
"!",
"isset",
"(",
"$",
"pinfo",
"[",
"'extension'",
"]",
")",
")",
"return",
"null",
";",
"// @codeCoverageIgnoreEnd",
"# Because these things are magically ambiguous, we'll",
"# resort to extension.",
"switch",
"(",
"strtolower",
"(",
"$",
"pinfo",
"[",
"'extension'",
"]",
")",
")",
"{",
"case",
"'css'",
":",
"return",
"'text/css'",
";",
"case",
"'js'",
":",
"return",
"'application/javascript'",
";",
"case",
"'json'",
":",
"return",
"'application/json'",
";",
"case",
"'htm'",
":",
"case",
"'html'",
":",
"# always assume UTF-8",
"return",
"'text/html; charset=utf-8'",
";",
"}",
"return",
"null",
";",
"}"
]
| Get MIME by extension.
Useful for serving typical text files that don't have unique
magic numbers. | [
"Get",
"MIME",
"by",
"extension",
"."
]
| 0ae4cb9370876ab3583556bf272063685ec57948 | https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/src/Common.php#L61-L82 |
16,067 | bfitech/zapcore | src/Common.php | Common._mime_magic | private static function _mime_magic(
string $fname, string $path_to_file=null
) {
# with builtin
if (
function_exists('mime_content_type') &&
($mime = @mime_content_type($fname)) &&
$mime != 'application/octet-stream'
)
return $mime;
# with `file`, skip coverage because `file` is usually
# not available on CI
// @codeCoverageIgnoreStart
if ($path_to_file && is_executable($path_to_file)) {
$bin = $path_to_file;
} elseif (!($bin = self::exec("bash -c 'type -p file'")[0])) {
return 'application/octet-stream';
}
if (
($mimes = self::exec('%s -bip %s', [$bin, $fname])) &&
preg_match('!^[a-z0-9\-]+/!i', $mimes[0])
)
return $mimes[0];
# giving up
return 'application/octet-stream';
// @codeCoverageIgnoreEnd
} | php | private static function _mime_magic(
string $fname, string $path_to_file=null
) {
# with builtin
if (
function_exists('mime_content_type') &&
($mime = @mime_content_type($fname)) &&
$mime != 'application/octet-stream'
)
return $mime;
# with `file`, skip coverage because `file` is usually
# not available on CI
// @codeCoverageIgnoreStart
if ($path_to_file && is_executable($path_to_file)) {
$bin = $path_to_file;
} elseif (!($bin = self::exec("bash -c 'type -p file'")[0])) {
return 'application/octet-stream';
}
if (
($mimes = self::exec('%s -bip %s', [$bin, $fname])) &&
preg_match('!^[a-z0-9\-]+/!i', $mimes[0])
)
return $mimes[0];
# giving up
return 'application/octet-stream';
// @codeCoverageIgnoreEnd
} | [
"private",
"static",
"function",
"_mime_magic",
"(",
"string",
"$",
"fname",
",",
"string",
"$",
"path_to_file",
"=",
"null",
")",
"{",
"# with builtin",
"if",
"(",
"function_exists",
"(",
"'mime_content_type'",
")",
"&&",
"(",
"$",
"mime",
"=",
"@",
"mime_content_type",
"(",
"$",
"fname",
")",
")",
"&&",
"$",
"mime",
"!=",
"'application/octet-stream'",
")",
"return",
"$",
"mime",
";",
"# with `file`, skip coverage because `file` is usually",
"# not available on CI",
"// @codeCoverageIgnoreStart",
"if",
"(",
"$",
"path_to_file",
"&&",
"is_executable",
"(",
"$",
"path_to_file",
")",
")",
"{",
"$",
"bin",
"=",
"$",
"path_to_file",
";",
"}",
"elseif",
"(",
"!",
"(",
"$",
"bin",
"=",
"self",
"::",
"exec",
"(",
"\"bash -c 'type -p file'\"",
")",
"[",
"0",
"]",
")",
")",
"{",
"return",
"'application/octet-stream'",
";",
"}",
"if",
"(",
"(",
"$",
"mimes",
"=",
"self",
"::",
"exec",
"(",
"'%s -bip %s'",
",",
"[",
"$",
"bin",
",",
"$",
"fname",
"]",
")",
")",
"&&",
"preg_match",
"(",
"'!^[a-z0-9\\-]+/!i'",
",",
"$",
"mimes",
"[",
"0",
"]",
")",
")",
"return",
"$",
"mimes",
"[",
"0",
"]",
";",
"# giving up",
"return",
"'application/octet-stream'",
";",
"// @codeCoverageIgnoreEnd",
"}"
]
| Get MIME type with `mime_content_type` or `file`. | [
"Get",
"MIME",
"type",
"with",
"mime_content_type",
"or",
"file",
"."
]
| 0ae4cb9370876ab3583556bf272063685ec57948 | https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/src/Common.php#L87-L116 |
16,068 | bfitech/zapcore | src/Common.php | Common.http_client | public static function http_client(array $kwargs) {
$url = $method = null;
$headers = $get = $post = $custom_opts = [];
$expect_json = false;
extract(self::extract_kwargs($kwargs, [
'url' => null,
'method' => 'GET',
'headers'=> [],
'get' => [],
'post' => [],
'custom_opts' => [],
'expect_json' => false,
]));
if (!$url)
throw new CommonError("URL not set.");
$opts = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_CONNECTTIMEOUT => 16,
CURLOPT_TIMEOUT => 16,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 8,
CURLOPT_HEADER => false,
];
foreach ($custom_opts as $key => $val)
$opts[$key] = $val;
$conn = curl_init();
foreach ($opts as $key => $val)
curl_setopt($conn, $key, $val);
if ($headers)
curl_setopt($conn, CURLOPT_HTTPHEADER, $headers);
if ($get) {
$url .= strpos($url, '?') !== false ? '&' : '?';
$url .= http_build_query($get);
}
curl_setopt($conn, CURLOPT_URL, $url);
if (is_array($post))
$post = http_build_query($post);
switch ($method) {
case 'GET':
break;
case 'HEAD':
case 'OPTIONS':
curl_setopt($conn, CURLOPT_NOBODY, true);
curl_setopt($conn, CURLOPT_HEADER, true);
break;
case 'POST':
case 'PUT':
case 'DELETE':
case 'PATCH':
case 'TRACE':
curl_setopt($conn, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($conn, CURLOPT_POSTFIELDS, $post);
break;
default:
# CONNECT etc. are not supported ... yet?
return [-1, null];
}
$body = curl_exec($conn);
$info = curl_getinfo($conn);
curl_close($conn);
if (in_array($method, ['HEAD', 'OPTIONS']))
return [$info['http_code'], $body];
if ($expect_json)
$body = @json_decode($body, true);
return [$info['http_code'], $body];
} | php | public static function http_client(array $kwargs) {
$url = $method = null;
$headers = $get = $post = $custom_opts = [];
$expect_json = false;
extract(self::extract_kwargs($kwargs, [
'url' => null,
'method' => 'GET',
'headers'=> [],
'get' => [],
'post' => [],
'custom_opts' => [],
'expect_json' => false,
]));
if (!$url)
throw new CommonError("URL not set.");
$opts = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_CONNECTTIMEOUT => 16,
CURLOPT_TIMEOUT => 16,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 8,
CURLOPT_HEADER => false,
];
foreach ($custom_opts as $key => $val)
$opts[$key] = $val;
$conn = curl_init();
foreach ($opts as $key => $val)
curl_setopt($conn, $key, $val);
if ($headers)
curl_setopt($conn, CURLOPT_HTTPHEADER, $headers);
if ($get) {
$url .= strpos($url, '?') !== false ? '&' : '?';
$url .= http_build_query($get);
}
curl_setopt($conn, CURLOPT_URL, $url);
if (is_array($post))
$post = http_build_query($post);
switch ($method) {
case 'GET':
break;
case 'HEAD':
case 'OPTIONS':
curl_setopt($conn, CURLOPT_NOBODY, true);
curl_setopt($conn, CURLOPT_HEADER, true);
break;
case 'POST':
case 'PUT':
case 'DELETE':
case 'PATCH':
case 'TRACE':
curl_setopt($conn, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($conn, CURLOPT_POSTFIELDS, $post);
break;
default:
# CONNECT etc. are not supported ... yet?
return [-1, null];
}
$body = curl_exec($conn);
$info = curl_getinfo($conn);
curl_close($conn);
if (in_array($method, ['HEAD', 'OPTIONS']))
return [$info['http_code'], $body];
if ($expect_json)
$body = @json_decode($body, true);
return [$info['http_code'], $body];
} | [
"public",
"static",
"function",
"http_client",
"(",
"array",
"$",
"kwargs",
")",
"{",
"$",
"url",
"=",
"$",
"method",
"=",
"null",
";",
"$",
"headers",
"=",
"$",
"get",
"=",
"$",
"post",
"=",
"$",
"custom_opts",
"=",
"[",
"]",
";",
"$",
"expect_json",
"=",
"false",
";",
"extract",
"(",
"self",
"::",
"extract_kwargs",
"(",
"$",
"kwargs",
",",
"[",
"'url'",
"=>",
"null",
",",
"'method'",
"=>",
"'GET'",
",",
"'headers'",
"=>",
"[",
"]",
",",
"'get'",
"=>",
"[",
"]",
",",
"'post'",
"=>",
"[",
"]",
",",
"'custom_opts'",
"=>",
"[",
"]",
",",
"'expect_json'",
"=>",
"false",
",",
"]",
")",
")",
";",
"if",
"(",
"!",
"$",
"url",
")",
"throw",
"new",
"CommonError",
"(",
"\"URL not set.\"",
")",
";",
"$",
"opts",
"=",
"[",
"CURLOPT_RETURNTRANSFER",
"=>",
"true",
",",
"CURLOPT_SSL_VERIFYPEER",
"=>",
"true",
",",
"CURLOPT_CONNECTTIMEOUT",
"=>",
"16",
",",
"CURLOPT_TIMEOUT",
"=>",
"16",
",",
"CURLOPT_FOLLOWLOCATION",
"=>",
"true",
",",
"CURLOPT_MAXREDIRS",
"=>",
"8",
",",
"CURLOPT_HEADER",
"=>",
"false",
",",
"]",
";",
"foreach",
"(",
"$",
"custom_opts",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"$",
"opts",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"$",
"conn",
"=",
"curl_init",
"(",
")",
";",
"foreach",
"(",
"$",
"opts",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"curl_setopt",
"(",
"$",
"conn",
",",
"$",
"key",
",",
"$",
"val",
")",
";",
"if",
"(",
"$",
"headers",
")",
"curl_setopt",
"(",
"$",
"conn",
",",
"CURLOPT_HTTPHEADER",
",",
"$",
"headers",
")",
";",
"if",
"(",
"$",
"get",
")",
"{",
"$",
"url",
".=",
"strpos",
"(",
"$",
"url",
",",
"'?'",
")",
"!==",
"false",
"?",
"'&'",
":",
"'?'",
";",
"$",
"url",
".=",
"http_build_query",
"(",
"$",
"get",
")",
";",
"}",
"curl_setopt",
"(",
"$",
"conn",
",",
"CURLOPT_URL",
",",
"$",
"url",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"post",
")",
")",
"$",
"post",
"=",
"http_build_query",
"(",
"$",
"post",
")",
";",
"switch",
"(",
"$",
"method",
")",
"{",
"case",
"'GET'",
":",
"break",
";",
"case",
"'HEAD'",
":",
"case",
"'OPTIONS'",
":",
"curl_setopt",
"(",
"$",
"conn",
",",
"CURLOPT_NOBODY",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"conn",
",",
"CURLOPT_HEADER",
",",
"true",
")",
";",
"break",
";",
"case",
"'POST'",
":",
"case",
"'PUT'",
":",
"case",
"'DELETE'",
":",
"case",
"'PATCH'",
":",
"case",
"'TRACE'",
":",
"curl_setopt",
"(",
"$",
"conn",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"$",
"method",
")",
";",
"curl_setopt",
"(",
"$",
"conn",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"post",
")",
";",
"break",
";",
"default",
":",
"# CONNECT etc. are not supported ... yet?",
"return",
"[",
"-",
"1",
",",
"null",
"]",
";",
"}",
"$",
"body",
"=",
"curl_exec",
"(",
"$",
"conn",
")",
";",
"$",
"info",
"=",
"curl_getinfo",
"(",
"$",
"conn",
")",
";",
"curl_close",
"(",
"$",
"conn",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"method",
",",
"[",
"'HEAD'",
",",
"'OPTIONS'",
"]",
")",
")",
"return",
"[",
"$",
"info",
"[",
"'http_code'",
"]",
",",
"$",
"body",
"]",
";",
"if",
"(",
"$",
"expect_json",
")",
"$",
"body",
"=",
"@",
"json_decode",
"(",
"$",
"body",
",",
"true",
")",
";",
"return",
"[",
"$",
"info",
"[",
"'http_code'",
"]",
",",
"$",
"body",
"]",
";",
"}"
]
| cURL-based HTTP client.
@param array $kwargs Dict with key-value:
- `url` : (string) the URL
- `method` : (string) HTTP request method
- `headers` : (array) optional request headers, useful for
setting MIME type, user agent, etc.
- `get` : (dict) query string will be built off of
this; leave empty if you already have
query string in URL, unless you have to
- `post` : (dict|string) POST, PUT, or other request
body; if it's a string, it won't be formatted
as a query string
- `custom_opts` :
(dict) custom cURL options to add or override
defaults
- `expect_json` :
(bool) JSON-decode response if true, whether
server honors `Accept: application/json`
request header or not; response data is null
if response body is not valid JSON
@return array A list of the form `[HTTP code, response body]`.
HTTP code is -1 for invalid method, 0 for failing connection,
and any of standard code for successful connection.
@if TRUE
@codeCoverageIgnore
@SuppressWarnings(PHPMD.CyclomaticComplexity)
@SuppressWarnings(PHPMD.NPathComplexity)
@endif | [
"cURL",
"-",
"based",
"HTTP",
"client",
"."
]
| 0ae4cb9370876ab3583556bf272063685ec57948 | https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/src/Common.php#L150-L225 |
16,069 | bfitech/zapcore | src/Common.php | Common.check_dict | final public static function check_dict(
array $array, array $keys, bool $trim=false
) {
$checked = [];
foreach ($keys as $key) {
if (!isset($array[$key]))
return false;
$val = $array[$key];
if ($trim) {
if (!is_string($val))
return false;
$val = trim($val);
if (!$val)
return false;
}
$checked[$key] = $val;
}
return $checked;
} | php | final public static function check_dict(
array $array, array $keys, bool $trim=false
) {
$checked = [];
foreach ($keys as $key) {
if (!isset($array[$key]))
return false;
$val = $array[$key];
if ($trim) {
if (!is_string($val))
return false;
$val = trim($val);
if (!$val)
return false;
}
$checked[$key] = $val;
}
return $checked;
} | [
"final",
"public",
"static",
"function",
"check_dict",
"(",
"array",
"$",
"array",
",",
"array",
"$",
"keys",
",",
"bool",
"$",
"trim",
"=",
"false",
")",
"{",
"$",
"checked",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
")",
")",
"return",
"false",
";",
"$",
"val",
"=",
"$",
"array",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"$",
"trim",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"val",
")",
")",
"return",
"false",
";",
"$",
"val",
"=",
"trim",
"(",
"$",
"val",
")",
";",
"if",
"(",
"!",
"$",
"val",
")",
"return",
"false",
";",
"}",
"$",
"checked",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"return",
"$",
"checked",
";",
"}"
]
| Check if a dict contains all necessary keys.
@param array $array Dict to verify.
@param array $keys List of keys to verify against.
@param bool $trim Whether it should treat everything as string
and trim the values and drop keys of those with empty values.
@return bool|array False on failure, filtered dict otherwise. | [
"Check",
"if",
"a",
"dict",
"contains",
"all",
"necessary",
"keys",
"."
]
| 0ae4cb9370876ab3583556bf272063685ec57948 | https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/src/Common.php#L236-L254 |
16,070 | bfitech/zapcore | src/Common.php | Common.check_idict | final public static function check_idict(
array $array, array $keys, bool $trim=false
) {
if (false === $array = self::check_dict($array, $keys, $trim))
return false;
foreach ($array as $val) {
if (!is_numeric($val) && !is_string($val))
return false;
}
return $array;
} | php | final public static function check_idict(
array $array, array $keys, bool $trim=false
) {
if (false === $array = self::check_dict($array, $keys, $trim))
return false;
foreach ($array as $val) {
if (!is_numeric($val) && !is_string($val))
return false;
}
return $array;
} | [
"final",
"public",
"static",
"function",
"check_idict",
"(",
"array",
"$",
"array",
",",
"array",
"$",
"keys",
",",
"bool",
"$",
"trim",
"=",
"false",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"array",
"=",
"self",
"::",
"check_dict",
"(",
"$",
"array",
",",
"$",
"keys",
",",
"$",
"trim",
")",
")",
"return",
"false",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"val",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"val",
")",
"&&",
"!",
"is_string",
"(",
"$",
"val",
")",
")",
"return",
"false",
";",
"}",
"return",
"$",
"array",
";",
"}"
]
| Check if a dict contains all necessary keys with elements being
immutables, i.e. numeric or string.
@param array $array Dict to verify.
@param array $keys List of keys to verify against.
@param bool $trim Whether it should treat everything as string
and trim the values and drop keys of those with empty values.
@return bool|array False on failure, filtered dict otherwise. | [
"Check",
"if",
"a",
"dict",
"contains",
"all",
"necessary",
"keys",
"with",
"elements",
"being",
"immutables",
"i",
".",
"e",
".",
"numeric",
"or",
"string",
"."
]
| 0ae4cb9370876ab3583556bf272063685ec57948 | https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/src/Common.php#L266-L276 |
16,071 | bfitech/zapcore | src/Common.php | Common.extract_kwargs | final public static function extract_kwargs(
array $input_array, array $init_array
) {
foreach (array_keys($init_array) as $key) {
if (isset($input_array[$key]))
$init_array[$key] = $input_array[$key];
}
return $init_array;
} | php | final public static function extract_kwargs(
array $input_array, array $init_array
) {
foreach (array_keys($init_array) as $key) {
if (isset($input_array[$key]))
$init_array[$key] = $input_array[$key];
}
return $init_array;
} | [
"final",
"public",
"static",
"function",
"extract_kwargs",
"(",
"array",
"$",
"input_array",
",",
"array",
"$",
"init_array",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"init_array",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"input_array",
"[",
"$",
"key",
"]",
")",
")",
"$",
"init_array",
"[",
"$",
"key",
"]",
"=",
"$",
"input_array",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"init_array",
";",
"}"
]
| Initiate a kwargs array for safe extraction.
This will remove keys not available in $init_array instead
of filling in holes in input array.
@param array $input_array Input array, typically first
parameter in a method.
@param array $init_array Fallback array when input array
is not complete, of the form: `key => default value`.
@return array A complete array ready to be extract()ed. | [
"Initiate",
"a",
"kwargs",
"array",
"for",
"safe",
"extraction",
"."
]
| 0ae4cb9370876ab3583556bf272063685ec57948 | https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/src/Common.php#L290-L298 |
16,072 | tonicospinelli/class-generation | src/ClassGeneration/Visibility.php | Visibility.isValid | public static function isValid($visibility)
{
switch ($visibility) {
case Visibility::TYPE_PRIVATE:
case Visibility::TYPE_PROTECTED:
case Visibility::TYPE_PUBLIC:
return true;
}
throw new \InvalidArgumentException('The ' . $visibility . ' is not allowed');
} | php | public static function isValid($visibility)
{
switch ($visibility) {
case Visibility::TYPE_PRIVATE:
case Visibility::TYPE_PROTECTED:
case Visibility::TYPE_PUBLIC:
return true;
}
throw new \InvalidArgumentException('The ' . $visibility . ' is not allowed');
} | [
"public",
"static",
"function",
"isValid",
"(",
"$",
"visibility",
")",
"{",
"switch",
"(",
"$",
"visibility",
")",
"{",
"case",
"Visibility",
"::",
"TYPE_PRIVATE",
":",
"case",
"Visibility",
"::",
"TYPE_PROTECTED",
":",
"case",
"Visibility",
"::",
"TYPE_PUBLIC",
":",
"return",
"true",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The '",
".",
"$",
"visibility",
".",
"' is not allowed'",
")",
";",
"}"
]
| Validate visiblity.
@param string $visibility
@throws \InvalidArgumentException
@return bool | [
"Validate",
"visiblity",
"."
]
| eee63bdb68c066b25b885b57b23656e809381a76 | https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/Visibility.php#L34-L43 |
16,073 | ua1-labs/firebug | Fire/Bug/Panel/Debugger.php | Debugger.render | public function render() {
if (!$this->_enableXDebugOverlay) {
ini_set('xdebug.overload_var_dump', 'off');
}
$debuggerCount = count($this->_debuggers);
$this->setName(str_replace('{count}', '{' . $debuggerCount . '}', self::NAME));
parent::render();
} | php | public function render() {
if (!$this->_enableXDebugOverlay) {
ini_set('xdebug.overload_var_dump', 'off');
}
$debuggerCount = count($this->_debuggers);
$this->setName(str_replace('{count}', '{' . $debuggerCount . '}', self::NAME));
parent::render();
} | [
"public",
"function",
"render",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_enableXDebugOverlay",
")",
"{",
"ini_set",
"(",
"'xdebug.overload_var_dump'",
",",
"'off'",
")",
";",
"}",
"$",
"debuggerCount",
"=",
"count",
"(",
"$",
"this",
"->",
"_debuggers",
")",
";",
"$",
"this",
"->",
"setName",
"(",
"str_replace",
"(",
"'{count}'",
",",
"'{'",
".",
"$",
"debuggerCount",
".",
"'}'",
",",
"self",
"::",
"NAME",
")",
")",
";",
"parent",
"::",
"render",
"(",
")",
";",
"}"
]
| Renders the panel HTML.
@return void | [
"Renders",
"the",
"panel",
"HTML",
"."
]
| 70a45b2c0bbf64978641eb07e5f3cddfc1951162 | https://github.com/ua1-labs/firebug/blob/70a45b2c0bbf64978641eb07e5f3cddfc1951162/Fire/Bug/Panel/Debugger.php#L89-L96 |
16,074 | blast-project/CoreBundle | src/Controller/CRUDController.php | CRUDController.generateEntityCodeAction | public function generateEntityCodeAction($id = null)
{
$request = $this->getRequest();
$id = $request->get($this->admin->getIdParameter());
if ($id) {
$subject = $this->admin->getObject($id);
if (!$subject) {
$error = sprintf('unable to find the object with id : %s', $id);
return new JsonResponse(['error' => $error]);
}
try {
$this->admin->checkAccess('edit', $subject); // TODO: is it necessary ? (we are not editing the entity)
} catch (Exception $exc) {
$error = $exc->getMessage();
return new JsonResponse(['error' => $error]);
}
} else {
$subject = $this->admin->getNewInstance();
}
$this->admin->setSubject($subject);
$form = $this->admin->getForm();
$form->setData($subject);
$form->submit($request->request->get($form->getName()));
$entity = $form->getData();
$field = $request->query->get('field', 'code');
$registry = $this->get('blast_core.code_generators');
$generator = $registry::getCodeGenerator(get_class($entity), $field);
try {
$code = $generator::generate($entity);
return new JsonResponse(['code' => $code]);
} catch (\Exception $exc) {
$error = $this->get('translator')->trans($exc->getMessage());
return new JsonResponse(['error' => $error, 'generator' => get_class($generator)]);
}
} | php | public function generateEntityCodeAction($id = null)
{
$request = $this->getRequest();
$id = $request->get($this->admin->getIdParameter());
if ($id) {
$subject = $this->admin->getObject($id);
if (!$subject) {
$error = sprintf('unable to find the object with id : %s', $id);
return new JsonResponse(['error' => $error]);
}
try {
$this->admin->checkAccess('edit', $subject); // TODO: is it necessary ? (we are not editing the entity)
} catch (Exception $exc) {
$error = $exc->getMessage();
return new JsonResponse(['error' => $error]);
}
} else {
$subject = $this->admin->getNewInstance();
}
$this->admin->setSubject($subject);
$form = $this->admin->getForm();
$form->setData($subject);
$form->submit($request->request->get($form->getName()));
$entity = $form->getData();
$field = $request->query->get('field', 'code');
$registry = $this->get('blast_core.code_generators');
$generator = $registry::getCodeGenerator(get_class($entity), $field);
try {
$code = $generator::generate($entity);
return new JsonResponse(['code' => $code]);
} catch (\Exception $exc) {
$error = $this->get('translator')->trans($exc->getMessage());
return new JsonResponse(['error' => $error, 'generator' => get_class($generator)]);
}
} | [
"public",
"function",
"generateEntityCodeAction",
"(",
"$",
"id",
"=",
"null",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"$",
"id",
"=",
"$",
"request",
"->",
"get",
"(",
"$",
"this",
"->",
"admin",
"->",
"getIdParameter",
"(",
")",
")",
";",
"if",
"(",
"$",
"id",
")",
"{",
"$",
"subject",
"=",
"$",
"this",
"->",
"admin",
"->",
"getObject",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"subject",
")",
"{",
"$",
"error",
"=",
"sprintf",
"(",
"'unable to find the object with id : %s'",
",",
"$",
"id",
")",
";",
"return",
"new",
"JsonResponse",
"(",
"[",
"'error'",
"=>",
"$",
"error",
"]",
")",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"admin",
"->",
"checkAccess",
"(",
"'edit'",
",",
"$",
"subject",
")",
";",
"// TODO: is it necessary ? (we are not editing the entity)",
"}",
"catch",
"(",
"Exception",
"$",
"exc",
")",
"{",
"$",
"error",
"=",
"$",
"exc",
"->",
"getMessage",
"(",
")",
";",
"return",
"new",
"JsonResponse",
"(",
"[",
"'error'",
"=>",
"$",
"error",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"subject",
"=",
"$",
"this",
"->",
"admin",
"->",
"getNewInstance",
"(",
")",
";",
"}",
"$",
"this",
"->",
"admin",
"->",
"setSubject",
"(",
"$",
"subject",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"admin",
"->",
"getForm",
"(",
")",
";",
"$",
"form",
"->",
"setData",
"(",
"$",
"subject",
")",
";",
"$",
"form",
"->",
"submit",
"(",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"$",
"form",
"->",
"getName",
"(",
")",
")",
")",
";",
"$",
"entity",
"=",
"$",
"form",
"->",
"getData",
"(",
")",
";",
"$",
"field",
"=",
"$",
"request",
"->",
"query",
"->",
"get",
"(",
"'field'",
",",
"'code'",
")",
";",
"$",
"registry",
"=",
"$",
"this",
"->",
"get",
"(",
"'blast_core.code_generators'",
")",
";",
"$",
"generator",
"=",
"$",
"registry",
"::",
"getCodeGenerator",
"(",
"get_class",
"(",
"$",
"entity",
")",
",",
"$",
"field",
")",
";",
"try",
"{",
"$",
"code",
"=",
"$",
"generator",
"::",
"generate",
"(",
"$",
"entity",
")",
";",
"return",
"new",
"JsonResponse",
"(",
"[",
"'code'",
"=>",
"$",
"code",
"]",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exc",
")",
"{",
"$",
"error",
"=",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"$",
"exc",
"->",
"getMessage",
"(",
")",
")",
";",
"return",
"new",
"JsonResponse",
"(",
"[",
"'error'",
"=>",
"$",
"error",
",",
"'generator'",
"=>",
"get_class",
"(",
"$",
"generator",
")",
"]",
")",
";",
"}",
"}"
]
| Generate Entity Code action.
@param int|string|null $id
@return JsonResponse | [
"Generate",
"Entity",
"Code",
"action",
"."
]
| 7a0832758ca14e5bc5d65515532c1220df3930ae | https://github.com/blast-project/CoreBundle/blob/7a0832758ca14e5bc5d65515532c1220df3930ae/src/Controller/CRUDController.php#L174-L216 |
16,075 | baleen/cli | src/CommandBus/Config/StatusHandler.php | StatusHandler.printPendingVersion | protected function printPendingVersion(Version $version, $style)
{
/** @var Version $version */
$id = $version->getId();
$reflectionClass = new \ReflectionClass($version->getMigration());
$absolutePath = $reflectionClass->getFileName();
$fileName = $absolutePath ? $this->getRelativePath(getcwd(), $absolutePath) : '';
$this->output->writeln("\t<$style>[$id] $fileName</$style>");
} | php | protected function printPendingVersion(Version $version, $style)
{
/** @var Version $version */
$id = $version->getId();
$reflectionClass = new \ReflectionClass($version->getMigration());
$absolutePath = $reflectionClass->getFileName();
$fileName = $absolutePath ? $this->getRelativePath(getcwd(), $absolutePath) : '';
$this->output->writeln("\t<$style>[$id] $fileName</$style>");
} | [
"protected",
"function",
"printPendingVersion",
"(",
"Version",
"$",
"version",
",",
"$",
"style",
")",
"{",
"/** @var Version $version */",
"$",
"id",
"=",
"$",
"version",
"->",
"getId",
"(",
")",
";",
"$",
"reflectionClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"version",
"->",
"getMigration",
"(",
")",
")",
";",
"$",
"absolutePath",
"=",
"$",
"reflectionClass",
"->",
"getFileName",
"(",
")",
";",
"$",
"fileName",
"=",
"$",
"absolutePath",
"?",
"$",
"this",
"->",
"getRelativePath",
"(",
"getcwd",
"(",
")",
",",
"$",
"absolutePath",
")",
":",
"''",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"\\t<$style>[$id] $fileName</$style>\"",
")",
";",
"}"
]
| Formats and prints a pending version with the given style.
@param Version $version The Version to print.
@param string $style One of the STYLE_* constants. | [
"Formats",
"and",
"prints",
"a",
"pending",
"version",
"with",
"the",
"given",
"style",
"."
]
| 2ecbc7179c5800c9075fd93204ef25da375536ed | https://github.com/baleen/cli/blob/2ecbc7179c5800c9075fd93204ef25da375536ed/src/CommandBus/Config/StatusHandler.php#L107-L115 |
16,076 | runcmf/runbb-ext-renderer | src/View.php | View.setStyle | public function setStyle($style)
{
$dir = ForumEnv::get('WEB_ROOT').'themes/'.$style.'/';
if (!is_dir($dir)) {
throw new RunBBException('The style '.$style.' doesn\'t exist');
}
if (is_file($dir . 'bootstrap.php')) {
$vars = include_once $dir . 'bootstrap.php';
// file exist but return nothing
if (!is_array($vars)) {
$vars = [];
}
foreach ($vars as $key => $assets) {
if ($key === 'jsraw' || !in_array($key, ['js', 'jshead', 'css'])) {
continue;
}
foreach ($assets as $asset) {
$params = ($key === 'css') ? ['type' => 'text/css', 'rel' => 'stylesheet'] : (
($key === 'js' || $key === 'jshead') ? ['type' => 'text/javascript'] : []
);
$this->addAsset($key, $asset, $params);
}
}
$this->set('jsraw', isset($vars['jsraw']) ? $vars['jsraw'] : '');
}
if (isset($vars['themeTemplates']) && $vars['themeTemplates'] == true) {
$templatesDir = ForumEnv::get('WEB_ROOT').'themes/'.$style.'/view';
} else {
$templatesDir = ForumEnv::get('FORUM_ROOT') . 'View/';
}
$this->set('style', (string) $style);
$this->addTemplatesDirectory($templatesDir);
} | php | public function setStyle($style)
{
$dir = ForumEnv::get('WEB_ROOT').'themes/'.$style.'/';
if (!is_dir($dir)) {
throw new RunBBException('The style '.$style.' doesn\'t exist');
}
if (is_file($dir . 'bootstrap.php')) {
$vars = include_once $dir . 'bootstrap.php';
// file exist but return nothing
if (!is_array($vars)) {
$vars = [];
}
foreach ($vars as $key => $assets) {
if ($key === 'jsraw' || !in_array($key, ['js', 'jshead', 'css'])) {
continue;
}
foreach ($assets as $asset) {
$params = ($key === 'css') ? ['type' => 'text/css', 'rel' => 'stylesheet'] : (
($key === 'js' || $key === 'jshead') ? ['type' => 'text/javascript'] : []
);
$this->addAsset($key, $asset, $params);
}
}
$this->set('jsraw', isset($vars['jsraw']) ? $vars['jsraw'] : '');
}
if (isset($vars['themeTemplates']) && $vars['themeTemplates'] == true) {
$templatesDir = ForumEnv::get('WEB_ROOT').'themes/'.$style.'/view';
} else {
$templatesDir = ForumEnv::get('FORUM_ROOT') . 'View/';
}
$this->set('style', (string) $style);
$this->addTemplatesDirectory($templatesDir);
} | [
"public",
"function",
"setStyle",
"(",
"$",
"style",
")",
"{",
"$",
"dir",
"=",
"ForumEnv",
"::",
"get",
"(",
"'WEB_ROOT'",
")",
".",
"'themes/'",
".",
"$",
"style",
".",
"'/'",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"throw",
"new",
"RunBBException",
"(",
"'The style '",
".",
"$",
"style",
".",
"' doesn\\'t exist'",
")",
";",
"}",
"if",
"(",
"is_file",
"(",
"$",
"dir",
".",
"'bootstrap.php'",
")",
")",
"{",
"$",
"vars",
"=",
"include_once",
"$",
"dir",
".",
"'bootstrap.php'",
";",
"// file exist but return nothing",
"if",
"(",
"!",
"is_array",
"(",
"$",
"vars",
")",
")",
"{",
"$",
"vars",
"=",
"[",
"]",
";",
"}",
"foreach",
"(",
"$",
"vars",
"as",
"$",
"key",
"=>",
"$",
"assets",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"'jsraw'",
"||",
"!",
"in_array",
"(",
"$",
"key",
",",
"[",
"'js'",
",",
"'jshead'",
",",
"'css'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"assets",
"as",
"$",
"asset",
")",
"{",
"$",
"params",
"=",
"(",
"$",
"key",
"===",
"'css'",
")",
"?",
"[",
"'type'",
"=>",
"'text/css'",
",",
"'rel'",
"=>",
"'stylesheet'",
"]",
":",
"(",
"(",
"$",
"key",
"===",
"'js'",
"||",
"$",
"key",
"===",
"'jshead'",
")",
"?",
"[",
"'type'",
"=>",
"'text/javascript'",
"]",
":",
"[",
"]",
")",
";",
"$",
"this",
"->",
"addAsset",
"(",
"$",
"key",
",",
"$",
"asset",
",",
"$",
"params",
")",
";",
"}",
"}",
"$",
"this",
"->",
"set",
"(",
"'jsraw'",
",",
"isset",
"(",
"$",
"vars",
"[",
"'jsraw'",
"]",
")",
"?",
"$",
"vars",
"[",
"'jsraw'",
"]",
":",
"''",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"vars",
"[",
"'themeTemplates'",
"]",
")",
"&&",
"$",
"vars",
"[",
"'themeTemplates'",
"]",
"==",
"true",
")",
"{",
"$",
"templatesDir",
"=",
"ForumEnv",
"::",
"get",
"(",
"'WEB_ROOT'",
")",
".",
"'themes/'",
".",
"$",
"style",
".",
"'/view'",
";",
"}",
"else",
"{",
"$",
"templatesDir",
"=",
"ForumEnv",
"::",
"get",
"(",
"'FORUM_ROOT'",
")",
".",
"'View/'",
";",
"}",
"$",
"this",
"->",
"set",
"(",
"'style'",
",",
"(",
"string",
")",
"$",
"style",
")",
";",
"$",
"this",
"->",
"addTemplatesDirectory",
"(",
"$",
"templatesDir",
")",
";",
"}"
]
| Initialise style, load assets for given style
@param $style
@throws RunBBException | [
"Initialise",
"style",
"load",
"assets",
"for",
"given",
"style"
]
| df47ea8550f79c34676df7abb4112a5addaccea0 | https://github.com/runcmf/runbb-ext-renderer/blob/df47ea8550f79c34676df7abb4112a5addaccea0/src/View.php#L55-L91 |
16,077 | wizbii/pipeline | Runnable/DispatcherStore.php | DispatcherStore.dumpAction | public function dumpAction()
{
return $this->newActionMatcher()->thenExecute(function($action) {
echo "Action '" . $action->getName() . "' : " . var_export($action->getProperties(), true) . "\n";
});
} | php | public function dumpAction()
{
return $this->newActionMatcher()->thenExecute(function($action) {
echo "Action '" . $action->getName() . "' : " . var_export($action->getProperties(), true) . "\n";
});
} | [
"public",
"function",
"dumpAction",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"newActionMatcher",
"(",
")",
"->",
"thenExecute",
"(",
"function",
"(",
"$",
"action",
")",
"{",
"echo",
"\"Action '\"",
".",
"$",
"action",
"->",
"getName",
"(",
")",
".",
"\"' : \"",
".",
"var_export",
"(",
"$",
"action",
"->",
"getProperties",
"(",
")",
",",
"true",
")",
".",
"\"\\n\"",
";",
"}",
")",
";",
"}"
]
| Used for debug purposes mainly
@return $this | [
"Used",
"for",
"debug",
"purposes",
"mainly"
]
| 8d22b976a53bb52abf0333b62b308ec7127cf414 | https://github.com/wizbii/pipeline/blob/8d22b976a53bb52abf0333b62b308ec7127cf414/Runnable/DispatcherStore.php#L162-L167 |
16,078 | jan-dolata/crude-crud | src/Http/Controllers/FileController.php | FileController.upload | public function upload(FileRequest $request)
{
$crudeName = $request->input('crudeName');
$crude = CrudeInstance::get($crudeName);
$files = $request->file()['file'];
$id = $request->input('modelId');
$errors = [];
if ($crude instanceof \JanDolata\CrudeCRUD\Engine\Interfaces\WithValidationInterface) {
foreach($files as $key => $file) {
$rules = $crude->getValidationRules(['file']);
$mime = $file->getMimeType();
$fileTypeRules = 'file_'.collect(explode('/', $mime))->first();
empty($crude->getValidationRules([$fileTypeRules])[$fileTypeRules])
? $rules = $rules
: $rules['file'] = $rules['file'] . '|' . $crude->getValidationRules([$fileTypeRules])[$fileTypeRules];
$validator = Validator::make(['file' => $file], $rules);
if ($validator->fails()) {
unset($files[$key]);
$errors[] = $file->getClientOriginalName() . ': '. $validator->messages()->first();
}
}
}
$model = empty($files)
? $crude->getById($id)
: $crude->uploadFilesById($id, $files);
$response = ['success' => true, 'model' => $model];
if (!empty($errors)) {
$response = array_merge($response, ['errors' => join('<br/>', $errors)]);
$response['success'] = false;
}
return $response;
} | php | public function upload(FileRequest $request)
{
$crudeName = $request->input('crudeName');
$crude = CrudeInstance::get($crudeName);
$files = $request->file()['file'];
$id = $request->input('modelId');
$errors = [];
if ($crude instanceof \JanDolata\CrudeCRUD\Engine\Interfaces\WithValidationInterface) {
foreach($files as $key => $file) {
$rules = $crude->getValidationRules(['file']);
$mime = $file->getMimeType();
$fileTypeRules = 'file_'.collect(explode('/', $mime))->first();
empty($crude->getValidationRules([$fileTypeRules])[$fileTypeRules])
? $rules = $rules
: $rules['file'] = $rules['file'] . '|' . $crude->getValidationRules([$fileTypeRules])[$fileTypeRules];
$validator = Validator::make(['file' => $file], $rules);
if ($validator->fails()) {
unset($files[$key]);
$errors[] = $file->getClientOriginalName() . ': '. $validator->messages()->first();
}
}
}
$model = empty($files)
? $crude->getById($id)
: $crude->uploadFilesById($id, $files);
$response = ['success' => true, 'model' => $model];
if (!empty($errors)) {
$response = array_merge($response, ['errors' => join('<br/>', $errors)]);
$response['success'] = false;
}
return $response;
} | [
"public",
"function",
"upload",
"(",
"FileRequest",
"$",
"request",
")",
"{",
"$",
"crudeName",
"=",
"$",
"request",
"->",
"input",
"(",
"'crudeName'",
")",
";",
"$",
"crude",
"=",
"CrudeInstance",
"::",
"get",
"(",
"$",
"crudeName",
")",
";",
"$",
"files",
"=",
"$",
"request",
"->",
"file",
"(",
")",
"[",
"'file'",
"]",
";",
"$",
"id",
"=",
"$",
"request",
"->",
"input",
"(",
"'modelId'",
")",
";",
"$",
"errors",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"crude",
"instanceof",
"\\",
"JanDolata",
"\\",
"CrudeCRUD",
"\\",
"Engine",
"\\",
"Interfaces",
"\\",
"WithValidationInterface",
")",
"{",
"foreach",
"(",
"$",
"files",
"as",
"$",
"key",
"=>",
"$",
"file",
")",
"{",
"$",
"rules",
"=",
"$",
"crude",
"->",
"getValidationRules",
"(",
"[",
"'file'",
"]",
")",
";",
"$",
"mime",
"=",
"$",
"file",
"->",
"getMimeType",
"(",
")",
";",
"$",
"fileTypeRules",
"=",
"'file_'",
".",
"collect",
"(",
"explode",
"(",
"'/'",
",",
"$",
"mime",
")",
")",
"->",
"first",
"(",
")",
";",
"empty",
"(",
"$",
"crude",
"->",
"getValidationRules",
"(",
"[",
"$",
"fileTypeRules",
"]",
")",
"[",
"$",
"fileTypeRules",
"]",
")",
"?",
"$",
"rules",
"=",
"$",
"rules",
":",
"$",
"rules",
"[",
"'file'",
"]",
"=",
"$",
"rules",
"[",
"'file'",
"]",
".",
"'|'",
".",
"$",
"crude",
"->",
"getValidationRules",
"(",
"[",
"$",
"fileTypeRules",
"]",
")",
"[",
"$",
"fileTypeRules",
"]",
";",
"$",
"validator",
"=",
"Validator",
"::",
"make",
"(",
"[",
"'file'",
"=>",
"$",
"file",
"]",
",",
"$",
"rules",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"fails",
"(",
")",
")",
"{",
"unset",
"(",
"$",
"files",
"[",
"$",
"key",
"]",
")",
";",
"$",
"errors",
"[",
"]",
"=",
"$",
"file",
"->",
"getClientOriginalName",
"(",
")",
".",
"': '",
".",
"$",
"validator",
"->",
"messages",
"(",
")",
"->",
"first",
"(",
")",
";",
"}",
"}",
"}",
"$",
"model",
"=",
"empty",
"(",
"$",
"files",
")",
"?",
"$",
"crude",
"->",
"getById",
"(",
"$",
"id",
")",
":",
"$",
"crude",
"->",
"uploadFilesById",
"(",
"$",
"id",
",",
"$",
"files",
")",
";",
"$",
"response",
"=",
"[",
"'success'",
"=>",
"true",
",",
"'model'",
"=>",
"$",
"model",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"errors",
")",
")",
"{",
"$",
"response",
"=",
"array_merge",
"(",
"$",
"response",
",",
"[",
"'errors'",
"=>",
"join",
"(",
"'<br/>'",
",",
"$",
"errors",
")",
"]",
")",
";",
"$",
"response",
"[",
"'success'",
"]",
"=",
"false",
";",
"}",
"return",
"$",
"response",
";",
"}"
]
| Handle files upload
file on model is a helper field
@author Wojciech Jurkowski <[email protected]> | [
"Handle",
"files",
"upload",
"file",
"on",
"model",
"is",
"a",
"helper",
"field"
]
| 9129ea08278835cf5cecfd46a90369226ae6bdd7 | https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Http/Controllers/FileController.php#L22-L62 |
16,079 | jan-dolata/crude-crud | src/Http/Controllers/FileController.php | FileController.downloadAll | public function downloadAll($crudeName = null, $id = null)
{
if (! $crudeName || ! $id)
return redirect()->back();
$crude = CrudeInstance::get($crudeName);
if (! $crude)
return redirect()->back();
$model = $crude->getModel()->find($id);
if (! $model)
return redirect()->back();
$filesZip = CrudeZip::run($model);
if (! $filesZip)
return redirect()->back();
return response()->download($filesZip, $crudeName . '-' . $id . '.zip')->deleteFileAfterSend(true);
} | php | public function downloadAll($crudeName = null, $id = null)
{
if (! $crudeName || ! $id)
return redirect()->back();
$crude = CrudeInstance::get($crudeName);
if (! $crude)
return redirect()->back();
$model = $crude->getModel()->find($id);
if (! $model)
return redirect()->back();
$filesZip = CrudeZip::run($model);
if (! $filesZip)
return redirect()->back();
return response()->download($filesZip, $crudeName . '-' . $id . '.zip')->deleteFileAfterSend(true);
} | [
"public",
"function",
"downloadAll",
"(",
"$",
"crudeName",
"=",
"null",
",",
"$",
"id",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"crudeName",
"||",
"!",
"$",
"id",
")",
"return",
"redirect",
"(",
")",
"->",
"back",
"(",
")",
";",
"$",
"crude",
"=",
"CrudeInstance",
"::",
"get",
"(",
"$",
"crudeName",
")",
";",
"if",
"(",
"!",
"$",
"crude",
")",
"return",
"redirect",
"(",
")",
"->",
"back",
"(",
")",
";",
"$",
"model",
"=",
"$",
"crude",
"->",
"getModel",
"(",
")",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"model",
")",
"return",
"redirect",
"(",
")",
"->",
"back",
"(",
")",
";",
"$",
"filesZip",
"=",
"CrudeZip",
"::",
"run",
"(",
"$",
"model",
")",
";",
"if",
"(",
"!",
"$",
"filesZip",
")",
"return",
"redirect",
"(",
")",
"->",
"back",
"(",
")",
";",
"return",
"response",
"(",
")",
"->",
"download",
"(",
"$",
"filesZip",
",",
"$",
"crudeName",
".",
"'-'",
".",
"$",
"id",
".",
"'.zip'",
")",
"->",
"deleteFileAfterSend",
"(",
"true",
")",
";",
"}"
]
| Download all files for model | [
"Download",
"all",
"files",
"for",
"model"
]
| 9129ea08278835cf5cecfd46a90369226ae6bdd7 | https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Http/Controllers/FileController.php#L92-L110 |
16,080 | JoffreyPoreeCoding/MongoDB-ODM | src/Tools/ClassMetadata/ClassMetadata.php | ClassMetadata.getNamespace | public function getNamespace()
{
if (!isset($this->namespace)) {
$reflectionClass = new \ReflectionClass($this->name);
$this->namespace = $reflectionClass->getNamespaceName();
}
return $this->namespace;
} | php | public function getNamespace()
{
if (!isset($this->namespace)) {
$reflectionClass = new \ReflectionClass($this->name);
$this->namespace = $reflectionClass->getNamespaceName();
}
return $this->namespace;
} | [
"public",
"function",
"getNamespace",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"namespace",
")",
")",
"{",
"$",
"reflectionClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"this",
"->",
"name",
")",
";",
"$",
"this",
"->",
"namespace",
"=",
"$",
"reflectionClass",
"->",
"getNamespaceName",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"namespace",
";",
"}"
]
| Get namespace of the class | [
"Get",
"namespace",
"of",
"the",
"class"
]
| 56fd7ab28c22f276573a89d56bb93c8d74ad7f74 | https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Tools/ClassMetadata/ClassMetadata.php#L103-L110 |
16,081 | JoffreyPoreeCoding/MongoDB-ODM | src/Tools/ClassMetadata/ClassMetadata.php | ClassMetadata.getPropertyInfo | public function getPropertyInfo($prop)
{
if (!$this->loaded) {
$this->load();
}
if (isset($this->propertiesInfos[$prop])) {
return $this->propertiesInfos[$prop];
}
return false;
} | php | public function getPropertyInfo($prop)
{
if (!$this->loaded) {
$this->load();
}
if (isset($this->propertiesInfos[$prop])) {
return $this->propertiesInfos[$prop];
}
return false;
} | [
"public",
"function",
"getPropertyInfo",
"(",
"$",
"prop",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"loaded",
")",
"{",
"$",
"this",
"->",
"load",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"prop",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"prop",
"]",
";",
"}",
"return",
"false",
";",
"}"
]
| Get property information
@param string $prop Name of the property
@return PropertyInfo | [
"Get",
"property",
"information"
]
| 56fd7ab28c22f276573a89d56bb93c8d74ad7f74 | https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Tools/ClassMetadata/ClassMetadata.php#L146-L157 |
16,082 | JoffreyPoreeCoding/MongoDB-ODM | src/Tools/ClassMetadata/ClassMetadata.php | ClassMetadata.getPropertyInfoForField | public function getPropertyInfoForField($field)
{
if (!$this->loaded) {
$this->load();
}
foreach ($this->propertiesInfos as $name => $infos) {
if ($infos->getField() == $field) {
return $infos;
}
}
return false;
} | php | public function getPropertyInfoForField($field)
{
if (!$this->loaded) {
$this->load();
}
foreach ($this->propertiesInfos as $name => $infos) {
if ($infos->getField() == $field) {
return $infos;
}
}
return false;
} | [
"public",
"function",
"getPropertyInfoForField",
"(",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"loaded",
")",
"{",
"$",
"this",
"->",
"load",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"propertiesInfos",
"as",
"$",
"name",
"=>",
"$",
"infos",
")",
"{",
"if",
"(",
"$",
"infos",
"->",
"getField",
"(",
")",
"==",
"$",
"field",
")",
"{",
"return",
"$",
"infos",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Get property info corresponding to a field
@param string $field Field
@return PropertyInfo | [
"Get",
"property",
"info",
"corresponding",
"to",
"a",
"field"
]
| 56fd7ab28c22f276573a89d56bb93c8d74ad7f74 | https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Tools/ClassMetadata/ClassMetadata.php#L179-L192 |
16,083 | JoffreyPoreeCoding/MongoDB-ODM | src/Tools/ClassMetadata/ClassMetadata.php | ClassMetadata.getPropertyForField | public function getPropertyForField($field)
{
if (!$this->loaded) {
$this->load();
}
foreach ($this->propertiesInfos as $name => $infos) {
if ($infos->getField() == $field) {
return new \ReflectionProperty($this->name, $name);
}
}
return false;
} | php | public function getPropertyForField($field)
{
if (!$this->loaded) {
$this->load();
}
foreach ($this->propertiesInfos as $name => $infos) {
if ($infos->getField() == $field) {
return new \ReflectionProperty($this->name, $name);
}
}
return false;
} | [
"public",
"function",
"getPropertyForField",
"(",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"loaded",
")",
"{",
"$",
"this",
"->",
"load",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"propertiesInfos",
"as",
"$",
"name",
"=>",
"$",
"infos",
")",
"{",
"if",
"(",
"$",
"infos",
"->",
"getField",
"(",
")",
"==",
"$",
"field",
")",
"{",
"return",
"new",
"\\",
"ReflectionProperty",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"name",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Get ReflectionProperty for a field
@param string $field Field
@return \ReflectionProperty | [
"Get",
"ReflectionProperty",
"for",
"a",
"field"
]
| 56fd7ab28c22f276573a89d56bb93c8d74ad7f74 | https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Tools/ClassMetadata/ClassMetadata.php#L200-L213 |
16,084 | JoffreyPoreeCoding/MongoDB-ODM | src/Tools/ClassMetadata/ClassMetadata.php | ClassMetadata.setCollection | public function setCollection($collection)
{
if (!$this->loaded) {
$this->load();
}
$this->collectionInfo->setCollection($collection);
return $this;
} | php | public function setCollection($collection)
{
if (!$this->loaded) {
$this->load();
}
$this->collectionInfo->setCollection($collection);
return $this;
} | [
"public",
"function",
"setCollection",
"(",
"$",
"collection",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"loaded",
")",
"{",
"$",
"this",
"->",
"load",
"(",
")",
";",
"}",
"$",
"this",
"->",
"collectionInfo",
"->",
"setCollection",
"(",
"$",
"collection",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the collection
@param string $collection Name of the collection
@return ClassMetadata | [
"Set",
"the",
"collection"
]
| 56fd7ab28c22f276573a89d56bb93c8d74ad7f74 | https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Tools/ClassMetadata/ClassMetadata.php#L249-L257 |
16,085 | JoffreyPoreeCoding/MongoDB-ODM | src/Tools/ClassMetadata/ClassMetadata.php | ClassMetadata.load | private function load()
{
$reflectionClass = new \ReflectionClass($this->name);
$this->collectionInfo = new CollectionInfo();
foreach ($this->reader->getClassAnnotations($reflectionClass) as $annotation) {
$this->processClassAnnotation($annotation);
}
$properties = $reflectionClass->getProperties();
foreach ($properties as $property) {
foreach ($this->reader->getPropertyAnnotations($property) as $annotation) {
if (!isset($this->propertiesInfos[$property->getName()])) {
$this->propertiesInfos[$property->getName()] = new PropertyInfo();
}
$this->processPropertiesAnnotation($property->getName(), $annotation);
}
}
$this->eventManager = new EventManager();
if ($this->hasEvent) {
$methods = $reflectionClass->getMethods();
foreach ($methods as $method) {
$annotations = $this->reader->getMethodAnnotations($method);
if (!empty($annotations)) {
foreach ($annotations as $annotation) {
if (in_array('JPC\MongoDB\ODM\Annotations\Event\Event', class_implements($annotation))) {
$this->eventManager->add($annotation, $method->getName());
}
}
}
}
}
$this->loaded = true;
} | php | private function load()
{
$reflectionClass = new \ReflectionClass($this->name);
$this->collectionInfo = new CollectionInfo();
foreach ($this->reader->getClassAnnotations($reflectionClass) as $annotation) {
$this->processClassAnnotation($annotation);
}
$properties = $reflectionClass->getProperties();
foreach ($properties as $property) {
foreach ($this->reader->getPropertyAnnotations($property) as $annotation) {
if (!isset($this->propertiesInfos[$property->getName()])) {
$this->propertiesInfos[$property->getName()] = new PropertyInfo();
}
$this->processPropertiesAnnotation($property->getName(), $annotation);
}
}
$this->eventManager = new EventManager();
if ($this->hasEvent) {
$methods = $reflectionClass->getMethods();
foreach ($methods as $method) {
$annotations = $this->reader->getMethodAnnotations($method);
if (!empty($annotations)) {
foreach ($annotations as $annotation) {
if (in_array('JPC\MongoDB\ODM\Annotations\Event\Event', class_implements($annotation))) {
$this->eventManager->add($annotation, $method->getName());
}
}
}
}
}
$this->loaded = true;
} | [
"private",
"function",
"load",
"(",
")",
"{",
"$",
"reflectionClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"this",
"->",
"name",
")",
";",
"$",
"this",
"->",
"collectionInfo",
"=",
"new",
"CollectionInfo",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"reader",
"->",
"getClassAnnotations",
"(",
"$",
"reflectionClass",
")",
"as",
"$",
"annotation",
")",
"{",
"$",
"this",
"->",
"processClassAnnotation",
"(",
"$",
"annotation",
")",
";",
"}",
"$",
"properties",
"=",
"$",
"reflectionClass",
"->",
"getProperties",
"(",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"reader",
"->",
"getPropertyAnnotations",
"(",
"$",
"property",
")",
"as",
"$",
"annotation",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"property",
"->",
"getName",
"(",
")",
"]",
")",
")",
"{",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"property",
"->",
"getName",
"(",
")",
"]",
"=",
"new",
"PropertyInfo",
"(",
")",
";",
"}",
"$",
"this",
"->",
"processPropertiesAnnotation",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
",",
"$",
"annotation",
")",
";",
"}",
"}",
"$",
"this",
"->",
"eventManager",
"=",
"new",
"EventManager",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasEvent",
")",
"{",
"$",
"methods",
"=",
"$",
"reflectionClass",
"->",
"getMethods",
"(",
")",
";",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"method",
")",
"{",
"$",
"annotations",
"=",
"$",
"this",
"->",
"reader",
"->",
"getMethodAnnotations",
"(",
"$",
"method",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"annotations",
")",
")",
"{",
"foreach",
"(",
"$",
"annotations",
"as",
"$",
"annotation",
")",
"{",
"if",
"(",
"in_array",
"(",
"'JPC\\MongoDB\\ODM\\Annotations\\Event\\Event'",
",",
"class_implements",
"(",
"$",
"annotation",
")",
")",
")",
"{",
"$",
"this",
"->",
"eventManager",
"->",
"add",
"(",
"$",
"annotation",
",",
"$",
"method",
"->",
"getName",
"(",
")",
")",
";",
"}",
"}",
"}",
"}",
"}",
"$",
"this",
"->",
"loaded",
"=",
"true",
";",
"}"
]
| Load all metadata
@return void | [
"Load",
"all",
"metadata"
]
| 56fd7ab28c22f276573a89d56bb93c8d74ad7f74 | https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Tools/ClassMetadata/ClassMetadata.php#L316-L352 |
16,086 | JoffreyPoreeCoding/MongoDB-ODM | src/Tools/ClassMetadata/ClassMetadata.php | ClassMetadata.processClassAnnotation | private function processClassAnnotation($annotation)
{
$class = get_class($annotation);
switch ($class) {
case "JPC\MongoDB\ODM\Annotations\Mapping\Document":
$this->collectionInfo->setCollection($annotation->collectionName);
if (null !== ($rep = $annotation->repositoryClass)) {
$this->collectionInfo->setRepository($annotation->repositoryClass);
} else {
if (class_exists($this->getName() . 'Repository')) {
$this->collectionInfo->setRepository($this->getName() . 'Repository');
} else {
$this->collectionInfo->setRepository("JPC\MongoDB\ODM\Repository");
}
}
if (null !== ($rep = $annotation->hydratorClass)) {
$this->collectionInfo->setHydrator($annotation->hydratorClass);
} else {
$this->collectionInfo->setHydrator("JPC\MongoDB\ODM\Hydrator");
}
$this->checkCollectionCreationOptions($annotation);
break;
case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\Document":
$this->collectionInfo->setBucketName($annotation->bucketName);
$this->collectionInfo->setCollection($annotation->bucketName . ".files");
if (null !== ($rep = $annotation->repositoryClass)) {
$this->collectionInfo->setRepository($annotation->repositoryClass);
} else {
$this->collectionInfo->setRepository("JPC\MongoDB\ODM\GridFS\Repository");
}
if (null !== ($rep = $annotation->hydratorClass)) {
$this->collectionInfo->setHydrator($annotation->hydratorClass);
} else {
$this->collectionInfo->setHydrator("JPC\MongoDB\ODM\GridFS\Hydrator");
}
break;
case "JPC\MongoDB\ODM\Annotations\Mapping\Option":
$this->processOptionAnnotation($annotation);
break;
case "JPC\MongoDB\ODM\Annotations\Event\HasLifecycleCallbacks":
$this->hasEvent = true;
break;
}
} | php | private function processClassAnnotation($annotation)
{
$class = get_class($annotation);
switch ($class) {
case "JPC\MongoDB\ODM\Annotations\Mapping\Document":
$this->collectionInfo->setCollection($annotation->collectionName);
if (null !== ($rep = $annotation->repositoryClass)) {
$this->collectionInfo->setRepository($annotation->repositoryClass);
} else {
if (class_exists($this->getName() . 'Repository')) {
$this->collectionInfo->setRepository($this->getName() . 'Repository');
} else {
$this->collectionInfo->setRepository("JPC\MongoDB\ODM\Repository");
}
}
if (null !== ($rep = $annotation->hydratorClass)) {
$this->collectionInfo->setHydrator($annotation->hydratorClass);
} else {
$this->collectionInfo->setHydrator("JPC\MongoDB\ODM\Hydrator");
}
$this->checkCollectionCreationOptions($annotation);
break;
case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\Document":
$this->collectionInfo->setBucketName($annotation->bucketName);
$this->collectionInfo->setCollection($annotation->bucketName . ".files");
if (null !== ($rep = $annotation->repositoryClass)) {
$this->collectionInfo->setRepository($annotation->repositoryClass);
} else {
$this->collectionInfo->setRepository("JPC\MongoDB\ODM\GridFS\Repository");
}
if (null !== ($rep = $annotation->hydratorClass)) {
$this->collectionInfo->setHydrator($annotation->hydratorClass);
} else {
$this->collectionInfo->setHydrator("JPC\MongoDB\ODM\GridFS\Hydrator");
}
break;
case "JPC\MongoDB\ODM\Annotations\Mapping\Option":
$this->processOptionAnnotation($annotation);
break;
case "JPC\MongoDB\ODM\Annotations\Event\HasLifecycleCallbacks":
$this->hasEvent = true;
break;
}
} | [
"private",
"function",
"processClassAnnotation",
"(",
"$",
"annotation",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"annotation",
")",
";",
"switch",
"(",
"$",
"class",
")",
"{",
"case",
"\"JPC\\MongoDB\\ODM\\Annotations\\Mapping\\Document\"",
":",
"$",
"this",
"->",
"collectionInfo",
"->",
"setCollection",
"(",
"$",
"annotation",
"->",
"collectionName",
")",
";",
"if",
"(",
"null",
"!==",
"(",
"$",
"rep",
"=",
"$",
"annotation",
"->",
"repositoryClass",
")",
")",
"{",
"$",
"this",
"->",
"collectionInfo",
"->",
"setRepository",
"(",
"$",
"annotation",
"->",
"repositoryClass",
")",
";",
"}",
"else",
"{",
"if",
"(",
"class_exists",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
".",
"'Repository'",
")",
")",
"{",
"$",
"this",
"->",
"collectionInfo",
"->",
"setRepository",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
".",
"'Repository'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"collectionInfo",
"->",
"setRepository",
"(",
"\"JPC\\MongoDB\\ODM\\Repository\"",
")",
";",
"}",
"}",
"if",
"(",
"null",
"!==",
"(",
"$",
"rep",
"=",
"$",
"annotation",
"->",
"hydratorClass",
")",
")",
"{",
"$",
"this",
"->",
"collectionInfo",
"->",
"setHydrator",
"(",
"$",
"annotation",
"->",
"hydratorClass",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"collectionInfo",
"->",
"setHydrator",
"(",
"\"JPC\\MongoDB\\ODM\\Hydrator\"",
")",
";",
"}",
"$",
"this",
"->",
"checkCollectionCreationOptions",
"(",
"$",
"annotation",
")",
";",
"break",
";",
"case",
"\"JPC\\MongoDB\\ODM\\GridFS\\Annotations\\Mapping\\Document\"",
":",
"$",
"this",
"->",
"collectionInfo",
"->",
"setBucketName",
"(",
"$",
"annotation",
"->",
"bucketName",
")",
";",
"$",
"this",
"->",
"collectionInfo",
"->",
"setCollection",
"(",
"$",
"annotation",
"->",
"bucketName",
".",
"\".files\"",
")",
";",
"if",
"(",
"null",
"!==",
"(",
"$",
"rep",
"=",
"$",
"annotation",
"->",
"repositoryClass",
")",
")",
"{",
"$",
"this",
"->",
"collectionInfo",
"->",
"setRepository",
"(",
"$",
"annotation",
"->",
"repositoryClass",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"collectionInfo",
"->",
"setRepository",
"(",
"\"JPC\\MongoDB\\ODM\\GridFS\\Repository\"",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"(",
"$",
"rep",
"=",
"$",
"annotation",
"->",
"hydratorClass",
")",
")",
"{",
"$",
"this",
"->",
"collectionInfo",
"->",
"setHydrator",
"(",
"$",
"annotation",
"->",
"hydratorClass",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"collectionInfo",
"->",
"setHydrator",
"(",
"\"JPC\\MongoDB\\ODM\\GridFS\\Hydrator\"",
")",
";",
"}",
"break",
";",
"case",
"\"JPC\\MongoDB\\ODM\\Annotations\\Mapping\\Option\"",
":",
"$",
"this",
"->",
"processOptionAnnotation",
"(",
"$",
"annotation",
")",
";",
"break",
";",
"case",
"\"JPC\\MongoDB\\ODM\\Annotations\\Event\\HasLifecycleCallbacks\"",
":",
"$",
"this",
"->",
"hasEvent",
"=",
"true",
";",
"break",
";",
"}",
"}"
]
| Process class annotation to extract infos
@param Annotation $annotation Annotation to process
@return void | [
"Process",
"class",
"annotation",
"to",
"extract",
"infos"
]
| 56fd7ab28c22f276573a89d56bb93c8d74ad7f74 | https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Tools/ClassMetadata/ClassMetadata.php#L360-L408 |
16,087 | JoffreyPoreeCoding/MongoDB-ODM | src/Tools/ClassMetadata/ClassMetadata.php | ClassMetadata.processOptionAnnotation | private function processOptionAnnotation(\JPC\MongoDB\ODM\Annotations\Mapping\Option $annotation)
{
$options = [];
if (isset($annotation->writeConcern)) {
$options["writeConcern"] = $annotation->writeConcern->getWriteConcern();
}
if (isset($annotation->readConcern)) {
$options["readConcern"] = $annotation->readConcern->getReadConcern();
}
if (isset($annotation->readPreference)) {
$options["readPreference"] = $annotation->readPreference->getReadPreference();
}
if (isset($annotation->typeMap)) {
$options["typeMap"] = $annotation->typeMap;
}
$this->collectionInfo->setOptions($options);
} | php | private function processOptionAnnotation(\JPC\MongoDB\ODM\Annotations\Mapping\Option $annotation)
{
$options = [];
if (isset($annotation->writeConcern)) {
$options["writeConcern"] = $annotation->writeConcern->getWriteConcern();
}
if (isset($annotation->readConcern)) {
$options["readConcern"] = $annotation->readConcern->getReadConcern();
}
if (isset($annotation->readPreference)) {
$options["readPreference"] = $annotation->readPreference->getReadPreference();
}
if (isset($annotation->typeMap)) {
$options["typeMap"] = $annotation->typeMap;
}
$this->collectionInfo->setOptions($options);
} | [
"private",
"function",
"processOptionAnnotation",
"(",
"\\",
"JPC",
"\\",
"MongoDB",
"\\",
"ODM",
"\\",
"Annotations",
"\\",
"Mapping",
"\\",
"Option",
"$",
"annotation",
")",
"{",
"$",
"options",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"annotation",
"->",
"writeConcern",
")",
")",
"{",
"$",
"options",
"[",
"\"writeConcern\"",
"]",
"=",
"$",
"annotation",
"->",
"writeConcern",
"->",
"getWriteConcern",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"annotation",
"->",
"readConcern",
")",
")",
"{",
"$",
"options",
"[",
"\"readConcern\"",
"]",
"=",
"$",
"annotation",
"->",
"readConcern",
"->",
"getReadConcern",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"annotation",
"->",
"readPreference",
")",
")",
"{",
"$",
"options",
"[",
"\"readPreference\"",
"]",
"=",
"$",
"annotation",
"->",
"readPreference",
"->",
"getReadPreference",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"annotation",
"->",
"typeMap",
")",
")",
"{",
"$",
"options",
"[",
"\"typeMap\"",
"]",
"=",
"$",
"annotation",
"->",
"typeMap",
";",
"}",
"$",
"this",
"->",
"collectionInfo",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"}"
]
| Process option annotation
@param \JPC\MongoDB\ODM\Annotations\Mapping\Option $annotation Annotation to process
@return void | [
"Process",
"option",
"annotation"
]
| 56fd7ab28c22f276573a89d56bb93c8d74ad7f74 | https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Tools/ClassMetadata/ClassMetadata.php#L416-L436 |
16,088 | JoffreyPoreeCoding/MongoDB-ODM | src/Tools/ClassMetadata/ClassMetadata.php | ClassMetadata.processPropertiesAnnotation | private function processPropertiesAnnotation($name, $annotation)
{
$class = get_class($annotation);
switch ($class) {
case "JPC\MongoDB\ODM\Annotations\Mapping\Id":
$this->propertiesInfos[$name]->setField("_id");
$this->idGenerator = $annotation->generator;
break;
case "JPC\MongoDB\ODM\Annotations\Mapping\Field":
$this->propertiesInfos[$name]->setField($annotation->name);
break;
case "JPC\MongoDB\ODM\Annotations\Mapping\EmbeddedDocument":
$this->propertiesInfos[$name]->setEmbedded(true);
$this->propertiesInfos[$name]->setEmbeddedClass($annotation->document);
break;
case "JPC\MongoDB\ODM\Annotations\Mapping\MultiEmbeddedDocument":
$this->propertiesInfos[$name]->setMultiEmbedded(true);
$this->propertiesInfos[$name]->setEmbeddedClass($annotation->document);
break;
case "JPC\MongoDB\ODM\Annotations\Mapping\Id":
$this->propertiesInfos[$name]->setField("_id");
break;
case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\Stream":
$this->propertiesInfos[$name]->setField("stream");
break;
case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\Filename":
$this->propertiesInfos[$name]->setField("filename");
break;
case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\Aliases":
$this->propertiesInfos[$name]->setField("aliases");
break;
case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\ChunkSize":
$this->propertiesInfos[$name]->setField("chunkSize");
break;
case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\UploadDate":
$this->propertiesInfos[$name]->setField("uploadDate");
break;
case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\Length":
$this->propertiesInfos[$name]->setField("length");
break;
case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\ContentType":
$this->propertiesInfos[$name]->setField("contentType");
break;
case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\Md5":
$this->propertiesInfos[$name]->setField("md5");
break;
case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\Metadata":
$this->propertiesInfos[$name]->setMetadata(true);
break;
case "JPC\MongoDB\ODM\Annotations\Mapping\RefersOne":
$referenceInfo = new ReferenceInfo();
$referenceInfo->setDocument($annotation->document)->setCollection($annotation->collection);
$this->propertiesInfos[$name]->setReferenceInfo($referenceInfo);
break;
case "JPC\MongoDB\ODM\Annotations\Mapping\RefersMany":
$referenceInfo = new ReferenceInfo();
$referenceInfo->setIsMultiple(true)->setDocument($annotation->document)->setCollection($annotation->collection);
$this->propertiesInfos[$name]->setReferenceInfo($referenceInfo);
break;
case "JPC\MongoDB\ODM\Annotations\Mapping\DiscriminatorField":
$this->propertiesInfos[$name]->setDiscriminatorField($annotation->field);
break;
case "JPC\MongoDB\ODM\Annotations\Mapping\DiscriminatorMap":
$this->propertiesInfos[$name]->setDiscriminatorMap($annotation->map);
break;
case "JPC\MongoDB\ODM\Annotations\Mapping\DiscriminatorMethod":
$this->propertiesInfos[$name]->setDiscriminatorMethod($annotation->method);
break;
}
} | php | private function processPropertiesAnnotation($name, $annotation)
{
$class = get_class($annotation);
switch ($class) {
case "JPC\MongoDB\ODM\Annotations\Mapping\Id":
$this->propertiesInfos[$name]->setField("_id");
$this->idGenerator = $annotation->generator;
break;
case "JPC\MongoDB\ODM\Annotations\Mapping\Field":
$this->propertiesInfos[$name]->setField($annotation->name);
break;
case "JPC\MongoDB\ODM\Annotations\Mapping\EmbeddedDocument":
$this->propertiesInfos[$name]->setEmbedded(true);
$this->propertiesInfos[$name]->setEmbeddedClass($annotation->document);
break;
case "JPC\MongoDB\ODM\Annotations\Mapping\MultiEmbeddedDocument":
$this->propertiesInfos[$name]->setMultiEmbedded(true);
$this->propertiesInfos[$name]->setEmbeddedClass($annotation->document);
break;
case "JPC\MongoDB\ODM\Annotations\Mapping\Id":
$this->propertiesInfos[$name]->setField("_id");
break;
case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\Stream":
$this->propertiesInfos[$name]->setField("stream");
break;
case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\Filename":
$this->propertiesInfos[$name]->setField("filename");
break;
case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\Aliases":
$this->propertiesInfos[$name]->setField("aliases");
break;
case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\ChunkSize":
$this->propertiesInfos[$name]->setField("chunkSize");
break;
case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\UploadDate":
$this->propertiesInfos[$name]->setField("uploadDate");
break;
case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\Length":
$this->propertiesInfos[$name]->setField("length");
break;
case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\ContentType":
$this->propertiesInfos[$name]->setField("contentType");
break;
case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\Md5":
$this->propertiesInfos[$name]->setField("md5");
break;
case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\Metadata":
$this->propertiesInfos[$name]->setMetadata(true);
break;
case "JPC\MongoDB\ODM\Annotations\Mapping\RefersOne":
$referenceInfo = new ReferenceInfo();
$referenceInfo->setDocument($annotation->document)->setCollection($annotation->collection);
$this->propertiesInfos[$name]->setReferenceInfo($referenceInfo);
break;
case "JPC\MongoDB\ODM\Annotations\Mapping\RefersMany":
$referenceInfo = new ReferenceInfo();
$referenceInfo->setIsMultiple(true)->setDocument($annotation->document)->setCollection($annotation->collection);
$this->propertiesInfos[$name]->setReferenceInfo($referenceInfo);
break;
case "JPC\MongoDB\ODM\Annotations\Mapping\DiscriminatorField":
$this->propertiesInfos[$name]->setDiscriminatorField($annotation->field);
break;
case "JPC\MongoDB\ODM\Annotations\Mapping\DiscriminatorMap":
$this->propertiesInfos[$name]->setDiscriminatorMap($annotation->map);
break;
case "JPC\MongoDB\ODM\Annotations\Mapping\DiscriminatorMethod":
$this->propertiesInfos[$name]->setDiscriminatorMethod($annotation->method);
break;
}
} | [
"private",
"function",
"processPropertiesAnnotation",
"(",
"$",
"name",
",",
"$",
"annotation",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"annotation",
")",
";",
"switch",
"(",
"$",
"class",
")",
"{",
"case",
"\"JPC\\MongoDB\\ODM\\Annotations\\Mapping\\Id\"",
":",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"name",
"]",
"->",
"setField",
"(",
"\"_id\"",
")",
";",
"$",
"this",
"->",
"idGenerator",
"=",
"$",
"annotation",
"->",
"generator",
";",
"break",
";",
"case",
"\"JPC\\MongoDB\\ODM\\Annotations\\Mapping\\Field\"",
":",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"name",
"]",
"->",
"setField",
"(",
"$",
"annotation",
"->",
"name",
")",
";",
"break",
";",
"case",
"\"JPC\\MongoDB\\ODM\\Annotations\\Mapping\\EmbeddedDocument\"",
":",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"name",
"]",
"->",
"setEmbedded",
"(",
"true",
")",
";",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"name",
"]",
"->",
"setEmbeddedClass",
"(",
"$",
"annotation",
"->",
"document",
")",
";",
"break",
";",
"case",
"\"JPC\\MongoDB\\ODM\\Annotations\\Mapping\\MultiEmbeddedDocument\"",
":",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"name",
"]",
"->",
"setMultiEmbedded",
"(",
"true",
")",
";",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"name",
"]",
"->",
"setEmbeddedClass",
"(",
"$",
"annotation",
"->",
"document",
")",
";",
"break",
";",
"case",
"\"JPC\\MongoDB\\ODM\\Annotations\\Mapping\\Id\"",
":",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"name",
"]",
"->",
"setField",
"(",
"\"_id\"",
")",
";",
"break",
";",
"case",
"\"JPC\\MongoDB\\ODM\\GridFS\\Annotations\\Mapping\\Stream\"",
":",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"name",
"]",
"->",
"setField",
"(",
"\"stream\"",
")",
";",
"break",
";",
"case",
"\"JPC\\MongoDB\\ODM\\GridFS\\Annotations\\Mapping\\Filename\"",
":",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"name",
"]",
"->",
"setField",
"(",
"\"filename\"",
")",
";",
"break",
";",
"case",
"\"JPC\\MongoDB\\ODM\\GridFS\\Annotations\\Mapping\\Aliases\"",
":",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"name",
"]",
"->",
"setField",
"(",
"\"aliases\"",
")",
";",
"break",
";",
"case",
"\"JPC\\MongoDB\\ODM\\GridFS\\Annotations\\Mapping\\ChunkSize\"",
":",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"name",
"]",
"->",
"setField",
"(",
"\"chunkSize\"",
")",
";",
"break",
";",
"case",
"\"JPC\\MongoDB\\ODM\\GridFS\\Annotations\\Mapping\\UploadDate\"",
":",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"name",
"]",
"->",
"setField",
"(",
"\"uploadDate\"",
")",
";",
"break",
";",
"case",
"\"JPC\\MongoDB\\ODM\\GridFS\\Annotations\\Mapping\\Length\"",
":",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"name",
"]",
"->",
"setField",
"(",
"\"length\"",
")",
";",
"break",
";",
"case",
"\"JPC\\MongoDB\\ODM\\GridFS\\Annotations\\Mapping\\ContentType\"",
":",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"name",
"]",
"->",
"setField",
"(",
"\"contentType\"",
")",
";",
"break",
";",
"case",
"\"JPC\\MongoDB\\ODM\\GridFS\\Annotations\\Mapping\\Md5\"",
":",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"name",
"]",
"->",
"setField",
"(",
"\"md5\"",
")",
";",
"break",
";",
"case",
"\"JPC\\MongoDB\\ODM\\GridFS\\Annotations\\Mapping\\Metadata\"",
":",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"name",
"]",
"->",
"setMetadata",
"(",
"true",
")",
";",
"break",
";",
"case",
"\"JPC\\MongoDB\\ODM\\Annotations\\Mapping\\RefersOne\"",
":",
"$",
"referenceInfo",
"=",
"new",
"ReferenceInfo",
"(",
")",
";",
"$",
"referenceInfo",
"->",
"setDocument",
"(",
"$",
"annotation",
"->",
"document",
")",
"->",
"setCollection",
"(",
"$",
"annotation",
"->",
"collection",
")",
";",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"name",
"]",
"->",
"setReferenceInfo",
"(",
"$",
"referenceInfo",
")",
";",
"break",
";",
"case",
"\"JPC\\MongoDB\\ODM\\Annotations\\Mapping\\RefersMany\"",
":",
"$",
"referenceInfo",
"=",
"new",
"ReferenceInfo",
"(",
")",
";",
"$",
"referenceInfo",
"->",
"setIsMultiple",
"(",
"true",
")",
"->",
"setDocument",
"(",
"$",
"annotation",
"->",
"document",
")",
"->",
"setCollection",
"(",
"$",
"annotation",
"->",
"collection",
")",
";",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"name",
"]",
"->",
"setReferenceInfo",
"(",
"$",
"referenceInfo",
")",
";",
"break",
";",
"case",
"\"JPC\\MongoDB\\ODM\\Annotations\\Mapping\\DiscriminatorField\"",
":",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"name",
"]",
"->",
"setDiscriminatorField",
"(",
"$",
"annotation",
"->",
"field",
")",
";",
"break",
";",
"case",
"\"JPC\\MongoDB\\ODM\\Annotations\\Mapping\\DiscriminatorMap\"",
":",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"name",
"]",
"->",
"setDiscriminatorMap",
"(",
"$",
"annotation",
"->",
"map",
")",
";",
"break",
";",
"case",
"\"JPC\\MongoDB\\ODM\\Annotations\\Mapping\\DiscriminatorMethod\"",
":",
"$",
"this",
"->",
"propertiesInfos",
"[",
"$",
"name",
"]",
"->",
"setDiscriminatorMethod",
"(",
"$",
"annotation",
"->",
"method",
")",
";",
"break",
";",
"}",
"}"
]
| Process property annotation
@param string $name Name of the property
@param Annotation $annotation Annotation to process
@return void | [
"Process",
"property",
"annotation"
]
| 56fd7ab28c22f276573a89d56bb93c8d74ad7f74 | https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Tools/ClassMetadata/ClassMetadata.php#L445-L514 |
16,089 | JoffreyPoreeCoding/MongoDB-ODM | src/Tools/ClassMetadata/ClassMetadata.php | ClassMetadata.checkCollectionCreationOptions | private function checkCollectionCreationOptions(\JPC\MongoDB\ODM\Annotations\Mapping\Document $annotation)
{
$options = [];
if ($annotation->capped) {
$options["capped"] = true;
$options["size"] = $annotation->size;
if ($annotation->max != false) {
$options["max"] = $annotation->max;
}
}
$this->collectionInfo->setCreationOptions($options);
} | php | private function checkCollectionCreationOptions(\JPC\MongoDB\ODM\Annotations\Mapping\Document $annotation)
{
$options = [];
if ($annotation->capped) {
$options["capped"] = true;
$options["size"] = $annotation->size;
if ($annotation->max != false) {
$options["max"] = $annotation->max;
}
}
$this->collectionInfo->setCreationOptions($options);
} | [
"private",
"function",
"checkCollectionCreationOptions",
"(",
"\\",
"JPC",
"\\",
"MongoDB",
"\\",
"ODM",
"\\",
"Annotations",
"\\",
"Mapping",
"\\",
"Document",
"$",
"annotation",
")",
"{",
"$",
"options",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"annotation",
"->",
"capped",
")",
"{",
"$",
"options",
"[",
"\"capped\"",
"]",
"=",
"true",
";",
"$",
"options",
"[",
"\"size\"",
"]",
"=",
"$",
"annotation",
"->",
"size",
";",
"if",
"(",
"$",
"annotation",
"->",
"max",
"!=",
"false",
")",
"{",
"$",
"options",
"[",
"\"max\"",
"]",
"=",
"$",
"annotation",
"->",
"max",
";",
"}",
"}",
"$",
"this",
"->",
"collectionInfo",
"->",
"setCreationOptions",
"(",
"$",
"options",
")",
";",
"}"
]
| Check and set collection creation options
@param \JPC\MongoDB\ODM\Annotations\Mapping\Document $annotation Annotation to process
@return void | [
"Check",
"and",
"set",
"collection",
"creation",
"options"
]
| 56fd7ab28c22f276573a89d56bb93c8d74ad7f74 | https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Tools/ClassMetadata/ClassMetadata.php#L522-L535 |
16,090 | Nayjest/Tree | src/Utils.php | Utils.applyCallback | public static function applyCallback(callable $callback, NodeInterface $root, $targetClass = ChildNodeInterface::class)
{
$processed = [];
$f = function (ChildNodeInterface $targetNode) use ($callback, $targetClass, &$f, &$processed) {
if (in_array($targetNode, $processed, true)) {
return;
}
$nodes = $targetNode instanceof ParentNodeInterface
? $targetNode->getChildrenRecursive()->toArray()
: [];
$nodes[] = $targetNode;
/** @var NodeInterface $node */
foreach ($nodes as $node) {
$node instanceof $targetClass && call_user_func($callback, $node);
$node instanceof ParentNodeInterface && $node->children()->onItemAdd($f);
$processed[] = $node;
}
};
$f($root);
} | php | public static function applyCallback(callable $callback, NodeInterface $root, $targetClass = ChildNodeInterface::class)
{
$processed = [];
$f = function (ChildNodeInterface $targetNode) use ($callback, $targetClass, &$f, &$processed) {
if (in_array($targetNode, $processed, true)) {
return;
}
$nodes = $targetNode instanceof ParentNodeInterface
? $targetNode->getChildrenRecursive()->toArray()
: [];
$nodes[] = $targetNode;
/** @var NodeInterface $node */
foreach ($nodes as $node) {
$node instanceof $targetClass && call_user_func($callback, $node);
$node instanceof ParentNodeInterface && $node->children()->onItemAdd($f);
$processed[] = $node;
}
};
$f($root);
} | [
"public",
"static",
"function",
"applyCallback",
"(",
"callable",
"$",
"callback",
",",
"NodeInterface",
"$",
"root",
",",
"$",
"targetClass",
"=",
"ChildNodeInterface",
"::",
"class",
")",
"{",
"$",
"processed",
"=",
"[",
"]",
";",
"$",
"f",
"=",
"function",
"(",
"ChildNodeInterface",
"$",
"targetNode",
")",
"use",
"(",
"$",
"callback",
",",
"$",
"targetClass",
",",
"&",
"$",
"f",
",",
"&",
"$",
"processed",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"targetNode",
",",
"$",
"processed",
",",
"true",
")",
")",
"{",
"return",
";",
"}",
"$",
"nodes",
"=",
"$",
"targetNode",
"instanceof",
"ParentNodeInterface",
"?",
"$",
"targetNode",
"->",
"getChildrenRecursive",
"(",
")",
"->",
"toArray",
"(",
")",
":",
"[",
"]",
";",
"$",
"nodes",
"[",
"]",
"=",
"$",
"targetNode",
";",
"/** @var NodeInterface $node */",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"node",
")",
"{",
"$",
"node",
"instanceof",
"$",
"targetClass",
"&&",
"call_user_func",
"(",
"$",
"callback",
",",
"$",
"node",
")",
";",
"$",
"node",
"instanceof",
"ParentNodeInterface",
"&&",
"$",
"node",
"->",
"children",
"(",
")",
"->",
"onItemAdd",
"(",
"$",
"f",
")",
";",
"$",
"processed",
"[",
"]",
"=",
"$",
"node",
";",
"}",
"}",
";",
"$",
"f",
"(",
"$",
"root",
")",
";",
"}"
]
| Applies callback to root node, if it's existing and further descendant nodes directly after adding to tree.
@param callable $callback function to apply
@param NodeInterface $root root node
@param string $targetClass callback will be applied only to nodes that are instances of $targetClass or inherited classes | [
"Applies",
"callback",
"to",
"root",
"node",
"if",
"it",
"s",
"existing",
"and",
"further",
"descendant",
"nodes",
"directly",
"after",
"adding",
"to",
"tree",
"."
]
| e73da75f939e207b1c25065e9466c28300e7113c | https://github.com/Nayjest/Tree/blob/e73da75f939e207b1c25065e9466c28300e7113c/src/Utils.php#L44-L64 |
16,091 | shawnsandy/ui-pages | src/Controllers/MarkdownController.php | MarkdownController.show | public function show($posts, Request $request)
{
$file = $posts;
$markdown = $this->pagekit->markdown($file);
$view = "page::missing-page";
if ($request->has('page')) :
$markdown = $this->pagekit->markdown($request->page, $posts);
endif;
if (!empty($markdown)) :
$view = 'page::markdown.show';
endif;
return view($view, compact('markdown'));
} | php | public function show($posts, Request $request)
{
$file = $posts;
$markdown = $this->pagekit->markdown($file);
$view = "page::missing-page";
if ($request->has('page')) :
$markdown = $this->pagekit->markdown($request->page, $posts);
endif;
if (!empty($markdown)) :
$view = 'page::markdown.show';
endif;
return view($view, compact('markdown'));
} | [
"public",
"function",
"show",
"(",
"$",
"posts",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"file",
"=",
"$",
"posts",
";",
"$",
"markdown",
"=",
"$",
"this",
"->",
"pagekit",
"->",
"markdown",
"(",
"$",
"file",
")",
";",
"$",
"view",
"=",
"\"page::missing-page\"",
";",
"if",
"(",
"$",
"request",
"->",
"has",
"(",
"'page'",
")",
")",
":",
"$",
"markdown",
"=",
"$",
"this",
"->",
"pagekit",
"->",
"markdown",
"(",
"$",
"request",
"->",
"page",
",",
"$",
"posts",
")",
";",
"endif",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"markdown",
")",
")",
":",
"$",
"view",
"=",
"'page::markdown.show'",
";",
"endif",
";",
"return",
"view",
"(",
"$",
"view",
",",
"compact",
"(",
"'markdown'",
")",
")",
";",
"}"
]
| Show a specific page params
@param $posts
@param Request $request
@return string | [
"Show",
"a",
"specific",
"page",
"params"
]
| 11584c12fa3e2b9a5c513f4ec9e2eaf78c206ca8 | https://github.com/shawnsandy/ui-pages/blob/11584c12fa3e2b9a5c513f4ec9e2eaf78c206ca8/src/Controllers/MarkdownController.php#L51-L69 |
16,092 | gregorybesson/PlaygroundCore | src/Service/Cron.php | Cron.getCronjobs | public function getCronjobs()
{
if (!$this->cronjobs) {
$cronjobs = array();
$results = $this->serviceLocator
->get('Application')
->getEventManager()
->trigger(__FUNCTION__, $this, array(
'cronjobs' => $cronjobs
));
if ($results) {
foreach ($results as $key => $cron) {
foreach ($cron as $id => $conf) {
$cronjobs[$id] = $conf;
}
}
}
$this->setCronjobs($cronjobs);
}
return $this->cronjobs;
} | php | public function getCronjobs()
{
if (!$this->cronjobs) {
$cronjobs = array();
$results = $this->serviceLocator
->get('Application')
->getEventManager()
->trigger(__FUNCTION__, $this, array(
'cronjobs' => $cronjobs
));
if ($results) {
foreach ($results as $key => $cron) {
foreach ($cron as $id => $conf) {
$cronjobs[$id] = $conf;
}
}
}
$this->setCronjobs($cronjobs);
}
return $this->cronjobs;
} | [
"public",
"function",
"getCronjobs",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"cronjobs",
")",
"{",
"$",
"cronjobs",
"=",
"array",
"(",
")",
";",
"$",
"results",
"=",
"$",
"this",
"->",
"serviceLocator",
"->",
"get",
"(",
"'Application'",
")",
"->",
"getEventManager",
"(",
")",
"->",
"trigger",
"(",
"__FUNCTION__",
",",
"$",
"this",
",",
"array",
"(",
"'cronjobs'",
"=>",
"$",
"cronjobs",
")",
")",
";",
"if",
"(",
"$",
"results",
")",
"{",
"foreach",
"(",
"$",
"results",
"as",
"$",
"key",
"=>",
"$",
"cron",
")",
"{",
"foreach",
"(",
"$",
"cron",
"as",
"$",
"id",
"=>",
"$",
"conf",
")",
"{",
"$",
"cronjobs",
"[",
"$",
"id",
"]",
"=",
"$",
"conf",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"setCronjobs",
"(",
"$",
"cronjobs",
")",
";",
"}",
"return",
"$",
"this",
"->",
"cronjobs",
";",
"}"
]
| trigger an event and fetch crons
Return array | [
"trigger",
"an",
"event",
"and",
"fetch",
"crons",
"Return",
"array"
]
| f8dfa4c7660b54354933b3c28c0cf35304a649df | https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/Service/Cron.php#L117-L141 |
16,093 | gregorybesson/PlaygroundCore | src/Service/Cron.php | Cron.schedule | public function schedule()
{
$em = $this->getEm();
$pending = $this->getPending();
$exists = array();
foreach ($pending as $job) {
$identifier = $job->getCode();
$identifier .= $job->getScheduleTime()->getTimeStamp();
$exists[$identifier] = true;
}
$scheduleAhead = $this->getScheduleAhead() * 60;
$cronRegistry = $this->getCronjobs();
foreach ($cronRegistry as $code => $item) {
$now = time();
$timeAhead = $now + $scheduleAhead;
for ($time = $now; $time < $timeAhead; $time += 60) {
$scheduleTime = new \DateTime();
$scheduleTime->setTimestamp($time);
$scheduleTime->setTime(
$scheduleTime->format('H'),
$scheduleTime->format('i')
);
$scheduleTimestamp = $scheduleTime->getTimestamp();
$identifier = $code . $scheduleTimestamp;
if (isset($exists[$identifier])) {
//already scheduled
continue;
}
$job = new Entity\Cronjob;
if ($this->matchTime(
$scheduleTimestamp,
$item['frequency']
)) {
$job
->setCode($code)
->setStatus(Mapper\Cronjob::STATUS_PENDING)
->setCreateTime(new \DateTime)
->setScheduleTime($scheduleTime);
$em->persist($job);
$exists[$identifier] = true;
}
}
}
$em->flush();
return $this;
} | php | public function schedule()
{
$em = $this->getEm();
$pending = $this->getPending();
$exists = array();
foreach ($pending as $job) {
$identifier = $job->getCode();
$identifier .= $job->getScheduleTime()->getTimeStamp();
$exists[$identifier] = true;
}
$scheduleAhead = $this->getScheduleAhead() * 60;
$cronRegistry = $this->getCronjobs();
foreach ($cronRegistry as $code => $item) {
$now = time();
$timeAhead = $now + $scheduleAhead;
for ($time = $now; $time < $timeAhead; $time += 60) {
$scheduleTime = new \DateTime();
$scheduleTime->setTimestamp($time);
$scheduleTime->setTime(
$scheduleTime->format('H'),
$scheduleTime->format('i')
);
$scheduleTimestamp = $scheduleTime->getTimestamp();
$identifier = $code . $scheduleTimestamp;
if (isset($exists[$identifier])) {
//already scheduled
continue;
}
$job = new Entity\Cronjob;
if ($this->matchTime(
$scheduleTimestamp,
$item['frequency']
)) {
$job
->setCode($code)
->setStatus(Mapper\Cronjob::STATUS_PENDING)
->setCreateTime(new \DateTime)
->setScheduleTime($scheduleTime);
$em->persist($job);
$exists[$identifier] = true;
}
}
}
$em->flush();
return $this;
} | [
"public",
"function",
"schedule",
"(",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getEm",
"(",
")",
";",
"$",
"pending",
"=",
"$",
"this",
"->",
"getPending",
"(",
")",
";",
"$",
"exists",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"pending",
"as",
"$",
"job",
")",
"{",
"$",
"identifier",
"=",
"$",
"job",
"->",
"getCode",
"(",
")",
";",
"$",
"identifier",
".=",
"$",
"job",
"->",
"getScheduleTime",
"(",
")",
"->",
"getTimeStamp",
"(",
")",
";",
"$",
"exists",
"[",
"$",
"identifier",
"]",
"=",
"true",
";",
"}",
"$",
"scheduleAhead",
"=",
"$",
"this",
"->",
"getScheduleAhead",
"(",
")",
"*",
"60",
";",
"$",
"cronRegistry",
"=",
"$",
"this",
"->",
"getCronjobs",
"(",
")",
";",
"foreach",
"(",
"$",
"cronRegistry",
"as",
"$",
"code",
"=>",
"$",
"item",
")",
"{",
"$",
"now",
"=",
"time",
"(",
")",
";",
"$",
"timeAhead",
"=",
"$",
"now",
"+",
"$",
"scheduleAhead",
";",
"for",
"(",
"$",
"time",
"=",
"$",
"now",
";",
"$",
"time",
"<",
"$",
"timeAhead",
";",
"$",
"time",
"+=",
"60",
")",
"{",
"$",
"scheduleTime",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"scheduleTime",
"->",
"setTimestamp",
"(",
"$",
"time",
")",
";",
"$",
"scheduleTime",
"->",
"setTime",
"(",
"$",
"scheduleTime",
"->",
"format",
"(",
"'H'",
")",
",",
"$",
"scheduleTime",
"->",
"format",
"(",
"'i'",
")",
")",
";",
"$",
"scheduleTimestamp",
"=",
"$",
"scheduleTime",
"->",
"getTimestamp",
"(",
")",
";",
"$",
"identifier",
"=",
"$",
"code",
".",
"$",
"scheduleTimestamp",
";",
"if",
"(",
"isset",
"(",
"$",
"exists",
"[",
"$",
"identifier",
"]",
")",
")",
"{",
"//already scheduled",
"continue",
";",
"}",
"$",
"job",
"=",
"new",
"Entity",
"\\",
"Cronjob",
";",
"if",
"(",
"$",
"this",
"->",
"matchTime",
"(",
"$",
"scheduleTimestamp",
",",
"$",
"item",
"[",
"'frequency'",
"]",
")",
")",
"{",
"$",
"job",
"->",
"setCode",
"(",
"$",
"code",
")",
"->",
"setStatus",
"(",
"Mapper",
"\\",
"Cronjob",
"::",
"STATUS_PENDING",
")",
"->",
"setCreateTime",
"(",
"new",
"\\",
"DateTime",
")",
"->",
"setScheduleTime",
"(",
"$",
"scheduleTime",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"job",
")",
";",
"$",
"exists",
"[",
"$",
"identifier",
"]",
"=",
"true",
";",
"}",
"}",
"}",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| schedule cron jobs
@return self | [
"schedule",
"cron",
"jobs"
]
| f8dfa4c7660b54354933b3c28c0cf35304a649df | https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/Service/Cron.php#L251-L304 |
16,094 | weavephp/weave | src/Resolve/Resolve.php | Resolve.resolve | public function resolve($value, &$resolutionType)
{
if (is_array($value)) {
$value = $value[0];
}
if (is_string($value)) {
if (strpos($value, '|') !== false) {
$resolutionType = ResolveAdaptorInterface::TYPE_PIPELINE;
return $this->resolveMiddlewarePipeline($value);
} elseif (strpos($value, '::') !== false) {
$resolutionType = ResolveAdaptorInterface::TYPE_STATIC;
return $this->resolveStatic($value);
} elseif (strpos($value, '->') !== false) {
$resolutionType = ResolveAdaptorInterface::TYPE_INSTANCE;
return $this->resolveInstanceMethod($value);
} else {
$resolutionType = ResolveAdaptorInterface::TYPE_INVOKE;
return $this->resolveInvokable($value);
}
} else {
$resolutionType = ResolveAdaptorInterface::TYPE_ORIGINAL;
return $value;
}
} | php | public function resolve($value, &$resolutionType)
{
if (is_array($value)) {
$value = $value[0];
}
if (is_string($value)) {
if (strpos($value, '|') !== false) {
$resolutionType = ResolveAdaptorInterface::TYPE_PIPELINE;
return $this->resolveMiddlewarePipeline($value);
} elseif (strpos($value, '::') !== false) {
$resolutionType = ResolveAdaptorInterface::TYPE_STATIC;
return $this->resolveStatic($value);
} elseif (strpos($value, '->') !== false) {
$resolutionType = ResolveAdaptorInterface::TYPE_INSTANCE;
return $this->resolveInstanceMethod($value);
} else {
$resolutionType = ResolveAdaptorInterface::TYPE_INVOKE;
return $this->resolveInvokable($value);
}
} else {
$resolutionType = ResolveAdaptorInterface::TYPE_ORIGINAL;
return $value;
}
} | [
"public",
"function",
"resolve",
"(",
"$",
"value",
",",
"&",
"$",
"resolutionType",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"[",
"0",
"]",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"value",
",",
"'|'",
")",
"!==",
"false",
")",
"{",
"$",
"resolutionType",
"=",
"ResolveAdaptorInterface",
"::",
"TYPE_PIPELINE",
";",
"return",
"$",
"this",
"->",
"resolveMiddlewarePipeline",
"(",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"value",
",",
"'::'",
")",
"!==",
"false",
")",
"{",
"$",
"resolutionType",
"=",
"ResolveAdaptorInterface",
"::",
"TYPE_STATIC",
";",
"return",
"$",
"this",
"->",
"resolveStatic",
"(",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"value",
",",
"'->'",
")",
"!==",
"false",
")",
"{",
"$",
"resolutionType",
"=",
"ResolveAdaptorInterface",
"::",
"TYPE_INSTANCE",
";",
"return",
"$",
"this",
"->",
"resolveInstanceMethod",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"resolutionType",
"=",
"ResolveAdaptorInterface",
"::",
"TYPE_INVOKE",
";",
"return",
"$",
"this",
"->",
"resolveInvokable",
"(",
"$",
"value",
")",
";",
"}",
"}",
"else",
"{",
"$",
"resolutionType",
"=",
"ResolveAdaptorInterface",
"::",
"TYPE_ORIGINAL",
";",
"return",
"$",
"value",
";",
"}",
"}"
]
| Attempt to convert a provided value into a callable.
If the value is an array, the rest of the rules apply to the first item.
If the value isn't a string it is simply returned.
If the string value contains '|' treat it as a pipeline name.
If the string value contains '::' treat it as a static method call.
If the string value contains '->' treat it as an instance method call.
Otherwise, attempt to treat it as an invokable.
@param string|callable|array $value The value to resolve.
@param string $resolutionType Set to the type of resolution identified.
@return callable Usually some form of callable. | [
"Attempt",
"to",
"convert",
"a",
"provided",
"value",
"into",
"a",
"callable",
"."
]
| 44183a5bcb9e3ed3754cc76aa9e0724d718caeec | https://github.com/weavephp/weave/blob/44183a5bcb9e3ed3754cc76aa9e0724d718caeec/src/Resolve/Resolve.php#L95-L118 |
16,095 | weavephp/weave | src/Resolve/Resolve.php | Resolve.resolveMiddlewarePipeline | protected function resolveMiddlewarePipeline($value)
{
$value = strstr($value, '|', true);
$instantiator = $this->instantiator;
$middleware = $instantiator(\Weave\Middleware\Middleware::class);
return function (Request $request, $response = null) use ($middleware, $value) {
return $middleware->chain($value, $request, $response);
};
} | php | protected function resolveMiddlewarePipeline($value)
{
$value = strstr($value, '|', true);
$instantiator = $this->instantiator;
$middleware = $instantiator(\Weave\Middleware\Middleware::class);
return function (Request $request, $response = null) use ($middleware, $value) {
return $middleware->chain($value, $request, $response);
};
} | [
"protected",
"function",
"resolveMiddlewarePipeline",
"(",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"strstr",
"(",
"$",
"value",
",",
"'|'",
",",
"true",
")",
";",
"$",
"instantiator",
"=",
"$",
"this",
"->",
"instantiator",
";",
"$",
"middleware",
"=",
"$",
"instantiator",
"(",
"\\",
"Weave",
"\\",
"Middleware",
"\\",
"Middleware",
"::",
"class",
")",
";",
"return",
"function",
"(",
"Request",
"$",
"request",
",",
"$",
"response",
"=",
"null",
")",
"use",
"(",
"$",
"middleware",
",",
"$",
"value",
")",
"{",
"return",
"$",
"middleware",
"->",
"chain",
"(",
"$",
"value",
",",
"$",
"request",
",",
"$",
"response",
")",
";",
"}",
";",
"}"
]
| Resolve the provided value to a named middleware chain.
@param string $value The name of the middleware chain plus optional chained dispatch.
@return callable A callable that executes the middleware chain. | [
"Resolve",
"the",
"provided",
"value",
"to",
"a",
"named",
"middleware",
"chain",
"."
]
| 44183a5bcb9e3ed3754cc76aa9e0724d718caeec | https://github.com/weavephp/weave/blob/44183a5bcb9e3ed3754cc76aa9e0724d718caeec/src/Resolve/Resolve.php#L127-L135 |
16,096 | weavephp/weave | src/Resolve/Resolve.php | Resolve.resolveInstanceMethod | protected function resolveInstanceMethod($value)
{
$callable = explode('->', $value);
$instantiator = $this->instantiator;
$callable[0] = $instantiator($callable[0]);
return function (...$params) use ($callable) {
return call_user_func_array($callable, $params);
};
} | php | protected function resolveInstanceMethod($value)
{
$callable = explode('->', $value);
$instantiator = $this->instantiator;
$callable[0] = $instantiator($callable[0]);
return function (...$params) use ($callable) {
return call_user_func_array($callable, $params);
};
} | [
"protected",
"function",
"resolveInstanceMethod",
"(",
"$",
"value",
")",
"{",
"$",
"callable",
"=",
"explode",
"(",
"'->'",
",",
"$",
"value",
")",
";",
"$",
"instantiator",
"=",
"$",
"this",
"->",
"instantiator",
";",
"$",
"callable",
"[",
"0",
"]",
"=",
"$",
"instantiator",
"(",
"$",
"callable",
"[",
"0",
"]",
")",
";",
"return",
"function",
"(",
"...",
"$",
"params",
")",
"use",
"(",
"$",
"callable",
")",
"{",
"return",
"call_user_func_array",
"(",
"$",
"callable",
",",
"$",
"params",
")",
";",
"}",
";",
"}"
]
| Resolve the provided value to an instancelass method call.
@param string $value The class and method definition string.
@return callable A callable that executes the instance method. | [
"Resolve",
"the",
"provided",
"value",
"to",
"an",
"instancelass",
"method",
"call",
"."
]
| 44183a5bcb9e3ed3754cc76aa9e0724d718caeec | https://github.com/weavephp/weave/blob/44183a5bcb9e3ed3754cc76aa9e0724d718caeec/src/Resolve/Resolve.php#L158-L166 |
16,097 | RinkAttendant6/JsonI18n | src/DateFormat.php | DateFormat.processData | private function processData(array $data): void
{
foreach ($data['formatters'] as $locale => $f) {
if (!isset($this->formatters[$locale])) {
$this->formatters[$locale] = array();
}
foreach ($f as $formatter => $d) {
$calendar = \IntlDateFormatter::GREGORIAN;
if (isset($d['calendar']) && $d['calendar'] === 'traditional') {
$calendar = \IntlDateFormatter::TRADITIONAL;
}
$this->formatters[$locale][$formatter] = new \IntlDateFormatter($locale, null, null, null, $calendar, $d['pattern']);
}
}
} | php | private function processData(array $data): void
{
foreach ($data['formatters'] as $locale => $f) {
if (!isset($this->formatters[$locale])) {
$this->formatters[$locale] = array();
}
foreach ($f as $formatter => $d) {
$calendar = \IntlDateFormatter::GREGORIAN;
if (isset($d['calendar']) && $d['calendar'] === 'traditional') {
$calendar = \IntlDateFormatter::TRADITIONAL;
}
$this->formatters[$locale][$formatter] = new \IntlDateFormatter($locale, null, null, null, $calendar, $d['pattern']);
}
}
} | [
"private",
"function",
"processData",
"(",
"array",
"$",
"data",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"data",
"[",
"'formatters'",
"]",
"as",
"$",
"locale",
"=>",
"$",
"f",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"formatters",
"[",
"$",
"locale",
"]",
")",
")",
"{",
"$",
"this",
"->",
"formatters",
"[",
"$",
"locale",
"]",
"=",
"array",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"f",
"as",
"$",
"formatter",
"=>",
"$",
"d",
")",
"{",
"$",
"calendar",
"=",
"\\",
"IntlDateFormatter",
"::",
"GREGORIAN",
";",
"if",
"(",
"isset",
"(",
"$",
"d",
"[",
"'calendar'",
"]",
")",
"&&",
"$",
"d",
"[",
"'calendar'",
"]",
"===",
"'traditional'",
")",
"{",
"$",
"calendar",
"=",
"\\",
"IntlDateFormatter",
"::",
"TRADITIONAL",
";",
"}",
"$",
"this",
"->",
"formatters",
"[",
"$",
"locale",
"]",
"[",
"$",
"formatter",
"]",
"=",
"new",
"\\",
"IntlDateFormatter",
"(",
"$",
"locale",
",",
"null",
",",
"null",
",",
"null",
",",
"$",
"calendar",
",",
"$",
"d",
"[",
"'pattern'",
"]",
")",
";",
"}",
"}",
"}"
]
| Processes the resource file data
@param array $data The data from the resource file | [
"Processes",
"the",
"resource",
"file",
"data"
]
| 882cbd43d273f771a384eb09d205d327033aaae3 | https://github.com/RinkAttendant6/JsonI18n/blob/882cbd43d273f771a384eb09d205d327033aaae3/src/DateFormat.php#L57-L73 |
16,098 | RinkAttendant6/JsonI18n | src/DateFormat.php | DateFormat.getFormatter | public function getFormatter(string $formatter, ?string $locale = null): \IntlDateFormatter
{
if ($locale === null) {
$locale = $this->locale;
}
if (!isset($this->formatters[$locale])) {
throw new \InvalidArgumentException('Locale data not found.');
}
if (!isset($this->formatters[$locale][$formatter])) {
throw new \InvalidArgumentException('Formatter not found for specified locale.');
}
return $this->formatters[$locale][$formatter];
} | php | public function getFormatter(string $formatter, ?string $locale = null): \IntlDateFormatter
{
if ($locale === null) {
$locale = $this->locale;
}
if (!isset($this->formatters[$locale])) {
throw new \InvalidArgumentException('Locale data not found.');
}
if (!isset($this->formatters[$locale][$formatter])) {
throw new \InvalidArgumentException('Formatter not found for specified locale.');
}
return $this->formatters[$locale][$formatter];
} | [
"public",
"function",
"getFormatter",
"(",
"string",
"$",
"formatter",
",",
"?",
"string",
"$",
"locale",
"=",
"null",
")",
":",
"\\",
"IntlDateFormatter",
"{",
"if",
"(",
"$",
"locale",
"===",
"null",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"locale",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"formatters",
"[",
"$",
"locale",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Locale data not found.'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"formatters",
"[",
"$",
"locale",
"]",
"[",
"$",
"formatter",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Formatter not found for specified locale.'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"formatters",
"[",
"$",
"locale",
"]",
"[",
"$",
"formatter",
"]",
";",
"}"
]
| Returns a IntlDateFormatter object
@param string $formatter The name of the formatter pattern
@param string $locale The locale. Defaults to default locale.
@return \IntlDateFormatter The formatter object
@throws \InvalidArgumentException If the locale or formatter name is invalid. | [
"Returns",
"a",
"IntlDateFormatter",
"object"
]
| 882cbd43d273f771a384eb09d205d327033aaae3 | https://github.com/RinkAttendant6/JsonI18n/blob/882cbd43d273f771a384eb09d205d327033aaae3/src/DateFormat.php#L111-L126 |
16,099 | markdegrootnl/omnipay-ideal | src/Message/AbstractRequest.php | AbstractRequest.signXML | public function signXML($data)
{
$xml = new DOMDocument;
$xml->preserveWhiteSpace = false;
$xml->loadXML($data);
$sig = new DOMDocument;
$sig->preserveWhiteSpace = false;
$sig->loadXML(
'<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<Reference URI="">
<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue/>
</Reference>
</SignedInfo>
<SignatureValue/>
<KeyInfo><KeyName/></KeyInfo>
</Signature>'
);
$sig = $xml->importNode($sig->documentElement, true);
$xml->documentElement->appendChild($sig);
// calculate digest
$xpath = $this->getXPath($xml);
$digestValue = $xpath->query('ds:Signature/ds:SignedInfo/ds:Reference/ds:DigestValue')->item(0);
$digestValue->nodeValue = $this->generateDigest($xml);
// calculate signature
$signedInfo = $xpath->query('ds:Signature/ds:SignedInfo')->item(0);
$signatureValue = $xpath->query('ds:Signature/ds:SignatureValue')->item(0);
$signatureValue->nodeValue = $this->generateSignature($signedInfo);
// add key reference
$keyName = $xpath->query('ds:Signature/ds:KeyInfo/ds:KeyName')->item(0);
$keyName->nodeValue = $this->getPublicKeyDigest();
return $xml->saveXML();
} | php | public function signXML($data)
{
$xml = new DOMDocument;
$xml->preserveWhiteSpace = false;
$xml->loadXML($data);
$sig = new DOMDocument;
$sig->preserveWhiteSpace = false;
$sig->loadXML(
'<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<Reference URI="">
<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue/>
</Reference>
</SignedInfo>
<SignatureValue/>
<KeyInfo><KeyName/></KeyInfo>
</Signature>'
);
$sig = $xml->importNode($sig->documentElement, true);
$xml->documentElement->appendChild($sig);
// calculate digest
$xpath = $this->getXPath($xml);
$digestValue = $xpath->query('ds:Signature/ds:SignedInfo/ds:Reference/ds:DigestValue')->item(0);
$digestValue->nodeValue = $this->generateDigest($xml);
// calculate signature
$signedInfo = $xpath->query('ds:Signature/ds:SignedInfo')->item(0);
$signatureValue = $xpath->query('ds:Signature/ds:SignatureValue')->item(0);
$signatureValue->nodeValue = $this->generateSignature($signedInfo);
// add key reference
$keyName = $xpath->query('ds:Signature/ds:KeyInfo/ds:KeyName')->item(0);
$keyName->nodeValue = $this->getPublicKeyDigest();
return $xml->saveXML();
} | [
"public",
"function",
"signXML",
"(",
"$",
"data",
")",
"{",
"$",
"xml",
"=",
"new",
"DOMDocument",
";",
"$",
"xml",
"->",
"preserveWhiteSpace",
"=",
"false",
";",
"$",
"xml",
"->",
"loadXML",
"(",
"$",
"data",
")",
";",
"$",
"sig",
"=",
"new",
"DOMDocument",
";",
"$",
"sig",
"->",
"preserveWhiteSpace",
"=",
"false",
";",
"$",
"sig",
"->",
"loadXML",
"(",
"'<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\">\n <SignedInfo>\n <CanonicalizationMethod Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"/>\n <SignatureMethod Algorithm=\"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256\"/>\n <Reference URI=\"\">\n <Transforms>\n <Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"/>\n </Transforms>\n <DigestMethod Algorithm=\"http://www.w3.org/2001/04/xmlenc#sha256\"/>\n <DigestValue/>\n </Reference>\n </SignedInfo>\n <SignatureValue/>\n <KeyInfo><KeyName/></KeyInfo>\n </Signature>'",
")",
";",
"$",
"sig",
"=",
"$",
"xml",
"->",
"importNode",
"(",
"$",
"sig",
"->",
"documentElement",
",",
"true",
")",
";",
"$",
"xml",
"->",
"documentElement",
"->",
"appendChild",
"(",
"$",
"sig",
")",
";",
"// calculate digest",
"$",
"xpath",
"=",
"$",
"this",
"->",
"getXPath",
"(",
"$",
"xml",
")",
";",
"$",
"digestValue",
"=",
"$",
"xpath",
"->",
"query",
"(",
"'ds:Signature/ds:SignedInfo/ds:Reference/ds:DigestValue'",
")",
"->",
"item",
"(",
"0",
")",
";",
"$",
"digestValue",
"->",
"nodeValue",
"=",
"$",
"this",
"->",
"generateDigest",
"(",
"$",
"xml",
")",
";",
"// calculate signature",
"$",
"signedInfo",
"=",
"$",
"xpath",
"->",
"query",
"(",
"'ds:Signature/ds:SignedInfo'",
")",
"->",
"item",
"(",
"0",
")",
";",
"$",
"signatureValue",
"=",
"$",
"xpath",
"->",
"query",
"(",
"'ds:Signature/ds:SignatureValue'",
")",
"->",
"item",
"(",
"0",
")",
";",
"$",
"signatureValue",
"->",
"nodeValue",
"=",
"$",
"this",
"->",
"generateSignature",
"(",
"$",
"signedInfo",
")",
";",
"// add key reference",
"$",
"keyName",
"=",
"$",
"xpath",
"->",
"query",
"(",
"'ds:Signature/ds:KeyInfo/ds:KeyName'",
")",
"->",
"item",
"(",
"0",
")",
";",
"$",
"keyName",
"->",
"nodeValue",
"=",
"$",
"this",
"->",
"getPublicKeyDigest",
"(",
")",
";",
"return",
"$",
"xml",
"->",
"saveXML",
"(",
")",
";",
"}"
]
| Sign an XML request
@param string
@return string | [
"Sign",
"an",
"XML",
"request"
]
| 565e942c2d22dd160ce6101cc5743f131af54660 | https://github.com/markdegrootnl/omnipay-ideal/blob/565e942c2d22dd160ce6101cc5743f131af54660/src/Message/AbstractRequest.php#L134-L178 |
Subsets and Splits