id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
|---|---|---|---|---|---|---|---|---|---|---|---|
227,200
|
secit-pl/schema-org
|
SchemaOrg/Generator.php
|
Generator.generateProperties
|
protected function generateProperties(array $schema)
{
$directory = $this->getMappingDirectory('Property');
$this->generateAbstractProperty($directory);
foreach ($schema['properties'] as $property => $data) {
$this->generateProperty($property, $data, $directory, $schema['datatypes']);
}
}
|
php
|
protected function generateProperties(array $schema)
{
$directory = $this->getMappingDirectory('Property');
$this->generateAbstractProperty($directory);
foreach ($schema['properties'] as $property => $data) {
$this->generateProperty($property, $data, $directory, $schema['datatypes']);
}
}
|
[
"protected",
"function",
"generateProperties",
"(",
"array",
"$",
"schema",
")",
"{",
"$",
"directory",
"=",
"$",
"this",
"->",
"getMappingDirectory",
"(",
"'Property'",
")",
";",
"$",
"this",
"->",
"generateAbstractProperty",
"(",
"$",
"directory",
")",
";",
"foreach",
"(",
"$",
"schema",
"[",
"'properties'",
"]",
"as",
"$",
"property",
"=>",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"generateProperty",
"(",
"$",
"property",
",",
"$",
"data",
",",
"$",
"directory",
",",
"$",
"schema",
"[",
"'datatypes'",
"]",
")",
";",
"}",
"}"
] |
Generate properties.
@param array $schema
|
[
"Generate",
"properties",
"."
] |
5d1656153b5eebf7227cc72dd77562e288157346
|
https://github.com/secit-pl/schema-org/blob/5d1656153b5eebf7227cc72dd77562e288157346/SchemaOrg/Generator.php#L240-L247
|
227,201
|
secit-pl/schema-org
|
SchemaOrg/Generator.php
|
Generator.generateTypes
|
protected function generateTypes(array $schema)
{
$directory = $this->getMappingDirectory('Type');
foreach ($schema['types'] as $type => $data) {
$this->generateType($type, $data, $directory, $schema);
}
}
|
php
|
protected function generateTypes(array $schema)
{
$directory = $this->getMappingDirectory('Type');
foreach ($schema['types'] as $type => $data) {
$this->generateType($type, $data, $directory, $schema);
}
}
|
[
"protected",
"function",
"generateTypes",
"(",
"array",
"$",
"schema",
")",
"{",
"$",
"directory",
"=",
"$",
"this",
"->",
"getMappingDirectory",
"(",
"'Type'",
")",
";",
"foreach",
"(",
"$",
"schema",
"[",
"'types'",
"]",
"as",
"$",
"type",
"=>",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"generateType",
"(",
"$",
"type",
",",
"$",
"data",
",",
"$",
"directory",
",",
"$",
"schema",
")",
";",
"}",
"}"
] |
Generate types.
@param array $schema
|
[
"Generate",
"types",
"."
] |
5d1656153b5eebf7227cc72dd77562e288157346
|
https://github.com/secit-pl/schema-org/blob/5d1656153b5eebf7227cc72dd77562e288157346/SchemaOrg/Generator.php#L254-L260
|
227,202
|
secit-pl/schema-org
|
SchemaOrg/Generator.php
|
Generator.generateDataType
|
protected function generateDataType($dataType, array $data, $directory)
{
$dataType = $this->getDataTypeClassName($dataType);
$class = new PhpClass();
$class
->setQualifiedName('SecIT\\SchemaOrg\\Mapping\\DataType\\'.$dataType)
->setDescription('Class '.$dataType.'.')
->setMethod(PhpMethod::create('getSchemaUrl')
->setDescription('Get schema URL.')
->setType('string')
->setBody('return \''.$data['url'].'\';')
)
;
if ($data['ancestors']) {
$class->setParentClassName($this->getDataTypeClassName(end($data['ancestors'])));
$class->setDescription($class->getDescription()."\n\n".'@method '.$dataType.' setValue($value)');
} else {
$constructorBody = 'if ($value !== null) {'."\n";
$constructorBody .= ' $this->setValue($value);'."\n";
$constructorBody .= '}';
$class
->addInterface($this->dataTypeInterfaceName)
->setProperty(PhpProperty::create('value')
->setVisibility('private')
->setType('string')
)
->setMethod(PhpMethod::create('__construct')
->setDescription($dataType.' constructor.')
->addParameter(PhpParameter::create('value')
->setType('string')
->setValue(null)
)
->setBody($constructorBody)
)
->setMethod(PhpMethod::create('setValue')
->setDescription('Set value.')
->addParameter(PhpParameter::create('value')
->setType('string')
)
->setType($dataType)
->setBody('$this->value = $value;'."\n\n".'return $this;')
)
->setMethod(PhpMethod::create('getValue')
->setDescription('Get value.')
->setBody('return $this->value;')
)
;
}
$generator = new CodeGenerator();
$code = $generator->generate($class);
file_put_contents($directory.$dataType.'.php', "<?php\n\n".$code);
}
|
php
|
protected function generateDataType($dataType, array $data, $directory)
{
$dataType = $this->getDataTypeClassName($dataType);
$class = new PhpClass();
$class
->setQualifiedName('SecIT\\SchemaOrg\\Mapping\\DataType\\'.$dataType)
->setDescription('Class '.$dataType.'.')
->setMethod(PhpMethod::create('getSchemaUrl')
->setDescription('Get schema URL.')
->setType('string')
->setBody('return \''.$data['url'].'\';')
)
;
if ($data['ancestors']) {
$class->setParentClassName($this->getDataTypeClassName(end($data['ancestors'])));
$class->setDescription($class->getDescription()."\n\n".'@method '.$dataType.' setValue($value)');
} else {
$constructorBody = 'if ($value !== null) {'."\n";
$constructorBody .= ' $this->setValue($value);'."\n";
$constructorBody .= '}';
$class
->addInterface($this->dataTypeInterfaceName)
->setProperty(PhpProperty::create('value')
->setVisibility('private')
->setType('string')
)
->setMethod(PhpMethod::create('__construct')
->setDescription($dataType.' constructor.')
->addParameter(PhpParameter::create('value')
->setType('string')
->setValue(null)
)
->setBody($constructorBody)
)
->setMethod(PhpMethod::create('setValue')
->setDescription('Set value.')
->addParameter(PhpParameter::create('value')
->setType('string')
)
->setType($dataType)
->setBody('$this->value = $value;'."\n\n".'return $this;')
)
->setMethod(PhpMethod::create('getValue')
->setDescription('Get value.')
->setBody('return $this->value;')
)
;
}
$generator = new CodeGenerator();
$code = $generator->generate($class);
file_put_contents($directory.$dataType.'.php', "<?php\n\n".$code);
}
|
[
"protected",
"function",
"generateDataType",
"(",
"$",
"dataType",
",",
"array",
"$",
"data",
",",
"$",
"directory",
")",
"{",
"$",
"dataType",
"=",
"$",
"this",
"->",
"getDataTypeClassName",
"(",
"$",
"dataType",
")",
";",
"$",
"class",
"=",
"new",
"PhpClass",
"(",
")",
";",
"$",
"class",
"->",
"setQualifiedName",
"(",
"'SecIT\\\\SchemaOrg\\\\Mapping\\\\DataType\\\\'",
".",
"$",
"dataType",
")",
"->",
"setDescription",
"(",
"'Class '",
".",
"$",
"dataType",
".",
"'.'",
")",
"->",
"setMethod",
"(",
"PhpMethod",
"::",
"create",
"(",
"'getSchemaUrl'",
")",
"->",
"setDescription",
"(",
"'Get schema URL.'",
")",
"->",
"setType",
"(",
"'string'",
")",
"->",
"setBody",
"(",
"'return \\''",
".",
"$",
"data",
"[",
"'url'",
"]",
".",
"'\\';'",
")",
")",
";",
"if",
"(",
"$",
"data",
"[",
"'ancestors'",
"]",
")",
"{",
"$",
"class",
"->",
"setParentClassName",
"(",
"$",
"this",
"->",
"getDataTypeClassName",
"(",
"end",
"(",
"$",
"data",
"[",
"'ancestors'",
"]",
")",
")",
")",
";",
"$",
"class",
"->",
"setDescription",
"(",
"$",
"class",
"->",
"getDescription",
"(",
")",
".",
"\"\\n\\n\"",
".",
"'@method '",
".",
"$",
"dataType",
".",
"' setValue($value)'",
")",
";",
"}",
"else",
"{",
"$",
"constructorBody",
"=",
"'if ($value !== null) {'",
".",
"\"\\n\"",
";",
"$",
"constructorBody",
".=",
"' $this->setValue($value);'",
".",
"\"\\n\"",
";",
"$",
"constructorBody",
".=",
"'}'",
";",
"$",
"class",
"->",
"addInterface",
"(",
"$",
"this",
"->",
"dataTypeInterfaceName",
")",
"->",
"setProperty",
"(",
"PhpProperty",
"::",
"create",
"(",
"'value'",
")",
"->",
"setVisibility",
"(",
"'private'",
")",
"->",
"setType",
"(",
"'string'",
")",
")",
"->",
"setMethod",
"(",
"PhpMethod",
"::",
"create",
"(",
"'__construct'",
")",
"->",
"setDescription",
"(",
"$",
"dataType",
".",
"' constructor.'",
")",
"->",
"addParameter",
"(",
"PhpParameter",
"::",
"create",
"(",
"'value'",
")",
"->",
"setType",
"(",
"'string'",
")",
"->",
"setValue",
"(",
"null",
")",
")",
"->",
"setBody",
"(",
"$",
"constructorBody",
")",
")",
"->",
"setMethod",
"(",
"PhpMethod",
"::",
"create",
"(",
"'setValue'",
")",
"->",
"setDescription",
"(",
"'Set value.'",
")",
"->",
"addParameter",
"(",
"PhpParameter",
"::",
"create",
"(",
"'value'",
")",
"->",
"setType",
"(",
"'string'",
")",
")",
"->",
"setType",
"(",
"$",
"dataType",
")",
"->",
"setBody",
"(",
"'$this->value = $value;'",
".",
"\"\\n\\n\"",
".",
"'return $this;'",
")",
")",
"->",
"setMethod",
"(",
"PhpMethod",
"::",
"create",
"(",
"'getValue'",
")",
"->",
"setDescription",
"(",
"'Get value.'",
")",
"->",
"setBody",
"(",
"'return $this->value;'",
")",
")",
";",
"}",
"$",
"generator",
"=",
"new",
"CodeGenerator",
"(",
")",
";",
"$",
"code",
"=",
"$",
"generator",
"->",
"generate",
"(",
"$",
"class",
")",
";",
"file_put_contents",
"(",
"$",
"directory",
".",
"$",
"dataType",
".",
"'.php'",
",",
"\"<?php\\n\\n\"",
".",
"$",
"code",
")",
";",
"}"
] |
Generate data type.
@param string $dataType
@param array $data
@param string $directory
|
[
"Generate",
"data",
"type",
"."
] |
5d1656153b5eebf7227cc72dd77562e288157346
|
https://github.com/secit-pl/schema-org/blob/5d1656153b5eebf7227cc72dd77562e288157346/SchemaOrg/Generator.php#L269-L325
|
227,203
|
secit-pl/schema-org
|
SchemaOrg/Generator.php
|
Generator.generateAbstractProperty
|
protected function generateAbstractProperty($directory)
{
$class = new PhpClass();
$class
->setDescription('Abstract class AbstractProperty.')
->setQualifiedName('SecIT\\SchemaOrg\\Mapping\\Property\\AbstractProperty')
->addInterface($this->propertyInterfaceName)
->setAbstract(true)
;
$constructorBody = 'if ($value !== null) {'."\n";
$constructorBody .= ' $this->setValue($value);'."\n";
$constructorBody .= '}';
$setterBody = 'if (is_array($value)) {'."\n";
$setterBody .= ' foreach ($value as $singleValue) {'."\n";
$setterBody .= ' if (!$this->isValueValid($singleValue)) {'."\n";
$setterBody .= ' throw new \\Exception(\'Unexpected value type\');'."\n";
$setterBody .= ' }'."\n";
$setterBody .= ' }'."\n";
$setterBody .= '} elseif (!$this->isValueValid($value)) {'."\n";
$setterBody .= ' throw new \\Exception(\'Unexpected value type\');'."\n";
$setterBody .= '}'."\n";
$setterBody .= '$this->value = $value;';
$class
->setProperty(PhpProperty::create('value')
->setVisibility('private')
->setType('string')
)
->setMethod(PhpMethod::create('__construct')
->setDescription('AbstractProperty constructor.')
->addParameter(PhpParameter::create('value')
->setType('string')
->setValue(null)
)
->setBody($constructorBody)
)
->setMethod(PhpMethod::create('setValue')
->setDescription('Set value.')
->addParameter(PhpParameter::create('value')
->setType('string')
)
->setType('AbstractProperty')
->setBody($setterBody."\n\n".'return $this;')
)
->setMethod(PhpMethod::create('getValue')
->setDescription('Get value.')
->setType('string')
->setBody('return $this->value;')
)
->setMethod(PhpMethod::create('isValueValid')
->setDescription('Check is value valid.')
->addParameter(PhpParameter::create('value')
->setType('string')
)
->setType('bool')
->setAbstract(true)
)
->setMethod(PhpMethod::create('getSchemaUrl')
->setDescription('Get schema URL.')
->setType('string')
->setAbstract(true)
)
;
$generator = new CodeGenerator();
$code = $generator->generate($class);
file_put_contents($directory.'AbstractProperty.php', "<?php\n\n".$code);
}
|
php
|
protected function generateAbstractProperty($directory)
{
$class = new PhpClass();
$class
->setDescription('Abstract class AbstractProperty.')
->setQualifiedName('SecIT\\SchemaOrg\\Mapping\\Property\\AbstractProperty')
->addInterface($this->propertyInterfaceName)
->setAbstract(true)
;
$constructorBody = 'if ($value !== null) {'."\n";
$constructorBody .= ' $this->setValue($value);'."\n";
$constructorBody .= '}';
$setterBody = 'if (is_array($value)) {'."\n";
$setterBody .= ' foreach ($value as $singleValue) {'."\n";
$setterBody .= ' if (!$this->isValueValid($singleValue)) {'."\n";
$setterBody .= ' throw new \\Exception(\'Unexpected value type\');'."\n";
$setterBody .= ' }'."\n";
$setterBody .= ' }'."\n";
$setterBody .= '} elseif (!$this->isValueValid($value)) {'."\n";
$setterBody .= ' throw new \\Exception(\'Unexpected value type\');'."\n";
$setterBody .= '}'."\n";
$setterBody .= '$this->value = $value;';
$class
->setProperty(PhpProperty::create('value')
->setVisibility('private')
->setType('string')
)
->setMethod(PhpMethod::create('__construct')
->setDescription('AbstractProperty constructor.')
->addParameter(PhpParameter::create('value')
->setType('string')
->setValue(null)
)
->setBody($constructorBody)
)
->setMethod(PhpMethod::create('setValue')
->setDescription('Set value.')
->addParameter(PhpParameter::create('value')
->setType('string')
)
->setType('AbstractProperty')
->setBody($setterBody."\n\n".'return $this;')
)
->setMethod(PhpMethod::create('getValue')
->setDescription('Get value.')
->setType('string')
->setBody('return $this->value;')
)
->setMethod(PhpMethod::create('isValueValid')
->setDescription('Check is value valid.')
->addParameter(PhpParameter::create('value')
->setType('string')
)
->setType('bool')
->setAbstract(true)
)
->setMethod(PhpMethod::create('getSchemaUrl')
->setDescription('Get schema URL.')
->setType('string')
->setAbstract(true)
)
;
$generator = new CodeGenerator();
$code = $generator->generate($class);
file_put_contents($directory.'AbstractProperty.php', "<?php\n\n".$code);
}
|
[
"protected",
"function",
"generateAbstractProperty",
"(",
"$",
"directory",
")",
"{",
"$",
"class",
"=",
"new",
"PhpClass",
"(",
")",
";",
"$",
"class",
"->",
"setDescription",
"(",
"'Abstract class AbstractProperty.'",
")",
"->",
"setQualifiedName",
"(",
"'SecIT\\\\SchemaOrg\\\\Mapping\\\\Property\\\\AbstractProperty'",
")",
"->",
"addInterface",
"(",
"$",
"this",
"->",
"propertyInterfaceName",
")",
"->",
"setAbstract",
"(",
"true",
")",
";",
"$",
"constructorBody",
"=",
"'if ($value !== null) {'",
".",
"\"\\n\"",
";",
"$",
"constructorBody",
".=",
"' $this->setValue($value);'",
".",
"\"\\n\"",
";",
"$",
"constructorBody",
".=",
"'}'",
";",
"$",
"setterBody",
"=",
"'if (is_array($value)) {'",
".",
"\"\\n\"",
";",
"$",
"setterBody",
".=",
"' foreach ($value as $singleValue) {'",
".",
"\"\\n\"",
";",
"$",
"setterBody",
".=",
"' if (!$this->isValueValid($singleValue)) {'",
".",
"\"\\n\"",
";",
"$",
"setterBody",
".=",
"' throw new \\\\Exception(\\'Unexpected value type\\');'",
".",
"\"\\n\"",
";",
"$",
"setterBody",
".=",
"' }'",
".",
"\"\\n\"",
";",
"$",
"setterBody",
".=",
"' }'",
".",
"\"\\n\"",
";",
"$",
"setterBody",
".=",
"'} elseif (!$this->isValueValid($value)) {'",
".",
"\"\\n\"",
";",
"$",
"setterBody",
".=",
"' throw new \\\\Exception(\\'Unexpected value type\\');'",
".",
"\"\\n\"",
";",
"$",
"setterBody",
".=",
"'}'",
".",
"\"\\n\"",
";",
"$",
"setterBody",
".=",
"'$this->value = $value;'",
";",
"$",
"class",
"->",
"setProperty",
"(",
"PhpProperty",
"::",
"create",
"(",
"'value'",
")",
"->",
"setVisibility",
"(",
"'private'",
")",
"->",
"setType",
"(",
"'string'",
")",
")",
"->",
"setMethod",
"(",
"PhpMethod",
"::",
"create",
"(",
"'__construct'",
")",
"->",
"setDescription",
"(",
"'AbstractProperty constructor.'",
")",
"->",
"addParameter",
"(",
"PhpParameter",
"::",
"create",
"(",
"'value'",
")",
"->",
"setType",
"(",
"'string'",
")",
"->",
"setValue",
"(",
"null",
")",
")",
"->",
"setBody",
"(",
"$",
"constructorBody",
")",
")",
"->",
"setMethod",
"(",
"PhpMethod",
"::",
"create",
"(",
"'setValue'",
")",
"->",
"setDescription",
"(",
"'Set value.'",
")",
"->",
"addParameter",
"(",
"PhpParameter",
"::",
"create",
"(",
"'value'",
")",
"->",
"setType",
"(",
"'string'",
")",
")",
"->",
"setType",
"(",
"'AbstractProperty'",
")",
"->",
"setBody",
"(",
"$",
"setterBody",
".",
"\"\\n\\n\"",
".",
"'return $this;'",
")",
")",
"->",
"setMethod",
"(",
"PhpMethod",
"::",
"create",
"(",
"'getValue'",
")",
"->",
"setDescription",
"(",
"'Get value.'",
")",
"->",
"setType",
"(",
"'string'",
")",
"->",
"setBody",
"(",
"'return $this->value;'",
")",
")",
"->",
"setMethod",
"(",
"PhpMethod",
"::",
"create",
"(",
"'isValueValid'",
")",
"->",
"setDescription",
"(",
"'Check is value valid.'",
")",
"->",
"addParameter",
"(",
"PhpParameter",
"::",
"create",
"(",
"'value'",
")",
"->",
"setType",
"(",
"'string'",
")",
")",
"->",
"setType",
"(",
"'bool'",
")",
"->",
"setAbstract",
"(",
"true",
")",
")",
"->",
"setMethod",
"(",
"PhpMethod",
"::",
"create",
"(",
"'getSchemaUrl'",
")",
"->",
"setDescription",
"(",
"'Get schema URL.'",
")",
"->",
"setType",
"(",
"'string'",
")",
"->",
"setAbstract",
"(",
"true",
")",
")",
";",
"$",
"generator",
"=",
"new",
"CodeGenerator",
"(",
")",
";",
"$",
"code",
"=",
"$",
"generator",
"->",
"generate",
"(",
"$",
"class",
")",
";",
"file_put_contents",
"(",
"$",
"directory",
".",
"'AbstractProperty.php'",
",",
"\"<?php\\n\\n\"",
".",
"$",
"code",
")",
";",
"}"
] |
Generate abstract property.
@param string $directory
|
[
"Generate",
"abstract",
"property",
"."
] |
5d1656153b5eebf7227cc72dd77562e288157346
|
https://github.com/secit-pl/schema-org/blob/5d1656153b5eebf7227cc72dd77562e288157346/SchemaOrg/Generator.php#L332-L402
|
227,204
|
secit-pl/schema-org
|
SchemaOrg/Generator.php
|
Generator.generateProperty
|
protected function generateProperty($propertyName, array $data, $directory, array $dataTypes)
{
$property = $this->getPropertyClassName($propertyName);
$class = new PhpClass();
$class
->setQualifiedName('SecIT\\SchemaOrg\\Mapping\\Property\\'.$property)
->setParentClassName('AbstractProperty')
->setDescription($property.' class.'."\n\n".'@method '.$property.' setValue($value)')
->setMethod(PhpMethod::create('getSchemaUrl')
->setDescription('Get schema URL.')
->setType('string')
->setBody('return \''.$data['url'].'\';')
)
;
if ($this->backwardCompatibility && !$this->php7ClassNames) {
$this->php7ClassNames = true;
$deprecatedMessage = 'This class is deprecated and will be removed in release 3.4. Use SecIT\\SchemaOrg\\Mapping\\Property\\'.$this->getPropertyClassName($propertyName).' instead.';
$this->php7ClassNames = false;
$class->setDescription($class->getDescription()."\n\n".'@deprecated '.$deprecatedMessage);
}
$instanceCheckConditions = [];
foreach ($data['ranges'] as $range) {
if (isset($dataTypes[$range])) {
$class->addUseStatement('SecIT\\SchemaOrg\\Mapping\\DataType');
$instanceCheckConditions[] = '$value instanceof DataType\\'.$this->getDataTypeClassName($range);
} else {
$class->addUseStatement('SecIT\\SchemaOrg\\Mapping\\Type');
$instanceCheckConditions[] = '$value instanceof Type\\'.$this->getTypeClassName($range);
}
}
// if no conditions than always return true
if (!$instanceCheckConditions) {
$instanceCheckConditions[] = 'true';
}
$class
->setMethod(PhpMethod::create('isValueValid')
->setDescription('Check is value valid.')
->addParameter(PhpParameter::create('value')
->setType('string')
)
->setType('bool')
->setBody('return '.implode(' || ', $instanceCheckConditions).';')
)
;
$generator = new CodeGenerator();
$code = $generator->generate($class);
file_put_contents($directory.$property.'.php', "<?php\n\n".$code);
}
|
php
|
protected function generateProperty($propertyName, array $data, $directory, array $dataTypes)
{
$property = $this->getPropertyClassName($propertyName);
$class = new PhpClass();
$class
->setQualifiedName('SecIT\\SchemaOrg\\Mapping\\Property\\'.$property)
->setParentClassName('AbstractProperty')
->setDescription($property.' class.'."\n\n".'@method '.$property.' setValue($value)')
->setMethod(PhpMethod::create('getSchemaUrl')
->setDescription('Get schema URL.')
->setType('string')
->setBody('return \''.$data['url'].'\';')
)
;
if ($this->backwardCompatibility && !$this->php7ClassNames) {
$this->php7ClassNames = true;
$deprecatedMessage = 'This class is deprecated and will be removed in release 3.4. Use SecIT\\SchemaOrg\\Mapping\\Property\\'.$this->getPropertyClassName($propertyName).' instead.';
$this->php7ClassNames = false;
$class->setDescription($class->getDescription()."\n\n".'@deprecated '.$deprecatedMessage);
}
$instanceCheckConditions = [];
foreach ($data['ranges'] as $range) {
if (isset($dataTypes[$range])) {
$class->addUseStatement('SecIT\\SchemaOrg\\Mapping\\DataType');
$instanceCheckConditions[] = '$value instanceof DataType\\'.$this->getDataTypeClassName($range);
} else {
$class->addUseStatement('SecIT\\SchemaOrg\\Mapping\\Type');
$instanceCheckConditions[] = '$value instanceof Type\\'.$this->getTypeClassName($range);
}
}
// if no conditions than always return true
if (!$instanceCheckConditions) {
$instanceCheckConditions[] = 'true';
}
$class
->setMethod(PhpMethod::create('isValueValid')
->setDescription('Check is value valid.')
->addParameter(PhpParameter::create('value')
->setType('string')
)
->setType('bool')
->setBody('return '.implode(' || ', $instanceCheckConditions).';')
)
;
$generator = new CodeGenerator();
$code = $generator->generate($class);
file_put_contents($directory.$property.'.php', "<?php\n\n".$code);
}
|
[
"protected",
"function",
"generateProperty",
"(",
"$",
"propertyName",
",",
"array",
"$",
"data",
",",
"$",
"directory",
",",
"array",
"$",
"dataTypes",
")",
"{",
"$",
"property",
"=",
"$",
"this",
"->",
"getPropertyClassName",
"(",
"$",
"propertyName",
")",
";",
"$",
"class",
"=",
"new",
"PhpClass",
"(",
")",
";",
"$",
"class",
"->",
"setQualifiedName",
"(",
"'SecIT\\\\SchemaOrg\\\\Mapping\\\\Property\\\\'",
".",
"$",
"property",
")",
"->",
"setParentClassName",
"(",
"'AbstractProperty'",
")",
"->",
"setDescription",
"(",
"$",
"property",
".",
"' class.'",
".",
"\"\\n\\n\"",
".",
"'@method '",
".",
"$",
"property",
".",
"' setValue($value)'",
")",
"->",
"setMethod",
"(",
"PhpMethod",
"::",
"create",
"(",
"'getSchemaUrl'",
")",
"->",
"setDescription",
"(",
"'Get schema URL.'",
")",
"->",
"setType",
"(",
"'string'",
")",
"->",
"setBody",
"(",
"'return \\''",
".",
"$",
"data",
"[",
"'url'",
"]",
".",
"'\\';'",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"backwardCompatibility",
"&&",
"!",
"$",
"this",
"->",
"php7ClassNames",
")",
"{",
"$",
"this",
"->",
"php7ClassNames",
"=",
"true",
";",
"$",
"deprecatedMessage",
"=",
"'This class is deprecated and will be removed in release 3.4. Use SecIT\\\\SchemaOrg\\\\Mapping\\\\Property\\\\'",
".",
"$",
"this",
"->",
"getPropertyClassName",
"(",
"$",
"propertyName",
")",
".",
"' instead.'",
";",
"$",
"this",
"->",
"php7ClassNames",
"=",
"false",
";",
"$",
"class",
"->",
"setDescription",
"(",
"$",
"class",
"->",
"getDescription",
"(",
")",
".",
"\"\\n\\n\"",
".",
"'@deprecated '",
".",
"$",
"deprecatedMessage",
")",
";",
"}",
"$",
"instanceCheckConditions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"[",
"'ranges'",
"]",
"as",
"$",
"range",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"dataTypes",
"[",
"$",
"range",
"]",
")",
")",
"{",
"$",
"class",
"->",
"addUseStatement",
"(",
"'SecIT\\\\SchemaOrg\\\\Mapping\\\\DataType'",
")",
";",
"$",
"instanceCheckConditions",
"[",
"]",
"=",
"'$value instanceof DataType\\\\'",
".",
"$",
"this",
"->",
"getDataTypeClassName",
"(",
"$",
"range",
")",
";",
"}",
"else",
"{",
"$",
"class",
"->",
"addUseStatement",
"(",
"'SecIT\\\\SchemaOrg\\\\Mapping\\\\Type'",
")",
";",
"$",
"instanceCheckConditions",
"[",
"]",
"=",
"'$value instanceof Type\\\\'",
".",
"$",
"this",
"->",
"getTypeClassName",
"(",
"$",
"range",
")",
";",
"}",
"}",
"// if no conditions than always return true",
"if",
"(",
"!",
"$",
"instanceCheckConditions",
")",
"{",
"$",
"instanceCheckConditions",
"[",
"]",
"=",
"'true'",
";",
"}",
"$",
"class",
"->",
"setMethod",
"(",
"PhpMethod",
"::",
"create",
"(",
"'isValueValid'",
")",
"->",
"setDescription",
"(",
"'Check is value valid.'",
")",
"->",
"addParameter",
"(",
"PhpParameter",
"::",
"create",
"(",
"'value'",
")",
"->",
"setType",
"(",
"'string'",
")",
")",
"->",
"setType",
"(",
"'bool'",
")",
"->",
"setBody",
"(",
"'return '",
".",
"implode",
"(",
"' || '",
",",
"$",
"instanceCheckConditions",
")",
".",
"';'",
")",
")",
";",
"$",
"generator",
"=",
"new",
"CodeGenerator",
"(",
")",
";",
"$",
"code",
"=",
"$",
"generator",
"->",
"generate",
"(",
"$",
"class",
")",
";",
"file_put_contents",
"(",
"$",
"directory",
".",
"$",
"property",
".",
"'.php'",
",",
"\"<?php\\n\\n\"",
".",
"$",
"code",
")",
";",
"}"
] |
Generate property.
@param string $propertyName
@param array $data
@param string $directory
@param array $dataTypes
|
[
"Generate",
"property",
"."
] |
5d1656153b5eebf7227cc72dd77562e288157346
|
https://github.com/secit-pl/schema-org/blob/5d1656153b5eebf7227cc72dd77562e288157346/SchemaOrg/Generator.php#L412-L466
|
227,205
|
secit-pl/schema-org
|
SchemaOrg/Generator.php
|
Generator.getPropertyClassName
|
protected function getPropertyClassName($name)
{
$name = ucfirst($name);
if (!$this->php7ClassNames) {
return $name;
}
if (substr($name, -8) == 'Property') {
return $name;
}
return $name.'Property';
}
|
php
|
protected function getPropertyClassName($name)
{
$name = ucfirst($name);
if (!$this->php7ClassNames) {
return $name;
}
if (substr($name, -8) == 'Property') {
return $name;
}
return $name.'Property';
}
|
[
"protected",
"function",
"getPropertyClassName",
"(",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"ucfirst",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"php7ClassNames",
")",
"{",
"return",
"$",
"name",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"name",
",",
"-",
"8",
")",
"==",
"'Property'",
")",
"{",
"return",
"$",
"name",
";",
"}",
"return",
"$",
"name",
".",
"'Property'",
";",
"}"
] |
Get valid PHP7 property class name.
@param string $name
@return string
|
[
"Get",
"valid",
"PHP7",
"property",
"class",
"name",
"."
] |
5d1656153b5eebf7227cc72dd77562e288157346
|
https://github.com/secit-pl/schema-org/blob/5d1656153b5eebf7227cc72dd77562e288157346/SchemaOrg/Generator.php#L659-L671
|
227,206
|
secit-pl/schema-org
|
SchemaOrg/Generator.php
|
Generator.getInheritedProperties
|
protected function getInheritedProperties($type, array $schema, $isRoot = true)
{
if (!isset($schema['types'][$type])) {
throw new \Exception('Unknown type '.$type);
}
$typeSchema = $schema['types'][$type];
$properties = [];
if (!$isRoot) {
foreach ($typeSchema['specific_properties'] as $property) {
if (!isset($schema['properties'][$property])) {
continue;
}
$properties[$property] = $property;
}
}
if ($typeSchema['ancestors']) {
$properties = array_merge(
$properties,
$this->getInheritedProperties(end($typeSchema['ancestors']), $schema, false)
);
}
ksort($properties);
return $properties;
}
|
php
|
protected function getInheritedProperties($type, array $schema, $isRoot = true)
{
if (!isset($schema['types'][$type])) {
throw new \Exception('Unknown type '.$type);
}
$typeSchema = $schema['types'][$type];
$properties = [];
if (!$isRoot) {
foreach ($typeSchema['specific_properties'] as $property) {
if (!isset($schema['properties'][$property])) {
continue;
}
$properties[$property] = $property;
}
}
if ($typeSchema['ancestors']) {
$properties = array_merge(
$properties,
$this->getInheritedProperties(end($typeSchema['ancestors']), $schema, false)
);
}
ksort($properties);
return $properties;
}
|
[
"protected",
"function",
"getInheritedProperties",
"(",
"$",
"type",
",",
"array",
"$",
"schema",
",",
"$",
"isRoot",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"schema",
"[",
"'types'",
"]",
"[",
"$",
"type",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Unknown type '",
".",
"$",
"type",
")",
";",
"}",
"$",
"typeSchema",
"=",
"$",
"schema",
"[",
"'types'",
"]",
"[",
"$",
"type",
"]",
";",
"$",
"properties",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"$",
"isRoot",
")",
"{",
"foreach",
"(",
"$",
"typeSchema",
"[",
"'specific_properties'",
"]",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"schema",
"[",
"'properties'",
"]",
"[",
"$",
"property",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"properties",
"[",
"$",
"property",
"]",
"=",
"$",
"property",
";",
"}",
"}",
"if",
"(",
"$",
"typeSchema",
"[",
"'ancestors'",
"]",
")",
"{",
"$",
"properties",
"=",
"array_merge",
"(",
"$",
"properties",
",",
"$",
"this",
"->",
"getInheritedProperties",
"(",
"end",
"(",
"$",
"typeSchema",
"[",
"'ancestors'",
"]",
")",
",",
"$",
"schema",
",",
"false",
")",
")",
";",
"}",
"ksort",
"(",
"$",
"properties",
")",
";",
"return",
"$",
"properties",
";",
"}"
] |
Get inherited properties.
@param string $type
@param array $schema
@param bool $isRoot
@return array
@throws \Exception
|
[
"Get",
"inherited",
"properties",
"."
] |
5d1656153b5eebf7227cc72dd77562e288157346
|
https://github.com/secit-pl/schema-org/blob/5d1656153b5eebf7227cc72dd77562e288157346/SchemaOrg/Generator.php#L704-L732
|
227,207
|
secit-pl/schema-org
|
SchemaOrg/Generator.php
|
Generator.cleanUp
|
protected function cleanUp()
{
$files = glob(__DIR__.DIRECTORY_SEPARATOR.'Mapping'.DIRECTORY_SEPARATOR.'{DataType,Property,Type}'.DIRECTORY_SEPARATOR.'*.php', GLOB_BRACE);
foreach ($files as $file) {
unlink($file);
}
}
|
php
|
protected function cleanUp()
{
$files = glob(__DIR__.DIRECTORY_SEPARATOR.'Mapping'.DIRECTORY_SEPARATOR.'{DataType,Property,Type}'.DIRECTORY_SEPARATOR.'*.php', GLOB_BRACE);
foreach ($files as $file) {
unlink($file);
}
}
|
[
"protected",
"function",
"cleanUp",
"(",
")",
"{",
"$",
"files",
"=",
"glob",
"(",
"__DIR__",
".",
"DIRECTORY_SEPARATOR",
".",
"'Mapping'",
".",
"DIRECTORY_SEPARATOR",
".",
"'{DataType,Property,Type}'",
".",
"DIRECTORY_SEPARATOR",
".",
"'*.php'",
",",
"GLOB_BRACE",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"unlink",
"(",
"$",
"file",
")",
";",
"}",
"}"
] |
Remove previously generated files.
|
[
"Remove",
"previously",
"generated",
"files",
"."
] |
5d1656153b5eebf7227cc72dd77562e288157346
|
https://github.com/secit-pl/schema-org/blob/5d1656153b5eebf7227cc72dd77562e288157346/SchemaOrg/Generator.php#L749-L755
|
227,208
|
secit-pl/schema-org
|
SchemaOrg/Generator.php
|
Generator.getDataType
|
protected function getDataType(Client $client, $href)
{
$response = $client->get($href);
$crawler = new Crawler($response->getBody()->__toString());
$ancestors = [];
$subclasses = $crawler->filter('[property="rdfs:subClassOf"]');
if ($subclasses->count() > 0) {
$ancestors[] = ltrim(preg_replace('/http[s]*:\/\/schema.org\//', '', $subclasses->first()->attr('href')), '/');
}
return [
'ancestors' => $ancestors,
'comment' => $crawler->filter('[property="rdfs:comment"]')->first()->text(),
'comment_plain' => strip_tags($crawler->filter('[property="rdfs:comment"]')->first()->text()),
'id' => $crawler->filter('[property="rdfs:label"]')->first()->text(),
'label' => $crawler->filter('[property="rdfs:label"]')->first()->text(),
'url' => $client->getConfig('base_uri').$href,
];
}
|
php
|
protected function getDataType(Client $client, $href)
{
$response = $client->get($href);
$crawler = new Crawler($response->getBody()->__toString());
$ancestors = [];
$subclasses = $crawler->filter('[property="rdfs:subClassOf"]');
if ($subclasses->count() > 0) {
$ancestors[] = ltrim(preg_replace('/http[s]*:\/\/schema.org\//', '', $subclasses->first()->attr('href')), '/');
}
return [
'ancestors' => $ancestors,
'comment' => $crawler->filter('[property="rdfs:comment"]')->first()->text(),
'comment_plain' => strip_tags($crawler->filter('[property="rdfs:comment"]')->first()->text()),
'id' => $crawler->filter('[property="rdfs:label"]')->first()->text(),
'label' => $crawler->filter('[property="rdfs:label"]')->first()->text(),
'url' => $client->getConfig('base_uri').$href,
];
}
|
[
"protected",
"function",
"getDataType",
"(",
"Client",
"$",
"client",
",",
"$",
"href",
")",
"{",
"$",
"response",
"=",
"$",
"client",
"->",
"get",
"(",
"$",
"href",
")",
";",
"$",
"crawler",
"=",
"new",
"Crawler",
"(",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"__toString",
"(",
")",
")",
";",
"$",
"ancestors",
"=",
"[",
"]",
";",
"$",
"subclasses",
"=",
"$",
"crawler",
"->",
"filter",
"(",
"'[property=\"rdfs:subClassOf\"]'",
")",
";",
"if",
"(",
"$",
"subclasses",
"->",
"count",
"(",
")",
">",
"0",
")",
"{",
"$",
"ancestors",
"[",
"]",
"=",
"ltrim",
"(",
"preg_replace",
"(",
"'/http[s]*:\\/\\/schema.org\\//'",
",",
"''",
",",
"$",
"subclasses",
"->",
"first",
"(",
")",
"->",
"attr",
"(",
"'href'",
")",
")",
",",
"'/'",
")",
";",
"}",
"return",
"[",
"'ancestors'",
"=>",
"$",
"ancestors",
",",
"'comment'",
"=>",
"$",
"crawler",
"->",
"filter",
"(",
"'[property=\"rdfs:comment\"]'",
")",
"->",
"first",
"(",
")",
"->",
"text",
"(",
")",
",",
"'comment_plain'",
"=>",
"strip_tags",
"(",
"$",
"crawler",
"->",
"filter",
"(",
"'[property=\"rdfs:comment\"]'",
")",
"->",
"first",
"(",
")",
"->",
"text",
"(",
")",
")",
",",
"'id'",
"=>",
"$",
"crawler",
"->",
"filter",
"(",
"'[property=\"rdfs:label\"]'",
")",
"->",
"first",
"(",
")",
"->",
"text",
"(",
")",
",",
"'label'",
"=>",
"$",
"crawler",
"->",
"filter",
"(",
"'[property=\"rdfs:label\"]'",
")",
"->",
"first",
"(",
")",
"->",
"text",
"(",
")",
",",
"'url'",
"=>",
"$",
"client",
"->",
"getConfig",
"(",
"'base_uri'",
")",
".",
"$",
"href",
",",
"]",
";",
"}"
] |
Get data type.
@param Client $client
@param string $href
@return array
|
[
"Get",
"data",
"type",
"."
] |
5d1656153b5eebf7227cc72dd77562e288157346
|
https://github.com/secit-pl/schema-org/blob/5d1656153b5eebf7227cc72dd77562e288157346/SchemaOrg/Generator.php#L856-L875
|
227,209
|
aik099/CodingStandard
|
CodingStandard/Sniffs/NamingConventions/ValidVariableNameSniff.php
|
ValidVariableNameSniff.isCamelCaps
|
protected function isCamelCaps($string, $public = true)
{
if (in_array($string, $this->memberExceptions) === true) {
return true;
}
return Common::isCamelCaps($string, false, $public, false);
}
|
php
|
protected function isCamelCaps($string, $public = true)
{
if (in_array($string, $this->memberExceptions) === true) {
return true;
}
return Common::isCamelCaps($string, false, $public, false);
}
|
[
"protected",
"function",
"isCamelCaps",
"(",
"$",
"string",
",",
"$",
"public",
"=",
"true",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"string",
",",
"$",
"this",
"->",
"memberExceptions",
")",
"===",
"true",
")",
"{",
"return",
"true",
";",
"}",
"return",
"Common",
"::",
"isCamelCaps",
"(",
"$",
"string",
",",
"false",
",",
"$",
"public",
",",
"false",
")",
";",
"}"
] |
Determines if a variable is in camel caps case.
@param string $string String.
@param bool $public If true, the first character in the string
must be an a-z character. If false, the
character must be an underscore. This
argument is only applicable if $classFormat
is false.
@return bool
|
[
"Determines",
"if",
"a",
"variable",
"is",
"in",
"camel",
"caps",
"case",
"."
] |
0f65c52bf2d95d5068af9f73110770ddb9de8de7
|
https://github.com/aik099/CodingStandard/blob/0f65c52bf2d95d5068af9f73110770ddb9de8de7/CodingStandard/Sniffs/NamingConventions/ValidVariableNameSniff.php#L242-L249
|
227,210
|
BootstrapCMS/Credentials
|
src/Presenters/RevisionDisplayers/User/AbstractDisplayer.php
|
AbstractDisplayer.wasActualUser
|
protected function wasActualUser()
{
return $this->wrappedObject->user_id == $this->wrappedObject->revisionable_id || !$this->wrappedObject->user_id;
}
|
php
|
protected function wasActualUser()
{
return $this->wrappedObject->user_id == $this->wrappedObject->revisionable_id || !$this->wrappedObject->user_id;
}
|
[
"protected",
"function",
"wasActualUser",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"wrappedObject",
"->",
"user_id",
"==",
"$",
"this",
"->",
"wrappedObject",
"->",
"revisionable_id",
"||",
"!",
"$",
"this",
"->",
"wrappedObject",
"->",
"user_id",
";",
"}"
] |
Was the action by the actual user?
@return bool
|
[
"Was",
"the",
"action",
"by",
"the",
"actual",
"user?"
] |
128c5359eea7417ca95670933a28d4e6c7e01e6b
|
https://github.com/BootstrapCMS/Credentials/blob/128c5359eea7417ca95670933a28d4e6c7e01e6b/src/Presenters/RevisionDisplayers/User/AbstractDisplayer.php#L59-L62
|
227,211
|
BootstrapCMS/Credentials
|
src/Presenters/RevisionDisplayers/User/AbstractDisplayer.php
|
AbstractDisplayer.isCurrentUser
|
protected function isCurrentUser()
{
return $this->credentials->check() && $this->credentials->getUser()->id == $this->wrappedObject->revisionable_id;
}
|
php
|
protected function isCurrentUser()
{
return $this->credentials->check() && $this->credentials->getUser()->id == $this->wrappedObject->revisionable_id;
}
|
[
"protected",
"function",
"isCurrentUser",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"credentials",
"->",
"check",
"(",
")",
"&&",
"$",
"this",
"->",
"credentials",
"->",
"getUser",
"(",
")",
"->",
"id",
"==",
"$",
"this",
"->",
"wrappedObject",
"->",
"revisionable_id",
";",
"}"
] |
Is the current user's account?
@return bool
|
[
"Is",
"the",
"current",
"user",
"s",
"account?"
] |
128c5359eea7417ca95670933a28d4e6c7e01e6b
|
https://github.com/BootstrapCMS/Credentials/blob/128c5359eea7417ca95670933a28d4e6c7e01e6b/src/Presenters/RevisionDisplayers/User/AbstractDisplayer.php#L69-L72
|
227,212
|
BootstrapCMS/Credentials
|
src/Presenters/RevisionDisplayers/User/AbstractDisplayer.php
|
AbstractDisplayer.author
|
protected function author()
{
if ($this->presenter->wasByCurrentUser() || !$this->wrappedObject->user_id) {
return 'You ';
}
if (!$this->wrappedObject->security) {
return 'This user ';
}
return $this->presenter->author().' ';
}
|
php
|
protected function author()
{
if ($this->presenter->wasByCurrentUser() || !$this->wrappedObject->user_id) {
return 'You ';
}
if (!$this->wrappedObject->security) {
return 'This user ';
}
return $this->presenter->author().' ';
}
|
[
"protected",
"function",
"author",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"presenter",
"->",
"wasByCurrentUser",
"(",
")",
"||",
"!",
"$",
"this",
"->",
"wrappedObject",
"->",
"user_id",
")",
"{",
"return",
"'You '",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"wrappedObject",
"->",
"security",
")",
"{",
"return",
"'This user '",
";",
"}",
"return",
"$",
"this",
"->",
"presenter",
"->",
"author",
"(",
")",
".",
"' '",
";",
"}"
] |
Get the author details.
@return string
|
[
"Get",
"the",
"author",
"details",
"."
] |
128c5359eea7417ca95670933a28d4e6c7e01e6b
|
https://github.com/BootstrapCMS/Credentials/blob/128c5359eea7417ca95670933a28d4e6c7e01e6b/src/Presenters/RevisionDisplayers/User/AbstractDisplayer.php#L79-L90
|
227,213
|
BootstrapCMS/Credentials
|
src/Presenters/RevisionDisplayers/User/AbstractDisplayer.php
|
AbstractDisplayer.user
|
protected function user()
{
if ($this->wrappedObject->security) {
return ' this user\'s ';
}
$user = $this->wrappedObject->revisionable()->withTrashed()->first(['first_name', 'last_name']);
return ' '.$user->first_name.' '.$user->last_name.'\'s ';
}
|
php
|
protected function user()
{
if ($this->wrappedObject->security) {
return ' this user\'s ';
}
$user = $this->wrappedObject->revisionable()->withTrashed()->first(['first_name', 'last_name']);
return ' '.$user->first_name.' '.$user->last_name.'\'s ';
}
|
[
"protected",
"function",
"user",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"wrappedObject",
"->",
"security",
")",
"{",
"return",
"' this user\\'s '",
";",
"}",
"$",
"user",
"=",
"$",
"this",
"->",
"wrappedObject",
"->",
"revisionable",
"(",
")",
"->",
"withTrashed",
"(",
")",
"->",
"first",
"(",
"[",
"'first_name'",
",",
"'last_name'",
"]",
")",
";",
"return",
"' '",
".",
"$",
"user",
"->",
"first_name",
".",
"' '",
".",
"$",
"user",
"->",
"last_name",
".",
"'\\'s '",
";",
"}"
] |
Get the user details.
@return string
|
[
"Get",
"the",
"user",
"details",
"."
] |
128c5359eea7417ca95670933a28d4e6c7e01e6b
|
https://github.com/BootstrapCMS/Credentials/blob/128c5359eea7417ca95670933a28d4e6c7e01e6b/src/Presenters/RevisionDisplayers/User/AbstractDisplayer.php#L97-L106
|
227,214
|
rdehnhardt/lumen-maintenance-mode
|
src/Http/Middleware/MaintenanceModeMiddleware.php
|
MaintenanceModeMiddleware.handle
|
public function handle($request, Closure $next)
{
if ($this->maintenance->isDownMode() && !$this->maintenance->checkAllowedIp($this->getIp())) {
if (app()['view']->exists('errors.503')) {
return new Response(app()['view']->make('errors.503'), 503);
}
return app()->abort(503, 'The application is down for maintenance.');
}
return $next($request);
}
|
php
|
public function handle($request, Closure $next)
{
if ($this->maintenance->isDownMode() && !$this->maintenance->checkAllowedIp($this->getIp())) {
if (app()['view']->exists('errors.503')) {
return new Response(app()['view']->make('errors.503'), 503);
}
return app()->abort(503, 'The application is down for maintenance.');
}
return $next($request);
}
|
[
"public",
"function",
"handle",
"(",
"$",
"request",
",",
"Closure",
"$",
"next",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"maintenance",
"->",
"isDownMode",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"maintenance",
"->",
"checkAllowedIp",
"(",
"$",
"this",
"->",
"getIp",
"(",
")",
")",
")",
"{",
"if",
"(",
"app",
"(",
")",
"[",
"'view'",
"]",
"->",
"exists",
"(",
"'errors.503'",
")",
")",
"{",
"return",
"new",
"Response",
"(",
"app",
"(",
")",
"[",
"'view'",
"]",
"->",
"make",
"(",
"'errors.503'",
")",
",",
"503",
")",
";",
"}",
"return",
"app",
"(",
")",
"->",
"abort",
"(",
"503",
",",
"'The application is down for maintenance.'",
")",
";",
"}",
"return",
"$",
"next",
"(",
"$",
"request",
")",
";",
"}"
] |
Handle incoming requests.
@param Request $request
@param \Closure $next
@return \Symfony\Component\HttpFoundation\Response
@throws \Symfony\Component\HttpKernel\Exception\HttpException
@throws \InvalidArgumentException
|
[
"Handle",
"incoming",
"requests",
"."
] |
6d40cc5658345fecdf5b7571df902f339964f513
|
https://github.com/rdehnhardt/lumen-maintenance-mode/blob/6d40cc5658345fecdf5b7571df902f339964f513/src/Http/Middleware/MaintenanceModeMiddleware.php#L38-L49
|
227,215
|
BootstrapCMS/Credentials
|
src/Http/Controllers/ResetController.php
|
ResetController.postReset
|
public function postReset()
{
$input = Binput::only('email');
$val = UserRepository::validate($input, array_keys($input));
if ($val->fails()) {
return Redirect::route('account.reset')->withInput()->withErrors($val->errors());
}
$this->throttler->hit();
try {
$user = Credentials::getUserProvider()->findByLogin($input['email']);
$code = $user->getResetPasswordCode();
$mail = [
'link' => URL::route('account.password', ['id' => $user->id, 'code' => $code]),
'email' => $user->getLogin(),
'subject' => Config::get('app.name').' - Password Reset Confirmation',
];
Mail::queue('credentials::emails.reset', $mail, function ($message) use ($mail) {
$message->to($mail['email'])->subject($mail['subject']);
});
return Redirect::route('account.reset')
->with('success', 'Check your email for password reset information.');
} catch (UserNotFoundException $e) {
return Redirect::route('account.reset')
->with('error', 'That user does not exist.');
}
}
|
php
|
public function postReset()
{
$input = Binput::only('email');
$val = UserRepository::validate($input, array_keys($input));
if ($val->fails()) {
return Redirect::route('account.reset')->withInput()->withErrors($val->errors());
}
$this->throttler->hit();
try {
$user = Credentials::getUserProvider()->findByLogin($input['email']);
$code = $user->getResetPasswordCode();
$mail = [
'link' => URL::route('account.password', ['id' => $user->id, 'code' => $code]),
'email' => $user->getLogin(),
'subject' => Config::get('app.name').' - Password Reset Confirmation',
];
Mail::queue('credentials::emails.reset', $mail, function ($message) use ($mail) {
$message->to($mail['email'])->subject($mail['subject']);
});
return Redirect::route('account.reset')
->with('success', 'Check your email for password reset information.');
} catch (UserNotFoundException $e) {
return Redirect::route('account.reset')
->with('error', 'That user does not exist.');
}
}
|
[
"public",
"function",
"postReset",
"(",
")",
"{",
"$",
"input",
"=",
"Binput",
"::",
"only",
"(",
"'email'",
")",
";",
"$",
"val",
"=",
"UserRepository",
"::",
"validate",
"(",
"$",
"input",
",",
"array_keys",
"(",
"$",
"input",
")",
")",
";",
"if",
"(",
"$",
"val",
"->",
"fails",
"(",
")",
")",
"{",
"return",
"Redirect",
"::",
"route",
"(",
"'account.reset'",
")",
"->",
"withInput",
"(",
")",
"->",
"withErrors",
"(",
"$",
"val",
"->",
"errors",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"throttler",
"->",
"hit",
"(",
")",
";",
"try",
"{",
"$",
"user",
"=",
"Credentials",
"::",
"getUserProvider",
"(",
")",
"->",
"findByLogin",
"(",
"$",
"input",
"[",
"'email'",
"]",
")",
";",
"$",
"code",
"=",
"$",
"user",
"->",
"getResetPasswordCode",
"(",
")",
";",
"$",
"mail",
"=",
"[",
"'link'",
"=>",
"URL",
"::",
"route",
"(",
"'account.password'",
",",
"[",
"'id'",
"=>",
"$",
"user",
"->",
"id",
",",
"'code'",
"=>",
"$",
"code",
"]",
")",
",",
"'email'",
"=>",
"$",
"user",
"->",
"getLogin",
"(",
")",
",",
"'subject'",
"=>",
"Config",
"::",
"get",
"(",
"'app.name'",
")",
".",
"' - Password Reset Confirmation'",
",",
"]",
";",
"Mail",
"::",
"queue",
"(",
"'credentials::emails.reset'",
",",
"$",
"mail",
",",
"function",
"(",
"$",
"message",
")",
"use",
"(",
"$",
"mail",
")",
"{",
"$",
"message",
"->",
"to",
"(",
"$",
"mail",
"[",
"'email'",
"]",
")",
"->",
"subject",
"(",
"$",
"mail",
"[",
"'subject'",
"]",
")",
";",
"}",
")",
";",
"return",
"Redirect",
"::",
"route",
"(",
"'account.reset'",
")",
"->",
"with",
"(",
"'success'",
",",
"'Check your email for password reset information.'",
")",
";",
"}",
"catch",
"(",
"UserNotFoundException",
"$",
"e",
")",
"{",
"return",
"Redirect",
"::",
"route",
"(",
"'account.reset'",
")",
"->",
"with",
"(",
"'error'",
",",
"'That user does not exist.'",
")",
";",
"}",
"}"
] |
Queue the sending of the password reset email.
@return \Illuminate\Http\Response
|
[
"Queue",
"the",
"sending",
"of",
"the",
"password",
"reset",
"email",
"."
] |
128c5359eea7417ca95670933a28d4e6c7e01e6b
|
https://github.com/BootstrapCMS/Credentials/blob/128c5359eea7417ca95670933a28d4e6c7e01e6b/src/Http/Controllers/ResetController.php#L72-L104
|
227,216
|
BootstrapCMS/Credentials
|
src/Http/Controllers/ResetController.php
|
ResetController.getPassword
|
public function getPassword($id, $code)
{
if (!$id || !$code) {
throw new BadRequestHttpException();
}
try {
$user = Credentials::getUserProvider()->findById($id);
$password = Str::random();
if (!$user->attemptResetPassword($code, $password)) {
return Redirect::to(Config::get('credentials.home', '/'))
->with('error', 'There was a problem resetting your password. Please contact support.');
}
$mail = [
'password' => $password,
'email' => $user->getLogin(),
'subject' => Config::get('app.name').' - New Password Information',
];
Mail::queue('credentials::emails.password', $mail, function ($message) use ($mail) {
$message->to($mail['email'])->subject($mail['subject']);
});
return Redirect::to(Config::get('credentials.home', '/'))
->with('success', 'Your password has been changed. Check your email for the new password.');
} catch (UserNotFoundException $e) {
return Redirect::to(Config::get('credentials.home', '/'))
->with('error', 'There was a problem resetting your password. Please contact support.');
}
}
|
php
|
public function getPassword($id, $code)
{
if (!$id || !$code) {
throw new BadRequestHttpException();
}
try {
$user = Credentials::getUserProvider()->findById($id);
$password = Str::random();
if (!$user->attemptResetPassword($code, $password)) {
return Redirect::to(Config::get('credentials.home', '/'))
->with('error', 'There was a problem resetting your password. Please contact support.');
}
$mail = [
'password' => $password,
'email' => $user->getLogin(),
'subject' => Config::get('app.name').' - New Password Information',
];
Mail::queue('credentials::emails.password', $mail, function ($message) use ($mail) {
$message->to($mail['email'])->subject($mail['subject']);
});
return Redirect::to(Config::get('credentials.home', '/'))
->with('success', 'Your password has been changed. Check your email for the new password.');
} catch (UserNotFoundException $e) {
return Redirect::to(Config::get('credentials.home', '/'))
->with('error', 'There was a problem resetting your password. Please contact support.');
}
}
|
[
"public",
"function",
"getPassword",
"(",
"$",
"id",
",",
"$",
"code",
")",
"{",
"if",
"(",
"!",
"$",
"id",
"||",
"!",
"$",
"code",
")",
"{",
"throw",
"new",
"BadRequestHttpException",
"(",
")",
";",
"}",
"try",
"{",
"$",
"user",
"=",
"Credentials",
"::",
"getUserProvider",
"(",
")",
"->",
"findById",
"(",
"$",
"id",
")",
";",
"$",
"password",
"=",
"Str",
"::",
"random",
"(",
")",
";",
"if",
"(",
"!",
"$",
"user",
"->",
"attemptResetPassword",
"(",
"$",
"code",
",",
"$",
"password",
")",
")",
"{",
"return",
"Redirect",
"::",
"to",
"(",
"Config",
"::",
"get",
"(",
"'credentials.home'",
",",
"'/'",
")",
")",
"->",
"with",
"(",
"'error'",
",",
"'There was a problem resetting your password. Please contact support.'",
")",
";",
"}",
"$",
"mail",
"=",
"[",
"'password'",
"=>",
"$",
"password",
",",
"'email'",
"=>",
"$",
"user",
"->",
"getLogin",
"(",
")",
",",
"'subject'",
"=>",
"Config",
"::",
"get",
"(",
"'app.name'",
")",
".",
"' - New Password Information'",
",",
"]",
";",
"Mail",
"::",
"queue",
"(",
"'credentials::emails.password'",
",",
"$",
"mail",
",",
"function",
"(",
"$",
"message",
")",
"use",
"(",
"$",
"mail",
")",
"{",
"$",
"message",
"->",
"to",
"(",
"$",
"mail",
"[",
"'email'",
"]",
")",
"->",
"subject",
"(",
"$",
"mail",
"[",
"'subject'",
"]",
")",
";",
"}",
")",
";",
"return",
"Redirect",
"::",
"to",
"(",
"Config",
"::",
"get",
"(",
"'credentials.home'",
",",
"'/'",
")",
")",
"->",
"with",
"(",
"'success'",
",",
"'Your password has been changed. Check your email for the new password.'",
")",
";",
"}",
"catch",
"(",
"UserNotFoundException",
"$",
"e",
")",
"{",
"return",
"Redirect",
"::",
"to",
"(",
"Config",
"::",
"get",
"(",
"'credentials.home'",
",",
"'/'",
")",
")",
"->",
"with",
"(",
"'error'",
",",
"'There was a problem resetting your password. Please contact support.'",
")",
";",
"}",
"}"
] |
Reset the user's password.
@param int $id
@param string $code
@throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
@return \Illuminate\Http\Response
|
[
"Reset",
"the",
"user",
"s",
"password",
"."
] |
128c5359eea7417ca95670933a28d4e6c7e01e6b
|
https://github.com/BootstrapCMS/Credentials/blob/128c5359eea7417ca95670933a28d4e6c7e01e6b/src/Http/Controllers/ResetController.php#L116-L148
|
227,217
|
javanile/moldable
|
src/Database/SocketApi.php
|
SocketApi.execute
|
public function execute($sql, $values = null)
{
$this->log('execute', $sql, $values);
return $this->_socket->execute($sql, $values);
}
|
php
|
public function execute($sql, $values = null)
{
$this->log('execute', $sql, $values);
return $this->_socket->execute($sql, $values);
}
|
[
"public",
"function",
"execute",
"(",
"$",
"sql",
",",
"$",
"values",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"'execute'",
",",
"$",
"sql",
",",
"$",
"values",
")",
";",
"return",
"$",
"this",
"->",
"_socket",
"->",
"execute",
"(",
"$",
"sql",
",",
"$",
"values",
")",
";",
"}"
] |
Execute SQL query to database.
@param type $sql
@param type $values
@return type
|
[
"Execute",
"SQL",
"query",
"to",
"database",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Database/SocketApi.php#L23-L28
|
227,218
|
javanile/moldable
|
src/Database/SocketApi.php
|
SocketApi.getPrefix
|
public function getPrefix($table = null)
{
$prefix = $this->_socket->getPrefix();
return $table ? $prefix.$table : $prefix;
}
|
php
|
public function getPrefix($table = null)
{
$prefix = $this->_socket->getPrefix();
return $table ? $prefix.$table : $prefix;
}
|
[
"public",
"function",
"getPrefix",
"(",
"$",
"table",
"=",
"null",
")",
"{",
"$",
"prefix",
"=",
"$",
"this",
"->",
"_socket",
"->",
"getPrefix",
"(",
")",
";",
"return",
"$",
"table",
"?",
"$",
"prefix",
".",
"$",
"table",
":",
"$",
"prefix",
";",
"}"
] |
Return current database prefix used.
@param null|mixed $table
@return type
|
[
"Return",
"current",
"database",
"prefix",
"used",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Database/SocketApi.php#L37-L42
|
227,219
|
javanile/moldable
|
src/Database/SocketApi.php
|
SocketApi.getRow
|
public function getRow($sql, $params = null)
{
$this->log('getRow', $sql, $params);
return $this->_socket->getRow($sql, $params);
}
|
php
|
public function getRow($sql, $params = null)
{
$this->log('getRow', $sql, $params);
return $this->_socket->getRow($sql, $params);
}
|
[
"public",
"function",
"getRow",
"(",
"$",
"sql",
",",
"$",
"params",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"'getRow'",
",",
"$",
"sql",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"_socket",
"->",
"getRow",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}"
] |
Get a single row of a result set.
@param type $sql
@param null|mixed $params
@return type
|
[
"Get",
"a",
"single",
"row",
"of",
"a",
"result",
"set",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Database/SocketApi.php#L79-L84
|
227,220
|
javanile/moldable
|
src/Database/SocketApi.php
|
SocketApi.tableExists
|
public function tableExists($table, $parse = true)
{
// prepare
if ($parse) {
$table = $this->getPrefix($table);
}
// escape table name for query
$escapedTable = str_replace('_', '\\_', $table);
// sql query to test if table exists
$sql = "SHOW TABLES LIKE '{$escapedTable}'";
// execute test if table exists
$exists = $this->getRow($sql);
return (bool) $exists;
}
|
php
|
public function tableExists($table, $parse = true)
{
// prepare
if ($parse) {
$table = $this->getPrefix($table);
}
// escape table name for query
$escapedTable = str_replace('_', '\\_', $table);
// sql query to test if table exists
$sql = "SHOW TABLES LIKE '{$escapedTable}'";
// execute test if table exists
$exists = $this->getRow($sql);
return (bool) $exists;
}
|
[
"public",
"function",
"tableExists",
"(",
"$",
"table",
",",
"$",
"parse",
"=",
"true",
")",
"{",
"// prepare",
"if",
"(",
"$",
"parse",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getPrefix",
"(",
"$",
"table",
")",
";",
"}",
"// escape table name for query",
"$",
"escapedTable",
"=",
"str_replace",
"(",
"'_'",
",",
"'\\\\_'",
",",
"$",
"table",
")",
";",
"// sql query to test if table exists",
"$",
"sql",
"=",
"\"SHOW TABLES LIKE '{$escapedTable}'\"",
";",
"// execute test if table exists",
"$",
"exists",
"=",
"$",
"this",
"->",
"getRow",
"(",
"$",
"sql",
")",
";",
"return",
"(",
"bool",
")",
"$",
"exists",
";",
"}"
] |
Test if a table exists.
@param type $table
@param mixed $parse
@return type
|
[
"Test",
"if",
"a",
"table",
"exists",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Database/SocketApi.php#L156-L173
|
227,221
|
javanile/moldable
|
src/Database/SocketApi.php
|
SocketApi.getTables
|
public function getTables($matchPrefix = true)
{
if ($matchPrefix) {
$prefix = str_replace('_', '\\_', $this->getPrefix());
$sql = "SHOW TABLES LIKE '{$prefix}%'";
} else {
$sql = 'SHOW TABLES';
}
$tables = $this->getValues($sql);
return $tables;
}
|
php
|
public function getTables($matchPrefix = true)
{
if ($matchPrefix) {
$prefix = str_replace('_', '\\_', $this->getPrefix());
$sql = "SHOW TABLES LIKE '{$prefix}%'";
} else {
$sql = 'SHOW TABLES';
}
$tables = $this->getValues($sql);
return $tables;
}
|
[
"public",
"function",
"getTables",
"(",
"$",
"matchPrefix",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"matchPrefix",
")",
"{",
"$",
"prefix",
"=",
"str_replace",
"(",
"'_'",
",",
"'\\\\_'",
",",
"$",
"this",
"->",
"getPrefix",
"(",
")",
")",
";",
"$",
"sql",
"=",
"\"SHOW TABLES LIKE '{$prefix}%'\"",
";",
"}",
"else",
"{",
"$",
"sql",
"=",
"'SHOW TABLES'",
";",
"}",
"$",
"tables",
"=",
"$",
"this",
"->",
"getValues",
"(",
"$",
"sql",
")",
";",
"return",
"$",
"tables",
";",
"}"
] |
Get array with current tables on database.
@param mixed $matchPrefix
@return array
|
[
"Get",
"array",
"with",
"current",
"tables",
"on",
"database",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Database/SocketApi.php#L182-L194
|
227,222
|
javanile/moldable
|
src/Database/SocketApi.php
|
SocketApi.log
|
private function log($method, $sql = null, $params = null)
{
$this->_logger->info(
str_pad('('.$method.')', 14, ' ', STR_PAD_RIGHT).'"'.$sql.'"',
(array) $params
);
/*
$arg1formatted = is_string($arg1) ? str_replace([
'SELECT ',
', ',
'FROM ',
'LEFT JOIN ',
'WHERE ',
'LIMIT ',
], [
'SELECT ',
"\n".' , ',
"\n".' FROM ',
"\n".' LEFT JOIN ',
"\n".' WHERE ',
"\n".' LIMIT ',
], trim($arg1)) : json_encode($arg1);
echo '<pre style="border:1px solid #9F6000;margin:0 0 1px 0;padding:2px 6px 3px 6px;color:#9F6000;background:#FEEFB3;">';
echo '<strong>'.str_pad($method,12,' ',STR_PAD_LEFT).'</strong>'.($arg1?': #1 -> '.$arg1formatted:'');
if (isset($arg2)) {
echo "\n".str_pad('#2 -> ',20,' ',STR_PAD_LEFT).json_encode($arg2);
}
echo '</pre>';
*/
}
|
php
|
private function log($method, $sql = null, $params = null)
{
$this->_logger->info(
str_pad('('.$method.')', 14, ' ', STR_PAD_RIGHT).'"'.$sql.'"',
(array) $params
);
/*
$arg1formatted = is_string($arg1) ? str_replace([
'SELECT ',
', ',
'FROM ',
'LEFT JOIN ',
'WHERE ',
'LIMIT ',
], [
'SELECT ',
"\n".' , ',
"\n".' FROM ',
"\n".' LEFT JOIN ',
"\n".' WHERE ',
"\n".' LIMIT ',
], trim($arg1)) : json_encode($arg1);
echo '<pre style="border:1px solid #9F6000;margin:0 0 1px 0;padding:2px 6px 3px 6px;color:#9F6000;background:#FEEFB3;">';
echo '<strong>'.str_pad($method,12,' ',STR_PAD_LEFT).'</strong>'.($arg1?': #1 -> '.$arg1formatted:'');
if (isset($arg2)) {
echo "\n".str_pad('#2 -> ',20,' ',STR_PAD_LEFT).json_encode($arg2);
}
echo '</pre>';
*/
}
|
[
"private",
"function",
"log",
"(",
"$",
"method",
",",
"$",
"sql",
"=",
"null",
",",
"$",
"params",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"info",
"(",
"str_pad",
"(",
"'('",
".",
"$",
"method",
".",
"')'",
",",
"14",
",",
"' '",
",",
"STR_PAD_RIGHT",
")",
".",
"'\"'",
".",
"$",
"sql",
".",
"'\"'",
",",
"(",
"array",
")",
"$",
"params",
")",
";",
"/*\n $arg1formatted = is_string($arg1) ? str_replace([\n 'SELECT ',\n ', ',\n 'FROM ',\n 'LEFT JOIN ',\n 'WHERE ',\n 'LIMIT ',\n ], [\n 'SELECT ',\n \"\\n\".' , ',\n \"\\n\".' FROM ',\n \"\\n\".' LEFT JOIN ',\n \"\\n\".' WHERE ',\n \"\\n\".' LIMIT ',\n ], trim($arg1)) : json_encode($arg1);\n\n echo '<pre style=\"border:1px solid #9F6000;margin:0 0 1px 0;padding:2px 6px 3px 6px;color:#9F6000;background:#FEEFB3;\">';\n echo '<strong>'.str_pad($method,12,' ',STR_PAD_LEFT).'</strong>'.($arg1?': #1 -> '.$arg1formatted:'');\n if (isset($arg2)) {\n echo \"\\n\".str_pad('#2 -> ',20,' ',STR_PAD_LEFT).json_encode($arg2);\n }\n echo '</pre>';\n */",
"}"
] |
Log called SocketApi into log file.
@param mixed $method
@param null|mixed $sql
@param null|mixed $params
|
[
"Log",
"called",
"SocketApi",
"into",
"log",
"file",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Database/SocketApi.php#L271-L302
|
227,223
|
javanile/moldable
|
src/Parser/Mysql/StringTrait.php
|
StringTrait.getNotationAspectsString
|
private function getNotationAspectsString($notation, $aspects)
{
$aspects['Type'] = 'varchar(255)';
$aspects['Null'] = 'NO';
$aspects['Default'] = $this->getNotationValue($notation);
return $aspects;
}
|
php
|
private function getNotationAspectsString($notation, $aspects)
{
$aspects['Type'] = 'varchar(255)';
$aspects['Null'] = 'NO';
$aspects['Default'] = $this->getNotationValue($notation);
return $aspects;
}
|
[
"private",
"function",
"getNotationAspectsString",
"(",
"$",
"notation",
",",
"$",
"aspects",
")",
"{",
"$",
"aspects",
"[",
"'Type'",
"]",
"=",
"'varchar(255)'",
";",
"$",
"aspects",
"[",
"'Null'",
"]",
"=",
"'NO'",
";",
"$",
"aspects",
"[",
"'Default'",
"]",
"=",
"$",
"this",
"->",
"getNotationValue",
"(",
"$",
"notation",
")",
";",
"return",
"$",
"aspects",
";",
"}"
] |
Get notaion aspect for string.
@param mixed $notation
@param mixed $aspects
|
[
"Get",
"notaion",
"aspect",
"for",
"string",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Parser/Mysql/StringTrait.php#L20-L27
|
227,224
|
BootstrapCMS/Credentials
|
src/Http/Controllers/LoginController.php
|
LoginController.postLogin
|
public function postLogin()
{
$remember = Binput::get('rememberMe');
$input = Binput::only(['email', 'password']);
$rules = UserRepository::rules(array_keys($input));
$rules['password'] = 'required|min:6';
$val = UserRepository::validate($input, $rules, true);
if ($val->fails()) {
return Redirect::route('account.login')->withInput()->withErrors($val->errors());
}
$this->throttler->hit();
try {
$throttle = Credentials::getThrottleProvider()->findByUserLogin($input['email']);
$throttle->check();
Credentials::authenticate($input, $remember);
} catch (WrongPasswordException $e) {
return Redirect::route('account.login')->withInput()->withErrors($val->errors())
->with('error', 'Your password was incorrect.');
} catch (UserNotFoundException $e) {
return Redirect::route('account.login')->withInput()->withErrors($val->errors())
->with('error', 'That user does not exist.');
} catch (UserNotActivatedException $e) {
if (Config::get('credentials::activation')) {
return Redirect::route('account.login')->withInput()->withErrors($val->errors())
->with('error', 'You have not yet activated this account.');
} else {
$throttle->user->attemptActivation($throttle->user->getActivationCode());
$throttle->user->addGroup(Credentials::getGroupProvider()->findByName('Users'));
return $this->postLogin();
}
} catch (UserSuspendedException $e) {
$time = $throttle->getSuspensionTime();
return Redirect::route('account.login')->withInput()->withErrors($val->errors())
->with('error', "Your account has been suspended for $time minutes.");
} catch (UserBannedException $e) {
return Redirect::route('account.login')->withInput()->withErrors($val->errors())
->with('error', 'You have been banned. Please contact support.');
}
return Redirect::intended(Config::get('credentials.home', '/'));
}
|
php
|
public function postLogin()
{
$remember = Binput::get('rememberMe');
$input = Binput::only(['email', 'password']);
$rules = UserRepository::rules(array_keys($input));
$rules['password'] = 'required|min:6';
$val = UserRepository::validate($input, $rules, true);
if ($val->fails()) {
return Redirect::route('account.login')->withInput()->withErrors($val->errors());
}
$this->throttler->hit();
try {
$throttle = Credentials::getThrottleProvider()->findByUserLogin($input['email']);
$throttle->check();
Credentials::authenticate($input, $remember);
} catch (WrongPasswordException $e) {
return Redirect::route('account.login')->withInput()->withErrors($val->errors())
->with('error', 'Your password was incorrect.');
} catch (UserNotFoundException $e) {
return Redirect::route('account.login')->withInput()->withErrors($val->errors())
->with('error', 'That user does not exist.');
} catch (UserNotActivatedException $e) {
if (Config::get('credentials::activation')) {
return Redirect::route('account.login')->withInput()->withErrors($val->errors())
->with('error', 'You have not yet activated this account.');
} else {
$throttle->user->attemptActivation($throttle->user->getActivationCode());
$throttle->user->addGroup(Credentials::getGroupProvider()->findByName('Users'));
return $this->postLogin();
}
} catch (UserSuspendedException $e) {
$time = $throttle->getSuspensionTime();
return Redirect::route('account.login')->withInput()->withErrors($val->errors())
->with('error', "Your account has been suspended for $time minutes.");
} catch (UserBannedException $e) {
return Redirect::route('account.login')->withInput()->withErrors($val->errors())
->with('error', 'You have been banned. Please contact support.');
}
return Redirect::intended(Config::get('credentials.home', '/'));
}
|
[
"public",
"function",
"postLogin",
"(",
")",
"{",
"$",
"remember",
"=",
"Binput",
"::",
"get",
"(",
"'rememberMe'",
")",
";",
"$",
"input",
"=",
"Binput",
"::",
"only",
"(",
"[",
"'email'",
",",
"'password'",
"]",
")",
";",
"$",
"rules",
"=",
"UserRepository",
"::",
"rules",
"(",
"array_keys",
"(",
"$",
"input",
")",
")",
";",
"$",
"rules",
"[",
"'password'",
"]",
"=",
"'required|min:6'",
";",
"$",
"val",
"=",
"UserRepository",
"::",
"validate",
"(",
"$",
"input",
",",
"$",
"rules",
",",
"true",
")",
";",
"if",
"(",
"$",
"val",
"->",
"fails",
"(",
")",
")",
"{",
"return",
"Redirect",
"::",
"route",
"(",
"'account.login'",
")",
"->",
"withInput",
"(",
")",
"->",
"withErrors",
"(",
"$",
"val",
"->",
"errors",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"throttler",
"->",
"hit",
"(",
")",
";",
"try",
"{",
"$",
"throttle",
"=",
"Credentials",
"::",
"getThrottleProvider",
"(",
")",
"->",
"findByUserLogin",
"(",
"$",
"input",
"[",
"'email'",
"]",
")",
";",
"$",
"throttle",
"->",
"check",
"(",
")",
";",
"Credentials",
"::",
"authenticate",
"(",
"$",
"input",
",",
"$",
"remember",
")",
";",
"}",
"catch",
"(",
"WrongPasswordException",
"$",
"e",
")",
"{",
"return",
"Redirect",
"::",
"route",
"(",
"'account.login'",
")",
"->",
"withInput",
"(",
")",
"->",
"withErrors",
"(",
"$",
"val",
"->",
"errors",
"(",
")",
")",
"->",
"with",
"(",
"'error'",
",",
"'Your password was incorrect.'",
")",
";",
"}",
"catch",
"(",
"UserNotFoundException",
"$",
"e",
")",
"{",
"return",
"Redirect",
"::",
"route",
"(",
"'account.login'",
")",
"->",
"withInput",
"(",
")",
"->",
"withErrors",
"(",
"$",
"val",
"->",
"errors",
"(",
")",
")",
"->",
"with",
"(",
"'error'",
",",
"'That user does not exist.'",
")",
";",
"}",
"catch",
"(",
"UserNotActivatedException",
"$",
"e",
")",
"{",
"if",
"(",
"Config",
"::",
"get",
"(",
"'credentials::activation'",
")",
")",
"{",
"return",
"Redirect",
"::",
"route",
"(",
"'account.login'",
")",
"->",
"withInput",
"(",
")",
"->",
"withErrors",
"(",
"$",
"val",
"->",
"errors",
"(",
")",
")",
"->",
"with",
"(",
"'error'",
",",
"'You have not yet activated this account.'",
")",
";",
"}",
"else",
"{",
"$",
"throttle",
"->",
"user",
"->",
"attemptActivation",
"(",
"$",
"throttle",
"->",
"user",
"->",
"getActivationCode",
"(",
")",
")",
";",
"$",
"throttle",
"->",
"user",
"->",
"addGroup",
"(",
"Credentials",
"::",
"getGroupProvider",
"(",
")",
"->",
"findByName",
"(",
"'Users'",
")",
")",
";",
"return",
"$",
"this",
"->",
"postLogin",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"UserSuspendedException",
"$",
"e",
")",
"{",
"$",
"time",
"=",
"$",
"throttle",
"->",
"getSuspensionTime",
"(",
")",
";",
"return",
"Redirect",
"::",
"route",
"(",
"'account.login'",
")",
"->",
"withInput",
"(",
")",
"->",
"withErrors",
"(",
"$",
"val",
"->",
"errors",
"(",
")",
")",
"->",
"with",
"(",
"'error'",
",",
"\"Your account has been suspended for $time minutes.\"",
")",
";",
"}",
"catch",
"(",
"UserBannedException",
"$",
"e",
")",
"{",
"return",
"Redirect",
"::",
"route",
"(",
"'account.login'",
")",
"->",
"withInput",
"(",
")",
"->",
"withErrors",
"(",
"$",
"val",
"->",
"errors",
"(",
")",
")",
"->",
"with",
"(",
"'error'",
",",
"'You have been banned. Please contact support.'",
")",
";",
"}",
"return",
"Redirect",
"::",
"intended",
"(",
"Config",
"::",
"get",
"(",
"'credentials.home'",
",",
"'/'",
")",
")",
";",
"}"
] |
Attempt to login the specified user.
@return \Illuminate\Http\Response
|
[
"Attempt",
"to",
"login",
"the",
"specified",
"user",
"."
] |
128c5359eea7417ca95670933a28d4e6c7e01e6b
|
https://github.com/BootstrapCMS/Credentials/blob/128c5359eea7417ca95670933a28d4e6c7e01e6b/src/Http/Controllers/LoginController.php#L78-L126
|
227,225
|
ExtPoint/yii2-megamenu
|
lib/MenuHelper.php
|
MenuHelper.menuToRules
|
public static function menuToRules($items)
{
$rules = [];
foreach ($items as $item) {
$url = ArrayHelper::getValue($item, 'url');
$urlRule = ArrayHelper::getValue($item, 'urlRule');
if ($url && $urlRule && is_array($url)) {
$defaults = $url;
$route = array_shift($defaults);
if (is_string($urlRule)) {
$rules[] = [
'pattern' => Yii::getAlias($urlRule),
'route' => $route,
];
} elseif (is_array($urlRule)) {
if (!isset($urlRule['route'])) {
$urlRule['route'] = $route;
}
$rules[] = $urlRule;
}
}
$subItems = ArrayHelper::getValue($item, 'items');
if (is_array($subItems)) {
$rules = array_merge(static::menuToRules($subItems), $rules);
}
}
return $rules;
}
|
php
|
public static function menuToRules($items)
{
$rules = [];
foreach ($items as $item) {
$url = ArrayHelper::getValue($item, 'url');
$urlRule = ArrayHelper::getValue($item, 'urlRule');
if ($url && $urlRule && is_array($url)) {
$defaults = $url;
$route = array_shift($defaults);
if (is_string($urlRule)) {
$rules[] = [
'pattern' => Yii::getAlias($urlRule),
'route' => $route,
];
} elseif (is_array($urlRule)) {
if (!isset($urlRule['route'])) {
$urlRule['route'] = $route;
}
$rules[] = $urlRule;
}
}
$subItems = ArrayHelper::getValue($item, 'items');
if (is_array($subItems)) {
$rules = array_merge(static::menuToRules($subItems), $rules);
}
}
return $rules;
}
|
[
"public",
"static",
"function",
"menuToRules",
"(",
"$",
"items",
")",
"{",
"$",
"rules",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"url",
"=",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"item",
",",
"'url'",
")",
";",
"$",
"urlRule",
"=",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"item",
",",
"'urlRule'",
")",
";",
"if",
"(",
"$",
"url",
"&&",
"$",
"urlRule",
"&&",
"is_array",
"(",
"$",
"url",
")",
")",
"{",
"$",
"defaults",
"=",
"$",
"url",
";",
"$",
"route",
"=",
"array_shift",
"(",
"$",
"defaults",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"urlRule",
")",
")",
"{",
"$",
"rules",
"[",
"]",
"=",
"[",
"'pattern'",
"=>",
"Yii",
"::",
"getAlias",
"(",
"$",
"urlRule",
")",
",",
"'route'",
"=>",
"$",
"route",
",",
"]",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"urlRule",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"urlRule",
"[",
"'route'",
"]",
")",
")",
"{",
"$",
"urlRule",
"[",
"'route'",
"]",
"=",
"$",
"route",
";",
"}",
"$",
"rules",
"[",
"]",
"=",
"$",
"urlRule",
";",
"}",
"}",
"$",
"subItems",
"=",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"item",
",",
"'items'",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"subItems",
")",
")",
"{",
"$",
"rules",
"=",
"array_merge",
"(",
"static",
"::",
"menuToRules",
"(",
"$",
"subItems",
")",
",",
"$",
"rules",
")",
";",
"}",
"}",
"return",
"$",
"rules",
";",
"}"
] |
Recursive scan all items and return url rules for `UrlManager` component
@param array $items
@return array
|
[
"Recursive",
"scan",
"all",
"items",
"and",
"return",
"url",
"rules",
"for",
"UrlManager",
"component"
] |
d5ce4e34787d77244022c677a3158c97a1c3c480
|
https://github.com/ExtPoint/yii2-megamenu/blob/d5ce4e34787d77244022c677a3158c97a1c3c480/lib/MenuHelper.php#L17-L47
|
227,226
|
neoxygen/neo4j-neogen
|
src/Schema/GraphSchema.php
|
GraphSchema.addNode
|
public function addNode(Node $node)
{
foreach ($this->nodes as $n) {
if ($n->getIdentifier() === $node->getIdentifier()) {
throw new SchemaDefinitionException(sprintf('The node with Identifier "%s" has already been declared', $node->getIdentifier()));
}
}
return $this->nodes->add($node);
}
|
php
|
public function addNode(Node $node)
{
foreach ($this->nodes as $n) {
if ($n->getIdentifier() === $node->getIdentifier()) {
throw new SchemaDefinitionException(sprintf('The node with Identifier "%s" has already been declared', $node->getIdentifier()));
}
}
return $this->nodes->add($node);
}
|
[
"public",
"function",
"addNode",
"(",
"Node",
"$",
"node",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"nodes",
"as",
"$",
"n",
")",
"{",
"if",
"(",
"$",
"n",
"->",
"getIdentifier",
"(",
")",
"===",
"$",
"node",
"->",
"getIdentifier",
"(",
")",
")",
"{",
"throw",
"new",
"SchemaDefinitionException",
"(",
"sprintf",
"(",
"'The node with Identifier \"%s\" has already been declared'",
",",
"$",
"node",
"->",
"getIdentifier",
"(",
")",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"nodes",
"->",
"add",
"(",
"$",
"node",
")",
";",
"}"
] |
Adds a node to the nodes collection
@param Node $node
@return bool
@throws SchemaDefinitionException
|
[
"Adds",
"a",
"node",
"to",
"the",
"nodes",
"collection"
] |
3bc3ae1b95aae13915ce699b4f2d20762b2f0146
|
https://github.com/neoxygen/neo4j-neogen/blob/3bc3ae1b95aae13915ce699b4f2d20762b2f0146/src/Schema/GraphSchema.php#L54-L63
|
227,227
|
neoxygen/neo4j-neogen
|
src/Schema/GraphSchema.php
|
GraphSchema.addRelationship
|
public function addRelationship(Relationship $relationship)
{
foreach ($this->relationships as $rel) {
if ($rel->getType() === $relationship->getType() &&
$rel->getStartNode() === $relationship->getStartNode() &&
$rel->getEndNode() === $relationship->getEndNode()) {
throw new SchemaDefinitionException(sprintf('There is already a relationship declared with TYPE "%s" and STARTNODE "%s" and ENDNODE "%s"',
$relationship->getType(), $relationship->getStartNode(), $relationship->getEndNode()));
}
}
return $this->relationships->add($relationship);
}
|
php
|
public function addRelationship(Relationship $relationship)
{
foreach ($this->relationships as $rel) {
if ($rel->getType() === $relationship->getType() &&
$rel->getStartNode() === $relationship->getStartNode() &&
$rel->getEndNode() === $relationship->getEndNode()) {
throw new SchemaDefinitionException(sprintf('There is already a relationship declared with TYPE "%s" and STARTNODE "%s" and ENDNODE "%s"',
$relationship->getType(), $relationship->getStartNode(), $relationship->getEndNode()));
}
}
return $this->relationships->add($relationship);
}
|
[
"public",
"function",
"addRelationship",
"(",
"Relationship",
"$",
"relationship",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"relationships",
"as",
"$",
"rel",
")",
"{",
"if",
"(",
"$",
"rel",
"->",
"getType",
"(",
")",
"===",
"$",
"relationship",
"->",
"getType",
"(",
")",
"&&",
"$",
"rel",
"->",
"getStartNode",
"(",
")",
"===",
"$",
"relationship",
"->",
"getStartNode",
"(",
")",
"&&",
"$",
"rel",
"->",
"getEndNode",
"(",
")",
"===",
"$",
"relationship",
"->",
"getEndNode",
"(",
")",
")",
"{",
"throw",
"new",
"SchemaDefinitionException",
"(",
"sprintf",
"(",
"'There is already a relationship declared with TYPE \"%s\" and STARTNODE \"%s\" and ENDNODE \"%s\"'",
",",
"$",
"relationship",
"->",
"getType",
"(",
")",
",",
"$",
"relationship",
"->",
"getStartNode",
"(",
")",
",",
"$",
"relationship",
"->",
"getEndNode",
"(",
")",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"relationships",
"->",
"add",
"(",
"$",
"relationship",
")",
";",
"}"
] |
Adds a relationship to the relationship collection
@param Relationship $relationship
@return bool
@throws SchemaDefinitionException
|
[
"Adds",
"a",
"relationship",
"to",
"the",
"relationship",
"collection"
] |
3bc3ae1b95aae13915ce699b4f2d20762b2f0146
|
https://github.com/neoxygen/neo4j-neogen/blob/3bc3ae1b95aae13915ce699b4f2d20762b2f0146/src/Schema/GraphSchema.php#L72-L84
|
227,228
|
javanile/moldable
|
src/Database/ModelApi.php
|
ModelApi.getFields
|
public function getFields($model)
{
//
$table = $this->getTable($model);
//
$sql = "DESC `{$table}`";
//
$results = $this->getResults($sql);
//
$fields = [];
//
foreach ($results as $field) {
$fields[] = $field['Field'];
}
//
return $fields;
}
|
php
|
public function getFields($model)
{
//
$table = $this->getTable($model);
//
$sql = "DESC `{$table}`";
//
$results = $this->getResults($sql);
//
$fields = [];
//
foreach ($results as $field) {
$fields[] = $field['Field'];
}
//
return $fields;
}
|
[
"public",
"function",
"getFields",
"(",
"$",
"model",
")",
"{",
"//",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
"$",
"model",
")",
";",
"//",
"$",
"sql",
"=",
"\"DESC `{$table}`\"",
";",
"//",
"$",
"results",
"=",
"$",
"this",
"->",
"getResults",
"(",
"$",
"sql",
")",
";",
"//",
"$",
"fields",
"=",
"[",
"]",
";",
"//",
"foreach",
"(",
"$",
"results",
"as",
"$",
"field",
")",
"{",
"$",
"fields",
"[",
"]",
"=",
"$",
"field",
"[",
"'Field'",
"]",
";",
"}",
"//",
"return",
"$",
"fields",
";",
"}"
] |
Describe table.
@param type $table
@param mixed $model
@return type
|
[
"Describe",
"table",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Database/ModelApi.php#L59-L80
|
227,229
|
javanile/moldable
|
src/Database/ModelApi.php
|
ModelApi.exists
|
public function exists($model, $query)
{
//
$params = [];
//
$whereArray = [];
//
if (isset($query['where'])) {
$whereArray[] = $query['where'];
unset($query['where']);
}
//
$schema = $this->getFields($model);
foreach ($schema as $field) {
if (!isset($query[$field])) {
continue;
}
$value = $query[$field];
$token = ':'.$field;
$params[$token] = $value;
$whereArray[] = "`{$field}` = {$token}";
}
$where = count($whereArray) > 0
? 'WHERE '.implode(' AND ', $whereArray) : '';
$table = $this->getPrefix($model);
$sql = "SELECT * FROM `{$table}` {$where} LIMIT 1";
$row = $this->getRow($sql, $params);
return $row;
}
|
php
|
public function exists($model, $query)
{
//
$params = [];
//
$whereArray = [];
//
if (isset($query['where'])) {
$whereArray[] = $query['where'];
unset($query['where']);
}
//
$schema = $this->getFields($model);
foreach ($schema as $field) {
if (!isset($query[$field])) {
continue;
}
$value = $query[$field];
$token = ':'.$field;
$params[$token] = $value;
$whereArray[] = "`{$field}` = {$token}";
}
$where = count($whereArray) > 0
? 'WHERE '.implode(' AND ', $whereArray) : '';
$table = $this->getPrefix($model);
$sql = "SELECT * FROM `{$table}` {$where} LIMIT 1";
$row = $this->getRow($sql, $params);
return $row;
}
|
[
"public",
"function",
"exists",
"(",
"$",
"model",
",",
"$",
"query",
")",
"{",
"//",
"$",
"params",
"=",
"[",
"]",
";",
"//",
"$",
"whereArray",
"=",
"[",
"]",
";",
"//",
"if",
"(",
"isset",
"(",
"$",
"query",
"[",
"'where'",
"]",
")",
")",
"{",
"$",
"whereArray",
"[",
"]",
"=",
"$",
"query",
"[",
"'where'",
"]",
";",
"unset",
"(",
"$",
"query",
"[",
"'where'",
"]",
")",
";",
"}",
"//",
"$",
"schema",
"=",
"$",
"this",
"->",
"getFields",
"(",
"$",
"model",
")",
";",
"foreach",
"(",
"$",
"schema",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"query",
"[",
"$",
"field",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"value",
"=",
"$",
"query",
"[",
"$",
"field",
"]",
";",
"$",
"token",
"=",
"':'",
".",
"$",
"field",
";",
"$",
"params",
"[",
"$",
"token",
"]",
"=",
"$",
"value",
";",
"$",
"whereArray",
"[",
"]",
"=",
"\"`{$field}` = {$token}\"",
";",
"}",
"$",
"where",
"=",
"count",
"(",
"$",
"whereArray",
")",
">",
"0",
"?",
"'WHERE '",
".",
"implode",
"(",
"' AND '",
",",
"$",
"whereArray",
")",
":",
"''",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"getPrefix",
"(",
"$",
"model",
")",
";",
"$",
"sql",
"=",
"\"SELECT * FROM `{$table}` {$where} LIMIT 1\"",
";",
"$",
"row",
"=",
"$",
"this",
"->",
"getRow",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"return",
"$",
"row",
";",
"}"
] |
Check if record exists.
@param mixed $model
@param mixed $query
|
[
"Check",
"if",
"record",
"exists",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Database/ModelApi.php#L116-L151
|
227,230
|
javanile/moldable
|
src/Database/ModelApi.php
|
ModelApi.import
|
public function import(
$model,
$records
//$map = null
) {
if (!$records || !is_array($records[0])) {
return;
}
foreach ($records as $record) {
$schema = [];
foreach (array_keys($record) as $field) {
$schema[$field] = '';
}
$this->adapt($model, $schema);
$this->submit($model, $record);
}
}
|
php
|
public function import(
$model,
$records
//$map = null
) {
if (!$records || !is_array($records[0])) {
return;
}
foreach ($records as $record) {
$schema = [];
foreach (array_keys($record) as $field) {
$schema[$field] = '';
}
$this->adapt($model, $schema);
$this->submit($model, $record);
}
}
|
[
"public",
"function",
"import",
"(",
"$",
"model",
",",
"$",
"records",
"//$map = null",
")",
"{",
"if",
"(",
"!",
"$",
"records",
"||",
"!",
"is_array",
"(",
"$",
"records",
"[",
"0",
"]",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"records",
"as",
"$",
"record",
")",
"{",
"$",
"schema",
"=",
"[",
"]",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"record",
")",
"as",
"$",
"field",
")",
"{",
"$",
"schema",
"[",
"$",
"field",
"]",
"=",
"''",
";",
"}",
"$",
"this",
"->",
"adapt",
"(",
"$",
"model",
",",
"$",
"schema",
")",
";",
"$",
"this",
"->",
"submit",
"(",
"$",
"model",
",",
"$",
"record",
")",
";",
"}",
"}"
] |
Import records into a model table.
@param type $list
@param mixed $model
@param mixed $records
|
[
"Import",
"records",
"into",
"a",
"model",
"table",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Database/ModelApi.php#L160-L179
|
227,231
|
javanile/moldable
|
src/Database/ModelApi.php
|
ModelApi.drop
|
public function drop($model, $confirm)
{
// exit if no correct confirmation string
if ($confirm != 'confirm') {
return;
}
//
$models = $model == '*'
? $this->getModels()
: [$model];
//
if (!count($models)) {
return;
}
//
foreach ($models as $model) {
$table = $this->getTable($model);
//
if (!$table) {
continue;
}
//
$sql = "DROP TABLE `{$table}`";
//
$this->execute($sql);
}
}
|
php
|
public function drop($model, $confirm)
{
// exit if no correct confirmation string
if ($confirm != 'confirm') {
return;
}
//
$models = $model == '*'
? $this->getModels()
: [$model];
//
if (!count($models)) {
return;
}
//
foreach ($models as $model) {
$table = $this->getTable($model);
//
if (!$table) {
continue;
}
//
$sql = "DROP TABLE `{$table}`";
//
$this->execute($sql);
}
}
|
[
"public",
"function",
"drop",
"(",
"$",
"model",
",",
"$",
"confirm",
")",
"{",
"// exit if no correct confirmation string",
"if",
"(",
"$",
"confirm",
"!=",
"'confirm'",
")",
"{",
"return",
";",
"}",
"//",
"$",
"models",
"=",
"$",
"model",
"==",
"'*'",
"?",
"$",
"this",
"->",
"getModels",
"(",
")",
":",
"[",
"$",
"model",
"]",
";",
"//",
"if",
"(",
"!",
"count",
"(",
"$",
"models",
")",
")",
"{",
"return",
";",
"}",
"//",
"foreach",
"(",
"$",
"models",
"as",
"$",
"model",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
"$",
"model",
")",
";",
"//",
"if",
"(",
"!",
"$",
"table",
")",
"{",
"continue",
";",
"}",
"//",
"$",
"sql",
"=",
"\"DROP TABLE `{$table}`\"",
";",
"//",
"$",
"this",
"->",
"execute",
"(",
"$",
"sql",
")",
";",
"}",
"}"
] |
Drop delete table related to a model.
@param string $model Model name to drop
@param string $confirm Confirmation string
|
[
"Drop",
"delete",
"table",
"related",
"to",
"a",
"model",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Database/ModelApi.php#L204-L236
|
227,232
|
javanile/moldable
|
src/Database/ModelApi.php
|
ModelApi.dump
|
public function dump($model = null)
{
if ($model) {
$all = $this->all($model);
Functions::dumpGrid($all, $model);
} else {
$this->dumpSchema();
}
}
|
php
|
public function dump($model = null)
{
if ($model) {
$all = $this->all($model);
Functions::dumpGrid($all, $model);
} else {
$this->dumpSchema();
}
}
|
[
"public",
"function",
"dump",
"(",
"$",
"model",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"model",
")",
"{",
"$",
"all",
"=",
"$",
"this",
"->",
"all",
"(",
"$",
"model",
")",
";",
"Functions",
"::",
"dumpGrid",
"(",
"$",
"all",
",",
"$",
"model",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"dumpSchema",
"(",
")",
";",
"}",
"}"
] |
Dump all data.
@param null|mixed $model
|
[
"Dump",
"all",
"data",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Database/ModelApi.php#L243-L251
|
227,233
|
aik099/CodingStandard
|
CodingStandard/Sniffs/WhiteSpace/CommaSpacingSniff.php
|
CommaSpacingSniff.checkContentBefore
|
public function checkContentBefore(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$prevToken = $tokens[($stackPtr - 1)];
if ($prevToken['content'] === '(') {
return;
}
if ($prevToken['code'] === T_WHITESPACE && $tokens[($stackPtr - 2)]['code'] !== T_COMMA) {
$error = 'Space found before comma';
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'Before');
if ($fix === true) {
$phpcsFile->fixer->replaceToken(($stackPtr - 1), '');
}
}
}
|
php
|
public function checkContentBefore(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$prevToken = $tokens[($stackPtr - 1)];
if ($prevToken['content'] === '(') {
return;
}
if ($prevToken['code'] === T_WHITESPACE && $tokens[($stackPtr - 2)]['code'] !== T_COMMA) {
$error = 'Space found before comma';
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'Before');
if ($fix === true) {
$phpcsFile->fixer->replaceToken(($stackPtr - 1), '');
}
}
}
|
[
"public",
"function",
"checkContentBefore",
"(",
"File",
"$",
"phpcsFile",
",",
"$",
"stackPtr",
")",
"{",
"$",
"tokens",
"=",
"$",
"phpcsFile",
"->",
"getTokens",
"(",
")",
";",
"$",
"prevToken",
"=",
"$",
"tokens",
"[",
"(",
"$",
"stackPtr",
"-",
"1",
")",
"]",
";",
"if",
"(",
"$",
"prevToken",
"[",
"'content'",
"]",
"===",
"'('",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"prevToken",
"[",
"'code'",
"]",
"===",
"T_WHITESPACE",
"&&",
"$",
"tokens",
"[",
"(",
"$",
"stackPtr",
"-",
"2",
")",
"]",
"[",
"'code'",
"]",
"!==",
"T_COMMA",
")",
"{",
"$",
"error",
"=",
"'Space found before comma'",
";",
"$",
"fix",
"=",
"$",
"phpcsFile",
"->",
"addFixableError",
"(",
"$",
"error",
",",
"$",
"stackPtr",
",",
"'Before'",
")",
";",
"if",
"(",
"$",
"fix",
"===",
"true",
")",
"{",
"$",
"phpcsFile",
"->",
"fixer",
"->",
"replaceToken",
"(",
"(",
"$",
"stackPtr",
"-",
"1",
")",
",",
"''",
")",
";",
"}",
"}",
"}"
] |
Checks spacing before comma.
@param File $phpcsFile The file being scanned.
@param int $stackPtr The position of the current token
in the stack passed in $tokens.
@return void
|
[
"Checks",
"spacing",
"before",
"comma",
"."
] |
0f65c52bf2d95d5068af9f73110770ddb9de8de7
|
https://github.com/aik099/CodingStandard/blob/0f65c52bf2d95d5068af9f73110770ddb9de8de7/CodingStandard/Sniffs/WhiteSpace/CommaSpacingSniff.php#L69-L85
|
227,234
|
aik099/CodingStandard
|
CodingStandard/Sniffs/WhiteSpace/CommaSpacingSniff.php
|
CommaSpacingSniff.checkContentAfter
|
public function checkContentAfter(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$nextToken = $tokens[($stackPtr + 1)];
if ($nextToken['content'] === ')') {
return;
}
if ($nextToken['code'] !== T_WHITESPACE) {
$error = 'No space found after comma';
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'After');
if ($fix === true) {
$phpcsFile->fixer->addContent($stackPtr, ' ');
}
} elseif ($nextToken['content'] !== $phpcsFile->eolChar) {
$spacingLength = $nextToken['length'];
if ($spacingLength === 1) {
$tokenAfterSpace = $tokens[($stackPtr + 2)];
if ($tokenAfterSpace['content'] === ')') {
$error = 'Space found after comma';
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'After');
if ($fix === true) {
$phpcsFile->fixer->replaceToken(($stackPtr + 1), '');
}
}
} else {
$error = 'Expected 1 space after comma; %s found';
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'After', array($spacingLength));
if ($fix === true) {
$phpcsFile->fixer->replaceToken(($stackPtr + 1), ' ');
}
}
}
}
|
php
|
public function checkContentAfter(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$nextToken = $tokens[($stackPtr + 1)];
if ($nextToken['content'] === ')') {
return;
}
if ($nextToken['code'] !== T_WHITESPACE) {
$error = 'No space found after comma';
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'After');
if ($fix === true) {
$phpcsFile->fixer->addContent($stackPtr, ' ');
}
} elseif ($nextToken['content'] !== $phpcsFile->eolChar) {
$spacingLength = $nextToken['length'];
if ($spacingLength === 1) {
$tokenAfterSpace = $tokens[($stackPtr + 2)];
if ($tokenAfterSpace['content'] === ')') {
$error = 'Space found after comma';
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'After');
if ($fix === true) {
$phpcsFile->fixer->replaceToken(($stackPtr + 1), '');
}
}
} else {
$error = 'Expected 1 space after comma; %s found';
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'After', array($spacingLength));
if ($fix === true) {
$phpcsFile->fixer->replaceToken(($stackPtr + 1), ' ');
}
}
}
}
|
[
"public",
"function",
"checkContentAfter",
"(",
"File",
"$",
"phpcsFile",
",",
"$",
"stackPtr",
")",
"{",
"$",
"tokens",
"=",
"$",
"phpcsFile",
"->",
"getTokens",
"(",
")",
";",
"$",
"nextToken",
"=",
"$",
"tokens",
"[",
"(",
"$",
"stackPtr",
"+",
"1",
")",
"]",
";",
"if",
"(",
"$",
"nextToken",
"[",
"'content'",
"]",
"===",
"')'",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"nextToken",
"[",
"'code'",
"]",
"!==",
"T_WHITESPACE",
")",
"{",
"$",
"error",
"=",
"'No space found after comma'",
";",
"$",
"fix",
"=",
"$",
"phpcsFile",
"->",
"addFixableError",
"(",
"$",
"error",
",",
"$",
"stackPtr",
",",
"'After'",
")",
";",
"if",
"(",
"$",
"fix",
"===",
"true",
")",
"{",
"$",
"phpcsFile",
"->",
"fixer",
"->",
"addContent",
"(",
"$",
"stackPtr",
",",
"' '",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"nextToken",
"[",
"'content'",
"]",
"!==",
"$",
"phpcsFile",
"->",
"eolChar",
")",
"{",
"$",
"spacingLength",
"=",
"$",
"nextToken",
"[",
"'length'",
"]",
";",
"if",
"(",
"$",
"spacingLength",
"===",
"1",
")",
"{",
"$",
"tokenAfterSpace",
"=",
"$",
"tokens",
"[",
"(",
"$",
"stackPtr",
"+",
"2",
")",
"]",
";",
"if",
"(",
"$",
"tokenAfterSpace",
"[",
"'content'",
"]",
"===",
"')'",
")",
"{",
"$",
"error",
"=",
"'Space found after comma'",
";",
"$",
"fix",
"=",
"$",
"phpcsFile",
"->",
"addFixableError",
"(",
"$",
"error",
",",
"$",
"stackPtr",
",",
"'After'",
")",
";",
"if",
"(",
"$",
"fix",
"===",
"true",
")",
"{",
"$",
"phpcsFile",
"->",
"fixer",
"->",
"replaceToken",
"(",
"(",
"$",
"stackPtr",
"+",
"1",
")",
",",
"''",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"error",
"=",
"'Expected 1 space after comma; %s found'",
";",
"$",
"fix",
"=",
"$",
"phpcsFile",
"->",
"addFixableError",
"(",
"$",
"error",
",",
"$",
"stackPtr",
",",
"'After'",
",",
"array",
"(",
"$",
"spacingLength",
")",
")",
";",
"if",
"(",
"$",
"fix",
"===",
"true",
")",
"{",
"$",
"phpcsFile",
"->",
"fixer",
"->",
"replaceToken",
"(",
"(",
"$",
"stackPtr",
"+",
"1",
")",
",",
"' '",
")",
";",
"}",
"}",
"}",
"}"
] |
Checks spacing after comma.
@param File $phpcsFile The file being scanned.
@param int $stackPtr The position of the current token
in the stack passed in $tokens.
@return void
|
[
"Checks",
"spacing",
"after",
"comma",
"."
] |
0f65c52bf2d95d5068af9f73110770ddb9de8de7
|
https://github.com/aik099/CodingStandard/blob/0f65c52bf2d95d5068af9f73110770ddb9de8de7/CodingStandard/Sniffs/WhiteSpace/CommaSpacingSniff.php#L96-L130
|
227,235
|
javanile/moldable
|
src/Database/SchemaApi.php
|
SchemaApi.desc
|
public function desc($only = null)
{
$schema = [];
$prefix = strlen($this->getPrefix());
$tables = $this->getTables();
if (!$tables) {
return $schema;
}
if (is_string($only)) {
$only = [$only];
}
foreach ($tables as $table) {
$model = substr($table, $prefix);
if (!$only || in_array($model, $only)) {
$schema[$model] = $this->descTable($table);
}
}
return $schema;
}
|
php
|
public function desc($only = null)
{
$schema = [];
$prefix = strlen($this->getPrefix());
$tables = $this->getTables();
if (!$tables) {
return $schema;
}
if (is_string($only)) {
$only = [$only];
}
foreach ($tables as $table) {
$model = substr($table, $prefix);
if (!$only || in_array($model, $only)) {
$schema[$model] = $this->descTable($table);
}
}
return $schema;
}
|
[
"public",
"function",
"desc",
"(",
"$",
"only",
"=",
"null",
")",
"{",
"$",
"schema",
"=",
"[",
"]",
";",
"$",
"prefix",
"=",
"strlen",
"(",
"$",
"this",
"->",
"getPrefix",
"(",
")",
")",
";",
"$",
"tables",
"=",
"$",
"this",
"->",
"getTables",
"(",
")",
";",
"if",
"(",
"!",
"$",
"tables",
")",
"{",
"return",
"$",
"schema",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"only",
")",
")",
"{",
"$",
"only",
"=",
"[",
"$",
"only",
"]",
";",
"}",
"foreach",
"(",
"$",
"tables",
"as",
"$",
"table",
")",
"{",
"$",
"model",
"=",
"substr",
"(",
"$",
"table",
",",
"$",
"prefix",
")",
";",
"if",
"(",
"!",
"$",
"only",
"||",
"in_array",
"(",
"$",
"model",
",",
"$",
"only",
")",
")",
"{",
"$",
"schema",
"[",
"$",
"model",
"]",
"=",
"$",
"this",
"->",
"descTable",
"(",
"$",
"table",
")",
";",
"}",
"}",
"return",
"$",
"schema",
";",
"}"
] |
Describe database each tables
with the specific prefix and her fields.
@param null|mixed $only
@return array return an array with database description schema
|
[
"Describe",
"database",
"each",
"tables",
"with",
"the",
"specific",
"prefix",
"and",
"her",
"fields",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Database/SchemaApi.php#L25-L48
|
227,236
|
javanile/moldable
|
src/Database/SchemaApi.php
|
SchemaApi.descTable
|
public function descTable($table)
{
//
$sql = "DESC `{$table}`";
$fields = $this->getResults($sql);
$desc = [];
$count = 0;
$before = false;
//
foreach ($fields as $field) {
$field['First'] = $count === 0;
$field['Before'] = $before;
$desc[$field['Field']] = $field;
$before = $field['Field'];
$count++;
}
return $desc;
}
|
php
|
public function descTable($table)
{
//
$sql = "DESC `{$table}`";
$fields = $this->getResults($sql);
$desc = [];
$count = 0;
$before = false;
//
foreach ($fields as $field) {
$field['First'] = $count === 0;
$field['Before'] = $before;
$desc[$field['Field']] = $field;
$before = $field['Field'];
$count++;
}
return $desc;
}
|
[
"public",
"function",
"descTable",
"(",
"$",
"table",
")",
"{",
"//",
"$",
"sql",
"=",
"\"DESC `{$table}`\"",
";",
"$",
"fields",
"=",
"$",
"this",
"->",
"getResults",
"(",
"$",
"sql",
")",
";",
"$",
"desc",
"=",
"[",
"]",
";",
"$",
"count",
"=",
"0",
";",
"$",
"before",
"=",
"false",
";",
"//",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"field",
"[",
"'First'",
"]",
"=",
"$",
"count",
"===",
"0",
";",
"$",
"field",
"[",
"'Before'",
"]",
"=",
"$",
"before",
";",
"$",
"desc",
"[",
"$",
"field",
"[",
"'Field'",
"]",
"]",
"=",
"$",
"field",
";",
"$",
"before",
"=",
"$",
"field",
"[",
"'Field'",
"]",
";",
"$",
"count",
"++",
";",
"}",
"return",
"$",
"desc",
";",
"}"
] |
describe table.
@param type $table
@return type
|
[
"describe",
"table",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Database/SchemaApi.php#L57-L76
|
227,237
|
javanile/moldable
|
src/Database/SchemaApi.php
|
SchemaApi.apply
|
public function apply($schema, $columns = null, $notation = null)
{
//
if (is_string($schema)) {
$schema = [
$schema => is_string($columns)
? [$columns => $notation]
: $columns,
];
}
//
if (!$schema || count($schema) == 0 || !is_array($schema)) {
$this->error('generic', 'empty schema not allowed');
}
//
foreach ($schema as $model => $attributes) {
if (!$attributes || count($attributes) == 0 || !is_array($attributes)) {
$this->error('generic', "empty model '{$model}' not allowed");
}
}
// retrive queries
$queries = $this->diff($schema);
// send all queries to align database
if (count($queries) > 0) {
foreach ($queries as $sql) {
$this->execute($sql);
}
}
return $queries;
}
|
php
|
public function apply($schema, $columns = null, $notation = null)
{
//
if (is_string($schema)) {
$schema = [
$schema => is_string($columns)
? [$columns => $notation]
: $columns,
];
}
//
if (!$schema || count($schema) == 0 || !is_array($schema)) {
$this->error('generic', 'empty schema not allowed');
}
//
foreach ($schema as $model => $attributes) {
if (!$attributes || count($attributes) == 0 || !is_array($attributes)) {
$this->error('generic', "empty model '{$model}' not allowed");
}
}
// retrive queries
$queries = $this->diff($schema);
// send all queries to align database
if (count($queries) > 0) {
foreach ($queries as $sql) {
$this->execute($sql);
}
}
return $queries;
}
|
[
"public",
"function",
"apply",
"(",
"$",
"schema",
",",
"$",
"columns",
"=",
"null",
",",
"$",
"notation",
"=",
"null",
")",
"{",
"//",
"if",
"(",
"is_string",
"(",
"$",
"schema",
")",
")",
"{",
"$",
"schema",
"=",
"[",
"$",
"schema",
"=>",
"is_string",
"(",
"$",
"columns",
")",
"?",
"[",
"$",
"columns",
"=>",
"$",
"notation",
"]",
":",
"$",
"columns",
",",
"]",
";",
"}",
"//",
"if",
"(",
"!",
"$",
"schema",
"||",
"count",
"(",
"$",
"schema",
")",
"==",
"0",
"||",
"!",
"is_array",
"(",
"$",
"schema",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'generic'",
",",
"'empty schema not allowed'",
")",
";",
"}",
"//",
"foreach",
"(",
"$",
"schema",
"as",
"$",
"model",
"=>",
"$",
"attributes",
")",
"{",
"if",
"(",
"!",
"$",
"attributes",
"||",
"count",
"(",
"$",
"attributes",
")",
"==",
"0",
"||",
"!",
"is_array",
"(",
"$",
"attributes",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'generic'",
",",
"\"empty model '{$model}' not allowed\"",
")",
";",
"}",
"}",
"// retrive queries",
"$",
"queries",
"=",
"$",
"this",
"->",
"diff",
"(",
"$",
"schema",
")",
";",
"// send all queries to align database",
"if",
"(",
"count",
"(",
"$",
"queries",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"queries",
"as",
"$",
"sql",
")",
"{",
"$",
"this",
"->",
"execute",
"(",
"$",
"sql",
")",
";",
"}",
"}",
"return",
"$",
"queries",
";",
"}"
] |
Apply schema on the database.
@param type $schema
@param null|mixed $columns
@param null|mixed $notation
@return type
|
[
"Apply",
"schema",
"on",
"the",
"database",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Database/SchemaApi.php#L87-L121
|
227,238
|
javanile/moldable
|
src/Database/SchemaApi.php
|
SchemaApi.applyTable
|
public function applyTable($table, $schema, $parse = true)
{
// retrive queries
$queries = $this->diffTable($table, $schema, $parse);
// execute queries
if ($queries && count($queries) > 0) {
// loop throu all queries calculated and execute it
foreach ($queries as $sql) {
// execute each queries
$this->execute($sql);
}
}
return $queries;
}
|
php
|
public function applyTable($table, $schema, $parse = true)
{
// retrive queries
$queries = $this->diffTable($table, $schema, $parse);
// execute queries
if ($queries && count($queries) > 0) {
// loop throu all queries calculated and execute it
foreach ($queries as $sql) {
// execute each queries
$this->execute($sql);
}
}
return $queries;
}
|
[
"public",
"function",
"applyTable",
"(",
"$",
"table",
",",
"$",
"schema",
",",
"$",
"parse",
"=",
"true",
")",
"{",
"// retrive queries",
"$",
"queries",
"=",
"$",
"this",
"->",
"diffTable",
"(",
"$",
"table",
",",
"$",
"schema",
",",
"$",
"parse",
")",
";",
"// execute queries",
"if",
"(",
"$",
"queries",
"&&",
"count",
"(",
"$",
"queries",
")",
">",
"0",
")",
"{",
"// loop throu all queries calculated and execute it",
"foreach",
"(",
"$",
"queries",
"as",
"$",
"sql",
")",
"{",
"// execute each queries",
"$",
"this",
"->",
"execute",
"(",
"$",
"sql",
")",
";",
"}",
"}",
"return",
"$",
"queries",
";",
"}"
] |
Update database table via schema.
@param string $table real table name to update
@param type $schema
@param type $parse
@return type
|
[
"Update",
"database",
"table",
"via",
"schema",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Database/SchemaApi.php#L132-L147
|
227,239
|
javanile/moldable
|
src/Database/SchemaApi.php
|
SchemaApi.diff
|
public function diff($schema, $parse = true)
{
// prepare
if ($parse) {
$this->getParser()->parse($schema);
}
// output container for rescued SQL query
$queries = [];
// loop throu the schema
foreach ($schema as $table => &$attributes) {
$table = $parse ? $this->getPrefix($table) : $table;
$query = $this->diffTable($table, $attributes, false);
if (count($query) > 0) {
$queries = array_merge($queries, $query);
}
}
return $queries;
}
|
php
|
public function diff($schema, $parse = true)
{
// prepare
if ($parse) {
$this->getParser()->parse($schema);
}
// output container for rescued SQL query
$queries = [];
// loop throu the schema
foreach ($schema as $table => &$attributes) {
$table = $parse ? $this->getPrefix($table) : $table;
$query = $this->diffTable($table, $attributes, false);
if (count($query) > 0) {
$queries = array_merge($queries, $query);
}
}
return $queries;
}
|
[
"public",
"function",
"diff",
"(",
"$",
"schema",
",",
"$",
"parse",
"=",
"true",
")",
"{",
"// prepare",
"if",
"(",
"$",
"parse",
")",
"{",
"$",
"this",
"->",
"getParser",
"(",
")",
"->",
"parse",
"(",
"$",
"schema",
")",
";",
"}",
"// output container for rescued SQL query",
"$",
"queries",
"=",
"[",
"]",
";",
"// loop throu the schema",
"foreach",
"(",
"$",
"schema",
"as",
"$",
"table",
"=>",
"&",
"$",
"attributes",
")",
"{",
"$",
"table",
"=",
"$",
"parse",
"?",
"$",
"this",
"->",
"getPrefix",
"(",
"$",
"table",
")",
":",
"$",
"table",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"diffTable",
"(",
"$",
"table",
",",
"$",
"attributes",
",",
"false",
")",
";",
"if",
"(",
"count",
"(",
"$",
"query",
")",
">",
"0",
")",
"{",
"$",
"queries",
"=",
"array_merge",
"(",
"$",
"queries",
",",
"$",
"query",
")",
";",
"}",
"}",
"return",
"$",
"queries",
";",
"}"
] |
Generate SQL query to align database
compare real database and passed schema.
@param type $schema
@param type $parse
@return type
|
[
"Generate",
"SQL",
"query",
"to",
"align",
"database",
"compare",
"real",
"database",
"and",
"passed",
"schema",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Database/SchemaApi.php#L158-L179
|
227,240
|
javanile/moldable
|
src/Database/SchemaApi.php
|
SchemaApi.diffTableFieldAttributes
|
private function diffTableFieldAttributes($field, &$attributes, &$fields)
{
// loop throd current column property
foreach ($fields[$field] as $key => $value) {
// if have a difference
if ($attributes[$key] == $value) {
continue;
}
//
if ($this->isDebug()) {
//echo '<pre style="background:#E66;color:#000;margin:0 0 1px 0;padding:2px 6px 3px 6px;border:1px solid #000;">';
//echo ' difference: "'.$attributes[$key].'" != "'.$value.'" in '.$field.'['.$key.']</pre>';
}
return true;
}
return false;
}
|
php
|
private function diffTableFieldAttributes($field, &$attributes, &$fields)
{
// loop throd current column property
foreach ($fields[$field] as $key => $value) {
// if have a difference
if ($attributes[$key] == $value) {
continue;
}
//
if ($this->isDebug()) {
//echo '<pre style="background:#E66;color:#000;margin:0 0 1px 0;padding:2px 6px 3px 6px;border:1px solid #000;">';
//echo ' difference: "'.$attributes[$key].'" != "'.$value.'" in '.$field.'['.$key.']</pre>';
}
return true;
}
return false;
}
|
[
"private",
"function",
"diffTableFieldAttributes",
"(",
"$",
"field",
",",
"&",
"$",
"attributes",
",",
"&",
"$",
"fields",
")",
"{",
"// loop throd current column property",
"foreach",
"(",
"$",
"fields",
"[",
"$",
"field",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// if have a difference",
"if",
"(",
"$",
"attributes",
"[",
"$",
"key",
"]",
"==",
"$",
"value",
")",
"{",
"continue",
";",
"}",
"//",
"if",
"(",
"$",
"this",
"->",
"isDebug",
"(",
")",
")",
"{",
"//echo '<pre style=\"background:#E66;color:#000;margin:0 0 1px 0;padding:2px 6px 3px 6px;border:1px solid #000;\">';",
"//echo ' difference: \"'.$attributes[$key].'\" != \"'.$value.'\" in '.$field.'['.$key.']</pre>';",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Evaluate diff between a field and their attributes
vs fields set definitions releaved direct from db.
@param type $field
@param type $attributes
@param type $fields
@return bool
|
[
"Evaluate",
"diff",
"between",
"a",
"field",
"and",
"their",
"attributes",
"vs",
"fields",
"set",
"definitions",
"releaved",
"direct",
"from",
"db",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Database/SchemaApi.php#L339-L358
|
227,241
|
javanile/moldable
|
src/Database/SchemaApi.php
|
SchemaApi.profile
|
public function profile($values)
{
$profile = [];
foreach (array_keys($values) as $field) {
$profile[$field] = '';
}
return $profile;
}
|
php
|
public function profile($values)
{
$profile = [];
foreach (array_keys($values) as $field) {
$profile[$field] = '';
}
return $profile;
}
|
[
"public",
"function",
"profile",
"(",
"$",
"values",
")",
"{",
"$",
"profile",
"=",
"[",
"]",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"values",
")",
"as",
"$",
"field",
")",
"{",
"$",
"profile",
"[",
"$",
"field",
"]",
"=",
"''",
";",
"}",
"return",
"$",
"profile",
";",
"}"
] |
Get values profile.
@param mixed $values
|
[
"Get",
"values",
"profile",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Database/SchemaApi.php#L459-L468
|
227,242
|
javanile/moldable
|
src/Database/UpdateApi.php
|
UpdateApi.getUpdateWhere
|
private function getUpdateWhere($query, &$params)
{
$whereArray = [];
if (isset($query['where'])) {
$whereArray[] = '('.$query['where'].')';
unset($query['where']);
}
foreach ($query as $field => $value) {
if ($field[0] == ':') {
$params[$field] = $value;
continue;
}
$token = ':'.$field;
$whereArray[] = "{$field} = {$token}";
$params[$token] = $value;
}
return implode(' AND ', $whereArray);
}
|
php
|
private function getUpdateWhere($query, &$params)
{
$whereArray = [];
if (isset($query['where'])) {
$whereArray[] = '('.$query['where'].')';
unset($query['where']);
}
foreach ($query as $field => $value) {
if ($field[0] == ':') {
$params[$field] = $value;
continue;
}
$token = ':'.$field;
$whereArray[] = "{$field} = {$token}";
$params[$token] = $value;
}
return implode(' AND ', $whereArray);
}
|
[
"private",
"function",
"getUpdateWhere",
"(",
"$",
"query",
",",
"&",
"$",
"params",
")",
"{",
"$",
"whereArray",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"query",
"[",
"'where'",
"]",
")",
")",
"{",
"$",
"whereArray",
"[",
"]",
"=",
"'('",
".",
"$",
"query",
"[",
"'where'",
"]",
".",
"')'",
";",
"unset",
"(",
"$",
"query",
"[",
"'where'",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"query",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"field",
"[",
"0",
"]",
"==",
"':'",
")",
"{",
"$",
"params",
"[",
"$",
"field",
"]",
"=",
"$",
"value",
";",
"continue",
";",
"}",
"$",
"token",
"=",
"':'",
".",
"$",
"field",
";",
"$",
"whereArray",
"[",
"]",
"=",
"\"{$field} = {$token}\"",
";",
"$",
"params",
"[",
"$",
"token",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"implode",
"(",
"' AND '",
",",
"$",
"whereArray",
")",
";",
"}"
] |
Build where conditions.
@param mixed $query
|
[
"Build",
"where",
"conditions",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Database/UpdateApi.php#L66-L86
|
227,243
|
ExtPoint/yii2-megamenu
|
lib/MegaMenu.php
|
MegaMenu.getItems
|
public function getItems()
{
if ($this->isModulesFetched === false) {
$this->isModulesFetched = true;
// Fetch items from modules
foreach (Yii::$app->getModules() as $id => $module) {
/** @var \yii\base\Module $module */
$module = Yii::$app->getModule($id);
if (method_exists($module, 'coreMenu')) {
$this->addItems($module->coreMenu(), true);
}
// Submodules support
foreach ($module->getModules() as $subId => $subModule) {
$subModule = $module->getModule($subId);
if (method_exists($subModule, 'coreMenu')) {
$this->addItems($subModule->coreMenu(), true);
}
}
}
}
return $this->_items;
}
|
php
|
public function getItems()
{
if ($this->isModulesFetched === false) {
$this->isModulesFetched = true;
// Fetch items from modules
foreach (Yii::$app->getModules() as $id => $module) {
/** @var \yii\base\Module $module */
$module = Yii::$app->getModule($id);
if (method_exists($module, 'coreMenu')) {
$this->addItems($module->coreMenu(), true);
}
// Submodules support
foreach ($module->getModules() as $subId => $subModule) {
$subModule = $module->getModule($subId);
if (method_exists($subModule, 'coreMenu')) {
$this->addItems($subModule->coreMenu(), true);
}
}
}
}
return $this->_items;
}
|
[
"public",
"function",
"getItems",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isModulesFetched",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"isModulesFetched",
"=",
"true",
";",
"// Fetch items from modules",
"foreach",
"(",
"Yii",
"::",
"$",
"app",
"->",
"getModules",
"(",
")",
"as",
"$",
"id",
"=>",
"$",
"module",
")",
"{",
"/** @var \\yii\\base\\Module $module */",
"$",
"module",
"=",
"Yii",
"::",
"$",
"app",
"->",
"getModule",
"(",
"$",
"id",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"module",
",",
"'coreMenu'",
")",
")",
"{",
"$",
"this",
"->",
"addItems",
"(",
"$",
"module",
"->",
"coreMenu",
"(",
")",
",",
"true",
")",
";",
"}",
"// Submodules support",
"foreach",
"(",
"$",
"module",
"->",
"getModules",
"(",
")",
"as",
"$",
"subId",
"=>",
"$",
"subModule",
")",
"{",
"$",
"subModule",
"=",
"$",
"module",
"->",
"getModule",
"(",
"$",
"subId",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"subModule",
",",
"'coreMenu'",
")",
")",
"{",
"$",
"this",
"->",
"addItems",
"(",
"$",
"subModule",
"->",
"coreMenu",
"(",
")",
",",
"true",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"_items",
";",
"}"
] |
Get all tree menu items
@return array
|
[
"Get",
"all",
"tree",
"menu",
"items"
] |
d5ce4e34787d77244022c677a3158c97a1c3c480
|
https://github.com/ExtPoint/yii2-megamenu/blob/d5ce4e34787d77244022c677a3158c97a1c3c480/lib/MegaMenu.php#L47-L71
|
227,244
|
ExtPoint/yii2-megamenu
|
lib/MegaMenu.php
|
MegaMenu.addItems
|
public function addItems(array $items, $append = true)
{
$this->_items = $this->mergeItems($this->_items, $items, $append);
}
|
php
|
public function addItems(array $items, $append = true)
{
$this->_items = $this->mergeItems($this->_items, $items, $append);
}
|
[
"public",
"function",
"addItems",
"(",
"array",
"$",
"items",
",",
"$",
"append",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"_items",
"=",
"$",
"this",
"->",
"mergeItems",
"(",
"$",
"this",
"->",
"_items",
",",
"$",
"items",
",",
"$",
"append",
")",
";",
"}"
] |
Add tree menu items
@param array $items
@param bool|true $append
|
[
"Add",
"tree",
"menu",
"items"
] |
d5ce4e34787d77244022c677a3158c97a1c3c480
|
https://github.com/ExtPoint/yii2-megamenu/blob/d5ce4e34787d77244022c677a3158c97a1c3c480/lib/MegaMenu.php#L78-L81
|
227,245
|
ExtPoint/yii2-megamenu
|
lib/MegaMenu.php
|
MegaMenu.getBreadcrumbs
|
public function getBreadcrumbs($url = null)
{
$url = $url ?: $this->getRequestedRoute();
// Find child and it parents by url
$itemModel = $this->getItem($url, $parents);
if (!$itemModel || (empty($parents) && $this->isHomeUrl($itemModel->normalizedUrl))) {
return [];
}
$parents = array_reverse((array)$parents);
$parents[] = [
'label' => $itemModel->modelLabel,
'url' => $itemModel->normalizedUrl,
'linkOptions' => is_array($itemModel->linkOptions) ? $itemModel->linkOptions : [],
];
foreach ($parents as &$parent) {
if (isset($parent['linkOptions'])) {
$parent = array_merge($parent, $parent['linkOptions']);
unset($parent['linkOptions']);
}
}
return $parents;
}
|
php
|
public function getBreadcrumbs($url = null)
{
$url = $url ?: $this->getRequestedRoute();
// Find child and it parents by url
$itemModel = $this->getItem($url, $parents);
if (!$itemModel || (empty($parents) && $this->isHomeUrl($itemModel->normalizedUrl))) {
return [];
}
$parents = array_reverse((array)$parents);
$parents[] = [
'label' => $itemModel->modelLabel,
'url' => $itemModel->normalizedUrl,
'linkOptions' => is_array($itemModel->linkOptions) ? $itemModel->linkOptions : [],
];
foreach ($parents as &$parent) {
if (isset($parent['linkOptions'])) {
$parent = array_merge($parent, $parent['linkOptions']);
unset($parent['linkOptions']);
}
}
return $parents;
}
|
[
"public",
"function",
"getBreadcrumbs",
"(",
"$",
"url",
"=",
"null",
")",
"{",
"$",
"url",
"=",
"$",
"url",
"?",
":",
"$",
"this",
"->",
"getRequestedRoute",
"(",
")",
";",
"// Find child and it parents by url",
"$",
"itemModel",
"=",
"$",
"this",
"->",
"getItem",
"(",
"$",
"url",
",",
"$",
"parents",
")",
";",
"if",
"(",
"!",
"$",
"itemModel",
"||",
"(",
"empty",
"(",
"$",
"parents",
")",
"&&",
"$",
"this",
"->",
"isHomeUrl",
"(",
"$",
"itemModel",
"->",
"normalizedUrl",
")",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"parents",
"=",
"array_reverse",
"(",
"(",
"array",
")",
"$",
"parents",
")",
";",
"$",
"parents",
"[",
"]",
"=",
"[",
"'label'",
"=>",
"$",
"itemModel",
"->",
"modelLabel",
",",
"'url'",
"=>",
"$",
"itemModel",
"->",
"normalizedUrl",
",",
"'linkOptions'",
"=>",
"is_array",
"(",
"$",
"itemModel",
"->",
"linkOptions",
")",
"?",
"$",
"itemModel",
"->",
"linkOptions",
":",
"[",
"]",
",",
"]",
";",
"foreach",
"(",
"$",
"parents",
"as",
"&",
"$",
"parent",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"parent",
"[",
"'linkOptions'",
"]",
")",
")",
"{",
"$",
"parent",
"=",
"array_merge",
"(",
"$",
"parent",
",",
"$",
"parent",
"[",
"'linkOptions'",
"]",
")",
";",
"unset",
"(",
"$",
"parent",
"[",
"'linkOptions'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"parents",
";",
"}"
] |
Return breadcrumbs links for widget \yii\widgets\Breadcrumbs
@param array|null $url Child url or route, default - current route
@return array
|
[
"Return",
"breadcrumbs",
"links",
"for",
"widget",
"\\",
"yii",
"\\",
"widgets",
"\\",
"Breadcrumbs"
] |
d5ce4e34787d77244022c677a3158c97a1c3c480
|
https://github.com/ExtPoint/yii2-megamenu/blob/d5ce4e34787d77244022c677a3158c97a1c3c480/lib/MegaMenu.php#L177-L203
|
227,246
|
ExtPoint/yii2-megamenu
|
lib/MegaMenu.php
|
MegaMenu.getItemUrl
|
public function getItemUrl($item)
{
$item = $this->getItem($item);
return $item ? $item->normalizedUrl : null;
}
|
php
|
public function getItemUrl($item)
{
$item = $this->getItem($item);
return $item ? $item->normalizedUrl : null;
}
|
[
"public",
"function",
"getItemUrl",
"(",
"$",
"item",
")",
"{",
"$",
"item",
"=",
"$",
"this",
"->",
"getItem",
"(",
"$",
"item",
")",
";",
"return",
"$",
"item",
"?",
"$",
"item",
"->",
"normalizedUrl",
":",
"null",
";",
"}"
] |
Find item by url or route and return it url
@param $item
@return array|null|string
|
[
"Find",
"item",
"by",
"url",
"or",
"route",
"and",
"return",
"it",
"url"
] |
d5ce4e34787d77244022c677a3158c97a1c3c480
|
https://github.com/ExtPoint/yii2-megamenu/blob/d5ce4e34787d77244022c677a3158c97a1c3c480/lib/MegaMenu.php#L229-L233
|
227,247
|
BootstrapCMS/Credentials
|
src/Presenters/RevisionDisplayers/User/RemovedGroupDisplayer.php
|
RemovedGroupDisplayer.current
|
protected function current()
{
if ($this->author() === 'You ') {
return 'You removed yourself from the "'.$this->wrappedObject->new_value.'" group.';
}
return $this->author().'removed you from the "'.$this->wrappedObject->new_value.'" group.';
}
|
php
|
protected function current()
{
if ($this->author() === 'You ') {
return 'You removed yourself from the "'.$this->wrappedObject->new_value.'" group.';
}
return $this->author().'removed you from the "'.$this->wrappedObject->new_value.'" group.';
}
|
[
"protected",
"function",
"current",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"author",
"(",
")",
"===",
"'You '",
")",
"{",
"return",
"'You removed yourself from the \"'",
".",
"$",
"this",
"->",
"wrappedObject",
"->",
"new_value",
".",
"'\" group.'",
";",
"}",
"return",
"$",
"this",
"->",
"author",
"(",
")",
".",
"'removed you from the \"'",
".",
"$",
"this",
"->",
"wrappedObject",
"->",
"new_value",
".",
"'\" group.'",
";",
"}"
] |
Get the change description from the context of
the change being made to the current user.
@return string
|
[
"Get",
"the",
"change",
"description",
"from",
"the",
"context",
"of",
"the",
"change",
"being",
"made",
"to",
"the",
"current",
"user",
"."
] |
128c5359eea7417ca95670933a28d4e6c7e01e6b
|
https://github.com/BootstrapCMS/Credentials/blob/128c5359eea7417ca95670933a28d4e6c7e01e6b/src/Presenters/RevisionDisplayers/User/RemovedGroupDisplayer.php#L37-L44
|
227,248
|
javanile/moldable
|
src/Model/LoadApi.php
|
LoadApi.load
|
public static function load($query, $fields = null)
{
//
static::applySchema();
//
if (is_array($query)) {
return static::loadByQuery($query, $fields);
}
//
$key = static::getPrimaryKey();
//
return $key
? static::loadByPrimaryKey($query, $fields)
: static::loadByMainField($query, $fields);
}
|
php
|
public static function load($query, $fields = null)
{
//
static::applySchema();
//
if (is_array($query)) {
return static::loadByQuery($query, $fields);
}
//
$key = static::getPrimaryKey();
//
return $key
? static::loadByPrimaryKey($query, $fields)
: static::loadByMainField($query, $fields);
}
|
[
"public",
"static",
"function",
"load",
"(",
"$",
"query",
",",
"$",
"fields",
"=",
"null",
")",
"{",
"//",
"static",
"::",
"applySchema",
"(",
")",
";",
"//",
"if",
"(",
"is_array",
"(",
"$",
"query",
")",
")",
"{",
"return",
"static",
"::",
"loadByQuery",
"(",
"$",
"query",
",",
"$",
"fields",
")",
";",
"}",
"//",
"$",
"key",
"=",
"static",
"::",
"getPrimaryKey",
"(",
")",
";",
"//",
"return",
"$",
"key",
"?",
"static",
"::",
"loadByPrimaryKey",
"(",
"$",
"query",
",",
"$",
"fields",
")",
":",
"static",
"::",
"loadByMainField",
"(",
"$",
"query",
",",
"$",
"fields",
")",
";",
"}"
] |
Load item from DB.
@param type $id
@param mixed $query
@param null|mixed $fields
@return type
|
[
"Load",
"item",
"from",
"DB",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Model/LoadApi.php#L23-L40
|
227,249
|
javanile/moldable
|
src/Model/LoadApi.php
|
LoadApi.loadByPrimaryKey
|
protected static function loadByPrimaryKey($index, $fields = null)
{
//
$table = static::getTable();
// get primary key
$key = static::getPrimaryKey();
//
$alias = static::getClassName();
//
$join = null;
//
$requestedFields = $fields ? $fields : static::getDefaultFields();
// parse SQL select fields
$selectFields = static::getDatabase()
->getWriter()
->selectFields($requestedFields, $alias, $join);
// prepare SQL query
$sql = " SELECT {$selectFields} "
." FROM {$table} AS {$alias} {$join} "
." WHERE {$alias}.{$key}=:index "
.' LIMIT 1';
$params = [
'index' => $index,
];
// fetch data on database and return it
$result = static::fetch($sql, $params, [
'SingleRow' => true,
'SingleValue' => is_string($fields),
'CastToObject' => is_null($fields),
//'ExpanseObject' => static::isReadable(),
'ExpanseObject' => false,
]);
//
return $result;
}
|
php
|
protected static function loadByPrimaryKey($index, $fields = null)
{
//
$table = static::getTable();
// get primary key
$key = static::getPrimaryKey();
//
$alias = static::getClassName();
//
$join = null;
//
$requestedFields = $fields ? $fields : static::getDefaultFields();
// parse SQL select fields
$selectFields = static::getDatabase()
->getWriter()
->selectFields($requestedFields, $alias, $join);
// prepare SQL query
$sql = " SELECT {$selectFields} "
." FROM {$table} AS {$alias} {$join} "
." WHERE {$alias}.{$key}=:index "
.' LIMIT 1';
$params = [
'index' => $index,
];
// fetch data on database and return it
$result = static::fetch($sql, $params, [
'SingleRow' => true,
'SingleValue' => is_string($fields),
'CastToObject' => is_null($fields),
//'ExpanseObject' => static::isReadable(),
'ExpanseObject' => false,
]);
//
return $result;
}
|
[
"protected",
"static",
"function",
"loadByPrimaryKey",
"(",
"$",
"index",
",",
"$",
"fields",
"=",
"null",
")",
"{",
"//",
"$",
"table",
"=",
"static",
"::",
"getTable",
"(",
")",
";",
"// get primary key",
"$",
"key",
"=",
"static",
"::",
"getPrimaryKey",
"(",
")",
";",
"//",
"$",
"alias",
"=",
"static",
"::",
"getClassName",
"(",
")",
";",
"//",
"$",
"join",
"=",
"null",
";",
"//",
"$",
"requestedFields",
"=",
"$",
"fields",
"?",
"$",
"fields",
":",
"static",
"::",
"getDefaultFields",
"(",
")",
";",
"// parse SQL select fields",
"$",
"selectFields",
"=",
"static",
"::",
"getDatabase",
"(",
")",
"->",
"getWriter",
"(",
")",
"->",
"selectFields",
"(",
"$",
"requestedFields",
",",
"$",
"alias",
",",
"$",
"join",
")",
";",
"// prepare SQL query",
"$",
"sql",
"=",
"\" SELECT {$selectFields} \"",
".",
"\" FROM {$table} AS {$alias} {$join} \"",
".",
"\" WHERE {$alias}.{$key}=:index \"",
".",
"' LIMIT 1'",
";",
"$",
"params",
"=",
"[",
"'index'",
"=>",
"$",
"index",
",",
"]",
";",
"// fetch data on database and return it",
"$",
"result",
"=",
"static",
"::",
"fetch",
"(",
"$",
"sql",
",",
"$",
"params",
",",
"[",
"'SingleRow'",
"=>",
"true",
",",
"'SingleValue'",
"=>",
"is_string",
"(",
"$",
"fields",
")",
",",
"'CastToObject'",
"=>",
"is_null",
"(",
"$",
"fields",
")",
",",
"//'ExpanseObject' => static::isReadable(),",
"'ExpanseObject'",
"=>",
"false",
",",
"]",
")",
";",
"//",
"return",
"$",
"result",
";",
"}"
] |
Load a record by primary key.
@param type $index
@param type $fields
@return type
|
[
"Load",
"a",
"record",
"by",
"primary",
"key",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Model/LoadApi.php#L50-L93
|
227,250
|
javanile/moldable
|
src/Model/LoadApi.php
|
LoadApi.loadByQuery
|
protected static function loadByQuery($query, $fields = null)
{
//
$table = static::getTable();
$writer = static::getDatabase()->getWriter();
$alias = static::getClassName();
//
$join = null;
$allFields = $fields ? $fields : static::getDefaultFields();
// parse SQL select fields
$selectFields = $writer->selectFields($allFields, $alias, $join);
//
$values = [];
$whereConditions = [];
//
if (isset($query['where'])) {
$whereConditions[] = '('.$query['where'].')';
unset($query['where']);
}
//
foreach ($query as $field => $value) {
$token = ':'.$field;
$whereConditions[] = "{$field} = {$token}";
$values[$field] = $value;
}
//
$where = implode(' AND ', $whereConditions);
// prepare SQL query
$sql = "SELECT {$selectFields} "
."FROM {$table} AS {$alias} {$join} "
."WHERE {$where} "
.'LIMIT 1';
// fetch data on database and return it
$result = static::fetch(
$sql,
$values,
true,
is_string($fields),
is_null($fields)
);
return $result;
}
|
php
|
protected static function loadByQuery($query, $fields = null)
{
//
$table = static::getTable();
$writer = static::getDatabase()->getWriter();
$alias = static::getClassName();
//
$join = null;
$allFields = $fields ? $fields : static::getDefaultFields();
// parse SQL select fields
$selectFields = $writer->selectFields($allFields, $alias, $join);
//
$values = [];
$whereConditions = [];
//
if (isset($query['where'])) {
$whereConditions[] = '('.$query['where'].')';
unset($query['where']);
}
//
foreach ($query as $field => $value) {
$token = ':'.$field;
$whereConditions[] = "{$field} = {$token}";
$values[$field] = $value;
}
//
$where = implode(' AND ', $whereConditions);
// prepare SQL query
$sql = "SELECT {$selectFields} "
."FROM {$table} AS {$alias} {$join} "
."WHERE {$where} "
.'LIMIT 1';
// fetch data on database and return it
$result = static::fetch(
$sql,
$values,
true,
is_string($fields),
is_null($fields)
);
return $result;
}
|
[
"protected",
"static",
"function",
"loadByQuery",
"(",
"$",
"query",
",",
"$",
"fields",
"=",
"null",
")",
"{",
"//",
"$",
"table",
"=",
"static",
"::",
"getTable",
"(",
")",
";",
"$",
"writer",
"=",
"static",
"::",
"getDatabase",
"(",
")",
"->",
"getWriter",
"(",
")",
";",
"$",
"alias",
"=",
"static",
"::",
"getClassName",
"(",
")",
";",
"//",
"$",
"join",
"=",
"null",
";",
"$",
"allFields",
"=",
"$",
"fields",
"?",
"$",
"fields",
":",
"static",
"::",
"getDefaultFields",
"(",
")",
";",
"// parse SQL select fields",
"$",
"selectFields",
"=",
"$",
"writer",
"->",
"selectFields",
"(",
"$",
"allFields",
",",
"$",
"alias",
",",
"$",
"join",
")",
";",
"//",
"$",
"values",
"=",
"[",
"]",
";",
"$",
"whereConditions",
"=",
"[",
"]",
";",
"//",
"if",
"(",
"isset",
"(",
"$",
"query",
"[",
"'where'",
"]",
")",
")",
"{",
"$",
"whereConditions",
"[",
"]",
"=",
"'('",
".",
"$",
"query",
"[",
"'where'",
"]",
".",
"')'",
";",
"unset",
"(",
"$",
"query",
"[",
"'where'",
"]",
")",
";",
"}",
"//",
"foreach",
"(",
"$",
"query",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"token",
"=",
"':'",
".",
"$",
"field",
";",
"$",
"whereConditions",
"[",
"]",
"=",
"\"{$field} = {$token}\"",
";",
"$",
"values",
"[",
"$",
"field",
"]",
"=",
"$",
"value",
";",
"}",
"//",
"$",
"where",
"=",
"implode",
"(",
"' AND '",
",",
"$",
"whereConditions",
")",
";",
"// prepare SQL query",
"$",
"sql",
"=",
"\"SELECT {$selectFields} \"",
".",
"\"FROM {$table} AS {$alias} {$join} \"",
".",
"\"WHERE {$where} \"",
".",
"'LIMIT 1'",
";",
"// fetch data on database and return it",
"$",
"result",
"=",
"static",
"::",
"fetch",
"(",
"$",
"sql",
",",
"$",
"values",
",",
"true",
",",
"is_string",
"(",
"$",
"fields",
")",
",",
"is_null",
"(",
"$",
"fields",
")",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Load one record by array-query.
@param type $query
@param type $fields
@return type
|
[
"Load",
"one",
"record",
"by",
"array",
"-",
"query",
"."
] |
463ec60ba1fc00ffac39416302103af47aae42fb
|
https://github.com/javanile/moldable/blob/463ec60ba1fc00ffac39416302103af47aae42fb/src/Model/LoadApi.php#L155-L205
|
227,251
|
web2all/safebrowsingv4
|
src/GoogleSafeBrowsing/Updater.php
|
GoogleSafeBrowsing_Updater.initializeFromStorage
|
protected function initializeFromStorage()
{
$this->debugLog('initializeFromStorage()');
$this->lists=$this->storage->getLists();
$this->next_request_timestamp=$this->storage->getNextRunTimestamp();
$this->error_count=$this->storage->getErrorCount();
$this->debugLog('current memory usage: '.memory_get_usage());
$this->debugLog('peak memory usage : '.memory_get_peak_usage());
}
|
php
|
protected function initializeFromStorage()
{
$this->debugLog('initializeFromStorage()');
$this->lists=$this->storage->getLists();
$this->next_request_timestamp=$this->storage->getNextRunTimestamp();
$this->error_count=$this->storage->getErrorCount();
$this->debugLog('current memory usage: '.memory_get_usage());
$this->debugLog('peak memory usage : '.memory_get_peak_usage());
}
|
[
"protected",
"function",
"initializeFromStorage",
"(",
")",
"{",
"$",
"this",
"->",
"debugLog",
"(",
"'initializeFromStorage()'",
")",
";",
"$",
"this",
"->",
"lists",
"=",
"$",
"this",
"->",
"storage",
"->",
"getLists",
"(",
")",
";",
"$",
"this",
"->",
"next_request_timestamp",
"=",
"$",
"this",
"->",
"storage",
"->",
"getNextRunTimestamp",
"(",
")",
";",
"$",
"this",
"->",
"error_count",
"=",
"$",
"this",
"->",
"storage",
"->",
"getErrorCount",
"(",
")",
";",
"$",
"this",
"->",
"debugLog",
"(",
"'current memory usage: '",
".",
"memory_get_usage",
"(",
")",
")",
";",
"$",
"this",
"->",
"debugLog",
"(",
"'peak memory usage : '",
".",
"memory_get_peak_usage",
"(",
")",
")",
";",
"}"
] |
Initializes object state from storage backend
|
[
"Initializes",
"object",
"state",
"from",
"storage",
"backend"
] |
e506341efa8d919974c8eb362987bc1e2f398983
|
https://github.com/web2all/safebrowsingv4/blob/e506341efa8d919974c8eb362987bc1e2f398983/src/GoogleSafeBrowsing/Updater.php#L125-L134
|
227,252
|
web2all/safebrowsingv4
|
src/GoogleSafeBrowsing/Updater.php
|
GoogleSafeBrowsing_Updater.serializeToStorage
|
protected function serializeToStorage()
{
$this->debugLog('serializeToStorage()');
$this->storage->updateLists($this->lists);
$this->storage->setUpdaterState($this->next_request_timestamp, $this->error_count);
$this->debugLog('current memory usage: '.memory_get_usage());
$this->debugLog('peak memory usage : '.memory_get_peak_usage());
}
|
php
|
protected function serializeToStorage()
{
$this->debugLog('serializeToStorage()');
$this->storage->updateLists($this->lists);
$this->storage->setUpdaterState($this->next_request_timestamp, $this->error_count);
$this->debugLog('current memory usage: '.memory_get_usage());
$this->debugLog('peak memory usage : '.memory_get_peak_usage());
}
|
[
"protected",
"function",
"serializeToStorage",
"(",
")",
"{",
"$",
"this",
"->",
"debugLog",
"(",
"'serializeToStorage()'",
")",
";",
"$",
"this",
"->",
"storage",
"->",
"updateLists",
"(",
"$",
"this",
"->",
"lists",
")",
";",
"$",
"this",
"->",
"storage",
"->",
"setUpdaterState",
"(",
"$",
"this",
"->",
"next_request_timestamp",
",",
"$",
"this",
"->",
"error_count",
")",
";",
"$",
"this",
"->",
"debugLog",
"(",
"'current memory usage: '",
".",
"memory_get_usage",
"(",
")",
")",
";",
"$",
"this",
"->",
"debugLog",
"(",
"'peak memory usage : '",
".",
"memory_get_peak_usage",
"(",
")",
")",
";",
"}"
] |
stores object state to storage backend
|
[
"stores",
"object",
"state",
"to",
"storage",
"backend"
] |
e506341efa8d919974c8eb362987bc1e2f398983
|
https://github.com/web2all/safebrowsingv4/blob/e506341efa8d919974c8eb362987bc1e2f398983/src/GoogleSafeBrowsing/Updater.php#L140-L148
|
227,253
|
web2all/safebrowsingv4
|
src/GoogleSafeBrowsing/Updater.php
|
GoogleSafeBrowsing_Updater.setLists
|
public function setLists($lists)
{
$this->lists=$lists;
// update the storage, else we are out of sync
$this->storage->updateLists($this->lists);
}
|
php
|
public function setLists($lists)
{
$this->lists=$lists;
// update the storage, else we are out of sync
$this->storage->updateLists($this->lists);
}
|
[
"public",
"function",
"setLists",
"(",
"$",
"lists",
")",
"{",
"$",
"this",
"->",
"lists",
"=",
"$",
"lists",
";",
"// update the storage, else we are out of sync",
"$",
"this",
"->",
"storage",
"->",
"updateLists",
"(",
"$",
"this",
"->",
"lists",
")",
";",
"}"
] |
Set the current lists
@param array $lists
|
[
"Set",
"the",
"current",
"lists"
] |
e506341efa8d919974c8eb362987bc1e2f398983
|
https://github.com/web2all/safebrowsingv4/blob/e506341efa8d919974c8eb362987bc1e2f398983/src/GoogleSafeBrowsing/Updater.php#L155-L160
|
227,254
|
web2all/safebrowsingv4
|
src/GoogleSafeBrowsing/Updater.php
|
GoogleSafeBrowsing_Updater.pcntlSignalSetup
|
protected function pcntlSignalSetup()
{
if (function_exists('pcntl_signal')) {
pcntl_signal(SIGHUP, array($this,'exitSignalHandler') );// kill -HUP
pcntl_signal(SIGTERM, array($this,'exitSignalHandler') );// kill
pcntl_signal(SIGINT, array($this,'exitSignalHandler') );// CTRL-C
$this->pcntl_enabled=true;
// pre 5.3 fallback
if (!function_exists('pcntl_signal_dispatch')) {
$this->pcntl_emulate_dispatch=true;
}
$this->debugLog('pcntlSignalSetup: signal handling enabled');
}
}
|
php
|
protected function pcntlSignalSetup()
{
if (function_exists('pcntl_signal')) {
pcntl_signal(SIGHUP, array($this,'exitSignalHandler') );// kill -HUP
pcntl_signal(SIGTERM, array($this,'exitSignalHandler') );// kill
pcntl_signal(SIGINT, array($this,'exitSignalHandler') );// CTRL-C
$this->pcntl_enabled=true;
// pre 5.3 fallback
if (!function_exists('pcntl_signal_dispatch')) {
$this->pcntl_emulate_dispatch=true;
}
$this->debugLog('pcntlSignalSetup: signal handling enabled');
}
}
|
[
"protected",
"function",
"pcntlSignalSetup",
"(",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'pcntl_signal'",
")",
")",
"{",
"pcntl_signal",
"(",
"SIGHUP",
",",
"array",
"(",
"$",
"this",
",",
"'exitSignalHandler'",
")",
")",
";",
"// kill -HUP",
"pcntl_signal",
"(",
"SIGTERM",
",",
"array",
"(",
"$",
"this",
",",
"'exitSignalHandler'",
")",
")",
";",
"// kill",
"pcntl_signal",
"(",
"SIGINT",
",",
"array",
"(",
"$",
"this",
",",
"'exitSignalHandler'",
")",
")",
";",
"// CTRL-C",
"$",
"this",
"->",
"pcntl_enabled",
"=",
"true",
";",
"// pre 5.3 fallback",
"if",
"(",
"!",
"function_exists",
"(",
"'pcntl_signal_dispatch'",
")",
")",
"{",
"$",
"this",
"->",
"pcntl_emulate_dispatch",
"=",
"true",
";",
"}",
"$",
"this",
"->",
"debugLog",
"(",
"'pcntlSignalSetup: signal handling enabled'",
")",
";",
"}",
"}"
] |
Set up signal handling if supported
Do NOT call from constructor!
|
[
"Set",
"up",
"signal",
"handling",
"if",
"supported"
] |
e506341efa8d919974c8eb362987bc1e2f398983
|
https://github.com/web2all/safebrowsingv4/blob/e506341efa8d919974c8eb362987bc1e2f398983/src/GoogleSafeBrowsing/Updater.php#L410-L423
|
227,255
|
ARCANEDEV/LaravelAuth
|
src/Seeders/UsersTableSeeder.php
|
UsersTableSeeder.prepareUsers
|
private function prepareUsers(array $data)
{
$users = [];
$now = Carbon::now();
foreach ($data as $user) {
$users[] = [
'username' => $user['username'],
'first_name' => Arr::get($user, 'first_name', null),
'last_name' => Arr::get($user, 'last_name', null),
'email' => $user['email'],
'password' => bcrypt($user['password']),
'is_admin' => true,
'created_at' => $now,
'updated_at' => $now,
'activated_at' => $user['activated_at'] ?? $now,
];
}
return $users;
}
|
php
|
private function prepareUsers(array $data)
{
$users = [];
$now = Carbon::now();
foreach ($data as $user) {
$users[] = [
'username' => $user['username'],
'first_name' => Arr::get($user, 'first_name', null),
'last_name' => Arr::get($user, 'last_name', null),
'email' => $user['email'],
'password' => bcrypt($user['password']),
'is_admin' => true,
'created_at' => $now,
'updated_at' => $now,
'activated_at' => $user['activated_at'] ?? $now,
];
}
return $users;
}
|
[
"private",
"function",
"prepareUsers",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"users",
"=",
"[",
"]",
";",
"$",
"now",
"=",
"Carbon",
"::",
"now",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"user",
")",
"{",
"$",
"users",
"[",
"]",
"=",
"[",
"'username'",
"=>",
"$",
"user",
"[",
"'username'",
"]",
",",
"'first_name'",
"=>",
"Arr",
"::",
"get",
"(",
"$",
"user",
",",
"'first_name'",
",",
"null",
")",
",",
"'last_name'",
"=>",
"Arr",
"::",
"get",
"(",
"$",
"user",
",",
"'last_name'",
",",
"null",
")",
",",
"'email'",
"=>",
"$",
"user",
"[",
"'email'",
"]",
",",
"'password'",
"=>",
"bcrypt",
"(",
"$",
"user",
"[",
"'password'",
"]",
")",
",",
"'is_admin'",
"=>",
"true",
",",
"'created_at'",
"=>",
"$",
"now",
",",
"'updated_at'",
"=>",
"$",
"now",
",",
"'activated_at'",
"=>",
"$",
"user",
"[",
"'activated_at'",
"]",
"??",
"$",
"now",
",",
"]",
";",
"}",
"return",
"$",
"users",
";",
"}"
] |
Prepare users.
@param array $data
@return array
|
[
"Prepare",
"users",
"."
] |
a2719e924c2299f931879139c6cd97642e80acc7
|
https://github.com/ARCANEDEV/LaravelAuth/blob/a2719e924c2299f931879139c6cd97642e80acc7/src/Seeders/UsersTableSeeder.php#L43-L63
|
227,256
|
yiimaker/yii2-translatable
|
src/TranslatableBehavior.php
|
TranslatableBehavior.getTranslation
|
public function getTranslation($language = null)
{
$language = $language ?: Yii::$app->language;
$translations = $this->getModelTranslations();
// search translation by language in exists translations
foreach ($translations as $translation) {
// if translation exists - return it
if ($translation->getAttribute($this->translationLanguageAttrName) === $language) {
$this->translationsBuffer[] = $translation;
return $translation;
}
}
// if translation doesn't exist - create and return
$translationEntityClass = $this->owner->getRelation($this->translationRelationName)->modelClass;
/* @var BaseActiveRecord $translation */
$translation = new $translationEntityClass();
$translation->setAttribute($this->translationLanguageAttrName, $language);
$translations[] = $translation;
$this->translationsBuffer = $translations;
$this->owner->populateRelation($this->translationRelationName, $translations);
return $translation;
}
|
php
|
public function getTranslation($language = null)
{
$language = $language ?: Yii::$app->language;
$translations = $this->getModelTranslations();
// search translation by language in exists translations
foreach ($translations as $translation) {
// if translation exists - return it
if ($translation->getAttribute($this->translationLanguageAttrName) === $language) {
$this->translationsBuffer[] = $translation;
return $translation;
}
}
// if translation doesn't exist - create and return
$translationEntityClass = $this->owner->getRelation($this->translationRelationName)->modelClass;
/* @var BaseActiveRecord $translation */
$translation = new $translationEntityClass();
$translation->setAttribute($this->translationLanguageAttrName, $language);
$translations[] = $translation;
$this->translationsBuffer = $translations;
$this->owner->populateRelation($this->translationRelationName, $translations);
return $translation;
}
|
[
"public",
"function",
"getTranslation",
"(",
"$",
"language",
"=",
"null",
")",
"{",
"$",
"language",
"=",
"$",
"language",
"?",
":",
"Yii",
"::",
"$",
"app",
"->",
"language",
";",
"$",
"translations",
"=",
"$",
"this",
"->",
"getModelTranslations",
"(",
")",
";",
"// search translation by language in exists translations",
"foreach",
"(",
"$",
"translations",
"as",
"$",
"translation",
")",
"{",
"// if translation exists - return it",
"if",
"(",
"$",
"translation",
"->",
"getAttribute",
"(",
"$",
"this",
"->",
"translationLanguageAttrName",
")",
"===",
"$",
"language",
")",
"{",
"$",
"this",
"->",
"translationsBuffer",
"[",
"]",
"=",
"$",
"translation",
";",
"return",
"$",
"translation",
";",
"}",
"}",
"// if translation doesn't exist - create and return",
"$",
"translationEntityClass",
"=",
"$",
"this",
"->",
"owner",
"->",
"getRelation",
"(",
"$",
"this",
"->",
"translationRelationName",
")",
"->",
"modelClass",
";",
"/* @var BaseActiveRecord $translation */",
"$",
"translation",
"=",
"new",
"$",
"translationEntityClass",
"(",
")",
";",
"$",
"translation",
"->",
"setAttribute",
"(",
"$",
"this",
"->",
"translationLanguageAttrName",
",",
"$",
"language",
")",
";",
"$",
"translations",
"[",
"]",
"=",
"$",
"translation",
";",
"$",
"this",
"->",
"translationsBuffer",
"=",
"$",
"translations",
";",
"$",
"this",
"->",
"owner",
"->",
"populateRelation",
"(",
"$",
"this",
"->",
"translationRelationName",
",",
"$",
"translations",
")",
";",
"return",
"$",
"translation",
";",
"}"
] |
Returns translation entity object for needed language.
@param null|string $language By default uses application current language.
@return \yii\db\ActiveRecord|BaseActiveRecord
|
[
"Returns",
"translation",
"entity",
"object",
"for",
"needed",
"language",
"."
] |
3c40cd3fa5821abc471a971fd21bfa591ecd25b5
|
https://github.com/yiimaker/yii2-translatable/blob/3c40cd3fa5821abc471a971fd21bfa591ecd25b5/src/TranslatableBehavior.php#L87-L113
|
227,257
|
yiimaker/yii2-translatable
|
src/TranslatableBehavior.php
|
TranslatableBehavior.hasTranslation
|
public function hasTranslation($language = null)
{
$language = $language ?: Yii::$app->language;
foreach ($this->getModelTranslations() as $translation) {
if ($translation->getAttribute($this->translationLanguageAttrName) === $language) {
return true;
}
}
return false;
}
|
php
|
public function hasTranslation($language = null)
{
$language = $language ?: Yii::$app->language;
foreach ($this->getModelTranslations() as $translation) {
if ($translation->getAttribute($this->translationLanguageAttrName) === $language) {
return true;
}
}
return false;
}
|
[
"public",
"function",
"hasTranslation",
"(",
"$",
"language",
"=",
"null",
")",
"{",
"$",
"language",
"=",
"$",
"language",
"?",
":",
"Yii",
"::",
"$",
"app",
"->",
"language",
";",
"foreach",
"(",
"$",
"this",
"->",
"getModelTranslations",
"(",
")",
"as",
"$",
"translation",
")",
"{",
"if",
"(",
"$",
"translation",
"->",
"getAttribute",
"(",
"$",
"this",
"->",
"translationLanguageAttrName",
")",
"===",
"$",
"language",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Check whether translation exists.
@param null|string $language By default uses application current language.
@return bool
|
[
"Check",
"whether",
"translation",
"exists",
"."
] |
3c40cd3fa5821abc471a971fd21bfa591ecd25b5
|
https://github.com/yiimaker/yii2-translatable/blob/3c40cd3fa5821abc471a971fd21bfa591ecd25b5/src/TranslatableBehavior.php#L122-L133
|
227,258
|
yiimaker/yii2-translatable
|
src/TranslatableBehavior.php
|
TranslatableBehavior.afterValidate
|
public function afterValidate()
{
$translations = $this->getModelTranslations();
$isValid = Model::validateMultiple($translations, $this->translationAttributeList);
if (!$isValid) {
foreach ($translations as $translation) {
foreach ($translation->getErrors() as $attribute => $errors) {
$attribute = \strtr($this->attributeNamePattern, [
'%name%' => $attribute,
'%language%' => $translation->{$this->translationLanguageAttrName},
]);
if (\is_array($errors)) {
foreach ($errors as $error) {
$this->owner->addError($attribute, $error);
}
} else {
$this->owner->addError($attribute, $errors);
}
}
}
}
}
|
php
|
public function afterValidate()
{
$translations = $this->getModelTranslations();
$isValid = Model::validateMultiple($translations, $this->translationAttributeList);
if (!$isValid) {
foreach ($translations as $translation) {
foreach ($translation->getErrors() as $attribute => $errors) {
$attribute = \strtr($this->attributeNamePattern, [
'%name%' => $attribute,
'%language%' => $translation->{$this->translationLanguageAttrName},
]);
if (\is_array($errors)) {
foreach ($errors as $error) {
$this->owner->addError($attribute, $error);
}
} else {
$this->owner->addError($attribute, $errors);
}
}
}
}
}
|
[
"public",
"function",
"afterValidate",
"(",
")",
"{",
"$",
"translations",
"=",
"$",
"this",
"->",
"getModelTranslations",
"(",
")",
";",
"$",
"isValid",
"=",
"Model",
"::",
"validateMultiple",
"(",
"$",
"translations",
",",
"$",
"this",
"->",
"translationAttributeList",
")",
";",
"if",
"(",
"!",
"$",
"isValid",
")",
"{",
"foreach",
"(",
"$",
"translations",
"as",
"$",
"translation",
")",
"{",
"foreach",
"(",
"$",
"translation",
"->",
"getErrors",
"(",
")",
"as",
"$",
"attribute",
"=>",
"$",
"errors",
")",
"{",
"$",
"attribute",
"=",
"\\",
"strtr",
"(",
"$",
"this",
"->",
"attributeNamePattern",
",",
"[",
"'%name%'",
"=>",
"$",
"attribute",
",",
"'%language%'",
"=>",
"$",
"translation",
"->",
"{",
"$",
"this",
"->",
"translationLanguageAttrName",
"}",
",",
"]",
")",
";",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"errors",
")",
")",
"{",
"foreach",
"(",
"$",
"errors",
"as",
"$",
"error",
")",
"{",
"$",
"this",
"->",
"owner",
"->",
"addError",
"(",
"$",
"attribute",
",",
"$",
"error",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"owner",
"->",
"addError",
"(",
"$",
"attribute",
",",
"$",
"errors",
")",
";",
"}",
"}",
"}",
"}",
"}"
] |
Triggers after validation of the main model.
|
[
"Triggers",
"after",
"validation",
"of",
"the",
"main",
"model",
"."
] |
3c40cd3fa5821abc471a971fd21bfa591ecd25b5
|
https://github.com/yiimaker/yii2-translatable/blob/3c40cd3fa5821abc471a971fd21bfa591ecd25b5/src/TranslatableBehavior.php#L150-L174
|
227,259
|
yiimaker/yii2-translatable
|
src/TranslatableBehavior.php
|
TranslatableBehavior.afterSave
|
public function afterSave()
{
foreach ($this->translationsBuffer as $translation) {
$this->owner->link($this->translationRelationName, $translation);
}
}
|
php
|
public function afterSave()
{
foreach ($this->translationsBuffer as $translation) {
$this->owner->link($this->translationRelationName, $translation);
}
}
|
[
"public",
"function",
"afterSave",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"translationsBuffer",
"as",
"$",
"translation",
")",
"{",
"$",
"this",
"->",
"owner",
"->",
"link",
"(",
"$",
"this",
"->",
"translationRelationName",
",",
"$",
"translation",
")",
";",
"}",
"}"
] |
Triggers after saving of the main model.
|
[
"Triggers",
"after",
"saving",
"of",
"the",
"main",
"model",
"."
] |
3c40cd3fa5821abc471a971fd21bfa591ecd25b5
|
https://github.com/yiimaker/yii2-translatable/blob/3c40cd3fa5821abc471a971fd21bfa591ecd25b5/src/TranslatableBehavior.php#L179-L184
|
227,260
|
moust/silex-cache-service-provider
|
src/Moust/Silex/Cache/FileCache.php
|
FileCache.setCacheDir
|
public function setCacheDir($cacheDir)
{
if (!$cacheDir) {
throw new \InvalidArgumentException('The parameter $cacheDir must not be empty.');
}
if (!is_dir($cacheDir) && !mkdir($cacheDir, 0777, true)) {
throw new \RuntimeException('Unable to create the directory "'.$cacheDir.'"');
}
// remove trailing slash
if (in_array(substr($cacheDir, -1), array('\\', '/'))) {
$cacheDir = substr($cacheDir, 0, -1);
}
$this->_cacheDir = $cacheDir;
}
|
php
|
public function setCacheDir($cacheDir)
{
if (!$cacheDir) {
throw new \InvalidArgumentException('The parameter $cacheDir must not be empty.');
}
if (!is_dir($cacheDir) && !mkdir($cacheDir, 0777, true)) {
throw new \RuntimeException('Unable to create the directory "'.$cacheDir.'"');
}
// remove trailing slash
if (in_array(substr($cacheDir, -1), array('\\', '/'))) {
$cacheDir = substr($cacheDir, 0, -1);
}
$this->_cacheDir = $cacheDir;
}
|
[
"public",
"function",
"setCacheDir",
"(",
"$",
"cacheDir",
")",
"{",
"if",
"(",
"!",
"$",
"cacheDir",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The parameter $cacheDir must not be empty.'",
")",
";",
"}",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"cacheDir",
")",
"&&",
"!",
"mkdir",
"(",
"$",
"cacheDir",
",",
"0777",
",",
"true",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Unable to create the directory \"'",
".",
"$",
"cacheDir",
".",
"'\"'",
")",
";",
"}",
"// remove trailing slash",
"if",
"(",
"in_array",
"(",
"substr",
"(",
"$",
"cacheDir",
",",
"-",
"1",
")",
",",
"array",
"(",
"'\\\\'",
",",
"'/'",
")",
")",
")",
"{",
"$",
"cacheDir",
"=",
"substr",
"(",
"$",
"cacheDir",
",",
"0",
",",
"-",
"1",
")",
";",
"}",
"$",
"this",
"->",
"_cacheDir",
"=",
"$",
"cacheDir",
";",
"}"
] |
Sets the cache directory to use.
@param string $cacheDir
|
[
"Sets",
"the",
"cache",
"directory",
"to",
"use",
"."
] |
b3ca953def0f95676eec6a47573a3da168486b37
|
https://github.com/moust/silex-cache-service-provider/blob/b3ca953def0f95676eec6a47573a3da168486b37/src/Moust/Silex/Cache/FileCache.php#L46-L62
|
227,261
|
BootstrapCMS/Credentials
|
src/Http/Controllers/AbstractController.php
|
AbstractController.setPermissions
|
protected function setPermissions($permissions)
{
foreach ($permissions as $action => $permission) {
$this->setPermission($action, $permission);
}
}
|
php
|
protected function setPermissions($permissions)
{
foreach ($permissions as $action => $permission) {
$this->setPermission($action, $permission);
}
}
|
[
"protected",
"function",
"setPermissions",
"(",
"$",
"permissions",
")",
"{",
"foreach",
"(",
"$",
"permissions",
"as",
"$",
"action",
"=>",
"$",
"permission",
")",
"{",
"$",
"this",
"->",
"setPermission",
"(",
"$",
"action",
",",
"$",
"permission",
")",
";",
"}",
"}"
] |
Set the permissions.
@param string[] $permissions
@return void
|
[
"Set",
"the",
"permissions",
"."
] |
128c5359eea7417ca95670933a28d4e6c7e01e6b
|
https://github.com/BootstrapCMS/Credentials/blob/128c5359eea7417ca95670933a28d4e6c7e01e6b/src/Http/Controllers/AbstractController.php#L87-L92
|
227,262
|
OpenSkill/Datatable
|
src/OpenSkill/Datatable/Queries/Parser/Datatable19QueryParser.php
|
Datatable19QueryParser.addColumnForOrdering
|
private function addColumnForOrdering($builder, $columnConfiguration, $item, $direction)
{
$c = $this->getColumnFromConfiguration($columnConfiguration, $item);
if ($c->getOrder()->isOrderable()) {
$builder->columnOrder($c->getName(), $direction);
}
}
|
php
|
private function addColumnForOrdering($builder, $columnConfiguration, $item, $direction)
{
$c = $this->getColumnFromConfiguration($columnConfiguration, $item);
if ($c->getOrder()->isOrderable()) {
$builder->columnOrder($c->getName(), $direction);
}
}
|
[
"private",
"function",
"addColumnForOrdering",
"(",
"$",
"builder",
",",
"$",
"columnConfiguration",
",",
"$",
"item",
",",
"$",
"direction",
")",
"{",
"$",
"c",
"=",
"$",
"this",
"->",
"getColumnFromConfiguration",
"(",
"$",
"columnConfiguration",
",",
"$",
"item",
")",
";",
"if",
"(",
"$",
"c",
"->",
"getOrder",
"(",
")",
"->",
"isOrderable",
"(",
")",
")",
"{",
"$",
"builder",
"->",
"columnOrder",
"(",
"$",
"c",
"->",
"getName",
"(",
")",
",",
"$",
"direction",
")",
";",
"}",
"}"
] |
Add a column for ordering to the QueryConfigurationBuilder
@see determineSortableColumns
@param $builder
@param $columnConfiguration
@param $item
@param $direction
@throws DatatableException
|
[
"Add",
"a",
"column",
"for",
"ordering",
"to",
"the",
"QueryConfigurationBuilder"
] |
e9814345dca4d0427da512f17c24117797e6ffbb
|
https://github.com/OpenSkill/Datatable/blob/e9814345dca4d0427da512f17c24117797e6ffbb/src/OpenSkill/Datatable/Queries/Parser/Datatable19QueryParser.php#L200-L207
|
227,263
|
OpenSkill/Datatable
|
src/OpenSkill/Datatable/Versions/VersionEngine.php
|
VersionEngine.setVersionFromRequest
|
private function setVersionFromRequest(array $versions)
{
$this->setDefaultVersion($versions);
foreach ($versions as $v) {
if ($v->canParseRequest()) {
$this->version = $v;
break;
}
}
}
|
php
|
private function setVersionFromRequest(array $versions)
{
$this->setDefaultVersion($versions);
foreach ($versions as $v) {
if ($v->canParseRequest()) {
$this->version = $v;
break;
}
}
}
|
[
"private",
"function",
"setVersionFromRequest",
"(",
"array",
"$",
"versions",
")",
"{",
"$",
"this",
"->",
"setDefaultVersion",
"(",
"$",
"versions",
")",
";",
"foreach",
"(",
"$",
"versions",
"as",
"$",
"v",
")",
"{",
"if",
"(",
"$",
"v",
"->",
"canParseRequest",
"(",
")",
")",
"{",
"$",
"this",
"->",
"version",
"=",
"$",
"v",
";",
"break",
";",
"}",
"}",
"}"
] |
Pick the verison of an engine that can parse a request.
@param Version[] $versions an array of possible version this data table supports
|
[
"Pick",
"the",
"verison",
"of",
"an",
"engine",
"that",
"can",
"parse",
"a",
"request",
"."
] |
e9814345dca4d0427da512f17c24117797e6ffbb
|
https://github.com/OpenSkill/Datatable/blob/e9814345dca4d0427da512f17c24117797e6ffbb/src/OpenSkill/Datatable/Versions/VersionEngine.php#L50-L60
|
227,264
|
aik099/CodingStandard
|
CodingStandard/Sniffs/Formatting/BlankLineBeforeReturnSniff.php
|
BlankLineBeforeReturnSniff.getLeadingLinePointer
|
protected function getLeadingLinePointer(File $phpcsFile, $fromStackPtr, $toStackPtr)
{
$tokens = $phpcsFile->getTokens();
$fromToken = $tokens[$fromStackPtr];
$prevCommentPtr = $phpcsFile->findPrevious(
T_COMMENT,
($fromStackPtr - 1),
$toStackPtr
);
if ($prevCommentPtr === false) {
return $fromStackPtr;
}
$prevCommentToken = $tokens[$prevCommentPtr];
if ($prevCommentToken['line'] === ($fromToken['line'] - 1)
&& $prevCommentToken['column'] === $fromToken['column']
) {
return $prevCommentPtr;
}
return $fromStackPtr;
}
|
php
|
protected function getLeadingLinePointer(File $phpcsFile, $fromStackPtr, $toStackPtr)
{
$tokens = $phpcsFile->getTokens();
$fromToken = $tokens[$fromStackPtr];
$prevCommentPtr = $phpcsFile->findPrevious(
T_COMMENT,
($fromStackPtr - 1),
$toStackPtr
);
if ($prevCommentPtr === false) {
return $fromStackPtr;
}
$prevCommentToken = $tokens[$prevCommentPtr];
if ($prevCommentToken['line'] === ($fromToken['line'] - 1)
&& $prevCommentToken['column'] === $fromToken['column']
) {
return $prevCommentPtr;
}
return $fromStackPtr;
}
|
[
"protected",
"function",
"getLeadingLinePointer",
"(",
"File",
"$",
"phpcsFile",
",",
"$",
"fromStackPtr",
",",
"$",
"toStackPtr",
")",
"{",
"$",
"tokens",
"=",
"$",
"phpcsFile",
"->",
"getTokens",
"(",
")",
";",
"$",
"fromToken",
"=",
"$",
"tokens",
"[",
"$",
"fromStackPtr",
"]",
";",
"$",
"prevCommentPtr",
"=",
"$",
"phpcsFile",
"->",
"findPrevious",
"(",
"T_COMMENT",
",",
"(",
"$",
"fromStackPtr",
"-",
"1",
")",
",",
"$",
"toStackPtr",
")",
";",
"if",
"(",
"$",
"prevCommentPtr",
"===",
"false",
")",
"{",
"return",
"$",
"fromStackPtr",
";",
"}",
"$",
"prevCommentToken",
"=",
"$",
"tokens",
"[",
"$",
"prevCommentPtr",
"]",
";",
"if",
"(",
"$",
"prevCommentToken",
"[",
"'line'",
"]",
"===",
"(",
"$",
"fromToken",
"[",
"'line'",
"]",
"-",
"1",
")",
"&&",
"$",
"prevCommentToken",
"[",
"'column'",
"]",
"===",
"$",
"fromToken",
"[",
"'column'",
"]",
")",
"{",
"return",
"$",
"prevCommentPtr",
";",
"}",
"return",
"$",
"fromStackPtr",
";",
"}"
] |
Returns leading comment stack pointer or own stack pointer, when no comment found.
@param File $phpcsFile All the tokens found in the document.
@param int $fromStackPtr Start from token.
@param int $toStackPtr Stop at token.
@return int|bool
|
[
"Returns",
"leading",
"comment",
"stack",
"pointer",
"or",
"own",
"stack",
"pointer",
"when",
"no",
"comment",
"found",
"."
] |
0f65c52bf2d95d5068af9f73110770ddb9de8de7
|
https://github.com/aik099/CodingStandard/blob/0f65c52bf2d95d5068af9f73110770ddb9de8de7/CodingStandard/Sniffs/Formatting/BlankLineBeforeReturnSniff.php#L106-L129
|
227,265
|
BootstrapCMS/Credentials
|
src/Presenters/RevisionPresenter.php
|
RevisionPresenter.getDisplayerClass
|
protected function getDisplayerClass()
{
$class = $this->wrappedObject->revisionable_type;
do {
if (class_exists($displayer = $this->generateDisplayerName($class))) {
return $displayer;
}
} while ($class = get_parent_class($class));
throw new Exception('No displayers could be found');
}
|
php
|
protected function getDisplayerClass()
{
$class = $this->wrappedObject->revisionable_type;
do {
if (class_exists($displayer = $this->generateDisplayerName($class))) {
return $displayer;
}
} while ($class = get_parent_class($class));
throw new Exception('No displayers could be found');
}
|
[
"protected",
"function",
"getDisplayerClass",
"(",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"wrappedObject",
"->",
"revisionable_type",
";",
"do",
"{",
"if",
"(",
"class_exists",
"(",
"$",
"displayer",
"=",
"$",
"this",
"->",
"generateDisplayerName",
"(",
"$",
"class",
")",
")",
")",
"{",
"return",
"$",
"displayer",
";",
"}",
"}",
"while",
"(",
"$",
"class",
"=",
"get_parent_class",
"(",
"$",
"class",
")",
")",
";",
"throw",
"new",
"Exception",
"(",
"'No displayers could be found'",
")",
";",
"}"
] |
Get the relevant displayer class.
@throws \Exception
@return string
|
[
"Get",
"the",
"relevant",
"displayer",
"class",
"."
] |
128c5359eea7417ca95670933a28d4e6c7e01e6b
|
https://github.com/BootstrapCMS/Credentials/blob/128c5359eea7417ca95670933a28d4e6c7e01e6b/src/Presenters/RevisionPresenter.php#L80-L91
|
227,266
|
BootstrapCMS/Credentials
|
src/Presenters/RevisionPresenter.php
|
RevisionPresenter.generateDisplayerName
|
protected function generateDisplayerName($class)
{
$shortArray = explode('\\', $class);
$short = end($shortArray);
$field = studly_case($this->field());
$temp = str_replace($short, 'RevisionDisplayers\\'.$short.'\\'.$field.'Displayer', $class);
return str_replace('Model', 'Presenter', $temp);
}
|
php
|
protected function generateDisplayerName($class)
{
$shortArray = explode('\\', $class);
$short = end($shortArray);
$field = studly_case($this->field());
$temp = str_replace($short, 'RevisionDisplayers\\'.$short.'\\'.$field.'Displayer', $class);
return str_replace('Model', 'Presenter', $temp);
}
|
[
"protected",
"function",
"generateDisplayerName",
"(",
"$",
"class",
")",
"{",
"$",
"shortArray",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"class",
")",
";",
"$",
"short",
"=",
"end",
"(",
"$",
"shortArray",
")",
";",
"$",
"field",
"=",
"studly_case",
"(",
"$",
"this",
"->",
"field",
"(",
")",
")",
";",
"$",
"temp",
"=",
"str_replace",
"(",
"$",
"short",
",",
"'RevisionDisplayers\\\\'",
".",
"$",
"short",
".",
"'\\\\'",
".",
"$",
"field",
".",
"'Displayer'",
",",
"$",
"class",
")",
";",
"return",
"str_replace",
"(",
"'Model'",
",",
"'Presenter'",
",",
"$",
"temp",
")",
";",
"}"
] |
Generate a possible displayer class name.
@return string
|
[
"Generate",
"a",
"possible",
"displayer",
"class",
"name",
"."
] |
128c5359eea7417ca95670933a28d4e6c7e01e6b
|
https://github.com/BootstrapCMS/Credentials/blob/128c5359eea7417ca95670933a28d4e6c7e01e6b/src/Presenters/RevisionPresenter.php#L98-L107
|
227,267
|
BootstrapCMS/Credentials
|
src/Presenters/RevisionPresenter.php
|
RevisionPresenter.field
|
public function field()
{
if (strpos($this->wrappedObject->key, '_id')) {
return str_replace('_id', '', $this->wrappedObject->key);
}
return $this->wrappedObject->key;
}
|
php
|
public function field()
{
if (strpos($this->wrappedObject->key, '_id')) {
return str_replace('_id', '', $this->wrappedObject->key);
}
return $this->wrappedObject->key;
}
|
[
"public",
"function",
"field",
"(",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"this",
"->",
"wrappedObject",
"->",
"key",
",",
"'_id'",
")",
")",
"{",
"return",
"str_replace",
"(",
"'_id'",
",",
"''",
",",
"$",
"this",
"->",
"wrappedObject",
"->",
"key",
")",
";",
"}",
"return",
"$",
"this",
"->",
"wrappedObject",
"->",
"key",
";",
"}"
] |
Get the change field.
@return string
|
[
"Get",
"the",
"change",
"field",
"."
] |
128c5359eea7417ca95670933a28d4e6c7e01e6b
|
https://github.com/BootstrapCMS/Credentials/blob/128c5359eea7417ca95670933a28d4e6c7e01e6b/src/Presenters/RevisionPresenter.php#L114-L121
|
227,268
|
BootstrapCMS/Credentials
|
src/Presenters/RevisionPresenter.php
|
RevisionPresenter.wasByCurrentUser
|
public function wasByCurrentUser()
{
return $this->credentials->check() && $this->credentials->getUser()->id == $this->wrappedObject->user_id;
}
|
php
|
public function wasByCurrentUser()
{
return $this->credentials->check() && $this->credentials->getUser()->id == $this->wrappedObject->user_id;
}
|
[
"public",
"function",
"wasByCurrentUser",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"credentials",
"->",
"check",
"(",
")",
"&&",
"$",
"this",
"->",
"credentials",
"->",
"getUser",
"(",
")",
"->",
"id",
"==",
"$",
"this",
"->",
"wrappedObject",
"->",
"user_id",
";",
"}"
] |
Was the event invoked by the current user?
@return bool
|
[
"Was",
"the",
"event",
"invoked",
"by",
"the",
"current",
"user?"
] |
128c5359eea7417ca95670933a28d4e6c7e01e6b
|
https://github.com/BootstrapCMS/Credentials/blob/128c5359eea7417ca95670933a28d4e6c7e01e6b/src/Presenters/RevisionPresenter.php#L128-L131
|
227,269
|
BootstrapCMS/Credentials
|
src/Http/Controllers/AccountController.php
|
AccountController.deleteProfile
|
public function deleteProfile()
{
$user = Credentials::getUser();
$this->checkUser($user);
$email = $user->getLogin();
Credentials::logout();
try {
$user->delete();
} catch (\Exception $e) {
return Redirect::to(Config::get('credentials.home', '/'))
->with('error', 'There was a problem deleting your account.');
}
$mail = [
'url' => URL::to(Config::get('credentials.home', '/')),
'email' => $email,
'subject' => Config::get('app.name').' - Account Deleted Notification',
];
Mail::queue('credentials::emails.userdeleted', $mail, function ($message) use ($mail) {
$message->to($mail['email'])->subject($mail['subject']);
});
return Redirect::to(Config::get('credentials.home', '/'))
->with('success', 'Your account has been deleted successfully.');
}
|
php
|
public function deleteProfile()
{
$user = Credentials::getUser();
$this->checkUser($user);
$email = $user->getLogin();
Credentials::logout();
try {
$user->delete();
} catch (\Exception $e) {
return Redirect::to(Config::get('credentials.home', '/'))
->with('error', 'There was a problem deleting your account.');
}
$mail = [
'url' => URL::to(Config::get('credentials.home', '/')),
'email' => $email,
'subject' => Config::get('app.name').' - Account Deleted Notification',
];
Mail::queue('credentials::emails.userdeleted', $mail, function ($message) use ($mail) {
$message->to($mail['email'])->subject($mail['subject']);
});
return Redirect::to(Config::get('credentials.home', '/'))
->with('success', 'Your account has been deleted successfully.');
}
|
[
"public",
"function",
"deleteProfile",
"(",
")",
"{",
"$",
"user",
"=",
"Credentials",
"::",
"getUser",
"(",
")",
";",
"$",
"this",
"->",
"checkUser",
"(",
"$",
"user",
")",
";",
"$",
"email",
"=",
"$",
"user",
"->",
"getLogin",
"(",
")",
";",
"Credentials",
"::",
"logout",
"(",
")",
";",
"try",
"{",
"$",
"user",
"->",
"delete",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"Redirect",
"::",
"to",
"(",
"Config",
"::",
"get",
"(",
"'credentials.home'",
",",
"'/'",
")",
")",
"->",
"with",
"(",
"'error'",
",",
"'There was a problem deleting your account.'",
")",
";",
"}",
"$",
"mail",
"=",
"[",
"'url'",
"=>",
"URL",
"::",
"to",
"(",
"Config",
"::",
"get",
"(",
"'credentials.home'",
",",
"'/'",
")",
")",
",",
"'email'",
"=>",
"$",
"email",
",",
"'subject'",
"=>",
"Config",
"::",
"get",
"(",
"'app.name'",
")",
".",
"' - Account Deleted Notification'",
",",
"]",
";",
"Mail",
"::",
"queue",
"(",
"'credentials::emails.userdeleted'",
",",
"$",
"mail",
",",
"function",
"(",
"$",
"message",
")",
"use",
"(",
"$",
"mail",
")",
"{",
"$",
"message",
"->",
"to",
"(",
"$",
"mail",
"[",
"'email'",
"]",
")",
"->",
"subject",
"(",
"$",
"mail",
"[",
"'subject'",
"]",
")",
";",
"}",
")",
";",
"return",
"Redirect",
"::",
"to",
"(",
"Config",
"::",
"get",
"(",
"'credentials.home'",
",",
"'/'",
")",
")",
"->",
"with",
"(",
"'success'",
",",
"'Your account has been deleted successfully.'",
")",
";",
"}"
] |
Delete the user's profile.
@return \Illuminate\Http\Response
|
[
"Delete",
"the",
"user",
"s",
"profile",
"."
] |
128c5359eea7417ca95670933a28d4e6c7e01e6b
|
https://github.com/BootstrapCMS/Credentials/blob/128c5359eea7417ca95670933a28d4e6c7e01e6b/src/Http/Controllers/AccountController.php#L74-L102
|
227,270
|
BootstrapCMS/Credentials
|
src/Http/Controllers/AccountController.php
|
AccountController.patchDetails
|
public function patchDetails()
{
$input = Binput::only(['first_name', 'last_name', 'email']);
$val = UserRepository::validate($input, array_keys($input));
if ($val->fails()) {
return Redirect::route('account.profile')->withInput()->withErrors($val->errors());
}
$user = Credentials::getUser();
$this->checkUser($user);
$email = $user['email'];
$user->update($input);
if ($email !== $input['email']) {
$mail = [
'old' => $email,
'new' => $input['email'],
'url' => URL::to(Config::get('credentials.home', '/')),
'subject' => Config::get('app.name').' - New Email Information',
];
Mail::queue('credentials::emails.newemail', $mail, function ($message) use ($mail) {
$message->to($mail['old'])->subject($mail['subject']);
});
Mail::queue('credentials::emails.newemail', $mail, function ($message) use ($mail) {
$message->to($mail['new'])->subject($mail['subject']);
});
}
return Redirect::route('account.profile')
->with('success', 'Your details have been updated successfully.');
}
|
php
|
public function patchDetails()
{
$input = Binput::only(['first_name', 'last_name', 'email']);
$val = UserRepository::validate($input, array_keys($input));
if ($val->fails()) {
return Redirect::route('account.profile')->withInput()->withErrors($val->errors());
}
$user = Credentials::getUser();
$this->checkUser($user);
$email = $user['email'];
$user->update($input);
if ($email !== $input['email']) {
$mail = [
'old' => $email,
'new' => $input['email'],
'url' => URL::to(Config::get('credentials.home', '/')),
'subject' => Config::get('app.name').' - New Email Information',
];
Mail::queue('credentials::emails.newemail', $mail, function ($message) use ($mail) {
$message->to($mail['old'])->subject($mail['subject']);
});
Mail::queue('credentials::emails.newemail', $mail, function ($message) use ($mail) {
$message->to($mail['new'])->subject($mail['subject']);
});
}
return Redirect::route('account.profile')
->with('success', 'Your details have been updated successfully.');
}
|
[
"public",
"function",
"patchDetails",
"(",
")",
"{",
"$",
"input",
"=",
"Binput",
"::",
"only",
"(",
"[",
"'first_name'",
",",
"'last_name'",
",",
"'email'",
"]",
")",
";",
"$",
"val",
"=",
"UserRepository",
"::",
"validate",
"(",
"$",
"input",
",",
"array_keys",
"(",
"$",
"input",
")",
")",
";",
"if",
"(",
"$",
"val",
"->",
"fails",
"(",
")",
")",
"{",
"return",
"Redirect",
"::",
"route",
"(",
"'account.profile'",
")",
"->",
"withInput",
"(",
")",
"->",
"withErrors",
"(",
"$",
"val",
"->",
"errors",
"(",
")",
")",
";",
"}",
"$",
"user",
"=",
"Credentials",
"::",
"getUser",
"(",
")",
";",
"$",
"this",
"->",
"checkUser",
"(",
"$",
"user",
")",
";",
"$",
"email",
"=",
"$",
"user",
"[",
"'email'",
"]",
";",
"$",
"user",
"->",
"update",
"(",
"$",
"input",
")",
";",
"if",
"(",
"$",
"email",
"!==",
"$",
"input",
"[",
"'email'",
"]",
")",
"{",
"$",
"mail",
"=",
"[",
"'old'",
"=>",
"$",
"email",
",",
"'new'",
"=>",
"$",
"input",
"[",
"'email'",
"]",
",",
"'url'",
"=>",
"URL",
"::",
"to",
"(",
"Config",
"::",
"get",
"(",
"'credentials.home'",
",",
"'/'",
")",
")",
",",
"'subject'",
"=>",
"Config",
"::",
"get",
"(",
"'app.name'",
")",
".",
"' - New Email Information'",
",",
"]",
";",
"Mail",
"::",
"queue",
"(",
"'credentials::emails.newemail'",
",",
"$",
"mail",
",",
"function",
"(",
"$",
"message",
")",
"use",
"(",
"$",
"mail",
")",
"{",
"$",
"message",
"->",
"to",
"(",
"$",
"mail",
"[",
"'old'",
"]",
")",
"->",
"subject",
"(",
"$",
"mail",
"[",
"'subject'",
"]",
")",
";",
"}",
")",
";",
"Mail",
"::",
"queue",
"(",
"'credentials::emails.newemail'",
",",
"$",
"mail",
",",
"function",
"(",
"$",
"message",
")",
"use",
"(",
"$",
"mail",
")",
"{",
"$",
"message",
"->",
"to",
"(",
"$",
"mail",
"[",
"'new'",
"]",
")",
"->",
"subject",
"(",
"$",
"mail",
"[",
"'subject'",
"]",
")",
";",
"}",
")",
";",
"}",
"return",
"Redirect",
"::",
"route",
"(",
"'account.profile'",
")",
"->",
"with",
"(",
"'success'",
",",
"'Your details have been updated successfully.'",
")",
";",
"}"
] |
Update the user's details.
@return \Illuminate\Http\Response
|
[
"Update",
"the",
"user",
"s",
"details",
"."
] |
128c5359eea7417ca95670933a28d4e6c7e01e6b
|
https://github.com/BootstrapCMS/Credentials/blob/128c5359eea7417ca95670933a28d4e6c7e01e6b/src/Http/Controllers/AccountController.php#L109-L144
|
227,271
|
aik099/CodingStandard
|
CodingStandard/Sniffs/Commenting/FunctionCommentSniff.php
|
FunctionCommentSniff.checkShort
|
public function checkShort(File $phpcsFile, $stackPtr, $short, $errorPos)
{
$tokens = $phpcsFile->getTokens();
$classToken = null;
foreach ($tokens[$stackPtr]['conditions'] as $condPtr => $condition) {
if ($condition === T_CLASS || $condition === T_INTERFACE || $condition === T_TRAIT) {
$classToken = $condPtr;
break;
}
}
$isEvent = false;
if ($classToken !== null) {
$className = $phpcsFile->getDeclarationName($classToken);
if (strpos($className, 'EventHandler') !== false) {
$methodName = $phpcsFile->getDeclarationName($stackPtr);
if (substr($methodName, 0, 2) === 'On') {
$isEvent = true;
}
}
}
if ($isEvent === true && preg_match('/(\p{Lu}|\[)/u', $short[0]) === 0) {
$error = 'Event comment short description must start with a capital letter or an [';
$phpcsFile->addError($error, $errorPos, 'EventShortNotCapital');
} elseif ($isEvent === false && preg_match('/\p{Lu}/u', $short[0]) === 0) {
$error = 'Doc comment short description must start with a capital letter';
$phpcsFile->addError($error, $errorPos, 'NonEventShortNotCapital');
}
}
|
php
|
public function checkShort(File $phpcsFile, $stackPtr, $short, $errorPos)
{
$tokens = $phpcsFile->getTokens();
$classToken = null;
foreach ($tokens[$stackPtr]['conditions'] as $condPtr => $condition) {
if ($condition === T_CLASS || $condition === T_INTERFACE || $condition === T_TRAIT) {
$classToken = $condPtr;
break;
}
}
$isEvent = false;
if ($classToken !== null) {
$className = $phpcsFile->getDeclarationName($classToken);
if (strpos($className, 'EventHandler') !== false) {
$methodName = $phpcsFile->getDeclarationName($stackPtr);
if (substr($methodName, 0, 2) === 'On') {
$isEvent = true;
}
}
}
if ($isEvent === true && preg_match('/(\p{Lu}|\[)/u', $short[0]) === 0) {
$error = 'Event comment short description must start with a capital letter or an [';
$phpcsFile->addError($error, $errorPos, 'EventShortNotCapital');
} elseif ($isEvent === false && preg_match('/\p{Lu}/u', $short[0]) === 0) {
$error = 'Doc comment short description must start with a capital letter';
$phpcsFile->addError($error, $errorPos, 'NonEventShortNotCapital');
}
}
|
[
"public",
"function",
"checkShort",
"(",
"File",
"$",
"phpcsFile",
",",
"$",
"stackPtr",
",",
"$",
"short",
",",
"$",
"errorPos",
")",
"{",
"$",
"tokens",
"=",
"$",
"phpcsFile",
"->",
"getTokens",
"(",
")",
";",
"$",
"classToken",
"=",
"null",
";",
"foreach",
"(",
"$",
"tokens",
"[",
"$",
"stackPtr",
"]",
"[",
"'conditions'",
"]",
"as",
"$",
"condPtr",
"=>",
"$",
"condition",
")",
"{",
"if",
"(",
"$",
"condition",
"===",
"T_CLASS",
"||",
"$",
"condition",
"===",
"T_INTERFACE",
"||",
"$",
"condition",
"===",
"T_TRAIT",
")",
"{",
"$",
"classToken",
"=",
"$",
"condPtr",
";",
"break",
";",
"}",
"}",
"$",
"isEvent",
"=",
"false",
";",
"if",
"(",
"$",
"classToken",
"!==",
"null",
")",
"{",
"$",
"className",
"=",
"$",
"phpcsFile",
"->",
"getDeclarationName",
"(",
"$",
"classToken",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"className",
",",
"'EventHandler'",
")",
"!==",
"false",
")",
"{",
"$",
"methodName",
"=",
"$",
"phpcsFile",
"->",
"getDeclarationName",
"(",
"$",
"stackPtr",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"methodName",
",",
"0",
",",
"2",
")",
"===",
"'On'",
")",
"{",
"$",
"isEvent",
"=",
"true",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"isEvent",
"===",
"true",
"&&",
"preg_match",
"(",
"'/(\\p{Lu}|\\[)/u'",
",",
"$",
"short",
"[",
"0",
"]",
")",
"===",
"0",
")",
"{",
"$",
"error",
"=",
"'Event comment short description must start with a capital letter or an ['",
";",
"$",
"phpcsFile",
"->",
"addError",
"(",
"$",
"error",
",",
"$",
"errorPos",
",",
"'EventShortNotCapital'",
")",
";",
"}",
"elseif",
"(",
"$",
"isEvent",
"===",
"false",
"&&",
"preg_match",
"(",
"'/\\p{Lu}/u'",
",",
"$",
"short",
"[",
"0",
"]",
")",
"===",
"0",
")",
"{",
"$",
"error",
"=",
"'Doc comment short description must start with a capital letter'",
";",
"$",
"phpcsFile",
"->",
"addError",
"(",
"$",
"error",
",",
"$",
"errorPos",
",",
"'NonEventShortNotCapital'",
")",
";",
"}",
"}"
] |
Process the short description of a function comment.
@param File $phpcsFile The file being scanned.
@param int $stackPtr The position of the function token
in the stack passed in $tokens.
@param string $short The content of the short description.
@param int $errorPos The position where an error should be thrown.
@return void
|
[
"Process",
"the",
"short",
"description",
"of",
"a",
"function",
"comment",
"."
] |
0f65c52bf2d95d5068af9f73110770ddb9de8de7
|
https://github.com/aik099/CodingStandard/blob/0f65c52bf2d95d5068af9f73110770ddb9de8de7/CodingStandard/Sniffs/Commenting/FunctionCommentSniff.php#L147-L177
|
227,272
|
cagartner/sql-anywhere-client
|
src/Cagartner/SQLAnywhereQuery.php
|
SQLAnywhereQuery.fetch
|
public function fetch($type=SQLAnywhereClient::FETCH_ASSOC)
{
$data = null;
if ($this->result) {
switch ($type) {
case 'array':
$data = sasql_fetch_array( $this->result );
break;
case 'assoc':
$data = sasql_fetch_assoc( $this->result );
break;
case 'row':
$data = sasql_fetch_row( $this->result );
break;
case 'field':
$data = sasql_fetch_field( $this->result );
break;
case 'object':
$data = sasql_fetch_object( $this->result );
break;
default:
$data = sasql_fetch_array( $this->result );
break;
}
}
return $data;
}
|
php
|
public function fetch($type=SQLAnywhereClient::FETCH_ASSOC)
{
$data = null;
if ($this->result) {
switch ($type) {
case 'array':
$data = sasql_fetch_array( $this->result );
break;
case 'assoc':
$data = sasql_fetch_assoc( $this->result );
break;
case 'row':
$data = sasql_fetch_row( $this->result );
break;
case 'field':
$data = sasql_fetch_field( $this->result );
break;
case 'object':
$data = sasql_fetch_object( $this->result );
break;
default:
$data = sasql_fetch_array( $this->result );
break;
}
}
return $data;
}
|
[
"public",
"function",
"fetch",
"(",
"$",
"type",
"=",
"SQLAnywhereClient",
"::",
"FETCH_ASSOC",
")",
"{",
"$",
"data",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"result",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'array'",
":",
"$",
"data",
"=",
"sasql_fetch_array",
"(",
"$",
"this",
"->",
"result",
")",
";",
"break",
";",
"case",
"'assoc'",
":",
"$",
"data",
"=",
"sasql_fetch_assoc",
"(",
"$",
"this",
"->",
"result",
")",
";",
"break",
";",
"case",
"'row'",
":",
"$",
"data",
"=",
"sasql_fetch_row",
"(",
"$",
"this",
"->",
"result",
")",
";",
"break",
";",
"case",
"'field'",
":",
"$",
"data",
"=",
"sasql_fetch_field",
"(",
"$",
"this",
"->",
"result",
")",
";",
"break",
";",
"case",
"'object'",
":",
"$",
"data",
"=",
"sasql_fetch_object",
"(",
"$",
"this",
"->",
"result",
")",
";",
"break",
";",
"default",
":",
"$",
"data",
"=",
"sasql_fetch_array",
"(",
"$",
"this",
"->",
"result",
")",
";",
"break",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] |
Return one row of result
@param constant $type Format of return
@return array|object
|
[
"Return",
"one",
"row",
"of",
"result"
] |
95280faf5b2cbf34d827665ce3cbc1de187d6f11
|
https://github.com/cagartner/sql-anywhere-client/blob/95280faf5b2cbf34d827665ce3cbc1de187d6f11/src/Cagartner/SQLAnywhereQuery.php#L75-L106
|
227,273
|
cagartner/sql-anywhere-client
|
src/Cagartner/SQLAnywhereQuery.php
|
SQLAnywhereQuery.fetchAll
|
public function fetchAll($type=SQLAnywhereClient::FETCH_ASSOC)
{
$data = array();
if ($this->result) {
switch ($type) {
case 'array':
while ($row = sasql_fetch_array( $this->result ))
array_push($data, $row);
break;
case 'assoc':
while ($row = sasql_fetch_assoc( $this->result ))
array_push($data, $row);
break;
case 'row':
while ($row = sasql_fetch_row( $this->result ))
array_push($data, $row);
break;
case 'field':
while ($row = sasql_fetch_field( $this->result ))
array_push($data, $row);
break;
case 'object':
while ($row = sasql_fetch_object( $this->result ))
array_push($data, $row);
break;
default:
while ($row = sasql_fetch_array( $this->result ))
array_push($data, $row);
break;
}
}
return $data;
}
|
php
|
public function fetchAll($type=SQLAnywhereClient::FETCH_ASSOC)
{
$data = array();
if ($this->result) {
switch ($type) {
case 'array':
while ($row = sasql_fetch_array( $this->result ))
array_push($data, $row);
break;
case 'assoc':
while ($row = sasql_fetch_assoc( $this->result ))
array_push($data, $row);
break;
case 'row':
while ($row = sasql_fetch_row( $this->result ))
array_push($data, $row);
break;
case 'field':
while ($row = sasql_fetch_field( $this->result ))
array_push($data, $row);
break;
case 'object':
while ($row = sasql_fetch_object( $this->result ))
array_push($data, $row);
break;
default:
while ($row = sasql_fetch_array( $this->result ))
array_push($data, $row);
break;
}
}
return $data;
}
|
[
"public",
"function",
"fetchAll",
"(",
"$",
"type",
"=",
"SQLAnywhereClient",
"::",
"FETCH_ASSOC",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"result",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'array'",
":",
"while",
"(",
"$",
"row",
"=",
"sasql_fetch_array",
"(",
"$",
"this",
"->",
"result",
")",
")",
"array_push",
"(",
"$",
"data",
",",
"$",
"row",
")",
";",
"break",
";",
"case",
"'assoc'",
":",
"while",
"(",
"$",
"row",
"=",
"sasql_fetch_assoc",
"(",
"$",
"this",
"->",
"result",
")",
")",
"array_push",
"(",
"$",
"data",
",",
"$",
"row",
")",
";",
"break",
";",
"case",
"'row'",
":",
"while",
"(",
"$",
"row",
"=",
"sasql_fetch_row",
"(",
"$",
"this",
"->",
"result",
")",
")",
"array_push",
"(",
"$",
"data",
",",
"$",
"row",
")",
";",
"break",
";",
"case",
"'field'",
":",
"while",
"(",
"$",
"row",
"=",
"sasql_fetch_field",
"(",
"$",
"this",
"->",
"result",
")",
")",
"array_push",
"(",
"$",
"data",
",",
"$",
"row",
")",
";",
"break",
";",
"case",
"'object'",
":",
"while",
"(",
"$",
"row",
"=",
"sasql_fetch_object",
"(",
"$",
"this",
"->",
"result",
")",
")",
"array_push",
"(",
"$",
"data",
",",
"$",
"row",
")",
";",
"break",
";",
"default",
":",
"while",
"(",
"$",
"row",
"=",
"sasql_fetch_array",
"(",
"$",
"this",
"->",
"result",
")",
")",
"array_push",
"(",
"$",
"data",
",",
"$",
"row",
")",
";",
"break",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] |
Return All values of Results in one choose format
@param constant $type Format of return
@return array
|
[
"Return",
"All",
"values",
"of",
"Results",
"in",
"one",
"choose",
"format"
] |
95280faf5b2cbf34d827665ce3cbc1de187d6f11
|
https://github.com/cagartner/sql-anywhere-client/blob/95280faf5b2cbf34d827665ce3cbc1de187d6f11/src/Cagartner/SQLAnywhereQuery.php#L113-L152
|
227,274
|
alphayax/freebox_api_php
|
freebox/api/v3/services/login/Association.php
|
Association.authorize
|
public function authorize(){
$this->application->loadAppToken();
if( ! $this->application->haveAppToken()){
$this->askAuthorization();
while( in_array( $this->status, [self::STATUS_UNKNOWN, self::STATUS_PENDING])){
$this->getAuthorizationStatus();
if( $this->status == self::STATUS_GRANTED){
$this->application->setAppToken( $this->app_token);
$this->application->saveAppToken();
break;
}
sleep( 5);
}
/// For verbose
switch( $this->status){
case self::STATUS_GRANTED : $this->application->getLogger()->addInfo( 'Access granted !'); break;
case self::STATUS_TIMEOUT : $this->application->getLogger()->addCritical( 'Access denied. You take to long to authorize app'); break;
case self::STATUS_DENIED : $this->application->getLogger()->addCritical( 'Access denied. Freebox denied app connexion'); break;
}
}
}
|
php
|
public function authorize(){
$this->application->loadAppToken();
if( ! $this->application->haveAppToken()){
$this->askAuthorization();
while( in_array( $this->status, [self::STATUS_UNKNOWN, self::STATUS_PENDING])){
$this->getAuthorizationStatus();
if( $this->status == self::STATUS_GRANTED){
$this->application->setAppToken( $this->app_token);
$this->application->saveAppToken();
break;
}
sleep( 5);
}
/// For verbose
switch( $this->status){
case self::STATUS_GRANTED : $this->application->getLogger()->addInfo( 'Access granted !'); break;
case self::STATUS_TIMEOUT : $this->application->getLogger()->addCritical( 'Access denied. You take to long to authorize app'); break;
case self::STATUS_DENIED : $this->application->getLogger()->addCritical( 'Access denied. Freebox denied app connexion'); break;
}
}
}
|
[
"public",
"function",
"authorize",
"(",
")",
"{",
"$",
"this",
"->",
"application",
"->",
"loadAppToken",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"application",
"->",
"haveAppToken",
"(",
")",
")",
"{",
"$",
"this",
"->",
"askAuthorization",
"(",
")",
";",
"while",
"(",
"in_array",
"(",
"$",
"this",
"->",
"status",
",",
"[",
"self",
"::",
"STATUS_UNKNOWN",
",",
"self",
"::",
"STATUS_PENDING",
"]",
")",
")",
"{",
"$",
"this",
"->",
"getAuthorizationStatus",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"status",
"==",
"self",
"::",
"STATUS_GRANTED",
")",
"{",
"$",
"this",
"->",
"application",
"->",
"setAppToken",
"(",
"$",
"this",
"->",
"app_token",
")",
";",
"$",
"this",
"->",
"application",
"->",
"saveAppToken",
"(",
")",
";",
"break",
";",
"}",
"sleep",
"(",
"5",
")",
";",
"}",
"/// For verbose",
"switch",
"(",
"$",
"this",
"->",
"status",
")",
"{",
"case",
"self",
"::",
"STATUS_GRANTED",
":",
"$",
"this",
"->",
"application",
"->",
"getLogger",
"(",
")",
"->",
"addInfo",
"(",
"'Access granted !'",
")",
";",
"break",
";",
"case",
"self",
"::",
"STATUS_TIMEOUT",
":",
"$",
"this",
"->",
"application",
"->",
"getLogger",
"(",
")",
"->",
"addCritical",
"(",
"'Access denied. You take to long to authorize app'",
")",
";",
"break",
";",
"case",
"self",
"::",
"STATUS_DENIED",
":",
"$",
"this",
"->",
"application",
"->",
"getLogger",
"(",
")",
"->",
"addCritical",
"(",
"'Access denied. Freebox denied app connexion'",
")",
";",
"break",
";",
"}",
"}",
"}"
] |
Check if an app token is defined, and launch the association process otherwise
@throws \Exception
|
[
"Check",
"if",
"an",
"app",
"token",
"is",
"defined",
"and",
"launch",
"the",
"association",
"process",
"otherwise"
] |
6b90f932fca9d74053dc0af9664881664a29cefb
|
https://github.com/alphayax/freebox_api_php/blob/6b90f932fca9d74053dc0af9664881664a29cefb/freebox/api/v3/services/login/Association.php#L37-L59
|
227,275
|
alphayax/freebox_api_php
|
freebox/api/v4/services/FileSystem/FileSystemOperation.php
|
FileSystemOperation.encodePaths
|
private function encodePaths(array $paths)
{
$paths_b64 = [];
foreach ($paths as $path) {
$paths_b64[] = $this->encodePath($path);
}
return $paths_b64;
}
|
php
|
private function encodePaths(array $paths)
{
$paths_b64 = [];
foreach ($paths as $path) {
$paths_b64[] = $this->encodePath($path);
}
return $paths_b64;
}
|
[
"private",
"function",
"encodePaths",
"(",
"array",
"$",
"paths",
")",
"{",
"$",
"paths_b64",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"path",
")",
"{",
"$",
"paths_b64",
"[",
"]",
"=",
"$",
"this",
"->",
"encodePath",
"(",
"$",
"path",
")",
";",
"}",
"return",
"$",
"paths_b64",
";",
"}"
] |
Base64 encode paths
@param array $paths
@return array
|
[
"Base64",
"encode",
"paths"
] |
6b90f932fca9d74053dc0af9664881664a29cefb
|
https://github.com/alphayax/freebox_api_php/blob/6b90f932fca9d74053dc0af9664881664a29cefb/freebox/api/v4/services/FileSystem/FileSystemOperation.php#L34-L41
|
227,276
|
alphayax/freebox_api_php
|
freebox/api/v4/services/FileSystem/FileSystemOperation.php
|
FileSystemOperation.archive
|
public function archive(array $fileParts, $destination)
{
/// Convert all paths in base64
$destination_b64 = $this->encodePath($destination);
$fileParts_b64 = $this->encodePaths($fileParts);
$result = $this->callService('POST', self::API_FS_ARCHIVE, [
'files' => $fileParts_b64,
'dst' => $destination_b64,
]);
return $result->getModel(models\FileSystem\FsTask::class);
}
|
php
|
public function archive(array $fileParts, $destination)
{
/// Convert all paths in base64
$destination_b64 = $this->encodePath($destination);
$fileParts_b64 = $this->encodePaths($fileParts);
$result = $this->callService('POST', self::API_FS_ARCHIVE, [
'files' => $fileParts_b64,
'dst' => $destination_b64,
]);
return $result->getModel(models\FileSystem\FsTask::class);
}
|
[
"public",
"function",
"archive",
"(",
"array",
"$",
"fileParts",
",",
"$",
"destination",
")",
"{",
"/// Convert all paths in base64",
"$",
"destination_b64",
"=",
"$",
"this",
"->",
"encodePath",
"(",
"$",
"destination",
")",
";",
"$",
"fileParts_b64",
"=",
"$",
"this",
"->",
"encodePaths",
"(",
"$",
"fileParts",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"callService",
"(",
"'POST'",
",",
"self",
"::",
"API_FS_ARCHIVE",
",",
"[",
"'files'",
"=>",
"$",
"fileParts_b64",
",",
"'dst'",
"=>",
"$",
"destination_b64",
",",
"]",
")",
";",
"return",
"$",
"result",
"->",
"getModel",
"(",
"models",
"\\",
"FileSystem",
"\\",
"FsTask",
"::",
"class",
")",
";",
"}"
] |
Create an archive
@param string[] $fileParts : The list of files to concatenate
@param string $destination : The destination file
@return models\FileSystem\FsTask
@throws \GuzzleHttp\Exception\GuzzleException
@throws \alphayax\freebox\Exception\FreeboxApiException
|
[
"Create",
"an",
"archive"
] |
6b90f932fca9d74053dc0af9664881664a29cefb
|
https://github.com/alphayax/freebox_api_php/blob/6b90f932fca9d74053dc0af9664881664a29cefb/freebox/api/v4/services/FileSystem/FileSystemOperation.php#L164-L176
|
227,277
|
alphayax/freebox_api_php
|
freebox/api/v4/services/FileSystem/FileSystemOperation.php
|
FileSystemOperation.extract
|
public function extract($source, $destination, $password = '', $isToDelete = false, $isToOverwrite = false)
{
/// Convert all paths in base64
$source_b64 = $this->encodePath($source);
$destination_b64 = $this->encodePath($destination);
$result = $this->callService('POST', self::API_FS_EXTRACT, [
'src' => $source_b64,
'dst' => $destination_b64,
'password' => $password,
'delete_archive' => $isToDelete,
'overwrite' => $isToOverwrite,
]);
return $result->getModel(models\FileSystem\FsTask::class);
}
|
php
|
public function extract($source, $destination, $password = '', $isToDelete = false, $isToOverwrite = false)
{
/// Convert all paths in base64
$source_b64 = $this->encodePath($source);
$destination_b64 = $this->encodePath($destination);
$result = $this->callService('POST', self::API_FS_EXTRACT, [
'src' => $source_b64,
'dst' => $destination_b64,
'password' => $password,
'delete_archive' => $isToDelete,
'overwrite' => $isToOverwrite,
]);
return $result->getModel(models\FileSystem\FsTask::class);
}
|
[
"public",
"function",
"extract",
"(",
"$",
"source",
",",
"$",
"destination",
",",
"$",
"password",
"=",
"''",
",",
"$",
"isToDelete",
"=",
"false",
",",
"$",
"isToOverwrite",
"=",
"false",
")",
"{",
"/// Convert all paths in base64",
"$",
"source_b64",
"=",
"$",
"this",
"->",
"encodePath",
"(",
"$",
"source",
")",
";",
"$",
"destination_b64",
"=",
"$",
"this",
"->",
"encodePath",
"(",
"$",
"destination",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"callService",
"(",
"'POST'",
",",
"self",
"::",
"API_FS_EXTRACT",
",",
"[",
"'src'",
"=>",
"$",
"source_b64",
",",
"'dst'",
"=>",
"$",
"destination_b64",
",",
"'password'",
"=>",
"$",
"password",
",",
"'delete_archive'",
"=>",
"$",
"isToDelete",
",",
"'overwrite'",
"=>",
"$",
"isToOverwrite",
",",
"]",
")",
";",
"return",
"$",
"result",
"->",
"getModel",
"(",
"models",
"\\",
"FileSystem",
"\\",
"FsTask",
"::",
"class",
")",
";",
"}"
] |
Extract an archive
@param string $source : The archive file
@param string $destination : The destination folder
@param string $password : The archive password
@param bool $isToDelete : Delete archive after extraction
@param bool $isToOverwrite : Overwrites the destination
@return models\FileSystem\FsTask
@throws \GuzzleHttp\Exception\GuzzleException
@throws \alphayax\freebox\Exception\FreeboxApiException
|
[
"Extract",
"an",
"archive"
] |
6b90f932fca9d74053dc0af9664881664a29cefb
|
https://github.com/alphayax/freebox_api_php/blob/6b90f932fca9d74053dc0af9664881664a29cefb/freebox/api/v4/services/FileSystem/FileSystemOperation.php#L189-L204
|
227,278
|
alphayax/freebox_api_php
|
freebox/api/v4/services/FileSystem/FileSystemOperation.php
|
FileSystemOperation.repair
|
public function repair($source, $isToDelete = false)
{
/// Convert all paths in base64
$source_b64 = $this->encodePath($source);
$result = $this->callService('POST', self::API_FS_REPAIR, [
'src' => $source_b64,
'delete_archive' => $isToDelete,
]);
return $result->getModel(models\FileSystem\FsTask::class);
}
|
php
|
public function repair($source, $isToDelete = false)
{
/// Convert all paths in base64
$source_b64 = $this->encodePath($source);
$result = $this->callService('POST', self::API_FS_REPAIR, [
'src' => $source_b64,
'delete_archive' => $isToDelete,
]);
return $result->getModel(models\FileSystem\FsTask::class);
}
|
[
"public",
"function",
"repair",
"(",
"$",
"source",
",",
"$",
"isToDelete",
"=",
"false",
")",
"{",
"/// Convert all paths in base64",
"$",
"source_b64",
"=",
"$",
"this",
"->",
"encodePath",
"(",
"$",
"source",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"callService",
"(",
"'POST'",
",",
"self",
"::",
"API_FS_REPAIR",
",",
"[",
"'src'",
"=>",
"$",
"source_b64",
",",
"'delete_archive'",
"=>",
"$",
"isToDelete",
",",
"]",
")",
";",
"return",
"$",
"result",
"->",
"getModel",
"(",
"models",
"\\",
"FileSystem",
"\\",
"FsTask",
"::",
"class",
")",
";",
"}"
] |
Repair files from a .par2
@param string $source : The .par2 file
@param bool $isToDelete : Delete par2 files after repair
@return models\FileSystem\FsTask
@throws \GuzzleHttp\Exception\GuzzleException
@throws \alphayax\freebox\Exception\FreeboxApiException
|
[
"Repair",
"files",
"from",
"a",
".",
"par2"
] |
6b90f932fca9d74053dc0af9664881664a29cefb
|
https://github.com/alphayax/freebox_api_php/blob/6b90f932fca9d74053dc0af9664881664a29cefb/freebox/api/v4/services/FileSystem/FileSystemOperation.php#L214-L225
|
227,279
|
alphayax/freebox_api_php
|
freebox/api/v4/services/FileSystem/FileSystemOperation.php
|
FileSystemOperation.createDirectory
|
public function createDirectory($parentDirectory, $newDirectoryName)
{
$result = $this->callService('POST', self::API_FS_MKDIR, [
'parent' => $this->encodePath($parentDirectory),
'dirname' => $newDirectoryName,
]);
return $result->getSuccess();
}
|
php
|
public function createDirectory($parentDirectory, $newDirectoryName)
{
$result = $this->callService('POST', self::API_FS_MKDIR, [
'parent' => $this->encodePath($parentDirectory),
'dirname' => $newDirectoryName,
]);
return $result->getSuccess();
}
|
[
"public",
"function",
"createDirectory",
"(",
"$",
"parentDirectory",
",",
"$",
"newDirectoryName",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"callService",
"(",
"'POST'",
",",
"self",
"::",
"API_FS_MKDIR",
",",
"[",
"'parent'",
"=>",
"$",
"this",
"->",
"encodePath",
"(",
"$",
"parentDirectory",
")",
",",
"'dirname'",
"=>",
"$",
"newDirectoryName",
",",
"]",
")",
";",
"return",
"$",
"result",
"->",
"getSuccess",
"(",
")",
";",
"}"
] |
Create a directory
Contrary to other file system tasks, this operation is done synchronously.
Instead of a returning a FsTask a call to this API will only return success status
@param string $parentDirectory : The parent directory path
@param string $newDirectoryName : The name of the directory to create
@return bool
@throws \GuzzleHttp\Exception\GuzzleException
@throws \alphayax\freebox\Exception\FreeboxApiException
|
[
"Create",
"a",
"directory",
"Contrary",
"to",
"other",
"file",
"system",
"tasks",
"this",
"operation",
"is",
"done",
"synchronously",
".",
"Instead",
"of",
"a",
"returning",
"a",
"FsTask",
"a",
"call",
"to",
"this",
"API",
"will",
"only",
"return",
"success",
"status"
] |
6b90f932fca9d74053dc0af9664881664a29cefb
|
https://github.com/alphayax/freebox_api_php/blob/6b90f932fca9d74053dc0af9664881664a29cefb/freebox/api/v4/services/FileSystem/FileSystemOperation.php#L275-L283
|
227,280
|
toplan/task-balancer
|
src/TaskBalancer/Task.php
|
Task.create
|
public static function create($name = null, $data = null, \Closure $ready = null)
{
$task = new self($data);
$task->name($name);
if (is_callable($ready)) {
call_user_func($ready, $task);
}
return $task;
}
|
php
|
public static function create($name = null, $data = null, \Closure $ready = null)
{
$task = new self($data);
$task->name($name);
if (is_callable($ready)) {
call_user_func($ready, $task);
}
return $task;
}
|
[
"public",
"static",
"function",
"create",
"(",
"$",
"name",
"=",
"null",
",",
"$",
"data",
"=",
"null",
",",
"\\",
"Closure",
"$",
"ready",
"=",
"null",
")",
"{",
"$",
"task",
"=",
"new",
"self",
"(",
"$",
"data",
")",
";",
"$",
"task",
"->",
"name",
"(",
"$",
"name",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"ready",
")",
")",
"{",
"call_user_func",
"(",
"$",
"ready",
",",
"$",
"task",
")",
";",
"}",
"return",
"$",
"task",
";",
"}"
] |
create a new task.
@param string|null $name
@param mixed $data
@param \Closure|null $ready
@return Task
|
[
"create",
"a",
"new",
"task",
"."
] |
6ba16aafbf6888de0f0c53ea93dfff844b6ef27f
|
https://github.com/toplan/task-balancer/blob/6ba16aafbf6888de0f0c53ea93dfff844b6ef27f/src/TaskBalancer/Task.php#L113-L122
|
227,281
|
toplan/task-balancer
|
src/TaskBalancer/Task.php
|
Task.beforeRun
|
protected function beforeRun()
{
$this->reset();
$pass = $this->callHookHandler('beforeRun');
if ($pass) {
$this->status = static::RUNNING;
$this->time['started_at'] = microtime();
}
return $pass;
}
|
php
|
protected function beforeRun()
{
$this->reset();
$pass = $this->callHookHandler('beforeRun');
if ($pass) {
$this->status = static::RUNNING;
$this->time['started_at'] = microtime();
}
return $pass;
}
|
[
"protected",
"function",
"beforeRun",
"(",
")",
"{",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"$",
"pass",
"=",
"$",
"this",
"->",
"callHookHandler",
"(",
"'beforeRun'",
")",
";",
"if",
"(",
"$",
"pass",
")",
"{",
"$",
"this",
"->",
"status",
"=",
"static",
"::",
"RUNNING",
";",
"$",
"this",
"->",
"time",
"[",
"'started_at'",
"]",
"=",
"microtime",
"(",
")",
";",
"}",
"return",
"$",
"pass",
";",
"}"
] |
before run task.
@return bool
|
[
"before",
"run",
"task",
"."
] |
6ba16aafbf6888de0f0c53ea93dfff844b6ef27f
|
https://github.com/toplan/task-balancer/blob/6ba16aafbf6888de0f0c53ea93dfff844b6ef27f/src/TaskBalancer/Task.php#L155-L165
|
227,282
|
toplan/task-balancer
|
src/TaskBalancer/Task.php
|
Task.reset
|
protected function reset()
{
$this->status = null;
$this->results = [];
$this->currentDriver = null;
$this->time['started_at'] = 0;
$this->time['finished_at'] = 0;
return $this;
}
|
php
|
protected function reset()
{
$this->status = null;
$this->results = [];
$this->currentDriver = null;
$this->time['started_at'] = 0;
$this->time['finished_at'] = 0;
return $this;
}
|
[
"protected",
"function",
"reset",
"(",
")",
"{",
"$",
"this",
"->",
"status",
"=",
"null",
";",
"$",
"this",
"->",
"results",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"currentDriver",
"=",
"null",
";",
"$",
"this",
"->",
"time",
"[",
"'started_at'",
"]",
"=",
"0",
";",
"$",
"this",
"->",
"time",
"[",
"'finished_at'",
"]",
"=",
"0",
";",
"return",
"$",
"this",
";",
"}"
] |
reset states.
@return $this
|
[
"reset",
"states",
"."
] |
6ba16aafbf6888de0f0c53ea93dfff844b6ef27f
|
https://github.com/toplan/task-balancer/blob/6ba16aafbf6888de0f0c53ea93dfff844b6ef27f/src/TaskBalancer/Task.php#L172-L181
|
227,283
|
toplan/task-balancer
|
src/TaskBalancer/Task.php
|
Task.afterRun
|
protected function afterRun($success)
{
$this->status = static::FINISHED;
$this->time['finished_at'] = microtime();
$return = [];
$return['success'] = $success;
$return['time'] = $this->time;
$return['logs'] = $this->results;
$data = $this->callHookHandler('afterRun', $return);
return is_bool($data) ? $return : $data;
}
|
php
|
protected function afterRun($success)
{
$this->status = static::FINISHED;
$this->time['finished_at'] = microtime();
$return = [];
$return['success'] = $success;
$return['time'] = $this->time;
$return['logs'] = $this->results;
$data = $this->callHookHandler('afterRun', $return);
return is_bool($data) ? $return : $data;
}
|
[
"protected",
"function",
"afterRun",
"(",
"$",
"success",
")",
"{",
"$",
"this",
"->",
"status",
"=",
"static",
"::",
"FINISHED",
";",
"$",
"this",
"->",
"time",
"[",
"'finished_at'",
"]",
"=",
"microtime",
"(",
")",
";",
"$",
"return",
"=",
"[",
"]",
";",
"$",
"return",
"[",
"'success'",
"]",
"=",
"$",
"success",
";",
"$",
"return",
"[",
"'time'",
"]",
"=",
"$",
"this",
"->",
"time",
";",
"$",
"return",
"[",
"'logs'",
"]",
"=",
"$",
"this",
"->",
"results",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"callHookHandler",
"(",
"'afterRun'",
",",
"$",
"return",
")",
";",
"return",
"is_bool",
"(",
"$",
"data",
")",
"?",
"$",
"return",
":",
"$",
"data",
";",
"}"
] |
after run task.
@param bool $success
@return mixed
|
[
"after",
"run",
"task",
"."
] |
6ba16aafbf6888de0f0c53ea93dfff844b6ef27f
|
https://github.com/toplan/task-balancer/blob/6ba16aafbf6888de0f0c53ea93dfff844b6ef27f/src/TaskBalancer/Task.php#L190-L201
|
227,284
|
toplan/task-balancer
|
src/TaskBalancer/Task.php
|
Task.runDriver
|
public function runDriver($name)
{
// if not found driver by the name, throw exception.
$driver = $this->getDriver($name);
if (!$driver) {
return false;
}
$this->currentDriver = $driver;
// before run a driver, call 'beforeDriverRun' hooks,
// and current driver has already changed.
// If 'beforeDriverRun' hook return false,
// stop to use current driver and try to use next driver.
$currentDriverEnable = $this->callHookHandler('beforeDriverRun', $driver);
if (!$currentDriverEnable) {
return $this->tryNextDriver();
}
// start run driver, and store the result.
$result = $driver->run();
$success = $driver->success;
$data = [
'driver' => $driver->name,
'time' => $driver->time,
'success' => $success,
'result' => $result,
];
array_push($this->results, $data);
// call 'afterDriverRun' hooks.
$this->callHookHandler('afterDriverRun', $data);
// if failed, try to use next backup driver.
if (!$success) {
return $this->tryNextDriver();
}
return true;
}
|
php
|
public function runDriver($name)
{
// if not found driver by the name, throw exception.
$driver = $this->getDriver($name);
if (!$driver) {
return false;
}
$this->currentDriver = $driver;
// before run a driver, call 'beforeDriverRun' hooks,
// and current driver has already changed.
// If 'beforeDriverRun' hook return false,
// stop to use current driver and try to use next driver.
$currentDriverEnable = $this->callHookHandler('beforeDriverRun', $driver);
if (!$currentDriverEnable) {
return $this->tryNextDriver();
}
// start run driver, and store the result.
$result = $driver->run();
$success = $driver->success;
$data = [
'driver' => $driver->name,
'time' => $driver->time,
'success' => $success,
'result' => $result,
];
array_push($this->results, $data);
// call 'afterDriverRun' hooks.
$this->callHookHandler('afterDriverRun', $data);
// if failed, try to use next backup driver.
if (!$success) {
return $this->tryNextDriver();
}
return true;
}
|
[
"public",
"function",
"runDriver",
"(",
"$",
"name",
")",
"{",
"// if not found driver by the name, throw exception.",
"$",
"driver",
"=",
"$",
"this",
"->",
"getDriver",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"$",
"driver",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"currentDriver",
"=",
"$",
"driver",
";",
"// before run a driver, call 'beforeDriverRun' hooks,",
"// and current driver has already changed.",
"// If 'beforeDriverRun' hook return false,",
"// stop to use current driver and try to use next driver.",
"$",
"currentDriverEnable",
"=",
"$",
"this",
"->",
"callHookHandler",
"(",
"'beforeDriverRun'",
",",
"$",
"driver",
")",
";",
"if",
"(",
"!",
"$",
"currentDriverEnable",
")",
"{",
"return",
"$",
"this",
"->",
"tryNextDriver",
"(",
")",
";",
"}",
"// start run driver, and store the result.",
"$",
"result",
"=",
"$",
"driver",
"->",
"run",
"(",
")",
";",
"$",
"success",
"=",
"$",
"driver",
"->",
"success",
";",
"$",
"data",
"=",
"[",
"'driver'",
"=>",
"$",
"driver",
"->",
"name",
",",
"'time'",
"=>",
"$",
"driver",
"->",
"time",
",",
"'success'",
"=>",
"$",
"success",
",",
"'result'",
"=>",
"$",
"result",
",",
"]",
";",
"array_push",
"(",
"$",
"this",
"->",
"results",
",",
"$",
"data",
")",
";",
"// call 'afterDriverRun' hooks.",
"$",
"this",
"->",
"callHookHandler",
"(",
"'afterDriverRun'",
",",
"$",
"data",
")",
";",
"// if failed, try to use next backup driver.",
"if",
"(",
"!",
"$",
"success",
")",
"{",
"return",
"$",
"this",
"->",
"tryNextDriver",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
run driver by name.
@param string $name
@throws TaskBalancerException
@return bool
|
[
"run",
"driver",
"by",
"name",
"."
] |
6ba16aafbf6888de0f0c53ea93dfff844b6ef27f
|
https://github.com/toplan/task-balancer/blob/6ba16aafbf6888de0f0c53ea93dfff844b6ef27f/src/TaskBalancer/Task.php#L212-L250
|
227,285
|
toplan/task-balancer
|
src/TaskBalancer/Task.php
|
Task.tryNextDriver
|
public function tryNextDriver()
{
$backupDriverName = array_pop($this->backupDrivers);
if ($backupDriverName) {
return $this->runDriver($backupDriverName);
}
return false;
}
|
php
|
public function tryNextDriver()
{
$backupDriverName = array_pop($this->backupDrivers);
if ($backupDriverName) {
return $this->runDriver($backupDriverName);
}
return false;
}
|
[
"public",
"function",
"tryNextDriver",
"(",
")",
"{",
"$",
"backupDriverName",
"=",
"array_pop",
"(",
"$",
"this",
"->",
"backupDrivers",
")",
";",
"if",
"(",
"$",
"backupDriverName",
")",
"{",
"return",
"$",
"this",
"->",
"runDriver",
"(",
"$",
"backupDriverName",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
try to use next backup driver.
@return bool
|
[
"try",
"to",
"use",
"next",
"backup",
"driver",
"."
] |
6ba16aafbf6888de0f0c53ea93dfff844b6ef27f
|
https://github.com/toplan/task-balancer/blob/6ba16aafbf6888de0f0c53ea93dfff844b6ef27f/src/TaskBalancer/Task.php#L257-L265
|
227,286
|
toplan/task-balancer
|
src/TaskBalancer/Task.php
|
Task.getDriverNameByWeight
|
public function getDriverNameByWeight()
{
$count = $base = 0;
$map = [];
foreach ($this->drivers as $driver) {
$count += $driver->weight;
if ($driver->weight) {
$max = $base + $driver->weight;
$map[] = [
'min' => $base,
'max' => $max,
'driver' => $driver->name,
];
$base = $max;
}
}
if ($count <= 0) {
return;
}
$number = mt_rand(0, $count - 1);
foreach ($map as $data) {
if ($number >= $data['min'] && $number < $data['max']) {
return $data['driver'];
}
}
}
|
php
|
public function getDriverNameByWeight()
{
$count = $base = 0;
$map = [];
foreach ($this->drivers as $driver) {
$count += $driver->weight;
if ($driver->weight) {
$max = $base + $driver->weight;
$map[] = [
'min' => $base,
'max' => $max,
'driver' => $driver->name,
];
$base = $max;
}
}
if ($count <= 0) {
return;
}
$number = mt_rand(0, $count - 1);
foreach ($map as $data) {
if ($number >= $data['min'] && $number < $data['max']) {
return $data['driver'];
}
}
}
|
[
"public",
"function",
"getDriverNameByWeight",
"(",
")",
"{",
"$",
"count",
"=",
"$",
"base",
"=",
"0",
";",
"$",
"map",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"drivers",
"as",
"$",
"driver",
")",
"{",
"$",
"count",
"+=",
"$",
"driver",
"->",
"weight",
";",
"if",
"(",
"$",
"driver",
"->",
"weight",
")",
"{",
"$",
"max",
"=",
"$",
"base",
"+",
"$",
"driver",
"->",
"weight",
";",
"$",
"map",
"[",
"]",
"=",
"[",
"'min'",
"=>",
"$",
"base",
",",
"'max'",
"=>",
"$",
"max",
",",
"'driver'",
"=>",
"$",
"driver",
"->",
"name",
",",
"]",
";",
"$",
"base",
"=",
"$",
"max",
";",
"}",
"}",
"if",
"(",
"$",
"count",
"<=",
"0",
")",
"{",
"return",
";",
"}",
"$",
"number",
"=",
"mt_rand",
"(",
"0",
",",
"$",
"count",
"-",
"1",
")",
";",
"foreach",
"(",
"$",
"map",
"as",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"number",
">=",
"$",
"data",
"[",
"'min'",
"]",
"&&",
"$",
"number",
"<",
"$",
"data",
"[",
"'max'",
"]",
")",
"{",
"return",
"$",
"data",
"[",
"'driver'",
"]",
";",
"}",
"}",
"}"
] |
get a driver's name from drivers by driver's weight.
@return string|null
|
[
"get",
"a",
"driver",
"s",
"name",
"from",
"drivers",
"by",
"driver",
"s",
"weight",
"."
] |
6ba16aafbf6888de0f0c53ea93dfff844b6ef27f
|
https://github.com/toplan/task-balancer/blob/6ba16aafbf6888de0f0c53ea93dfff844b6ef27f/src/TaskBalancer/Task.php#L272-L297
|
227,287
|
toplan/task-balancer
|
src/TaskBalancer/Task.php
|
Task.driver
|
public function driver()
{
$args = func_get_args();
$props = Driver::parseArgs($args);
$newProps = $this->callHookHandler('beforeCreateDriver', $props);
if (is_array($newProps)) {
$props = array_merge($props, $newProps);
}
extract($props);
$driver = Driver::create($this, $name, $weight, $backup, $work);
$this->drivers[$name] = $driver;
$this->callHookHandler('afterCreateDriver', $driver);
return $driver;
}
|
php
|
public function driver()
{
$args = func_get_args();
$props = Driver::parseArgs($args);
$newProps = $this->callHookHandler('beforeCreateDriver', $props);
if (is_array($newProps)) {
$props = array_merge($props, $newProps);
}
extract($props);
$driver = Driver::create($this, $name, $weight, $backup, $work);
$this->drivers[$name] = $driver;
$this->callHookHandler('afterCreateDriver', $driver);
return $driver;
}
|
[
"public",
"function",
"driver",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"props",
"=",
"Driver",
"::",
"parseArgs",
"(",
"$",
"args",
")",
";",
"$",
"newProps",
"=",
"$",
"this",
"->",
"callHookHandler",
"(",
"'beforeCreateDriver'",
",",
"$",
"props",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"newProps",
")",
")",
"{",
"$",
"props",
"=",
"array_merge",
"(",
"$",
"props",
",",
"$",
"newProps",
")",
";",
"}",
"extract",
"(",
"$",
"props",
")",
";",
"$",
"driver",
"=",
"Driver",
"::",
"create",
"(",
"$",
"this",
",",
"$",
"name",
",",
"$",
"weight",
",",
"$",
"backup",
",",
"$",
"work",
")",
";",
"$",
"this",
"->",
"drivers",
"[",
"$",
"name",
"]",
"=",
"$",
"driver",
";",
"$",
"this",
"->",
"callHookHandler",
"(",
"'afterCreateDriver'",
",",
"$",
"driver",
")",
";",
"return",
"$",
"driver",
";",
"}"
] |
create a new driver instance for current task.
@return Driver
|
[
"create",
"a",
"new",
"driver",
"instance",
"for",
"current",
"task",
"."
] |
6ba16aafbf6888de0f0c53ea93dfff844b6ef27f
|
https://github.com/toplan/task-balancer/blob/6ba16aafbf6888de0f0c53ea93dfff844b6ef27f/src/TaskBalancer/Task.php#L304-L318
|
227,288
|
toplan/task-balancer
|
src/TaskBalancer/Task.php
|
Task.removeDriver
|
public function removeDriver($driver)
{
if ($driver instanceof Driver) {
$driver = $driver->name;
}
if (!$this->hasDriver($driver)) {
return;
}
$this->removeFromBackupDrivers($driver);
unset($this->drivers[$driver]);
}
|
php
|
public function removeDriver($driver)
{
if ($driver instanceof Driver) {
$driver = $driver->name;
}
if (!$this->hasDriver($driver)) {
return;
}
$this->removeFromBackupDrivers($driver);
unset($this->drivers[$driver]);
}
|
[
"public",
"function",
"removeDriver",
"(",
"$",
"driver",
")",
"{",
"if",
"(",
"$",
"driver",
"instanceof",
"Driver",
")",
"{",
"$",
"driver",
"=",
"$",
"driver",
"->",
"name",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"hasDriver",
"(",
"$",
"driver",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"removeFromBackupDrivers",
"(",
"$",
"driver",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"drivers",
"[",
"$",
"driver",
"]",
")",
";",
"}"
] |
remove driver.
@param Driver|string $driver
|
[
"remove",
"driver",
"."
] |
6ba16aafbf6888de0f0c53ea93dfff844b6ef27f
|
https://github.com/toplan/task-balancer/blob/6ba16aafbf6888de0f0c53ea93dfff844b6ef27f/src/TaskBalancer/Task.php#L355-L365
|
227,289
|
toplan/task-balancer
|
src/TaskBalancer/Task.php
|
Task.initBackupDrivers
|
public function initBackupDrivers(array $excepted = [])
{
$this->backupDrivers = [];
foreach ($this->drivers as $name => $driver) {
if ($driver->backup && !in_array($name, $excepted)) {
array_unshift($this->backupDrivers, $name);
}
}
}
|
php
|
public function initBackupDrivers(array $excepted = [])
{
$this->backupDrivers = [];
foreach ($this->drivers as $name => $driver) {
if ($driver->backup && !in_array($name, $excepted)) {
array_unshift($this->backupDrivers, $name);
}
}
}
|
[
"public",
"function",
"initBackupDrivers",
"(",
"array",
"$",
"excepted",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"backupDrivers",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"drivers",
"as",
"$",
"name",
"=>",
"$",
"driver",
")",
"{",
"if",
"(",
"$",
"driver",
"->",
"backup",
"&&",
"!",
"in_array",
"(",
"$",
"name",
",",
"$",
"excepted",
")",
")",
"{",
"array_unshift",
"(",
"$",
"this",
"->",
"backupDrivers",
",",
"$",
"name",
")",
";",
"}",
"}",
"}"
] |
initialize back up drivers.
@param string[] excepted
|
[
"initialize",
"back",
"up",
"drivers",
"."
] |
6ba16aafbf6888de0f0c53ea93dfff844b6ef27f
|
https://github.com/toplan/task-balancer/blob/6ba16aafbf6888de0f0c53ea93dfff844b6ef27f/src/TaskBalancer/Task.php#L372-L380
|
227,290
|
toplan/task-balancer
|
src/TaskBalancer/Task.php
|
Task.appendToBackupDrivers
|
public function appendToBackupDrivers($driver)
{
if ($driver instanceof Driver) {
$driver = $driver->name;
}
if (!in_array($driver, $this->backupDrivers)) {
array_push($this->backupDrivers, $driver);
}
}
|
php
|
public function appendToBackupDrivers($driver)
{
if ($driver instanceof Driver) {
$driver = $driver->name;
}
if (!in_array($driver, $this->backupDrivers)) {
array_push($this->backupDrivers, $driver);
}
}
|
[
"public",
"function",
"appendToBackupDrivers",
"(",
"$",
"driver",
")",
"{",
"if",
"(",
"$",
"driver",
"instanceof",
"Driver",
")",
"{",
"$",
"driver",
"=",
"$",
"driver",
"->",
"name",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"driver",
",",
"$",
"this",
"->",
"backupDrivers",
")",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"backupDrivers",
",",
"$",
"driver",
")",
";",
"}",
"}"
] |
append driver to backup drivers.
@param Driver|string $driver
|
[
"append",
"driver",
"to",
"backup",
"drivers",
"."
] |
6ba16aafbf6888de0f0c53ea93dfff844b6ef27f
|
https://github.com/toplan/task-balancer/blob/6ba16aafbf6888de0f0c53ea93dfff844b6ef27f/src/TaskBalancer/Task.php#L397-L405
|
227,291
|
toplan/task-balancer
|
src/TaskBalancer/Task.php
|
Task.removeFromBackupDrivers
|
public function removeFromBackupDrivers($driver)
{
if ($driver instanceof Driver) {
$driver = $driver->name;
}
if (in_array($driver, $this->backupDrivers)) {
$index = array_search($driver, $this->backupDrivers);
array_splice($this->backupDrivers, $index, 1);
}
}
|
php
|
public function removeFromBackupDrivers($driver)
{
if ($driver instanceof Driver) {
$driver = $driver->name;
}
if (in_array($driver, $this->backupDrivers)) {
$index = array_search($driver, $this->backupDrivers);
array_splice($this->backupDrivers, $index, 1);
}
}
|
[
"public",
"function",
"removeFromBackupDrivers",
"(",
"$",
"driver",
")",
"{",
"if",
"(",
"$",
"driver",
"instanceof",
"Driver",
")",
"{",
"$",
"driver",
"=",
"$",
"driver",
"->",
"name",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"driver",
",",
"$",
"this",
"->",
"backupDrivers",
")",
")",
"{",
"$",
"index",
"=",
"array_search",
"(",
"$",
"driver",
",",
"$",
"this",
"->",
"backupDrivers",
")",
";",
"array_splice",
"(",
"$",
"this",
"->",
"backupDrivers",
",",
"$",
"index",
",",
"1",
")",
";",
"}",
"}"
] |
remove driver from backup drivers.
@param Driver|string $driver
|
[
"remove",
"driver",
"from",
"backup",
"drivers",
"."
] |
6ba16aafbf6888de0f0c53ea93dfff844b6ef27f
|
https://github.com/toplan/task-balancer/blob/6ba16aafbf6888de0f0c53ea93dfff844b6ef27f/src/TaskBalancer/Task.php#L412-L421
|
227,292
|
toplan/task-balancer
|
src/TaskBalancer/Task.php
|
Task.name
|
public function name($name)
{
if (!is_string($name) || empty($name)) {
throw new TaskBalancerException('Expected task name to be a non-empty string.');
}
$this->name = $name;
return $this;
}
|
php
|
public function name($name)
{
if (!is_string($name) || empty($name)) {
throw new TaskBalancerException('Expected task name to be a non-empty string.');
}
$this->name = $name;
return $this;
}
|
[
"public",
"function",
"name",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"name",
")",
"||",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"TaskBalancerException",
"(",
"'Expected task name to be a non-empty string.'",
")",
";",
"}",
"$",
"this",
"->",
"name",
"=",
"$",
"name",
";",
"return",
"$",
"this",
";",
"}"
] |
set the name of task.
@param string $name
@return $this
@throws TaskBalancerException
|
[
"set",
"the",
"name",
"of",
"task",
"."
] |
6ba16aafbf6888de0f0c53ea93dfff844b6ef27f
|
https://github.com/toplan/task-balancer/blob/6ba16aafbf6888de0f0c53ea93dfff844b6ef27f/src/TaskBalancer/Task.php#L431-L439
|
227,293
|
toplan/task-balancer
|
src/TaskBalancer/Task.php
|
Task.hook
|
public function hook($hookName, $handler = null, $override = false)
{
if (is_callable($handler) && is_string($hookName)) {
if (in_array($hookName, self::$hooks)) {
if (!isset($this->handlers[$hookName])) {
$this->handlers[$hookName] = [];
}
if ($override) {
$this->handlers[$hookName] = [$handler];
} else {
array_push($this->handlers[$hookName], $handler);
}
} else {
throw new TaskBalancerException("Don't support hooks `$hookName`.");
}
} elseif (is_array($hookName)) {
if (is_bool($handler) && $handler) {
$this->handlers = [];
}
foreach ($hookName as $k => $v) {
$this->hook($k, $v, false);
}
}
}
|
php
|
public function hook($hookName, $handler = null, $override = false)
{
if (is_callable($handler) && is_string($hookName)) {
if (in_array($hookName, self::$hooks)) {
if (!isset($this->handlers[$hookName])) {
$this->handlers[$hookName] = [];
}
if ($override) {
$this->handlers[$hookName] = [$handler];
} else {
array_push($this->handlers[$hookName], $handler);
}
} else {
throw new TaskBalancerException("Don't support hooks `$hookName`.");
}
} elseif (is_array($hookName)) {
if (is_bool($handler) && $handler) {
$this->handlers = [];
}
foreach ($hookName as $k => $v) {
$this->hook($k, $v, false);
}
}
}
|
[
"public",
"function",
"hook",
"(",
"$",
"hookName",
",",
"$",
"handler",
"=",
"null",
",",
"$",
"override",
"=",
"false",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"handler",
")",
"&&",
"is_string",
"(",
"$",
"hookName",
")",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"hookName",
",",
"self",
"::",
"$",
"hooks",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"handlers",
"[",
"$",
"hookName",
"]",
")",
")",
"{",
"$",
"this",
"->",
"handlers",
"[",
"$",
"hookName",
"]",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"$",
"override",
")",
"{",
"$",
"this",
"->",
"handlers",
"[",
"$",
"hookName",
"]",
"=",
"[",
"$",
"handler",
"]",
";",
"}",
"else",
"{",
"array_push",
"(",
"$",
"this",
"->",
"handlers",
"[",
"$",
"hookName",
"]",
",",
"$",
"handler",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"TaskBalancerException",
"(",
"\"Don't support hooks `$hookName`.\"",
")",
";",
"}",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"hookName",
")",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"handler",
")",
"&&",
"$",
"handler",
")",
"{",
"$",
"this",
"->",
"handlers",
"=",
"[",
"]",
";",
"}",
"foreach",
"(",
"$",
"hookName",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"this",
"->",
"hook",
"(",
"$",
"k",
",",
"$",
"v",
",",
"false",
")",
";",
"}",
"}",
"}"
] |
set hook's handlers.
@param string|array $hookName
@param \Closure|bool $handler
@param bool $override
@throws TaskBalancerException
|
[
"set",
"hook",
"s",
"handlers",
"."
] |
6ba16aafbf6888de0f0c53ea93dfff844b6ef27f
|
https://github.com/toplan/task-balancer/blob/6ba16aafbf6888de0f0c53ea93dfff844b6ef27f/src/TaskBalancer/Task.php#L464-L487
|
227,294
|
toplan/task-balancer
|
src/TaskBalancer/Task.php
|
Task.callHookHandler
|
protected function callHookHandler($hookName, $data = null)
{
if (array_key_exists($hookName, $this->handlers)) {
$handlers = $this->handlers[$hookName] ?: [];
$result = null;
foreach ($handlers as $index => $handler) {
$handlerArgs = $data === null ?
[$this, $index, &$handlers, $result] :
[$this, $data, $index, &$handlers, $result];
$result = call_user_func_array($handler, $handlerArgs);
}
if ($result === null) {
return true;
}
return $result;
}
return true;
}
|
php
|
protected function callHookHandler($hookName, $data = null)
{
if (array_key_exists($hookName, $this->handlers)) {
$handlers = $this->handlers[$hookName] ?: [];
$result = null;
foreach ($handlers as $index => $handler) {
$handlerArgs = $data === null ?
[$this, $index, &$handlers, $result] :
[$this, $data, $index, &$handlers, $result];
$result = call_user_func_array($handler, $handlerArgs);
}
if ($result === null) {
return true;
}
return $result;
}
return true;
}
|
[
"protected",
"function",
"callHookHandler",
"(",
"$",
"hookName",
",",
"$",
"data",
"=",
"null",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"hookName",
",",
"$",
"this",
"->",
"handlers",
")",
")",
"{",
"$",
"handlers",
"=",
"$",
"this",
"->",
"handlers",
"[",
"$",
"hookName",
"]",
"?",
":",
"[",
"]",
";",
"$",
"result",
"=",
"null",
";",
"foreach",
"(",
"$",
"handlers",
"as",
"$",
"index",
"=>",
"$",
"handler",
")",
"{",
"$",
"handlerArgs",
"=",
"$",
"data",
"===",
"null",
"?",
"[",
"$",
"this",
",",
"$",
"index",
",",
"&",
"$",
"handlers",
",",
"$",
"result",
"]",
":",
"[",
"$",
"this",
",",
"$",
"data",
",",
"$",
"index",
",",
"&",
"$",
"handlers",
",",
"$",
"result",
"]",
";",
"$",
"result",
"=",
"call_user_func_array",
"(",
"$",
"handler",
",",
"$",
"handlerArgs",
")",
";",
"}",
"if",
"(",
"$",
"result",
"===",
"null",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"result",
";",
"}",
"return",
"true",
";",
"}"
] |
call hook's handlers.
@param string $hookName
@param mixed $data
@return mixed
|
[
"call",
"hook",
"s",
"handlers",
"."
] |
6ba16aafbf6888de0f0c53ea93dfff844b6ef27f
|
https://github.com/toplan/task-balancer/blob/6ba16aafbf6888de0f0c53ea93dfff844b6ef27f/src/TaskBalancer/Task.php#L497-L516
|
227,295
|
AaronJan/Housekeeper
|
src/Housekeeper/Support/InjectionContainer.php
|
InjectionContainer.sortInjections
|
public function sortInjections($group = null)
{
if ($group) {
usort($this->groupedInjections[$group], [$this, 'sortInjection']);
} else {
foreach ($this->groupedInjections as $injections) {
usort($injections, [$this, 'sortInjection']);
}
}
}
|
php
|
public function sortInjections($group = null)
{
if ($group) {
usort($this->groupedInjections[$group], [$this, 'sortInjection']);
} else {
foreach ($this->groupedInjections as $injections) {
usort($injections, [$this, 'sortInjection']);
}
}
}
|
[
"public",
"function",
"sortInjections",
"(",
"$",
"group",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"group",
")",
"{",
"usort",
"(",
"$",
"this",
"->",
"groupedInjections",
"[",
"$",
"group",
"]",
",",
"[",
"$",
"this",
",",
"'sortInjection'",
"]",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"this",
"->",
"groupedInjections",
"as",
"$",
"injections",
")",
"{",
"usort",
"(",
"$",
"injections",
",",
"[",
"$",
"this",
",",
"'sortInjection'",
"]",
")",
";",
"}",
"}",
"}"
] |
Sort by priority ASC.
@param string|null $group
|
[
"Sort",
"by",
"priority",
"ASC",
"."
] |
9a5f9547e65532111f839c50cd665e9d4ff6cd3f
|
https://github.com/AaronJan/Housekeeper/blob/9a5f9547e65532111f839c50cd665e9d4ff6cd3f/src/Housekeeper/Support/InjectionContainer.php#L133-L142
|
227,296
|
AaronJan/Housekeeper
|
src/Housekeeper/Support/InjectionContainer.php
|
InjectionContainer.sortInjection
|
static protected function sortInjection(BasicInjectionContract $a, BasicInjectionContract $b)
{
if ($a->priority() == $b->priority()) {
return 0;
}
return ($a->priority() < $b->priority()) ? - 1 : 1;
}
|
php
|
static protected function sortInjection(BasicInjectionContract $a, BasicInjectionContract $b)
{
if ($a->priority() == $b->priority()) {
return 0;
}
return ($a->priority() < $b->priority()) ? - 1 : 1;
}
|
[
"static",
"protected",
"function",
"sortInjection",
"(",
"BasicInjectionContract",
"$",
"a",
",",
"BasicInjectionContract",
"$",
"b",
")",
"{",
"if",
"(",
"$",
"a",
"->",
"priority",
"(",
")",
"==",
"$",
"b",
"->",
"priority",
"(",
")",
")",
"{",
"return",
"0",
";",
"}",
"return",
"(",
"$",
"a",
"->",
"priority",
"(",
")",
"<",
"$",
"b",
"->",
"priority",
"(",
")",
")",
"?",
"-",
"1",
":",
"1",
";",
"}"
] |
Custom function for "usort" used by "sortAllInjections".
@param \Housekeeper\Contracts\Injection\Basic $a
@param \Housekeeper\Contracts\Injection\Basic $b
@return int
|
[
"Custom",
"function",
"for",
"usort",
"used",
"by",
"sortAllInjections",
"."
] |
9a5f9547e65532111f839c50cd665e9d4ff6cd3f
|
https://github.com/AaronJan/Housekeeper/blob/9a5f9547e65532111f839c50cd665e9d4ff6cd3f/src/Housekeeper/Support/InjectionContainer.php#L151-L158
|
227,297
|
jk/RestServer
|
src/JK/RestServer/HeaderManager.php
|
HeaderManager.setStatusHeader
|
public function setStatusHeader($status, $protocol = null)
{
if (is_null($protocol) && isset($_SERVER['SERVER_PROTOCOL'])) {
$protocol = $_SERVER['SERVER_PROTOCOL'];
} elseif (is_null($protocol) && !isset($_SERVER['SERVER_PROTOCOL'])) {
$protocol = 'HTTP/1.1';
}
$this->status_header = trim($protocol . ' ' . $status);
}
|
php
|
public function setStatusHeader($status, $protocol = null)
{
if (is_null($protocol) && isset($_SERVER['SERVER_PROTOCOL'])) {
$protocol = $_SERVER['SERVER_PROTOCOL'];
} elseif (is_null($protocol) && !isset($_SERVER['SERVER_PROTOCOL'])) {
$protocol = 'HTTP/1.1';
}
$this->status_header = trim($protocol . ' ' . $status);
}
|
[
"public",
"function",
"setStatusHeader",
"(",
"$",
"status",
",",
"$",
"protocol",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"protocol",
")",
"&&",
"isset",
"(",
"$",
"_SERVER",
"[",
"'SERVER_PROTOCOL'",
"]",
")",
")",
"{",
"$",
"protocol",
"=",
"$",
"_SERVER",
"[",
"'SERVER_PROTOCOL'",
"]",
";",
"}",
"elseif",
"(",
"is_null",
"(",
"$",
"protocol",
")",
"&&",
"!",
"isset",
"(",
"$",
"_SERVER",
"[",
"'SERVER_PROTOCOL'",
"]",
")",
")",
"{",
"$",
"protocol",
"=",
"'HTTP/1.1'",
";",
"}",
"$",
"this",
"->",
"status_header",
"=",
"trim",
"(",
"$",
"protocol",
".",
"' '",
".",
"$",
"status",
")",
";",
"}"
] |
Set the HTTP status header
@param string $status HTTP status header (e.g. 200 OK)
@param string $protocol Server protocol [HTTP/1.1 by default]
|
[
"Set",
"the",
"HTTP",
"status",
"header"
] |
477e6a0f0b601008bf96db9767492d5b35637d0b
|
https://github.com/jk/RestServer/blob/477e6a0f0b601008bf96db9767492d5b35637d0b/src/JK/RestServer/HeaderManager.php#L93-L102
|
227,298
|
jk/RestServer
|
src/JK/RestServer/HeaderManager.php
|
HeaderManager.sendAllHeaders
|
public function sendAllHeaders()
{
if ($this->status_header !== null) {
header($this->status_header);
}
foreach ($this->headers as $name => $value) {
header($name . ': ' . $value);
}
}
|
php
|
public function sendAllHeaders()
{
if ($this->status_header !== null) {
header($this->status_header);
}
foreach ($this->headers as $name => $value) {
header($name . ': ' . $value);
}
}
|
[
"public",
"function",
"sendAllHeaders",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"status_header",
"!==",
"null",
")",
"{",
"header",
"(",
"$",
"this",
"->",
"status_header",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"headers",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"header",
"(",
"$",
"name",
".",
"': '",
".",
"$",
"value",
")",
";",
"}",
"}"
] |
Send all headers at once
|
[
"Send",
"all",
"headers",
"at",
"once"
] |
477e6a0f0b601008bf96db9767492d5b35637d0b
|
https://github.com/jk/RestServer/blob/477e6a0f0b601008bf96db9767492d5b35637d0b/src/JK/RestServer/HeaderManager.php#L117-L126
|
227,299
|
llvdl/slim-router-js
|
src/RouterJs.php
|
RouterJs.getRouterJavascriptResponse
|
public function getRouterJavascriptResponse()
{
$fh = fopen('php://temp', 'rw');
$stream = new Stream($fh);
$stream->write($this->getRouterJavascript());
return (new Response())
->withBody($stream)
->withHeader('Content-Type', 'application/javascript');
}
|
php
|
public function getRouterJavascriptResponse()
{
$fh = fopen('php://temp', 'rw');
$stream = new Stream($fh);
$stream->write($this->getRouterJavascript());
return (new Response())
->withBody($stream)
->withHeader('Content-Type', 'application/javascript');
}
|
[
"public",
"function",
"getRouterJavascriptResponse",
"(",
")",
"{",
"$",
"fh",
"=",
"fopen",
"(",
"'php://temp'",
",",
"'rw'",
")",
";",
"$",
"stream",
"=",
"new",
"Stream",
"(",
"$",
"fh",
")",
";",
"$",
"stream",
"->",
"write",
"(",
"$",
"this",
"->",
"getRouterJavascript",
"(",
")",
")",
";",
"return",
"(",
"new",
"Response",
"(",
")",
")",
"->",
"withBody",
"(",
"$",
"stream",
")",
"->",
"withHeader",
"(",
"'Content-Type'",
",",
"'application/javascript'",
")",
";",
"}"
] |
Returns a Response object for returning the router Javascript code as HTTP response.
|
[
"Returns",
"a",
"Response",
"object",
"for",
"returning",
"the",
"router",
"Javascript",
"code",
"as",
"HTTP",
"response",
"."
] |
d5b5d3407c197e0699d2a0d8c3dc57a52cab5ed7
|
https://github.com/llvdl/slim-router-js/blob/d5b5d3407c197e0699d2a0d8c3dc57a52cab5ed7/src/RouterJs.php#L82-L93
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.