repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
bseddon/XBRL | Formulas/Resources/Formulas/GeneratedFacts.php | GeneratedFacts.moveToFirstConcept | private function moveToFirstConcept( $nav, &$contexts, &$units )
{
$nav->MoveToDocumentElement();
$result = $nav->MoveToChild( XPathNodeType::Element );
while ( $result )
{
switch ( $nav->getLocalName() )
{
case 'schemaRef':
break;
case 'linkbaseRef':
break;
case 'context':
$id = $nav->GetAttribute( 'id', null );
$contexts[ $id ] = $nav->CloneInstance();
break;
case 'unit':
$id = $nav->GetAttribute( 'id', null );
$units[ $id ] = $nav->CloneInstance();
break;
default:
// Don't be tempted to chgange this
return true;
}
$result = $nav->MoveToNext( XPathNodeType::Element );
}
return false;
} | php | private function moveToFirstConcept( $nav, &$contexts, &$units )
{
$nav->MoveToDocumentElement();
$result = $nav->MoveToChild( XPathNodeType::Element );
while ( $result )
{
switch ( $nav->getLocalName() )
{
case 'schemaRef':
break;
case 'linkbaseRef':
break;
case 'context':
$id = $nav->GetAttribute( 'id', null );
$contexts[ $id ] = $nav->CloneInstance();
break;
case 'unit':
$id = $nav->GetAttribute( 'id', null );
$units[ $id ] = $nav->CloneInstance();
break;
default:
// Don't be tempted to chgange this
return true;
}
$result = $nav->MoveToNext( XPathNodeType::Element );
}
return false;
} | [
"private",
"function",
"moveToFirstConcept",
"(",
"$",
"nav",
",",
"&",
"$",
"contexts",
",",
"&",
"$",
"units",
")",
"{",
"$",
"nav",
"->",
"MoveToDocumentElement",
"(",
")",
";",
"$",
"result",
"=",
"$",
"nav",
"->",
"MoveToChild",
"(",
"XPathNodeType"... | Move the navigator to the first concept in the document processng all elements along the way
@param DOMXPathNavigator $nav
@param array $contexts (by reference)
@param array $units (by reference) | [
"Move",
"the",
"navigator",
"to",
"the",
"first",
"concept",
"in",
"the",
"document",
"processng",
"all",
"elements",
"along",
"the",
"way"
] | 6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94 | https://github.com/bseddon/XBRL/blob/6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94/Formulas/Resources/Formulas/GeneratedFacts.php#L862-L896 | train |
bseddon/XBRL | Formulas/Resources/Formulas/GeneratedFacts.php | GeneratedFacts.addContexts | private function addContexts( &$document, $xbrldiPrefix )
{
foreach ( $this->contexts as $contextRef => $context )
{
$document[] = " <context id=\"$contextRef\">";
if ( isset( $context['entity'] ) )
{
$document[] = " <entity>";
if ( isset( $context['entity']['identifier'] ) )
{
$document[] = " <identifier scheme=\"{$context['entity']['identifier']['scheme']}\">{$context['entity']['identifier']['value']}</identifier>";
}
if ( isset( $context['entity']['segment'] ) )
{
$this->addComponent( "segment", $context['entity']['segment'], $document, " ", $xbrldiPrefix );
}
if ( isset( $context['entity']['scenario'] ) )
{
$this->addComponent( "scenario", $context['entity']['scenario'], $document, " ", $xbrldiPrefix );
}
$document[] = " </entity>";
}
if ( isset( $context['period'] ) )
{
$document[] = " <period>";
if ( $context['period']['is_instant'] )
{
$document[] = " <instant>{$context['period']['startDate']}</instant>";
}
else if ( isset( $context['period']['type'] ) && $context['period']['type'] == 'forever' )
{
$document[] = " <forever/>";
}
else if ( isset( $context['period']['type'] ) && $context['period']['type'] == 'duration' )
{
$document[] = " <startDate>{$context['period']['startDate']}</startDate>";
$document[] = " <endDate>{$context['period']['endDate']}</endDate>";
}
$document[] = " </period>";
}
if ( isset( $context['segment'] ) )
{
$this->addComponent( "segment", $context['segment'], $document, " ", $xbrldiPrefix );
}
if ( isset( $context['scenario'] ) )
{
$this->addComponent( "scenario", $context['scenario'], $document, " ", $xbrldiPrefix );
}
$document[] = " </context>";
$document[] = "";
}
} | php | private function addContexts( &$document, $xbrldiPrefix )
{
foreach ( $this->contexts as $contextRef => $context )
{
$document[] = " <context id=\"$contextRef\">";
if ( isset( $context['entity'] ) )
{
$document[] = " <entity>";
if ( isset( $context['entity']['identifier'] ) )
{
$document[] = " <identifier scheme=\"{$context['entity']['identifier']['scheme']}\">{$context['entity']['identifier']['value']}</identifier>";
}
if ( isset( $context['entity']['segment'] ) )
{
$this->addComponent( "segment", $context['entity']['segment'], $document, " ", $xbrldiPrefix );
}
if ( isset( $context['entity']['scenario'] ) )
{
$this->addComponent( "scenario", $context['entity']['scenario'], $document, " ", $xbrldiPrefix );
}
$document[] = " </entity>";
}
if ( isset( $context['period'] ) )
{
$document[] = " <period>";
if ( $context['period']['is_instant'] )
{
$document[] = " <instant>{$context['period']['startDate']}</instant>";
}
else if ( isset( $context['period']['type'] ) && $context['period']['type'] == 'forever' )
{
$document[] = " <forever/>";
}
else if ( isset( $context['period']['type'] ) && $context['period']['type'] == 'duration' )
{
$document[] = " <startDate>{$context['period']['startDate']}</startDate>";
$document[] = " <endDate>{$context['period']['endDate']}</endDate>";
}
$document[] = " </period>";
}
if ( isset( $context['segment'] ) )
{
$this->addComponent( "segment", $context['segment'], $document, " ", $xbrldiPrefix );
}
if ( isset( $context['scenario'] ) )
{
$this->addComponent( "scenario", $context['scenario'], $document, " ", $xbrldiPrefix );
}
$document[] = " </context>";
$document[] = "";
}
} | [
"private",
"function",
"addContexts",
"(",
"&",
"$",
"document",
",",
"$",
"xbrldiPrefix",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"contexts",
"as",
"$",
"contextRef",
"=>",
"$",
"context",
")",
"{",
"$",
"document",
"[",
"]",
"=",
"\" <context id=... | An array to which context information should be added
@param array $document (passed by reference)
@param string $xbrldiPrefix | [
"An",
"array",
"to",
"which",
"context",
"information",
"should",
"be",
"added"
] | 6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94 | https://github.com/bseddon/XBRL/blob/6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94/Formulas/Resources/Formulas/GeneratedFacts.php#L903-L964 | train |
bseddon/XBRL | Formulas/Resources/Formulas/GeneratedFacts.php | GeneratedFacts.addComponent | private function addComponent( $componentType, $component, &$document, $prefix, $xbrldiPrefix )
{
$entry[] = "<$componentType>";
foreach ( $component as $memberType => $members )
{
switch ( $memberType )
{
case 'member':
// $entry[] = " <member>";
foreach ( $members as $member )
{
$attributesList = array();
$attributes = "";
if ( isset( $member['attributes'] ) )
{
foreach ( $member['attributes'] as $name => $attribute )
{
$attributesList[] = "{$attribute['name']}=\"{$attribute['value']}\"";
}
$attributes = " " . implode( " ", $attributesList ) . " ";
}
if ( isset( $member['member'] ) )
{
if ( $member['member'] )
{
$entry[] = " <{$member['name']}>{$member['member']}</{$member['name']}$attributes>";
}
else
{
$entry[] = " <{$member['name']}$attributes/>";
}
}
else if ( isset( $member['children'] ) )
{
$createXml = function( $member, $length, $attributes = null ) use( &$createXml, &$entry )
{
$padding = str_pad( "", $length, " ");
if ( isset( $member['children'] ) )
{
$entry[] = $padding . "<{$member['prefix']}:{$member['name']}$attributes>";
foreach ( $member['children'] as $child )
{
$createXml( $child, $length + 2 );
}
$entry[] = $padding . "</{$member['prefix']}:{$member['name']}>";
}
else
{
$entry[] = $padding. "<{$member['prefix']}:{$member['name']}$attributes/>";
}
};
$createXml( $member, 2, $attributes);
}
}
// $entry[] = " </member>";
break;
case 'explicitMember':
foreach ( $members as $member )
{
$entry[] = " <$xbrldiPrefix:explicitMember dimension=\"{$member['dimension']}\">{$member['member']}</$xbrldiPrefix:explicitMember>";
}
break;
case 'typedMember':
foreach ( $members as $member )
{
$entry[] = " <$xbrldiPrefix:typedMember dimension=\"{$member['dimension']}\">";
foreach ( $member['member'] as $valueName => $names )
{
if ( is_array( $names ) )
{
foreach ( $names as $name )
{
// $entry[] = " <$valueName>$name</$valueName>";
$entry[] = " $name";
}
}
else
{
$entry[] = " <$valueName>$names</$valueName>";
}
}
$entry[] = " </$xbrldiPrefix:typedMember>";
}
break;
}
}
$entry[] = "</$componentType>";
$document[] = $prefix . implode( "\n$prefix", $entry );
} | php | private function addComponent( $componentType, $component, &$document, $prefix, $xbrldiPrefix )
{
$entry[] = "<$componentType>";
foreach ( $component as $memberType => $members )
{
switch ( $memberType )
{
case 'member':
// $entry[] = " <member>";
foreach ( $members as $member )
{
$attributesList = array();
$attributes = "";
if ( isset( $member['attributes'] ) )
{
foreach ( $member['attributes'] as $name => $attribute )
{
$attributesList[] = "{$attribute['name']}=\"{$attribute['value']}\"";
}
$attributes = " " . implode( " ", $attributesList ) . " ";
}
if ( isset( $member['member'] ) )
{
if ( $member['member'] )
{
$entry[] = " <{$member['name']}>{$member['member']}</{$member['name']}$attributes>";
}
else
{
$entry[] = " <{$member['name']}$attributes/>";
}
}
else if ( isset( $member['children'] ) )
{
$createXml = function( $member, $length, $attributes = null ) use( &$createXml, &$entry )
{
$padding = str_pad( "", $length, " ");
if ( isset( $member['children'] ) )
{
$entry[] = $padding . "<{$member['prefix']}:{$member['name']}$attributes>";
foreach ( $member['children'] as $child )
{
$createXml( $child, $length + 2 );
}
$entry[] = $padding . "</{$member['prefix']}:{$member['name']}>";
}
else
{
$entry[] = $padding. "<{$member['prefix']}:{$member['name']}$attributes/>";
}
};
$createXml( $member, 2, $attributes);
}
}
// $entry[] = " </member>";
break;
case 'explicitMember':
foreach ( $members as $member )
{
$entry[] = " <$xbrldiPrefix:explicitMember dimension=\"{$member['dimension']}\">{$member['member']}</$xbrldiPrefix:explicitMember>";
}
break;
case 'typedMember':
foreach ( $members as $member )
{
$entry[] = " <$xbrldiPrefix:typedMember dimension=\"{$member['dimension']}\">";
foreach ( $member['member'] as $valueName => $names )
{
if ( is_array( $names ) )
{
foreach ( $names as $name )
{
// $entry[] = " <$valueName>$name</$valueName>";
$entry[] = " $name";
}
}
else
{
$entry[] = " <$valueName>$names</$valueName>";
}
}
$entry[] = " </$xbrldiPrefix:typedMember>";
}
break;
}
}
$entry[] = "</$componentType>";
$document[] = $prefix . implode( "\n$prefix", $entry );
} | [
"private",
"function",
"addComponent",
"(",
"$",
"componentType",
",",
"$",
"component",
",",
"&",
"$",
"document",
",",
"$",
"prefix",
",",
"$",
"xbrldiPrefix",
")",
"{",
"$",
"entry",
"[",
"]",
"=",
"\"<$componentType>\"",
";",
"foreach",
"(",
"$",
"co... | Add the details for an OCC
@param string $componentType Scenario or segment
@param array $component A list of componets for the component type
@param array $document An array of lines
@param string $prefix The text (spaces) to add as a prefix to the line
@param string $xbrldiPrefix The xbrldi prefix to use in this generated document | [
"Add",
"the",
"details",
"for",
"an",
"OCC"
] | 6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94 | https://github.com/bseddon/XBRL/blob/6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94/Formulas/Resources/Formulas/GeneratedFacts.php#L974-L1080 | train |
bseddon/XBRL | Formulas/Resources/Formulas/GeneratedFacts.php | GeneratedFacts.addUnits | private function addUnits( &$document )
{
foreach ( $this->units as $unitRef => $unit )
{
$entry = array();
$entry[] = " <unit id=\"$unitRef\">";
if ( isset( $unit['divide'] ) )
{
$entry[] = " <divide>";
if ( isset( $unit['divide']['numerator'] ) && count( $unit['divide']['numerator'] ) )
{
$entry[] = " <unitNumerator>";
foreach ( $unit['divide']['numerator'] as $measure )
{
$entry[] = " <measure>$measure</measure>";
}
$entry[] = " </unitNumerator>";
}
if ( isset( $unit['divide']['denominator'] ) && count( $unit['divide']['denominator'] ) )
{
$entry[] = " <unitDenominator>";
foreach ( $unit['divide']['denominator'] as $measure )
{
$entry[] = " <measure>$measure</measure>";
}
$entry[] = " </unitDenominator>";
}
$entry[] = " </divide>";
}
else if ( isset( $unit['measures'] ) )
{
foreach ( $unit['measures'] as $measure )
{
$entry[] = " <measure>$measure</measure>";
}
}
else
{
$xbrli = STANDARD_PREFIX_XBRLI;
$unit = str_replace( "{$xbrli}:", "", $unit );
$entry[] = " <measure>$unit</measure>";
}
$entry[] = " </unit>";
$entry[] = "";
$document[] = implode( "\n", $entry );
}
} | php | private function addUnits( &$document )
{
foreach ( $this->units as $unitRef => $unit )
{
$entry = array();
$entry[] = " <unit id=\"$unitRef\">";
if ( isset( $unit['divide'] ) )
{
$entry[] = " <divide>";
if ( isset( $unit['divide']['numerator'] ) && count( $unit['divide']['numerator'] ) )
{
$entry[] = " <unitNumerator>";
foreach ( $unit['divide']['numerator'] as $measure )
{
$entry[] = " <measure>$measure</measure>";
}
$entry[] = " </unitNumerator>";
}
if ( isset( $unit['divide']['denominator'] ) && count( $unit['divide']['denominator'] ) )
{
$entry[] = " <unitDenominator>";
foreach ( $unit['divide']['denominator'] as $measure )
{
$entry[] = " <measure>$measure</measure>";
}
$entry[] = " </unitDenominator>";
}
$entry[] = " </divide>";
}
else if ( isset( $unit['measures'] ) )
{
foreach ( $unit['measures'] as $measure )
{
$entry[] = " <measure>$measure</measure>";
}
}
else
{
$xbrli = STANDARD_PREFIX_XBRLI;
$unit = str_replace( "{$xbrli}:", "", $unit );
$entry[] = " <measure>$unit</measure>";
}
$entry[] = " </unit>";
$entry[] = "";
$document[] = implode( "\n", $entry );
}
} | [
"private",
"function",
"addUnits",
"(",
"&",
"$",
"document",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"units",
"as",
"$",
"unitRef",
"=>",
"$",
"unit",
")",
"{",
"$",
"entry",
"=",
"array",
"(",
")",
";",
"$",
"entry",
"[",
"]",
"=",
"\" <u... | An array to which unit information should be added
@param array $document (passed by reference) | [
"An",
"array",
"to",
"which",
"unit",
"information",
"should",
"be",
"added"
] | 6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94 | https://github.com/bseddon/XBRL/blob/6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94/Formulas/Resources/Formulas/GeneratedFacts.php#L1086-L1141 | train |
bseddon/XBRL | Formulas/Resources/Variables/Variable.php | Variable.getQName | public function getQName()
{
// Use the cached name if there is one.
if ( ! $this->qname )
{
if ( ! property_exists( $this, 'name' ) ) return null;
$this->qname = $qname = new QName( $this->name['originalPrefix'], $this->name['namespace'], $this->name['name'] );
}
return $this->qname;
} | php | public function getQName()
{
// Use the cached name if there is one.
if ( ! $this->qname )
{
if ( ! property_exists( $this, 'name' ) ) return null;
$this->qname = $qname = new QName( $this->name['originalPrefix'], $this->name['namespace'], $this->name['name'] );
}
return $this->qname;
} | [
"public",
"function",
"getQName",
"(",
")",
"{",
"// Use the cached name if there is one.\r",
"if",
"(",
"!",
"$",
"this",
"->",
"qname",
")",
"{",
"if",
"(",
"!",
"property_exists",
"(",
"$",
"this",
",",
"'name'",
")",
")",
"return",
"null",
";",
"$",
... | Return the QName of the 'name' property if any
@return NULL|QName | [
"Return",
"the",
"QName",
"of",
"the",
"name",
"property",
"if",
"any"
] | 6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94 | https://github.com/bseddon/XBRL/blob/6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94/Formulas/Resources/Variables/Variable.php#L109-L119 | train |
bseddon/XBRL | XBRL-DateInterval.php | XBRL_DateInterval.createFromDateInterval | public static function createFromDateInterval(DateInterval $interval)
{
$obj = new self( 'PT0S' );
foreach ( $interval as $property => $value ) {
$obj->$property = $value;
}
return $obj;
} | php | public static function createFromDateInterval(DateInterval $interval)
{
$obj = new self( 'PT0S' );
foreach ( $interval as $property => $value ) {
$obj->$property = $value;
}
return $obj;
} | [
"public",
"static",
"function",
"createFromDateInterval",
"(",
"DateInterval",
"$",
"interval",
")",
"{",
"$",
"obj",
"=",
"new",
"self",
"(",
"'PT0S'",
")",
";",
"foreach",
"(",
"$",
"interval",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"$",
... | Create an instance of this class from an existing DateInterval instance
@param DateInterval $interval
@return XBRL_DateInterval | [
"Create",
"an",
"instance",
"of",
"this",
"class",
"from",
"an",
"existing",
"DateInterval",
"instance"
] | 6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94 | https://github.com/bseddon/XBRL/blob/6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94/XBRL-DateInterval.php#L65-L72 | train |
bseddon/XBRL | Formulas/Resources/Variables/Signature.php | Signature.validate | public function validate( $variableSet, $nsMgr )
{
if ( ! $this->name )
{
\XBRL_Log::getInstance()->formula_validation( 'Custom function', 'Custom function name is not defined', array(
'error' => 'xbrlve:noNameForCustomFunction'
) );
return false;
}
$qname = $this->getQName();
if ( $qname->namespaceURI == \XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_FUNCTION_INSTANCE ] )
{
\XBRL_Log::getInstance()->formula_validation( 'Custom function', 'Custom function name has a namespace reserved for functions in the function registry (xfi)', array(
'signature' => $qname->prefix . ":" . $qname->localName,
'error' => 'xbrlve:noProhibitedNamespaceForCustomFunction'
) );
}
if ( $this->output )
{
$outputQName = qname( $this->output, $nsMgr->getNamespaces() );
if ( $outputQName && ! \XBRL::startsWith( $this->output, "xs:" ) && $outputQName->namespaceURI != \XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_SCHEMA ] )
{
\XBRL_Log::getInstance()->formula_validation( 'Custom function', 'Custom function outut type is not valid', array(
'type' => $this->output ? $this->output : "missing",
'error' => 'xbrlve:invalidDatatypeInCustomFunctionSignature'
) );
}
}
return true;
} | php | public function validate( $variableSet, $nsMgr )
{
if ( ! $this->name )
{
\XBRL_Log::getInstance()->formula_validation( 'Custom function', 'Custom function name is not defined', array(
'error' => 'xbrlve:noNameForCustomFunction'
) );
return false;
}
$qname = $this->getQName();
if ( $qname->namespaceURI == \XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_FUNCTION_INSTANCE ] )
{
\XBRL_Log::getInstance()->formula_validation( 'Custom function', 'Custom function name has a namespace reserved for functions in the function registry (xfi)', array(
'signature' => $qname->prefix . ":" . $qname->localName,
'error' => 'xbrlve:noProhibitedNamespaceForCustomFunction'
) );
}
if ( $this->output )
{
$outputQName = qname( $this->output, $nsMgr->getNamespaces() );
if ( $outputQName && ! \XBRL::startsWith( $this->output, "xs:" ) && $outputQName->namespaceURI != \XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_SCHEMA ] )
{
\XBRL_Log::getInstance()->formula_validation( 'Custom function', 'Custom function outut type is not valid', array(
'type' => $this->output ? $this->output : "missing",
'error' => 'xbrlve:invalidDatatypeInCustomFunctionSignature'
) );
}
}
return true;
} | [
"public",
"function",
"validate",
"(",
"$",
"variableSet",
",",
"$",
"nsMgr",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"name",
")",
"{",
"\\",
"XBRL_Log",
"::",
"getInstance",
"(",
")",
"->",
"formula_validation",
"(",
"'Custom function'",
",",
"'Cus... | Validate the signature values
@param VariableSet $variableSet
@param XmlNamespaceManager $nsMgr
@return bool | [
"Validate",
"the",
"signature",
"values"
] | 6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94 | https://github.com/bseddon/XBRL/blob/6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94/Formulas/Resources/Variables/Signature.php#L134-L167 | train |
bseddon/XBRL | XBRL-SEC-XML-Package.php | XBRL_SEC_XML_Package.processElement | private function processElement( $elements )
{
foreach ( $elements as $name => $value )
{
if ( $value->count() ) continue;
if ( ! property_exists( $this, $name ) ) continue;
$this->$name = (string)$value;
}
} | php | private function processElement( $elements )
{
foreach ( $elements as $name => $value )
{
if ( $value->count() ) continue;
if ( ! property_exists( $this, $name ) ) continue;
$this->$name = (string)$value;
}
} | [
"private",
"function",
"processElement",
"(",
"$",
"elements",
")",
"{",
"foreach",
"(",
"$",
"elements",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"->",
"count",
"(",
")",
")",
"continue",
";",
"if",
"(",
"!",
"prop... | Grab the values from the XML
@param SimpleXMLElement $elements | [
"Grab",
"the",
"values",
"from",
"the",
"XML"
] | 6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94 | https://github.com/bseddon/XBRL/blob/6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94/XBRL-SEC-XML-Package.php#L152-L161 | train |
bseddon/XBRL | XBRL-SEC-XML-Package.php | XBRL_SEC_XML_Package.processXBRLFiles | private function processXBRLFiles( $elements )
{
/**
* An array of files each with the following elements
* sequence="1"
* file="quest_10k.htm"
* type="10-K"
* size="314940"
* description="FORM 10-K"
* url="http://www.sec.gov/Archives/edgar/data/1627554/000147793216008346/quest_10k.htm"
* @var array $xbrlFiles
*/
$xbrlFiles = array();
foreach ( $elements as $name => $element )
{
$xbrlFile = array();
foreach ( $element->attributes( XBRL_SEC_XML_Package::edgarNamespace ) as $attributeName => $value )
{
$xbrlFile[ $attributeName ] = (string)$value;
}
$xbrlFiles[] = $xbrlFile;
}
$this->xbrlFiles = $xbrlFiles;
// Create the array contain just the file names
$this->files = array_map( function( $item ) {
return $item['file'];
}, $xbrlFiles );
} | php | private function processXBRLFiles( $elements )
{
/**
* An array of files each with the following elements
* sequence="1"
* file="quest_10k.htm"
* type="10-K"
* size="314940"
* description="FORM 10-K"
* url="http://www.sec.gov/Archives/edgar/data/1627554/000147793216008346/quest_10k.htm"
* @var array $xbrlFiles
*/
$xbrlFiles = array();
foreach ( $elements as $name => $element )
{
$xbrlFile = array();
foreach ( $element->attributes( XBRL_SEC_XML_Package::edgarNamespace ) as $attributeName => $value )
{
$xbrlFile[ $attributeName ] = (string)$value;
}
$xbrlFiles[] = $xbrlFile;
}
$this->xbrlFiles = $xbrlFiles;
// Create the array contain just the file names
$this->files = array_map( function( $item ) {
return $item['file'];
}, $xbrlFiles );
} | [
"private",
"function",
"processXBRLFiles",
"(",
"$",
"elements",
")",
"{",
"/**\r\n\t\t * An array of files each with the following elements\r\n\t\t * \t\tsequence=\"1\"\r\n\t\t * \t\tfile=\"quest_10k.htm\"\r\n\t\t * \t\ttype=\"10-K\"\r\n\t\t * \t\tsize=\"314940\"\r\n\t\t * \t\tdescription=\"FORM 10... | Extract the file names from the manifest
@param SimpleXMLElement $elements | [
"Extract",
"the",
"file",
"names",
"from",
"the",
"manifest"
] | 6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94 | https://github.com/bseddon/XBRL/blob/6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94/XBRL-SEC-XML-Package.php#L167-L199 | train |
bseddon/XBRL | Formulas/Resources/Formulas/Aspects/ExplicitDimension.php | ExplicitDimension.getValue | public function getValue( $variableSet, $evaluationResult, $log )
{
// This is an error
if ( ! isset( $variableSet->context ) ) return array();
// Get context for this rule's source
$sourceContext = $variableSet->getComponentForPath( $this->source, $variableSet->explicitDimensionsComponentPath, 'explicitMember', $evaluationResult, $this->aspectDimension, $log, $contextRef );
$sourceContext = Dimension::contextToIndex( $sourceContext, true, $variableSet, $this->aspectDimension );
// Get original context
$context = $variableSet->context;
if ( ! $variableSet->xbrlInstance->getNamespaceForPrefix( $this->dimension['originalPrefix'] ) )
{
$this->dimension['originalPrefix'] = $variableSet->xbrlInstance->getPrefixForNamespace( $this->dimension['namespace'] );
}
$dimensionQName = "{$this->dimension['originalPrefix']}:{$this->dimension['name']}";
if ( $this->omit )
{
// Omit always applies to the default context
unset( $context[ $dimensionQName ] );
}
else if ( $this->member )
{
// If a member is defined then the dimension/member is being added or updated
if ( isset( $this->member['qname'] ) )
{
// Make sure the prefix is compatible with the instance document
$qname = qname( $this->member['qname'], $variableSet->nsMgr->getNamespaces() );
if ( ! $variableSet->xbrlInstance->getNamespaceForPrefix( $qname->prefix ) )
{
$qname->prefix = $variableSet->xbrlInstance->getPrefixForNamespace( $qname->namespaceURI );
}
$name = "{$qname->prefix}:{$qname->localName}";
$context[ $dimensionQName ] = array( $name => $name );
}
else if ( $this->member['qnameExpression'] )
{
$vars = $evaluationResult['vars'];
$result = $this->evaluateXPath( $variableSet, "{$this->member['qnameExpression']} cast as xs:string", $vars );
$qname = qname( $result->getValue(), $variableSet->nsMgr->getNamespaces() );
if ( ! $variableSet->xbrlInstance->getNamespaceForPrefix( $qname->prefix ) )
{
$qname->prefix = $variableSet->xbrlInstance->getPrefixForNamespace( $qname->namespaceURI );
}
$name = "{$qname->prefix}:{$qname->localName}";
$context[ $dimensionQName ] = array( $name => $name );
}
}
else if ( isset( $sourceContext[ $dimensionQName ] ) )
{
// Add any members from the source
$context[ $dimensionQName ] = $sourceContext[ $dimensionQName ];
}
else
{
$log->formula_validation( "Explicit dimension aspect rule", "A dimension is being added but there are no members",
array(
'dimension' => $dimensionQName,
'error' => 'xbrlfe:missingSAVForExplicitDimensionRule'
)
);
}
return $context;
} | php | public function getValue( $variableSet, $evaluationResult, $log )
{
// This is an error
if ( ! isset( $variableSet->context ) ) return array();
// Get context for this rule's source
$sourceContext = $variableSet->getComponentForPath( $this->source, $variableSet->explicitDimensionsComponentPath, 'explicitMember', $evaluationResult, $this->aspectDimension, $log, $contextRef );
$sourceContext = Dimension::contextToIndex( $sourceContext, true, $variableSet, $this->aspectDimension );
// Get original context
$context = $variableSet->context;
if ( ! $variableSet->xbrlInstance->getNamespaceForPrefix( $this->dimension['originalPrefix'] ) )
{
$this->dimension['originalPrefix'] = $variableSet->xbrlInstance->getPrefixForNamespace( $this->dimension['namespace'] );
}
$dimensionQName = "{$this->dimension['originalPrefix']}:{$this->dimension['name']}";
if ( $this->omit )
{
// Omit always applies to the default context
unset( $context[ $dimensionQName ] );
}
else if ( $this->member )
{
// If a member is defined then the dimension/member is being added or updated
if ( isset( $this->member['qname'] ) )
{
// Make sure the prefix is compatible with the instance document
$qname = qname( $this->member['qname'], $variableSet->nsMgr->getNamespaces() );
if ( ! $variableSet->xbrlInstance->getNamespaceForPrefix( $qname->prefix ) )
{
$qname->prefix = $variableSet->xbrlInstance->getPrefixForNamespace( $qname->namespaceURI );
}
$name = "{$qname->prefix}:{$qname->localName}";
$context[ $dimensionQName ] = array( $name => $name );
}
else if ( $this->member['qnameExpression'] )
{
$vars = $evaluationResult['vars'];
$result = $this->evaluateXPath( $variableSet, "{$this->member['qnameExpression']} cast as xs:string", $vars );
$qname = qname( $result->getValue(), $variableSet->nsMgr->getNamespaces() );
if ( ! $variableSet->xbrlInstance->getNamespaceForPrefix( $qname->prefix ) )
{
$qname->prefix = $variableSet->xbrlInstance->getPrefixForNamespace( $qname->namespaceURI );
}
$name = "{$qname->prefix}:{$qname->localName}";
$context[ $dimensionQName ] = array( $name => $name );
}
}
else if ( isset( $sourceContext[ $dimensionQName ] ) )
{
// Add any members from the source
$context[ $dimensionQName ] = $sourceContext[ $dimensionQName ];
}
else
{
$log->formula_validation( "Explicit dimension aspect rule", "A dimension is being added but there are no members",
array(
'dimension' => $dimensionQName,
'error' => 'xbrlfe:missingSAVForExplicitDimensionRule'
)
);
}
return $context;
} | [
"public",
"function",
"getValue",
"(",
"$",
"variableSet",
",",
"$",
"evaluationResult",
",",
"$",
"log",
")",
"{",
"// This is an error\r",
"if",
"(",
"!",
"isset",
"(",
"$",
"variableSet",
"->",
"context",
")",
")",
"return",
"array",
"(",
")",
";",
"/... | Get the explicity dimension context information for this rule
@param Formula $variableSet
@param array $evaluationResult
@param \XBRL_Log $log
@return DOMXPathNavigator | [
"Get",
"the",
"explicity",
"dimension",
"context",
"information",
"for",
"this",
"rule"
] | 6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94 | https://github.com/bseddon/XBRL/blob/6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94/Formulas/Resources/Formulas/Aspects/ExplicitDimension.php#L130-L198 | train |
bseddon/XBRL | Formulas/Resources/Assertions/ConsistencyAssertion.php | ConsistencyAssertion.roundValue | private function roundValue( $value, $precision )
{
if ( $precision == INF ) return $value;
return round( $value, \XBRL_Instance::inferDecimals( $value, $precision ) );
} | php | private function roundValue( $value, $precision )
{
if ( $precision == INF ) return $value;
return round( $value, \XBRL_Instance::inferDecimals( $value, $precision ) );
} | [
"private",
"function",
"roundValue",
"(",
"$",
"value",
",",
"$",
"precision",
")",
"{",
"if",
"(",
"$",
"precision",
"==",
"INF",
")",
"return",
"$",
"value",
";",
"return",
"round",
"(",
"$",
"value",
",",
"\\",
"XBRL_Instance",
"::",
"inferDecimals",
... | Rounds a fact value takng into account the fact precision
@param float $value
@param int $precision
@return unknown|number | [
"Rounds",
"a",
"fact",
"value",
"takng",
"into",
"account",
"the",
"fact",
"precision"
] | 6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94 | https://github.com/bseddon/XBRL/blob/6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94/Formulas/Resources/Assertions/ConsistencyAssertion.php#L542-L546 | train |
bseddon/XBRL | Formulas/Resources/Assertions/ConsistencyAssertion.php | ConsistencyAssertion.evaluateAcceptanceRadius | private function evaluateAcceptanceRadius( $variableSet, $derivedValue, $fact, $factVars = array() )
{
if ( is_null( $this->radiusValue ) )
{
if ( ! is_null( $this->absoluteAcceptanceRadius ) || ! is_null( $this->proportionalAcceptanceRadius ) )
{
$expression = ! is_null( $this->absoluteAcceptanceRadius )
? $this->absoluteAcceptanceRadius
: $this->proportionalAcceptanceRadius;
$expression = "$expression cast as xs:float";
$vars = array_map( function( $param ) { return $param->result; }, $this->parameters );
$vars = array_merge( $factVars, $vars );
// $result = $this->evaluateXPath( $variableSet, $expression, $vars );
$provider = new NodeProvider( $fact );
$xpathExpression = XPath2Expression::Compile( $expression, $variableSet->nsMgr );
$xpathExpression->AddToContext( "xbrlInstance", $variableSet->xbrlInstance );
$xpathExpression->AddToContext( "xbrlTaxonomy", $variableSet->xbrlTaxonomy );
$xpathExpression->AddToContext( "base", $variableSet->base );
$result = $xpathExpression->EvaluateWithVars( $provider, $vars );
$this->radiusValue = $result instanceof XPath2Item ? $result->getTypedValue() : $result;
}
else
{
$this->radiusValue = false;
}
}
if ( ! is_null( $this->absoluteAcceptanceRadius ) )
{
return $this->radiusValue;
}
if ( ! is_null( $this->proportionalAcceptanceRadius ) )
{
return $this->radiusValue * $derivedValue;
}
return null;
} | php | private function evaluateAcceptanceRadius( $variableSet, $derivedValue, $fact, $factVars = array() )
{
if ( is_null( $this->radiusValue ) )
{
if ( ! is_null( $this->absoluteAcceptanceRadius ) || ! is_null( $this->proportionalAcceptanceRadius ) )
{
$expression = ! is_null( $this->absoluteAcceptanceRadius )
? $this->absoluteAcceptanceRadius
: $this->proportionalAcceptanceRadius;
$expression = "$expression cast as xs:float";
$vars = array_map( function( $param ) { return $param->result; }, $this->parameters );
$vars = array_merge( $factVars, $vars );
// $result = $this->evaluateXPath( $variableSet, $expression, $vars );
$provider = new NodeProvider( $fact );
$xpathExpression = XPath2Expression::Compile( $expression, $variableSet->nsMgr );
$xpathExpression->AddToContext( "xbrlInstance", $variableSet->xbrlInstance );
$xpathExpression->AddToContext( "xbrlTaxonomy", $variableSet->xbrlTaxonomy );
$xpathExpression->AddToContext( "base", $variableSet->base );
$result = $xpathExpression->EvaluateWithVars( $provider, $vars );
$this->radiusValue = $result instanceof XPath2Item ? $result->getTypedValue() : $result;
}
else
{
$this->radiusValue = false;
}
}
if ( ! is_null( $this->absoluteAcceptanceRadius ) )
{
return $this->radiusValue;
}
if ( ! is_null( $this->proportionalAcceptanceRadius ) )
{
return $this->radiusValue * $derivedValue;
}
return null;
} | [
"private",
"function",
"evaluateAcceptanceRadius",
"(",
"$",
"variableSet",
",",
"$",
"derivedValue",
",",
"$",
"fact",
",",
"$",
"factVars",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"radiusValue",
")",
")",
"{",
... | Check the value is wthin the acceptance radius
@param Formula $variableSet
@param mixed $derivedValue
@param XPathNavigator $fact
@param array $factVars
@return number|NULL | [
"Check",
"the",
"value",
"is",
"wthin",
"the",
"acceptance",
"radius"
] | 6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94 | https://github.com/bseddon/XBRL/blob/6ffdcedd68b0a7957b2358bcec15b22bd4c5dc94/Formulas/Resources/Assertions/ConsistencyAssertion.php#L556-L599 | train |
botman/driver-facebook | src/FacebookDriver.php | FacebookDriver.getUserWithFields | public function getUserWithFields(array $fields, IncomingMessage $matchingMessage)
{
$messagingDetails = $this->event->get('messaging')[0];
// implode field array to create concatinated comma string
$fields = implode(',', $fields);
// WORKPLACE (Facebook for companies)
// if community isset in sender Object, it is a request done by workplace
if (isset($messagingDetails['sender']['community'])) {
$fields = 'first_name,last_name,email,title,department,employee_number,primary_phone,primary_address,picture,link,locale,name,name_format,updated_time';
}
$userInfoData = $this->http->get($this->facebookProfileEndpoint.$matchingMessage->getSender().'?fields='.$fields.'&access_token='.$this->config->get('token'));
$this->throwExceptionIfResponseNotOk($userInfoData);
$userInfo = json_decode($userInfoData->getContent(), true);
$firstName = $userInfo['first_name'] ?? null;
$lastName = $userInfo['last_name'] ?? null;
return new User($matchingMessage->getSender(), $firstName, $lastName, null, $userInfo);
} | php | public function getUserWithFields(array $fields, IncomingMessage $matchingMessage)
{
$messagingDetails = $this->event->get('messaging')[0];
// implode field array to create concatinated comma string
$fields = implode(',', $fields);
// WORKPLACE (Facebook for companies)
// if community isset in sender Object, it is a request done by workplace
if (isset($messagingDetails['sender']['community'])) {
$fields = 'first_name,last_name,email,title,department,employee_number,primary_phone,primary_address,picture,link,locale,name,name_format,updated_time';
}
$userInfoData = $this->http->get($this->facebookProfileEndpoint.$matchingMessage->getSender().'?fields='.$fields.'&access_token='.$this->config->get('token'));
$this->throwExceptionIfResponseNotOk($userInfoData);
$userInfo = json_decode($userInfoData->getContent(), true);
$firstName = $userInfo['first_name'] ?? null;
$lastName = $userInfo['last_name'] ?? null;
return new User($matchingMessage->getSender(), $firstName, $lastName, null, $userInfo);
} | [
"public",
"function",
"getUserWithFields",
"(",
"array",
"$",
"fields",
",",
"IncomingMessage",
"$",
"matchingMessage",
")",
"{",
"$",
"messagingDetails",
"=",
"$",
"this",
"->",
"event",
"->",
"get",
"(",
"'messaging'",
")",
"[",
"0",
"]",
";",
"// implode ... | Retrieve specific User field information.
@param array $fields
@param IncomingMessage $matchingMessage
@return User
@throws FacebookException | [
"Retrieve",
"specific",
"User",
"field",
"information",
"."
] | a02096c5b9dafddc3353e8c5eff060fcb004985f | https://github.com/botman/driver-facebook/blob/a02096c5b9dafddc3353e8c5eff060fcb004985f/src/FacebookDriver.php#L432-L449 | train |
botman/driver-facebook | src/FacebookDriver.php | FacebookDriver.handover | public function handover(IncomingMessage $message, $bot)
{
return $this->http->post($this->facebookProfileEndpoint.'me/pass_thread_control?access_token='.$this->config->get('token'), [], [
'recipient' => [
'id' => $message->getSender(),
],
'target_app_id' => self::HANDOVER_INBOX_PAGE_ID,
]);
} | php | public function handover(IncomingMessage $message, $bot)
{
return $this->http->post($this->facebookProfileEndpoint.'me/pass_thread_control?access_token='.$this->config->get('token'), [], [
'recipient' => [
'id' => $message->getSender(),
],
'target_app_id' => self::HANDOVER_INBOX_PAGE_ID,
]);
} | [
"public",
"function",
"handover",
"(",
"IncomingMessage",
"$",
"message",
",",
"$",
"bot",
")",
"{",
"return",
"$",
"this",
"->",
"http",
"->",
"post",
"(",
"$",
"this",
"->",
"facebookProfileEndpoint",
".",
"'me/pass_thread_control?access_token='",
".",
"$",
... | Pass a conversation to the page inbox.
@param IncomingMessage $message
@param $bot
@return Response | [
"Pass",
"a",
"conversation",
"to",
"the",
"page",
"inbox",
"."
] | a02096c5b9dafddc3353e8c5eff060fcb004985f | https://github.com/botman/driver-facebook/blob/a02096c5b9dafddc3353e8c5eff060fcb004985f/src/FacebookDriver.php#L551-L559 | train |
botman/driver-facebook | src/FacebookFileDriver.php | FacebookFileDriver.getFiles | public function getFiles(array $message)
{
return Collection::make($message['message']['attachments'])->where('type',
'file')->pluck('payload')->map(function ($item) {
return new File($item['url'], $item);
})->toArray();
} | php | public function getFiles(array $message)
{
return Collection::make($message['message']['attachments'])->where('type',
'file')->pluck('payload')->map(function ($item) {
return new File($item['url'], $item);
})->toArray();
} | [
"public",
"function",
"getFiles",
"(",
"array",
"$",
"message",
")",
"{",
"return",
"Collection",
"::",
"make",
"(",
"$",
"message",
"[",
"'message'",
"]",
"[",
"'attachments'",
"]",
")",
"->",
"where",
"(",
"'type'",
",",
"'file'",
")",
"->",
"pluck",
... | Retrieve file urls from an incoming message.
@param array $message
@return array A download for the file. | [
"Retrieve",
"file",
"urls",
"from",
"an",
"incoming",
"message",
"."
] | a02096c5b9dafddc3353e8c5eff060fcb004985f | https://github.com/botman/driver-facebook/blob/a02096c5b9dafddc3353e8c5eff060fcb004985f/src/FacebookFileDriver.php#L75-L81 | train |
botman/driver-facebook | src/FacebookLocationDriver.php | FacebookLocationDriver.getLocation | public function getLocation(array $messages)
{
$data = Collection::make($messages['message']['attachments'])->where('type',
'location')->pluck('payload')->first();
return new Location($data['coordinates']['lat'], $data['coordinates']['long'], $data);
} | php | public function getLocation(array $messages)
{
$data = Collection::make($messages['message']['attachments'])->where('type',
'location')->pluck('payload')->first();
return new Location($data['coordinates']['lat'], $data['coordinates']['long'], $data);
} | [
"public",
"function",
"getLocation",
"(",
"array",
"$",
"messages",
")",
"{",
"$",
"data",
"=",
"Collection",
"::",
"make",
"(",
"$",
"messages",
"[",
"'message'",
"]",
"[",
"'attachments'",
"]",
")",
"->",
"where",
"(",
"'type'",
",",
"'location'",
")",... | Retrieve location from an incoming message.
@param array $messages
@return \BotMan\BotMan\Messages\Attachments\Location | [
"Retrieve",
"location",
"from",
"an",
"incoming",
"message",
"."
] | a02096c5b9dafddc3353e8c5eff060fcb004985f | https://github.com/botman/driver-facebook/blob/a02096c5b9dafddc3353e8c5eff060fcb004985f/src/FacebookLocationDriver.php#L75-L81 | train |
botman/driver-facebook | src/FacebookVideoDriver.php | FacebookVideoDriver.getVideoUrls | public function getVideoUrls(array $message)
{
return Collection::make($message['message']['attachments'])->where('type',
'video')->pluck('payload')->map(function ($item) {
return new Video($item['url'], $item);
})->toArray();
} | php | public function getVideoUrls(array $message)
{
return Collection::make($message['message']['attachments'])->where('type',
'video')->pluck('payload')->map(function ($item) {
return new Video($item['url'], $item);
})->toArray();
} | [
"public",
"function",
"getVideoUrls",
"(",
"array",
"$",
"message",
")",
"{",
"return",
"Collection",
"::",
"make",
"(",
"$",
"message",
"[",
"'message'",
"]",
"[",
"'attachments'",
"]",
")",
"->",
"where",
"(",
"'type'",
",",
"'video'",
")",
"->",
"pluc... | Retrieve video urls from an incoming message.
@param array $message
@return array A download for the image file. | [
"Retrieve",
"video",
"urls",
"from",
"an",
"incoming",
"message",
"."
] | a02096c5b9dafddc3353e8c5eff060fcb004985f | https://github.com/botman/driver-facebook/blob/a02096c5b9dafddc3353e8c5eff060fcb004985f/src/FacebookVideoDriver.php#L75-L81 | train |
botman/driver-facebook | src/FacebookAudioDriver.php | FacebookAudioDriver.getAudioUrls | public function getAudioUrls(array $message)
{
return Collection::make($message['message']['attachments'])->where('type',
'audio')->pluck('payload')->map(function ($item) {
return new Audio($item['url'], $item);
})->toArray();
} | php | public function getAudioUrls(array $message)
{
return Collection::make($message['message']['attachments'])->where('type',
'audio')->pluck('payload')->map(function ($item) {
return new Audio($item['url'], $item);
})->toArray();
} | [
"public",
"function",
"getAudioUrls",
"(",
"array",
"$",
"message",
")",
"{",
"return",
"Collection",
"::",
"make",
"(",
"$",
"message",
"[",
"'message'",
"]",
"[",
"'attachments'",
"]",
")",
"->",
"where",
"(",
"'type'",
",",
"'audio'",
")",
"->",
"pluc... | Retrieve audio file urls from an incoming message.
@param array $message
@return array A download for the audio file. | [
"Retrieve",
"audio",
"file",
"urls",
"from",
"an",
"incoming",
"message",
"."
] | a02096c5b9dafddc3353e8c5eff060fcb004985f | https://github.com/botman/driver-facebook/blob/a02096c5b9dafddc3353e8c5eff060fcb004985f/src/FacebookAudioDriver.php#L75-L81 | train |
inhere/php-validate | src/Validators.php | Validators.number | public static function number($val, $min = null, $max = null, $flags = 0): bool
{
if (!\is_numeric($val)) {
return false;
}
if ($val <= 0) {
return false;
}
return self::integer($val, $min, $max, $flags);
} | php | public static function number($val, $min = null, $max = null, $flags = 0): bool
{
if (!\is_numeric($val)) {
return false;
}
if ($val <= 0) {
return false;
}
return self::integer($val, $min, $max, $flags);
} | [
"public",
"static",
"function",
"number",
"(",
"$",
"val",
",",
"$",
"min",
"=",
"null",
",",
"$",
"max",
"=",
"null",
",",
"$",
"flags",
"=",
"0",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"\\",
"is_numeric",
"(",
"$",
"val",
")",
")",
"{",
"re... | check var is a integer and greater than 0
@param mixed $val
@param null|integer $min 最小值
@param null|int $max 最大值
@param int $flags
@return bool | [
"check",
"var",
"is",
"a",
"integer",
"and",
"greater",
"than",
"0"
] | e900fac6ce181220aba5982e59b6917108e60b84 | https://github.com/inhere/php-validate/blob/e900fac6ce181220aba5982e59b6917108e60b84/src/Validators.php#L234-L245 | train |
inhere/php-validate | src/Validators.php | Validators.string | public static function string($val, $minLen = 0, $maxLen = null): bool
{
if (!\is_string($val)) {
return false;
}
// only type check.
if ($minLen === 0 && $maxLen === null) {
return true;
}
return self::integer(Helper::strlen($val), $minLen, $maxLen);
} | php | public static function string($val, $minLen = 0, $maxLen = null): bool
{
if (!\is_string($val)) {
return false;
}
// only type check.
if ($minLen === 0 && $maxLen === null) {
return true;
}
return self::integer(Helper::strlen($val), $minLen, $maxLen);
} | [
"public",
"static",
"function",
"string",
"(",
"$",
"val",
",",
"$",
"minLen",
"=",
"0",
",",
"$",
"maxLen",
"=",
"null",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"\\",
"is_string",
"(",
"$",
"val",
")",
")",
"{",
"return",
"false",
";",
"}",
"//... | check val is a string
@param mixed $val
@param int $minLen
@param null|int $maxLen
@return bool | [
"check",
"val",
"is",
"a",
"string"
] | e900fac6ce181220aba5982e59b6917108e60b84 | https://github.com/inhere/php-validate/blob/e900fac6ce181220aba5982e59b6917108e60b84/src/Validators.php#L263-L275 | train |
inhere/php-validate | src/Validators.php | Validators.eq | public static function eq($val, $expected, $strict = true): bool
{
return $strict ? $val === $expected : $val == $expected;
} | php | public static function eq($val, $expected, $strict = true): bool
{
return $strict ? $val === $expected : $val == $expected;
} | [
"public",
"static",
"function",
"eq",
"(",
"$",
"val",
",",
"$",
"expected",
",",
"$",
"strict",
"=",
"true",
")",
":",
"bool",
"{",
"return",
"$",
"strict",
"?",
"$",
"val",
"===",
"$",
"expected",
":",
"$",
"val",
"==",
"$",
"expected",
";",
"}... | Must be equal to the given value
@param mixed $val
@param mixed $expected
@param bool $strict
@return bool | [
"Must",
"be",
"equal",
"to",
"the",
"given",
"value"
] | e900fac6ce181220aba5982e59b6917108e60b84 | https://github.com/inhere/php-validate/blob/e900fac6ce181220aba5982e59b6917108e60b84/src/Validators.php#L351-L354 | train |
inhere/php-validate | src/Validators.php | Validators.neq | public static function neq($val, $expected, $strict = true): bool
{
return $strict ? $val !== $expected : $val != $expected;
} | php | public static function neq($val, $expected, $strict = true): bool
{
return $strict ? $val !== $expected : $val != $expected;
} | [
"public",
"static",
"function",
"neq",
"(",
"$",
"val",
",",
"$",
"expected",
",",
"$",
"strict",
"=",
"true",
")",
":",
"bool",
"{",
"return",
"$",
"strict",
"?",
"$",
"val",
"!==",
"$",
"expected",
":",
"$",
"val",
"!=",
"$",
"expected",
";",
"... | Cannot be equal to a given value
@param mixed $val
@param mixed $expected
@param bool $strict
@return bool | [
"Cannot",
"be",
"equal",
"to",
"a",
"given",
"value"
] | e900fac6ce181220aba5982e59b6917108e60b84 | https://github.com/inhere/php-validate/blob/e900fac6ce181220aba5982e59b6917108e60b84/src/Validators.php#L363-L366 | train |
inhere/php-validate | src/Validators.php | Validators.isDate | public static function isDate($date): bool
{
if (!\preg_match('/^([\d]{4})-((?:0?[\d])|(?:1[0-2]))-((?:0?[\d])|(?:[1-2][\d])|(?:3[01]))( [\d]{2}:[\d]{2}:[\d]{2})?$/',
$date, $matches)) {
return false;
}
return \checkdate((int)$matches[2], (int)$matches[3], (int)$matches[1]);
} | php | public static function isDate($date): bool
{
if (!\preg_match('/^([\d]{4})-((?:0?[\d])|(?:1[0-2]))-((?:0?[\d])|(?:[1-2][\d])|(?:3[01]))( [\d]{2}:[\d]{2}:[\d]{2})?$/',
$date, $matches)) {
return false;
}
return \checkdate((int)$matches[2], (int)$matches[3], (int)$matches[1]);
} | [
"public",
"static",
"function",
"isDate",
"(",
"$",
"date",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"\\",
"preg_match",
"(",
"'/^([\\d]{4})-((?:0?[\\d])|(?:1[0-2]))-((?:0?[\\d])|(?:[1-2][\\d])|(?:3[01]))( [\\d]{2}:[\\d]{2}:[\\d]{2})?$/'",
",",
"$",
"date",
",",
"$",
"mat... | Check for date validity
@param string $date Date to validate
@return bool Validity is ok or not | [
"Check",
"for",
"date",
"validity"
] | e900fac6ce181220aba5982e59b6917108e60b84 | https://github.com/inhere/php-validate/blob/e900fac6ce181220aba5982e59b6917108e60b84/src/Validators.php#L1173-L1181 | train |
inhere/php-validate | src/Validators.php | Validators.isFloat | public static function isFloat($float): bool
{
if (!\is_scalar($float)) {
return false;
}
return (string)((float)$float) === (string)$float;
} | php | public static function isFloat($float): bool
{
if (!\is_scalar($float)) {
return false;
}
return (string)((float)$float) === (string)$float;
} | [
"public",
"static",
"function",
"isFloat",
"(",
"$",
"float",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"\\",
"is_scalar",
"(",
"$",
"float",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"string",
")",
"(",
"(",
"float",
")",
"$",
"flo... | Check for a float number validity
@param float|mixed $float Float number to validate
@return bool Validity is ok or not | [
"Check",
"for",
"a",
"float",
"number",
"validity"
] | e900fac6ce181220aba5982e59b6917108e60b84 | https://github.com/inhere/php-validate/blob/e900fac6ce181220aba5982e59b6917108e60b84/src/Validators.php#L1234-L1241 | train |
inhere/php-validate | src/ValidationTrait.php | ValidationTrait.applyRule | protected function applyRule($fields, array $rule, array $onlyChecked)
{
$fields = \is_string($fields) ? Filters::explode($fields) : (array)$fields;
$validator = \array_shift($rule);
// How to determine the property is empty(default use the Validators::isEmpty)
$isEmpty = [Validators::class, 'isEmpty'];
if (!empty($rule['isEmpty']) && (\is_string($rule['isEmpty']) || $rule['isEmpty'] instanceof \Closure)) {
$isEmpty = $rule['isEmpty'];
}
// Preconditions for verification -- If do not meet the conditions, skip this rule
$when = $rule['when'] ?? null;
if ($when && ($when instanceof \Closure) && $when($this->data, $this) !== true) {
return;
}
// Whether to skip when empty(When not required). ref yii2
$skipOnEmpty = $rule['skipOnEmpty'] ?? $this->_skipOnEmpty;
$filters = $rule['filter'] ?? null; // filter
$defMsg = $rule['msg'] ?? null; // Custom error message
$defValue = $rule['default'] ?? null;// Allow default
// clear all keywords options. 0 is the validator
unset($rule['msg'], $rule['default'], $rule['skipOnEmpty'], $rule['isEmpty'], $rule['when'], $rule['filter']);
// The rest are validator parameters. Some validators require parameters. e.g. size()
$args = $rule;
foreach ($fields as $field) {
if (!$field || ($onlyChecked && !\in_array($field, $onlyChecked, true))) {
continue;
}
$value = $this->getByPath($field, $defValue);
if (\is_string($validator)) {
if ($validator === 'safe') {
$this->setSafe($field, $value);
continue;
}
// required*系列字段检查 || 文件资源检查
if (self::isCheckRequired($validator) || self::isCheckFile($validator)) {
$result = $this->fieldValidate($field, $value, $validator, $args, $defMsg);
if (false === $result && $this->isStopOnError()) {
break;
}
continue;
}
}
// skip On Empty && The value is empty
if ($skipOnEmpty && Helper::call($isEmpty, $value)) {
continue;
}
// Field value filtering(有通配符`*`的字段, 不应用过滤器)
if ($filters && !\strpos($field, '.*')) {
$value = $this->valueFiltering($value, $filters);
// save
$this->data[$field] = $value;
}
// Field value verification check
if (!$this->valueValidate($field, $value, $validator, $args, $defMsg) && $this->isStopOnError()) {
break;
}
}
} | php | protected function applyRule($fields, array $rule, array $onlyChecked)
{
$fields = \is_string($fields) ? Filters::explode($fields) : (array)$fields;
$validator = \array_shift($rule);
// How to determine the property is empty(default use the Validators::isEmpty)
$isEmpty = [Validators::class, 'isEmpty'];
if (!empty($rule['isEmpty']) && (\is_string($rule['isEmpty']) || $rule['isEmpty'] instanceof \Closure)) {
$isEmpty = $rule['isEmpty'];
}
// Preconditions for verification -- If do not meet the conditions, skip this rule
$when = $rule['when'] ?? null;
if ($when && ($when instanceof \Closure) && $when($this->data, $this) !== true) {
return;
}
// Whether to skip when empty(When not required). ref yii2
$skipOnEmpty = $rule['skipOnEmpty'] ?? $this->_skipOnEmpty;
$filters = $rule['filter'] ?? null; // filter
$defMsg = $rule['msg'] ?? null; // Custom error message
$defValue = $rule['default'] ?? null;// Allow default
// clear all keywords options. 0 is the validator
unset($rule['msg'], $rule['default'], $rule['skipOnEmpty'], $rule['isEmpty'], $rule['when'], $rule['filter']);
// The rest are validator parameters. Some validators require parameters. e.g. size()
$args = $rule;
foreach ($fields as $field) {
if (!$field || ($onlyChecked && !\in_array($field, $onlyChecked, true))) {
continue;
}
$value = $this->getByPath($field, $defValue);
if (\is_string($validator)) {
if ($validator === 'safe') {
$this->setSafe($field, $value);
continue;
}
// required*系列字段检查 || 文件资源检查
if (self::isCheckRequired($validator) || self::isCheckFile($validator)) {
$result = $this->fieldValidate($field, $value, $validator, $args, $defMsg);
if (false === $result && $this->isStopOnError()) {
break;
}
continue;
}
}
// skip On Empty && The value is empty
if ($skipOnEmpty && Helper::call($isEmpty, $value)) {
continue;
}
// Field value filtering(有通配符`*`的字段, 不应用过滤器)
if ($filters && !\strpos($field, '.*')) {
$value = $this->valueFiltering($value, $filters);
// save
$this->data[$field] = $value;
}
// Field value verification check
if (!$this->valueValidate($field, $value, $validator, $args, $defMsg) && $this->isStopOnError()) {
break;
}
}
} | [
"protected",
"function",
"applyRule",
"(",
"$",
"fields",
",",
"array",
"$",
"rule",
",",
"array",
"$",
"onlyChecked",
")",
"{",
"$",
"fields",
"=",
"\\",
"is_string",
"(",
"$",
"fields",
")",
"?",
"Filters",
"::",
"explode",
"(",
"$",
"fields",
")",
... | apply validate rule for given fields
@param string|array $fields
@param array $rule
@param array $onlyChecked | [
"apply",
"validate",
"rule",
"for",
"given",
"fields"
] | e900fac6ce181220aba5982e59b6917108e60b84 | https://github.com/inhere/php-validate/blob/e900fac6ce181220aba5982e59b6917108e60b84/src/ValidationTrait.php#L213-L283 | train |
inhere/php-validate | src/ValidationTrait.php | ValidationTrait.collectSafeValue | protected function collectSafeValue(string $field, $value)
{
// 进行的是子级属性检查 eg: 'goods.apple'
if ($pos = \strpos($field, '.')) {
$field = (string)\substr($field, 0, $pos);
$value = $this->getRaw($field, []);
}
// set
$this->_safeData[$field] = $value;
} | php | protected function collectSafeValue(string $field, $value)
{
// 进行的是子级属性检查 eg: 'goods.apple'
if ($pos = \strpos($field, '.')) {
$field = (string)\substr($field, 0, $pos);
$value = $this->getRaw($field, []);
}
// set
$this->_safeData[$field] = $value;
} | [
"protected",
"function",
"collectSafeValue",
"(",
"string",
"$",
"field",
",",
"$",
"value",
")",
"{",
"// 进行的是子级属性检查 eg: 'goods.apple'",
"if",
"(",
"$",
"pos",
"=",
"\\",
"strpos",
"(",
"$",
"field",
",",
"'.'",
")",
")",
"{",
"$",
"field",
"=",
"(",
... | collect Safe Value
@param string $field
@param mixed $value | [
"collect",
"Safe",
"Value"
] | e900fac6ce181220aba5982e59b6917108e60b84 | https://github.com/inhere/php-validate/blob/e900fac6ce181220aba5982e59b6917108e60b84/src/ValidationTrait.php#L394-L404 | train |
inhere/php-validate | src/ValidationTrait.php | ValidationTrait.setRaw | public function setRaw(string $key, $value): self
{
$this->data[$key] = $value;
return $this;
} | php | public function setRaw(string $key, $value): self
{
$this->data[$key] = $value;
return $this;
} | [
"public",
"function",
"setRaw",
"(",
"string",
"$",
"key",
",",
"$",
"value",
")",
":",
"self",
"{",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Set data item by key
@param string $key The data key
@param mixed $value The data value
@return $this | [
"Set",
"data",
"item",
"by",
"key"
] | e900fac6ce181220aba5982e59b6917108e60b84 | https://github.com/inhere/php-validate/blob/e900fac6ce181220aba5982e59b6917108e60b84/src/ValidationTrait.php#L681-L685 | train |
inhere/php-validate | src/Filter/Filters.php | Filters.trim | public static function trim($val)
{
return \is_array($val) ? \array_map(function ($val) {
return \is_string($val) ? \trim($val) : $val;
}, $val) : \trim((string)$val);
} | php | public static function trim($val)
{
return \is_array($val) ? \array_map(function ($val) {
return \is_string($val) ? \trim($val) : $val;
}, $val) : \trim((string)$val);
} | [
"public",
"static",
"function",
"trim",
"(",
"$",
"val",
")",
"{",
"return",
"\\",
"is_array",
"(",
"$",
"val",
")",
"?",
"\\",
"array_map",
"(",
"function",
"(",
"$",
"val",
")",
"{",
"return",
"\\",
"is_string",
"(",
"$",
"val",
")",
"?",
"\\",
... | simple trim space
@param string|array $val
@return string|array | [
"simple",
"trim",
"space"
] | e900fac6ce181220aba5982e59b6917108e60b84 | https://github.com/inhere/php-validate/blob/e900fac6ce181220aba5982e59b6917108e60b84/src/Filter/Filters.php#L173-L178 | train |
inhere/php-validate | src/Filter/Filters.php | Filters.lowercase | public static function lowercase($val): string
{
if (!$val || !\is_string($val)) {
return \is_int($val) ? $val : '';
}
if (\function_exists('mb_strtolower')) {
return \mb_strtolower($val, 'utf-8');
}
return \strtolower($val);
} | php | public static function lowercase($val): string
{
if (!$val || !\is_string($val)) {
return \is_int($val) ? $val : '';
}
if (\function_exists('mb_strtolower')) {
return \mb_strtolower($val, 'utf-8');
}
return \strtolower($val);
} | [
"public",
"static",
"function",
"lowercase",
"(",
"$",
"val",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"val",
"||",
"!",
"\\",
"is_string",
"(",
"$",
"val",
")",
")",
"{",
"return",
"\\",
"is_int",
"(",
"$",
"val",
")",
"?",
"$",
"val",
":... | string to lowercase
@param string|int $val
@return string | [
"string",
"to",
"lowercase"
] | e900fac6ce181220aba5982e59b6917108e60b84 | https://github.com/inhere/php-validate/blob/e900fac6ce181220aba5982e59b6917108e60b84/src/Filter/Filters.php#L215-L226 | train |
inhere/php-validate | src/Filter/Filters.php | Filters.uppercase | public static function uppercase($str): string
{
if (!$str || !\is_string($str)) {
return \is_int($str) ? $str : '';
}
if (\function_exists('mb_strtoupper')) {
return \mb_strtoupper($str, 'utf-8');
}
return \strtoupper($str);
} | php | public static function uppercase($str): string
{
if (!$str || !\is_string($str)) {
return \is_int($str) ? $str : '';
}
if (\function_exists('mb_strtoupper')) {
return \mb_strtoupper($str, 'utf-8');
}
return \strtoupper($str);
} | [
"public",
"static",
"function",
"uppercase",
"(",
"$",
"str",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"str",
"||",
"!",
"\\",
"is_string",
"(",
"$",
"str",
")",
")",
"{",
"return",
"\\",
"is_int",
"(",
"$",
"str",
")",
"?",
"$",
"str",
":... | string to uppercase
@param string|int $str
@return string | [
"string",
"to",
"uppercase"
] | e900fac6ce181220aba5982e59b6917108e60b84 | https://github.com/inhere/php-validate/blob/e900fac6ce181220aba5982e59b6917108e60b84/src/Filter/Filters.php#L243-L254 | train |
inhere/php-validate | src/Filter/Filters.php | Filters.snakeCase | public static function snakeCase($val, string $sep = '_'): string
{
if (!$val || !\is_string($val)) {
return '';
}
$val = \preg_replace('/([A-Z][a-z])/', $sep . '$1', $val);
return self::lowercase(\trim($val, $sep));
} | php | public static function snakeCase($val, string $sep = '_'): string
{
if (!$val || !\is_string($val)) {
return '';
}
$val = \preg_replace('/([A-Z][a-z])/', $sep . '$1', $val);
return self::lowercase(\trim($val, $sep));
} | [
"public",
"static",
"function",
"snakeCase",
"(",
"$",
"val",
",",
"string",
"$",
"sep",
"=",
"'_'",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"val",
"||",
"!",
"\\",
"is_string",
"(",
"$",
"val",
")",
")",
"{",
"return",
"''",
";",
"}",
"$... | Transform a CamelCase string to underscore_case string
'CMSCategories' => 'cms_categories'
'RangePrice' => 'range_price'
@param string $val
@param string $sep
@return string | [
"Transform",
"a",
"CamelCase",
"string",
"to",
"underscore_case",
"string",
"CMSCategories",
"=",
">",
"cms_categories",
"RangePrice",
"=",
">",
"range_price"
] | e900fac6ce181220aba5982e59b6917108e60b84 | https://github.com/inhere/php-validate/blob/e900fac6ce181220aba5982e59b6917108e60b84/src/Filter/Filters.php#L305-L314 | train |
inhere/php-validate | src/Helper.php | Helper.compareSize | public static function compareSize($val, string $operator, $expected): bool
{
// type must be same
if (\gettype($val) !== \gettype($expected)) {
return false;
}
// not in: int, string, array
if (($len = self::length($val)) < 0) {
return false;
}
$wantLen = self::length($expected);
switch ($operator) {
case '>':
$ok = $len > $wantLen;
break;
case '>=':
$ok = $len >= $wantLen;
break;
case '<':
$ok = $len < $wantLen;
break;
case '<=':
$ok = $len <= $wantLen;
break;
default:
$ok = false;
}
return $ok;
} | php | public static function compareSize($val, string $operator, $expected): bool
{
// type must be same
if (\gettype($val) !== \gettype($expected)) {
return false;
}
// not in: int, string, array
if (($len = self::length($val)) < 0) {
return false;
}
$wantLen = self::length($expected);
switch ($operator) {
case '>':
$ok = $len > $wantLen;
break;
case '>=':
$ok = $len >= $wantLen;
break;
case '<':
$ok = $len < $wantLen;
break;
case '<=':
$ok = $len <= $wantLen;
break;
default:
$ok = false;
}
return $ok;
} | [
"public",
"static",
"function",
"compareSize",
"(",
"$",
"val",
",",
"string",
"$",
"operator",
",",
"$",
"expected",
")",
":",
"bool",
"{",
"// type must be same",
"if",
"(",
"\\",
"gettype",
"(",
"$",
"val",
")",
"!==",
"\\",
"gettype",
"(",
"$",
"ex... | compare of size
- int Compare size
- string Compare length
- array Compare length
@param mixed $val
@param mixed $expected
@param string $operator
@return bool | [
"compare",
"of",
"size",
"-",
"int",
"Compare",
"size",
"-",
"string",
"Compare",
"length",
"-",
"array",
"Compare",
"length"
] | e900fac6ce181220aba5982e59b6917108e60b84 | https://github.com/inhere/php-validate/blob/e900fac6ce181220aba5982e59b6917108e60b84/src/Helper.php#L237-L269 | train |
inhere/php-validate | src/Traits/ErrorMessageTrait.php | ErrorMessageTrait.inError | public function inError(string $field): bool
{
foreach ($this->_errors as $item) {
if ($field === $item['name']) {
return true;
}
}
return false;
} | php | public function inError(string $field): bool
{
foreach ($this->_errors as $item) {
if ($field === $item['name']) {
return true;
}
}
return false;
} | [
"public",
"function",
"inError",
"(",
"string",
"$",
"field",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_errors",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"field",
"===",
"$",
"item",
"[",
"'name'",
"]",
")",
"{",
"return",
"... | check field whether in the errors
@param string $field
@return bool | [
"check",
"field",
"whether",
"in",
"the",
"errors"
] | e900fac6ce181220aba5982e59b6917108e60b84 | https://github.com/inhere/php-validate/blob/e900fac6ce181220aba5982e59b6917108e60b84/src/Traits/ErrorMessageTrait.php#L145-L153 | train |
inhere/php-validate | src/Traits/ErrorMessageTrait.php | ErrorMessageTrait.firstError | public function firstError(bool $onlyMsg = true)
{
if (!$errors = $this->_errors) {
return $onlyMsg ? '' : [];
}
$first = \array_shift($errors);
return $onlyMsg ? $first['msg'] : $first;
} | php | public function firstError(bool $onlyMsg = true)
{
if (!$errors = $this->_errors) {
return $onlyMsg ? '' : [];
}
$first = \array_shift($errors);
return $onlyMsg ? $first['msg'] : $first;
} | [
"public",
"function",
"firstError",
"(",
"bool",
"$",
"onlyMsg",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"errors",
"=",
"$",
"this",
"->",
"_errors",
")",
"{",
"return",
"$",
"onlyMsg",
"?",
"''",
":",
"[",
"]",
";",
"}",
"$",
"first",
"=",
... | Get the first error message
@param bool $onlyMsg
@return array|string | [
"Get",
"the",
"first",
"error",
"message"
] | e900fac6ce181220aba5982e59b6917108e60b84 | https://github.com/inhere/php-validate/blob/e900fac6ce181220aba5982e59b6917108e60b84/src/Traits/ErrorMessageTrait.php#L200-L208 | train |
inhere/php-validate | src/Traits/ErrorMessageTrait.php | ErrorMessageTrait.lastError | public function lastError(bool $onlyMsg = true)
{
if (!$errors = $this->_errors) {
return $onlyMsg ? '' : [];
}
$last = \array_pop($errors);
return $onlyMsg ? $last['msg'] : $last;
} | php | public function lastError(bool $onlyMsg = true)
{
if (!$errors = $this->_errors) {
return $onlyMsg ? '' : [];
}
$last = \array_pop($errors);
return $onlyMsg ? $last['msg'] : $last;
} | [
"public",
"function",
"lastError",
"(",
"bool",
"$",
"onlyMsg",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"errors",
"=",
"$",
"this",
"->",
"_errors",
")",
"{",
"return",
"$",
"onlyMsg",
"?",
"''",
":",
"[",
"]",
";",
"}",
"$",
"last",
"=",
"... | Get the last error message
@param bool $onlyMsg
@return array|string | [
"Get",
"the",
"last",
"error",
"message"
] | e900fac6ce181220aba5982e59b6917108e60b84 | https://github.com/inhere/php-validate/blob/e900fac6ce181220aba5982e59b6917108e60b84/src/Traits/ErrorMessageTrait.php#L215-L223 | train |
inhere/php-validate | src/Traits/ErrorMessageTrait.php | ErrorMessageTrait.addTranslates | public function addTranslates(array $fieldTrans): self
{
foreach ($fieldTrans as $field => $tran) {
$this->_translates[$field] = $tran;
}
return $this;
} | php | public function addTranslates(array $fieldTrans): self
{
foreach ($fieldTrans as $field => $tran) {
$this->_translates[$field] = $tran;
}
return $this;
} | [
"public",
"function",
"addTranslates",
"(",
"array",
"$",
"fieldTrans",
")",
":",
"self",
"{",
"foreach",
"(",
"$",
"fieldTrans",
"as",
"$",
"field",
"=>",
"$",
"tran",
")",
"{",
"$",
"this",
"->",
"_translates",
"[",
"$",
"field",
"]",
"=",
"$",
"tr... | add the attrs translation data
@param array $fieldTrans
@return $this | [
"add",
"the",
"attrs",
"translation",
"data"
] | e900fac6ce181220aba5982e59b6917108e60b84 | https://github.com/inhere/php-validate/blob/e900fac6ce181220aba5982e59b6917108e60b84/src/Traits/ErrorMessageTrait.php#L370-L376 | train |
inhere/php-validate | src/Traits/ErrorMessageTrait.php | ErrorMessageTrait.getTranslate | public function getTranslate(string $field): string
{
$trans = $this->getTranslates();
if (isset($trans[$field])) {
return $trans[$field];
}
if ($this->_prettifyName) {
return Helper::prettifyFieldName($field);
}
return $field;
} | php | public function getTranslate(string $field): string
{
$trans = $this->getTranslates();
if (isset($trans[$field])) {
return $trans[$field];
}
if ($this->_prettifyName) {
return Helper::prettifyFieldName($field);
}
return $field;
} | [
"public",
"function",
"getTranslate",
"(",
"string",
"$",
"field",
")",
":",
"string",
"{",
"$",
"trans",
"=",
"$",
"this",
"->",
"getTranslates",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"trans",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return"... | get field translate string.
@param string $field
@return string | [
"get",
"field",
"translate",
"string",
"."
] | e900fac6ce181220aba5982e59b6917108e60b84 | https://github.com/inhere/php-validate/blob/e900fac6ce181220aba5982e59b6917108e60b84/src/Traits/ErrorMessageTrait.php#L391-L404 | train |
mauricesvay/php-facedetection | FaceDetector.php | FaceDetector.cropFaceToJpeg | public function cropFaceToJpeg($outFileName = null)
{
if (empty($this->face)) {
throw new NoFaceException('No face detected');
}
$canvas = imagecreatetruecolor($this->face['w'], $this->face['w']);
imagecopy($canvas, $this->canvas, 0, 0, $this->face['x'], $this->face['y'], $this->face['w'], $this->face['w']);
if ($outFileName === null) {
header('Content-type: image/jpeg');
}
imagejpeg($canvas, $outFileName);
} | php | public function cropFaceToJpeg($outFileName = null)
{
if (empty($this->face)) {
throw new NoFaceException('No face detected');
}
$canvas = imagecreatetruecolor($this->face['w'], $this->face['w']);
imagecopy($canvas, $this->canvas, 0, 0, $this->face['x'], $this->face['y'], $this->face['w'], $this->face['w']);
if ($outFileName === null) {
header('Content-type: image/jpeg');
}
imagejpeg($canvas, $outFileName);
} | [
"public",
"function",
"cropFaceToJpeg",
"(",
"$",
"outFileName",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"face",
")",
")",
"{",
"throw",
"new",
"NoFaceException",
"(",
"'No face detected'",
")",
";",
"}",
"$",
"canvas",
"=",
... | Crops the face from the photo.
Should be called after `faceDetect` function call
If file is provided, the face will be stored in file, other way it will be output to standard output.
@param string|null $outFileName file name to store. If null, will be printed to output
@throws NoFaceException | [
"Crops",
"the",
"face",
"from",
"the",
"photo",
".",
"Should",
"be",
"called",
"after",
"faceDetect",
"function",
"call",
"If",
"file",
"is",
"provided",
"the",
"face",
"will",
"be",
"stored",
"in",
"file",
"other",
"way",
"it",
"will",
"be",
"output",
"... | b016273ceceacd85562bbc50384fbabc947fe525 | https://github.com/mauricesvay/php-facedetection/blob/b016273ceceacd85562bbc50384fbabc947fe525/FaceDetector.php#L165-L179 | train |
nahid/jsonq | src/Condition.php | Condition.match | public static function match($value, $comparable)
{
if (is_array($comparable) || is_array($value) || is_object($comparable) || is_object($value)) {
return false;
}
$comparable = trim($comparable);
if (preg_match("/^$comparable$/", $value)) {
return true;
}
return false;
} | php | public static function match($value, $comparable)
{
if (is_array($comparable) || is_array($value) || is_object($comparable) || is_object($value)) {
return false;
}
$comparable = trim($comparable);
if (preg_match("/^$comparable$/", $value)) {
return true;
}
return false;
} | [
"public",
"static",
"function",
"match",
"(",
"$",
"value",
",",
"$",
"comparable",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"comparable",
")",
"||",
"is_array",
"(",
"$",
"value",
")",
"||",
"is_object",
"(",
"$",
"comparable",
")",
"||",
"is_object... | Match with pattern
@param mixed $value
@param string $comparable
@return bool | [
"Match",
"with",
"pattern"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Condition.php#L211-L224 | train |
nahid/jsonq | src/JsonQueriable.php | JsonQueriable.import | public function import($file = null)
{
if (!is_null($file)) {
if (is_string($file) && file_exists($file)) {
$this->_map = $this->getDataFromFile($file);
$this->_baseContents = $this->_map;
return true;
}
}
throw new FileNotFoundException();
} | php | public function import($file = null)
{
if (!is_null($file)) {
if (is_string($file) && file_exists($file)) {
$this->_map = $this->getDataFromFile($file);
$this->_baseContents = $this->_map;
return true;
}
}
throw new FileNotFoundException();
} | [
"public",
"function",
"import",
"(",
"$",
"file",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"file",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"file",
")",
"&&",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"$",
"this... | import data from file
@param string|null $file
@return bool
@throws FileNotFoundException
@throws InvalidJsonException | [
"import",
"data",
"from",
"file"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/JsonQueriable.php#L99-L110 | train |
nahid/jsonq | src/JsonQueriable.php | JsonQueriable.prepare | protected function prepare()
{
if ($this->_isProcessed) {
return $this;
}
if (count($this->_conditions) > 0) {
$calculatedData = $this->processConditions();
$this->_map = $this->objectToArray($calculatedData);
$this->_conditions = [];
$this->_node = '';
$this->_isProcessed = true;
return $this;
}
$this->_isProcessed = true;
$this->_map = $this->objectToArray($this->getData());
return $this;
} | php | protected function prepare()
{
if ($this->_isProcessed) {
return $this;
}
if (count($this->_conditions) > 0) {
$calculatedData = $this->processConditions();
$this->_map = $this->objectToArray($calculatedData);
$this->_conditions = [];
$this->_node = '';
$this->_isProcessed = true;
return $this;
}
$this->_isProcessed = true;
$this->_map = $this->objectToArray($this->getData());
return $this;
} | [
"protected",
"function",
"prepare",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_isProcessed",
")",
"{",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"_conditions",
")",
">",
"0",
")",
"{",
"$",
"calculatedData",
"... | Prepare data from desire conditions
@return $this
@throws ConditionNotAllowedException | [
"Prepare",
"data",
"from",
"desire",
"conditions"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/JsonQueriable.php#L118-L137 | train |
nahid/jsonq | src/JsonQueriable.php | JsonQueriable.objectToArray | protected function objectToArray($obj)
{
if (!is_array($obj) && !is_object($obj)) {
return $obj;
}
if (is_array($obj)) {
return $obj;
}
if (is_object($obj)) {
$obj = get_object_vars($obj);
}
return array_map([$this, 'objectToArray'], $obj);
} | php | protected function objectToArray($obj)
{
if (!is_array($obj) && !is_object($obj)) {
return $obj;
}
if (is_array($obj)) {
return $obj;
}
if (is_object($obj)) {
$obj = get_object_vars($obj);
}
return array_map([$this, 'objectToArray'], $obj);
} | [
"protected",
"function",
"objectToArray",
"(",
"$",
"obj",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"obj",
")",
"&&",
"!",
"is_object",
"(",
"$",
"obj",
")",
")",
"{",
"return",
"$",
"obj",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"obj",... | Parse object to array
@param object $obj
@return array|mixed | [
"Parse",
"object",
"to",
"array"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/JsonQueriable.php#L157-L172 | train |
nahid/jsonq | src/JsonQueriable.php | JsonQueriable.isMultiArray | protected function isMultiArray($arr)
{
if (!is_array($arr)) {
return false;
}
rsort($arr);
return isset($arr[0]) && is_array($arr[0]);
} | php | protected function isMultiArray($arr)
{
if (!is_array($arr)) {
return false;
}
rsort($arr);
return isset($arr[0]) && is_array($arr[0]);
} | [
"protected",
"function",
"isMultiArray",
"(",
"$",
"arr",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"arr",
")",
")",
"{",
"return",
"false",
";",
"}",
"rsort",
"(",
"$",
"arr",
")",
";",
"return",
"isset",
"(",
"$",
"arr",
"[",
"0",
"]",
... | Check given value is multidimensional array
@param array $arr
@return bool | [
"Check",
"given",
"value",
"is",
"multidimensional",
"array"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/JsonQueriable.php#L180-L189 | train |
nahid/jsonq | src/JsonQueriable.php | JsonQueriable.isJson | public function isJson($value, $isReturnMap = false)
{
if (is_array($value) || is_object($value)) {
return false;
}
$data = json_decode($value, true);
if (json_last_error() !== JSON_ERROR_NONE) {
return false;
}
return $isReturnMap ? $data : true;
} | php | public function isJson($value, $isReturnMap = false)
{
if (is_array($value) || is_object($value)) {
return false;
}
$data = json_decode($value, true);
if (json_last_error() !== JSON_ERROR_NONE) {
return false;
}
return $isReturnMap ? $data : true;
} | [
"public",
"function",
"isJson",
"(",
"$",
"value",
",",
"$",
"isReturnMap",
"=",
"false",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"||",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"data",
"=",
... | Check given value is valid JSON
@param string $value
@param bool $isReturnMap
@return bool|array | [
"Check",
"given",
"value",
"is",
"valid",
"JSON"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/JsonQueriable.php#L199-L212 | train |
nahid/jsonq | src/JsonQueriable.php | JsonQueriable.prepareResult | protected function prepareResult($data, $isObject)
{
$output = [];
if (is_null($data) || is_scalar($data)) {
return $data;
}
if ($this->isMultiArray($data)) {
foreach ($data as $key => $val) {
$val = $this->takeColumn($val);
$output[$key] = $isObject ? (object) $val : $val;
}
} else {
$output = json_decode(json_encode($this->takeColumn($data)), $isObject);
}
return $output;
} | php | protected function prepareResult($data, $isObject)
{
$output = [];
if (is_null($data) || is_scalar($data)) {
return $data;
}
if ($this->isMultiArray($data)) {
foreach ($data as $key => $val) {
$val = $this->takeColumn($val);
$output[$key] = $isObject ? (object) $val : $val;
}
} else {
$output = json_decode(json_encode($this->takeColumn($data)), $isObject);
}
return $output;
} | [
"protected",
"function",
"prepareResult",
"(",
"$",
"data",
",",
"$",
"isObject",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"if",
"(",
"is_null",
"(",
"$",
"data",
")",
"||",
"is_scalar",
"(",
"$",
"data",
")",
")",
"{",
"return",
"$",
"data",
... | Prepare data for result
@param mixed $data
@param bool $isObject
@return array|mixed | [
"Prepare",
"data",
"for",
"result"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/JsonQueriable.php#L262-L280 | train |
nahid/jsonq | src/JsonQueriable.php | JsonQueriable.getDataFromFile | protected function getDataFromFile($file, $type = 'application/json')
{
if (file_exists($file)) {
$opts = [
'http' => [
'header' => 'Content-Type: '.$type.'; charset=utf-8',
],
];
$context = stream_context_create($opts);
$data = file_get_contents($file, 0, $context);
$json = $this->isJson($data, true);
if (!$json) {
throw new InvalidJsonException();
}
return $json;
}
throw new FileNotFoundException();
} | php | protected function getDataFromFile($file, $type = 'application/json')
{
if (file_exists($file)) {
$opts = [
'http' => [
'header' => 'Content-Type: '.$type.'; charset=utf-8',
],
];
$context = stream_context_create($opts);
$data = file_get_contents($file, 0, $context);
$json = $this->isJson($data, true);
if (!$json) {
throw new InvalidJsonException();
}
return $json;
}
throw new FileNotFoundException();
} | [
"protected",
"function",
"getDataFromFile",
"(",
"$",
"file",
",",
"$",
"type",
"=",
"'application/json'",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"$",
"opts",
"=",
"[",
"'http'",
"=>",
"[",
"'header'",
"=>",
"'Content-Type: ... | Read JSON data from file
@param string $file
@param string $type
@return bool|string|array
@throws FileNotFoundException
@throws InvalidJsonException | [
"Read",
"JSON",
"data",
"from",
"file"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/JsonQueriable.php#L291-L312 | train |
nahid/jsonq | src/JsonQueriable.php | JsonQueriable.getFromNested | protected function getFromNested($map, $node)
{
if (empty($node) || $node == '.') {
return $map;
}
if ($node) {
$terminate = false;
$path = explode('.', $node);
foreach ($path as $val) {
if (!array_key_exists($val, $map)) {
$terminate = true;
break;
}
$map = &$map[$val];
}
if ($terminate) {
return new ValueNotFound();
}
return $map;
}
return new ValueNotFound();
} | php | protected function getFromNested($map, $node)
{
if (empty($node) || $node == '.') {
return $map;
}
if ($node) {
$terminate = false;
$path = explode('.', $node);
foreach ($path as $val) {
if (!array_key_exists($val, $map)) {
$terminate = true;
break;
}
$map = &$map[$val];
}
if ($terminate) {
return new ValueNotFound();
}
return $map;
}
return new ValueNotFound();
} | [
"protected",
"function",
"getFromNested",
"(",
"$",
"map",
",",
"$",
"node",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"node",
")",
"||",
"$",
"node",
"==",
"'.'",
")",
"{",
"return",
"$",
"map",
";",
"}",
"if",
"(",
"$",
"node",
")",
"{",
"$",
... | Get data from nested array
@param $map array
@param $node string
@return bool|array|mixed | [
"Get",
"data",
"from",
"nested",
"array"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/JsonQueriable.php#L323-L350 | train |
nahid/jsonq | src/JsonQueriable.php | JsonQueriable.processConditions | protected function processConditions()
{
$data = $this->getData();
$conditions = $this->_conditions;
$result = array_filter($data, function ($val) use ($conditions) {
$res = false;
foreach ($conditions as $cond) {
$tmp = true;
foreach ($cond as $rule) {
$function = self::$_rulesMap[$rule['condition']];
if (!is_callable($function)) {
if (!method_exists(Condition::class, $function)) {
throw new ConditionNotAllowedException("Exception: $function condition not allowed");
}
$function = [Condition::class, $function];
}
$value = $this->getFromNested($val, $rule['key']);
$return = $value instanceof ValueNotFound ? false : call_user_func_array($function, [$value, $rule['value']]);
$tmp &= $return;
}
$res |= $tmp;
}
return $res;
});
return $result;
} | php | protected function processConditions()
{
$data = $this->getData();
$conditions = $this->_conditions;
$result = array_filter($data, function ($val) use ($conditions) {
$res = false;
foreach ($conditions as $cond) {
$tmp = true;
foreach ($cond as $rule) {
$function = self::$_rulesMap[$rule['condition']];
if (!is_callable($function)) {
if (!method_exists(Condition::class, $function)) {
throw new ConditionNotAllowedException("Exception: $function condition not allowed");
}
$function = [Condition::class, $function];
}
$value = $this->getFromNested($val, $rule['key']);
$return = $value instanceof ValueNotFound ? false : call_user_func_array($function, [$value, $rule['value']]);
$tmp &= $return;
}
$res |= $tmp;
}
return $res;
});
return $result;
} | [
"protected",
"function",
"processConditions",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getData",
"(",
")",
";",
"$",
"conditions",
"=",
"$",
"this",
"->",
"_conditions",
";",
"$",
"result",
"=",
"array_filter",
"(",
"$",
"data",
",",
"funct... | process AND and OR conditions
@return array|string|object
@throws ConditionNotAllowedException | [
"process",
"AND",
"and",
"OR",
"conditions"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/JsonQueriable.php#L368-L396 | train |
nahid/jsonq | src/JsonQueriable.php | JsonQueriable.where | public function where($key, $condition = null, $value = null)
{
if (!is_null($condition) && is_null($value)) {
$value = $condition;
$condition = '=';
}
if (count($this->_conditions) < 1) {
array_push($this->_conditions, []);
}
return $this->makeWhere($key, $condition, $value);
} | php | public function where($key, $condition = null, $value = null)
{
if (!is_null($condition) && is_null($value)) {
$value = $condition;
$condition = '=';
}
if (count($this->_conditions) < 1) {
array_push($this->_conditions, []);
}
return $this->makeWhere($key, $condition, $value);
} | [
"public",
"function",
"where",
"(",
"$",
"key",
",",
"$",
"condition",
"=",
"null",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"condition",
")",
"&&",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
... | make WHERE clause
@param string $key
@param string $condition
@param mixed $value
@return $this | [
"make",
"WHERE",
"clause"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/JsonQueriable.php#L406-L417 | train |
nahid/jsonq | src/JsonQueriable.php | JsonQueriable.orWhere | public function orWhere($key = null, $condition = null, $value = null)
{
if (!is_null($condition) && is_null($value)) {
$value = $condition;
$condition = '=';
}
array_push($this->_conditions, []);
return $this->makeWhere($key, $condition, $value);
} | php | public function orWhere($key = null, $condition = null, $value = null)
{
if (!is_null($condition) && is_null($value)) {
$value = $condition;
$condition = '=';
}
array_push($this->_conditions, []);
return $this->makeWhere($key, $condition, $value);
} | [
"public",
"function",
"orWhere",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"condition",
"=",
"null",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"condition",
")",
"&&",
"is_null",
"(",
"$",
"value",
")",
")",
"{",... | make WHERE clause with OR
@param string $key
@param string $condition
@param mixed $value
@return $this | [
"make",
"WHERE",
"clause",
"with",
"OR"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/JsonQueriable.php#L427-L437 | train |
nahid/jsonq | src/JsonQueriable.php | JsonQueriable.makeWhere | protected function makeWhere($key, $condition = null, $value = null)
{
$current = end($this->_conditions);
$index = key($this->_conditions);
if (is_callable($key)) {
$key($this);
return $this;
}
array_push($current, [
'key' => $key,
'condition' => $condition,
'value' => $value,
]);
$this->_conditions[$index] = $current;
return $this;
} | php | protected function makeWhere($key, $condition = null, $value = null)
{
$current = end($this->_conditions);
$index = key($this->_conditions);
if (is_callable($key)) {
$key($this);
return $this;
}
array_push($current, [
'key' => $key,
'condition' => $condition,
'value' => $value,
]);
$this->_conditions[$index] = $current;
return $this;
} | [
"protected",
"function",
"makeWhere",
"(",
"$",
"key",
",",
"$",
"condition",
"=",
"null",
",",
"$",
"value",
"=",
"null",
")",
"{",
"$",
"current",
"=",
"end",
"(",
"$",
"this",
"->",
"_conditions",
")",
";",
"$",
"index",
"=",
"key",
"(",
"$",
... | generator for AND and OR where
@param string $key
@param string $condition
@param mixed $value
@return $this | [
"generator",
"for",
"AND",
"and",
"OR",
"where"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/JsonQueriable.php#L447-L465 | train |
nahid/jsonq | src/JsonQueriable.php | JsonQueriable.whereBool | public function whereBool($key = null, $value)
{
if (is_bool($value)) {
$this->where($key, '==', $value);
}
return $this;
} | php | public function whereBool($key = null, $value)
{
if (is_bool($value)) {
$this->where($key, '==', $value);
}
return $this;
} | [
"public",
"function",
"whereBool",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"value",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"where",
"(",
"$",
"key",
",",
"'=='",
",",
"$",
"value",
")",
";",
"}",
... | make WHERE Boolean clause
@param string $key
@return $this | [
"make",
"WHERE",
"Boolean",
"clause"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/JsonQueriable.php#L513-L519 | train |
nahid/jsonq | src/JsonQueriable.php | JsonQueriable.macro | public static function macro($name, callable $fn)
{
if (!in_array($name, self::$_rulesMap)) {
self::$_rulesMap[$name] = $fn;
return true;
}
return false;
} | php | public static function macro($name, callable $fn)
{
if (!in_array($name, self::$_rulesMap)) {
self::$_rulesMap[$name] = $fn;
return true;
}
return false;
} | [
"public",
"static",
"function",
"macro",
"(",
"$",
"name",
",",
"callable",
"$",
"fn",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"name",
",",
"self",
"::",
"$",
"_rulesMap",
")",
")",
"{",
"self",
"::",
"$",
"_rulesMap",
"[",
"$",
"name",
"... | make macro for custom where clause
@param string $name
@param callable $fn
@return bool | [
"make",
"macro",
"for",
"custom",
"where",
"clause"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/JsonQueriable.php#L639-L647 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.from | public function from($node = null)
{
$this->_isProcessed = false;
if (is_null($node) || $node == '') {
throw new NullValueException("Null node exception");
}
$this->_node = $node;
return $this;
} | php | public function from($node = null)
{
$this->_isProcessed = false;
if (is_null($node) || $node == '') {
throw new NullValueException("Null node exception");
}
$this->_node = $node;
return $this;
} | [
"public",
"function",
"from",
"(",
"$",
"node",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"_isProcessed",
"=",
"false",
";",
"if",
"(",
"is_null",
"(",
"$",
"node",
")",
"||",
"$",
"node",
"==",
"''",
")",
"{",
"throw",
"new",
"NullValueException",
... | Set node path, where JsonQ start to prepare
@param null $node
@return $this
@throws NullValueException | [
"Set",
"node",
"path",
"where",
"JsonQ",
"start",
"to",
"prepare"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L54-L65 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.get | public function get($object = false)
{
$this->prepare();
return $this->prepareResult($this->_map, $object);
} | php | public function get($object = false)
{
$this->prepare();
return $this->prepareResult($this->_map, $object);
} | [
"public",
"function",
"get",
"(",
"$",
"object",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"prepare",
"(",
")",
";",
"return",
"$",
"this",
"->",
"prepareResult",
"(",
"$",
"this",
"->",
"_map",
",",
"$",
"object",
")",
";",
"}"
] | getting prepared data
@param bool $object
@return array|object
@throws ConditionNotAllowedException | [
"getting",
"prepared",
"data"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L118-L123 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.groupBy | public function groupBy($column)
{
$this->prepare();
$data = [];
foreach ($this->_map as $map) {
$value = $this->getFromNested($map, $column);
if ($value) {
$data[$value][] = $map;
}
}
$this->_map = $data;
return $this;
} | php | public function groupBy($column)
{
$this->prepare();
$data = [];
foreach ($this->_map as $map) {
$value = $this->getFromNested($map, $column);
if ($value) {
$data[$value][] = $map;
}
}
$this->_map = $data;
return $this;
} | [
"public",
"function",
"groupBy",
"(",
"$",
"column",
")",
"{",
"$",
"this",
"->",
"prepare",
"(",
")",
";",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_map",
"as",
"$",
"map",
")",
"{",
"$",
"value",
"=",
"$",
"this",
... | getting group data from specific column
@param string $column
@return $this
@throws ConditionNotAllowedException | [
"getting",
"group",
"data",
"from",
"specific",
"column"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L183-L197 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.sum | public function sum($column = null)
{
$this->prepare();
$sum = 0;
if (is_null($column)) {
$sum = array_sum($this->_map);
} else {
foreach ($this->_map as $key => $val) {
$value = $this->getFromNested($val, $column);
if (is_scalar($value)) {
$sum += $value;
}
}
}
return $sum;
} | php | public function sum($column = null)
{
$this->prepare();
$sum = 0;
if (is_null($column)) {
$sum = array_sum($this->_map);
} else {
foreach ($this->_map as $key => $val) {
$value = $this->getFromNested($val, $column);
if (is_scalar($value)) {
$sum += $value;
}
}
}
return $sum;
} | [
"public",
"function",
"sum",
"(",
"$",
"column",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"prepare",
"(",
")",
";",
"$",
"sum",
"=",
"0",
";",
"if",
"(",
"is_null",
"(",
"$",
"column",
")",
")",
"{",
"$",
"sum",
"=",
"array_sum",
"(",
"$",
"... | sum prepared data
@param int $column
@return int
@throws ConditionNotAllowedException | [
"sum",
"prepared",
"data"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L252-L270 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.max | public function max($column = null)
{
$this->prepare();
if (is_null($column)) {
$max = max($this->_map);
} else {
$max = max(array_column($this->_map, $column));
}
return $max;
} | php | public function max($column = null)
{
$this->prepare();
if (is_null($column)) {
$max = max($this->_map);
} else {
$max = max(array_column($this->_map, $column));
}
return $max;
} | [
"public",
"function",
"max",
"(",
"$",
"column",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"prepare",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"column",
")",
")",
"{",
"$",
"max",
"=",
"max",
"(",
"$",
"this",
"->",
"_map",
")",
";",
"}... | getting max value from prepared data
@param int $column
@return int
@throws ConditionNotAllowedException | [
"getting",
"max",
"value",
"from",
"prepared",
"data"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L279-L290 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.min | public function min($column = null)
{
$this->prepare();
if (is_null($column)) {
$min = min($this->_map);
} else {
$min = min(array_column($this->_map, $column));
}
return $min;
} | php | public function min($column = null)
{
$this->prepare();
if (is_null($column)) {
$min = min($this->_map);
} else {
$min = min(array_column($this->_map, $column));
}
return $min;
} | [
"public",
"function",
"min",
"(",
"$",
"column",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"prepare",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"column",
")",
")",
"{",
"$",
"min",
"=",
"min",
"(",
"$",
"this",
"->",
"_map",
")",
";",
"}... | getting min value from prepared data
@param int $column
@return string
@throws ConditionNotAllowedException | [
"getting",
"min",
"value",
"from",
"prepared",
"data"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L299-L310 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.avg | public function avg($column = null)
{
$this->prepare();
$count = $this->count();
$total = $this->sum($column);
return ($total/$count);
} | php | public function avg($column = null)
{
$this->prepare();
$count = $this->count();
$total = $this->sum($column);
return ($total/$count);
} | [
"public",
"function",
"avg",
"(",
"$",
"column",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"prepare",
"(",
")",
";",
"$",
"count",
"=",
"$",
"this",
"->",
"count",
"(",
")",
";",
"$",
"total",
"=",
"$",
"this",
"->",
"sum",
"(",
"$",
"column",
... | getting average value from prepared data
@param int $column
@return string
@throws ConditionNotAllowedException | [
"getting",
"average",
"value",
"from",
"prepared",
"data"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L319-L327 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.first | public function first($object = false)
{
$this->prepare();
$data = $this->_map;
if (count($data) > 0) {
return $this->prepareResult(reset($data), $object);
}
return null;
} | php | public function first($object = false)
{
$this->prepare();
$data = $this->_map;
if (count($data) > 0) {
return $this->prepareResult(reset($data), $object);
}
return null;
} | [
"public",
"function",
"first",
"(",
"$",
"object",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"prepare",
"(",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"_map",
";",
"if",
"(",
"count",
"(",
"$",
"data",
")",
">",
"0",
")",
"{",
"return",
... | getting first element of prepared data
@param bool $object
@return object|array|null
@throws ConditionNotAllowedException | [
"getting",
"first",
"element",
"of",
"prepared",
"data"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L336-L346 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.last | public function last($object = false)
{
$this->prepare();
$data = $this->_map;
if (count($data) > 0) {
return $this->prepareResult(end($data), $object);
}
return null;
} | php | public function last($object = false)
{
$this->prepare();
$data = $this->_map;
if (count($data) > 0) {
return $this->prepareResult(end($data), $object);
}
return null;
} | [
"public",
"function",
"last",
"(",
"$",
"object",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"prepare",
"(",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"_map",
";",
"if",
"(",
"count",
"(",
"$",
"data",
")",
">",
"0",
")",
"{",
"return",
... | getting last element of prepared data
@param bool $object
@return object|array|null
@throws ConditionNotAllowedException | [
"getting",
"last",
"element",
"of",
"prepared",
"data"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L355-L365 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.nth | public function nth($index, $object = false)
{
$this->prepare();
$data = $this->_map;
$total_elm = count($data);
$idx = abs($index);
if (!is_integer($index) || $total_elm < $idx || $index == 0 || !is_array($this->_map)) {
return null;
}
if ($index > 0) {
$result = $data[$index - 1];
} else {
$result = $data[$this->count() + $index];
}
return $this->prepareResult($result, $object);
} | php | public function nth($index, $object = false)
{
$this->prepare();
$data = $this->_map;
$total_elm = count($data);
$idx = abs($index);
if (!is_integer($index) || $total_elm < $idx || $index == 0 || !is_array($this->_map)) {
return null;
}
if ($index > 0) {
$result = $data[$index - 1];
} else {
$result = $data[$this->count() + $index];
}
return $this->prepareResult($result, $object);
} | [
"public",
"function",
"nth",
"(",
"$",
"index",
",",
"$",
"object",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"prepare",
"(",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"_map",
";",
"$",
"total_elm",
"=",
"count",
"(",
"$",
"data",
")",
";... | getting nth number of element of prepared data
@param int $index
@param bool $object
@return object|array|null
@throws ConditionNotAllowedException | [
"getting",
"nth",
"number",
"of",
"element",
"of",
"prepared",
"data"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L375-L394 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.sortBy | public function sortBy($column, $order = 'asc')
{
$this->prepare();
if (!is_array($this->_map)) {
return $this;
}
usort($this->_map, function ($a, $b) use ($column, $order) {
$val1 = $this->getFromNested($a, $column);
$val2 = $this->getFromNested($b, $column);
if (is_string($val1)) {
$val1 = strtolower($val1);
}
if (is_string($val2)) {
$val2 = strtolower($val2);
}
if ($val1 == $val2) {
return 0;
}
$order = strtolower(trim($order));
if ($order == 'desc') {
return ($val1 > $val2) ? -1 : 1;
} else {
return ($val1 < $val2) ? -1 : 1;
}
});
return $this;
} | php | public function sortBy($column, $order = 'asc')
{
$this->prepare();
if (!is_array($this->_map)) {
return $this;
}
usort($this->_map, function ($a, $b) use ($column, $order) {
$val1 = $this->getFromNested($a, $column);
$val2 = $this->getFromNested($b, $column);
if (is_string($val1)) {
$val1 = strtolower($val1);
}
if (is_string($val2)) {
$val2 = strtolower($val2);
}
if ($val1 == $val2) {
return 0;
}
$order = strtolower(trim($order));
if ($order == 'desc') {
return ($val1 > $val2) ? -1 : 1;
} else {
return ($val1 < $val2) ? -1 : 1;
}
});
return $this;
} | [
"public",
"function",
"sortBy",
"(",
"$",
"column",
",",
"$",
"order",
"=",
"'asc'",
")",
"{",
"$",
"this",
"->",
"prepare",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"_map",
")",
")",
"{",
"return",
"$",
"this",
";",
"... | sorting from prepared data
@param string $column
@param string $order
@return object|array|null
@throws ConditionNotAllowedException | [
"sorting",
"from",
"prepared",
"data"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L404-L436 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.sortByCallable | public function sortByCallable(callable $sortFunc)
{
$this->prepare();
if (!is_array($this->_map)) {
return $this;
}
usort($this->_map, $sortFunc);
return $this;
} | php | public function sortByCallable(callable $sortFunc)
{
$this->prepare();
if (!is_array($this->_map)) {
return $this;
}
usort($this->_map, $sortFunc);
return $this;
} | [
"public",
"function",
"sortByCallable",
"(",
"callable",
"$",
"sortFunc",
")",
"{",
"$",
"this",
"->",
"prepare",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"_map",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"usort",
"(... | Sort prepared data using a custom sort function.
@param callable $sortFunc
@return object|array|null
@throws ConditionNotAllowedException | [
"Sort",
"prepared",
"data",
"using",
"a",
"custom",
"sort",
"function",
"."
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L446-L457 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.sort | public function sort($order = 'asc')
{
if ($order == 'desc') {
rsort($this->_map);
}else{
sort($this->_map);
}
return $this;
} | php | public function sort($order = 'asc')
{
if ($order == 'desc') {
rsort($this->_map);
}else{
sort($this->_map);
}
return $this;
} | [
"public",
"function",
"sort",
"(",
"$",
"order",
"=",
"'asc'",
")",
"{",
"if",
"(",
"$",
"order",
"==",
"'desc'",
")",
"{",
"rsort",
"(",
"$",
"this",
"->",
"_map",
")",
";",
"}",
"else",
"{",
"sort",
"(",
"$",
"this",
"->",
"_map",
")",
";",
... | Sort an array value
@param string $order
@return Jsonq | [
"Sort",
"an",
"array",
"value"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L465-L474 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.find | public function find($path, $object = false)
{
return $this->from($path)->prepare()->get($object);
} | php | public function find($path, $object = false)
{
return $this->from($path)->prepare()->get($object);
} | [
"public",
"function",
"find",
"(",
"$",
"path",
",",
"$",
"object",
"=",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"from",
"(",
"$",
"path",
")",
"->",
"prepare",
"(",
")",
"->",
"get",
"(",
"$",
"object",
")",
";",
"}"
] | getting data from desire path
@param string $path
@param bool $object
@return mixed
@throws NullValueException
@throws ConditionNotAllowedException | [
"getting",
"data",
"from",
"desire",
"path"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L485-L488 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.each | public function each(callable $fn)
{
$this->prepare();
foreach ($this->_map as $key => $val) {
$fn($key, $val);
}
} | php | public function each(callable $fn)
{
$this->prepare();
foreach ($this->_map as $key => $val) {
$fn($key, $val);
}
} | [
"public",
"function",
"each",
"(",
"callable",
"$",
"fn",
")",
"{",
"$",
"this",
"->",
"prepare",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_map",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"fn",
"(",
"$",
"key",
",",
"$",
"v... | take action of each element of prepared data
@param callable $fn
@throws ConditionNotAllowedException | [
"take",
"action",
"of",
"each",
"element",
"of",
"prepared",
"data"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L496-L503 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.transform | public function transform(callable $fn)
{
$this->prepare();
$new_data = [];
foreach ($this->_map as $key => $val) {
$new_data[$key] = $fn($val);
}
return $this->prepareResult($new_data, false);
} | php | public function transform(callable $fn)
{
$this->prepare();
$new_data = [];
foreach ($this->_map as $key => $val) {
$new_data[$key] = $fn($val);
}
return $this->prepareResult($new_data, false);
} | [
"public",
"function",
"transform",
"(",
"callable",
"$",
"fn",
")",
"{",
"$",
"this",
"->",
"prepare",
"(",
")",
";",
"$",
"new_data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_map",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
... | transform prepared data by using callable function
@param callable $fn
@return object|array
@throws ConditionNotAllowedException | [
"transform",
"prepared",
"data",
"by",
"using",
"callable",
"function"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L512-L522 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.pipe | public function pipe(callable $fn, $class = null)
{
$this->prepare();
if (is_string($fn) && !is_null($class)) {
$instance = new $class;
$this->_map = call_user_func_array([$instance, $fn], [$this]);
return $this;
}
$this->_map = $fn($this);
return $this;
} | php | public function pipe(callable $fn, $class = null)
{
$this->prepare();
if (is_string($fn) && !is_null($class)) {
$instance = new $class;
$this->_map = call_user_func_array([$instance, $fn], [$this]);
return $this;
}
$this->_map = $fn($this);
return $this;
} | [
"public",
"function",
"pipe",
"(",
"callable",
"$",
"fn",
",",
"$",
"class",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"prepare",
"(",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"fn",
")",
"&&",
"!",
"is_null",
"(",
"$",
"class",
")",
")",
"{"... | pipe send output in next pipe
@param callable $fn
@param string|null $class
@return object|array
@throws ConditionNotAllowedException | [
"pipe",
"send",
"output",
"in",
"next",
"pipe"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L532-L545 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.filter | public function filter(callable $fn, $key = false)
{
$this->prepare();
$data = [];
foreach ($this->_map as $k => $val) {
if ($fn($val)) {
if ($key) {
$data[$k] = $val;
} else {
$data[] = $val;
}
}
}
return $this->prepareResult($data, false);
} | php | public function filter(callable $fn, $key = false)
{
$this->prepare();
$data = [];
foreach ($this->_map as $k => $val) {
if ($fn($val)) {
if ($key) {
$data[$k] = $val;
} else {
$data[] = $val;
}
}
}
return $this->prepareResult($data, false);
} | [
"public",
"function",
"filter",
"(",
"callable",
"$",
"fn",
",",
"$",
"key",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"prepare",
"(",
")",
";",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_map",
"as",
"$",
"k",
"=>",
... | filtered each element of prepared data
@param callable $fn
@param bool $key
@return mixed|array
@throws ConditionNotAllowedException | [
"filtered",
"each",
"element",
"of",
"prepared",
"data"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L555-L571 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.then | public function then($node)
{
$this->_map = $this->prepare()->first(false);
$this->from($node);
return $this;
} | php | public function then($node)
{
$this->_map = $this->prepare()->first(false);
$this->from($node);
return $this;
} | [
"public",
"function",
"then",
"(",
"$",
"node",
")",
"{",
"$",
"this",
"->",
"_map",
"=",
"$",
"this",
"->",
"prepare",
"(",
")",
"->",
"first",
"(",
"false",
")",
";",
"$",
"this",
"->",
"from",
"(",
"$",
"node",
")",
";",
"return",
"$",
"this... | then method set position of working data
@param string $node
@return jsonq
@throws NullValueException
@throws ConditionNotAllowedException | [
"then",
"method",
"set",
"position",
"of",
"working",
"data"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L581-L588 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.json | public function json($data)
{
$json = $this->isJson($data, true);
if ($json) {
return $this->collect($json);
}
return $this;
} | php | public function json($data)
{
$json = $this->isJson($data, true);
if ($json) {
return $this->collect($json);
}
return $this;
} | [
"public",
"function",
"json",
"(",
"$",
"data",
")",
"{",
"$",
"json",
"=",
"$",
"this",
"->",
"isJson",
"(",
"$",
"data",
",",
"true",
")",
";",
"if",
"(",
"$",
"json",
")",
"{",
"return",
"$",
"this",
"->",
"collect",
"(",
"$",
"json",
")",
... | import raw JSON data for process
@param string $data
@return jsonq | [
"import",
"raw",
"JSON",
"data",
"for",
"process"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L596-L605 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.collect | public function collect($data)
{
$this->_map = $this->objectToArray($data);
$this->_baseContents = &$this->_map;
return $this;
} | php | public function collect($data)
{
$this->_map = $this->objectToArray($data);
$this->_baseContents = &$this->_map;
return $this;
} | [
"public",
"function",
"collect",
"(",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"_map",
"=",
"$",
"this",
"->",
"objectToArray",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"_baseContents",
"=",
"&",
"$",
"this",
"->",
"_map",
";",
"return",
"$"... | import parsed data from raw json
@param array|object $data
@return jsonq | [
"import",
"parsed",
"data",
"from",
"raw",
"json"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L613-L619 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.implode | public function implode($key, $delimiter = ',')
{
$this->prepare();
$implode = [];
if (is_string($key)) {
return $this->makeImplode($key, $delimiter);
}
if (is_array($key)) {
foreach ($key as $k) {
$imp = $this->makeImplode($k, $delimiter);
$implode[$k] = $imp;
}
return $implode;
}
return '';
} | php | public function implode($key, $delimiter = ',')
{
$this->prepare();
$implode = [];
if (is_string($key)) {
return $this->makeImplode($key, $delimiter);
}
if (is_array($key)) {
foreach ($key as $k) {
$imp = $this->makeImplode($k, $delimiter);
$implode[$k] = $imp;
}
return $implode;
}
return '';
} | [
"public",
"function",
"implode",
"(",
"$",
"key",
",",
"$",
"delimiter",
"=",
"','",
")",
"{",
"$",
"this",
"->",
"prepare",
"(",
")",
";",
"$",
"implode",
"=",
"[",
"]",
";",
"if",
"(",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$... | implode resulting data from desire key and delimeter
@param string|array $key
@param string $delimiter
@return string|array
@throws ConditionNotAllowedException | [
"implode",
"resulting",
"data",
"from",
"desire",
"key",
"and",
"delimeter"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L629-L647 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.makeImplode | protected function makeImplode($key, $delimiter)
{
$data = array_column($this->_map, $key);
if (is_array($data)) {
return implode($delimiter, $data);
}
return null;
} | php | protected function makeImplode($key, $delimiter)
{
$data = array_column($this->_map, $key);
if (is_array($data)) {
return implode($delimiter, $data);
}
return null;
} | [
"protected",
"function",
"makeImplode",
"(",
"$",
"key",
",",
"$",
"delimiter",
")",
"{",
"$",
"data",
"=",
"array_column",
"(",
"$",
"this",
"->",
"_map",
",",
"$",
"key",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"return",... | process implode from resulting data
@param string $key
@param string $delimiter
@return string|null | [
"process",
"implode",
"from",
"resulting",
"data"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L656-L665 | train |
nahid/jsonq | src/Jsonq.php | Jsonq.chunk | public function chunk($amount, callable $fn = null)
{
$this->prepare();
$chunk_value = array_chunk($this->_map, $amount);
$chunks = [];
if (!is_null($fn) && is_callable($fn)) {
foreach ($chunk_value as $chunk) {
$return = $fn($chunk);
if (!is_null($return)) {
$chunks[] = $return;
}
}
return count($chunks) > 0 ? $chunks : null;
}
return $chunk_value;
} | php | public function chunk($amount, callable $fn = null)
{
$this->prepare();
$chunk_value = array_chunk($this->_map, $amount);
$chunks = [];
if (!is_null($fn) && is_callable($fn)) {
foreach ($chunk_value as $chunk) {
$return = $fn($chunk);
if (!is_null($return)) {
$chunks[] = $return;
}
}
return count($chunks) > 0 ? $chunks : null;
}
return $chunk_value;
} | [
"public",
"function",
"chunk",
"(",
"$",
"amount",
",",
"callable",
"$",
"fn",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"prepare",
"(",
")",
";",
"$",
"chunk_value",
"=",
"array_chunk",
"(",
"$",
"this",
"->",
"_map",
",",
"$",
"amount",
")",
";",... | getting chunk values from prepared data
@param int $amount
@param $fn
@return object|array|bool
@throws ConditionNotAllowedException | [
"getting",
"chunk",
"values",
"from",
"prepared",
"data"
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/Jsonq.php#L728-L746 | train |
nahid/jsonq | src/JsonqServiceProvider.php | JsonqServiceProvider.registerJsonManager | protected function registerJsonManager()
{
$config = $this->app['config'];
$this->app->singleton('jsonq.manager', function () use ($config) {
return new JsonQueriable($config->get('jsonq.json.storage_path'));
});
$this->app->alias('jsonq.manager', JsonQueriable::class);
} | php | protected function registerJsonManager()
{
$config = $this->app['config'];
$this->app->singleton('jsonq.manager', function () use ($config) {
return new JsonQueriable($config->get('jsonq.json.storage_path'));
});
$this->app->alias('jsonq.manager', JsonQueriable::class);
} | [
"protected",
"function",
"registerJsonManager",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'jsonq.manager'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"co... | register JsonManager. | [
"register",
"JsonManager",
"."
] | 34e85d068c1cfacf00de32c3ac081b34559e9e53 | https://github.com/nahid/jsonq/blob/34e85d068c1cfacf00de32c3ac081b34559e9e53/src/JsonqServiceProvider.php#L46-L54 | train |
adldap/adLDAP | src/Adldap.php | Adldap.getBaseDn | public function getBaseDn()
{
/*
* If the base DN is empty, we'll assume the dev
* wants it set automatically
*/
if (empty($this->baseDn)) {
$this->setBaseDn($this->findBaseDn());
}
return $this->baseDn;
} | php | public function getBaseDn()
{
/*
* If the base DN is empty, we'll assume the dev
* wants it set automatically
*/
if (empty($this->baseDn)) {
$this->setBaseDn($this->findBaseDn());
}
return $this->baseDn;
} | [
"public",
"function",
"getBaseDn",
"(",
")",
"{",
"/*\n * If the base DN is empty, we'll assume the dev\n * wants it set automatically\n */",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"baseDn",
")",
")",
"{",
"$",
"this",
"->",
"setBaseDn",
"(",
... | Get the current base DN.
@return string | [
"Get",
"the",
"current",
"base",
"DN",
"."
] | 63fd63e4f680e521bdf6cba23e0e524a2c34c0d5 | https://github.com/adldap/adLDAP/blob/63fd63e4f680e521bdf6cba23e0e524a2c34c0d5/src/Adldap.php#L268-L279 | train |
adldap/adLDAP | src/Adldap.php | Adldap.getPersonFilter | public function getPersonFilter($key = null)
{
if ($key == 'category') {
return $this->personFilter['category'];
}
if ($key == 'person') {
return $this->personFilter['person'];
}
return implode('=', $this->personFilter);
} | php | public function getPersonFilter($key = null)
{
if ($key == 'category') {
return $this->personFilter['category'];
}
if ($key == 'person') {
return $this->personFilter['person'];
}
return implode('=', $this->personFilter);
} | [
"public",
"function",
"getPersonFilter",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"key",
"==",
"'category'",
")",
"{",
"return",
"$",
"this",
"->",
"personFilter",
"[",
"'category'",
"]",
";",
"}",
"if",
"(",
"$",
"key",
"==",
"'person... | Get the person search filter.
An optional parameter may be used to specify the desired part.
Without a parameter, returns an imploded string of the form "category=person".
@param string $key
@return string | [
"Get",
"the",
"person",
"search",
"filter",
".",
"An",
"optional",
"parameter",
"may",
"be",
"used",
"to",
"specify",
"the",
"desired",
"part",
".",
"Without",
"a",
"parameter",
"returns",
"an",
"imploded",
"string",
"of",
"the",
"form",
"category",
"=",
"... | 63fd63e4f680e521bdf6cba23e0e524a2c34c0d5 | https://github.com/adldap/adLDAP/blob/63fd63e4f680e521bdf6cba23e0e524a2c34c0d5/src/Adldap.php#L352-L363 | train |
adldap/adLDAP | src/Adldap.php | Adldap.setPort | public function setPort($adPort)
{
if (!is_numeric($adPort)) {
if ($adPort === null) {
$adPort = 'null';
}
throw new AdldapException("The Port: $adPort is not numeric and cannot be used.");
}
$this->adPort = (string) $adPort;
} | php | public function setPort($adPort)
{
if (!is_numeric($adPort)) {
if ($adPort === null) {
$adPort = 'null';
}
throw new AdldapException("The Port: $adPort is not numeric and cannot be used.");
}
$this->adPort = (string) $adPort;
} | [
"public",
"function",
"setPort",
"(",
"$",
"adPort",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"adPort",
")",
")",
"{",
"if",
"(",
"$",
"adPort",
"===",
"null",
")",
"{",
"$",
"adPort",
"=",
"'null'",
";",
"}",
"throw",
"new",
"AdldapExcept... | Sets the port number your domain controller communicates over.
@param int|string $adPort
@throws AdldapException | [
"Sets",
"the",
"port",
"number",
"your",
"domain",
"controller",
"communicates",
"over",
"."
] | 63fd63e4f680e521bdf6cba23e0e524a2c34c0d5 | https://github.com/adldap/adLDAP/blob/63fd63e4f680e521bdf6cba23e0e524a2c34c0d5/src/Adldap.php#L399-L410 | train |
adldap/adLDAP | src/Adldap.php | Adldap.setUseSSL | public function setUseSSL($useSSL)
{
// Make sure we set the correct SSL port if using SSL
if ($useSSL) {
$this->ldapConnection->useSSL();
$this->setPort(ConnectionInterface::PORT_SSL);
} else {
$this->setPort(ConnectionInterface::PORT);
}
} | php | public function setUseSSL($useSSL)
{
// Make sure we set the correct SSL port if using SSL
if ($useSSL) {
$this->ldapConnection->useSSL();
$this->setPort(ConnectionInterface::PORT_SSL);
} else {
$this->setPort(ConnectionInterface::PORT);
}
} | [
"public",
"function",
"setUseSSL",
"(",
"$",
"useSSL",
")",
"{",
"// Make sure we set the correct SSL port if using SSL",
"if",
"(",
"$",
"useSSL",
")",
"{",
"$",
"this",
"->",
"ldapConnection",
"->",
"useSSL",
"(",
")",
";",
"$",
"this",
"->",
"setPort",
"(",... | Set whether to use SSL on the
current ldap connection.
@param bool $useSSL | [
"Set",
"whether",
"to",
"use",
"SSL",
"on",
"the",
"current",
"ldap",
"connection",
"."
] | 63fd63e4f680e521bdf6cba23e0e524a2c34c0d5 | https://github.com/adldap/adLDAP/blob/63fd63e4f680e521bdf6cba23e0e524a2c34c0d5/src/Adldap.php#L491-L501 | train |
adldap/adLDAP | src/Adldap.php | Adldap.connect | public function connect()
{
// Select a random domain controller
$domainController = $this->domainControllers[array_rand($this->domainControllers)];
// Get the LDAP port
$port = $this->getPort();
// Create the LDAP connection
$this->ldapConnection->connect($domainController, $port);
// Set the LDAP options
$this->ldapConnection->setOption(LDAP_OPT_PROTOCOL_VERSION, 3);
$this->ldapConnection->setOption(LDAP_OPT_REFERRALS, $this->followReferrals);
// Authenticate to the server
return $this->authenticate($this->getAdminUsername(), $this->getAdminPassword(), true);
} | php | public function connect()
{
// Select a random domain controller
$domainController = $this->domainControllers[array_rand($this->domainControllers)];
// Get the LDAP port
$port = $this->getPort();
// Create the LDAP connection
$this->ldapConnection->connect($domainController, $port);
// Set the LDAP options
$this->ldapConnection->setOption(LDAP_OPT_PROTOCOL_VERSION, 3);
$this->ldapConnection->setOption(LDAP_OPT_REFERRALS, $this->followReferrals);
// Authenticate to the server
return $this->authenticate($this->getAdminUsername(), $this->getAdminPassword(), true);
} | [
"public",
"function",
"connect",
"(",
")",
"{",
"// Select a random domain controller",
"$",
"domainController",
"=",
"$",
"this",
"->",
"domainControllers",
"[",
"array_rand",
"(",
"$",
"this",
"->",
"domainControllers",
")",
"]",
";",
"// Get the LDAP port",
"$",
... | Connects and Binds to the Domain Controller.
@return bool
@throws AdldapException | [
"Connects",
"and",
"Binds",
"to",
"the",
"Domain",
"Controller",
"."
] | 63fd63e4f680e521bdf6cba23e0e524a2c34c0d5 | https://github.com/adldap/adLDAP/blob/63fd63e4f680e521bdf6cba23e0e524a2c34c0d5/src/Adldap.php#L686-L703 | train |
adldap/adLDAP | src/Adldap.php | Adldap.authenticate | public function authenticate($username, $password, $preventRebind = false)
{
$auth = false;
try {
if ($this->getUseSSO()) {
// If SSO is enabled, we'll try binding over kerberos
$remoteUser = $this->getRemoteUserInput();
$kerberos = $this->getKerberosAuthInput();
/*
* If the remote user input equals the username we're
* trying to authenticate, we'll perform the bind
*/
if ($remoteUser == $username) {
$auth = $this->bindUsingKerberos($kerberos);
}
} else {
// Looks like SSO isn't enabled, we'll bind regularly instead
$auth = $this->bindUsingCredentials($username, $password);
}
} catch (AdldapException $e) {
if ($preventRebind === true) {
/*
* Binding failed and we're not allowed
* to rebind, we'll return false
*/
return $auth;
}
}
// If we're allowed to rebind, we'll rebind as administrator
if ($preventRebind === false) {
$adminUsername = $this->getAdminUsername();
$adminPassword = $this->getAdminPassword();
$this->bindUsingCredentials($adminUsername, $adminPassword);
if (!$this->ldapConnection->isBound()) {
throw new AdldapException('Rebind to Active Directory failed. AD said: '.$this->ldapConnection->getLastError());
}
}
return $auth;
} | php | public function authenticate($username, $password, $preventRebind = false)
{
$auth = false;
try {
if ($this->getUseSSO()) {
// If SSO is enabled, we'll try binding over kerberos
$remoteUser = $this->getRemoteUserInput();
$kerberos = $this->getKerberosAuthInput();
/*
* If the remote user input equals the username we're
* trying to authenticate, we'll perform the bind
*/
if ($remoteUser == $username) {
$auth = $this->bindUsingKerberos($kerberos);
}
} else {
// Looks like SSO isn't enabled, we'll bind regularly instead
$auth = $this->bindUsingCredentials($username, $password);
}
} catch (AdldapException $e) {
if ($preventRebind === true) {
/*
* Binding failed and we're not allowed
* to rebind, we'll return false
*/
return $auth;
}
}
// If we're allowed to rebind, we'll rebind as administrator
if ($preventRebind === false) {
$adminUsername = $this->getAdminUsername();
$adminPassword = $this->getAdminPassword();
$this->bindUsingCredentials($adminUsername, $adminPassword);
if (!$this->ldapConnection->isBound()) {
throw new AdldapException('Rebind to Active Directory failed. AD said: '.$this->ldapConnection->getLastError());
}
}
return $auth;
} | [
"public",
"function",
"authenticate",
"(",
"$",
"username",
",",
"$",
"password",
",",
"$",
"preventRebind",
"=",
"false",
")",
"{",
"$",
"auth",
"=",
"false",
";",
"try",
"{",
"if",
"(",
"$",
"this",
"->",
"getUseSSO",
"(",
")",
")",
"{",
"// If SSO... | Authenticates a user using the specified credentials.
@param string $username The users AD username
@param string $password The users AD password
@param bool $preventRebind
@return bool
@throws AdldapException | [
"Authenticates",
"a",
"user",
"using",
"the",
"specified",
"credentials",
"."
] | 63fd63e4f680e521bdf6cba23e0e524a2c34c0d5 | https://github.com/adldap/adLDAP/blob/63fd63e4f680e521bdf6cba23e0e524a2c34c0d5/src/Adldap.php#L716-L760 | train |
adldap/adLDAP | src/Adldap.php | Adldap.getObjectClass | public function getObjectClass($distinguishedName)
{
$this->utilities()->validateNotNull('Distinguished Name [dn]', $distinguishedName);
$result = $this->search()
->select('objectClass')
->where('distinguishedName', '=', $distinguishedName)
->first();
if (is_array($result) && array_key_exists('objectclass', $result)) {
return $result['objectclass'];
}
return false;
} | php | public function getObjectClass($distinguishedName)
{
$this->utilities()->validateNotNull('Distinguished Name [dn]', $distinguishedName);
$result = $this->search()
->select('objectClass')
->where('distinguishedName', '=', $distinguishedName)
->first();
if (is_array($result) && array_key_exists('objectclass', $result)) {
return $result['objectclass'];
}
return false;
} | [
"public",
"function",
"getObjectClass",
"(",
"$",
"distinguishedName",
")",
"{",
"$",
"this",
"->",
"utilities",
"(",
")",
"->",
"validateNotNull",
"(",
"'Distinguished Name [dn]'",
",",
"$",
"distinguishedName",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->"... | Returns objectClass in an array.
@param string $distinguishedName The full DN of a contact
@return array|bool | [
"Returns",
"objectClass",
"in",
"an",
"array",
"."
] | 63fd63e4f680e521bdf6cba23e0e524a2c34c0d5 | https://github.com/adldap/adLDAP/blob/63fd63e4f680e521bdf6cba23e0e524a2c34c0d5/src/Adldap.php#L769-L783 | train |
adldap/adLDAP | src/Adldap.php | Adldap.getRootDse | public function getRootDse($attributes = ['*', '+'])
{
return $this->search()
->setDn(null)
->read(true)
->select($attributes)
->where('objectClass', '*')
->first();
} | php | public function getRootDse($attributes = ['*', '+'])
{
return $this->search()
->setDn(null)
->read(true)
->select($attributes)
->where('objectClass', '*')
->first();
} | [
"public",
"function",
"getRootDse",
"(",
"$",
"attributes",
"=",
"[",
"'*'",
",",
"'+'",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"search",
"(",
")",
"->",
"setDn",
"(",
"null",
")",
"->",
"read",
"(",
"true",
")",
"->",
"select",
"(",
"$",
"a... | Get the RootDSE properties from a domain controller.
@param array $attributes The attributes you wish to query e.g. defaultnamingcontext
@return array|bool | [
"Get",
"the",
"RootDSE",
"properties",
"from",
"a",
"domain",
"controller",
"."
] | 63fd63e4f680e521bdf6cba23e0e524a2c34c0d5 | https://github.com/adldap/adLDAP/blob/63fd63e4f680e521bdf6cba23e0e524a2c34c0d5/src/Adldap.php#L808-L816 | train |
adldap/adLDAP | src/Adldap.php | Adldap.ldapSchema | public function ldapSchema(array $attributes)
{
// Check every attribute to see if it contains 8bit characters and then UTF8 encode them
array_walk($attributes, [$this->utilities(), 'encode8bit']);
$adldapSchema = new AdldapSchema($attributes);
$ldapSchema = new LdapSchema($adldapSchema);
if ($ldapSchema->countAttributes() === 0) {
return false;
}
// Return a filtered array to remove NULL attributes
return array_filter($ldapSchema->getAttributes(), function ($attribute) {
// Only return the attribute if it is not null
if ($attribute[0] !== null) {
return $attribute;
}
});
} | php | public function ldapSchema(array $attributes)
{
// Check every attribute to see if it contains 8bit characters and then UTF8 encode them
array_walk($attributes, [$this->utilities(), 'encode8bit']);
$adldapSchema = new AdldapSchema($attributes);
$ldapSchema = new LdapSchema($adldapSchema);
if ($ldapSchema->countAttributes() === 0) {
return false;
}
// Return a filtered array to remove NULL attributes
return array_filter($ldapSchema->getAttributes(), function ($attribute) {
// Only return the attribute if it is not null
if ($attribute[0] !== null) {
return $attribute;
}
});
} | [
"public",
"function",
"ldapSchema",
"(",
"array",
"$",
"attributes",
")",
"{",
"// Check every attribute to see if it contains 8bit characters and then UTF8 encode them",
"array_walk",
"(",
"$",
"attributes",
",",
"[",
"$",
"this",
"->",
"utilities",
"(",
")",
",",
"'en... | Returns an LDAP compatible schema array for modifications.
@param array $attributes Attributes to be queried
@return array|bool | [
"Returns",
"an",
"LDAP",
"compatible",
"schema",
"array",
"for",
"modifications",
"."
] | 63fd63e4f680e521bdf6cba23e0e524a2c34c0d5 | https://github.com/adldap/adLDAP/blob/63fd63e4f680e521bdf6cba23e0e524a2c34c0d5/src/Adldap.php#L843-L863 | train |
adldap/adLDAP | src/Adldap.php | Adldap.bindUsingKerberos | private function bindUsingKerberos($kerberosCredentials)
{
putenv('KRB5CCNAME='.$kerberosCredentials);
$bound = $this->ldapConnection->bind(null, null, true);
if (!$bound) {
$message = 'Bind to Active Directory failed. AD said: '.$this->ldapConnection->getLastError();
throw new AdldapException($message);
}
return true;
} | php | private function bindUsingKerberos($kerberosCredentials)
{
putenv('KRB5CCNAME='.$kerberosCredentials);
$bound = $this->ldapConnection->bind(null, null, true);
if (!$bound) {
$message = 'Bind to Active Directory failed. AD said: '.$this->ldapConnection->getLastError();
throw new AdldapException($message);
}
return true;
} | [
"private",
"function",
"bindUsingKerberos",
"(",
"$",
"kerberosCredentials",
")",
"{",
"putenv",
"(",
"'KRB5CCNAME='",
".",
"$",
"kerberosCredentials",
")",
";",
"$",
"bound",
"=",
"$",
"this",
"->",
"ldapConnection",
"->",
"bind",
"(",
"null",
",",
"null",
... | Binds to the current connection using kerberos.
@param $kerberosCredentials
@returns bool
@throws AdldapException | [
"Binds",
"to",
"the",
"current",
"connection",
"using",
"kerberos",
"."
] | 63fd63e4f680e521bdf6cba23e0e524a2c34c0d5 | https://github.com/adldap/adLDAP/blob/63fd63e4f680e521bdf6cba23e0e524a2c34c0d5/src/Adldap.php#L893-L906 | train |
adldap/adLDAP | src/Adldap.php | Adldap.bindUsingCredentials | private function bindUsingCredentials($username, $password)
{
// Allow binding with null credentials
if (empty($username)) {
$username = null;
} else {
$username .= $this->getAccountSuffix();
}
if (empty($password)) {
$password = null;
}
$this->ldapConnection->bind($username, $password);
if (!$this->ldapConnection->isBound()) {
$error = $this->ldapConnection->getLastError();
if ($this->ldapConnection->isUsingSSL() && !$this->ldapConnection->isUsingTLS()) {
$message = 'Bind to Active Directory failed. Either the LDAPs connection failed or the login credentials are incorrect. AD said: '.$error;
} else {
$message = 'Bind to Active Directory failed. Check the login credentials and/or server details. AD said: '.$error;
}
throw new AdldapException($message);
}
return true;
} | php | private function bindUsingCredentials($username, $password)
{
// Allow binding with null credentials
if (empty($username)) {
$username = null;
} else {
$username .= $this->getAccountSuffix();
}
if (empty($password)) {
$password = null;
}
$this->ldapConnection->bind($username, $password);
if (!$this->ldapConnection->isBound()) {
$error = $this->ldapConnection->getLastError();
if ($this->ldapConnection->isUsingSSL() && !$this->ldapConnection->isUsingTLS()) {
$message = 'Bind to Active Directory failed. Either the LDAPs connection failed or the login credentials are incorrect. AD said: '.$error;
} else {
$message = 'Bind to Active Directory failed. Check the login credentials and/or server details. AD said: '.$error;
}
throw new AdldapException($message);
}
return true;
} | [
"private",
"function",
"bindUsingCredentials",
"(",
"$",
"username",
",",
"$",
"password",
")",
"{",
"// Allow binding with null credentials",
"if",
"(",
"empty",
"(",
"$",
"username",
")",
")",
"{",
"$",
"username",
"=",
"null",
";",
"}",
"else",
"{",
"$",
... | Binds to the current connection using the
inserted credentials.
@param string $username
@param string $password
@returns bool
@throws AdldapException | [
"Binds",
"to",
"the",
"current",
"connection",
"using",
"the",
"inserted",
"credentials",
"."
] | 63fd63e4f680e521bdf6cba23e0e524a2c34c0d5 | https://github.com/adldap/adLDAP/blob/63fd63e4f680e521bdf6cba23e0e524a2c34c0d5/src/Adldap.php#L918-L946 | train |
adldap/adLDAP | src/Classes/AdldapUsers.php | AdldapUsers.authenticate | public function authenticate($username, $password, $preventRebind = false)
{
return $this->adldap->authenticate($username, $password, $preventRebind);
} | php | public function authenticate($username, $password, $preventRebind = false)
{
return $this->adldap->authenticate($username, $password, $preventRebind);
} | [
"public",
"function",
"authenticate",
"(",
"$",
"username",
",",
"$",
"password",
",",
"$",
"preventRebind",
"=",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"adldap",
"->",
"authenticate",
"(",
"$",
"username",
",",
"$",
"password",
",",
"$",
"preve... | Validate a user's login credentials.
@param string $username The users AD username
@param string $password The users AD password
@param bool $preventRebind
@return bool | [
"Validate",
"a",
"user",
"s",
"login",
"credentials",
"."
] | 63fd63e4f680e521bdf6cba23e0e524a2c34c0d5 | https://github.com/adldap/adLDAP/blob/63fd63e4f680e521bdf6cba23e0e524a2c34c0d5/src/Classes/AdldapUsers.php#L28-L31 | train |
adldap/adLDAP | src/Classes/AdldapUsers.php | AdldapUsers.all | public function all($fields = [], $sorted = true, $sortBy = 'cn', $sortByDirection = 'asc')
{
$personCategory = $this->adldap->getPersonFilter('category');
$person = $this->adldap->getPersonFilter('person');
$search = $this->adldap->search()
->select($fields)
->where($personCategory, '=', $person)
->where('samaccounttype', '=', Adldap::ADLDAP_NORMAL_ACCOUNT);
if ($sorted) {
$search->sortBy($sortBy, $sortByDirection);
}
return $search->get();
} | php | public function all($fields = [], $sorted = true, $sortBy = 'cn', $sortByDirection = 'asc')
{
$personCategory = $this->adldap->getPersonFilter('category');
$person = $this->adldap->getPersonFilter('person');
$search = $this->adldap->search()
->select($fields)
->where($personCategory, '=', $person)
->where('samaccounttype', '=', Adldap::ADLDAP_NORMAL_ACCOUNT);
if ($sorted) {
$search->sortBy($sortBy, $sortByDirection);
}
return $search->get();
} | [
"public",
"function",
"all",
"(",
"$",
"fields",
"=",
"[",
"]",
",",
"$",
"sorted",
"=",
"true",
",",
"$",
"sortBy",
"=",
"'cn'",
",",
"$",
"sortByDirection",
"=",
"'asc'",
")",
"{",
"$",
"personCategory",
"=",
"$",
"this",
"->",
"adldap",
"->",
"g... | Returns all users from the current connection.
@param array $fields
@param bool $sorted
@param string $sortBy
@param string $sortByDirection
@return array|bool
@throws AdldapException | [
"Returns",
"all",
"users",
"from",
"the",
"current",
"connection",
"."
] | 63fd63e4f680e521bdf6cba23e0e524a2c34c0d5 | https://github.com/adldap/adLDAP/blob/63fd63e4f680e521bdf6cba23e0e524a2c34c0d5/src/Classes/AdldapUsers.php#L45-L60 | train |
adldap/adLDAP | src/Classes/AdldapUsers.php | AdldapUsers.find | public function find($username, $fields = [])
{
$this->adldap->utilities()->validateNotNullOrEmpty('Username', $username);
$personCategory = $this->adldap->getPersonFilter('category');
$person = $this->adldap->getPersonFilter('person');
return $this->adldap->search()
->select($fields)
->where($personCategory, '=', $person)
->where('samaccounttype', '=', Adldap::ADLDAP_NORMAL_ACCOUNT)
->where('anr', '=', $username)
->first();
} | php | public function find($username, $fields = [])
{
$this->adldap->utilities()->validateNotNullOrEmpty('Username', $username);
$personCategory = $this->adldap->getPersonFilter('category');
$person = $this->adldap->getPersonFilter('person');
return $this->adldap->search()
->select($fields)
->where($personCategory, '=', $person)
->where('samaccounttype', '=', Adldap::ADLDAP_NORMAL_ACCOUNT)
->where('anr', '=', $username)
->first();
} | [
"public",
"function",
"find",
"(",
"$",
"username",
",",
"$",
"fields",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"adldap",
"->",
"utilities",
"(",
")",
"->",
"validateNotNullOrEmpty",
"(",
"'Username'",
",",
"$",
"username",
")",
";",
"$",
"personCa... | Finds a user with the specified username
in the connection connection.
The username parameter can be any attribute on the user.
Such as a their name, their logon, their mail, etc.
@param string $username
@param array $fields
@return array|bool | [
"Finds",
"a",
"user",
"with",
"the",
"specified",
"username",
"in",
"the",
"connection",
"connection",
"."
] | 63fd63e4f680e521bdf6cba23e0e524a2c34c0d5 | https://github.com/adldap/adLDAP/blob/63fd63e4f680e521bdf6cba23e0e524a2c34c0d5/src/Classes/AdldapUsers.php#L74-L87 | train |
adldap/adLDAP | src/Classes/AdldapUsers.php | AdldapUsers.passwordExpiry | public function passwordExpiry($username)
{
$this->adldap->utilities()->validateBcmodExists();
$user = $this->info($username, ['pwdlastset', 'useraccountcontrol']);
if (is_array($user) && array_key_exists('pwdlastset', $user)) {
$pwdLastSet = $user['pwdlastset'];
$status = [
'expires' => true,
'has_expired' => false,
];
// Check if the password expires
if (array_key_exists('useraccountcontrol', $user) && $user['useraccountcontrol'] == '66048') {
$status['expires'] = false;
}
// Check if the password is expired
if ($pwdLastSet === '0') {
$status['has_expired'] = true;
}
$result = $this->adldap->search()
->select(['maxPwdAge'])
->where('objectclass', '*')
->first();
if ($result && $status['expires'] === true) {
$maxPwdAge = $result['maxpwdage'];
// See MSDN: http://msdn.microsoft.com/en-us/library/ms974598.aspx
if (bcmod($maxPwdAge, 4294967296) === '0') {
return 'Domain does not expire passwords';
}
// Add maxpwdage and pwdlastset and we get password expiration time in Microsoft's
// time units. Because maxpwd age is negative we need to subtract it.
$pwdExpire = bcsub($pwdLastSet, $maxPwdAge);
// Convert MS's time to Unix time
$unixTime = bcsub(bcdiv($pwdExpire, '10000000'), '11644473600');
$status['expiry_timestamp'] = $unixTime;
$status['expiry_formatted'] = date('Y-m-d H:i:s', $unixTime);
}
return $status;
}
return false;
} | php | public function passwordExpiry($username)
{
$this->adldap->utilities()->validateBcmodExists();
$user = $this->info($username, ['pwdlastset', 'useraccountcontrol']);
if (is_array($user) && array_key_exists('pwdlastset', $user)) {
$pwdLastSet = $user['pwdlastset'];
$status = [
'expires' => true,
'has_expired' => false,
];
// Check if the password expires
if (array_key_exists('useraccountcontrol', $user) && $user['useraccountcontrol'] == '66048') {
$status['expires'] = false;
}
// Check if the password is expired
if ($pwdLastSet === '0') {
$status['has_expired'] = true;
}
$result = $this->adldap->search()
->select(['maxPwdAge'])
->where('objectclass', '*')
->first();
if ($result && $status['expires'] === true) {
$maxPwdAge = $result['maxpwdage'];
// See MSDN: http://msdn.microsoft.com/en-us/library/ms974598.aspx
if (bcmod($maxPwdAge, 4294967296) === '0') {
return 'Domain does not expire passwords';
}
// Add maxpwdage and pwdlastset and we get password expiration time in Microsoft's
// time units. Because maxpwd age is negative we need to subtract it.
$pwdExpire = bcsub($pwdLastSet, $maxPwdAge);
// Convert MS's time to Unix time
$unixTime = bcsub(bcdiv($pwdExpire, '10000000'), '11644473600');
$status['expiry_timestamp'] = $unixTime;
$status['expiry_formatted'] = date('Y-m-d H:i:s', $unixTime);
}
return $status;
}
return false;
} | [
"public",
"function",
"passwordExpiry",
"(",
"$",
"username",
")",
"{",
"$",
"this",
"->",
"adldap",
"->",
"utilities",
"(",
")",
"->",
"validateBcmodExists",
"(",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"info",
"(",
"$",
"username",
",",
"[",
... | Determine a user's password expiry date.
@param $username
@return array|bool
@throws AdldapException
@requires bcmod http://php.net/manual/en/function.bcmod.php | [
"Determine",
"a",
"user",
"s",
"password",
"expiry",
"date",
"."
] | 63fd63e4f680e521bdf6cba23e0e524a2c34c0d5 | https://github.com/adldap/adLDAP/blob/63fd63e4f680e521bdf6cba23e0e524a2c34c0d5/src/Classes/AdldapUsers.php#L149-L201 | train |
adldap/adLDAP | src/Classes/AdldapUsers.php | AdldapUsers.modify | public function modify($username, $attributes, $isGUID = false)
{
$user = new User($attributes);
/*
* Set the username attribute manually so it's properly
* validated using toModifySchema method
*/
$user->setAttribute('username', $username);
if ($user->getAttribute('password') && !$this->connection->canChangePasswords()) {
throw new AdldapException('SSL/TLS must be configured on your webserver and enabled in the class to set passwords.');
}
// Find the dn of the user
$userDn = $this->dn($username, $isGUID);
if ($userDn === false) {
return false;
}
// Translate the update to the LDAP schema
$mod = $this->adldap->ldapSchema($user->toModifySchema());
$enabled = $user->getAttribute('enabled');
// Check to see if this is an enabled status update
if (!$mod && !$enabled) {
return false;
}
if ($enabled) {
$controlOptions = ['NORMAL_ACCOUNT'];
} else {
$controlOptions = ['NORMAL_ACCOUNT', 'ACCOUNTDISABLE'];
}
$mod['userAccountControl'][0] = $this->accountControl($controlOptions);
// Do the update
return $this->connection->modify($userDn, $mod);
} | php | public function modify($username, $attributes, $isGUID = false)
{
$user = new User($attributes);
/*
* Set the username attribute manually so it's properly
* validated using toModifySchema method
*/
$user->setAttribute('username', $username);
if ($user->getAttribute('password') && !$this->connection->canChangePasswords()) {
throw new AdldapException('SSL/TLS must be configured on your webserver and enabled in the class to set passwords.');
}
// Find the dn of the user
$userDn = $this->dn($username, $isGUID);
if ($userDn === false) {
return false;
}
// Translate the update to the LDAP schema
$mod = $this->adldap->ldapSchema($user->toModifySchema());
$enabled = $user->getAttribute('enabled');
// Check to see if this is an enabled status update
if (!$mod && !$enabled) {
return false;
}
if ($enabled) {
$controlOptions = ['NORMAL_ACCOUNT'];
} else {
$controlOptions = ['NORMAL_ACCOUNT', 'ACCOUNTDISABLE'];
}
$mod['userAccountControl'][0] = $this->accountControl($controlOptions);
// Do the update
return $this->connection->modify($userDn, $mod);
} | [
"public",
"function",
"modify",
"(",
"$",
"username",
",",
"$",
"attributes",
",",
"$",
"isGUID",
"=",
"false",
")",
"{",
"$",
"user",
"=",
"new",
"User",
"(",
"$",
"attributes",
")",
";",
"/*\n * Set the username attribute manually so it's properly\n ... | Modify a user.
@param string $username The username to query
@param array $attributes The attributes to modify. Note if you set the enabled attribute you must not specify any other attributes
@param bool $isGUID Is the username passed a GUID or a samAccountName
@return bool|string
@throws AdldapException | [
"Modify",
"a",
"user",
"."
] | 63fd63e4f680e521bdf6cba23e0e524a2c34c0d5 | https://github.com/adldap/adLDAP/blob/63fd63e4f680e521bdf6cba23e0e524a2c34c0d5/src/Classes/AdldapUsers.php#L214-L255 | train |
adldap/adLDAP | src/Classes/AdldapUsers.php | AdldapUsers.enable | public function enable($username, $isGUID = false)
{
$this->adldap->utilities()->validateNotNull('Username', $username);
$attributes = ['enabled' => 1];
return $this->modify($username, $attributes, $isGUID);
} | php | public function enable($username, $isGUID = false)
{
$this->adldap->utilities()->validateNotNull('Username', $username);
$attributes = ['enabled' => 1];
return $this->modify($username, $attributes, $isGUID);
} | [
"public",
"function",
"enable",
"(",
"$",
"username",
",",
"$",
"isGUID",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"adldap",
"->",
"utilities",
"(",
")",
"->",
"validateNotNull",
"(",
"'Username'",
",",
"$",
"username",
")",
";",
"$",
"attributes",
"... | Enable a user account.
@param string $username The username to enable
@param bool $isGUID Is the username passed a GUID or a samAccountName
@return bool|string
@throws AdldapException | [
"Enable",
"a",
"user",
"account",
"."
] | 63fd63e4f680e521bdf6cba23e0e524a2c34c0d5 | https://github.com/adldap/adLDAP/blob/63fd63e4f680e521bdf6cba23e0e524a2c34c0d5/src/Classes/AdldapUsers.php#L286-L293 | train |
adldap/adLDAP | src/Classes/AdldapUsers.php | AdldapUsers.password | public function password($username, $password, $isGUID = false)
{
$this->adldap->utilities()->validateNotNull('Username', $username);
$this->adldap->utilities()->validateNotNull('Password', $password);
$this->adldap->utilities()->validateLdapIsBound();
if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
$message = 'SSL must be configured on your webserver and enabled in the class to set passwords.';
throw new AdldapException($message);
}
$userDn = $this->dn($username, $isGUID);
if ($userDn === false) {
return false;
}
$add = [];
$add['unicodePwd'][0] = $this->encodePassword($password);
$result = $this->connection->modReplace($userDn, $add);
if ($result === false) {
$err = $this->connection->errNo();
if ($err) {
$error = $this->connection->err2Str($err);
$msg = 'Error '.$err.': '.$error.'.';
if ($err == 53) {
$msg .= ' Your password might not match the password policy.';
}
throw new AdldapException($msg);
} else {
return false;
}
}
return true;
} | php | public function password($username, $password, $isGUID = false)
{
$this->adldap->utilities()->validateNotNull('Username', $username);
$this->adldap->utilities()->validateNotNull('Password', $password);
$this->adldap->utilities()->validateLdapIsBound();
if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
$message = 'SSL must be configured on your webserver and enabled in the class to set passwords.';
throw new AdldapException($message);
}
$userDn = $this->dn($username, $isGUID);
if ($userDn === false) {
return false;
}
$add = [];
$add['unicodePwd'][0] = $this->encodePassword($password);
$result = $this->connection->modReplace($userDn, $add);
if ($result === false) {
$err = $this->connection->errNo();
if ($err) {
$error = $this->connection->err2Str($err);
$msg = 'Error '.$err.': '.$error.'.';
if ($err == 53) {
$msg .= ' Your password might not match the password policy.';
}
throw new AdldapException($msg);
} else {
return false;
}
}
return true;
} | [
"public",
"function",
"password",
"(",
"$",
"username",
",",
"$",
"password",
",",
"$",
"isGUID",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"adldap",
"->",
"utilities",
"(",
")",
"->",
"validateNotNull",
"(",
"'Username'",
",",
"$",
"username",
")",
"... | Set the password of a user - This must be performed over SSL.
@param string $username The username to modify
@param string $password The new password
@param bool $isGUID Is the username passed a GUID or a samAccountName
@return bool
@throws AdldapException | [
"Set",
"the",
"password",
"of",
"a",
"user",
"-",
"This",
"must",
"be",
"performed",
"over",
"SSL",
"."
] | 63fd63e4f680e521bdf6cba23e0e524a2c34c0d5 | https://github.com/adldap/adLDAP/blob/63fd63e4f680e521bdf6cba23e0e524a2c34c0d5/src/Classes/AdldapUsers.php#L306-L350 | train |
adldap/adLDAP | src/Classes/AdldapUsers.php | AdldapUsers.changePassword | public function changePassword($username, $password, $oldPassword, $isGUID = false)
{
$this->adldap->utilities()->validateNotNull('Username', $username);
$this->adldap->utilities()->validateNotNull('Password', $password);
$this->adldap->utilities()->validateNotNull('Old Password', $oldPassword);
$this->adldap->utilities()->validateLdapIsBound();
if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
$message = 'SSL must be configured on your webserver and enabled in the class to set passwords.';
throw new AdldapException($message);
}
if (!$this->connection->isBatchSupported()) {
$message = 'Missing function support [ldap_modify_batch] http://php.net/manual/en/function.ldap-modify-batch.php';
throw new AdldapException($message);
}
$userDn = $this->dn($username, $isGUID);
if ($userDn === false) {
return false;
}
$modification = [
[
'attrib' => 'unicodePwd',
'modtype' => LDAP_MODIFY_BATCH_REMOVE,
'values' => [$this->encodePassword($oldPassword)],
],
[
'attrib' => 'unicodePwd',
'modtype' => LDAP_MODIFY_BATCH_ADD,
'values' => [$this->encodePassword($password)],
],
];
$result = $this->connection->modifyBatch($userDn, $modification);
if ($result === false) {
$error = $this->connection->getExtendedError();
if ($error) {
$errorCode = $this->connection->getExtendedErrorCode();
$msg = 'Error: '.$error;
if ($errorCode == '0000052D') {
$msg = "Error: $errorCode. Your new password might not match the password policy.";
throw new PasswordPolicyException($msg);
} elseif ($errorCode == '00000056') {
$msg = "Error: $errorCode. Your old password might be wrong.";
throw new WrongPasswordException($msg);
}
throw new AdldapException($msg);
} else {
return false;
}
}
return true;
} | php | public function changePassword($username, $password, $oldPassword, $isGUID = false)
{
$this->adldap->utilities()->validateNotNull('Username', $username);
$this->adldap->utilities()->validateNotNull('Password', $password);
$this->adldap->utilities()->validateNotNull('Old Password', $oldPassword);
$this->adldap->utilities()->validateLdapIsBound();
if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
$message = 'SSL must be configured on your webserver and enabled in the class to set passwords.';
throw new AdldapException($message);
}
if (!$this->connection->isBatchSupported()) {
$message = 'Missing function support [ldap_modify_batch] http://php.net/manual/en/function.ldap-modify-batch.php';
throw new AdldapException($message);
}
$userDn = $this->dn($username, $isGUID);
if ($userDn === false) {
return false;
}
$modification = [
[
'attrib' => 'unicodePwd',
'modtype' => LDAP_MODIFY_BATCH_REMOVE,
'values' => [$this->encodePassword($oldPassword)],
],
[
'attrib' => 'unicodePwd',
'modtype' => LDAP_MODIFY_BATCH_ADD,
'values' => [$this->encodePassword($password)],
],
];
$result = $this->connection->modifyBatch($userDn, $modification);
if ($result === false) {
$error = $this->connection->getExtendedError();
if ($error) {
$errorCode = $this->connection->getExtendedErrorCode();
$msg = 'Error: '.$error;
if ($errorCode == '0000052D') {
$msg = "Error: $errorCode. Your new password might not match the password policy.";
throw new PasswordPolicyException($msg);
} elseif ($errorCode == '00000056') {
$msg = "Error: $errorCode. Your old password might be wrong.";
throw new WrongPasswordException($msg);
}
throw new AdldapException($msg);
} else {
return false;
}
}
return true;
} | [
"public",
"function",
"changePassword",
"(",
"$",
"username",
",",
"$",
"password",
",",
"$",
"oldPassword",
",",
"$",
"isGUID",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"adldap",
"->",
"utilities",
"(",
")",
"->",
"validateNotNull",
"(",
"'Username'",
... | Change the password of a user - This must be performed over SSL
Requires PHP 5.4 >= 5.4.26, PHP 5.5 >= 5.5.10 or PHP 5.6 >= 5.6.0.
@param string $username The username to modify
@param string $password The new password
@param string $oldPassword The old password
@param bool $isGUID Is the username passed a GUID or a samAccountName
@return bool
@throws AdldapException | [
"Change",
"the",
"password",
"of",
"a",
"user",
"-",
"This",
"must",
"be",
"performed",
"over",
"SSL",
"Requires",
"PHP",
"5",
".",
"4",
">",
"=",
"5",
".",
"4",
".",
"26",
"PHP",
"5",
".",
"5",
">",
"=",
"5",
".",
"5",
".",
"10",
"or",
"PHP"... | 63fd63e4f680e521bdf6cba23e0e524a2c34c0d5 | https://github.com/adldap/adLDAP/blob/63fd63e4f680e521bdf6cba23e0e524a2c34c0d5/src/Classes/AdldapUsers.php#L365-L431 | train |
adldap/adLDAP | src/Classes/AdldapUsers.php | AdldapUsers.encodePassword | public function encodePassword($password)
{
$password = '"'.$password.'"';
$encoded = '';
$length = strlen($password);
for ($i = 0; $i < $length; $i++) {
$encoded .= "{$password{$i}
}\000";
}
return $encoded;
} | php | public function encodePassword($password)
{
$password = '"'.$password.'"';
$encoded = '';
$length = strlen($password);
for ($i = 0; $i < $length; $i++) {
$encoded .= "{$password{$i}
}\000";
}
return $encoded;
} | [
"public",
"function",
"encodePassword",
"(",
"$",
"password",
")",
"{",
"$",
"password",
"=",
"'\"'",
".",
"$",
"password",
".",
"'\"'",
";",
"$",
"encoded",
"=",
"''",
";",
"$",
"length",
"=",
"strlen",
"(",
"$",
"password",
")",
";",
"for",
"(",
... | Encode a password for transmission over LDAP.
@param string $password The password to encode
@return string | [
"Encode",
"a",
"password",
"for",
"transmission",
"over",
"LDAP",
"."
] | 63fd63e4f680e521bdf6cba23e0e524a2c34c0d5 | https://github.com/adldap/adLDAP/blob/63fd63e4f680e521bdf6cba23e0e524a2c34c0d5/src/Classes/AdldapUsers.php#L440-L454 | train |
adldap/adLDAP | src/Classes/AdldapUsers.php | AdldapUsers.move | public function move($username, $container)
{
$user = new User([
'username' => $username,
'container' => $container,
]);
// Validate only the username and container attributes
$user->validateRequired(['username', 'container']);
$this->adldap->utilities()->validateLdapIsBound();
$userInfo = $this->info($user->getAttribute('username'));
$dn = $userInfo['dn'];
$newRDn = 'cn='.$user->getAttribute('username');
$container = array_reverse($container);
$newContainer = 'ou='.implode(',ou=', $container);
$newBaseDn = strtolower($newContainer).','.$this->adldap->getBaseDn();
return $this->connection->rename($dn, $newRDn, $newBaseDn, true);
} | php | public function move($username, $container)
{
$user = new User([
'username' => $username,
'container' => $container,
]);
// Validate only the username and container attributes
$user->validateRequired(['username', 'container']);
$this->adldap->utilities()->validateLdapIsBound();
$userInfo = $this->info($user->getAttribute('username'));
$dn = $userInfo['dn'];
$newRDn = 'cn='.$user->getAttribute('username');
$container = array_reverse($container);
$newContainer = 'ou='.implode(',ou=', $container);
$newBaseDn = strtolower($newContainer).','.$this->adldap->getBaseDn();
return $this->connection->rename($dn, $newRDn, $newBaseDn, true);
} | [
"public",
"function",
"move",
"(",
"$",
"username",
",",
"$",
"container",
")",
"{",
"$",
"user",
"=",
"new",
"User",
"(",
"[",
"'username'",
"=>",
"$",
"username",
",",
"'container'",
"=>",
"$",
"container",
",",
"]",
")",
";",
"// Validate only the use... | Move a user account to a different OU.
When specifying containers, it accepts containers in 1. parent 2. child order
@param string $username The username to move
@param string $container The container or containers to move the user to
@return bool|string | [
"Move",
"a",
"user",
"account",
"to",
"a",
"different",
"OU",
"."
] | 63fd63e4f680e521bdf6cba23e0e524a2c34c0d5 | https://github.com/adldap/adLDAP/blob/63fd63e4f680e521bdf6cba23e0e524a2c34c0d5/src/Classes/AdldapUsers.php#L500-L525 | train |
adldap/adLDAP | src/Classes/AdldapUsers.php | AdldapUsers.getLastLogon | public function getLastLogon($username)
{
$this->adldap->utilities()->validateNotNull('Username', $username);
$userInfo = $this->info($username, ['lastlogontimestamp']);
if (is_array($userInfo) && array_key_exists('lastlogontimestamp', $userInfo)) {
return AdldapUtils::convertWindowsTimeToUnixTime($userInfo['lastlogontimestamp']);
}
return false;
} | php | public function getLastLogon($username)
{
$this->adldap->utilities()->validateNotNull('Username', $username);
$userInfo = $this->info($username, ['lastlogontimestamp']);
if (is_array($userInfo) && array_key_exists('lastlogontimestamp', $userInfo)) {
return AdldapUtils::convertWindowsTimeToUnixTime($userInfo['lastlogontimestamp']);
}
return false;
} | [
"public",
"function",
"getLastLogon",
"(",
"$",
"username",
")",
"{",
"$",
"this",
"->",
"adldap",
"->",
"utilities",
"(",
")",
"->",
"validateNotNull",
"(",
"'Username'",
",",
"$",
"username",
")",
";",
"$",
"userInfo",
"=",
"$",
"this",
"->",
"info",
... | Get the last logon time of any user as a Unix timestamp.
@param string $username
@return float|bool|string | [
"Get",
"the",
"last",
"logon",
"time",
"of",
"any",
"user",
"as",
"a",
"Unix",
"timestamp",
"."
] | 63fd63e4f680e521bdf6cba23e0e524a2c34c0d5 | https://github.com/adldap/adLDAP/blob/63fd63e4f680e521bdf6cba23e0e524a2c34c0d5/src/Classes/AdldapUsers.php#L534-L545 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.