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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
ldaptools/ldaptools | src/LdapTools/AttributeConverter/ConvertValueToDn.php | ConvertValueToDn.getAttributeFromLdapQuery | protected function getAttributeFromLdapQuery($value, $toSelect)
{
$query = $this->buildLdapQuery($this->options['filter'], $this->options['or_filter'], $toSelect);
$bOr = $this->getQueryOrStatement($query, $value);
$eq = $this->getQueryComparisonStatement($value, $query);
if (!empty($bOr->getChildren())) {
$bOr->add($eq);
$query->where($bOr);
} else {
$query->where($eq);
}
$query->setBaseDn($this->options['base_dn']);
try {
return $query->getLdapQuery()->getSingleScalarResult();
} catch (EmptyResultException $e) {
throw new AttributeConverterException(sprintf(
'Unable to convert value "%s" to a %s for attribute "%s"',
$value,
$toSelect,
$this->getAttribute()
));
}
} | php | protected function getAttributeFromLdapQuery($value, $toSelect)
{
$query = $this->buildLdapQuery($this->options['filter'], $this->options['or_filter'], $toSelect);
$bOr = $this->getQueryOrStatement($query, $value);
$eq = $this->getQueryComparisonStatement($value, $query);
if (!empty($bOr->getChildren())) {
$bOr->add($eq);
$query->where($bOr);
} else {
$query->where($eq);
}
$query->setBaseDn($this->options['base_dn']);
try {
return $query->getLdapQuery()->getSingleScalarResult();
} catch (EmptyResultException $e) {
throw new AttributeConverterException(sprintf(
'Unable to convert value "%s" to a %s for attribute "%s"',
$value,
$toSelect,
$this->getAttribute()
));
}
} | [
"protected",
"function",
"getAttributeFromLdapQuery",
"(",
"$",
"value",
",",
"$",
"toSelect",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"buildLdapQuery",
"(",
"$",
"this",
"->",
"options",
"[",
"'filter'",
"]",
",",
"$",
"this",
"->",
"options",
"... | Attempt to look-up the attribute from a LDAP query based on the value.
@param string $value
@param string $toSelect
@return string The distinguished name.
@throws AttributeConverterException | [
"Attempt",
"to",
"look",
"-",
"up",
"the",
"attribute",
"from",
"a",
"LDAP",
"query",
"based",
"on",
"the",
"value",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/AttributeConverter/ConvertValueToDn.php#L109-L134 | train |
ldaptools/ldaptools | src/LdapTools/Object/LdapObjectCreator.php | LdapObjectCreator.create | public function create($type)
{
if (!is_string($type) && !($type instanceof LdapObjectSchema)) {
throw new InvalidArgumentException(
'You must either pass the schema object type as a string to this method, or pass the schema types '
. 'LdapObjectSchema to this method.'
);
}
if (!($type instanceof LdapObjectSchema)) {
$type = $this->schemaFactory->get($this->connection->getConfig()->getSchemaName(), $type);
}
$this->schema = $type;
$this->container = $type->getDefaultContainer();
return $this;
} | php | public function create($type)
{
if (!is_string($type) && !($type instanceof LdapObjectSchema)) {
throw new InvalidArgumentException(
'You must either pass the schema object type as a string to this method, or pass the schema types '
. 'LdapObjectSchema to this method.'
);
}
if (!($type instanceof LdapObjectSchema)) {
$type = $this->schemaFactory->get($this->connection->getConfig()->getSchemaName(), $type);
}
$this->schema = $type;
$this->container = $type->getDefaultContainer();
return $this;
} | [
"public",
"function",
"create",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"type",
")",
"&&",
"!",
"(",
"$",
"type",
"instanceof",
"LdapObjectSchema",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'You must either... | Specify the object type to create. Either by its string name type from the schema of the LdapObjectSchema.
@param string|LdapObjectSchema $type
@return $this | [
"Specify",
"the",
"object",
"type",
"to",
"create",
".",
"Either",
"by",
"its",
"string",
"name",
"type",
"from",
"the",
"schema",
"of",
"the",
"LdapObjectSchema",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Object/LdapObjectCreator.php#L101-L116 | train |
ldaptools/ldaptools | src/LdapTools/Object/LdapObjectCreator.php | LdapObjectCreator.execute | public function execute()
{
$this->triggerBeforeCreationEvent();
$operation = $this->getAddOperation()->setServer($this->server);
$this->connection->execute($operation);
$this->triggerAfterCreationEvent($operation);
} | php | public function execute()
{
$this->triggerBeforeCreationEvent();
$operation = $this->getAddOperation()->setServer($this->server);
$this->connection->execute($operation);
$this->triggerAfterCreationEvent($operation);
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"$",
"this",
"->",
"triggerBeforeCreationEvent",
"(",
")",
";",
"$",
"operation",
"=",
"$",
"this",
"->",
"getAddOperation",
"(",
")",
"->",
"setServer",
"(",
"$",
"this",
"->",
"server",
")",
";",
"$",
"... | Add the object with the selected attributes into LDAP. | [
"Add",
"the",
"object",
"with",
"the",
"selected",
"attributes",
"into",
"LDAP",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Object/LdapObjectCreator.php#L249-L255 | train |
ldaptools/ldaptools | src/LdapTools/Object/LdapObjectCreator.php | LdapObjectCreator.getAddOperation | protected function getAddOperation()
{
$operation = new AddOperation($this->dn, $this->attributes);
$operation->setLocation($this->container);
foreach ($this->parameters as $parameter => $value) {
$this->hydrator->setParameter($parameter, $value);
}
$this->hydrator->setLdapObjectSchema($this->schema);
$this->hydrator->setLdapConnection($this->connection);
$this->hydrator->setOperationType(AttributeConverterInterface::TYPE_CREATE);
return $this->hydrator->hydrateToLdap($operation);
} | php | protected function getAddOperation()
{
$operation = new AddOperation($this->dn, $this->attributes);
$operation->setLocation($this->container);
foreach ($this->parameters as $parameter => $value) {
$this->hydrator->setParameter($parameter, $value);
}
$this->hydrator->setLdapObjectSchema($this->schema);
$this->hydrator->setLdapConnection($this->connection);
$this->hydrator->setOperationType(AttributeConverterInterface::TYPE_CREATE);
return $this->hydrator->hydrateToLdap($operation);
} | [
"protected",
"function",
"getAddOperation",
"(",
")",
"{",
"$",
"operation",
"=",
"new",
"AddOperation",
"(",
"$",
"this",
"->",
"dn",
",",
"$",
"this",
"->",
"attributes",
")",
";",
"$",
"operation",
"->",
"setLocation",
"(",
"$",
"this",
"->",
"contain... | Get the add operation and take care of the hydration process.
@return AddOperation | [
"Get",
"the",
"add",
"operation",
"and",
"take",
"care",
"of",
"the",
"hydration",
"process",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Object/LdapObjectCreator.php#L262-L275 | train |
ldaptools/ldaptools | src/LdapTools/Object/LdapObjectCreator.php | LdapObjectCreator.triggerBeforeCreationEvent | protected function triggerBeforeCreationEvent()
{
$event = new LdapObjectCreationEvent(Event::LDAP_OBJECT_BEFORE_CREATE, $this->schema ? $this->schema->getObjectType() : null);
$event->setData($this->attributes);
$event->setContainer($this->container);
$event->setDn($this->dn);
$this->dispatcher->dispatch($event);
$this->attributes = $event->getData();
$this->container = $event->getContainer();
$this->dn = $event->getDn();
} | php | protected function triggerBeforeCreationEvent()
{
$event = new LdapObjectCreationEvent(Event::LDAP_OBJECT_BEFORE_CREATE, $this->schema ? $this->schema->getObjectType() : null);
$event->setData($this->attributes);
$event->setContainer($this->container);
$event->setDn($this->dn);
$this->dispatcher->dispatch($event);
$this->attributes = $event->getData();
$this->container = $event->getContainer();
$this->dn = $event->getDn();
} | [
"protected",
"function",
"triggerBeforeCreationEvent",
"(",
")",
"{",
"$",
"event",
"=",
"new",
"LdapObjectCreationEvent",
"(",
"Event",
"::",
"LDAP_OBJECT_BEFORE_CREATE",
",",
"$",
"this",
"->",
"schema",
"?",
"$",
"this",
"->",
"schema",
"->",
"getObjectType",
... | Trigger a LDAP object before creation event. | [
"Trigger",
"a",
"LDAP",
"object",
"before",
"creation",
"event",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Object/LdapObjectCreator.php#L280-L292 | train |
ldaptools/ldaptools | src/LdapTools/Object/LdapObjectCreator.php | LdapObjectCreator.triggerAfterCreationEvent | protected function triggerAfterCreationEvent(AddOperation $operation)
{
$event = new LdapObjectCreationEvent(Event::LDAP_OBJECT_AFTER_CREATE, $this->schema ? $this->schema->getObjectType() : null);
$event->setData((new ParameterResolver($this->attributes, $this->hydrator->getParameters()))->resolve());
$event->setContainer($operation->getLocation());
$event->setDn($operation->getDn());
$this->dispatcher->dispatch($event);
} | php | protected function triggerAfterCreationEvent(AddOperation $operation)
{
$event = new LdapObjectCreationEvent(Event::LDAP_OBJECT_AFTER_CREATE, $this->schema ? $this->schema->getObjectType() : null);
$event->setData((new ParameterResolver($this->attributes, $this->hydrator->getParameters()))->resolve());
$event->setContainer($operation->getLocation());
$event->setDn($operation->getDn());
$this->dispatcher->dispatch($event);
} | [
"protected",
"function",
"triggerAfterCreationEvent",
"(",
"AddOperation",
"$",
"operation",
")",
"{",
"$",
"event",
"=",
"new",
"LdapObjectCreationEvent",
"(",
"Event",
"::",
"LDAP_OBJECT_AFTER_CREATE",
",",
"$",
"this",
"->",
"schema",
"?",
"$",
"this",
"->",
... | Trigger a LDAP object after creation event.
@param AddOperation $operation | [
"Trigger",
"a",
"LDAP",
"object",
"after",
"creation",
"event",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Object/LdapObjectCreator.php#L299-L307 | train |
ldaptools/ldaptools | src/LdapTools/AttributeConverter/ConvertGroupType.php | ConvertGroupType.modifyFlagValue | protected function modifyFlagValue($value)
{
$this->setDefaultLastValue('groupType', $this->getDefaultEnumValue());
$flags = $this->getFlagFromLastValue($this->getLastValue());
if (!in_array($this->flagName, self::SCOPES)) {
$this->modifyBitmaskValue(
$flags,
$this->options['invert'] ? !$value : $value,
$this->flagName
);
} else {
$this->modifyGroupScopeBit($flags, $value);
}
return $flags->getValue();
} | php | protected function modifyFlagValue($value)
{
$this->setDefaultLastValue('groupType', $this->getDefaultEnumValue());
$flags = $this->getFlagFromLastValue($this->getLastValue());
if (!in_array($this->flagName, self::SCOPES)) {
$this->modifyBitmaskValue(
$flags,
$this->options['invert'] ? !$value : $value,
$this->flagName
);
} else {
$this->modifyGroupScopeBit($flags, $value);
}
return $flags->getValue();
} | [
"protected",
"function",
"modifyFlagValue",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setDefaultLastValue",
"(",
"'groupType'",
",",
"$",
"this",
"->",
"getDefaultEnumValue",
"(",
")",
")",
";",
"$",
"flags",
"=",
"$",
"this",
"->",
"getFlagFromLastVa... | Given a bool value, do the needed bitwise comparison against the groupType value to either remove or
add the bit from the overall value.
@param bool $value
@return int | [
"Given",
"a",
"bool",
"value",
"do",
"the",
"needed",
"bitwise",
"comparison",
"against",
"the",
"groupType",
"value",
"to",
"either",
"remove",
"or",
"add",
"the",
"bit",
"from",
"the",
"overall",
"value",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/AttributeConverter/ConvertGroupType.php#L44-L60 | train |
ldaptools/ldaptools | src/LdapTools/AttributeConverter/ConvertGroupType.php | ConvertGroupType.modifyBitmaskValue | protected function modifyBitmaskValue($flags, $toggle, $flagName)
{
$bit = $this->getBitForAttribute($flagName);
if ($toggle) {
$flags->add($bit);
} else {
$flags->remove($bit);
}
} | php | protected function modifyBitmaskValue($flags, $toggle, $flagName)
{
$bit = $this->getBitForAttribute($flagName);
if ($toggle) {
$flags->add($bit);
} else {
$flags->remove($bit);
}
} | [
"protected",
"function",
"modifyBitmaskValue",
"(",
"$",
"flags",
",",
"$",
"toggle",
",",
"$",
"flagName",
")",
"{",
"$",
"bit",
"=",
"$",
"this",
"->",
"getBitForAttribute",
"(",
"$",
"flagName",
")",
";",
"if",
"(",
"$",
"toggle",
")",
"{",
"$",
"... | Modify the existing value based on the attributes bit.
@param FlagEnumInterface $flags
@param bool $toggle
@param string $flagName | [
"Modify",
"the",
"existing",
"value",
"based",
"on",
"the",
"attributes",
"bit",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/AttributeConverter/ConvertGroupType.php#L92-L101 | train |
ldaptools/ldaptools | src/LdapTools/Resolver/BatchValueResolver.php | BatchValueResolver.batchCanConvert | protected function batchCanConvert(Batch $batch)
{
return ($this->schema->hasConverter($batch->getAttribute()) && !$batch->isTypeRemoveAll());
} | php | protected function batchCanConvert(Batch $batch)
{
return ($this->schema->hasConverter($batch->getAttribute()) && !$batch->isTypeRemoveAll());
} | [
"protected",
"function",
"batchCanConvert",
"(",
"Batch",
"$",
"batch",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"schema",
"->",
"hasConverter",
"(",
"$",
"batch",
"->",
"getAttribute",
"(",
")",
")",
"&&",
"!",
"$",
"batch",
"->",
"isTypeRemoveAll",
... | Determine if a specific batch is correctly formatted and needs conversion.
@param Batch $batch
@return bool | [
"Determine",
"if",
"a",
"specific",
"batch",
"is",
"correctly",
"formatted",
"and",
"needs",
"conversion",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Resolver/BatchValueResolver.php#L81-L84 | train |
ldaptools/ldaptools | src/LdapTools/Resolver/BatchValueResolver.php | BatchValueResolver.getBatchesForAttributes | protected function getBatchesForAttributes(array $attributes)
{
$batches = [];
$lcAttributes = array_map('strtolower', $attributes);
foreach ($this->batches as $index => $batch) {
/** @var Batch $batch */
if (in_array(strtolower($batch->getAttribute()), $lcAttributes)) {
$batches[$index] = $batch;
}
}
return $batches;
} | php | protected function getBatchesForAttributes(array $attributes)
{
$batches = [];
$lcAttributes = array_map('strtolower', $attributes);
foreach ($this->batches as $index => $batch) {
/** @var Batch $batch */
if (in_array(strtolower($batch->getAttribute()), $lcAttributes)) {
$batches[$index] = $batch;
}
}
return $batches;
} | [
"protected",
"function",
"getBatchesForAttributes",
"(",
"array",
"$",
"attributes",
")",
"{",
"$",
"batches",
"=",
"[",
"]",
";",
"$",
"lcAttributes",
"=",
"array_map",
"(",
"'strtolower'",
",",
"$",
"attributes",
")",
";",
"foreach",
"(",
"$",
"this",
"-... | Given an array of attribute names, get all of the batches they have with their respective indexes
@param array $attributes
@return array | [
"Given",
"an",
"array",
"of",
"attribute",
"names",
"get",
"all",
"of",
"the",
"batches",
"they",
"have",
"with",
"their",
"respective",
"indexes"
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Resolver/BatchValueResolver.php#L115-L128 | train |
ldaptools/ldaptools | src/LdapTools/Factory/CacheFactory.php | CacheFactory.get | public static function get($type, array $options)
{
if (self::TYPE_STASH == $type) {
$cache = new StashCache();
} elseif (self::TYPE_DOCTRINE == $type) {
$cache = new DoctrineCache();
} elseif (self::TYPE_NONE == $type) {
$cache = new NoCache();
} else {
throw new InvalidArgumentException(sprintf('Unknown cache type "%s".', $type));
}
$cache->setOptions($options);
return $cache;
} | php | public static function get($type, array $options)
{
if (self::TYPE_STASH == $type) {
$cache = new StashCache();
} elseif (self::TYPE_DOCTRINE == $type) {
$cache = new DoctrineCache();
} elseif (self::TYPE_NONE == $type) {
$cache = new NoCache();
} else {
throw new InvalidArgumentException(sprintf('Unknown cache type "%s".', $type));
}
$cache->setOptions($options);
return $cache;
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"type",
",",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"self",
"::",
"TYPE_STASH",
"==",
"$",
"type",
")",
"{",
"$",
"cache",
"=",
"new",
"StashCache",
"(",
")",
";",
"}",
"elseif",
"(",
"self",
... | Retrieve the Cache object by its configured type and options.
@param $type
@param array $options
@return CacheInterface | [
"Retrieve",
"the",
"Cache",
"object",
"by",
"its",
"configured",
"type",
"and",
"options",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Factory/CacheFactory.php#L48-L62 | train |
ldaptools/ldaptools | src/LdapTools/Utilities/TSProperty.php | TSProperty.getDecodedValueForProp | protected function getDecodedValueForProp($propName, $propValue)
{
if (in_array($propName, $this->propTypes['string'])) {
// Strip away null terminators. I think this should be desired, otherwise it just ends in confusion.
$value = str_replace("\0", '', $this->decodePropValue($propValue, true));
} elseif (in_array($propName, $this->propTypes['time'])) {
// Convert from microseconds to minutes (how ADUC displays it anyway, and seems the most practical).
$value = hexdec($this->decodePropValue($propValue)) / self::TIME_CONVERSION;
} elseif (in_array($propName, $this->propTypes['int'])) {
$value = hexdec($this->decodePropValue($propValue));
} else {
$value = $this->decodePropValue($propValue);
}
return $value;
} | php | protected function getDecodedValueForProp($propName, $propValue)
{
if (in_array($propName, $this->propTypes['string'])) {
// Strip away null terminators. I think this should be desired, otherwise it just ends in confusion.
$value = str_replace("\0", '', $this->decodePropValue($propValue, true));
} elseif (in_array($propName, $this->propTypes['time'])) {
// Convert from microseconds to minutes (how ADUC displays it anyway, and seems the most practical).
$value = hexdec($this->decodePropValue($propValue)) / self::TIME_CONVERSION;
} elseif (in_array($propName, $this->propTypes['int'])) {
$value = hexdec($this->decodePropValue($propValue));
} else {
$value = $this->decodePropValue($propValue);
}
return $value;
} | [
"protected",
"function",
"getDecodedValueForProp",
"(",
"$",
"propName",
",",
"$",
"propValue",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"propName",
",",
"$",
"this",
"->",
"propTypes",
"[",
"'string'",
"]",
")",
")",
"{",
"// Strip away null terminators. I ... | Based on the property name in question, get its actual value from the binary blob value.
@param string $propName
@param string $propValue
@return string|int | [
"Based",
"on",
"the",
"property",
"name",
"in",
"question",
"get",
"its",
"actual",
"value",
"from",
"the",
"binary",
"blob",
"value",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Utilities/TSProperty.php#L210-L225 | train |
ldaptools/ldaptools | src/LdapTools/Utilities/TSProperty.php | TSProperty.nibbleControl | protected function nibbleControl($nibble, $control)
{
// This control stays constant for the low/high nibbles, so it doesn't matter which we compare to
if ($control == self::NIBBLE_CONTROL['X'][1]) {
$dec = bindec($nibble);
$dec += 9;
$nibble = str_pad(decbin($dec), 4, '0', STR_PAD_LEFT);
}
return $nibble;
} | php | protected function nibbleControl($nibble, $control)
{
// This control stays constant for the low/high nibbles, so it doesn't matter which we compare to
if ($control == self::NIBBLE_CONTROL['X'][1]) {
$dec = bindec($nibble);
$dec += 9;
$nibble = str_pad(decbin($dec), 4, '0', STR_PAD_LEFT);
}
return $nibble;
} | [
"protected",
"function",
"nibbleControl",
"(",
"$",
"nibble",
",",
"$",
"control",
")",
"{",
"// This control stays constant for the low/high nibbles, so it doesn't matter which we compare to",
"if",
"(",
"$",
"control",
"==",
"self",
"::",
"NIBBLE_CONTROL",
"[",
"'X'",
"... | Based on the control, adjust the nibble accordingly.
@param string $nibble
@param string $control
@return string | [
"Based",
"on",
"the",
"control",
"adjust",
"the",
"nibble",
"accordingly",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Utilities/TSProperty.php#L322-L332 | train |
ldaptools/ldaptools | src/LdapTools/Object/LdapObjectManager.php | LdapObjectManager.persist | public function persist(LdapObject $ldapObject)
{
if (empty($ldapObject->getBatchCollection()->toArray())) {
return;
}
$this->dispatcher->dispatch(new LdapObjectEvent(Event::LDAP_OBJECT_BEFORE_MODIFY, $ldapObject));
$this->validateObject($ldapObject);
$this->executeBatchOperation($ldapObject);
$this->dispatcher->dispatch(new LdapObjectEvent(Event::LDAP_OBJECT_AFTER_MODIFY, $ldapObject));
} | php | public function persist(LdapObject $ldapObject)
{
if (empty($ldapObject->getBatchCollection()->toArray())) {
return;
}
$this->dispatcher->dispatch(new LdapObjectEvent(Event::LDAP_OBJECT_BEFORE_MODIFY, $ldapObject));
$this->validateObject($ldapObject);
$this->executeBatchOperation($ldapObject);
$this->dispatcher->dispatch(new LdapObjectEvent(Event::LDAP_OBJECT_AFTER_MODIFY, $ldapObject));
} | [
"public",
"function",
"persist",
"(",
"LdapObject",
"$",
"ldapObject",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"ldapObject",
"->",
"getBatchCollection",
"(",
")",
"->",
"toArray",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"dispatc... | Updates an object in LDAP. It will only update attributes that actually changed on the object.
@param LdapObject $ldapObject | [
"Updates",
"an",
"object",
"in",
"LDAP",
".",
"It",
"will",
"only",
"update",
"attributes",
"that",
"actually",
"changed",
"on",
"the",
"object",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Object/LdapObjectManager.php#L74-L85 | train |
ldaptools/ldaptools | src/LdapTools/Object/LdapObjectManager.php | LdapObjectManager.delete | public function delete(LdapObject $ldapObject, $recursively = false)
{
$this->dispatcher->dispatch(new LdapObjectEvent(Event::LDAP_OBJECT_BEFORE_DELETE, $ldapObject));
$this->validateObject($ldapObject);
$operation = new DeleteOperation($ldapObject->get('dn'));
if ($recursively) {
$operation->addControl((new LdapControl(LdapControlOid::SubTreeDelete))->setCriticality(true));
}
$this->connection->execute($operation);
$this->dispatcher->dispatch(new LdapObjectEvent(Event::LDAP_OBJECT_AFTER_DELETE, $ldapObject));
} | php | public function delete(LdapObject $ldapObject, $recursively = false)
{
$this->dispatcher->dispatch(new LdapObjectEvent(Event::LDAP_OBJECT_BEFORE_DELETE, $ldapObject));
$this->validateObject($ldapObject);
$operation = new DeleteOperation($ldapObject->get('dn'));
if ($recursively) {
$operation->addControl((new LdapControl(LdapControlOid::SubTreeDelete))->setCriticality(true));
}
$this->connection->execute($operation);
$this->dispatcher->dispatch(new LdapObjectEvent(Event::LDAP_OBJECT_AFTER_DELETE, $ldapObject));
} | [
"public",
"function",
"delete",
"(",
"LdapObject",
"$",
"ldapObject",
",",
"$",
"recursively",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"new",
"LdapObjectEvent",
"(",
"Event",
"::",
"LDAP_OBJECT_BEFORE_DELETE",
",",
"$",
... | Removes an object from LDAP.
@param LdapObject $ldapObject
@param bool $recursively | [
"Removes",
"an",
"object",
"from",
"LDAP",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Object/LdapObjectManager.php#L93-L105 | train |
ldaptools/ldaptools | src/LdapTools/Object/LdapObjectManager.php | LdapObjectManager.getObjectRestoreLocation | protected function getObjectRestoreLocation(LdapObject $ldapObject, $location)
{
// If a location was defined, use that.
if ($location) {
$newLocation = (string) $location;
// Check the attribute for the last known location first...
} elseif ($ldapObject->has('lastKnownLocation')) {
$newLocation = $ldapObject->get('lastKnownLocation');
// All else failed, so query it from the DN...
} else {
try {
$newLocation = (new LdapQueryBuilder($this->connection, $this->schemaFactory))
->select('lastKnownParent')
->from(LdapObjectType::DELETED)
->where(['dn' => $ldapObject->get('dn')])
->getLdapQuery()
->getSingleScalarOrNullResult();
} catch (Exception $e) {
$newLocation = null;
}
}
// Either this was not a deleted object or it no longer exists?
if (is_null($newLocation)) {
throw new InvalidArgumentException(sprintf(
'No restore location specified and cannot find the last known location for "%s".',
$ldapObject->get('dn')
));
}
return $newLocation;
} | php | protected function getObjectRestoreLocation(LdapObject $ldapObject, $location)
{
// If a location was defined, use that.
if ($location) {
$newLocation = (string) $location;
// Check the attribute for the last known location first...
} elseif ($ldapObject->has('lastKnownLocation')) {
$newLocation = $ldapObject->get('lastKnownLocation');
// All else failed, so query it from the DN...
} else {
try {
$newLocation = (new LdapQueryBuilder($this->connection, $this->schemaFactory))
->select('lastKnownParent')
->from(LdapObjectType::DELETED)
->where(['dn' => $ldapObject->get('dn')])
->getLdapQuery()
->getSingleScalarOrNullResult();
} catch (Exception $e) {
$newLocation = null;
}
}
// Either this was not a deleted object or it no longer exists?
if (is_null($newLocation)) {
throw new InvalidArgumentException(sprintf(
'No restore location specified and cannot find the last known location for "%s".',
$ldapObject->get('dn')
));
}
return $newLocation;
} | [
"protected",
"function",
"getObjectRestoreLocation",
"(",
"LdapObject",
"$",
"ldapObject",
",",
"$",
"location",
")",
"{",
"// If a location was defined, use that.",
"if",
"(",
"$",
"location",
")",
"{",
"$",
"newLocation",
"=",
"(",
"string",
")",
"$",
"location"... | It's possible a new location was not explicitly given and the attribute that contains the last know location
was not queried for when the object was originally found. In that case attempt to retrieve the last known
location from a separate LDAP query.
@param LdapObject $ldapObject
@param string|null $location
@return string | [
"It",
"s",
"possible",
"a",
"new",
"location",
"was",
"not",
"explicitly",
"given",
"and",
"the",
"attribute",
"that",
"contains",
"the",
"last",
"know",
"location",
"was",
"not",
"queried",
"for",
"when",
"the",
"object",
"was",
"originally",
"found",
".",
... | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Object/LdapObjectManager.php#L193-L224 | train |
ldaptools/ldaptools | src/LdapTools/Object/LdapObjectManager.php | LdapObjectManager.hydrateOperation | protected function hydrateOperation(BatchModifyOperation $operation, $type)
{
$this->hydrator->setOperationType(AttributeConverterInterface::TYPE_MODIFY);
$this->hydrator->setLdapObjectSchema($type ? $this->schemaFactory->get($this->connection->getConfig()->getSchemaName(), $type) : null);
$this->hydrator->hydrateToLdap($operation);
$this->hydrator->setLdapObjectSchema(null);
} | php | protected function hydrateOperation(BatchModifyOperation $operation, $type)
{
$this->hydrator->setOperationType(AttributeConverterInterface::TYPE_MODIFY);
$this->hydrator->setLdapObjectSchema($type ? $this->schemaFactory->get($this->connection->getConfig()->getSchemaName(), $type) : null);
$this->hydrator->hydrateToLdap($operation);
$this->hydrator->setLdapObjectSchema(null);
} | [
"protected",
"function",
"hydrateOperation",
"(",
"BatchModifyOperation",
"$",
"operation",
",",
"$",
"type",
")",
"{",
"$",
"this",
"->",
"hydrator",
"->",
"setOperationType",
"(",
"AttributeConverterInterface",
"::",
"TYPE_MODIFY",
")",
";",
"$",
"this",
"->",
... | Get the batch modification array that ldap_modify_batch expects.
@param BatchModifyOperation $operation
@param string $type | [
"Get",
"the",
"batch",
"modification",
"array",
"that",
"ldap_modify_batch",
"expects",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Object/LdapObjectManager.php#L244-L250 | train |
ldaptools/ldaptools | src/LdapTools/Object/LdapObjectManager.php | LdapObjectManager.refreshDnIfNeeded | protected function refreshDnIfNeeded(LdapOperationInterface $operation, LdapObject $ldapObject)
{
foreach ($operation->getPreOperations() as $childOp) {
$this->refreshDnIfNeeded($childOp, $ldapObject);
}
if ($operation instanceof RenameOperation) {
$ldapObject->refresh(['dn' => $this->getNewDnFromOperation($operation, $ldapObject)]);
}
foreach ($operation->getPostOperations() as $childOp) {
$this->refreshDnIfNeeded($childOp, $ldapObject);
}
} | php | protected function refreshDnIfNeeded(LdapOperationInterface $operation, LdapObject $ldapObject)
{
foreach ($operation->getPreOperations() as $childOp) {
$this->refreshDnIfNeeded($childOp, $ldapObject);
}
if ($operation instanceof RenameOperation) {
$ldapObject->refresh(['dn' => $this->getNewDnFromOperation($operation, $ldapObject)]);
}
foreach ($operation->getPostOperations() as $childOp) {
$this->refreshDnIfNeeded($childOp, $ldapObject);
}
} | [
"protected",
"function",
"refreshDnIfNeeded",
"(",
"LdapOperationInterface",
"$",
"operation",
",",
"LdapObject",
"$",
"ldapObject",
")",
"{",
"foreach",
"(",
"$",
"operation",
"->",
"getPreOperations",
"(",
")",
"as",
"$",
"childOp",
")",
"{",
"$",
"this",
"-... | Based on the operation type, refresh the DN if needed. The order is important here. Older 'pre' operations are
refreshed first, then the operation itself, and finally any 'post' operations.
@param LdapOperationInterface $operation
@param LdapObject $ldapObject | [
"Based",
"on",
"the",
"operation",
"type",
"refresh",
"the",
"DN",
"if",
"needed",
".",
"The",
"order",
"is",
"important",
"here",
".",
"Older",
"pre",
"operations",
"are",
"refreshed",
"first",
"then",
"the",
"operation",
"itself",
"and",
"finally",
"any",
... | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Object/LdapObjectManager.php#L259-L272 | train |
ldaptools/ldaptools | src/LdapTools/Operation/LdapOperationTrait.php | LdapOperationTrait.addControl | public function addControl(LdapControl ...$controls)
{
foreach ($controls as $control) {
$this->controls[] = $control;
}
return $this;
} | php | public function addControl(LdapControl ...$controls)
{
foreach ($controls as $control) {
$this->controls[] = $control;
}
return $this;
} | [
"public",
"function",
"addControl",
"(",
"LdapControl",
"...",
"$",
"controls",
")",
"{",
"foreach",
"(",
"$",
"controls",
"as",
"$",
"control",
")",
"{",
"$",
"this",
"->",
"controls",
"[",
"]",
"=",
"$",
"control",
";",
"}",
"return",
"$",
"this",
... | Add a control to the operation.
@param LdapControl[] ...$controls
@return $this | [
"Add",
"a",
"control",
"to",
"the",
"operation",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Operation/LdapOperationTrait.php#L81-L88 | train |
ldaptools/ldaptools | src/LdapTools/Operation/LdapOperationTrait.php | LdapOperationTrait.addPreOperation | public function addPreOperation(LdapOperationInterface ...$operations)
{
foreach ($operations as $operation) {
$this->preOperations[] = $operation;
}
return $this;
} | php | public function addPreOperation(LdapOperationInterface ...$operations)
{
foreach ($operations as $operation) {
$this->preOperations[] = $operation;
}
return $this;
} | [
"public",
"function",
"addPreOperation",
"(",
"LdapOperationInterface",
"...",
"$",
"operations",
")",
"{",
"foreach",
"(",
"$",
"operations",
"as",
"$",
"operation",
")",
"{",
"$",
"this",
"->",
"preOperations",
"[",
"]",
"=",
"$",
"operation",
";",
"}",
... | Add an operation that should be executed before this operation.
@param LdapOperationInterface[] ...$operations
@return $this | [
"Add",
"an",
"operation",
"that",
"should",
"be",
"executed",
"before",
"this",
"operation",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Operation/LdapOperationTrait.php#L96-L103 | train |
ldaptools/ldaptools | src/LdapTools/Operation/LdapOperationTrait.php | LdapOperationTrait.addPostOperation | public function addPostOperation(LdapOperationInterface ...$operations)
{
foreach ($operations as $operation) {
$this->postOperations[] = $operation;
}
return $this;
} | php | public function addPostOperation(LdapOperationInterface ...$operations)
{
foreach ($operations as $operation) {
$this->postOperations[] = $operation;
}
return $this;
} | [
"public",
"function",
"addPostOperation",
"(",
"LdapOperationInterface",
"...",
"$",
"operations",
")",
"{",
"foreach",
"(",
"$",
"operations",
"as",
"$",
"operation",
")",
"{",
"$",
"this",
"->",
"postOperations",
"[",
"]",
"=",
"$",
"operation",
";",
"}",
... | Add an operation that should be executed after this operation.
@param LdapOperationInterface[] ...$operations
@return $this | [
"Add",
"an",
"operation",
"that",
"should",
"be",
"executed",
"after",
"this",
"operation",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Operation/LdapOperationTrait.php#L121-L128 | train |
ldaptools/ldaptools | src/LdapTools/Operation/LdapOperationTrait.php | LdapOperationTrait.mergeLogDefaults | protected function mergeLogDefaults(array $log)
{
$defaults = [];
$controls = [];
if (!empty($this->controls)) {
foreach ($this->controls as $control) {
$controls[] = $control->toArray();
}
}
if ($this instanceof CacheableOperationInterface) {
$defaults['Use Cache'] = var_export($this->getUseCache(), true);
$defaults['Execute on Cache Miss'] = var_export($this->getExecuteOnCacheMiss(), true);
$defaults['Invalidate Cache'] = var_export($this->getInvalidateCache(), true);
}
$defaults['Server'] = $this->server;
$defaults['Controls'] = var_export($controls, true);
return array_merge($log, $defaults);
} | php | protected function mergeLogDefaults(array $log)
{
$defaults = [];
$controls = [];
if (!empty($this->controls)) {
foreach ($this->controls as $control) {
$controls[] = $control->toArray();
}
}
if ($this instanceof CacheableOperationInterface) {
$defaults['Use Cache'] = var_export($this->getUseCache(), true);
$defaults['Execute on Cache Miss'] = var_export($this->getExecuteOnCacheMiss(), true);
$defaults['Invalidate Cache'] = var_export($this->getInvalidateCache(), true);
}
$defaults['Server'] = $this->server;
$defaults['Controls'] = var_export($controls, true);
return array_merge($log, $defaults);
} | [
"protected",
"function",
"mergeLogDefaults",
"(",
"array",
"$",
"log",
")",
"{",
"$",
"defaults",
"=",
"[",
"]",
";",
"$",
"controls",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"controls",
")",
")",
"{",
"foreach",
"(",
... | Merges the log array with common log properties.
@param array $log
@return array | [
"Merges",
"the",
"log",
"array",
"with",
"common",
"log",
"properties",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Operation/LdapOperationTrait.php#L146-L164 | train |
ldaptools/ldaptools | src/LdapTools/Operation/Invoker/LdapOperationInvokerTrait.php | LdapOperationInvokerTrait.logExceptionAndThrow | protected function logExceptionAndThrow($exception, LogOperation $log = null)
{
if ($this->shouldLog($log) && is_null($log->getStartTime())) {
$this->logStart($log);
}
if ($this->shouldLog($log)) {
$log->setError($exception->getMessage());
}
throw $exception;
} | php | protected function logExceptionAndThrow($exception, LogOperation $log = null)
{
if ($this->shouldLog($log) && is_null($log->getStartTime())) {
$this->logStart($log);
}
if ($this->shouldLog($log)) {
$log->setError($exception->getMessage());
}
throw $exception;
} | [
"protected",
"function",
"logExceptionAndThrow",
"(",
"$",
"exception",
",",
"LogOperation",
"$",
"log",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"shouldLog",
"(",
"$",
"log",
")",
"&&",
"is_null",
"(",
"$",
"log",
"->",
"getStartTime",
"(",
... | Handles exception error message logging if logging is enabled then re-throws the exception.
@param LogOperation|null $log
@param \Throwable|\Exception $exception
@throws \LdapTools\Exception\LdapConnectionException | [
"Handles",
"exception",
"error",
"message",
"logging",
"if",
"logging",
"is",
"enabled",
"then",
"re",
"-",
"throws",
"the",
"exception",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Operation/Invoker/LdapOperationInvokerTrait.php#L99-L109 | train |
ldaptools/ldaptools | src/LdapTools/Operation/Invoker/LdapOperationInvokerTrait.php | LdapOperationInvokerTrait.logStart | protected function logStart(LogOperation $log = null)
{
if ($this->shouldLog($log)) {
$this->logger->start($log->start());
}
} | php | protected function logStart(LogOperation $log = null)
{
if ($this->shouldLog($log)) {
$this->logger->start($log->start());
}
} | [
"protected",
"function",
"logStart",
"(",
"LogOperation",
"$",
"log",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"shouldLog",
"(",
"$",
"log",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"start",
"(",
"$",
"log",
"->",
"start",
"(",... | Start a logging operation.
@param LogOperation|null $log | [
"Start",
"a",
"logging",
"operation",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Operation/Invoker/LdapOperationInvokerTrait.php#L116-L121 | train |
ldaptools/ldaptools | src/LdapTools/Operation/Invoker/LdapOperationInvokerTrait.php | LdapOperationInvokerTrait.logEnd | protected function logEnd(LogOperation $log = null)
{
if ($this->shouldLog($log)) {
$this->logger->end($log->stop());
}
} | php | protected function logEnd(LogOperation $log = null)
{
if ($this->shouldLog($log)) {
$this->logger->end($log->stop());
}
} | [
"protected",
"function",
"logEnd",
"(",
"LogOperation",
"$",
"log",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"shouldLog",
"(",
"$",
"log",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"end",
"(",
"$",
"log",
"->",
"stop",
"(",
")... | End a logging operation.
@param LogOperation|null $log | [
"End",
"a",
"logging",
"operation",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Operation/Invoker/LdapOperationInvokerTrait.php#L128-L133 | train |
Laralum/Laralum | src/Controllers/LoginController.php | LoginController.login | public function login(Request $request)
{
$this->validate($request, [
'email' => 'required|max:255',
'password' => 'required|max:255',
]);
if (Auth::attempt(['email' => $request->email, 'password' => $request->password], $request->remember ? true : false)) {
return redirect()->intended(route('laralum::index'));
}
return redirect()->route('laralum::login')->with('error', trans('auth.failed'))->withInput();
} | php | public function login(Request $request)
{
$this->validate($request, [
'email' => 'required|max:255',
'password' => 'required|max:255',
]);
if (Auth::attempt(['email' => $request->email, 'password' => $request->password], $request->remember ? true : false)) {
return redirect()->intended(route('laralum::index'));
}
return redirect()->route('laralum::login')->with('error', trans('auth.failed'))->withInput();
} | [
"public",
"function",
"login",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"validate",
"(",
"$",
"request",
",",
"[",
"'email'",
"=>",
"'required|max:255'",
",",
"'password'",
"=>",
"'required|max:255'",
",",
"]",
")",
";",
"if",
"(",
"A... | Manual user login.
@param $request | [
"Manual",
"user",
"login",
"."
] | 6f13eec2c898bcc523fb6c19bc78146b9898e689 | https://github.com/Laralum/Laralum/blob/6f13eec2c898bcc523fb6c19bc78146b9898e689/src/Controllers/LoginController.php#L29-L41 | train |
Laralum/Laralum | src/Injector.php | Injector.inject | public static function inject($injector, $package)
{
$dir = __DIR__."/../../$package/src/Injectors";
$files = is_dir($dir) ? scandir($dir) : [];
foreach ($files as $file) {
if (substr($file, 0, -4) == $injector and substr($file, -4) == '.php') {
$file = $dir.'/'.$file;
return include $file;
}
}
return '';
} | php | public static function inject($injector, $package)
{
$dir = __DIR__."/../../$package/src/Injectors";
$files = is_dir($dir) ? scandir($dir) : [];
foreach ($files as $file) {
if (substr($file, 0, -4) == $injector and substr($file, -4) == '.php') {
$file = $dir.'/'.$file;
return include $file;
}
}
return '';
} | [
"public",
"static",
"function",
"inject",
"(",
"$",
"injector",
",",
"$",
"package",
")",
"{",
"$",
"dir",
"=",
"__DIR__",
".",
"\"/../../$package/src/Injectors\"",
";",
"$",
"files",
"=",
"is_dir",
"(",
"$",
"dir",
")",
"?",
"scandir",
"(",
"$",
"dir",
... | Returns the injection of the specified injector and package.
@param string $package | [
"Returns",
"the",
"injection",
"of",
"the",
"specified",
"injector",
"and",
"package",
"."
] | 6f13eec2c898bcc523fb6c19bc78146b9898e689 | https://github.com/Laralum/Laralum/blob/6f13eec2c898bcc523fb6c19bc78146b9898e689/src/Injector.php#L28-L42 | train |
Laralum/Laralum | src/Packages.php | Packages.get | public static function get()
{
// Check for Laralum packages
$packages = [];
$location = __DIR__.'/../../';
$files = is_dir($location) ? scandir($location) : [];
foreach ($files as $package) {
if ($package != '.' and $package != '..' and ucfirst($package) != 'Laralum') {
array_push($packages, strtolower($package));
}
}
return $packages;
} | php | public static function get()
{
// Check for Laralum packages
$packages = [];
$location = __DIR__.'/../../';
$files = is_dir($location) ? scandir($location) : [];
foreach ($files as $package) {
if ($package != '.' and $package != '..' and ucfirst($package) != 'Laralum') {
array_push($packages, strtolower($package));
}
}
return $packages;
} | [
"public",
"static",
"function",
"get",
"(",
")",
"{",
"// Check for Laralum packages",
"$",
"packages",
"=",
"[",
"]",
";",
"$",
"location",
"=",
"__DIR__",
".",
"'/../../'",
";",
"$",
"files",
"=",
"is_dir",
"(",
"$",
"location",
")",
"?",
"scandir",
"(... | Returns an array of all the installed packages. | [
"Returns",
"an",
"array",
"of",
"all",
"the",
"installed",
"packages",
"."
] | 6f13eec2c898bcc523fb6c19bc78146b9898e689 | https://github.com/Laralum/Laralum/blob/6f13eec2c898bcc523fb6c19bc78146b9898e689/src/Packages.php#L26-L41 | train |
Laralum/Laralum | src/Packages.php | Packages.provider | public static function provider($package)
{
$location = __DIR__.'/../../'.$package.'/src';
$files = is_dir($location) ? scandir($location) : [];
foreach ($files as $file) {
if (strpos($file, 'ServiceProvider') !== false) {
return str_replace('.php', '', $file);
}
}
return false;
} | php | public static function provider($package)
{
$location = __DIR__.'/../../'.$package.'/src';
$files = is_dir($location) ? scandir($location) : [];
foreach ($files as $file) {
if (strpos($file, 'ServiceProvider') !== false) {
return str_replace('.php', '', $file);
}
}
return false;
} | [
"public",
"static",
"function",
"provider",
"(",
"$",
"package",
")",
"{",
"$",
"location",
"=",
"__DIR__",
".",
"'/../../'",
".",
"$",
"package",
".",
"'/src'",
";",
"$",
"files",
"=",
"is_dir",
"(",
"$",
"location",
")",
"?",
"scandir",
"(",
"$",
"... | Returns the package service provider if exists.
@param string $package | [
"Returns",
"the",
"package",
"service",
"provider",
"if",
"exists",
"."
] | 6f13eec2c898bcc523fb6c19bc78146b9898e689 | https://github.com/Laralum/Laralum/blob/6f13eec2c898bcc523fb6c19bc78146b9898e689/src/Packages.php#L48-L61 | train |
Laralum/Laralum | src/Packages.php | Packages.menu | public static function menu($package)
{
$dir = __DIR__.'/../../'.$package.'/src';
$files = is_dir($dir) ? scandir($dir) : [];
foreach ($files as $file) {
if ($file == 'Menu.json') {
$file_r = file_get_contents($dir.'/'.$file);
return json_decode($file_r, true);
}
}
return [];
} | php | public static function menu($package)
{
$dir = __DIR__.'/../../'.$package.'/src';
$files = is_dir($dir) ? scandir($dir) : [];
foreach ($files as $file) {
if ($file == 'Menu.json') {
$file_r = file_get_contents($dir.'/'.$file);
return json_decode($file_r, true);
}
}
return [];
} | [
"public",
"static",
"function",
"menu",
"(",
"$",
"package",
")",
"{",
"$",
"dir",
"=",
"__DIR__",
".",
"'/../../'",
".",
"$",
"package",
".",
"'/src'",
";",
"$",
"files",
"=",
"is_dir",
"(",
"$",
"dir",
")",
"?",
"scandir",
"(",
"$",
"dir",
")",
... | Returns the package menu if exists.
@param string $package | [
"Returns",
"the",
"package",
"menu",
"if",
"exists",
"."
] | 6f13eec2c898bcc523fb6c19bc78146b9898e689 | https://github.com/Laralum/Laralum/blob/6f13eec2c898bcc523fb6c19bc78146b9898e689/src/Packages.php#L78-L92 | train |
Laralum/Laralum | src/Packages.php | Packages.all | public static function all()
{
$preference = collect(['laralum', 'dashboard', 'users', 'roles', 'permissions']);
collect(static::get())->each(function ($package) use ($preference) {
if (!$preference->contains($package)) {
$preference->push($package);
}
});
return $preference->toArray();
} | php | public static function all()
{
$preference = collect(['laralum', 'dashboard', 'users', 'roles', 'permissions']);
collect(static::get())->each(function ($package) use ($preference) {
if (!$preference->contains($package)) {
$preference->push($package);
}
});
return $preference->toArray();
} | [
"public",
"static",
"function",
"all",
"(",
")",
"{",
"$",
"preference",
"=",
"collect",
"(",
"[",
"'laralum'",
",",
"'dashboard'",
",",
"'users'",
",",
"'roles'",
",",
"'permissions'",
"]",
")",
";",
"collect",
"(",
"static",
"::",
"get",
"(",
")",
")... | Gets all packages and orders them by preference.
@return array | [
"Gets",
"all",
"packages",
"and",
"orders",
"them",
"by",
"preference",
"."
] | 6f13eec2c898bcc523fb6c19bc78146b9898e689 | https://github.com/Laralum/Laralum/blob/6f13eec2c898bcc523fb6c19bc78146b9898e689/src/Packages.php#L99-L110 | train |
Laralum/Laralum | src/Menu.php | Menu.getCustomMenuItems | public static function getCustomMenuItems($user)
{
$menuItems = [];
if (array_key_exists('menu', config('laralum'))) {
foreach (config('laralum.menu') as $custom_menu) {
$pm = new self();
$pm->name(ucfirst($custom_menu['title']));
$pm->items = array_merge($pm->items, static::getPackageMenuItems($custom_menu, $user));
if (count($pm->items) > 0) {
array_push($menuItems, $pm);
}
}
}
return $menuItems;
} | php | public static function getCustomMenuItems($user)
{
$menuItems = [];
if (array_key_exists('menu', config('laralum'))) {
foreach (config('laralum.menu') as $custom_menu) {
$pm = new self();
$pm->name(ucfirst($custom_menu['title']));
$pm->items = array_merge($pm->items, static::getPackageMenuItems($custom_menu, $user));
if (count($pm->items) > 0) {
array_push($menuItems, $pm);
}
}
}
return $menuItems;
} | [
"public",
"static",
"function",
"getCustomMenuItems",
"(",
"$",
"user",
")",
"{",
"$",
"menuItems",
"=",
"[",
"]",
";",
"if",
"(",
"array_key_exists",
"(",
"'menu'",
",",
"config",
"(",
"'laralum'",
")",
")",
")",
"{",
"foreach",
"(",
"config",
"(",
"'... | Get custom menus defined in the laralum config.
@return [type] [description] | [
"Get",
"custom",
"menus",
"defined",
"in",
"the",
"laralum",
"config",
"."
] | 6f13eec2c898bcc523fb6c19bc78146b9898e689 | https://github.com/Laralum/Laralum/blob/6f13eec2c898bcc523fb6c19bc78146b9898e689/src/Menu.php#L89-L106 | train |
Laralum/Laralum | src/Menu.php | Menu.getPackageMenuItems | public static function getPackageMenuItems($menu, $user)
{
$packageItems = [];
foreach ($menu['items'] as $i) {
$item = new Item();
$item->text = array_key_exists('trans', $i) ? __($i['trans']) : $i['text'];
$item->url = array_key_exists('route', $i) ? route($i['route']) : url($i['link']);
if (array_key_exists('permission', $i) && !$user->superAdmin()) {
if (!$user->hasPermission($i['permission'])) {
continue;
}
}
array_push($packageItems, $item);
}
return $packageItems;
} | php | public static function getPackageMenuItems($menu, $user)
{
$packageItems = [];
foreach ($menu['items'] as $i) {
$item = new Item();
$item->text = array_key_exists('trans', $i) ? __($i['trans']) : $i['text'];
$item->url = array_key_exists('route', $i) ? route($i['route']) : url($i['link']);
if (array_key_exists('permission', $i) && !$user->superAdmin()) {
if (!$user->hasPermission($i['permission'])) {
continue;
}
}
array_push($packageItems, $item);
}
return $packageItems;
} | [
"public",
"static",
"function",
"getPackageMenuItems",
"(",
"$",
"menu",
",",
"$",
"user",
")",
"{",
"$",
"packageItems",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"menu",
"[",
"'items'",
"]",
"as",
"$",
"i",
")",
"{",
"$",
"item",
"=",
"new",
"Item... | Get package menu Items.
@param [type] $packageMenu [description]
@param [type] $items [description]
@return [type] [description] | [
"Get",
"package",
"menu",
"Items",
"."
] | 6f13eec2c898bcc523fb6c19bc78146b9898e689 | https://github.com/Laralum/Laralum/blob/6f13eec2c898bcc523fb6c19bc78146b9898e689/src/Menu.php#L116-L135 | train |
quazardous/ImageStack | src/ImageStack/ImageManipulator/OptimizerImageManipulator.php | OptimizerImageManipulator.registerImageOptimizer | public function registerImageOptimizer(ImageOptimizerInterface $imageOptimizer)
{
foreach ($imageOptimizer->getSupportedMimeTypes() as $mimeType) {
$this->imageOptimizers[$mimeType][] = $imageOptimizer;
}
} | php | public function registerImageOptimizer(ImageOptimizerInterface $imageOptimizer)
{
foreach ($imageOptimizer->getSupportedMimeTypes() as $mimeType) {
$this->imageOptimizers[$mimeType][] = $imageOptimizer;
}
} | [
"public",
"function",
"registerImageOptimizer",
"(",
"ImageOptimizerInterface",
"$",
"imageOptimizer",
")",
"{",
"foreach",
"(",
"$",
"imageOptimizer",
"->",
"getSupportedMimeTypes",
"(",
")",
"as",
"$",
"mimeType",
")",
"{",
"$",
"this",
"->",
"imageOptimizers",
... | Register an image optimizer.
@param string $mimeType
@param ImageOptimizerInterface $imageOptimizer | [
"Register",
"an",
"image",
"optimizer",
"."
] | bca5632edfc7703300407984bbaefb3c91c1560c | https://github.com/quazardous/ImageStack/blob/bca5632edfc7703300407984bbaefb3c91c1560c/src/ImageStack/ImageManipulator/OptimizerImageManipulator.php#L36-L41 | train |
peakphp/framework | src/Backpack/Bootstrap/Routing.php | Routing.boot | public function boot()
{
if ($this->app->getProps() === null) {
return;
}
$routes = [];
$pathPrefix = $this->app->getProp($this->routesPathPrefixPropName, '');
$propRoutes = $this->app->getProp($this->routesPropName, []);
if (!is_array($propRoutes)) {
throw new \Exception('Routes definitions must be an array!');
}
foreach ($this->app->getProp($this->routesPropName, []) as $route) {
$this->validate($route);
$routes[] = $this->app->createRoute(
$route['method'] ?? null,
$pathPrefix.$route['path'],
$route['stack']
);
}
$this->app->stack($routes);
} | php | public function boot()
{
if ($this->app->getProps() === null) {
return;
}
$routes = [];
$pathPrefix = $this->app->getProp($this->routesPathPrefixPropName, '');
$propRoutes = $this->app->getProp($this->routesPropName, []);
if (!is_array($propRoutes)) {
throw new \Exception('Routes definitions must be an array!');
}
foreach ($this->app->getProp($this->routesPropName, []) as $route) {
$this->validate($route);
$routes[] = $this->app->createRoute(
$route['method'] ?? null,
$pathPrefix.$route['path'],
$route['stack']
);
}
$this->app->stack($routes);
} | [
"public",
"function",
"boot",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"app",
"->",
"getProps",
"(",
")",
"===",
"null",
")",
"{",
"return",
";",
"}",
"$",
"routes",
"=",
"[",
"]",
";",
"$",
"pathPrefix",
"=",
"$",
"this",
"->",
"app",
"->"... | Look for routes to register in application properties
@throws \Exception | [
"Look",
"for",
"routes",
"to",
"register",
"in",
"application",
"properties"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Backpack/Bootstrap/Routing.php#L49-L73 | train |
milejko/mmi | src/Mmi/Navigation/Navigation.php | Navigation._setupBreadcrumbs | private function _setupBreadcrumbs($tree)
{
//iteracja po drzewie
foreach ($tree as $item) {
//jeśli nieaktywny przechodzi do następnego
if (!$item['active']) {
continue;
}
$this->_breadcrumbs[] = $item;
//jeśli dzieci
if (isset($item['children'])) {
//zejście rekurencyjne
$this->_setupBreadcrumbs($item['children']);
}
//optymalizacja wydajności
break;
}
//brak breadcrumbs
if (count($this->_breadcrumbs) == 0) {
return;
}
//ostatni item
$currentItem = $this->_breadcrumbs[count($this->_breadcrumbs) - 1];
//jeśli jest niezależny kasujemy wszystko poza nim
if (isset($currentItem['independent']) && $currentItem['independent']) {
$this->_breadcrumbs = [$this->_breadcrumbs[count($this->_breadcrumbs) - 1]];
}
} | php | private function _setupBreadcrumbs($tree)
{
//iteracja po drzewie
foreach ($tree as $item) {
//jeśli nieaktywny przechodzi do następnego
if (!$item['active']) {
continue;
}
$this->_breadcrumbs[] = $item;
//jeśli dzieci
if (isset($item['children'])) {
//zejście rekurencyjne
$this->_setupBreadcrumbs($item['children']);
}
//optymalizacja wydajności
break;
}
//brak breadcrumbs
if (count($this->_breadcrumbs) == 0) {
return;
}
//ostatni item
$currentItem = $this->_breadcrumbs[count($this->_breadcrumbs) - 1];
//jeśli jest niezależny kasujemy wszystko poza nim
if (isset($currentItem['independent']) && $currentItem['independent']) {
$this->_breadcrumbs = [$this->_breadcrumbs[count($this->_breadcrumbs) - 1]];
}
} | [
"private",
"function",
"_setupBreadcrumbs",
"(",
"$",
"tree",
")",
"{",
"//iteracja po drzewie",
"foreach",
"(",
"$",
"tree",
"as",
"$",
"item",
")",
"{",
"//jeśli nieaktywny przechodzi do następnego",
"if",
"(",
"!",
"$",
"item",
"[",
"'active'",
"]",
")",
"{... | Buduje breadcrumbs z aktywowanego drzewa
@param array $tree drzewo | [
"Buduje",
"breadcrumbs",
"z",
"aktywowanego",
"drzewa"
] | c1e8dddf83665ad3463ff801074aa2b0875db19b | https://github.com/milejko/mmi/blob/c1e8dddf83665ad3463ff801074aa2b0875db19b/src/Mmi/Navigation/Navigation.php#L127-L154 | train |
honeybee/honeybee | src/Infrastructure/DataAccess/Connector/RabbitMqConnector.php | RabbitMqConnector.getStatus | public function getStatus()
{
if ($this->config->has('fake_status')) {
return new Status($this, $this->config->get('fake_status'));
}
try {
$conn = $this->getFreshConnection();
$conn->reconnect();
$info = $conn->getServerProperties();
return Status::working($this, [
'message' => 'Could reconnect to rabbitmq server.',
'server_properties' => $info
]);
} catch (Exception $e) {
error_log(
'[' . static::CLASS . '] Error on status check: ' . $e->getMessage() . "\n" . $e->getTraceAsString()
);
return Status::failing($this, [ 'error' => $e->getMessage() ]);
}
} | php | public function getStatus()
{
if ($this->config->has('fake_status')) {
return new Status($this, $this->config->get('fake_status'));
}
try {
$conn = $this->getFreshConnection();
$conn->reconnect();
$info = $conn->getServerProperties();
return Status::working($this, [
'message' => 'Could reconnect to rabbitmq server.',
'server_properties' => $info
]);
} catch (Exception $e) {
error_log(
'[' . static::CLASS . '] Error on status check: ' . $e->getMessage() . "\n" . $e->getTraceAsString()
);
return Status::failing($this, [ 'error' => $e->getMessage() ]);
}
} | [
"public",
"function",
"getStatus",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"has",
"(",
"'fake_status'",
")",
")",
"{",
"return",
"new",
"Status",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'fake_status... | Tries to connect to rabbitmq server and get the server properties.
@return Status of this connector | [
"Tries",
"to",
"connect",
"to",
"rabbitmq",
"server",
"and",
"get",
"the",
"server",
"properties",
"."
] | 6e46b4f20a0b8a3ce686565440f739960e325a05 | https://github.com/honeybee/honeybee/blob/6e46b4f20a0b8a3ce686565440f739960e325a05/src/Infrastructure/DataAccess/Connector/RabbitMqConnector.php#L142-L162 | train |
milejko/mmi | src/Mmi/Mvc/ViewHelper/HeadMeta.php | HeadMeta.openGraph | public function openGraph($property, $content, $replace = false, $conditional = '')
{
return $this->headMeta(['property' => $property, 'content' => $content], $replace, $conditional);
} | php | public function openGraph($property, $content, $replace = false, $conditional = '')
{
return $this->headMeta(['property' => $property, 'content' => $content], $replace, $conditional);
} | [
"public",
"function",
"openGraph",
"(",
"$",
"property",
",",
"$",
"content",
",",
"$",
"replace",
"=",
"false",
",",
"$",
"conditional",
"=",
"''",
")",
"{",
"return",
"$",
"this",
"->",
"headMeta",
"(",
"[",
"'property'",
"=>",
"$",
"property",
",",
... | Dodaje znacznik dla Open Graph
@param string $property nazwa właściwości, np. og:image
@param string $content zawartość
@param boolean $replace nadpisz definicję dla klucza
@param string $conditional warunek np. ie6
@return \Mmi\Mvc\ViewHelper\HeadMeta | [
"Dodaje",
"znacznik",
"dla",
"Open",
"Graph"
] | c1e8dddf83665ad3463ff801074aa2b0875db19b | https://github.com/milejko/mmi/blob/c1e8dddf83665ad3463ff801074aa2b0875db19b/src/Mmi/Mvc/ViewHelper/HeadMeta.php#L52-L55 | train |
milejko/mmi | src/Mmi/Validator/EmailAddressList.php | EmailAddressList.isValid | public function isValid($value)
{
$emails = explode(((false !== strpos($value, ',')) ? ',' : ';'), $value);
//iteracja po mailach
foreach ($emails as $email) {
//niepoprawny email
if (!(new EmailAddress)->isValid($email)) {
return $this->_error(self::INVALID);
}
}
return true;
} | php | public function isValid($value)
{
$emails = explode(((false !== strpos($value, ',')) ? ',' : ';'), $value);
//iteracja po mailach
foreach ($emails as $email) {
//niepoprawny email
if (!(new EmailAddress)->isValid($email)) {
return $this->_error(self::INVALID);
}
}
return true;
} | [
"public",
"function",
"isValid",
"(",
"$",
"value",
")",
"{",
"$",
"emails",
"=",
"explode",
"(",
"(",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"value",
",",
"','",
")",
")",
"?",
"','",
":",
"';'",
")",
",",
"$",
"value",
")",
";",
"//iteracja p... | Sprawdza czy tekst jest e-mailem
@param string $value
@return boolean | [
"Sprawdza",
"czy",
"tekst",
"jest",
"e",
"-",
"mailem"
] | c1e8dddf83665ad3463ff801074aa2b0875db19b | https://github.com/milejko/mmi/blob/c1e8dddf83665ad3463ff801074aa2b0875db19b/src/Mmi/Validator/EmailAddressList.php#L29-L40 | train |
peakphp/framework | src/Http/Request/RouteExpression.php | RouteExpression.compile | private function compile()
{
// replace pseudo {param}:type syntax to valid regex
if (strpos($this->regex, '}:') !== false) {
$this->regex = preg_replace('#\{([a-zA-Z0-9_-]+)\}:([a-z]+)#', '(?P<$1>:$2)', $this->expression);
$this->regex = str_replace(
array_keys($this->regexExpression),
array_values($this->regexExpression),
$this->regex
);
}
// replace pseudo {param} syntax without type to valid regex
if (strpos($this->regex, '}') !== false) {
$this->regex = preg_replace('#\{([a-zA-Z_]+)\}#', '(?P<$1>[^\/]+)', $this->regex);
}
// allow optional trailing slash at the end
if (substr($this->regex, -1) !== '/') {
$this->regex .= '[\/]?';
}
} | php | private function compile()
{
// replace pseudo {param}:type syntax to valid regex
if (strpos($this->regex, '}:') !== false) {
$this->regex = preg_replace('#\{([a-zA-Z0-9_-]+)\}:([a-z]+)#', '(?P<$1>:$2)', $this->expression);
$this->regex = str_replace(
array_keys($this->regexExpression),
array_values($this->regexExpression),
$this->regex
);
}
// replace pseudo {param} syntax without type to valid regex
if (strpos($this->regex, '}') !== false) {
$this->regex = preg_replace('#\{([a-zA-Z_]+)\}#', '(?P<$1>[^\/]+)', $this->regex);
}
// allow optional trailing slash at the end
if (substr($this->regex, -1) !== '/') {
$this->regex .= '[\/]?';
}
} | [
"private",
"function",
"compile",
"(",
")",
"{",
"// replace pseudo {param}:type syntax to valid regex",
"if",
"(",
"strpos",
"(",
"$",
"this",
"->",
"regex",
",",
"'}:'",
")",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"regex",
"=",
"preg_replace",
"(",
"... | Compile expression to valid regex | [
"Compile",
"expression",
"to",
"valid",
"regex"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Http/Request/RouteExpression.php#L77-L98 | train |
milejko/mmi | src/Mmi/Mvc/ActionHelper.php | ActionHelper._checkAcl | private function _checkAcl(Request $request)
{
//brak acl lub brak auth lub dozwolone acl
return !$this->_acl || !$this->_auth || $this->_acl->isAllowed($this->_auth->getRoles(), $request->getAsColonSeparatedString());
} | php | private function _checkAcl(Request $request)
{
//brak acl lub brak auth lub dozwolone acl
return !$this->_acl || !$this->_auth || $this->_acl->isAllowed($this->_auth->getRoles(), $request->getAsColonSeparatedString());
} | [
"private",
"function",
"_checkAcl",
"(",
"Request",
"$",
"request",
")",
"{",
"//brak acl lub brak auth lub dozwolone acl",
"return",
"!",
"$",
"this",
"->",
"_acl",
"||",
"!",
"$",
"this",
"->",
"_auth",
"||",
"$",
"this",
"->",
"_acl",
"->",
"isAllowed",
"... | Sprawdza uprawnienie do widgetu
@param \Mmi\Http\Request $request
@return boolean | [
"Sprawdza",
"uprawnienie",
"do",
"widgetu"
] | c1e8dddf83665ad3463ff801074aa2b0875db19b | https://github.com/milejko/mmi/blob/c1e8dddf83665ad3463ff801074aa2b0875db19b/src/Mmi/Mvc/ActionHelper.php#L160-L164 | train |
quazardous/ImageStack | src/ImageStack/Cache/RawFileCache.php | RawFileCache.assertValidId | protected function assertValidId($id)
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$bad = preg_match('/[\x00-\x1F\x7F]\<\>\:\"\|\?\*]/', $id);
} else {
$bad = preg_match('/\x00/', $id);
}
if ($bad) {
throw new RawFileCacheException('Invalid character found in cache ID', RawFileCacheException::INVALID_CHARACTER);
}
} | php | protected function assertValidId($id)
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$bad = preg_match('/[\x00-\x1F\x7F]\<\>\:\"\|\?\*]/', $id);
} else {
$bad = preg_match('/\x00/', $id);
}
if ($bad) {
throw new RawFileCacheException('Invalid character found in cache ID', RawFileCacheException::INVALID_CHARACTER);
}
} | [
"protected",
"function",
"assertValidId",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"defined",
"(",
"'PHP_WINDOWS_VERSION_BUILD'",
")",
")",
"{",
"$",
"bad",
"=",
"preg_match",
"(",
"'/[\\x00-\\x1F\\x7F]\\<\\>\\:\\\"\\|\\?\\*]/'",
",",
"$",
"id",
")",
";",
"}",
"el... | Assert that cache ID is usable as file path.
@param string $id
@throws \InvalidArgumentException | [
"Assert",
"that",
"cache",
"ID",
"is",
"usable",
"as",
"file",
"path",
"."
] | bca5632edfc7703300407984bbaefb3c91c1560c | https://github.com/quazardous/ImageStack/blob/bca5632edfc7703300407984bbaefb3c91c1560c/src/ImageStack/Cache/RawFileCache.php#L157-L167 | train |
quazardous/ImageStack | src/ImageStack/Cache/RawFileCache.php | RawFileCache.getFilename | protected function getFilename($id, $metadata = false)
{
$this->assertValidId($id);
$path = rtrim(dirname($id), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
if ($level = $this->getOption('hash_tree', 0)) {
$level = min(32, $level);
$md5 = md5($id);
for ($i = 0; $i < $level; ++$i) {
$path .= $md5[$i] . DIRECTORY_SEPARATOR;
}
}
$path .= basename($id);
if ($metadata) {
$root = $this->getOption('metadata_root', $this->getOption('root') . DIRECTORY_SEPARATOR . '.cache_metadata');
} else {
$root = $this->getOption('root');
}
return rtrim(sanitize_path($root . DIRECTORY_SEPARATOR . $path), DIRECTORY_SEPARATOR);
} | php | protected function getFilename($id, $metadata = false)
{
$this->assertValidId($id);
$path = rtrim(dirname($id), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
if ($level = $this->getOption('hash_tree', 0)) {
$level = min(32, $level);
$md5 = md5($id);
for ($i = 0; $i < $level; ++$i) {
$path .= $md5[$i] . DIRECTORY_SEPARATOR;
}
}
$path .= basename($id);
if ($metadata) {
$root = $this->getOption('metadata_root', $this->getOption('root') . DIRECTORY_SEPARATOR . '.cache_metadata');
} else {
$root = $this->getOption('root');
}
return rtrim(sanitize_path($root . DIRECTORY_SEPARATOR . $path), DIRECTORY_SEPARATOR);
} | [
"protected",
"function",
"getFilename",
"(",
"$",
"id",
",",
"$",
"metadata",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"assertValidId",
"(",
"$",
"id",
")",
";",
"$",
"path",
"=",
"rtrim",
"(",
"dirname",
"(",
"$",
"id",
")",
",",
"DIRECTORY_SEPARA... | Get the filename for the given ID.
@param string $id
@param string $metadata get the metadata filename
@return string | [
"Get",
"the",
"filename",
"for",
"the",
"given",
"ID",
"."
] | bca5632edfc7703300407984bbaefb3c91c1560c | https://github.com/quazardous/ImageStack/blob/bca5632edfc7703300407984bbaefb3c91c1560c/src/ImageStack/Cache/RawFileCache.php#L175-L193 | train |
quazardous/ImageStack | src/ImageStack/Cache/RawFileCache.php | RawFileCache.writeMetadata | protected function writeMetadata($id, array $metadata)
{
$filename = $this->getFilename($id, true);
$this->assertDirectory($filename);
$this->assertFile($filename);
if (false === file_put_contents($filename, serialize($metadata))) {
throw new RawFileCacheException(sprintf('Cannot write file : %s', $filename), RawFileCacheException::CANNOT_WRITE_FILE);
}
} | php | protected function writeMetadata($id, array $metadata)
{
$filename = $this->getFilename($id, true);
$this->assertDirectory($filename);
$this->assertFile($filename);
if (false === file_put_contents($filename, serialize($metadata))) {
throw new RawFileCacheException(sprintf('Cannot write file : %s', $filename), RawFileCacheException::CANNOT_WRITE_FILE);
}
} | [
"protected",
"function",
"writeMetadata",
"(",
"$",
"id",
",",
"array",
"$",
"metadata",
")",
"{",
"$",
"filename",
"=",
"$",
"this",
"->",
"getFilename",
"(",
"$",
"id",
",",
"true",
")",
";",
"$",
"this",
"->",
"assertDirectory",
"(",
"$",
"filename"... | Read metadata.
@param string $id
@param array $metadata
@throws RawFileCacheException | [
"Read",
"metadata",
"."
] | bca5632edfc7703300407984bbaefb3c91c1560c | https://github.com/quazardous/ImageStack/blob/bca5632edfc7703300407984bbaefb3c91c1560c/src/ImageStack/Cache/RawFileCache.php#L201-L209 | train |
quazardous/ImageStack | src/ImageStack/Cache/RawFileCache.php | RawFileCache.readMetadata | protected function readMetadata($id)
{
$filename = $this->getFilename($id, true);
$this->assertFile($filename);
if (is_file($filename)) {
if (false === ($data = file_get_contents($filename))) {
throw new RawFileCacheException(sprintf('Cannot read file : %s', $filename), RawFileCacheException::CANNOT_READ_FILE);
}
return (array)unserialize($data);
}
return [];
} | php | protected function readMetadata($id)
{
$filename = $this->getFilename($id, true);
$this->assertFile($filename);
if (is_file($filename)) {
if (false === ($data = file_get_contents($filename))) {
throw new RawFileCacheException(sprintf('Cannot read file : %s', $filename), RawFileCacheException::CANNOT_READ_FILE);
}
return (array)unserialize($data);
}
return [];
} | [
"protected",
"function",
"readMetadata",
"(",
"$",
"id",
")",
"{",
"$",
"filename",
"=",
"$",
"this",
"->",
"getFilename",
"(",
"$",
"id",
",",
"true",
")",
";",
"$",
"this",
"->",
"assertFile",
"(",
"$",
"filename",
")",
";",
"if",
"(",
"is_file",
... | Write metadata.
@param string $id
@throws RawFileCacheException
@return array | [
"Write",
"metadata",
"."
] | bca5632edfc7703300407984bbaefb3c91c1560c | https://github.com/quazardous/ImageStack/blob/bca5632edfc7703300407984bbaefb3c91c1560c/src/ImageStack/Cache/RawFileCache.php#L217-L228 | train |
quazardous/ImageStack | src/ImageStack/Cache/RawFileCache.php | RawFileCache.assertDirectory | protected function assertDirectory($filename)
{
$dirname = dirname($filename);
if (!is_dir($dirname)) {
if (is_file($dirname)) {
throw new RawFileCacheException(sprintf('File with same name : %s', $dirname), RawFileCacheException::FILE_WITH_SAME_NAME);
}
@mkdir($dirname, $this->getOption('dir_mode', 0755), true);
if (!is_dir($dirname)) {
throw new RawFileCacheException(sprintf('Cannot create directory : %s', $dirname), RawFileCacheException::CANNOT_CREATE_DIRECTORY);
}
}
} | php | protected function assertDirectory($filename)
{
$dirname = dirname($filename);
if (!is_dir($dirname)) {
if (is_file($dirname)) {
throw new RawFileCacheException(sprintf('File with same name : %s', $dirname), RawFileCacheException::FILE_WITH_SAME_NAME);
}
@mkdir($dirname, $this->getOption('dir_mode', 0755), true);
if (!is_dir($dirname)) {
throw new RawFileCacheException(sprintf('Cannot create directory : %s', $dirname), RawFileCacheException::CANNOT_CREATE_DIRECTORY);
}
}
} | [
"protected",
"function",
"assertDirectory",
"(",
"$",
"filename",
")",
"{",
"$",
"dirname",
"=",
"dirname",
"(",
"$",
"filename",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dirname",
")",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"dirname",
")",
... | Assert that the parent directory can or will exist.
@param string $filename
@throws RawFileCacheException | [
"Assert",
"that",
"the",
"parent",
"directory",
"can",
"or",
"will",
"exist",
"."
] | bca5632edfc7703300407984bbaefb3c91c1560c | https://github.com/quazardous/ImageStack/blob/bca5632edfc7703300407984bbaefb3c91c1560c/src/ImageStack/Cache/RawFileCache.php#L235-L247 | train |
quazardous/ImageStack | src/ImageStack/Cache/RawFileCache.php | RawFileCache.assertFile | protected function assertFile($filename)
{
if (is_dir($filename)) {
throw new RawFileCacheException(sprintf('Directory with same name : %s', $filename), RawFileCacheException::DIRECTORY_WITH_SAME_NAME);
}
return is_file($filename);
} | php | protected function assertFile($filename)
{
if (is_dir($filename)) {
throw new RawFileCacheException(sprintf('Directory with same name : %s', $filename), RawFileCacheException::DIRECTORY_WITH_SAME_NAME);
}
return is_file($filename);
} | [
"protected",
"function",
"assertFile",
"(",
"$",
"filename",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"filename",
")",
")",
"{",
"throw",
"new",
"RawFileCacheException",
"(",
"sprintf",
"(",
"'Directory with same name : %s'",
",",
"$",
"filename",
")",
",",
... | Assert that the filename can be used.
@param string $filename
@throws RawFileCacheException
@return boolean | [
"Assert",
"that",
"the",
"filename",
"can",
"be",
"used",
"."
] | bca5632edfc7703300407984bbaefb3c91c1560c | https://github.com/quazardous/ImageStack/blob/bca5632edfc7703300407984bbaefb3c91c1560c/src/ImageStack/Cache/RawFileCache.php#L255-L261 | train |
milejko/mmi | src/Mmi/Orm/RecordRo.php | RecordRo.setFromArray | public function setFromArray(array $row = [])
{
$joinedRows = [];
foreach ($row as $key => $value) {
//przyjęcie pól z joinów
if (false !== strpos($key, '__')) {
$keyParts = explode('__', $key);
$joinedRows[$keyParts[0]][$keyParts[1]][$keyParts[2]] = $value;
continue;
}
$field = \Mmi\Orm\Convert::underscoreToCamelcase($key);
if (property_exists($this, $field)) {
$this->$field = $value;
continue;
}
$this->setOption($field, $value);
}
//podpięcie joinów pod główny rekord
foreach ($joinedRows as $alias => $tables) {
foreach ($tables as $tableName => $fields) {
$recordClass = \Mmi\Orm\DbConnector::getRecordNameByTable($tableName);
$record = new $recordClass;
$record->setFromArray($fields)
->clearModified();
$this->_joined[$alias] = $record;
}
}
//wypełniony
$this->_filled = true;
return $this;
} | php | public function setFromArray(array $row = [])
{
$joinedRows = [];
foreach ($row as $key => $value) {
//przyjęcie pól z joinów
if (false !== strpos($key, '__')) {
$keyParts = explode('__', $key);
$joinedRows[$keyParts[0]][$keyParts[1]][$keyParts[2]] = $value;
continue;
}
$field = \Mmi\Orm\Convert::underscoreToCamelcase($key);
if (property_exists($this, $field)) {
$this->$field = $value;
continue;
}
$this->setOption($field, $value);
}
//podpięcie joinów pod główny rekord
foreach ($joinedRows as $alias => $tables) {
foreach ($tables as $tableName => $fields) {
$recordClass = \Mmi\Orm\DbConnector::getRecordNameByTable($tableName);
$record = new $recordClass;
$record->setFromArray($fields)
->clearModified();
$this->_joined[$alias] = $record;
}
}
//wypełniony
$this->_filled = true;
return $this;
} | [
"public",
"function",
"setFromArray",
"(",
"array",
"$",
"row",
"=",
"[",
"]",
")",
"{",
"$",
"joinedRows",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"row",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"//przyjęcie pól z joinów",
"if",
"(",
"false"... | Ustawia dane w obiekcie na podstawie tabeli
@param array $row tabela z danymi
@param bool $fromDb czy z bazy danych
@return \Mmi\Orm\Record | [
"Ustawia",
"dane",
"w",
"obiekcie",
"na",
"podstawie",
"tabeli"
] | c1e8dddf83665ad3463ff801074aa2b0875db19b | https://github.com/milejko/mmi/blob/c1e8dddf83665ad3463ff801074aa2b0875db19b/src/Mmi/Orm/RecordRo.php#L156-L186 | train |
milejko/mmi | src/Mmi/Orm/RecordRo.php | RecordRo.isModified | public final function isModified($field)
{
//brak klucza w tablicy stanu - niezmodyfikowane
if (!array_key_exists($field, $this->_state)) {
return false;
}
//wartość liczbowa - porównanie proste
if (is_numeric($this->$field) && $this->_state[$field] == $this->$field) {
return false;
}
//porównanie z typem
return ($this->_state[$field] !== $this->$field);
} | php | public final function isModified($field)
{
//brak klucza w tablicy stanu - niezmodyfikowane
if (!array_key_exists($field, $this->_state)) {
return false;
}
//wartość liczbowa - porównanie proste
if (is_numeric($this->$field) && $this->_state[$field] == $this->$field) {
return false;
}
//porównanie z typem
return ($this->_state[$field] !== $this->$field);
} | [
"public",
"final",
"function",
"isModified",
"(",
"$",
"field",
")",
"{",
"//brak klucza w tablicy stanu - niezmodyfikowane",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"field",
",",
"$",
"this",
"->",
"_state",
")",
")",
"{",
"return",
"false",
";",
"}",
... | Zwraca czy zmodyfikowano pole
@param string $field nazwa pola
@return boolean | [
"Zwraca",
"czy",
"zmodyfikowano",
"pole"
] | c1e8dddf83665ad3463ff801074aa2b0875db19b | https://github.com/milejko/mmi/blob/c1e8dddf83665ad3463ff801074aa2b0875db19b/src/Mmi/Orm/RecordRo.php#L205-L217 | train |
milejko/mmi | src/Mmi/Orm/RecordRo.php | RecordRo.toArray | public function toArray()
{
//tworzy array z opcji
$array = $this->_options;
//dołącza joinowane tabele
foreach ($this->_joined as $name => $value) {
if ($value instanceof \Mmi\Orm\RecordRo) {
$value = $value->toArray();
}
$array[$name] = $value;
}
//dołącza pola obiektu
foreach ($this as $name => $value) {
//tylko publiczne zmienne
if (substr($name, 0, 1) == '_') {
continue;
}
$array[$name] = $value;
}
return $array;
} | php | public function toArray()
{
//tworzy array z opcji
$array = $this->_options;
//dołącza joinowane tabele
foreach ($this->_joined as $name => $value) {
if ($value instanceof \Mmi\Orm\RecordRo) {
$value = $value->toArray();
}
$array[$name] = $value;
}
//dołącza pola obiektu
foreach ($this as $name => $value) {
//tylko publiczne zmienne
if (substr($name, 0, 1) == '_') {
continue;
}
$array[$name] = $value;
}
return $array;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"//tworzy array z opcji",
"$",
"array",
"=",
"$",
"this",
"->",
"_options",
";",
"//dołącza joinowane tabele",
"foreach",
"(",
"$",
"this",
"->",
"_joined",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"i... | Zwraca dane z obiektu w postaci tablicy
@return array | [
"Zwraca",
"dane",
"z",
"obiektu",
"w",
"postaci",
"tablicy"
] | c1e8dddf83665ad3463ff801074aa2b0875db19b | https://github.com/milejko/mmi/blob/c1e8dddf83665ad3463ff801074aa2b0875db19b/src/Mmi/Orm/RecordRo.php#L233-L253 | train |
quazardous/ImageStack | src/ImageStack/ImageBackend/FileImageBackend.php | FileImageBackend.getImageFilename | protected function getImageFilename(ImagePathInterface $path) {
return sanitize_path(implode(DIRECTORY_SEPARATOR, [
$this->getOption('root'),
$path->getPath(),
]));
} | php | protected function getImageFilename(ImagePathInterface $path) {
return sanitize_path(implode(DIRECTORY_SEPARATOR, [
$this->getOption('root'),
$path->getPath(),
]));
} | [
"protected",
"function",
"getImageFilename",
"(",
"ImagePathInterface",
"$",
"path",
")",
"{",
"return",
"sanitize_path",
"(",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"[",
"$",
"this",
"->",
"getOption",
"(",
"'root'",
")",
",",
"$",
"path",
"->",
"getPath... | Get the image filename.
@param ImagePathInterface $path
@return string | [
"Get",
"the",
"image",
"filename",
"."
] | bca5632edfc7703300407984bbaefb3c91c1560c | https://github.com/quazardous/ImageStack/blob/bca5632edfc7703300407984bbaefb3c91c1560c/src/ImageStack/ImageBackend/FileImageBackend.php#L37-L42 | train |
peakphp/framework | src/Config/ConfigResolver.php | ConfigResolver.resolve | public function resolve($resource): Stream
{
// detect best way to load and process configuration content
if (is_array($resource)) {
return new DataStream($resource, new ArrayProcessor());
} elseif (is_callable($resource)) {
return new DataStream($resource, new CallableProcessor());
} elseif ($resource instanceof Config) {
return new DataStream($resource, new ConfigProcessor());
} elseif ($resource instanceof Collection) {
return new DataStream($resource, new CollectionProcessor());
} elseif ($resource instanceof Stream) {
return $resource;
} elseif ($resource instanceof stdClass) {
return new DataStream($resource, new StdClassProcessor());
} elseif (is_string($resource)) {
$filesHandlers = $this->filesHandlers;
if (null === $filesHandlers) {
$filesHandlers = new FilesHandlers(null);
}
return new FileStream($resource, $filesHandlers);
}
throw new UnknownResourceException($resource);
} | php | public function resolve($resource): Stream
{
// detect best way to load and process configuration content
if (is_array($resource)) {
return new DataStream($resource, new ArrayProcessor());
} elseif (is_callable($resource)) {
return new DataStream($resource, new CallableProcessor());
} elseif ($resource instanceof Config) {
return new DataStream($resource, new ConfigProcessor());
} elseif ($resource instanceof Collection) {
return new DataStream($resource, new CollectionProcessor());
} elseif ($resource instanceof Stream) {
return $resource;
} elseif ($resource instanceof stdClass) {
return new DataStream($resource, new StdClassProcessor());
} elseif (is_string($resource)) {
$filesHandlers = $this->filesHandlers;
if (null === $filesHandlers) {
$filesHandlers = new FilesHandlers(null);
}
return new FileStream($resource, $filesHandlers);
}
throw new UnknownResourceException($resource);
} | [
"public",
"function",
"resolve",
"(",
"$",
"resource",
")",
":",
"Stream",
"{",
"// detect best way to load and process configuration content",
"if",
"(",
"is_array",
"(",
"$",
"resource",
")",
")",
"{",
"return",
"new",
"DataStream",
"(",
"$",
"resource",
",",
... | Resolve a config resource to a valid StreamInterface
@param mixed $resource
@return Stream
@throws UnknownResourceException | [
"Resolve",
"a",
"config",
"resource",
"to",
"a",
"valid",
"StreamInterface"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Config/ConfigResolver.php#L49-L73 | train |
milejko/mmi | src/Mmi/Mvc/Dispatcher.php | Dispatcher.routeStartup | public function routeStartup()
{
//iteracja po pluginach
foreach (FrontController::getInstance()->getPlugins() as $plugin) {
//wykonywanie routeStartup() na kolejnych pluginach
$plugin->routeStartup(FrontController::getInstance()->getRequest());
}
//profiler
FrontController::getInstance()->getProfiler()->event('Mvc\Dispatcher: plugins route startup');
} | php | public function routeStartup()
{
//iteracja po pluginach
foreach (FrontController::getInstance()->getPlugins() as $plugin) {
//wykonywanie routeStartup() na kolejnych pluginach
$plugin->routeStartup(FrontController::getInstance()->getRequest());
}
//profiler
FrontController::getInstance()->getProfiler()->event('Mvc\Dispatcher: plugins route startup');
} | [
"public",
"function",
"routeStartup",
"(",
")",
"{",
"//iteracja po pluginach",
"foreach",
"(",
"FrontController",
"::",
"getInstance",
"(",
")",
"->",
"getPlugins",
"(",
")",
"as",
"$",
"plugin",
")",
"{",
"//wykonywanie routeStartup() na kolejnych pluginach",
"$",
... | Uruchamianie metody routeStartup na zarejestrowanych pluginach | [
"Uruchamianie",
"metody",
"routeStartup",
"na",
"zarejestrowanych",
"pluginach"
] | c1e8dddf83665ad3463ff801074aa2b0875db19b | https://github.com/milejko/mmi/blob/c1e8dddf83665ad3463ff801074aa2b0875db19b/src/Mmi/Mvc/Dispatcher.php#L24-L33 | train |
honeybee/honeybee | src/Infrastructure/Filesystem/FilesystemService.php | FilesystemService.generatePath | public static function generatePath(
AttributeInterface $attribute,
$additional_prefix = '',
$extension = '',
$uuid = null
) {
$uuid = $uuid ? UuidGenerator::fromString($uuid) : UuidGenerator::uuid4();
$uuid_string = $uuid->toString();
$uuid_parts = $uuid->getClockSeqLow(); // 8 bit int => 256 folders
$root_type = $attribute->getRootType();
$root_type_name = $root_type->getName();
if ($root_type instanceof EntityTypeInterface) {
$root_type_name = $root_type->getPrefix();
}
$attribute_path = $attribute->getPath();
$identifier = '';
if (!empty($additional_prefix)) {
$identifier = $additional_prefix . '/';
}
$identifier .= sprintf('%s/%s/%s/%s', $root_type_name, $attribute_path, $uuid_parts, $uuid_string);
if (!empty($extension)) {
$identifier .= '.' . $extension;
}
return $identifier;
} | php | public static function generatePath(
AttributeInterface $attribute,
$additional_prefix = '',
$extension = '',
$uuid = null
) {
$uuid = $uuid ? UuidGenerator::fromString($uuid) : UuidGenerator::uuid4();
$uuid_string = $uuid->toString();
$uuid_parts = $uuid->getClockSeqLow(); // 8 bit int => 256 folders
$root_type = $attribute->getRootType();
$root_type_name = $root_type->getName();
if ($root_type instanceof EntityTypeInterface) {
$root_type_name = $root_type->getPrefix();
}
$attribute_path = $attribute->getPath();
$identifier = '';
if (!empty($additional_prefix)) {
$identifier = $additional_prefix . '/';
}
$identifier .= sprintf('%s/%s/%s/%s', $root_type_name, $attribute_path, $uuid_parts, $uuid_string);
if (!empty($extension)) {
$identifier .= '.' . $extension;
}
return $identifier;
} | [
"public",
"static",
"function",
"generatePath",
"(",
"AttributeInterface",
"$",
"attribute",
",",
"$",
"additional_prefix",
"=",
"''",
",",
"$",
"extension",
"=",
"''",
",",
"$",
"uuid",
"=",
"null",
")",
"{",
"$",
"uuid",
"=",
"$",
"uuid",
"?",
"UuidGen... | Generates a unique file identifier that may be used as a relative file path.
@param AttributeInterface $attribute attribute to generate a file identifier for
@param string $additional_prefix a string to add in front of the generated identifier
@param string $extension a (file) extension to append to the generated identifier (e.g. 'jpg')
@return string unique relative file path | [
"Generates",
"a",
"unique",
"file",
"identifier",
"that",
"may",
"be",
"used",
"as",
"a",
"relative",
"file",
"path",
"."
] | 6e46b4f20a0b8a3ce686565440f739960e325a05 | https://github.com/honeybee/honeybee/blob/6e46b4f20a0b8a3ce686565440f739960e325a05/src/Infrastructure/Filesystem/FilesystemService.php#L291-L322 | train |
honeybee/honeybee | src/Projection/ProjectionType.php | ProjectionType.createEntity | public function createEntity(array $data = [], EntityInterface $parent_entity = null, $apply_default_values = false)
{
return parent::createEntity($data, $parent_entity, true);
} | php | public function createEntity(array $data = [], EntityInterface $parent_entity = null, $apply_default_values = false)
{
return parent::createEntity($data, $parent_entity, true);
} | [
"public",
"function",
"createEntity",
"(",
"array",
"$",
"data",
"=",
"[",
"]",
",",
"EntityInterface",
"$",
"parent_entity",
"=",
"null",
",",
"$",
"apply_default_values",
"=",
"false",
")",
"{",
"return",
"parent",
"::",
"createEntity",
"(",
"$",
"data",
... | Creates a new Projection instance.
@param array $data Optional data for initial hydration.
@param EntityInterface $parent_entity
@param boolean $apply_default_values
@return ProjectionInterface
@throws InvalidTypeException | [
"Creates",
"a",
"new",
"Projection",
"instance",
"."
] | 6e46b4f20a0b8a3ce686565440f739960e325a05 | https://github.com/honeybee/honeybee/blob/6e46b4f20a0b8a3ce686565440f739960e325a05/src/Projection/ProjectionType.php#L61-L64 | train |
peakphp/framework | src/Common/TextUtils.php | TextUtils.countWords | public static function countWords(string $text): int
{
// split text by ' ',\r,\n,\f,\t
$split_array = preg_split('/\s+/', $text);
// count matches that contain alphanumerics
$word_count = preg_grep('/[a-zA-Z0-9\\x80-\\xff]/', $split_array);
return count($word_count);
} | php | public static function countWords(string $text): int
{
// split text by ' ',\r,\n,\f,\t
$split_array = preg_split('/\s+/', $text);
// count matches that contain alphanumerics
$word_count = preg_grep('/[a-zA-Z0-9\\x80-\\xff]/', $split_array);
return count($word_count);
} | [
"public",
"static",
"function",
"countWords",
"(",
"string",
"$",
"text",
")",
":",
"int",
"{",
"// split text by ' ',\\r,\\n,\\f,\\t",
"$",
"split_array",
"=",
"preg_split",
"(",
"'/\\s+/'",
",",
"$",
"text",
")",
";",
"// count matches that contain alphanumerics",
... | Count the number of words in a text
@param string $text
@return int | [
"Count",
"the",
"number",
"of",
"words",
"in",
"a",
"text"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Common/TextUtils.php#L24-L32 | train |
peakphp/framework | src/Common/TextUtils.php | TextUtils.countChars | public static function countChars(string $text, bool $includeSpaces = false): int
{
if ($includeSpaces === false) {
$text = preg_replace("/[\s]/", '', $text);
}
return mb_strlen($text);
} | php | public static function countChars(string $text, bool $includeSpaces = false): int
{
if ($includeSpaces === false) {
$text = preg_replace("/[\s]/", '', $text);
}
return mb_strlen($text);
} | [
"public",
"static",
"function",
"countChars",
"(",
"string",
"$",
"text",
",",
"bool",
"$",
"includeSpaces",
"=",
"false",
")",
":",
"int",
"{",
"if",
"(",
"$",
"includeSpaces",
"===",
"false",
")",
"{",
"$",
"text",
"=",
"preg_replace",
"(",
"\"/[\\s]/\... | Count the number of characters in a text
@param string $text
@param bool $includeSpaces
@return int | [
"Count",
"the",
"number",
"of",
"characters",
"in",
"a",
"text"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Common/TextUtils.php#L51-L57 | train |
peakphp/framework | src/Common/TextUtils.php | TextUtils.wordwrap | public static function wordwrap(string $string, int $length = 80, string $break = "\n", bool $cut = false): string
{
return wordwrap($string, $length, $break, $cut);
} | php | public static function wordwrap(string $string, int $length = 80, string $break = "\n", bool $cut = false): string
{
return wordwrap($string, $length, $break, $cut);
} | [
"public",
"static",
"function",
"wordwrap",
"(",
"string",
"$",
"string",
",",
"int",
"$",
"length",
"=",
"80",
",",
"string",
"$",
"break",
"=",
"\"\\n\"",
",",
"bool",
"$",
"cut",
"=",
"false",
")",
":",
"string",
"{",
"return",
"wordwrap",
"(",
"$... | Wrap a string of text at a given length
@param string $string
@param integer $length
@param string $break
@param bool $cut
@return string | [
"Wrap",
"a",
"string",
"of",
"text",
"at",
"a",
"given",
"length"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Common/TextUtils.php#L106-L109 | train |
milejko/mmi | src/Mmi/Mvc/RouterMatcher.php | RouterMatcher._routeMatch | protected function _routeMatch($matches)
{
if (isset($this->_tmpMatches[$matches[1]])) {
return $this->_tmpMatches[$matches[1]];
}
if (isset($this->_tmpDefault[$this->_tmpKey])) {
return $this->_tmpDefault[$this->_tmpKey];
}
throw new \Mmi\Mvc\MvcException('Router failed due to invalid route definition - no default param for key: ' . $this->_tmpKey);
} | php | protected function _routeMatch($matches)
{
if (isset($this->_tmpMatches[$matches[1]])) {
return $this->_tmpMatches[$matches[1]];
}
if (isset($this->_tmpDefault[$this->_tmpKey])) {
return $this->_tmpDefault[$this->_tmpKey];
}
throw new \Mmi\Mvc\MvcException('Router failed due to invalid route definition - no default param for key: ' . $this->_tmpKey);
} | [
"protected",
"function",
"_routeMatch",
"(",
"$",
"matches",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_tmpMatches",
"[",
"$",
"matches",
"[",
"1",
"]",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_tmpMatches",
"[",
"$",
"matches",... | Callback dla zmieniania rout
@param array $matches dopasowania
@return mixed
@throws \Mmi\Mvc\MvcException | [
"Callback",
"dla",
"zmieniania",
"rout"
] | c1e8dddf83665ad3463ff801074aa2b0875db19b | https://github.com/milejko/mmi/blob/c1e8dddf83665ad3463ff801074aa2b0875db19b/src/Mmi/Mvc/RouterMatcher.php#L137-L146 | train |
boekkooi/TwigJackBundle | src/Twig/Loader/DoctrineLoader.php | DoctrineLoader.isLoadableTemplate | protected function isLoadableTemplate($name)
{
return !empty($name) && (empty($this->prefix) || strlen($name) > strlen($this->prefix) && strpos($name, $this->prefix) === 0);
} | php | protected function isLoadableTemplate($name)
{
return !empty($name) && (empty($this->prefix) || strlen($name) > strlen($this->prefix) && strpos($name, $this->prefix) === 0);
} | [
"protected",
"function",
"isLoadableTemplate",
"(",
"$",
"name",
")",
"{",
"return",
"!",
"empty",
"(",
"$",
"name",
")",
"&&",
"(",
"empty",
"(",
"$",
"this",
"->",
"prefix",
")",
"||",
"strlen",
"(",
"$",
"name",
")",
">",
"strlen",
"(",
"$",
"th... | Check if the given name has the correct prefix for loading.
@param string $name The name of the template to check
@return bool | [
"Check",
"if",
"the",
"given",
"name",
"has",
"the",
"correct",
"prefix",
"for",
"loading",
"."
] | 8aa9fe7681eaabe6285aa76d0a52e9da4ff67ffa | https://github.com/boekkooi/TwigJackBundle/blob/8aa9fe7681eaabe6285aa76d0a52e9da4ff67ffa/src/Twig/Loader/DoctrineLoader.php#L100-L103 | train |
boekkooi/TwigJackBundle | src/Twig/Loader/DoctrineLoader.php | DoctrineLoader.findTemplate | protected function findTemplate($name)
{
if (!$this->isLoadableTemplate($name)) {
throw new \Twig_Error_Loader(sprintf('Malformed namespaced template name "%s" (expecting "%stemplate_name").', $name, $this->prefix));
}
$templateIdentifier = substr($name, strlen($this->prefix));
$template = $this->repository->find($templateIdentifier);
if ($template === null) {
throw new \Twig_Error_Loader(sprintf('Unable to find template "%s".', $name));
}
if (!($template instanceof TemplateInterface)) {
throw new \Twig_Error_Loader(sprintf('Unexpected template type "%s" found for template "%s".', get_class($template), $name));
}
if ($template instanceof TranslatableTemplateInterface) {
/** @var TranslatableTemplateInterface $template */
$locale = $this->getCurrentLocale();
$template->setCurrentLocale($locale);
}
return $template;
} | php | protected function findTemplate($name)
{
if (!$this->isLoadableTemplate($name)) {
throw new \Twig_Error_Loader(sprintf('Malformed namespaced template name "%s" (expecting "%stemplate_name").', $name, $this->prefix));
}
$templateIdentifier = substr($name, strlen($this->prefix));
$template = $this->repository->find($templateIdentifier);
if ($template === null) {
throw new \Twig_Error_Loader(sprintf('Unable to find template "%s".', $name));
}
if (!($template instanceof TemplateInterface)) {
throw new \Twig_Error_Loader(sprintf('Unexpected template type "%s" found for template "%s".', get_class($template), $name));
}
if ($template instanceof TranslatableTemplateInterface) {
/** @var TranslatableTemplateInterface $template */
$locale = $this->getCurrentLocale();
$template->setCurrentLocale($locale);
}
return $template;
} | [
"protected",
"function",
"findTemplate",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isLoadableTemplate",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"Twig_Error_Loader",
"(",
"sprintf",
"(",
"'Malformed namespaced template name ... | Find a template by it's name
@param string $name The name of the template to find
@return TemplateInterface
@throws \Twig_Error_Loader | [
"Find",
"a",
"template",
"by",
"it",
"s",
"name"
] | 8aa9fe7681eaabe6285aa76d0a52e9da4ff67ffa | https://github.com/boekkooi/TwigJackBundle/blob/8aa9fe7681eaabe6285aa76d0a52e9da4ff67ffa/src/Twig/Loader/DoctrineLoader.php#L112-L133 | train |
peakphp/framework | src/Config/FilesHandlers.php | FilesHandlers.get | public function get(string $name): array
{
if (!$this->has($name)) {
throw new NoFileHandlersException($name);
}
return $this->handlers[$name];
} | php | public function get(string $name): array
{
if (!$this->has($name)) {
throw new NoFileHandlersException($name);
}
return $this->handlers[$name];
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"name",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"has",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"NoFileHandlersException",
"(",
"$",
"name",
")",
";",
"}",
"return",
"$",
... | Get a file handlers
@param string $name
@return array
@throws NoFileHandlersException | [
"Get",
"a",
"file",
"handlers"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Config/FilesHandlers.php#L90-L97 | train |
peakphp/framework | src/Config/FilesHandlers.php | FilesHandlers.set | public function set(string $name, string $loader, string $processor): FilesHandlers
{
$this->handlers[$name] = [
'loader' => new $loader(),
'processor' => new $processor(),
];
return $this;
} | php | public function set(string $name, string $loader, string $processor): FilesHandlers
{
$this->handlers[$name] = [
'loader' => new $loader(),
'processor' => new $processor(),
];
return $this;
} | [
"public",
"function",
"set",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"loader",
",",
"string",
"$",
"processor",
")",
":",
"FilesHandlers",
"{",
"$",
"this",
"->",
"handlers",
"[",
"$",
"name",
"]",
"=",
"[",
"'loader'",
"=>",
"new",
"$",
"loa... | Add or override a file handlers
@param string $name
@param string $loader
@param string $processor
@return FilesHandlers | [
"Add",
"or",
"override",
"a",
"file",
"handlers"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Config/FilesHandlers.php#L143-L150 | train |
milejko/mmi | src/Mmi/App/BootstrapCli.php | BootstrapCli.run | public function run()
{
$request = new \Mmi\Http\Request;
//ustawianie domyślnego języka jeśli istnieje
if (isset(\App\Registry::$config->languages[0])) {
$request->lang = \App\Registry::$config->languages[0];
}
$request->setModuleName('mmi')
->setControllerName('index')
->setActionName('index');
//ustawianie żądania
FrontController::getInstance()->setRequest($request)
->getView()->setRequest($request);
FrontController::getInstance()->getResponse()->clearHeaders();
} | php | public function run()
{
$request = new \Mmi\Http\Request;
//ustawianie domyślnego języka jeśli istnieje
if (isset(\App\Registry::$config->languages[0])) {
$request->lang = \App\Registry::$config->languages[0];
}
$request->setModuleName('mmi')
->setControllerName('index')
->setActionName('index');
//ustawianie żądania
FrontController::getInstance()->setRequest($request)
->getView()->setRequest($request);
FrontController::getInstance()->getResponse()->clearHeaders();
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"request",
"=",
"new",
"\\",
"Mmi",
"\\",
"Http",
"\\",
"Request",
";",
"//ustawianie domyślnego języka jeśli istnieje",
"if",
"(",
"isset",
"(",
"\\",
"App",
"\\",
"Registry",
"::",
"$",
"config",
"->",
"la... | Uruchamianie bootstrapa - brak front kontrolera | [
"Uruchamianie",
"bootstrapa",
"-",
"brak",
"front",
"kontrolera"
] | c1e8dddf83665ad3463ff801074aa2b0875db19b | https://github.com/milejko/mmi/blob/c1e8dddf83665ad3463ff801074aa2b0875db19b/src/Mmi/App/BootstrapCli.php#L31-L45 | train |
milejko/mmi | src/Mmi/Security/Auth.php | Auth._setAuthentication | protected function _setAuthentication(\Mmi\Security\AuthRecord $record)
{
//przekazanie danych z rekordu autoryzacji do sesji
$this->_session->setFromArray((array)$record);
return true;
} | php | protected function _setAuthentication(\Mmi\Security\AuthRecord $record)
{
//przekazanie danych z rekordu autoryzacji do sesji
$this->_session->setFromArray((array)$record);
return true;
} | [
"protected",
"function",
"_setAuthentication",
"(",
"\\",
"Mmi",
"\\",
"Security",
"\\",
"AuthRecord",
"$",
"record",
")",
"{",
"//przekazanie danych z rekordu autoryzacji do sesji",
"$",
"this",
"->",
"_session",
"->",
"setFromArray",
"(",
"(",
"array",
")",
"$",
... | Wymuszenie ustawienia autoryzacji
@param \Mmi\Security\AuthRecord $record
@return boolean | [
"Wymuszenie",
"ustawienia",
"autoryzacji"
] | c1e8dddf83665ad3463ff801074aa2b0875db19b | https://github.com/milejko/mmi/blob/c1e8dddf83665ad3463ff801074aa2b0875db19b/src/Mmi/Security/Auth.php#L285-L290 | train |
milejko/mmi | src/Mmi/Security/Auth.php | Auth.httpAuth | public function httpAuth($realm = '', $errorMessage = '')
{
//pobieranie usera i hasła ze zmiennych środowiskowych
$this->setIdentity(\Mmi\App\FrontController::getInstance()->getEnvironment()->authUser)
->setCredential(\Mmi\App\FrontController::getInstance()->getEnvironment()->authPassword);
//model autoryzacji
$model = $this->_modelName;
//autoryzacja
$record = $model::authenticate($this->_identity, $this->_credential);
//autoryzacja poprawna
if ($record) {
return;
}
//odpowiedź 401
\Mmi\App\FrontController::getInstance()->getResponse()
->setHeader('WWW-Authenticate', 'Basic realm="' . $realm . '"')
->setCodeUnauthorized()
->setContent($errorMessage);
//zakończenie skryptu
exit;
} | php | public function httpAuth($realm = '', $errorMessage = '')
{
//pobieranie usera i hasła ze zmiennych środowiskowych
$this->setIdentity(\Mmi\App\FrontController::getInstance()->getEnvironment()->authUser)
->setCredential(\Mmi\App\FrontController::getInstance()->getEnvironment()->authPassword);
//model autoryzacji
$model = $this->_modelName;
//autoryzacja
$record = $model::authenticate($this->_identity, $this->_credential);
//autoryzacja poprawna
if ($record) {
return;
}
//odpowiedź 401
\Mmi\App\FrontController::getInstance()->getResponse()
->setHeader('WWW-Authenticate', 'Basic realm="' . $realm . '"')
->setCodeUnauthorized()
->setContent($errorMessage);
//zakończenie skryptu
exit;
} | [
"public",
"function",
"httpAuth",
"(",
"$",
"realm",
"=",
"''",
",",
"$",
"errorMessage",
"=",
"''",
")",
"{",
"//pobieranie usera i hasła ze zmiennych środowiskowych",
"$",
"this",
"->",
"setIdentity",
"(",
"\\",
"Mmi",
"\\",
"App",
"\\",
"FrontController",
"::... | Uwierzytelnienie przez http
@param string $realm identyfikator przestrzeni chronionej
@param string $errorMessage treść komunikatu zwrotnego - błędnego | [
"Uwierzytelnienie",
"przez",
"http"
] | c1e8dddf83665ad3463ff801074aa2b0875db19b | https://github.com/milejko/mmi/blob/c1e8dddf83665ad3463ff801074aa2b0875db19b/src/Mmi/Security/Auth.php#L317-L337 | train |
peakphp/framework | src/Di/BindingResolver.php | BindingResolver.resolve | public function resolve(BindingInterface $binding, Container $container, $args = [], $explicit = null)
{
return $binding->resolve($container, $args, $explicit);
} | php | public function resolve(BindingInterface $binding, Container $container, $args = [], $explicit = null)
{
return $binding->resolve($container, $args, $explicit);
} | [
"public",
"function",
"resolve",
"(",
"BindingInterface",
"$",
"binding",
",",
"Container",
"$",
"container",
",",
"$",
"args",
"=",
"[",
"]",
",",
"$",
"explicit",
"=",
"null",
")",
"{",
"return",
"$",
"binding",
"->",
"resolve",
"(",
"$",
"container",
... | Resolve a binding request
@param BindingInterface $binding
@param Container $container
@param array $args
@param null $explicit
@return mixed | [
"Resolve",
"a",
"binding",
"request"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Di/BindingResolver.php#L20-L23 | train |
peakphp/framework | src/Bedrock/Bootstrap/BootableResolver.php | BootableResolver.resolve | public function resolve($item): Bootable
{
if(is_string($item) && class_exists($item)) {
if (null !== $this->container) {
$item = $this->container->get($item);
}
if (is_string($item)) {
$item = new $item();
}
} elseif (is_callable($item)) {
$item = new CallableProcess($item);
}
if (!$item instanceof Bootable) {
throw new InvalidBootableProcessException($item);
}
return $item;
} | php | public function resolve($item): Bootable
{
if(is_string($item) && class_exists($item)) {
if (null !== $this->container) {
$item = $this->container->get($item);
}
if (is_string($item)) {
$item = new $item();
}
} elseif (is_callable($item)) {
$item = new CallableProcess($item);
}
if (!$item instanceof Bootable) {
throw new InvalidBootableProcessException($item);
}
return $item;
} | [
"public",
"function",
"resolve",
"(",
"$",
"item",
")",
":",
"Bootable",
"{",
"if",
"(",
"is_string",
"(",
"$",
"item",
")",
"&&",
"class_exists",
"(",
"$",
"item",
")",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"container",
")",
"{",
... | Try to return a resolved item or throw an exception
@param mixed $item
@return Bootable
@throws InvalidBootableProcessException | [
"Try",
"to",
"return",
"a",
"resolved",
"item",
"or",
"throw",
"an",
"exception"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Bedrock/Bootstrap/BootableResolver.php#L36-L54 | train |
cedx/lcov.php | lib/FunctionData.php | FunctionData.fromJson | static function fromJson(object $map): self {
return new static(
isset($map->functionName) && is_string($map->functionName) ? $map->functionName : '',
isset($map->lineNumber) && is_int($map->lineNumber) ? $map->lineNumber : 0,
isset($map->executionCount) && is_int($map->executionCount) ? $map->executionCount : 0
);
} | php | static function fromJson(object $map): self {
return new static(
isset($map->functionName) && is_string($map->functionName) ? $map->functionName : '',
isset($map->lineNumber) && is_int($map->lineNumber) ? $map->lineNumber : 0,
isset($map->executionCount) && is_int($map->executionCount) ? $map->executionCount : 0
);
} | [
"static",
"function",
"fromJson",
"(",
"object",
"$",
"map",
")",
":",
"self",
"{",
"return",
"new",
"static",
"(",
"isset",
"(",
"$",
"map",
"->",
"functionName",
")",
"&&",
"is_string",
"(",
"$",
"map",
"->",
"functionName",
")",
"?",
"$",
"map",
"... | Creates a new function data from the specified JSON map.
@param object $map A JSON map representing a function data.
@return static The instance corresponding to the specified JSON map. | [
"Creates",
"a",
"new",
"function",
"data",
"from",
"the",
"specified",
"JSON",
"map",
"."
] | ae0129ec01f3e77e3598b82971383c334b213afe | https://github.com/cedx/lcov.php/blob/ae0129ec01f3e77e3598b82971383c334b213afe/lib/FunctionData.php#L41-L47 | train |
cedx/lcov.php | lib/FunctionData.php | FunctionData.toString | function toString(bool $asDefinition = false): string {
$token = $asDefinition ? Token::functionName : Token::functionData;
$number = $asDefinition ? $this->getLineNumber() : $this->getExecutionCount();
return "$token:$number,{$this->getFunctionName()}";
} | php | function toString(bool $asDefinition = false): string {
$token = $asDefinition ? Token::functionName : Token::functionData;
$number = $asDefinition ? $this->getLineNumber() : $this->getExecutionCount();
return "$token:$number,{$this->getFunctionName()}";
} | [
"function",
"toString",
"(",
"bool",
"$",
"asDefinition",
"=",
"false",
")",
":",
"string",
"{",
"$",
"token",
"=",
"$",
"asDefinition",
"?",
"Token",
"::",
"functionName",
":",
"Token",
"::",
"functionData",
";",
"$",
"number",
"=",
"$",
"asDefinition",
... | Returns a string representation of this object.
@param bool $asDefinition Value indicating whether to return the function definition (e.g. name and line number) instead of its data (e.g. name and execution count).
@return string The string representation of this object. | [
"Returns",
"a",
"string",
"representation",
"of",
"this",
"object",
"."
] | ae0129ec01f3e77e3598b82971383c334b213afe | https://github.com/cedx/lcov.php/blob/ae0129ec01f3e77e3598b82971383c334b213afe/lib/FunctionData.php#L100-L104 | train |
milejko/mmi | src/Mmi/Db/Deployer.php | Deployer._importIncremental | protected function _importIncremental($file)
{
//nazwa pliku
$baseFileName = basename($file);
//hash pliku
$md5file = md5_file($file);
//ustawianie domyślnych parametrów importu
\App\Registry::$db->setDefaultImportParams();
//pobranie rekordu
try {
$dc = (new Orm\ChangelogQuery)->whereFilename()->equals(basename($file))->findFirst();
} catch (\Exception $e) {
echo 'INITIAL IMPORT.' . "\n";
$dc = null;
}
//restore istnieje md5 zgodne
if ($dc && $dc->md5 == $md5file) {
echo 'INCREMENTAL PRESENT: ' . $baseFileName . "\n";
return;
}
//restore istnieje md5 niezgodne - plik się zmienił - przerwanie importu
if ($dc) {
throw new \Mmi\App\KernelException('INVALID MD5: ' . $baseFileName . ' --- VALID: ' . $md5file . ' --- IMPORT TERMINATED!\n');
}
//informacja na ekran przed importem aby bylo wiadomo który
echo 'RESTORE INCREMENTAL: ' . $baseFileName . "\n";
//import danych
$this->_importSql($file);
//resetowanie struktur tabeli
\Mmi\Orm\DbConnector::resetTableStructures();
//brak restore - zakłada nowy rekord
$newDc = new Orm\ChangelogRecord;
//zapis informacji o incrementalu
$newDc->filename = $baseFileName;
//wstawienie md5
$newDc->md5 = $md5file;
//zapis rekordu
$newDc->save();
} | php | protected function _importIncremental($file)
{
//nazwa pliku
$baseFileName = basename($file);
//hash pliku
$md5file = md5_file($file);
//ustawianie domyślnych parametrów importu
\App\Registry::$db->setDefaultImportParams();
//pobranie rekordu
try {
$dc = (new Orm\ChangelogQuery)->whereFilename()->equals(basename($file))->findFirst();
} catch (\Exception $e) {
echo 'INITIAL IMPORT.' . "\n";
$dc = null;
}
//restore istnieje md5 zgodne
if ($dc && $dc->md5 == $md5file) {
echo 'INCREMENTAL PRESENT: ' . $baseFileName . "\n";
return;
}
//restore istnieje md5 niezgodne - plik się zmienił - przerwanie importu
if ($dc) {
throw new \Mmi\App\KernelException('INVALID MD5: ' . $baseFileName . ' --- VALID: ' . $md5file . ' --- IMPORT TERMINATED!\n');
}
//informacja na ekran przed importem aby bylo wiadomo który
echo 'RESTORE INCREMENTAL: ' . $baseFileName . "\n";
//import danych
$this->_importSql($file);
//resetowanie struktur tabeli
\Mmi\Orm\DbConnector::resetTableStructures();
//brak restore - zakłada nowy rekord
$newDc = new Orm\ChangelogRecord;
//zapis informacji o incrementalu
$newDc->filename = $baseFileName;
//wstawienie md5
$newDc->md5 = $md5file;
//zapis rekordu
$newDc->save();
} | [
"protected",
"function",
"_importIncremental",
"(",
"$",
"file",
")",
"{",
"//nazwa pliku",
"$",
"baseFileName",
"=",
"basename",
"(",
"$",
"file",
")",
";",
"//hash pliku",
"$",
"md5file",
"=",
"md5_file",
"(",
"$",
"file",
")",
";",
"//ustawianie domyślnych ... | Importuje pojedynczy plik
@param string $file
@throws \Mmi\App\KernelException | [
"Importuje",
"pojedynczy",
"plik"
] | c1e8dddf83665ad3463ff801074aa2b0875db19b | https://github.com/milejko/mmi/blob/c1e8dddf83665ad3463ff801074aa2b0875db19b/src/Mmi/Db/Deployer.php#L61-L99 | train |
milejko/mmi | src/Mmi/Db/Deployer.php | Deployer._importSql | protected function _importSql($fileName)
{
//rozbicie zapytań po średniku i końcu linii
foreach (explode(';' . PHP_EOL, file_get_contents($fileName)) as $query) {
//wykonanie zapytania
$this->_performQuery($query);
}
} | php | protected function _importSql($fileName)
{
//rozbicie zapytań po średniku i końcu linii
foreach (explode(';' . PHP_EOL, file_get_contents($fileName)) as $query) {
//wykonanie zapytania
$this->_performQuery($query);
}
} | [
"protected",
"function",
"_importSql",
"(",
"$",
"fileName",
")",
"{",
"//rozbicie zapytań po średniku i końcu linii",
"foreach",
"(",
"explode",
"(",
"';'",
".",
"PHP_EOL",
",",
"file_get_contents",
"(",
"$",
"fileName",
")",
")",
"as",
"$",
"query",
")",
"{",
... | Import pliku sql
@param string $fileName nazwa pliku | [
"Import",
"pliku",
"sql"
] | c1e8dddf83665ad3463ff801074aa2b0875db19b | https://github.com/milejko/mmi/blob/c1e8dddf83665ad3463ff801074aa2b0875db19b/src/Mmi/Db/Deployer.php#L105-L112 | train |
milejko/mmi | src/Mmi/Db/Deployer.php | Deployer._performQuery | protected function _performQuery($query)
{
//brak query
if (!trim($query)) {
return;
}
//start transakcji
\App\Registry::$db->beginTransaction();
//quera jeśli błędna rollback i die, jeśli poprawna commit
try {
//wykonanie zapytania
\App\Registry::$db->query($query);
//commit
\App\Registry::$db->commit();
} catch (\Mmi\Db\DbException $e) {
//rollback
\App\Registry::$db->rollBack();
throw $e;
}
} | php | protected function _performQuery($query)
{
//brak query
if (!trim($query)) {
return;
}
//start transakcji
\App\Registry::$db->beginTransaction();
//quera jeśli błędna rollback i die, jeśli poprawna commit
try {
//wykonanie zapytania
\App\Registry::$db->query($query);
//commit
\App\Registry::$db->commit();
} catch (\Mmi\Db\DbException $e) {
//rollback
\App\Registry::$db->rollBack();
throw $e;
}
} | [
"protected",
"function",
"_performQuery",
"(",
"$",
"query",
")",
"{",
"//brak query",
"if",
"(",
"!",
"trim",
"(",
"$",
"query",
")",
")",
"{",
"return",
";",
"}",
"//start transakcji",
"\\",
"App",
"\\",
"Registry",
"::",
"$",
"db",
"->",
"beginTransac... | Wykonanie pojedynczego zapytania
@param string $query | [
"Wykonanie",
"pojedynczego",
"zapytania"
] | c1e8dddf83665ad3463ff801074aa2b0875db19b | https://github.com/milejko/mmi/blob/c1e8dddf83665ad3463ff801074aa2b0875db19b/src/Mmi/Db/Deployer.php#L118-L137 | train |
milejko/mmi | src/Mmi/App/ComposerInstaller.php | ComposerInstaller._copyDistFiles | protected static function _copyDistFiles()
{
//iteracja po wymaganych plikach
foreach (self::$_distFiles as $src => $dest) {
//kalkulacja ścieżki
$source = BASE_PATH . $src;
//brak pliku
if (!file_exists($source)) {
continue;
}
//kopiowanie katalogów
\Mmi\FileSystem::copyRecursive($source, BASE_PATH . $dest, false);
//usuwanie źródła
\Mmi\FileSystem::rmdirRecursive($source);
//usuwanie placeholderów
\Mmi\FileSystem::unlinkRecursive('.placeholder', BASE_PATH . $dest);
}
} | php | protected static function _copyDistFiles()
{
//iteracja po wymaganych plikach
foreach (self::$_distFiles as $src => $dest) {
//kalkulacja ścieżki
$source = BASE_PATH . $src;
//brak pliku
if (!file_exists($source)) {
continue;
}
//kopiowanie katalogów
\Mmi\FileSystem::copyRecursive($source, BASE_PATH . $dest, false);
//usuwanie źródła
\Mmi\FileSystem::rmdirRecursive($source);
//usuwanie placeholderów
\Mmi\FileSystem::unlinkRecursive('.placeholder', BASE_PATH . $dest);
}
} | [
"protected",
"static",
"function",
"_copyDistFiles",
"(",
")",
"{",
"//iteracja po wymaganych plikach ",
"foreach",
"(",
"self",
"::",
"$",
"_distFiles",
"as",
"$",
"src",
"=>",
"$",
"dest",
")",
"{",
"//kalkulacja ścieżki ",
"$",
"source",
"=",
"BASE_PATH",
"."... | Kopiuje pliki z dystrybucji | [
"Kopiuje",
"pliki",
"z",
"dystrybucji"
] | c1e8dddf83665ad3463ff801074aa2b0875db19b | https://github.com/milejko/mmi/blob/c1e8dddf83665ad3463ff801074aa2b0875db19b/src/Mmi/App/ComposerInstaller.php#L98-L115 | train |
honeybee/honeybee | src/Infrastructure/DataAccess/Connector/StatusReport.php | StatusReport.generate | public static function generate(ConnectorMap $connector_map)
{
$details = [];
$failing = 0;
$working = 0;
$unknown = 0;
$connections = [];
foreach ($connector_map as $name => $connector) {
try {
$connections[$name] = $connector->getStatus();
} catch (Exception $e) {
$connections[$name] = Status::failing(
$connector,
[ 'message' => 'Exception on getStatus(): ' . $e->getMessage() ]
);
error_log('Error while getting status of connection "' . $name . '": ' . $e->getTraceAsString());
}
}
ksort($connections);
foreach ($connections as $name => $connection) {
$details[$name] = $connection->toArray();
if ($connection->isFailing()) {
$failing++;
} elseif ($connection->isWorking()) {
$working++;
} else {
$unknown++;
}
}
$overall = $connector_map->count();
$status = Status::UNKNOWN;
if ($failing > 0) {
$status = Status::FAILING;
} elseif ($working === $overall) {
$status = Status::WORKING;
}
$stats = [
'overall' => $overall,
'failing' => $failing,
'working' => $working,
'unknown' => $unknown
];
return new static($status, $stats, $details);
} | php | public static function generate(ConnectorMap $connector_map)
{
$details = [];
$failing = 0;
$working = 0;
$unknown = 0;
$connections = [];
foreach ($connector_map as $name => $connector) {
try {
$connections[$name] = $connector->getStatus();
} catch (Exception $e) {
$connections[$name] = Status::failing(
$connector,
[ 'message' => 'Exception on getStatus(): ' . $e->getMessage() ]
);
error_log('Error while getting status of connection "' . $name . '": ' . $e->getTraceAsString());
}
}
ksort($connections);
foreach ($connections as $name => $connection) {
$details[$name] = $connection->toArray();
if ($connection->isFailing()) {
$failing++;
} elseif ($connection->isWorking()) {
$working++;
} else {
$unknown++;
}
}
$overall = $connector_map->count();
$status = Status::UNKNOWN;
if ($failing > 0) {
$status = Status::FAILING;
} elseif ($working === $overall) {
$status = Status::WORKING;
}
$stats = [
'overall' => $overall,
'failing' => $failing,
'working' => $working,
'unknown' => $unknown
];
return new static($status, $stats, $details);
} | [
"public",
"static",
"function",
"generate",
"(",
"ConnectorMap",
"$",
"connector_map",
")",
"{",
"$",
"details",
"=",
"[",
"]",
";",
"$",
"failing",
"=",
"0",
";",
"$",
"working",
"=",
"0",
";",
"$",
"unknown",
"=",
"0",
";",
"$",
"connections",
"=",... | Generates a new StatusReport by getting the Status from all known connections.
@todo Should only specific exceptions be catched when getStatus() is called on the connectors? Rethrow?
@param ConnectorMap $connector_map
@return StatusReport | [
"Generates",
"a",
"new",
"StatusReport",
"by",
"getting",
"the",
"Status",
"from",
"all",
"known",
"connections",
"."
] | 6e46b4f20a0b8a3ce686565440f739960e325a05 | https://github.com/honeybee/honeybee/blob/6e46b4f20a0b8a3ce686565440f739960e325a05/src/Infrastructure/DataAccess/Connector/StatusReport.php#L42-L93 | train |
milejko/mmi | src/Mmi/Cache/FileHandler.php | FileHandler._deleteNoBroadcasting | protected function _deleteNoBroadcasting($key)
{
//próba usunięcia pliku
try {
unlink($this->_cache->getConfig()->path . '/' . $key);
} catch (\Exception $e) {
//nic
}
return true;
} | php | protected function _deleteNoBroadcasting($key)
{
//próba usunięcia pliku
try {
unlink($this->_cache->getConfig()->path . '/' . $key);
} catch (\Exception $e) {
//nic
}
return true;
} | [
"protected",
"function",
"_deleteNoBroadcasting",
"(",
"$",
"key",
")",
"{",
"//próba usunięcia pliku",
"try",
"{",
"unlink",
"(",
"$",
"this",
"->",
"_cache",
"->",
"getConfig",
"(",
")",
"->",
"path",
".",
"'/'",
".",
"$",
"key",
")",
";",
"}",
"catch"... | Kasuje dane o podanym kluczu
@param string $key klucz
@return boolean | [
"Kasuje",
"dane",
"o",
"podanym",
"kluczu"
] | c1e8dddf83665ad3463ff801074aa2b0875db19b | https://github.com/milejko/mmi/blob/c1e8dddf83665ad3463ff801074aa2b0875db19b/src/Mmi/Cache/FileHandler.php#L54-L63 | train |
peakphp/framework | src/Common/ClassFinder.php | ClassFinder.findFirst | public function findFirst(string $basename): ?string
{
$basename = $this->getClassName($basename);
foreach ($this->namespaces as $ns) {
if (class_exists($ns.'\\'.$basename)) {
return $ns.'\\'.$basename;
}
}
return null;
} | php | public function findFirst(string $basename): ?string
{
$basename = $this->getClassName($basename);
foreach ($this->namespaces as $ns) {
if (class_exists($ns.'\\'.$basename)) {
return $ns.'\\'.$basename;
}
}
return null;
} | [
"public",
"function",
"findFirst",
"(",
"string",
"$",
"basename",
")",
":",
"?",
"string",
"{",
"$",
"basename",
"=",
"$",
"this",
"->",
"getClassName",
"(",
"$",
"basename",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"namespaces",
"as",
"$",
"ns",
... | Return the first class name found or false
@param string $basename
@return string|null | [
"Return",
"the",
"first",
"class",
"name",
"found",
"or",
"false"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Common/ClassFinder.php#L67-L76 | train |
milejko/mmi | src/Mmi/FileSystem.php | FileSystem.unlinkRecursive | public static function unlinkRecursive($fileName, $rootName)
{
//brak katalogu głównego
if (!file_exists($rootName)) {
return false;
}
//iteracja po katalogu głównym
foreach (new \DirectoryIterator($rootName) as $file) {
//katalog .
if ($file->isDot()) {
continue;
}
//katalog
if ($file->isDir()) {
//zejście rekurencyjne
self::unlinkRecursive($fileName, $file->getPathname());
continue;
}
//to nie jest szukany plik
if ($fileName != $file->getFilename()) {
continue;
}
//próba usunięcia
try {
unlink($file->getPathname());
} catch (\Exception $e) {
//nic
}
}
return true;
} | php | public static function unlinkRecursive($fileName, $rootName)
{
//brak katalogu głównego
if (!file_exists($rootName)) {
return false;
}
//iteracja po katalogu głównym
foreach (new \DirectoryIterator($rootName) as $file) {
//katalog .
if ($file->isDot()) {
continue;
}
//katalog
if ($file->isDir()) {
//zejście rekurencyjne
self::unlinkRecursive($fileName, $file->getPathname());
continue;
}
//to nie jest szukany plik
if ($fileName != $file->getFilename()) {
continue;
}
//próba usunięcia
try {
unlink($file->getPathname());
} catch (\Exception $e) {
//nic
}
}
return true;
} | [
"public",
"static",
"function",
"unlinkRecursive",
"(",
"$",
"fileName",
",",
"$",
"rootName",
")",
"{",
"//brak katalogu głównego",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"rootName",
")",
")",
"{",
"return",
"false",
";",
"}",
"//iteracja po katalogu głównym"... | Kasuje pliki rekurencyjnie
@param string $fileName nazwa pliku
@param string $rootName katalog główny
@return boolean | [
"Kasuje",
"pliki",
"rekurencyjnie"
] | c1e8dddf83665ad3463ff801074aa2b0875db19b | https://github.com/milejko/mmi/blob/c1e8dddf83665ad3463ff801074aa2b0875db19b/src/Mmi/FileSystem.php#L62-L92 | train |
milejko/mmi | src/Mmi/FileSystem.php | FileSystem.rmdirRecursive | public static function rmdirRecursive($dirName)
{
//próba zbadania czy jest plikiem
try {
$isFile = is_file($dirName);
} catch (\Exception $e) {
return false;
}
//zwykły plik
if ($isFile) {
//próba usunięcia
try {
unlink($dirName);
} catch (\Exception $e) {
//prawdopodobnie już usunięty
return false;
}
return true;
}
//próba otwarcia katalogu
try {
$directoryIterator = new \DirectoryIterator($dirName);
} catch (\Exception $e) {
//prawdopodobnie już usunięty
return false;
}
//iteracja po katalogu
foreach ($directoryIterator as $dir) {
//katalog .
if ($dir->isDot()) {
continue;
}
//usunięcie rekurencyjne
self::rmdirRecursive($dir->getPathname());
}
//próba usunięcia pustego katalogu
try {
rmdir($dirName);
} catch (\Exception $e) {
//prawdopodobnie już usunięty
return false;
}
return true;
} | php | public static function rmdirRecursive($dirName)
{
//próba zbadania czy jest plikiem
try {
$isFile = is_file($dirName);
} catch (\Exception $e) {
return false;
}
//zwykły plik
if ($isFile) {
//próba usunięcia
try {
unlink($dirName);
} catch (\Exception $e) {
//prawdopodobnie już usunięty
return false;
}
return true;
}
//próba otwarcia katalogu
try {
$directoryIterator = new \DirectoryIterator($dirName);
} catch (\Exception $e) {
//prawdopodobnie już usunięty
return false;
}
//iteracja po katalogu
foreach ($directoryIterator as $dir) {
//katalog .
if ($dir->isDot()) {
continue;
}
//usunięcie rekurencyjne
self::rmdirRecursive($dir->getPathname());
}
//próba usunięcia pustego katalogu
try {
rmdir($dirName);
} catch (\Exception $e) {
//prawdopodobnie już usunięty
return false;
}
return true;
} | [
"public",
"static",
"function",
"rmdirRecursive",
"(",
"$",
"dirName",
")",
"{",
"//próba zbadania czy jest plikiem",
"try",
"{",
"$",
"isFile",
"=",
"is_file",
"(",
"$",
"dirName",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"retur... | Usuwa katalog rekurencyjnie
@param string $dirName nazwa katalogu
@return boolean | [
"Usuwa",
"katalog",
"rekurencyjnie"
] | c1e8dddf83665ad3463ff801074aa2b0875db19b | https://github.com/milejko/mmi/blob/c1e8dddf83665ad3463ff801074aa2b0875db19b/src/Mmi/FileSystem.php#L99-L142 | train |
peakphp/framework | src/Di/Container.php | Container.create | public function create(string $class, $args = [], $explicit = null)
{
// check first for definition even if auto wiring is on
$def = $this->getDefinition($class);
if ($def === null && !$this->auto_wiring) {
throw new ClassDefinitionNotFoundException($class);
} elseif ($def !== null) {
return $this->binding_resolver->resolve(
$this->getDefinition($class),
$this,
$args,
$explicit
);
}
// process class dependencies with reflection
$args = $this->resolver->resolve($class, $this, $args, $explicit);
// instantiate class with resolved dependencies and args if apply
return $this->instantiator->instantiate($class, $args);
} | php | public function create(string $class, $args = [], $explicit = null)
{
// check first for definition even if auto wiring is on
$def = $this->getDefinition($class);
if ($def === null && !$this->auto_wiring) {
throw new ClassDefinitionNotFoundException($class);
} elseif ($def !== null) {
return $this->binding_resolver->resolve(
$this->getDefinition($class),
$this,
$args,
$explicit
);
}
// process class dependencies with reflection
$args = $this->resolver->resolve($class, $this, $args, $explicit);
// instantiate class with resolved dependencies and args if apply
return $this->instantiator->instantiate($class, $args);
} | [
"public",
"function",
"create",
"(",
"string",
"$",
"class",
",",
"$",
"args",
"=",
"[",
"]",
",",
"$",
"explicit",
"=",
"null",
")",
"{",
"// check first for definition even if auto wiring is on",
"$",
"def",
"=",
"$",
"this",
"->",
"getDefinition",
"(",
"$... | Instantiate a class
The generated instance is not stored, but may use stored
instance(s) as dependency when needed
@param string $class
@param array $args
@param null $explicit
@return mixed|object
@throws ClassDefinitionNotFoundException
@throws Exception\AmbiguousResolutionException
@throws Exception\InterfaceNotFoundException
@throws \ReflectionException | [
"Instantiate",
"a",
"class"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Di/Container.php#L95-L115 | train |
peakphp/framework | src/Di/Container.php | Container.resolve | public function resolve(string $definition, array $args = [])
{
$def = $this->getDefinition($definition);
if ($def === null) {
throw new ClassDefinitionNotFoundException($definition);
}
return $this->binding_resolver->resolve($def, $this, $args);
} | php | public function resolve(string $definition, array $args = [])
{
$def = $this->getDefinition($definition);
if ($def === null) {
throw new ClassDefinitionNotFoundException($definition);
}
return $this->binding_resolver->resolve($def, $this, $args);
} | [
"public",
"function",
"resolve",
"(",
"string",
"$",
"definition",
",",
"array",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"def",
"=",
"$",
"this",
"->",
"getDefinition",
"(",
"$",
"definition",
")",
";",
"if",
"(",
"$",
"def",
"===",
"null",
")",... | Resolve a stored definition
@param string $definition
@param array $args
@return mixed
@throws ClassDefinitionNotFoundException | [
"Resolve",
"a",
"stored",
"definition"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Di/Container.php#L164-L172 | train |
peakphp/framework | src/Di/Container.php | Container.get | public function get($id)
{
if ($this->has($id)) {
return $this->instances[$id];
} elseif ($this->hasAlias($id) && $this->has($this->aliases[$id])) {
return $this->instances[$this->aliases[$id]];
}
return $this->create($id);
} | php | public function get($id)
{
if ($this->has($id)) {
return $this->instances[$id];
} elseif ($this->hasAlias($id) && $this->has($this->aliases[$id])) {
return $this->instances[$this->aliases[$id]];
}
return $this->create($id);
} | [
"public",
"function",
"get",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"id",
")",
")",
"{",
"return",
"$",
"this",
"->",
"instances",
"[",
"$",
"id",
"]",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"hasAlias",
... | Get an instance if exists, otherwise try to create it return null
@param string $id
@return mixed|object
@throws ClassDefinitionNotFoundException
@throws Exception\AmbiguousResolutionException
@throws Exception\InterfaceNotFoundException
@throws \ReflectionException | [
"Get",
"an",
"instance",
"if",
"exists",
"otherwise",
"try",
"to",
"create",
"it",
"return",
"null"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Di/Container.php#L195-L204 | train |
peakphp/framework | src/Di/Container.php | Container.set | public function set(object $object, string $alias = null)
{
$class = get_class($object);
$this->instances[$class] = $object;
if (isset($alias)) {
$this->addAlias($alias, $class);
}
$interfaces = class_implements($object);
if (is_array($interfaces)) {
foreach ($interfaces as $i) {
$this->addInterface($i, $class);
}
}
return $this;
} | php | public function set(object $object, string $alias = null)
{
$class = get_class($object);
$this->instances[$class] = $object;
if (isset($alias)) {
$this->addAlias($alias, $class);
}
$interfaces = class_implements($object);
if (is_array($interfaces)) {
foreach ($interfaces as $i) {
$this->addInterface($i, $class);
}
}
return $this;
} | [
"public",
"function",
"set",
"(",
"object",
"$",
"object",
",",
"string",
"$",
"alias",
"=",
"null",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"object",
")",
";",
"$",
"this",
"->",
"instances",
"[",
"$",
"class",
"]",
"=",
"$",
"object",... | Set an object instance. Chainable
@param object $object
@param string|null $alias
@return Container | [
"Set",
"an",
"object",
"instance",
".",
"Chainable"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Di/Container.php#L213-L230 | train |
peakphp/framework | src/Di/Container.php | Container.delete | public function delete($id)
{
if ($this->has($id)) {
//remove instance
unset($this->instances[$id]);
//remove interface reference if exists
foreach ($this->interfaces as $int => $classes) {
$key = array_search($id, $classes);
if ($key !== false) {
unset($classes[$key]);
$this->interfaces[$int] = $classes;
}
}
//remove instance from singleton binding
if ($this->hasDefinition($id)) {
$definition = $this->getDefinition($id);
if ($definition instanceof Singleton) {
$definition->deleteStoredInstance();
}
}
}
return $this;
} | php | public function delete($id)
{
if ($this->has($id)) {
//remove instance
unset($this->instances[$id]);
//remove interface reference if exists
foreach ($this->interfaces as $int => $classes) {
$key = array_search($id, $classes);
if ($key !== false) {
unset($classes[$key]);
$this->interfaces[$int] = $classes;
}
}
//remove instance from singleton binding
if ($this->hasDefinition($id)) {
$definition = $this->getDefinition($id);
if ($definition instanceof Singleton) {
$definition->deleteStoredInstance();
}
}
}
return $this;
} | [
"public",
"function",
"delete",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"id",
")",
")",
"{",
"//remove instance",
"unset",
"(",
"$",
"this",
"->",
"instances",
"[",
"$",
"id",
"]",
")",
";",
"//remove interface refere... | Delete an instance if exists.
@param string $id
@return Container | [
"Delete",
"an",
"instance",
"if",
"exists",
"."
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Di/Container.php#L238-L262 | train |
peakphp/framework | src/Di/Container.php | Container.addAlias | public function addAlias(string $name, string $className)
{
$this->aliases[$name] = $className;
return $this;
} | php | public function addAlias(string $name, string $className)
{
$this->aliases[$name] = $className;
return $this;
} | [
"public",
"function",
"addAlias",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"className",
")",
"{",
"$",
"this",
"->",
"aliases",
"[",
"$",
"name",
"]",
"=",
"$",
"className",
";",
"return",
"$",
"this",
";",
"}"
] | Add a class alias
@param string $name
@param string $className
@return $this | [
"Add",
"a",
"class",
"alias"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Di/Container.php#L271-L275 | train |
peakphp/framework | src/Di/Container.php | Container.addInterface | protected function addInterface(string $name, string $class)
{
if (!$this->hasInterface($name)) {
$this->interfaces[$name] = $class;
return;
}
$interfaces = $this->getInterface($name);
if (!is_array($interfaces)) {
$interfaces = [$interfaces];
}
if (!in_array($class, $interfaces)) {
$interfaces[] = $class;
$this->interfaces[$name] = $interfaces;
}
} | php | protected function addInterface(string $name, string $class)
{
if (!$this->hasInterface($name)) {
$this->interfaces[$name] = $class;
return;
}
$interfaces = $this->getInterface($name);
if (!is_array($interfaces)) {
$interfaces = [$interfaces];
}
if (!in_array($class, $interfaces)) {
$interfaces[] = $class;
$this->interfaces[$name] = $interfaces;
}
} | [
"protected",
"function",
"addInterface",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"class",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasInterface",
"(",
"$",
"name",
")",
")",
"{",
"$",
"this",
"->",
"interfaces",
"[",
"$",
"name",
"]",
... | Catalogue also class interface when using add
@param string $name
@param string $class | [
"Catalogue",
"also",
"class",
"interface",
"when",
"using",
"add"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Di/Container.php#L314-L330 | train |
peakphp/framework | src/Di/Container.php | Container.getInterface | public function getInterface(string $name)
{
if ($this->hasInterface($name)) {
return $this->interfaces[$name];
}
return null;
} | php | public function getInterface(string $name)
{
if ($this->hasInterface($name)) {
return $this->interfaces[$name];
}
return null;
} | [
"public",
"function",
"getInterface",
"(",
"string",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasInterface",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"this",
"->",
"interfaces",
"[",
"$",
"name",
"]",
";",
"}",
"return",
"null",
... | Get an interface
@param string $name
@return mixed|null | [
"Get",
"an",
"interface"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Di/Container.php#L349-L355 | train |
peakphp/framework | src/Di/Container.php | Container.getDefinition | public function getDefinition(string $name)
{
if ($this->hasDefinition($name)) {
return $this->definitions[$name];
}
return null;
} | php | public function getDefinition(string $name)
{
if ($this->hasDefinition($name)) {
return $this->definitions[$name];
}
return null;
} | [
"public",
"function",
"getDefinition",
"(",
"string",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasDefinition",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"this",
"->",
"definitions",
"[",
"$",
"name",
"]",
";",
"}",
"return",
"null"... | Get a definition
@param string $name
@return mixed | [
"Get",
"a",
"definition"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Di/Container.php#L409-L415 | train |
peakphp/framework | src/Di/Container.php | Container.bind | public function bind(string $name, $definition)
{
$this->definitions[$name] = new Singleton($name, $definition);
return $this;
} | php | public function bind(string $name, $definition)
{
$this->definitions[$name] = new Singleton($name, $definition);
return $this;
} | [
"public",
"function",
"bind",
"(",
"string",
"$",
"name",
",",
"$",
"definition",
")",
"{",
"$",
"this",
"->",
"definitions",
"[",
"$",
"name",
"]",
"=",
"new",
"Singleton",
"(",
"$",
"name",
",",
"$",
"definition",
")",
";",
"return",
"$",
"this",
... | Add a singleton definition
@param string $name
@param mixed $definition
@return $this | [
"Add",
"a",
"singleton",
"definition"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Di/Container.php#L432-L436 | train |
peakphp/framework | src/Di/Container.php | Container.bindPrototype | public function bindPrototype(string $name, $definition)
{
$this->definitions[$name] = new Prototype($name, $definition);
return $this;
} | php | public function bindPrototype(string $name, $definition)
{
$this->definitions[$name] = new Prototype($name, $definition);
return $this;
} | [
"public",
"function",
"bindPrototype",
"(",
"string",
"$",
"name",
",",
"$",
"definition",
")",
"{",
"$",
"this",
"->",
"definitions",
"[",
"$",
"name",
"]",
"=",
"new",
"Prototype",
"(",
"$",
"name",
",",
"$",
"definition",
")",
";",
"return",
"$",
... | Add a prototype definition
@param string $name
@param mixed $definition
@return $this | [
"Add",
"a",
"prototype",
"definition"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Di/Container.php#L445-L449 | train |
peakphp/framework | src/Di/Container.php | Container.bindFactory | public function bindFactory(string $name, $definition)
{
$this->definitions[$name] = new Factory($name, $definition);
return $this;
} | php | public function bindFactory(string $name, $definition)
{
$this->definitions[$name] = new Factory($name, $definition);
return $this;
} | [
"public",
"function",
"bindFactory",
"(",
"string",
"$",
"name",
",",
"$",
"definition",
")",
"{",
"$",
"this",
"->",
"definitions",
"[",
"$",
"name",
"]",
"=",
"new",
"Factory",
"(",
"$",
"name",
",",
"$",
"definition",
")",
";",
"return",
"$",
"thi... | Add a factory definition
@param string $name
@param mixed $definition
@return $this | [
"Add",
"a",
"factory",
"definition"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Di/Container.php#L458-L462 | train |
ScriptFUSION/Mapper | src/Mapper.php | Mapper.map | public function map(array $record, $expression, $context = null, $key = null)
{
// Null or scalar values.
if (null === $expression || is_scalar($expression)) {
return $expression;
}
// Strategy.
if ($expression instanceof Strategy) {
return $this->mapStrategy($record, $expression, $context, $key);
}
// Mapping.
if ($expression instanceof Mapping) {
return $this->mapMapping($record, $expression, $context, $key);
}
// Mapping fragment.
if (is_array($expression)) {
return $this->mapFragment($record, $expression, $context, $key);
}
throw new InvalidExpressionException('Invalid strategy or mapping: "' . get_class($expression) . '".');
} | php | public function map(array $record, $expression, $context = null, $key = null)
{
// Null or scalar values.
if (null === $expression || is_scalar($expression)) {
return $expression;
}
// Strategy.
if ($expression instanceof Strategy) {
return $this->mapStrategy($record, $expression, $context, $key);
}
// Mapping.
if ($expression instanceof Mapping) {
return $this->mapMapping($record, $expression, $context, $key);
}
// Mapping fragment.
if (is_array($expression)) {
return $this->mapFragment($record, $expression, $context, $key);
}
throw new InvalidExpressionException('Invalid strategy or mapping: "' . get_class($expression) . '".');
} | [
"public",
"function",
"map",
"(",
"array",
"$",
"record",
",",
"$",
"expression",
",",
"$",
"context",
"=",
"null",
",",
"$",
"key",
"=",
"null",
")",
"{",
"// Null or scalar values.",
"if",
"(",
"null",
"===",
"$",
"expression",
"||",
"is_scalar",
"(",
... | Maps the specified record according to the specified expression type. Optionally, used-defined contextual data
may be passed to the expression. The record key is for internal use only and represents the current array key.
May be called recursively if the expression embeds more expressions.
@param array $record Record.
@param Strategy|Mapping|array|mixed $expression Expression.
@param mixed $context Optional. Contextual data.
@param string|int|null $key Internal. Record key.
@return mixed
@throws InvalidExpressionException An invalid strategy or mapping object was specified. | [
"Maps",
"the",
"specified",
"record",
"according",
"to",
"the",
"specified",
"expression",
"type",
".",
"Optionally",
"used",
"-",
"defined",
"contextual",
"data",
"may",
"be",
"passed",
"to",
"the",
"expression",
".",
"The",
"record",
"key",
"is",
"for",
"i... | 1b8326e238876db9e5f86533ef924f003316a433 | https://github.com/ScriptFUSION/Mapper/blob/1b8326e238876db9e5f86533ef924f003316a433/src/Mapper.php#L26-L49 | train |
quazardous/ImageStack | src/ImageStack/ImageBackend/CacheImageBackend.php | CacheImageBackend.getCacheId | protected function getCacheId(ImagePathInterface $path) {
if ($cid = $this->getOption('cache_prefix')) {
$cid .= DIRECTORY_SEPARATOR;
}
$cid .= $path->getPath();
if ($sanitizer = $this->getOption('cache_id_sanitizer')) {
$cid = call_user_func($sanitizer, $cid);
}
return $cid;
} | php | protected function getCacheId(ImagePathInterface $path) {
if ($cid = $this->getOption('cache_prefix')) {
$cid .= DIRECTORY_SEPARATOR;
}
$cid .= $path->getPath();
if ($sanitizer = $this->getOption('cache_id_sanitizer')) {
$cid = call_user_func($sanitizer, $cid);
}
return $cid;
} | [
"protected",
"function",
"getCacheId",
"(",
"ImagePathInterface",
"$",
"path",
")",
"{",
"if",
"(",
"$",
"cid",
"=",
"$",
"this",
"->",
"getOption",
"(",
"'cache_prefix'",
")",
")",
"{",
"$",
"cid",
".=",
"DIRECTORY_SEPARATOR",
";",
"}",
"$",
"cid",
".="... | Get the cache ID from the path and can do sanitize stuff.
@param ImagePathInterface $path
@return string | [
"Get",
"the",
"cache",
"ID",
"from",
"the",
"path",
"and",
"can",
"do",
"sanitize",
"stuff",
"."
] | bca5632edfc7703300407984bbaefb3c91c1560c | https://github.com/quazardous/ImageStack/blob/bca5632edfc7703300407984bbaefb3c91c1560c/src/ImageStack/ImageBackend/CacheImageBackend.php#L50-L59 | train |
quazardous/ImageStack | src/ImageStack/OptionnableTrait.php | OptionnableTrait.setOptions | public function setOptions(array $options, $merge = true)
{
if ($merge) {
$this->options = array_replace($this->options, $options);
} else {
$this->options = $options;
}
} | php | public function setOptions(array $options, $merge = true)
{
if ($merge) {
$this->options = array_replace($this->options, $options);
} else {
$this->options = $options;
}
} | [
"public",
"function",
"setOptions",
"(",
"array",
"$",
"options",
",",
"$",
"merge",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"merge",
")",
"{",
"$",
"this",
"->",
"options",
"=",
"array_replace",
"(",
"$",
"this",
"->",
"options",
",",
"$",
"options",... | Set all options.
@param array $options | [
"Set",
"all",
"options",
"."
] | bca5632edfc7703300407984bbaefb3c91c1560c | https://github.com/quazardous/ImageStack/blob/bca5632edfc7703300407984bbaefb3c91c1560c/src/ImageStack/OptionnableTrait.php#L15-L22 | train |
quazardous/ImageStack | src/ImageStack/OptionnableTrait.php | OptionnableTrait.getOption | public function getOption($name, $default = null)
{
if (!isset($this->options[$name])) {
if (is_callable($default)) {
$default = call_user_func($default);
} if ($default instanceof \Exception) {
throw $default;
}
return $default;
}
return $this->options[$name];
} | php | public function getOption($name, $default = null)
{
if (!isset($this->options[$name])) {
if (is_callable($default)) {
$default = call_user_func($default);
} if ($default instanceof \Exception) {
throw $default;
}
return $default;
}
return $this->options[$name];
} | [
"public",
"function",
"getOption",
"(",
"$",
"name",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"$",
"name",
"]",
")",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"default",
")",... | Get option value or default or throws exception.
@param string $name
@param mixed|callable|\Exception $default
@throws \Exception
@return mixed | [
"Get",
"option",
"value",
"or",
"default",
"or",
"throws",
"exception",
"."
] | bca5632edfc7703300407984bbaefb3c91c1560c | https://github.com/quazardous/ImageStack/blob/bca5632edfc7703300407984bbaefb3c91c1560c/src/ImageStack/OptionnableTrait.php#L50-L61 | train |
CVO-Technologies/cakephp-gearman | src/JobAwareTrait.php | JobAwareTrait.gearmanClient | public function gearmanClient()
{
$client = new GearmanClient();
$servers = static::_getGearmanServers();
$client->addServers(implode(',', $servers));
return $client;
} | php | public function gearmanClient()
{
$client = new GearmanClient();
$servers = static::_getGearmanServers();
$client->addServers(implode(',', $servers));
return $client;
} | [
"public",
"function",
"gearmanClient",
"(",
")",
"{",
"$",
"client",
"=",
"new",
"GearmanClient",
"(",
")",
";",
"$",
"servers",
"=",
"static",
"::",
"_getGearmanServers",
"(",
")",
";",
"$",
"client",
"->",
"addServers",
"(",
"implode",
"(",
"','",
",",... | Setup a GearmanClient object configured
with the servers from the configuration.
@return GearmanClient | [
"Setup",
"a",
"GearmanClient",
"object",
"configured",
"with",
"the",
"servers",
"from",
"the",
"configuration",
"."
] | 538f060a617165482159c4f5f42d4b0562a14194 | https://github.com/CVO-Technologies/cakephp-gearman/blob/538f060a617165482159c4f5f42d4b0562a14194/src/JobAwareTrait.php#L17-L26 | train |
CVO-Technologies/cakephp-gearman | src/JobAwareTrait.php | JobAwareTrait.gearmanWorker | public function gearmanWorker()
{
$client = new GearmanWorker();
$servers = static::_getGearmanServers();
$client->addServers(implode(',', $servers));
return $client;
} | php | public function gearmanWorker()
{
$client = new GearmanWorker();
$servers = static::_getGearmanServers();
$client->addServers(implode(',', $servers));
return $client;
} | [
"public",
"function",
"gearmanWorker",
"(",
")",
"{",
"$",
"client",
"=",
"new",
"GearmanWorker",
"(",
")",
";",
"$",
"servers",
"=",
"static",
"::",
"_getGearmanServers",
"(",
")",
";",
"$",
"client",
"->",
"addServers",
"(",
"implode",
"(",
"','",
",",... | Setup a GearmanWorker object configured
with the servers from the configuration.
@return GearmanWorker | [
"Setup",
"a",
"GearmanWorker",
"object",
"configured",
"with",
"the",
"servers",
"from",
"the",
"configuration",
"."
] | 538f060a617165482159c4f5f42d4b0562a14194 | https://github.com/CVO-Technologies/cakephp-gearman/blob/538f060a617165482159c4f5f42d4b0562a14194/src/JobAwareTrait.php#L34-L43 | train |
CVO-Technologies/cakephp-gearman | src/JobAwareTrait.php | JobAwareTrait.execute | public function execute($name, $workload, $background = true, $priority = Gearman::PRIORITY_NORMAL)
{
$func = 'do';
switch ($priority) {
case Gearman::PRIORITY_LOW:
$func .= 'Low';
break;
case Gearman::PRIORITY_HIGH:
$func .= 'High';
break;
case Gearman::PRIORITY_NORMAL:
if (!$background) {
$func .= 'Normal';
}
break;
}
$func .= ($background) ? 'Background' : '';
if (is_array($workload) || is_object($workload)) {
$workload = serialize($workload);
}
$response = $this->gearmanClient()->{$func}($name, $workload);
DebugJob::add($name, $workload, $background, $priority);
if ($background) {
return $response;
}
$serializedResponse = unserialize($response);
if ($serializedResponse !== false) {
$response = $serializedResponse;
}
return $response;
} | php | public function execute($name, $workload, $background = true, $priority = Gearman::PRIORITY_NORMAL)
{
$func = 'do';
switch ($priority) {
case Gearman::PRIORITY_LOW:
$func .= 'Low';
break;
case Gearman::PRIORITY_HIGH:
$func .= 'High';
break;
case Gearman::PRIORITY_NORMAL:
if (!$background) {
$func .= 'Normal';
}
break;
}
$func .= ($background) ? 'Background' : '';
if (is_array($workload) || is_object($workload)) {
$workload = serialize($workload);
}
$response = $this->gearmanClient()->{$func}($name, $workload);
DebugJob::add($name, $workload, $background, $priority);
if ($background) {
return $response;
}
$serializedResponse = unserialize($response);
if ($serializedResponse !== false) {
$response = $serializedResponse;
}
return $response;
} | [
"public",
"function",
"execute",
"(",
"$",
"name",
",",
"$",
"workload",
",",
"$",
"background",
"=",
"true",
",",
"$",
"priority",
"=",
"Gearman",
"::",
"PRIORITY_NORMAL",
")",
"{",
"$",
"func",
"=",
"'do'",
";",
"switch",
"(",
"$",
"priority",
")",
... | Execute a job by sending it to the
Gearman server using the GearmanClient.
Example for a background job with normal priority:
$this->execute('sleep', ['seconds' => 60]);
Example for a background job with HIGH priority:
$this->execute('sleep', ['seconds' => 60], true, Gearman::PRIORITY_HIGH);
Example for a normal job with HIGH priority:
$this->execute('sleep', ['seconds' => 60], false, Gearman::PRIORITY_HIGH);
@param string $name Name of the job to execute
@param mixed $workload Any type of workload is supported (as long as it's serializable)
@param bool $background If it's a background job
@param int $priority A priority level from Gearman::PRIORTIY_*
@return mixed The response from the job or the job id in case of a background job | [
"Execute",
"a",
"job",
"by",
"sending",
"it",
"to",
"the",
"Gearman",
"server",
"using",
"the",
"GearmanClient",
"."
] | 538f060a617165482159c4f5f42d4b0562a14194 | https://github.com/CVO-Technologies/cakephp-gearman/blob/538f060a617165482159c4f5f42d4b0562a14194/src/JobAwareTrait.php#L64-L101 | train |
peakphp/framework | src/Di/ClassInspector.php | ClassInspector.inspect | public function inspect($class, $method = '__construct')
{
if (is_string($class) && !class_exists($class)) {
throw new ClassNotFoundException($class);
}
$dependencies = [];
$r = new ReflectionClass($class);
if (!$r->hasMethod($method)) {
if ($method === '__construct') {
return $dependencies;
}
throw new MethodNotFoundException($r->getName(), $method);
}
$rp = $r->getMethod($method)->getParameters();
foreach ($rp as $p) {
$prop = $p->name;
$dependencies[$prop] = [];
$dependencies[$prop]['optional'] = $p->isOptional();
try {
$class = $p->getClass();
if (isset($class)) {
$dependencies[$prop]['class'] = $class->name;
}
} catch (\Exception $e) {
$dependencies[$prop]['error'] = $e->getMessage();
}
}
return $dependencies;
} | php | public function inspect($class, $method = '__construct')
{
if (is_string($class) && !class_exists($class)) {
throw new ClassNotFoundException($class);
}
$dependencies = [];
$r = new ReflectionClass($class);
if (!$r->hasMethod($method)) {
if ($method === '__construct') {
return $dependencies;
}
throw new MethodNotFoundException($r->getName(), $method);
}
$rp = $r->getMethod($method)->getParameters();
foreach ($rp as $p) {
$prop = $p->name;
$dependencies[$prop] = [];
$dependencies[$prop]['optional'] = $p->isOptional();
try {
$class = $p->getClass();
if (isset($class)) {
$dependencies[$prop]['class'] = $class->name;
}
} catch (\Exception $e) {
$dependencies[$prop]['error'] = $e->getMessage();
}
}
return $dependencies;
} | [
"public",
"function",
"inspect",
"(",
"$",
"class",
",",
"$",
"method",
"=",
"'__construct'",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"class",
")",
"&&",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"ClassNotFoundException",... | Get class dependencies method.
By default, method is the constructor itself
@param mixed $class
@param string $method
@return array
@throws Exception | [
"Get",
"class",
"dependencies",
"method",
".",
"By",
"default",
"method",
"is",
"the",
"constructor",
"itself"
] | 412c13c2a0f165ee645eb3636f23a74a81429d3a | https://github.com/peakphp/framework/blob/412c13c2a0f165ee645eb3636f23a74a81429d3a/src/Di/ClassInspector.php#L26-L61 | train |
milejko/mmi | src/Mmi/Http/Response.php | Response.setCode | public function setCode($code, $replace = false)
{
//kod nie istnieje
if (!($message = ResponseTypes::getMessageByCode($code))) {
//wyjątek o nieistniejącym kodzie HTTP
throw new HttpException('HTTP code not found');
}
//zapis kodu
$this->_code = $code;
//wysłanie nagłówka z kodem
return $this->setHeader('HTTP/1.1 ' . $code . ' ' . $message, null, $replace);
} | php | public function setCode($code, $replace = false)
{
//kod nie istnieje
if (!($message = ResponseTypes::getMessageByCode($code))) {
//wyjątek o nieistniejącym kodzie HTTP
throw new HttpException('HTTP code not found');
}
//zapis kodu
$this->_code = $code;
//wysłanie nagłówka z kodem
return $this->setHeader('HTTP/1.1 ' . $code . ' ' . $message, null, $replace);
} | [
"public",
"function",
"setCode",
"(",
"$",
"code",
",",
"$",
"replace",
"=",
"false",
")",
"{",
"//kod nie istnieje",
"if",
"(",
"!",
"(",
"$",
"message",
"=",
"ResponseTypes",
"::",
"getMessageByCode",
"(",
"$",
"code",
")",
")",
")",
"{",
"//wyjątek o ... | Ustawia kod odpowiedzi
@param int $code kod
@param boolean $replace zastąpienie
@return \Mmi\Http\Response | [
"Ustawia",
"kod",
"odpowiedzi"
] | c1e8dddf83665ad3463ff801074aa2b0875db19b | https://github.com/milejko/mmi/blob/c1e8dddf83665ad3463ff801074aa2b0875db19b/src/Mmi/Http/Response.php#L96-L107 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.