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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
42,100 | drupal-code-builder/drupal-code-builder | Utility/CodeAnalysis/Method.php | Method.getDocblockParams | public function getDocblockParams() {
$docblock = $this->getDocComment();
$matches = [];
preg_match_all('/\* @param (?P<type>\S+) \$(?P<name>\w+)/', $docblock, $matches, PREG_SET_ORDER);
// TODO: complain if no match.
$param_data = [];
foreach ($matches as $match_set) {
$param_data[$match_set['name']] = $match_set['type'];
}
return $param_data;
} | php | public function getDocblockParams() {
$docblock = $this->getDocComment();
$matches = [];
preg_match_all('/\* @param (?P<type>\S+) \$(?P<name>\w+)/', $docblock, $matches, PREG_SET_ORDER);
// TODO: complain if no match.
$param_data = [];
foreach ($matches as $match_set) {
$param_data[$match_set['name']] = $match_set['type'];
}
return $param_data;
} | [
"public",
"function",
"getDocblockParams",
"(",
")",
"{",
"$",
"docblock",
"=",
"$",
"this",
"->",
"getDocComment",
"(",
")",
";",
"$",
"matches",
"=",
"[",
"]",
";",
"preg_match_all",
"(",
"'/\\* @param (?P<type>\\S+) \\$(?P<name>\\w+)/'",
",",
"$",
"docblock",... | Extract parameter types from the docblock.
@return
An array keyed by the parameter name (without the initial $), whose
values are the type in the docblock, such as 'mixed', 'int', or an
interface. (Although note that interface typehints which are also used
in the actual code are best detected with reflection). | [
"Extract",
"parameter",
"types",
"from",
"the",
"docblock",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Utility/CodeAnalysis/Method.php#L83-L97 |
42,101 | drupal-code-builder/drupal-code-builder | Generator/YMLFile.php | YMLFile.getYamlBody | protected function getYamlBody($yaml_data_array) {
$yaml_parser = new \Symfony\Component\Yaml\Yaml;
$yaml_parser_inline_switch_level = $this->component_data['yaml_inline_level'];
if ($this->component_data['line_break_between_blocks']) {
$body = [];
foreach (range(0, count($yaml_data_array) -1 ) as $index) {
$yaml_slice = array_slice($yaml_data_array, $index, 1);
// Each YAML piece comes with a terminal newline, so when these are
// joined there will be the desired blank line between each section.
$body[] = $yaml_parser->dump($yaml_slice, $yaml_parser_inline_switch_level, static::YAML_INDENT);
}
}
else {
$yaml = $yaml_parser->dump($yaml_data_array, $yaml_parser_inline_switch_level, static::YAML_INDENT);
$this->expandInlineItems($yaml_data_array, $yaml);
// Because the yaml is all built for us, this is just a singleton array.
$body = array($yaml);
}
//drush_print_r($yaml);
return $body;
} | php | protected function getYamlBody($yaml_data_array) {
$yaml_parser = new \Symfony\Component\Yaml\Yaml;
$yaml_parser_inline_switch_level = $this->component_data['yaml_inline_level'];
if ($this->component_data['line_break_between_blocks']) {
$body = [];
foreach (range(0, count($yaml_data_array) -1 ) as $index) {
$yaml_slice = array_slice($yaml_data_array, $index, 1);
// Each YAML piece comes with a terminal newline, so when these are
// joined there will be the desired blank line between each section.
$body[] = $yaml_parser->dump($yaml_slice, $yaml_parser_inline_switch_level, static::YAML_INDENT);
}
}
else {
$yaml = $yaml_parser->dump($yaml_data_array, $yaml_parser_inline_switch_level, static::YAML_INDENT);
$this->expandInlineItems($yaml_data_array, $yaml);
// Because the yaml is all built for us, this is just a singleton array.
$body = array($yaml);
}
//drush_print_r($yaml);
return $body;
} | [
"protected",
"function",
"getYamlBody",
"(",
"$",
"yaml_data_array",
")",
"{",
"$",
"yaml_parser",
"=",
"new",
"\\",
"Symfony",
"\\",
"Component",
"\\",
"Yaml",
"\\",
"Yaml",
";",
"$",
"yaml_parser_inline_switch_level",
"=",
"$",
"this",
"->",
"component_data",
... | Get the YAML body for the file.
@param $yaml_data_array
An array of data to convert to YAML.
@return
An array containing the YAML string. | [
"Get",
"the",
"YAML",
"body",
"for",
"the",
"file",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/YMLFile.php#L100-L127 |
42,102 | drupal-code-builder/drupal-code-builder | Generator/YMLFile.php | YMLFile.expandInlineItems | protected function expandInlineItems($yaml_data_array, &$yaml) {
if (empty($this->component_data['inline_levels_extra'])) {
return;
}
foreach ($this->component_data['inline_levels_extra'] as $extra_expansion_rule) {
// The rule address may use wildcards. Get a list of actual properties
// to expand.
$rule_address = $extra_expansion_rule['address'];
$properties_to_expand = [];
// Iterate recursively through the whole YAML data structure.
$iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($yaml_data_array), \RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $key => $value) {
$depth = $iterator->getDepth();
if ($depth != count($rule_address) - 1) {
// The current item's depth does not match the rule's address: skip.
// Note that the iterator's notion of depth is zero-based.
continue;
}
// Get the address of the iterator's current location.
// See https://stackoverflow.com/questions/7590662/walk-array-recursively-and-print-the-path-of-the-walk
$current_address = [];
for ($i = 0; $i <= $depth; $i++) {
$current_address[] = $iterator->getSubIterator($i)->key();
}
// Compare the current address with the rule address.
for ($i = 0; $i <= $depth; $i++) {
if ($rule_address[$i] == '*') {
// Wildcard matches anything: pass this level.
continue;
}
if ($rule_address[$i] != $current_address[$i]) {
// There is a mismatch: give up on this item in the iterator and
// move on to the next.
continue 2;
}
}
// If we are still here, all levels of the current address passed the
// comparison with the rule address: the address is valid.
$properties_to_expand[] = $current_address;
}
foreach ($properties_to_expand as $property) {
// Get the value for the property.
$value = NestedArray::getValue($yaml_data_array, $property);
// Create a YAML subarray that has the key for the value.
$key = end($property);
$yaml_data_sub_array = [
$key => $value,
];
$yaml_parser = new \Symfony\Component\Yaml\Yaml;
$original = $yaml_parser->dump($yaml_data_sub_array, 1, static::YAML_INDENT);
$replacement = $yaml_parser->dump($yaml_data_sub_array, 2, static::YAML_INDENT);
// We need to put the right indent at the front of all lines.
// The indent is one level less than the level of the address, which
// itself is one less than the count of the address array.
$indent = str_repeat(' ', static::YAML_INDENT * (count($property) - 2));
$original = $indent . $original;
$replacement = preg_replace('@^@m', $indent, $replacement);
// Replace the inlined original YAML text with the multi-line
// replacement.
// WARNING: this is a bit dicey, as we might be replacing multiple
// instances of this data, at ANY level!
// However, since the only use of this so far is for services.yml
// file tags, that's not a problem: YAGNI.
// A better way to do this -- but far more complicated -- might be to
// replace the data with a placeholder token before we generate the
// YAML, so we are sure we are replacing the right thing.
$yaml = str_replace($original, $replacement, $yaml);
}
}
} | php | protected function expandInlineItems($yaml_data_array, &$yaml) {
if (empty($this->component_data['inline_levels_extra'])) {
return;
}
foreach ($this->component_data['inline_levels_extra'] as $extra_expansion_rule) {
// The rule address may use wildcards. Get a list of actual properties
// to expand.
$rule_address = $extra_expansion_rule['address'];
$properties_to_expand = [];
// Iterate recursively through the whole YAML data structure.
$iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($yaml_data_array), \RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $key => $value) {
$depth = $iterator->getDepth();
if ($depth != count($rule_address) - 1) {
// The current item's depth does not match the rule's address: skip.
// Note that the iterator's notion of depth is zero-based.
continue;
}
// Get the address of the iterator's current location.
// See https://stackoverflow.com/questions/7590662/walk-array-recursively-and-print-the-path-of-the-walk
$current_address = [];
for ($i = 0; $i <= $depth; $i++) {
$current_address[] = $iterator->getSubIterator($i)->key();
}
// Compare the current address with the rule address.
for ($i = 0; $i <= $depth; $i++) {
if ($rule_address[$i] == '*') {
// Wildcard matches anything: pass this level.
continue;
}
if ($rule_address[$i] != $current_address[$i]) {
// There is a mismatch: give up on this item in the iterator and
// move on to the next.
continue 2;
}
}
// If we are still here, all levels of the current address passed the
// comparison with the rule address: the address is valid.
$properties_to_expand[] = $current_address;
}
foreach ($properties_to_expand as $property) {
// Get the value for the property.
$value = NestedArray::getValue($yaml_data_array, $property);
// Create a YAML subarray that has the key for the value.
$key = end($property);
$yaml_data_sub_array = [
$key => $value,
];
$yaml_parser = new \Symfony\Component\Yaml\Yaml;
$original = $yaml_parser->dump($yaml_data_sub_array, 1, static::YAML_INDENT);
$replacement = $yaml_parser->dump($yaml_data_sub_array, 2, static::YAML_INDENT);
// We need to put the right indent at the front of all lines.
// The indent is one level less than the level of the address, which
// itself is one less than the count of the address array.
$indent = str_repeat(' ', static::YAML_INDENT * (count($property) - 2));
$original = $indent . $original;
$replacement = preg_replace('@^@m', $indent, $replacement);
// Replace the inlined original YAML text with the multi-line
// replacement.
// WARNING: this is a bit dicey, as we might be replacing multiple
// instances of this data, at ANY level!
// However, since the only use of this so far is for services.yml
// file tags, that's not a problem: YAGNI.
// A better way to do this -- but far more complicated -- might be to
// replace the data with a placeholder token before we generate the
// YAML, so we are sure we are replacing the right thing.
$yaml = str_replace($original, $replacement, $yaml);
}
}
} | [
"protected",
"function",
"expandInlineItems",
"(",
"$",
"yaml_data_array",
",",
"&",
"$",
"yaml",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"component_data",
"[",
"'inline_levels_extra'",
"]",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
... | Change specified YAML properties from inlined to expanded.
We need this because some Drupal YAML files have variable levels of
inlining, and Symfony's YAML dumper does not support this, nor plan to:
see https://github.com/symfony/symfony/issues/19014#event-688175812.
For example, a services.yml file has 'arguments' and 'tags' at the same
level, but while 'arguments' is inlined, 'tags' is expanded, and inlined
one level lower:
@code
forum_manager:
class: Drupal\forum\ForumManager
arguments: ['@config.factory', '@entity.manager', '@database', '@string_translation', '@comment.manager']
tags:
- { name: backend_overridable }
@endcode
The properties to expand are specified in the 'inline_levels_extra'
component data. This is an array of rules, keyed by an arbitrary name,
where each rule is an array consisting of:
- 'address': An address array of the property or properties to expand.
This supports verbatim address pieces, and a '*' for a wildcard.
- 'level': NOT YET USED.
TODO: this is not currently run for YAML which puts line breaks between
blocks: there's no use case for this yet.
@param array $yaml_data_array
The original YAML data array.
@param string &$yaml
The generated YAML text. | [
"Change",
"specified",
"YAML",
"properties",
"from",
"inlined",
"to",
"expanded",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/YMLFile.php#L163-L243 |
42,103 | drupal-code-builder/drupal-code-builder | Task/ReportHookDataFolder.php | ReportHookDataFolder.lastUpdatedDate | public function lastUpdatedDate() {
$directory = $this->environment->getHooksDirectory();
$hooks_file = "$directory/hooks_processed.php";
if (file_exists($hooks_file)) {
$timestamp = filemtime($hooks_file);
return $timestamp;
}
} | php | public function lastUpdatedDate() {
$directory = $this->environment->getHooksDirectory();
$hooks_file = "$directory/hooks_processed.php";
if (file_exists($hooks_file)) {
$timestamp = filemtime($hooks_file);
return $timestamp;
}
} | [
"public",
"function",
"lastUpdatedDate",
"(",
")",
"{",
"$",
"directory",
"=",
"$",
"this",
"->",
"environment",
"->",
"getHooksDirectory",
"(",
")",
";",
"$",
"hooks_file",
"=",
"\"$directory/hooks_processed.php\"",
";",
"if",
"(",
"file_exists",
"(",
"$",
"h... | Get the timestamp of the last hook data upate.
@return
A unix timestamp, or NULL if the hooks have never been collected. | [
"Get",
"the",
"timestamp",
"of",
"the",
"last",
"hook",
"data",
"upate",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportHookDataFolder.php#L31-L38 |
42,104 | drupal-code-builder/drupal-code-builder | Task/ReportHookDataFolder.php | ReportHookDataFolder.listHookFiles | public function listHookFiles() {
$directory = $this->environment->getHooksDirectory();
$files = array();
// No need to verify $directory; our sanity check has taken care of it.
$dh = opendir($directory);
while (($file = readdir($dh)) !== FALSE) {
// Ignore files that don't make sense to include.
// System files and cruft.
// TODO: replace all the .foo with one of the arcane PHP string checking functions
if (in_array($file, array('.', '..', '.DS_Store', 'CVS', 'hooks_processed.php'))) {
continue;
}
// Our own processed files.
if (strpos($file, '_processed.php')) {
continue;
}
$files[] = $file;
}
closedir($dh);
return $files;
} | php | public function listHookFiles() {
$directory = $this->environment->getHooksDirectory();
$files = array();
// No need to verify $directory; our sanity check has taken care of it.
$dh = opendir($directory);
while (($file = readdir($dh)) !== FALSE) {
// Ignore files that don't make sense to include.
// System files and cruft.
// TODO: replace all the .foo with one of the arcane PHP string checking functions
if (in_array($file, array('.', '..', '.DS_Store', 'CVS', 'hooks_processed.php'))) {
continue;
}
// Our own processed files.
if (strpos($file, '_processed.php')) {
continue;
}
$files[] = $file;
}
closedir($dh);
return $files;
} | [
"public",
"function",
"listHookFiles",
"(",
")",
"{",
"$",
"directory",
"=",
"$",
"this",
"->",
"environment",
"->",
"getHooksDirectory",
"(",
")",
";",
"$",
"files",
"=",
"array",
"(",
")",
";",
"// No need to verify $directory; our sanity check has taken care of i... | Get a list of all collected hook api.php files.
@return
A flat array of filenames, relative to the hooks directory. If no files
are present, an empty array is returned. | [
"Get",
"a",
"list",
"of",
"all",
"collected",
"hook",
"api",
".",
"php",
"files",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportHookDataFolder.php#L47-L71 |
42,105 | drupal-code-builder/drupal-code-builder | Generator/Profile.php | Profile.componentDataDefinition | public static function componentDataDefinition() {
$component_data_definition = parent::componentDataDefinition();
$component_data_definition['base'] = [
'internal' => TRUE,
'default' => 'profile',
'process_default' => TRUE,
];
$component_data_definition['root_name'] = [
'label' => 'Profile machine name',
'default' => 'myprofile',
] + $component_data_definition['root_name'];
$component_data_definition += [
'readable_name' => array(
'label' => 'Profile readable name',
'default' => function($component_data) {
return ucfirst(str_replace('_', ' ', $component_data['root_name']));
},
'required' => FALSE,
),
'short_description' => array(
'label' => 'Profile .info file description',
'default' => 'TODO: Description of profile',
'required' => FALSE,
),
];
return $component_data_definition;
} | php | public static function componentDataDefinition() {
$component_data_definition = parent::componentDataDefinition();
$component_data_definition['base'] = [
'internal' => TRUE,
'default' => 'profile',
'process_default' => TRUE,
];
$component_data_definition['root_name'] = [
'label' => 'Profile machine name',
'default' => 'myprofile',
] + $component_data_definition['root_name'];
$component_data_definition += [
'readable_name' => array(
'label' => 'Profile readable name',
'default' => function($component_data) {
return ucfirst(str_replace('_', ' ', $component_data['root_name']));
},
'required' => FALSE,
),
'short_description' => array(
'label' => 'Profile .info file description',
'default' => 'TODO: Description of profile',
'required' => FALSE,
),
];
return $component_data_definition;
} | [
"public",
"static",
"function",
"componentDataDefinition",
"(",
")",
"{",
"$",
"component_data_definition",
"=",
"parent",
"::",
"componentDataDefinition",
"(",
")",
";",
"$",
"component_data_definition",
"[",
"'base'",
"]",
"=",
"[",
"'internal'",
"=>",
"TRUE",
"... | This can't be a class property due to use of closures.
@return
An array that defines the data this component needs to operate. This
includes:
- data that must be specified by the user
- data that may be specified by the user, but can be computed or take from
defaults
- data that should not be specified by the user, as it is computed from
other input. | [
"This",
"can",
"t",
"be",
"a",
"class",
"property",
"due",
"to",
"use",
"of",
"closures",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/Profile.php#L34-L63 |
42,106 | drupal-code-builder/drupal-code-builder | Task/Collect/FieldTypesCollector.php | FieldTypesCollector.collect | public function collect($job_list) {
$plugin_manager = \Drupal::service('plugin.manager.field.field_type');
$plugin_definitions = $plugin_manager->getDefinitions();
$field_types_data = [];
foreach ($plugin_definitions as $plugin_id => $plugin_definition) {
$field_types_data[$plugin_id] = [
'type' => $plugin_id,
// Labels and descriptions need to be stringified from
// TranslatableMarkup.
'label' => (string) $plugin_definition['label'],
// Some field types brokenly don't define a description.
'description' => (string) ( $plugin_definition['description'] ?? $plugin_definition['label'] ),
// Some of the weirder plugins don't have these.
'default_widget' => $plugin_definition['default_widget'] ?? '',
'default_formatter' => $plugin_definition['default_formatter'] ?? '',
];
}
// Filter for testing sample data collection.
if (!empty($this->environment->sample_data_write)) {
$field_types_data = array_intersect_key($field_types_data, $this->testingFieldTypes);
}
uasort($field_types_data, function($a, $b) {
return strcmp($a['label'], $b['label']);
});
return $field_types_data;
} | php | public function collect($job_list) {
$plugin_manager = \Drupal::service('plugin.manager.field.field_type');
$plugin_definitions = $plugin_manager->getDefinitions();
$field_types_data = [];
foreach ($plugin_definitions as $plugin_id => $plugin_definition) {
$field_types_data[$plugin_id] = [
'type' => $plugin_id,
// Labels and descriptions need to be stringified from
// TranslatableMarkup.
'label' => (string) $plugin_definition['label'],
// Some field types brokenly don't define a description.
'description' => (string) ( $plugin_definition['description'] ?? $plugin_definition['label'] ),
// Some of the weirder plugins don't have these.
'default_widget' => $plugin_definition['default_widget'] ?? '',
'default_formatter' => $plugin_definition['default_formatter'] ?? '',
];
}
// Filter for testing sample data collection.
if (!empty($this->environment->sample_data_write)) {
$field_types_data = array_intersect_key($field_types_data, $this->testingFieldTypes);
}
uasort($field_types_data, function($a, $b) {
return strcmp($a['label'], $b['label']);
});
return $field_types_data;
} | [
"public",
"function",
"collect",
"(",
"$",
"job_list",
")",
"{",
"$",
"plugin_manager",
"=",
"\\",
"Drupal",
"::",
"service",
"(",
"'plugin.manager.field.field_type'",
")",
";",
"$",
"plugin_definitions",
"=",
"$",
"plugin_manager",
"->",
"getDefinitions",
"(",
... | Gets definitions of field types.
@return array
An array whose keys are the field types, and whose values are arrays
containing:
- 'type': The field type, that is, the field type plugin ID.
- 'label': The field type label.
- 'description': The field type description.
- 'default_widget': The default widget plugin ID.
- 'default_formatter': The default formatter plugin ID. | [
"Gets",
"definitions",
"of",
"field",
"types",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Collect/FieldTypesCollector.php#L62-L92 |
42,107 | drupal-code-builder/drupal-code-builder | Task/Generate/ComponentClassHandler.php | ComponentClassHandler.getGenerator | public function getGenerator($component_type, $component_data) {
$class = $this->getGeneratorClass($component_type);
if (!class_exists($class)) {
throw new \DrupalCodeBuilder\Exception\InvalidInputException(strtr("Invalid component type !type.", array(
'!type' => htmlspecialchars($component_type, ENT_QUOTES, 'UTF-8'),
)));
}
$generator = new $class($component_data);
// Quick hack for the benefit of the Hooks generator.
$generator->classHandlerHelper = $this;
return $generator;
} | php | public function getGenerator($component_type, $component_data) {
$class = $this->getGeneratorClass($component_type);
if (!class_exists($class)) {
throw new \DrupalCodeBuilder\Exception\InvalidInputException(strtr("Invalid component type !type.", array(
'!type' => htmlspecialchars($component_type, ENT_QUOTES, 'UTF-8'),
)));
}
$generator = new $class($component_data);
// Quick hack for the benefit of the Hooks generator.
$generator->classHandlerHelper = $this;
return $generator;
} | [
"public",
"function",
"getGenerator",
"(",
"$",
"component_type",
",",
"$",
"component_data",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"getGeneratorClass",
"(",
"$",
"component_type",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",... | Generator factory.
@param $component_type
The type of the component. This is use to build the class name: see
getGeneratorClass().
@param $component_data
An array of data for the component. This is passed to the generator's
__construct().
@return
A generator object, with the component name and data set on it, as well
as a reference to this task handler.
@throws \DrupalCodeBuilder\Exception\InvalidInputException
Throws an exception if the given component type does not correspond to
a component class. | [
"Generator",
"factory",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Generate/ComponentClassHandler.php#L53-L68 |
42,108 | drupal-code-builder/drupal-code-builder | Task/Generate/ComponentClassHandler.php | ComponentClassHandler.getGeneratorClass | public function getGeneratorClass($type) {
$type = ucfirst($type);
if (!isset($this->classes[$type])) {
$version = \DrupalCodeBuilder\Factory::getEnvironment()->getCoreMajorVersion();
$class = 'DrupalCodeBuilder\\Generator\\' . $type . $version;
// If there is no version-specific class, use the base class.
if (!class_exists($class)) {
$class = 'DrupalCodeBuilder\\Generator\\' . $type;
}
$this->classes[$type] = $class;
}
return $this->classes[$type];
} | php | public function getGeneratorClass($type) {
$type = ucfirst($type);
if (!isset($this->classes[$type])) {
$version = \DrupalCodeBuilder\Factory::getEnvironment()->getCoreMajorVersion();
$class = 'DrupalCodeBuilder\\Generator\\' . $type . $version;
// If there is no version-specific class, use the base class.
if (!class_exists($class)) {
$class = 'DrupalCodeBuilder\\Generator\\' . $type;
}
$this->classes[$type] = $class;
}
return $this->classes[$type];
} | [
"public",
"function",
"getGeneratorClass",
"(",
"$",
"type",
")",
"{",
"$",
"type",
"=",
"ucfirst",
"(",
"$",
"type",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"classes",
"[",
"$",
"type",
"]",
")",
")",
"{",
"$",
"version",
"=",... | Helper function to get the desired Generator class.
@param $type
The type of the component. This is the name of the class, without the
version suffix. For classes in camel case, the string given here may be
all in lower case.
@return
A fully qualified class name for the type and, if it exists, version, e.g.
'DrupalCodeBuilder\Generator\Info6'. | [
"Helper",
"function",
"to",
"get",
"the",
"desired",
"Generator",
"class",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Generate/ComponentClassHandler.php#L82-L98 |
42,109 | IndraGunawan/api-rate-limit-bundle | EventListener/RateLimitListener.php | RateLimitListener.createRateLimitExceededException | protected function createRateLimitExceededException(Request $request)
{
$config = $this->exceptionConfig;
$class = $config['custom_exception'] ?? RateLimitExceededException::class;
$username = null;
if (null !== $token = $this->tokenStorage->getToken()) {
if (is_object($token->getUser())) {
$username = $token->getUsername();
}
}
return new $class($config['status_code'], $config['message'], $request->getClientIp(), $username);
} | php | protected function createRateLimitExceededException(Request $request)
{
$config = $this->exceptionConfig;
$class = $config['custom_exception'] ?? RateLimitExceededException::class;
$username = null;
if (null !== $token = $this->tokenStorage->getToken()) {
if (is_object($token->getUser())) {
$username = $token->getUsername();
}
}
return new $class($config['status_code'], $config['message'], $request->getClientIp(), $username);
} | [
"protected",
"function",
"createRateLimitExceededException",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"exceptionConfig",
";",
"$",
"class",
"=",
"$",
"config",
"[",
"'custom_exception'",
"]",
"??",
"RateLimitExceededExceptio... | Returns an RateLimitExceededException.
@param Request $request
@return RateLimitExceededException | [
"Returns",
"an",
"RateLimitExceededException",
"."
] | 1096ebfe1b181d6b6e38ccf58884ab871b41c47b | https://github.com/IndraGunawan/api-rate-limit-bundle/blob/1096ebfe1b181d6b6e38ccf58884ab871b41c47b/EventListener/RateLimitListener.php#L87-L100 |
42,110 | ckdarby/PHP-UptimeRobot | src/UptimeRobot/API.php | API.request | public function request($resource, $args = array())
{
$url = $this->buildUrl($resource, $args);
$curl = curl_init($url);
curl_setopt_array($curl, $this->options);
$this->contents = curl_exec($curl);
$this->setDebug($curl);
if (curl_errno($curl) > 0) {
throw new \Exception('There was an error while making the request');
}
$jsonDecodeContent = json_decode($this->contents, true);
if(is_null($jsonDecodeContent)) {
throw new \Exception('Unable to decode JSON response');
}
return $jsonDecodeContent;
} | php | public function request($resource, $args = array())
{
$url = $this->buildUrl($resource, $args);
$curl = curl_init($url);
curl_setopt_array($curl, $this->options);
$this->contents = curl_exec($curl);
$this->setDebug($curl);
if (curl_errno($curl) > 0) {
throw new \Exception('There was an error while making the request');
}
$jsonDecodeContent = json_decode($this->contents, true);
if(is_null($jsonDecodeContent)) {
throw new \Exception('Unable to decode JSON response');
}
return $jsonDecodeContent;
} | [
"public",
"function",
"request",
"(",
"$",
"resource",
",",
"$",
"args",
"=",
"array",
"(",
")",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"buildUrl",
"(",
"$",
"resource",
",",
"$",
"args",
")",
";",
"$",
"curl",
"=",
"curl_init",
"(",
"$",
... | Makes curl call to the url & returns output.
@param string $resource The resource of the api
@param array $args Array of options for the query query
@return array json_decoded contents
@throws \Exception If the curl request fails | [
"Makes",
"curl",
"call",
"to",
"the",
"url",
"&",
"returns",
"output",
"."
] | d90129522bd5daa4227a5390ef5a12ab78d76880 | https://github.com/ckdarby/PHP-UptimeRobot/blob/d90129522bd5daa4227a5390ef5a12ab78d76880/src/UptimeRobot/API.php#L55-L76 |
42,111 | ckdarby/PHP-UptimeRobot | src/UptimeRobot/API.php | API.getOptions | private function getOptions($options)
{
$conf = [
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_FOLLOWLOCATION => true
];
if (isset($options['timeout'])) {
$conf[CURLOPT_TIMEOUT_MS] = $options['timeout'] * 1000;
}
if (isset($options['connect_timeout'])) {
$conf[CURLOPT_CONNECTTIMEOUT_MS] = $options['connect_timeout'] * 1000;
}
return $conf;
} | php | private function getOptions($options)
{
$conf = [
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_FOLLOWLOCATION => true
];
if (isset($options['timeout'])) {
$conf[CURLOPT_TIMEOUT_MS] = $options['timeout'] * 1000;
}
if (isset($options['connect_timeout'])) {
$conf[CURLOPT_CONNECTTIMEOUT_MS] = $options['connect_timeout'] * 1000;
}
return $conf;
} | [
"private",
"function",
"getOptions",
"(",
"$",
"options",
")",
"{",
"$",
"conf",
"=",
"[",
"CURLOPT_HEADER",
"=>",
"false",
",",
"CURLOPT_RETURNTRANSFER",
"=>",
"true",
",",
"CURLOPT_SSL_VERIFYPEER",
"=>",
"false",
",",
"CURLOPT_FOLLOWLOCATION",
"=>",
"true",
"]... | Get options for curl.
@param $options
@return array | [
"Get",
"options",
"for",
"curl",
"."
] | d90129522bd5daa4227a5390ef5a12ab78d76880 | https://github.com/ckdarby/PHP-UptimeRobot/blob/d90129522bd5daa4227a5390ef5a12ab78d76880/src/UptimeRobot/API.php#L85-L102 |
42,112 | ckdarby/PHP-UptimeRobot | src/UptimeRobot/API.php | API.buildUrl | private function buildUrl($resource, $args)
{
//Merge args(apiKey, Format, noJsonCallback)
$args = array_merge($args, $this->args);
$query = http_build_query($args);
$url = $this->url;
$url .= $resource . '?' . $query;
return $url;
} | php | private function buildUrl($resource, $args)
{
//Merge args(apiKey, Format, noJsonCallback)
$args = array_merge($args, $this->args);
$query = http_build_query($args);
$url = $this->url;
$url .= $resource . '?' . $query;
return $url;
} | [
"private",
"function",
"buildUrl",
"(",
"$",
"resource",
",",
"$",
"args",
")",
"{",
"//Merge args(apiKey, Format, noJsonCallback)",
"$",
"args",
"=",
"array_merge",
"(",
"$",
"args",
",",
"$",
"this",
"->",
"args",
")",
";",
"$",
"query",
"=",
"http_build_q... | Builds the url for the curl request.
@param string $resource The resource of the api
@param array $args Array of options for the query query
@return string Finalized Url | [
"Builds",
"the",
"url",
"for",
"the",
"curl",
"request",
"."
] | d90129522bd5daa4227a5390ef5a12ab78d76880 | https://github.com/ckdarby/PHP-UptimeRobot/blob/d90129522bd5daa4227a5390ef5a12ab78d76880/src/UptimeRobot/API.php#L112-L122 |
42,113 | ckdarby/PHP-UptimeRobot | src/UptimeRobot/API.php | API.setDebug | private function setDebug($curl)
{
$this->debug = [
'errorNum' => curl_errno($curl),
'error' => curl_error($curl),
'info' => curl_getinfo($curl),
'raw' => $this->contents,
];
} | php | private function setDebug($curl)
{
$this->debug = [
'errorNum' => curl_errno($curl),
'error' => curl_error($curl),
'info' => curl_getinfo($curl),
'raw' => $this->contents,
];
} | [
"private",
"function",
"setDebug",
"(",
"$",
"curl",
")",
"{",
"$",
"this",
"->",
"debug",
"=",
"[",
"'errorNum'",
"=>",
"curl_errno",
"(",
"$",
"curl",
")",
",",
"'error'",
"=>",
"curl_error",
"(",
"$",
"curl",
")",
",",
"'info'",
"=>",
"curl_getinfo"... | Sets debug information from last curl.
@param resource $curl Curl handle | [
"Sets",
"debug",
"information",
"from",
"last",
"curl",
"."
] | d90129522bd5daa4227a5390ef5a12ab78d76880 | https://github.com/ckdarby/PHP-UptimeRobot/blob/d90129522bd5daa4227a5390ef5a12ab78d76880/src/UptimeRobot/API.php#L129-L137 |
42,114 | IAkumaI/SphinxsearchBundle | Search/Sphinxsearch.php | Sphinxsearch.addQuery | public function addQuery($query, array $indexes)
{
if (empty($indexes)) {
throw new EmptyIndexException('Try to search with empty indexes');
}
$this->sphinx->addQuery($query, implode(' ', $indexes));
} | php | public function addQuery($query, array $indexes)
{
if (empty($indexes)) {
throw new EmptyIndexException('Try to search with empty indexes');
}
$this->sphinx->addQuery($query, implode(' ', $indexes));
} | [
"public",
"function",
"addQuery",
"(",
"$",
"query",
",",
"array",
"$",
"indexes",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"indexes",
")",
")",
"{",
"throw",
"new",
"EmptyIndexException",
"(",
"'Try to search with empty indexes'",
")",
";",
"}",
"$",
"this... | Adds a query to a multi-query batch
@param string $query Search query
@param array $indexes Index list to perform the search
@throws EmptyIndexException If $indexes is empty | [
"Adds",
"a",
"query",
"to",
"a",
"multi",
"-",
"query",
"batch"
] | cf622949f64a7d10b5e5abc9e4d95f280095e43d | https://github.com/IAkumaI/SphinxsearchBundle/blob/cf622949f64a7d10b5e5abc9e4d95f280095e43d/Search/Sphinxsearch.php#L213-L220 |
42,115 | IAkumaI/SphinxsearchBundle | Doctrine/Bridge.php | Bridge.getEntityManager | public function getEntityManager()
{
if ($this->em === null) {
$this->setEntityManager($this->container->get('doctrine')->getManager($this->emName));
}
return $this->em;
} | php | public function getEntityManager()
{
if ($this->em === null) {
$this->setEntityManager($this->container->get('doctrine')->getManager($this->emName));
}
return $this->em;
} | [
"public",
"function",
"getEntityManager",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"em",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"setEntityManager",
"(",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'doctrine'",
")",
"->",
"getManager",
"... | Get an EntityManager
@return EntityManager | [
"Get",
"an",
"EntityManager"
] | cf622949f64a7d10b5e5abc9e4d95f280095e43d | https://github.com/IAkumaI/SphinxsearchBundle/blob/cf622949f64a7d10b5e5abc9e4d95f280095e43d/Doctrine/Bridge.php#L58-L65 |
42,116 | IAkumaI/SphinxsearchBundle | Doctrine/Bridge.php | Bridge.setEntityManager | public function setEntityManager(EntityManager $em)
{
if ($this->em !== null) {
throw new \LogicException('Entity manager can only be set before any results are fetched');
}
$this->em = $em;
} | php | public function setEntityManager(EntityManager $em)
{
if ($this->em !== null) {
throw new \LogicException('Entity manager can only be set before any results are fetched');
}
$this->em = $em;
} | [
"public",
"function",
"setEntityManager",
"(",
"EntityManager",
"$",
"em",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"em",
"!==",
"null",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Entity manager can only be set before any results are fetched'",
")",
"... | Set an EntityManager
@param EntityManager $em
@throws LogicException If entity manager already set | [
"Set",
"an",
"EntityManager"
] | cf622949f64a7d10b5e5abc9e4d95f280095e43d | https://github.com/IAkumaI/SphinxsearchBundle/blob/cf622949f64a7d10b5e5abc9e4d95f280095e43d/Doctrine/Bridge.php#L74-L81 |
42,117 | Shipu/laratie | src/Support/Stub.php | Stub.save | public function save($path, $filename)
{
if (!file_exists($path)) {
$this->makeDirectory($path);
}
return file_put_contents($path . '/' . $filename, $this->getContents());
} | php | public function save($path, $filename)
{
if (!file_exists($path)) {
$this->makeDirectory($path);
}
return file_put_contents($path . '/' . $filename, $this->getContents());
} | [
"public",
"function",
"save",
"(",
"$",
"path",
",",
"$",
"filename",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"this",
"->",
"makeDirectory",
"(",
"$",
"path",
")",
";",
"}",
"return",
"file_put_contents",
"(",
... | Save stub to specific path.
@param string $path
@param string $filename
@return bool | [
"Save",
"stub",
"to",
"specific",
"path",
"."
] | 45a73521467ab18a9bb56b53a287cff6f5a0b63a | https://github.com/Shipu/laratie/blob/45a73521467ab18a9bb56b53a287cff6f5a0b63a/src/Support/Stub.php#L70-L77 |
42,118 | Shipu/laratie | src/Consoles/BaseCommand.php | BaseCommand.requiredTaskAndInputs | protected function requiredTaskAndInputs()
{
$this->vendor = $this->setVendor();
$this->package = $this->setPackage();
if (blank($this->vendor)) {
$this->vendor = !blank($this->config->get('tie.vendor')) ? $this->config->get('tie.vendor') : snake_case(strtolower($this->ask('Vendor Name?')));
} else {
$vendor = explode('/', $this->vendor);
if (isset($vendor[1])) {
$this->package = $vendor[1];
$this->vendor = $vendor[0];
}
}
if (blank($this->package)) {
$this->package = strtolower($this->ask('Your Package Name?'));
}
$this->package = $this->package;
$this->makeBaseDirectory();
$this->configureNamespace();
} | php | protected function requiredTaskAndInputs()
{
$this->vendor = $this->setVendor();
$this->package = $this->setPackage();
if (blank($this->vendor)) {
$this->vendor = !blank($this->config->get('tie.vendor')) ? $this->config->get('tie.vendor') : snake_case(strtolower($this->ask('Vendor Name?')));
} else {
$vendor = explode('/', $this->vendor);
if (isset($vendor[1])) {
$this->package = $vendor[1];
$this->vendor = $vendor[0];
}
}
if (blank($this->package)) {
$this->package = strtolower($this->ask('Your Package Name?'));
}
$this->package = $this->package;
$this->makeBaseDirectory();
$this->configureNamespace();
} | [
"protected",
"function",
"requiredTaskAndInputs",
"(",
")",
"{",
"$",
"this",
"->",
"vendor",
"=",
"$",
"this",
"->",
"setVendor",
"(",
")",
";",
"$",
"this",
"->",
"package",
"=",
"$",
"this",
"->",
"setPackage",
"(",
")",
";",
"if",
"(",
"blank",
"... | Modify or Getting inputs | [
"Modify",
"or",
"Getting",
"inputs"
] | 45a73521467ab18a9bb56b53a287cff6f5a0b63a | https://github.com/Shipu/laratie/blob/45a73521467ab18a9bb56b53a287cff6f5a0b63a/src/Consoles/BaseCommand.php#L87-L109 |
42,119 | Shipu/laratie | src/Consoles/BaseCommand.php | BaseCommand.makeBaseDirectory | public function makeBaseDirectory()
{
$this->path = $this->config->get('tie.root') . '/' . $this->vendor . '/' . $this->package;
$this->makeDir($this->path);
} | php | public function makeBaseDirectory()
{
$this->path = $this->config->get('tie.root') . '/' . $this->vendor . '/' . $this->package;
$this->makeDir($this->path);
} | [
"public",
"function",
"makeBaseDirectory",
"(",
")",
"{",
"$",
"this",
"->",
"path",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'tie.root'",
")",
".",
"'/'",
".",
"$",
"this",
"->",
"vendor",
".",
"'/'",
".",
"$",
"this",
"->",
"package",
... | Make package development base directory | [
"Make",
"package",
"development",
"base",
"directory"
] | 45a73521467ab18a9bb56b53a287cff6f5a0b63a | https://github.com/Shipu/laratie/blob/45a73521467ab18a9bb56b53a287cff6f5a0b63a/src/Consoles/BaseCommand.php#L118-L123 |
42,120 | Shipu/laratie | src/Consoles/BaseCommand.php | BaseCommand.configureNamespace | public function configureNamespace()
{
$this->namespace = (!blank($this->config->get('tie.rootNamespace')) ? $this->config->get('tie.rootNamespace') : studly_case($this->vendor)) . '\\' . studly_case($this->package) . '\\';
} | php | public function configureNamespace()
{
$this->namespace = (!blank($this->config->get('tie.rootNamespace')) ? $this->config->get('tie.rootNamespace') : studly_case($this->vendor)) . '\\' . studly_case($this->package) . '\\';
} | [
"public",
"function",
"configureNamespace",
"(",
")",
"{",
"$",
"this",
"->",
"namespace",
"=",
"(",
"!",
"blank",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'tie.rootNamespace'",
")",
")",
"?",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
... | Making package namespace | [
"Making",
"package",
"namespace"
] | 45a73521467ab18a9bb56b53a287cff6f5a0b63a | https://github.com/Shipu/laratie/blob/45a73521467ab18a9bb56b53a287cff6f5a0b63a/src/Consoles/BaseCommand.php#L142-L145 |
42,121 | Shipu/laratie | src/Consoles/BaseCommand.php | BaseCommand.generateStubFile | public function generateStubFile($location, $fileFullName, $configuration)
{
$fileName = str_replace([ 'VENDOR_NAME', 'VENDOR_NAME_LOWER', 'PACKAGE_NAME', 'PACKAGE_NAME_LOWER' ], [
studly_case($this->vendor),
strtolower($this->vendor),
studly_case($this->package),
strtolower($this->package),
], $this->filesystem->name($fileFullName));
$fileExtension = $this->filesystem->extension($fileFullName);
if (blank($fileExtension)) {
$fileExtension = data_get($configuration, 'extension', 'php');
}
$suffix = data_get($configuration, 'suffix', '');
$prefix = data_get($configuration, 'prefix', '');
$namespace = data_get($configuration, 'namespace', '');
$fileName = $this->fileNameCaseConvention($prefix . $fileName . $suffix, $configuration);
$this->makeDir($location);
Stub::create(
$this->findingStub($this->stubKey),
$this->replaceStubString($fileName, $namespace)
)->save($location, $fileName . '.' . $fileExtension);
} | php | public function generateStubFile($location, $fileFullName, $configuration)
{
$fileName = str_replace([ 'VENDOR_NAME', 'VENDOR_NAME_LOWER', 'PACKAGE_NAME', 'PACKAGE_NAME_LOWER' ], [
studly_case($this->vendor),
strtolower($this->vendor),
studly_case($this->package),
strtolower($this->package),
], $this->filesystem->name($fileFullName));
$fileExtension = $this->filesystem->extension($fileFullName);
if (blank($fileExtension)) {
$fileExtension = data_get($configuration, 'extension', 'php');
}
$suffix = data_get($configuration, 'suffix', '');
$prefix = data_get($configuration, 'prefix', '');
$namespace = data_get($configuration, 'namespace', '');
$fileName = $this->fileNameCaseConvention($prefix . $fileName . $suffix, $configuration);
$this->makeDir($location);
Stub::create(
$this->findingStub($this->stubKey),
$this->replaceStubString($fileName, $namespace)
)->save($location, $fileName . '.' . $fileExtension);
} | [
"public",
"function",
"generateStubFile",
"(",
"$",
"location",
",",
"$",
"fileFullName",
",",
"$",
"configuration",
")",
"{",
"$",
"fileName",
"=",
"str_replace",
"(",
"[",
"'VENDOR_NAME'",
",",
"'VENDOR_NAME_LOWER'",
",",
"'PACKAGE_NAME'",
",",
"'PACKAGE_NAME_LO... | Generate stub file and save specific location
@param $location
@param $fileFullName
@param $configuration | [
"Generate",
"stub",
"file",
"and",
"save",
"specific",
"location"
] | 45a73521467ab18a9bb56b53a287cff6f5a0b63a | https://github.com/Shipu/laratie/blob/45a73521467ab18a9bb56b53a287cff6f5a0b63a/src/Consoles/BaseCommand.php#L156-L180 |
42,122 | Shipu/laratie | src/Consoles/BaseCommand.php | BaseCommand.fileNameCaseConvention | public function fileNameCaseConvention($name, $case = 'studly')
{
if (is_array($case)) {
$case = data_get($case, 'case', 'studly');
}
switch ($case) {
case 'studly':
return studly_case($name);
case 'lower':
return strtolower($name);
case 'upper':
return strtoupper($name);
case 'snake':
return snake_case($name);
case 'title':
return title_case($name);
case 'camel':
return camel_case($name);
case 'kebab':
return kebab_case($name);
}
return $name;
} | php | public function fileNameCaseConvention($name, $case = 'studly')
{
if (is_array($case)) {
$case = data_get($case, 'case', 'studly');
}
switch ($case) {
case 'studly':
return studly_case($name);
case 'lower':
return strtolower($name);
case 'upper':
return strtoupper($name);
case 'snake':
return snake_case($name);
case 'title':
return title_case($name);
case 'camel':
return camel_case($name);
case 'kebab':
return kebab_case($name);
}
return $name;
} | [
"public",
"function",
"fileNameCaseConvention",
"(",
"$",
"name",
",",
"$",
"case",
"=",
"'studly'",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"case",
")",
")",
"{",
"$",
"case",
"=",
"data_get",
"(",
"$",
"case",
",",
"'case'",
",",
"'studly'",
")"... | File name case convention
@param $name
@param string $case
@return string | [
"File",
"name",
"case",
"convention"
] | 45a73521467ab18a9bb56b53a287cff6f5a0b63a | https://github.com/Shipu/laratie/blob/45a73521467ab18a9bb56b53a287cff6f5a0b63a/src/Consoles/BaseCommand.php#L189-L213 |
42,123 | Shipu/laratie | src/Consoles/BaseCommand.php | BaseCommand.findingStub | public function findingStub($stubName)
{
$stubRoots = $this->config->get('tie.stubs.path');
foreach ($stubRoots as $stubRoot) {
$stub = $stubRoot . '/' . $stubName . '.stub';
if ($this->filesystem->exists($stub)) {
return $stub;
}
}
return '';
} | php | public function findingStub($stubName)
{
$stubRoots = $this->config->get('tie.stubs.path');
foreach ($stubRoots as $stubRoot) {
$stub = $stubRoot . '/' . $stubName . '.stub';
if ($this->filesystem->exists($stub)) {
return $stub;
}
}
return '';
} | [
"public",
"function",
"findingStub",
"(",
"$",
"stubName",
")",
"{",
"$",
"stubRoots",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'tie.stubs.path'",
")",
";",
"foreach",
"(",
"$",
"stubRoots",
"as",
"$",
"stubRoot",
")",
"{",
"$",
"stub",
"="... | Finding multi location stub
@param $stubName
@return string | [
"Finding",
"multi",
"location",
"stub"
] | 45a73521467ab18a9bb56b53a287cff6f5a0b63a | https://github.com/Shipu/laratie/blob/45a73521467ab18a9bb56b53a287cff6f5a0b63a/src/Consoles/BaseCommand.php#L221-L232 |
42,124 | Shipu/laratie | src/Consoles/BaseCommand.php | BaseCommand.replaceStubString | protected function replaceStubString($className, $namespace)
{
return array_merge([
'VENDOR_NAME_LOWER' => strtolower($this->vendor),
'VENDOR_NAME' => studly_case($this->vendor),
'PACKAGE_NAME_LOWER' => strtolower($this->package),
'PACKAGE_NAME' => studly_case($this->package),
'DummyClass' => studly_case($className),
'DummyTarget' => strtolower($className),
'DummyNamespace' => $this->namespace . $namespace,
'DummyRootNamespace' => $this->laravel->getNamespace(),
], $this->config->get('tie.stubs.replace'));
} | php | protected function replaceStubString($className, $namespace)
{
return array_merge([
'VENDOR_NAME_LOWER' => strtolower($this->vendor),
'VENDOR_NAME' => studly_case($this->vendor),
'PACKAGE_NAME_LOWER' => strtolower($this->package),
'PACKAGE_NAME' => studly_case($this->package),
'DummyClass' => studly_case($className),
'DummyTarget' => strtolower($className),
'DummyNamespace' => $this->namespace . $namespace,
'DummyRootNamespace' => $this->laravel->getNamespace(),
], $this->config->get('tie.stubs.replace'));
} | [
"protected",
"function",
"replaceStubString",
"(",
"$",
"className",
",",
"$",
"namespace",
")",
"{",
"return",
"array_merge",
"(",
"[",
"'VENDOR_NAME_LOWER'",
"=>",
"strtolower",
"(",
"$",
"this",
"->",
"vendor",
")",
",",
"'VENDOR_NAME'",
"=>",
"studly_case",
... | Replace dummy name to real name
@param $className
@param $namespace
@return array | [
"Replace",
"dummy",
"name",
"to",
"real",
"name"
] | 45a73521467ab18a9bb56b53a287cff6f5a0b63a | https://github.com/Shipu/laratie/blob/45a73521467ab18a9bb56b53a287cff6f5a0b63a/src/Consoles/BaseCommand.php#L241-L253 |
42,125 | Shipu/laratie | src/Consoles/BaseCommand.php | BaseCommand.addingNamespaceInComposer | public function addingNamespaceInComposer($namespace, $path, $output = 'composer.json')
{
$file = base_path('composer.json');
$data = json_decode($this->filesystem->get($file), true);
$rootStub = $this->config->get('tie.stubs.root');
if(is_array($rootStub)) {
$rootStub = data_get($this->config->get($rootStub), 'path', '');
}
$path = str_replace(base_path().'/', '', $path) . '/' . $rootStub;
$data["autoload"]["psr-4"] = array_merge($data["autoload"]["psr-4"], [ $namespace => $path ]);
$this->filesystem->put(base_path($output), json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
} | php | public function addingNamespaceInComposer($namespace, $path, $output = 'composer.json')
{
$file = base_path('composer.json');
$data = json_decode($this->filesystem->get($file), true);
$rootStub = $this->config->get('tie.stubs.root');
if(is_array($rootStub)) {
$rootStub = data_get($this->config->get($rootStub), 'path', '');
}
$path = str_replace(base_path().'/', '', $path) . '/' . $rootStub;
$data["autoload"]["psr-4"] = array_merge($data["autoload"]["psr-4"], [ $namespace => $path ]);
$this->filesystem->put(base_path($output), json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
} | [
"public",
"function",
"addingNamespaceInComposer",
"(",
"$",
"namespace",
",",
"$",
"path",
",",
"$",
"output",
"=",
"'composer.json'",
")",
"{",
"$",
"file",
"=",
"base_path",
"(",
"'composer.json'",
")",
";",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"t... | Package namespace adding in composer
@param $namespace
@param $path
@param string $output
@internal param $key | [
"Package",
"namespace",
"adding",
"in",
"composer"
] | 45a73521467ab18a9bb56b53a287cff6f5a0b63a | https://github.com/Shipu/laratie/blob/45a73521467ab18a9bb56b53a287cff6f5a0b63a/src/Consoles/BaseCommand.php#L263-L277 |
42,126 | Shipu/laratie | src/Consoles/TieResourceCommand.php | TieResourceCommand.createStubs | public function createStubs()
{
foreach ($this->options() as $stubKey => $fileName) {
if(!blank($fileName) && $fileName) {
$this->resourceName = $fileName;
$this->stubKey = $stubKey;
if($stubKey == 'key') {
$this->stubKey = $fileName;
$this->resourceName = strtolower($this->ask('Enter your file name'));
}
$configuration = $this->config->get('tie.stubs.structure.' . $this->stubKey);
$this->createStubFiles($configuration);
}
}
} | php | public function createStubs()
{
foreach ($this->options() as $stubKey => $fileName) {
if(!blank($fileName) && $fileName) {
$this->resourceName = $fileName;
$this->stubKey = $stubKey;
if($stubKey == 'key') {
$this->stubKey = $fileName;
$this->resourceName = strtolower($this->ask('Enter your file name'));
}
$configuration = $this->config->get('tie.stubs.structure.' . $this->stubKey);
$this->createStubFiles($configuration);
}
}
} | [
"public",
"function",
"createStubs",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"options",
"(",
")",
"as",
"$",
"stubKey",
"=>",
"$",
"fileName",
")",
"{",
"if",
"(",
"!",
"blank",
"(",
"$",
"fileName",
")",
"&&",
"$",
"fileName",
")",
"{",
... | Eligible stub config | [
"Eligible",
"stub",
"config"
] | 45a73521467ab18a9bb56b53a287cff6f5a0b63a | https://github.com/Shipu/laratie/blob/45a73521467ab18a9bb56b53a287cff6f5a0b63a/src/Consoles/TieResourceCommand.php#L82-L96 |
42,127 | Shipu/laratie | src/Consoles/TieResourceCommand.php | TieResourceCommand.createStubFiles | public function createStubFiles($configuration)
{
$stubPathLocation = $this->path . '/' . data_get($configuration, 'path', $configuration);
$this->generateStubFile($stubPathLocation, $this->resourceName, $configuration);
$this->comment("Successfully Create ".$this->resourceName." Resource");
$this->comment("Path Location ".$stubPathLocation);
$this->output->writeln('');
} | php | public function createStubFiles($configuration)
{
$stubPathLocation = $this->path . '/' . data_get($configuration, 'path', $configuration);
$this->generateStubFile($stubPathLocation, $this->resourceName, $configuration);
$this->comment("Successfully Create ".$this->resourceName." Resource");
$this->comment("Path Location ".$stubPathLocation);
$this->output->writeln('');
} | [
"public",
"function",
"createStubFiles",
"(",
"$",
"configuration",
")",
"{",
"$",
"stubPathLocation",
"=",
"$",
"this",
"->",
"path",
".",
"'/'",
".",
"data_get",
"(",
"$",
"configuration",
",",
"'path'",
",",
"$",
"configuration",
")",
";",
"$",
"this",
... | Create Stub File
@param $configuration | [
"Create",
"Stub",
"File"
] | 45a73521467ab18a9bb56b53a287cff6f5a0b63a | https://github.com/Shipu/laratie/blob/45a73521467ab18a9bb56b53a287cff6f5a0b63a/src/Consoles/TieResourceCommand.php#L103-L110 |
42,128 | Shipu/laratie | src/Consoles/TieCommand.php | TieCommand.makeDefaultPackageStructure | public function makeDefaultPackageStructure()
{
$default = $this->config->get('tie.stubs.default');
if (!blank($default)) {
foreach ($default as $stubKey) {
$this->stubKey = $stubKey;
$configuration = $this->config->get('tie.stubs.structure.' . $stubKey);
if (is_array($configuration)) {
$this->createStubFiles($configuration);
} else {
$this->makeDir($this->path . '/' . $configuration);
}
}
}
} | php | public function makeDefaultPackageStructure()
{
$default = $this->config->get('tie.stubs.default');
if (!blank($default)) {
foreach ($default as $stubKey) {
$this->stubKey = $stubKey;
$configuration = $this->config->get('tie.stubs.structure.' . $stubKey);
if (is_array($configuration)) {
$this->createStubFiles($configuration);
} else {
$this->makeDir($this->path . '/' . $configuration);
}
}
}
} | [
"public",
"function",
"makeDefaultPackageStructure",
"(",
")",
"{",
"$",
"default",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'tie.stubs.default'",
")",
";",
"if",
"(",
"!",
"blank",
"(",
"$",
"default",
")",
")",
"{",
"foreach",
"(",
"$",
"... | Default configuration package structure | [
"Default",
"configuration",
"package",
"structure"
] | 45a73521467ab18a9bb56b53a287cff6f5a0b63a | https://github.com/Shipu/laratie/blob/45a73521467ab18a9bb56b53a287cff6f5a0b63a/src/Consoles/TieCommand.php#L63-L77 |
42,129 | Shipu/laratie | src/Consoles/TieCommand.php | TieCommand.createStubFiles | public function createStubFiles($configuration)
{
$stubPathLocation = $this->path . '/' . data_get($configuration, 'path', '');
if (isset($configuration['files'])) {
foreach ($configuration['files'] as $file) {
$this->generateStubFile($stubPathLocation, $file, $configuration);
}
}
} | php | public function createStubFiles($configuration)
{
$stubPathLocation = $this->path . '/' . data_get($configuration, 'path', '');
if (isset($configuration['files'])) {
foreach ($configuration['files'] as $file) {
$this->generateStubFile($stubPathLocation, $file, $configuration);
}
}
} | [
"public",
"function",
"createStubFiles",
"(",
"$",
"configuration",
")",
"{",
"$",
"stubPathLocation",
"=",
"$",
"this",
"->",
"path",
".",
"'/'",
".",
"data_get",
"(",
"$",
"configuration",
",",
"'path'",
",",
"''",
")",
";",
"if",
"(",
"isset",
"(",
... | Create default configuration folder and files
@param $configuration | [
"Create",
"default",
"configuration",
"folder",
"and",
"files"
] | 45a73521467ab18a9bb56b53a287cff6f5a0b63a | https://github.com/Shipu/laratie/blob/45a73521467ab18a9bb56b53a287cff6f5a0b63a/src/Consoles/TieCommand.php#L84-L92 |
42,130 | Shipu/laratie | src/Consoles/TieCommand.php | TieCommand.endingTask | public function endingTask()
{
$this->alert("Successfully Create ".$this->vendor.'/'.$this->package." Package");
$this->comment(str_repeat('*', 65));
$this->comment(' Package: '.$this->package);
$this->output->writeln('');
$this->line(' Namespace: '.htmlentities($this->namespace));
$this->output->writeln('');
$this->comment(' Path Location: '.$this->path);
$this->comment(str_repeat('*', 65));
$this->output->writeln('');
$this->alert("Run: composer dump-autoload");
} | php | public function endingTask()
{
$this->alert("Successfully Create ".$this->vendor.'/'.$this->package." Package");
$this->comment(str_repeat('*', 65));
$this->comment(' Package: '.$this->package);
$this->output->writeln('');
$this->line(' Namespace: '.htmlentities($this->namespace));
$this->output->writeln('');
$this->comment(' Path Location: '.$this->path);
$this->comment(str_repeat('*', 65));
$this->output->writeln('');
$this->alert("Run: composer dump-autoload");
} | [
"public",
"function",
"endingTask",
"(",
")",
"{",
"$",
"this",
"->",
"alert",
"(",
"\"Successfully Create \"",
".",
"$",
"this",
"->",
"vendor",
".",
"'/'",
".",
"$",
"this",
"->",
"package",
".",
"\" Package\"",
")",
";",
"$",
"this",
"->",
"comment",
... | After successfully creating task | [
"After",
"successfully",
"creating",
"task"
] | 45a73521467ab18a9bb56b53a287cff6f5a0b63a | https://github.com/Shipu/laratie/blob/45a73521467ab18a9bb56b53a287cff6f5a0b63a/src/Consoles/TieCommand.php#L97-L109 |
42,131 | EmanueleMinotto/PlaceholdItProvider | PlaceholdItProvider.php | PlaceholdItProvider.imageUrl | public static function imageUrl($size, $format = 'gif', array $colors = [], $text = null)
{
// $colors should be 100 or 100x100
// but can be ['height' => 100, 'width' => 100]
// or ['w' => 100, 'h' => 100]
if (is_array($size)) {
ksort($size);
$size = implode('x', $size);
}
$base = 'http://placehold.it/'.$size.'.'.trim($format, '.');
// $colors should be ['background', 'text']
// but can be ['text' => '000', 'background' => 'fff']
// or ['txt' => '000', 'bg' => 'fff']
// or ['foreground' => '000', 'background' => 'fff']
// or ['fg' => '000', 'bg' => 'fff']
ksort($colors);
if (2 === count($colors)) {
$base .= '/'.implode('/', $colors);
}
if ($text) {
$base .= '?'.http_build_query([
'text' => $text,
]);
}
return $base;
} | php | public static function imageUrl($size, $format = 'gif', array $colors = [], $text = null)
{
// $colors should be 100 or 100x100
// but can be ['height' => 100, 'width' => 100]
// or ['w' => 100, 'h' => 100]
if (is_array($size)) {
ksort($size);
$size = implode('x', $size);
}
$base = 'http://placehold.it/'.$size.'.'.trim($format, '.');
// $colors should be ['background', 'text']
// but can be ['text' => '000', 'background' => 'fff']
// or ['txt' => '000', 'bg' => 'fff']
// or ['foreground' => '000', 'background' => 'fff']
// or ['fg' => '000', 'bg' => 'fff']
ksort($colors);
if (2 === count($colors)) {
$base .= '/'.implode('/', $colors);
}
if ($text) {
$base .= '?'.http_build_query([
'text' => $text,
]);
}
return $base;
} | [
"public",
"static",
"function",
"imageUrl",
"(",
"$",
"size",
",",
"$",
"format",
"=",
"'gif'",
",",
"array",
"$",
"colors",
"=",
"[",
"]",
",",
"$",
"text",
"=",
"null",
")",
"{",
"// $colors should be 100 or 100x100",
"// but can be ['height' => 100, 'width' =... | placehold.it image URL.
@param int|string|array $size Height is optional, if no height is specified the image will be a square.
@param string $format Adding an image file extension will render the image in the proper format.
@param array $colors An array containing background color and foreground color.
@param string $text Custom text can be entered using a query string at the very end of the url.
@return string | [
"placehold",
".",
"it",
"image",
"URL",
"."
] | 0d5b70ad56f26735c8caab83529befb8250841fa | https://github.com/EmanueleMinotto/PlaceholdItProvider/blob/0d5b70ad56f26735c8caab83529befb8250841fa/PlaceholdItProvider.php#L26-L56 |
42,132 | noam148/yii2-image-resize | ImageResize.php | ImageResize.getUrl | public function getUrl($filePath, $width, $height, $mode = "outbound", $quality = null, $fileName = null) {
//get original file
$normalizePath = FileHelper::normalizePath(Yii::getAlias($filePath));
//get cache url
$filesUrls = [];
foreach ($this->cachePath as $cachePath)
{
$cacheUrl = Yii::getAlias($cachePath);
//generate file
$resizedFilePath = self::generateImage($normalizePath, $width, $height, $mode, $quality, $fileName);
//get resized file
$normalizeResizedFilePath = FileHelper::normalizePath($resizedFilePath);
$resizedFileName = pathinfo($normalizeResizedFilePath, PATHINFO_BASENAME);
//get url
$sFileUrl = Url::to('@web/' . $cacheUrl . '/' . substr($resizedFileName, 0, 2) . '/' . $resizedFileName, $this->absoluteUrl);
//return path
$filesUrls[] = $sFileUrl;
}
return $filesUrls[0];
} | php | public function getUrl($filePath, $width, $height, $mode = "outbound", $quality = null, $fileName = null) {
//get original file
$normalizePath = FileHelper::normalizePath(Yii::getAlias($filePath));
//get cache url
$filesUrls = [];
foreach ($this->cachePath as $cachePath)
{
$cacheUrl = Yii::getAlias($cachePath);
//generate file
$resizedFilePath = self::generateImage($normalizePath, $width, $height, $mode, $quality, $fileName);
//get resized file
$normalizeResizedFilePath = FileHelper::normalizePath($resizedFilePath);
$resizedFileName = pathinfo($normalizeResizedFilePath, PATHINFO_BASENAME);
//get url
$sFileUrl = Url::to('@web/' . $cacheUrl . '/' . substr($resizedFileName, 0, 2) . '/' . $resizedFileName, $this->absoluteUrl);
//return path
$filesUrls[] = $sFileUrl;
}
return $filesUrls[0];
} | [
"public",
"function",
"getUrl",
"(",
"$",
"filePath",
",",
"$",
"width",
",",
"$",
"height",
",",
"$",
"mode",
"=",
"\"outbound\"",
",",
"$",
"quality",
"=",
"null",
",",
"$",
"fileName",
"=",
"null",
")",
"{",
"//get original file \r",
"$",
"normalizePa... | Creates and caches the image and returns URL from resized file.
@param string $filePath to original file
@param integer $width
@param integer $height
@param string $mode
@param integer $quality (1 - 100 quality)
@param string $fileName (custome filename)
@return string | [
"Creates",
"and",
"caches",
"the",
"image",
"and",
"returns",
"URL",
"from",
"resized",
"file",
"."
] | 32c5adf7211e06cefc6861a2164855573e968038 | https://github.com/noam148/yii2-image-resize/blob/32c5adf7211e06cefc6861a2164855573e968038/ImageResize.php#L167-L188 |
42,133 | noam148/yii2-image-resize | ImageResize.php | ImageResize.getCropRectangle | private function getCropRectangle($image, $targetBox, $horzMode, $vertMode)
{
$imageBox = $image->getSize();
$kw = $imageBox->getWidth() / $targetBox->getWidth();
$kh = $imageBox->getHeight() / $targetBox->getHeight();
$x = $y = $w = $h = 0;
if($kh > $kw) {
$x = 0;
$w = $imageBox->getWidth();
$h = $targetBox->getHeight() * $kw;
switch ($vertMode) {
case self::CROP_TOP:
$y = 0;
break;
case self::CROP_BOTTOM:
$y = $imageBox->getHeight() - $h;
break;
case self::CROP_CENTER:
$y = ($imageBox->getHeight() - $h) / 2;
break;
}
} else {
$y = 0;
$h = $imageBox->getHeight();
$w = $targetBox->getWidth() * $kh;
switch ($horzMode) {
case self::CROP_LEFT:
$x = 0;
break;
case self::CROP_RIGHT:
$x = $imageBox->getWidth() - $w;
break;
case self::CROP_CENTER:
$x = ($imageBox->getWidth() - $w) / 2;
break;
}
}
return [$x, $y, $w, $h];
} | php | private function getCropRectangle($image, $targetBox, $horzMode, $vertMode)
{
$imageBox = $image->getSize();
$kw = $imageBox->getWidth() / $targetBox->getWidth();
$kh = $imageBox->getHeight() / $targetBox->getHeight();
$x = $y = $w = $h = 0;
if($kh > $kw) {
$x = 0;
$w = $imageBox->getWidth();
$h = $targetBox->getHeight() * $kw;
switch ($vertMode) {
case self::CROP_TOP:
$y = 0;
break;
case self::CROP_BOTTOM:
$y = $imageBox->getHeight() - $h;
break;
case self::CROP_CENTER:
$y = ($imageBox->getHeight() - $h) / 2;
break;
}
} else {
$y = 0;
$h = $imageBox->getHeight();
$w = $targetBox->getWidth() * $kh;
switch ($horzMode) {
case self::CROP_LEFT:
$x = 0;
break;
case self::CROP_RIGHT:
$x = $imageBox->getWidth() - $w;
break;
case self::CROP_CENTER:
$x = ($imageBox->getWidth() - $w) / 2;
break;
}
}
return [$x, $y, $w, $h];
} | [
"private",
"function",
"getCropRectangle",
"(",
"$",
"image",
",",
"$",
"targetBox",
",",
"$",
"horzMode",
",",
"$",
"vertMode",
")",
"{",
"$",
"imageBox",
"=",
"$",
"image",
"->",
"getSize",
"(",
")",
";",
"$",
"kw",
"=",
"$",
"imageBox",
"->",
"get... | Get crop rectangle for custom thumbnail mode
@param ImageInterface $image
@param Box $targetBox
@param string $horzMode
@param string $vertMode
@return int[] | [
"Get",
"crop",
"rectangle",
"for",
"custom",
"thumbnail",
"mode"
] | 32c5adf7211e06cefc6861a2164855573e968038 | https://github.com/noam148/yii2-image-resize/blob/32c5adf7211e06cefc6861a2164855573e968038/ImageResize.php#L212-L250 |
42,134 | giansalex/greenter-core | src/Core/Model/Perception/Perception.php | Perception.getName | public function getName()
{
$parts = [
$this->company->getRuc(),
'40',
$this->getSerie(),
$this->getCorrelativo(),
];
return join('-', $parts);
} | php | public function getName()
{
$parts = [
$this->company->getRuc(),
'40',
$this->getSerie(),
$this->getCorrelativo(),
];
return join('-', $parts);
} | [
"public",
"function",
"getName",
"(",
")",
"{",
"$",
"parts",
"=",
"[",
"$",
"this",
"->",
"company",
"->",
"getRuc",
"(",
")",
",",
"'40'",
",",
"$",
"this",
"->",
"getSerie",
"(",
")",
",",
"$",
"this",
"->",
"getCorrelativo",
"(",
")",
",",
"]... | Get FileName without extension.
@return string | [
"Get",
"FileName",
"without",
"extension",
"."
] | 024d6db507968f56af906e21a026d0c0d8fe9af1 | https://github.com/giansalex/greenter-core/blob/024d6db507968f56af906e21a026d0c0d8fe9af1/src/Core/Model/Perception/Perception.php#L308-L318 |
42,135 | mpyw/co | src/Internal/ControlUtils.php | ControlUtils.getWrapperGenerator | public static function getWrapperGenerator(array $yieldables, callable $filter)
{
$gens = [];
foreach ($yieldables as $yieldable) {
$gens[(string)$yieldable['value']] = $filter($yieldable['value']);
}
yield CoInterface::RETURN_WITH => (yield $gens);
// @codeCoverageIgnoreStart
} | php | public static function getWrapperGenerator(array $yieldables, callable $filter)
{
$gens = [];
foreach ($yieldables as $yieldable) {
$gens[(string)$yieldable['value']] = $filter($yieldable['value']);
}
yield CoInterface::RETURN_WITH => (yield $gens);
// @codeCoverageIgnoreStart
} | [
"public",
"static",
"function",
"getWrapperGenerator",
"(",
"array",
"$",
"yieldables",
",",
"callable",
"$",
"filter",
")",
"{",
"$",
"gens",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"yieldables",
"as",
"$",
"yieldable",
")",
"{",
"$",
"gens",
"[",
"(... | Wrap yieldables with specified filter function.
@param array $yieldables
@param callable $filter self::reverse or self::fail.
@return \Generator | [
"Wrap",
"yieldables",
"with",
"specified",
"filter",
"function",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Internal/ControlUtils.php#L36-L44 |
42,136 | mpyw/co | src/Internal/ControlUtils.php | ControlUtils.reverse | public static function reverse($yieldable)
{
try {
$result = (yield $yieldable);
} catch (\RuntimeException $e) {
yield CoInterface::RETURN_WITH => $e;
}
throw new ControlException($result);
} | php | public static function reverse($yieldable)
{
try {
$result = (yield $yieldable);
} catch (\RuntimeException $e) {
yield CoInterface::RETURN_WITH => $e;
}
throw new ControlException($result);
} | [
"public",
"static",
"function",
"reverse",
"(",
"$",
"yieldable",
")",
"{",
"try",
"{",
"$",
"result",
"=",
"(",
"yield",
"$",
"yieldable",
")",
";",
"}",
"catch",
"(",
"\\",
"RuntimeException",
"$",
"e",
")",
"{",
"yield",
"CoInterface",
"::",
"RETURN... | Handle success as ControlException, failure as resolved.
@param mixed $yieldable
@return \Generator | [
"Handle",
"success",
"as",
"ControlException",
"failure",
"as",
"resolved",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Internal/ControlUtils.php#L52-L60 |
42,137 | mpyw/co | src/Co.php | Co.wait | public static function wait($value, array $options = [])
{
try {
if (self::$self) {
throw new \BadMethodCallException('Co::wait() is already running. Use Co::async() instead.');
}
self::$self = new self;
self::$self->options = new CoOption($options);
self::$self->pool = new Pool(self::$self->options);
return self::$self->start($value);
} finally {
self::$self = null;
}
// @codeCoverageIgnoreStart
} | php | public static function wait($value, array $options = [])
{
try {
if (self::$self) {
throw new \BadMethodCallException('Co::wait() is already running. Use Co::async() instead.');
}
self::$self = new self;
self::$self->options = new CoOption($options);
self::$self->pool = new Pool(self::$self->options);
return self::$self->start($value);
} finally {
self::$self = null;
}
// @codeCoverageIgnoreStart
} | [
"public",
"static",
"function",
"wait",
"(",
"$",
"value",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"try",
"{",
"if",
"(",
"self",
"::",
"$",
"self",
")",
"{",
"throw",
"new",
"\\",
"BadMethodCallException",
"(",
"'Co::wait() is already run... | Wait until value is recursively resolved to return it.
This function call must be atomic.
@param mixed $value
@param array $options
@return mixed | [
"Wait",
"until",
"value",
"is",
"recursively",
"resolved",
"to",
"return",
"it",
".",
"This",
"function",
"call",
"must",
"be",
"atomic",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Co.php#L67-L81 |
42,138 | mpyw/co | src/Co.php | Co.start | private function start($value, $wait = true, $throw = null)
{
$return = null;
// For convenience, all values are wrapped into generator
$con = YieldableUtils::normalize($this->getRootGenerator($throw, $value, $return));
$promise = $this->processGeneratorContainerRunning($con);
if ($promise instanceof ExtendedPromiseInterface) {
// This is actually 100% true; just used for unwrapping Exception thrown.
$promise->done();
}
// We have to wait $return only if $wait
if ($wait) {
$this->pool->wait();
return $return;
}
} | php | private function start($value, $wait = true, $throw = null)
{
$return = null;
// For convenience, all values are wrapped into generator
$con = YieldableUtils::normalize($this->getRootGenerator($throw, $value, $return));
$promise = $this->processGeneratorContainerRunning($con);
if ($promise instanceof ExtendedPromiseInterface) {
// This is actually 100% true; just used for unwrapping Exception thrown.
$promise->done();
}
// We have to wait $return only if $wait
if ($wait) {
$this->pool->wait();
return $return;
}
} | [
"private",
"function",
"start",
"(",
"$",
"value",
",",
"$",
"wait",
"=",
"true",
",",
"$",
"throw",
"=",
"null",
")",
"{",
"$",
"return",
"=",
"null",
";",
"// For convenience, all values are wrapped into generator",
"$",
"con",
"=",
"YieldableUtils",
"::",
... | Start resovling.
@param mixed $value
@param bool $wait
@param mixed $throw Used for Co::async() overrides.
@param mixed If $wait, return resolved value. | [
"Start",
"resovling",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Co.php#L127-L142 |
42,139 | mpyw/co | src/Co.php | Co.processGeneratorContainer | private function processGeneratorContainer(GeneratorContainer $gc)
{
return $gc->valid()
? $this->processGeneratorContainerRunning($gc)
: $this->processGeneratorContainerDone($gc);
} | php | private function processGeneratorContainer(GeneratorContainer $gc)
{
return $gc->valid()
? $this->processGeneratorContainerRunning($gc)
: $this->processGeneratorContainerDone($gc);
} | [
"private",
"function",
"processGeneratorContainer",
"(",
"GeneratorContainer",
"$",
"gc",
")",
"{",
"return",
"$",
"gc",
"->",
"valid",
"(",
")",
"?",
"$",
"this",
"->",
"processGeneratorContainerRunning",
"(",
"$",
"gc",
")",
":",
"$",
"this",
"->",
"proces... | Handle resolving generators.
@param GeneratorContainer $gc
@return PromiseInterface | [
"Handle",
"resolving",
"generators",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Co.php#L149-L154 |
42,140 | mpyw/co | src/Co.php | Co.processGeneratorContainerDone | private function processGeneratorContainerDone(GeneratorContainer $gc)
{
// If exception has been thrown in generator, we have to propagate it as rejected value
if ($gc->thrown()) {
return new RejectedPromise($gc->getReturnOrThrown());
}
// Now we normalize returned value
$returned = YieldableUtils::normalize($gc->getReturnOrThrown(), $gc->getYieldKey());
$yieldables = YieldableUtils::getYieldables($returned, [], $this->runners);
// If normalized value contains yieldables, we have to chain resolver
if ($yieldables) {
$deferred = new Deferred;
return $this->promiseAll($yieldables, true)
->then(
YieldableUtils::getApplier($returned, $yieldables, [$deferred, 'resolve']),
[$deferred, 'reject']
)
->then(function () use ($yieldables, $deferred) {
$this->runners = array_diff_key($this->runners, $yieldables);
return $deferred->promise();
});
}
// Propagate normalized returned value
return new FulfilledPromise($returned);
} | php | private function processGeneratorContainerDone(GeneratorContainer $gc)
{
// If exception has been thrown in generator, we have to propagate it as rejected value
if ($gc->thrown()) {
return new RejectedPromise($gc->getReturnOrThrown());
}
// Now we normalize returned value
$returned = YieldableUtils::normalize($gc->getReturnOrThrown(), $gc->getYieldKey());
$yieldables = YieldableUtils::getYieldables($returned, [], $this->runners);
// If normalized value contains yieldables, we have to chain resolver
if ($yieldables) {
$deferred = new Deferred;
return $this->promiseAll($yieldables, true)
->then(
YieldableUtils::getApplier($returned, $yieldables, [$deferred, 'resolve']),
[$deferred, 'reject']
)
->then(function () use ($yieldables, $deferred) {
$this->runners = array_diff_key($this->runners, $yieldables);
return $deferred->promise();
});
}
// Propagate normalized returned value
return new FulfilledPromise($returned);
} | [
"private",
"function",
"processGeneratorContainerDone",
"(",
"GeneratorContainer",
"$",
"gc",
")",
"{",
"// If exception has been thrown in generator, we have to propagate it as rejected value",
"if",
"(",
"$",
"gc",
"->",
"thrown",
"(",
")",
")",
"{",
"return",
"new",
"R... | Handle resolving generators already done.
@param GeneratorContainer $gc
@return PromiseInterface | [
"Handle",
"resolving",
"generators",
"already",
"done",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Co.php#L161-L188 |
42,141 | mpyw/co | src/Co.php | Co.processGeneratorContainerRunning | private function processGeneratorContainerRunning(GeneratorContainer $gc)
{
// Check delay request yields
if ($gc->key() === CoInterface::DELAY) {
return $this->pool->addDelay($gc->current())
->then(function () use ($gc) {
$gc->send(null);
return $this->processGeneratorContainer($gc);
});
}
// Now we normalize yielded value
$yielded = YieldableUtils::normalize($gc->current());
$yieldables = YieldableUtils::getYieldables($yielded, [], $this->runners);
if (!$yieldables) {
// If there are no yieldables, send yielded value back into generator
$gc->send($yielded);
// Continue
return $this->processGeneratorContainer($gc);
}
// Chain resolver
return $this->promiseAll($yieldables, $gc->key() !== CoInterface::SAFE)
->then(
YieldableUtils::getApplier($yielded, $yieldables, [$gc, 'send']),
[$gc, 'throw_']
)->then(function () use ($gc, $yieldables) {
// Continue
$this->runners = array_diff_key($this->runners, $yieldables);
return $this->processGeneratorContainer($gc);
});
} | php | private function processGeneratorContainerRunning(GeneratorContainer $gc)
{
// Check delay request yields
if ($gc->key() === CoInterface::DELAY) {
return $this->pool->addDelay($gc->current())
->then(function () use ($gc) {
$gc->send(null);
return $this->processGeneratorContainer($gc);
});
}
// Now we normalize yielded value
$yielded = YieldableUtils::normalize($gc->current());
$yieldables = YieldableUtils::getYieldables($yielded, [], $this->runners);
if (!$yieldables) {
// If there are no yieldables, send yielded value back into generator
$gc->send($yielded);
// Continue
return $this->processGeneratorContainer($gc);
}
// Chain resolver
return $this->promiseAll($yieldables, $gc->key() !== CoInterface::SAFE)
->then(
YieldableUtils::getApplier($yielded, $yieldables, [$gc, 'send']),
[$gc, 'throw_']
)->then(function () use ($gc, $yieldables) {
// Continue
$this->runners = array_diff_key($this->runners, $yieldables);
return $this->processGeneratorContainer($gc);
});
} | [
"private",
"function",
"processGeneratorContainerRunning",
"(",
"GeneratorContainer",
"$",
"gc",
")",
"{",
"// Check delay request yields",
"if",
"(",
"$",
"gc",
"->",
"key",
"(",
")",
"===",
"CoInterface",
"::",
"DELAY",
")",
"{",
"return",
"$",
"this",
"->",
... | Handle resolving generators still running.
@param GeneratorContainer $gc
@return PromiseInterface | [
"Handle",
"resolving",
"generators",
"still",
"running",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Co.php#L195-L226 |
42,142 | mpyw/co | src/Co.php | Co.getRootGenerator | private function getRootGenerator($throw, $value, &$return)
{
try {
if ($throw !== null) {
$key = $throw ? null : CoInterface::SAFE;
} else {
$key = $this->options['throw'] ? null : CoInterface::SAFE;
}
$return = (yield $key => $value);
return;
} catch (\Throwable $e) {} catch (\Exception $e) {}
$this->pool->reserveHaltException($e);
} | php | private function getRootGenerator($throw, $value, &$return)
{
try {
if ($throw !== null) {
$key = $throw ? null : CoInterface::SAFE;
} else {
$key = $this->options['throw'] ? null : CoInterface::SAFE;
}
$return = (yield $key => $value);
return;
} catch (\Throwable $e) {} catch (\Exception $e) {}
$this->pool->reserveHaltException($e);
} | [
"private",
"function",
"getRootGenerator",
"(",
"$",
"throw",
",",
"$",
"value",
",",
"&",
"$",
"return",
")",
"{",
"try",
"{",
"if",
"(",
"$",
"throw",
"!==",
"null",
")",
"{",
"$",
"key",
"=",
"$",
"throw",
"?",
"null",
":",
"CoInterface",
"::",
... | Return root wrapper generator.
@param mixed $throw
@param mixed $value
@param mixed &$return | [
"Return",
"root",
"wrapper",
"generator",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Co.php#L234-L246 |
42,143 | mpyw/co | src/Co.php | Co.promiseAll | private function promiseAll(array $yieldables, $throw_acceptable)
{
$promises = [];
foreach ($yieldables as $yieldable) {
// Add or enqueue cURL handles
if (TypeUtils::isCurl($yieldable['value'])) {
$promises[(string)$yieldable['value']] = $this->pool->addCurl($yieldable['value']);
continue;
}
// Process generators
if (TypeUtils::isGeneratorContainer($yieldable['value'])) {
$promises[(string)$yieldable['value']] = $this->processGeneratorContainer($yieldable['value']);
continue;
}
}
// If caller cannot accept exception,
// we handle rejected value as resolved.
if (!$throw_acceptable) {
$promises = array_map(
['\mpyw\Co\Internal\YieldableUtils', 'safePromise'],
$promises
);
}
return \React\Promise\all($promises);
} | php | private function promiseAll(array $yieldables, $throw_acceptable)
{
$promises = [];
foreach ($yieldables as $yieldable) {
// Add or enqueue cURL handles
if (TypeUtils::isCurl($yieldable['value'])) {
$promises[(string)$yieldable['value']] = $this->pool->addCurl($yieldable['value']);
continue;
}
// Process generators
if (TypeUtils::isGeneratorContainer($yieldable['value'])) {
$promises[(string)$yieldable['value']] = $this->processGeneratorContainer($yieldable['value']);
continue;
}
}
// If caller cannot accept exception,
// we handle rejected value as resolved.
if (!$throw_acceptable) {
$promises = array_map(
['\mpyw\Co\Internal\YieldableUtils', 'safePromise'],
$promises
);
}
return \React\Promise\all($promises);
} | [
"private",
"function",
"promiseAll",
"(",
"array",
"$",
"yieldables",
",",
"$",
"throw_acceptable",
")",
"{",
"$",
"promises",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"yieldables",
"as",
"$",
"yieldable",
")",
"{",
"// Add or enqueue cURL handles",
"if",
"(... | Promise all changes in yieldables are prepared.
@param array $yieldables
@param bool $throw_acceptable
@return PromiseInterface | [
"Promise",
"all",
"changes",
"in",
"yieldables",
"are",
"prepared",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Co.php#L254-L278 |
42,144 | mpyw/co | src/Internal/Delayer.php | Delayer.add | public function add($time)
{
$deferred = new Deferred;
$time = filter_var($time, FILTER_VALIDATE_FLOAT);
if ($time === false) {
throw new \InvalidArgumentException('Delay must be number.');
}
if ($time < 0) {
throw new \DomainException('Delay must be positive.');
}
do {
$id = uniqid();
} while (isset($this->untils[$id]));
$this->untils[$id] = microtime(true) + $time;
$this->deferreds[$id] = $deferred;
return $deferred->promise();
} | php | public function add($time)
{
$deferred = new Deferred;
$time = filter_var($time, FILTER_VALIDATE_FLOAT);
if ($time === false) {
throw new \InvalidArgumentException('Delay must be number.');
}
if ($time < 0) {
throw new \DomainException('Delay must be positive.');
}
do {
$id = uniqid();
} while (isset($this->untils[$id]));
$this->untils[$id] = microtime(true) + $time;
$this->deferreds[$id] = $deferred;
return $deferred->promise();
} | [
"public",
"function",
"add",
"(",
"$",
"time",
")",
"{",
"$",
"deferred",
"=",
"new",
"Deferred",
";",
"$",
"time",
"=",
"filter_var",
"(",
"$",
"time",
",",
"FILTER_VALIDATE_FLOAT",
")",
";",
"if",
"(",
"$",
"time",
"===",
"false",
")",
"{",
"throw"... | Add delay.
@param int $time
@return PromiseInterface | [
"Add",
"delay",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Internal/Delayer.php#L26-L42 |
42,145 | mpyw/co | src/Internal/Delayer.php | Delayer.sleep | public function sleep()
{
$now = microtime(true);
$min = null;
foreach ($this->untils as $id => $until) {
$diff = $until - $now;
if ($diff < 0) {
// @codeCoverageIgnoreStart
return;
// @codeCoverageIgnoreEnd
}
if ($min !== null && $diff >= $min) {
continue;
}
$min = $diff;
}
$min && usleep($min * 1000000);
} | php | public function sleep()
{
$now = microtime(true);
$min = null;
foreach ($this->untils as $id => $until) {
$diff = $until - $now;
if ($diff < 0) {
// @codeCoverageIgnoreStart
return;
// @codeCoverageIgnoreEnd
}
if ($min !== null && $diff >= $min) {
continue;
}
$min = $diff;
}
$min && usleep($min * 1000000);
} | [
"public",
"function",
"sleep",
"(",
")",
"{",
"$",
"now",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"min",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"untils",
"as",
"$",
"id",
"=>",
"$",
"until",
")",
"{",
"$",
"diff",
"=",
"$",
... | Sleep at least required. | [
"Sleep",
"at",
"least",
"required",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Internal/Delayer.php#L47-L64 |
42,146 | mpyw/co | src/Internal/Delayer.php | Delayer.consume | public function consume()
{
foreach ($this->untils as $id => $until) {
$diff = $until - microtime(true);
if ($diff > 0.0 || !isset($this->deferreds[$id])) {
continue;
}
$deferred = $this->deferreds[$id];
unset($this->deferreds[$id], $this->untils[$id]);
$deferred->resolve(null);
}
} | php | public function consume()
{
foreach ($this->untils as $id => $until) {
$diff = $until - microtime(true);
if ($diff > 0.0 || !isset($this->deferreds[$id])) {
continue;
}
$deferred = $this->deferreds[$id];
unset($this->deferreds[$id], $this->untils[$id]);
$deferred->resolve(null);
}
} | [
"public",
"function",
"consume",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"untils",
"as",
"$",
"id",
"=>",
"$",
"until",
")",
"{",
"$",
"diff",
"=",
"$",
"until",
"-",
"microtime",
"(",
"true",
")",
";",
"if",
"(",
"$",
"diff",
">",
"0... | Consume delay queue. | [
"Consume",
"delay",
"queue",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Internal/Delayer.php#L69-L80 |
42,147 | mpyw/co | src/Internal/AbstractScheduler.php | AbstractScheduler.consume | public function consume()
{
$entries = $this->readCompletedEntries();
foreach ($entries as $entry) {
curl_multi_remove_handle($this->mh, $entry['handle']);
unset($this->added[(string)$entry['handle']]);
$this->interruptConsume();
}
$this->resolveEntries($entries);
} | php | public function consume()
{
$entries = $this->readCompletedEntries();
foreach ($entries as $entry) {
curl_multi_remove_handle($this->mh, $entry['handle']);
unset($this->added[(string)$entry['handle']]);
$this->interruptConsume();
}
$this->resolveEntries($entries);
} | [
"public",
"function",
"consume",
"(",
")",
"{",
"$",
"entries",
"=",
"$",
"this",
"->",
"readCompletedEntries",
"(",
")",
";",
"foreach",
"(",
"$",
"entries",
"as",
"$",
"entry",
")",
"{",
"curl_multi_remove_handle",
"(",
"$",
"this",
"->",
"mh",
",",
... | Poll completed cURL entries, consume cURL queue and resolve them. | [
"Poll",
"completed",
"cURL",
"entries",
"consume",
"cURL",
"queue",
"and",
"resolve",
"them",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Internal/AbstractScheduler.php#L62-L71 |
42,148 | mpyw/co | src/Internal/AbstractScheduler.php | AbstractScheduler.resolveEntries | protected function resolveEntries(array $entries)
{
foreach ($entries as $entry) {
$deferred = $this->deferreds[(string)$entry['handle']];
unset($this->deferreds[(string)$entry['handle']]);
$entry['result'] === CURLE_OK
? $deferred->resolve(curl_multi_getcontent($entry['handle']))
: $deferred->reject(new CURLException(curl_error($entry['handle']), $entry['result'], $entry['handle']));
}
} | php | protected function resolveEntries(array $entries)
{
foreach ($entries as $entry) {
$deferred = $this->deferreds[(string)$entry['handle']];
unset($this->deferreds[(string)$entry['handle']]);
$entry['result'] === CURLE_OK
? $deferred->resolve(curl_multi_getcontent($entry['handle']))
: $deferred->reject(new CURLException(curl_error($entry['handle']), $entry['result'], $entry['handle']));
}
} | [
"protected",
"function",
"resolveEntries",
"(",
"array",
"$",
"entries",
")",
"{",
"foreach",
"(",
"$",
"entries",
"as",
"$",
"entry",
")",
"{",
"$",
"deferred",
"=",
"$",
"this",
"->",
"deferreds",
"[",
"(",
"string",
")",
"$",
"entry",
"[",
"'handle'... | Resolve polled cURLs.
@param array $entries Polled cURL entries. | [
"Resolve",
"polled",
"cURLs",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Internal/AbstractScheduler.php#L91-L100 |
42,149 | mpyw/co | src/Internal/GeneratorContainer.php | GeneratorContainer.valid | public function valid()
{
try {
$this->g->current();
return $this->e === null && $this->g->valid() && $this->g->key() !== CoInterface::RETURN_WITH;
} catch (\Throwable $e) {} catch (\Exception $e) {}
$this->e = $e;
return false;
} | php | public function valid()
{
try {
$this->g->current();
return $this->e === null && $this->g->valid() && $this->g->key() !== CoInterface::RETURN_WITH;
} catch (\Throwable $e) {} catch (\Exception $e) {}
$this->e = $e;
return false;
} | [
"public",
"function",
"valid",
"(",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"g",
"->",
"current",
"(",
")",
";",
"return",
"$",
"this",
"->",
"e",
"===",
"null",
"&&",
"$",
"this",
"->",
"g",
"->",
"valid",
"(",
")",
"&&",
"$",
"this",
"->",
... | Return whether generator is actually working.
@return bool | [
"Return",
"whether",
"generator",
"is",
"actually",
"working",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Internal/GeneratorContainer.php#L66-L74 |
42,150 | mpyw/co | src/Internal/GeneratorContainer.php | GeneratorContainer.send | public function send($value)
{
$this->validateValidity();
try {
$this->g->send($value);
return;
} catch (\Throwable $e) {} catch (\Exception $e) {}
$this->e = $e;
} | php | public function send($value)
{
$this->validateValidity();
try {
$this->g->send($value);
return;
} catch (\Throwable $e) {} catch (\Exception $e) {}
$this->e = $e;
} | [
"public",
"function",
"send",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"validateValidity",
"(",
")",
";",
"try",
"{",
"$",
"this",
"->",
"g",
"->",
"send",
"(",
"$",
"value",
")",
";",
"return",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"... | Send value into generator.
@param mixed $value
@NOTE: This method returns nothing,
while original generator returns something. | [
"Send",
"value",
"into",
"generator",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Internal/GeneratorContainer.php#L102-L110 |
42,151 | mpyw/co | src/Internal/GeneratorContainer.php | GeneratorContainer.throw_ | public function throw_($e)
{
$this->validateValidity();
try {
$this->g->throw($e);
return;
} catch (\Throwable $e) {} catch (\Exception $e) {}
$this->e = $e;
} | php | public function throw_($e)
{
$this->validateValidity();
try {
$this->g->throw($e);
return;
} catch (\Throwable $e) {} catch (\Exception $e) {}
$this->e = $e;
} | [
"public",
"function",
"throw_",
"(",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"validateValidity",
"(",
")",
";",
"try",
"{",
"$",
"this",
"->",
"g",
"->",
"throw",
"(",
"$",
"e",
")",
";",
"return",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
... | Throw exception into generator.
@param \Throwable|\Exception $e
@NOTE: This method returns nothing,
while original generator returns something. | [
"Throw",
"exception",
"into",
"generator",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Internal/GeneratorContainer.php#L118-L126 |
42,152 | mpyw/co | src/Internal/GeneratorContainer.php | GeneratorContainer.getReturnOrThrown | public function getReturnOrThrown()
{
$this->validateInvalidity();
if ($this->e === null && $this->g->valid() && !$this->valid()) {
return $this->g->current();
}
if ($this->e) {
return $this->e;
}
return method_exists($this->g, 'getReturn') ? $this->g->getReturn() : null;
} | php | public function getReturnOrThrown()
{
$this->validateInvalidity();
if ($this->e === null && $this->g->valid() && !$this->valid()) {
return $this->g->current();
}
if ($this->e) {
return $this->e;
}
return method_exists($this->g, 'getReturn') ? $this->g->getReturn() : null;
} | [
"public",
"function",
"getReturnOrThrown",
"(",
")",
"{",
"$",
"this",
"->",
"validateInvalidity",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"e",
"===",
"null",
"&&",
"$",
"this",
"->",
"g",
"->",
"valid",
"(",
")",
"&&",
"!",
"$",
"this",
"->",... | Return value that generator has returned or thrown.
@return mixed | [
"Return",
"value",
"that",
"generator",
"has",
"returned",
"or",
"thrown",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Internal/GeneratorContainer.php#L141-L151 |
42,153 | mpyw/co | src/Internal/ManualScheduler.php | ManualScheduler.addReserved | private function addReserved($ch, Deferred $deferred = null)
{
$this->queue[(string)$ch] = $ch;
$deferred && $this->deferreds[(string)$ch] = $deferred;
} | php | private function addReserved($ch, Deferred $deferred = null)
{
$this->queue[(string)$ch] = $ch;
$deferred && $this->deferreds[(string)$ch] = $deferred;
} | [
"private",
"function",
"addReserved",
"(",
"$",
"ch",
",",
"Deferred",
"$",
"deferred",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"queue",
"[",
"(",
"string",
")",
"$",
"ch",
"]",
"=",
"$",
"ch",
";",
"$",
"deferred",
"&&",
"$",
"this",
"->",
"de... | Push into queue.
@param resource $ch
@param Deferred $deferred | [
"Push",
"into",
"queue",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Internal/ManualScheduler.php#L76-L80 |
42,154 | mpyw/co | src/Internal/CoOption.php | CoOption.offsetGet | public function offsetGet($offset)
{
if (!isset($this->options[$offset])) {
throw new \DomainException('Undefined field: ' + $offset);
}
return $this->options[$offset];
} | php | public function offsetGet($offset)
{
if (!isset($this->options[$offset])) {
throw new \DomainException('Undefined field: ' + $offset);
}
return $this->options[$offset];
} | [
"public",
"function",
"offsetGet",
"(",
"$",
"offset",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"$",
"offset",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"DomainException",
"(",
"'Undefined field: '",
"+",
"$",
"offset"... | Implemention of ArrayAccess.
@param mixed $offset
@return mixed | [
"Implemention",
"of",
"ArrayAccess",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Internal/CoOption.php#L90-L96 |
42,155 | mpyw/co | src/Internal/CoOption.php | CoOption.validateOptions | private static function validateOptions(array $options)
{
foreach ($options as $key => $value) {
if (!isset(self::$types[$key])) {
throw new \DomainException("Unknown option: $key");
}
if ($key === 'autoschedule' && !defined('CURLMOPT_MAX_TOTAL_CONNECTIONS')) {
throw new \OutOfBoundsException('"autoschedule" can be used only on PHP 7.0.7 or later.');
}
$validator = [__CLASS__, 'validate' . self::$types[$key]];
$options[$key] = $validator($key, $value);
}
return $options;
} | php | private static function validateOptions(array $options)
{
foreach ($options as $key => $value) {
if (!isset(self::$types[$key])) {
throw new \DomainException("Unknown option: $key");
}
if ($key === 'autoschedule' && !defined('CURLMOPT_MAX_TOTAL_CONNECTIONS')) {
throw new \OutOfBoundsException('"autoschedule" can be used only on PHP 7.0.7 or later.');
}
$validator = [__CLASS__, 'validate' . self::$types[$key]];
$options[$key] = $validator($key, $value);
}
return $options;
} | [
"private",
"static",
"function",
"validateOptions",
"(",
"array",
"$",
"options",
")",
"{",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"types",
"[",
"$",
"key",
"... | Validate options.
@param array $options
@return array | [
"Validate",
"options",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Internal/CoOption.php#L124-L137 |
42,156 | mpyw/co | src/Internal/CoOption.php | CoOption.validateBool | private static function validateBool($key, $value)
{
$value = filter_var($value, FILTER_VALIDATE_BOOLEAN, [
'flags' => FILTER_NULL_ON_FAILURE,
]);
if ($value === null) {
throw new \InvalidArgumentException("Option[$key] must be boolean.");
}
return $value;
} | php | private static function validateBool($key, $value)
{
$value = filter_var($value, FILTER_VALIDATE_BOOLEAN, [
'flags' => FILTER_NULL_ON_FAILURE,
]);
if ($value === null) {
throw new \InvalidArgumentException("Option[$key] must be boolean.");
}
return $value;
} | [
"private",
"static",
"function",
"validateBool",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"filter_var",
"(",
"$",
"value",
",",
"FILTER_VALIDATE_BOOLEAN",
",",
"[",
"'flags'",
"=>",
"FILTER_NULL_ON_FAILURE",
",",
"]",
")",
";",
"if"... | Validate bool value.
@param string $key
@param mixed $value
@throws InvalidArgumentException
@return bool | [
"Validate",
"bool",
"value",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Internal/CoOption.php#L146-L155 |
42,157 | mpyw/co | src/Internal/CoOption.php | CoOption.validateNaturalFloat | private static function validateNaturalFloat($key, $value)
{
$value = filter_var($value, FILTER_VALIDATE_FLOAT);
if ($value === false) {
throw new \InvalidArgumentException("Option[$key] must be float.");
}
if ($value < 0.0) {
throw new \DomainException("Option[$key] must be positive or zero.");
}
return $value;
} | php | private static function validateNaturalFloat($key, $value)
{
$value = filter_var($value, FILTER_VALIDATE_FLOAT);
if ($value === false) {
throw new \InvalidArgumentException("Option[$key] must be float.");
}
if ($value < 0.0) {
throw new \DomainException("Option[$key] must be positive or zero.");
}
return $value;
} | [
"private",
"static",
"function",
"validateNaturalFloat",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"filter_var",
"(",
"$",
"value",
",",
"FILTER_VALIDATE_FLOAT",
")",
";",
"if",
"(",
"$",
"value",
"===",
"false",
")",
"{",
"throw",... | Validate natural float value.
@param string $key
@param mixed $value
@throws InvalidArgumentException
@return float | [
"Validate",
"natural",
"float",
"value",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Internal/CoOption.php#L164-L174 |
42,158 | mpyw/co | src/Internal/CoOption.php | CoOption.validateNaturalInt | private static function validateNaturalInt($key, $value)
{
$value = filter_var($value, FILTER_VALIDATE_INT);
if ($value === false) {
throw new \InvalidArgumentException("Option[$key] must be integer.");
}
if ($value < 0) {
throw new \DomainException("Option[$key] must be positive or zero.");
}
return $value;
} | php | private static function validateNaturalInt($key, $value)
{
$value = filter_var($value, FILTER_VALIDATE_INT);
if ($value === false) {
throw new \InvalidArgumentException("Option[$key] must be integer.");
}
if ($value < 0) {
throw new \DomainException("Option[$key] must be positive or zero.");
}
return $value;
} | [
"private",
"static",
"function",
"validateNaturalInt",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"filter_var",
"(",
"$",
"value",
",",
"FILTER_VALIDATE_INT",
")",
";",
"if",
"(",
"$",
"value",
"===",
"false",
")",
"{",
"throw",
"... | Validate natural int value.
@param string $key
@param mixed $value
@throws InvalidArgumentException
@return int | [
"Validate",
"natural",
"int",
"value",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Internal/CoOption.php#L183-L193 |
42,159 | mpyw/co | src/Internal/YieldableUtils.php | YieldableUtils.getYieldables | public static function getYieldables($value, array $keylist = [], array &$runners = [])
{
$r = [];
if (!is_array($value)) {
if (TypeUtils::isCurl($value) || TypeUtils::isGeneratorContainer($value)) {
if (isset($runners[(string)$value])) {
throw new \DomainException('Duplicated cURL resource or Generator instance found.');
}
$r[(string)$value] = $runners[(string)$value] = [
'value' => $value,
'keylist' => $keylist,
];
}
return $r;
}
foreach ($value as $k => $v) {
$newlist = array_merge($keylist, [$k]);
$r = array_merge($r, self::getYieldables($v, $newlist, $runners));
}
return $r;
} | php | public static function getYieldables($value, array $keylist = [], array &$runners = [])
{
$r = [];
if (!is_array($value)) {
if (TypeUtils::isCurl($value) || TypeUtils::isGeneratorContainer($value)) {
if (isset($runners[(string)$value])) {
throw new \DomainException('Duplicated cURL resource or Generator instance found.');
}
$r[(string)$value] = $runners[(string)$value] = [
'value' => $value,
'keylist' => $keylist,
];
}
return $r;
}
foreach ($value as $k => $v) {
$newlist = array_merge($keylist, [$k]);
$r = array_merge($r, self::getYieldables($v, $newlist, $runners));
}
return $r;
} | [
"public",
"static",
"function",
"getYieldables",
"(",
"$",
"value",
",",
"array",
"$",
"keylist",
"=",
"[",
"]",
",",
"array",
"&",
"$",
"runners",
"=",
"[",
"]",
")",
"{",
"$",
"r",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"va... | Recursively search yieldable values.
Each entries are assoc those contain keys 'value' and 'keylist'.
value -> the value itself.
keylist -> position of the value. nests are represented as array values.
@param mixed $value Must be already normalized.
@param array $keylist Internally used.
@param array &$runners Running cURL or Generator identifiers.
@return array | [
"Recursively",
"search",
"yieldable",
"values",
".",
"Each",
"entries",
"are",
"assoc",
"those",
"contain",
"keys",
"value",
"and",
"keylist",
".",
"value",
"-",
">",
"the",
"value",
"itself",
".",
"keylist",
"-",
">",
"position",
"of",
"the",
"value",
"."... | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Internal/YieldableUtils.php#L45-L65 |
42,160 | mpyw/co | src/Internal/YieldableUtils.php | YieldableUtils.getApplier | public static function getApplier($yielded, array $yieldables, callable $next = null)
{
return function (array $results) use ($yielded, $yieldables, $next) {
foreach ($results as $hash => $resolved) {
$current = &$yielded;
foreach ($yieldables[$hash]['keylist'] as $key) {
$current = &$current[$key];
}
$current = $resolved;
unset($current);
}
return $next ? $next($yielded) : $yielded;
};
} | php | public static function getApplier($yielded, array $yieldables, callable $next = null)
{
return function (array $results) use ($yielded, $yieldables, $next) {
foreach ($results as $hash => $resolved) {
$current = &$yielded;
foreach ($yieldables[$hash]['keylist'] as $key) {
$current = &$current[$key];
}
$current = $resolved;
unset($current);
}
return $next ? $next($yielded) : $yielded;
};
} | [
"public",
"static",
"function",
"getApplier",
"(",
"$",
"yielded",
",",
"array",
"$",
"yieldables",
",",
"callable",
"$",
"next",
"=",
"null",
")",
"{",
"return",
"function",
"(",
"array",
"$",
"results",
")",
"use",
"(",
"$",
"yielded",
",",
"$",
"yie... | Return function that apply changes in yieldables.
@param mixed $yielded
@param array $yieldables
@param callable|null $next
@return mixed | [
"Return",
"function",
"that",
"apply",
"changes",
"in",
"yieldables",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Internal/YieldableUtils.php#L74-L87 |
42,161 | mpyw/co | src/Internal/YieldableUtils.php | YieldableUtils.safePromise | public static function safePromise(PromiseInterface $promise)
{
return $promise->then(null, function ($value) {
if (TypeUtils::isFatalThrowable($value)) {
throw $value;
}
return $value;
});
} | php | public static function safePromise(PromiseInterface $promise)
{
return $promise->then(null, function ($value) {
if (TypeUtils::isFatalThrowable($value)) {
throw $value;
}
return $value;
});
} | [
"public",
"static",
"function",
"safePromise",
"(",
"PromiseInterface",
"$",
"promise",
")",
"{",
"return",
"$",
"promise",
"->",
"then",
"(",
"null",
",",
"function",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"TypeUtils",
"::",
"isFatalThrowable",
"(",
"$",... | Return Promise that absorbs rejects, excluding fatal Throwable.
@param PromiseInterface $promise
@return PromiseInterface | [
"Return",
"Promise",
"that",
"absorbs",
"rejects",
"excluding",
"fatal",
"Throwable",
"."
] | 1ab101b8ef5feb634a028d385aadeba23da18dca | https://github.com/mpyw/co/blob/1ab101b8ef5feb634a028d385aadeba23da18dca/src/Internal/YieldableUtils.php#L94-L102 |
42,162 | sitepoint-editors/Container | src/Container.php | Container.createService | private function createService($name)
{
$entry = &$this->services[$name];
if (!is_array($entry) || !isset($entry['class'])) {
throw new ContainerException($name.' service entry must be an array containing a \'class\' key');
} elseif (!class_exists($entry['class'])) {
throw new ContainerException($name.' service class does not exist: '.$entry['class']);
} elseif (isset($entry['lock'])) {
throw new ContainerException($name.' contains circular reference');
}
$entry['lock'] = true;
$arguments = isset($entry['arguments']) ? $this->resolveArguments($entry['arguments']) : [];
$reflector = new \ReflectionClass($entry['class']);
$service = $reflector->newInstanceArgs($arguments);
if (isset($entry['calls'])) {
$this->initializeService($service, $name, $entry['calls']);
}
return $service;
} | php | private function createService($name)
{
$entry = &$this->services[$name];
if (!is_array($entry) || !isset($entry['class'])) {
throw new ContainerException($name.' service entry must be an array containing a \'class\' key');
} elseif (!class_exists($entry['class'])) {
throw new ContainerException($name.' service class does not exist: '.$entry['class']);
} elseif (isset($entry['lock'])) {
throw new ContainerException($name.' contains circular reference');
}
$entry['lock'] = true;
$arguments = isset($entry['arguments']) ? $this->resolveArguments($entry['arguments']) : [];
$reflector = new \ReflectionClass($entry['class']);
$service = $reflector->newInstanceArgs($arguments);
if (isset($entry['calls'])) {
$this->initializeService($service, $name, $entry['calls']);
}
return $service;
} | [
"private",
"function",
"createService",
"(",
"$",
"name",
")",
"{",
"$",
"entry",
"=",
"&",
"$",
"this",
"->",
"services",
"[",
"$",
"name",
"]",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"entry",
")",
"||",
"!",
"isset",
"(",
"$",
"entry",
"[",... | Attempt to create a service.
@param string $name The service name.
@return mixed The created service.
@throws ContainerException On failure. | [
"Attempt",
"to",
"create",
"a",
"service",
"."
] | 03a26a6a8014c21faaca697cbab17d4e5c8d7f64 | https://github.com/sitepoint-editors/Container/blob/03a26a6a8014c21faaca697cbab17d4e5c8d7f64/src/Container.php#L121-L145 |
42,163 | sitepoint-editors/Container | src/Container.php | Container.resolveArguments | private function resolveArguments(array $argumentDefinitions)
{
$arguments = [];
foreach ($argumentDefinitions as $argumentDefinition) {
if ($argumentDefinition instanceof ServiceReference) {
$argumentServiceName = $argumentDefinition->getName();
$arguments[] = $this->get($argumentServiceName);
} elseif ($argumentDefinition instanceof ParameterReference) {
$argumentParameterName = $argumentDefinition->getName();
$arguments[] = $this->getParameter($argumentParameterName);
} else {
$arguments[] = $argumentDefinition;
}
}
return $arguments;
} | php | private function resolveArguments(array $argumentDefinitions)
{
$arguments = [];
foreach ($argumentDefinitions as $argumentDefinition) {
if ($argumentDefinition instanceof ServiceReference) {
$argumentServiceName = $argumentDefinition->getName();
$arguments[] = $this->get($argumentServiceName);
} elseif ($argumentDefinition instanceof ParameterReference) {
$argumentParameterName = $argumentDefinition->getName();
$arguments[] = $this->getParameter($argumentParameterName);
} else {
$arguments[] = $argumentDefinition;
}
}
return $arguments;
} | [
"private",
"function",
"resolveArguments",
"(",
"array",
"$",
"argumentDefinitions",
")",
"{",
"$",
"arguments",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"argumentDefinitions",
"as",
"$",
"argumentDefinition",
")",
"{",
"if",
"(",
"$",
"argumentDefinition",
"i... | Resolve argument definitions into an array of arguments.
@param array $argumentDefinitions The service arguments definition.
@return array The service constructor arguments.
@throws ContainerException On failure. | [
"Resolve",
"argument",
"definitions",
"into",
"an",
"array",
"of",
"arguments",
"."
] | 03a26a6a8014c21faaca697cbab17d4e5c8d7f64 | https://github.com/sitepoint-editors/Container/blob/03a26a6a8014c21faaca697cbab17d4e5c8d7f64/src/Container.php#L156-L175 |
42,164 | sitepoint-editors/Container | src/Container.php | Container.initializeService | private function initializeService($service, $name, array $callDefinitions)
{
foreach ($callDefinitions as $callDefinition) {
if (!is_array($callDefinition) || !isset($callDefinition['method'])) {
throw new ContainerException($name.' service calls must be arrays containing a \'method\' key');
} elseif (!is_callable([$service, $callDefinition['method']])) {
throw new ContainerException($name.' service asks for call to uncallable method: '.$callDefinition['method']);
}
$arguments = isset($callDefinition['arguments']) ? $this->resolveArguments($callDefinition['arguments']) : [];
call_user_func_array([$service, $callDefinition['method']], $arguments);
}
} | php | private function initializeService($service, $name, array $callDefinitions)
{
foreach ($callDefinitions as $callDefinition) {
if (!is_array($callDefinition) || !isset($callDefinition['method'])) {
throw new ContainerException($name.' service calls must be arrays containing a \'method\' key');
} elseif (!is_callable([$service, $callDefinition['method']])) {
throw new ContainerException($name.' service asks for call to uncallable method: '.$callDefinition['method']);
}
$arguments = isset($callDefinition['arguments']) ? $this->resolveArguments($callDefinition['arguments']) : [];
call_user_func_array([$service, $callDefinition['method']], $arguments);
}
} | [
"private",
"function",
"initializeService",
"(",
"$",
"service",
",",
"$",
"name",
",",
"array",
"$",
"callDefinitions",
")",
"{",
"foreach",
"(",
"$",
"callDefinitions",
"as",
"$",
"callDefinition",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"callDef... | Initialize a service using the call definitions.
@param object $service The service.
@param string $name The service name.
@param array $callDefinitions The service calls definition.
@throws ContainerException On failure. | [
"Initialize",
"a",
"service",
"using",
"the",
"call",
"definitions",
"."
] | 03a26a6a8014c21faaca697cbab17d4e5c8d7f64 | https://github.com/sitepoint-editors/Container/blob/03a26a6a8014c21faaca697cbab17d4e5c8d7f64/src/Container.php#L186-L199 |
42,165 | jarektkaczyk/eloquence-mutable | src/Mutator/Mutator.php | Mutator.mutate | public function mutate($value, $callables)
{
if (!is_array($callables)) {
$callables = explode('|', $callables);
}
foreach ($callables as $callable) {
list($callable, $args) = $this->parse(trim($callable));
$value = call_user_func_array($callable, array_merge([$value], $args));
}
return $value;
} | php | public function mutate($value, $callables)
{
if (!is_array($callables)) {
$callables = explode('|', $callables);
}
foreach ($callables as $callable) {
list($callable, $args) = $this->parse(trim($callable));
$value = call_user_func_array($callable, array_merge([$value], $args));
}
return $value;
} | [
"public",
"function",
"mutate",
"(",
"$",
"value",
",",
"$",
"callables",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"callables",
")",
")",
"{",
"$",
"callables",
"=",
"explode",
"(",
"'|'",
",",
"$",
"callables",
")",
";",
"}",
"foreach",
"("... | Mutate value using provided methods.
@param mixed $value
@param string|array $callables
@return mixed
@throws \LogicException | [
"Mutate",
"value",
"using",
"provided",
"methods",
"."
] | c2d361e8b2a7ae6aaa2324b78b401e944ef3bc69 | https://github.com/jarektkaczyk/eloquence-mutable/blob/c2d361e8b2a7ae6aaa2324b78b401e944ef3bc69/src/Mutator/Mutator.php#L24-L37 |
42,166 | jarektkaczyk/eloquence-mutable | src/Mutator/Mutator.php | Mutator.parse | protected function parse($callable)
{
list($callable, $args) = $this->parseArgs($callable);
if ($this->isClassMethod($callable)) {
$callable = $this->parseClassMethod($callable);
} elseif ($this->isMutatorMethod($callable)) {
$callable = [$this, $callable];
} elseif (!function_exists($callable)) {
throw new InvalidCallableException("Function [{$callable}] not found.");
}
return [$callable, $args];
} | php | protected function parse($callable)
{
list($callable, $args) = $this->parseArgs($callable);
if ($this->isClassMethod($callable)) {
$callable = $this->parseClassMethod($callable);
} elseif ($this->isMutatorMethod($callable)) {
$callable = [$this, $callable];
} elseif (!function_exists($callable)) {
throw new InvalidCallableException("Function [{$callable}] not found.");
}
return [$callable, $args];
} | [
"protected",
"function",
"parse",
"(",
"$",
"callable",
")",
"{",
"list",
"(",
"$",
"callable",
",",
"$",
"args",
")",
"=",
"$",
"this",
"->",
"parseArgs",
"(",
"$",
"callable",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isClassMethod",
"(",
"$",
"ca... | Parse provided mutator functions.
@param string $callable
@return array
@throws \Sofa\Eloquence\Mutator\InvalidCallableException | [
"Parse",
"provided",
"mutator",
"functions",
"."
] | c2d361e8b2a7ae6aaa2324b78b401e944ef3bc69 | https://github.com/jarektkaczyk/eloquence-mutable/blob/c2d361e8b2a7ae6aaa2324b78b401e944ef3bc69/src/Mutator/Mutator.php#L47-L60 |
42,167 | jarektkaczyk/eloquence-mutable | src/Mutator/Mutator.php | Mutator.parseArgs | protected function parseArgs($callable)
{
$args = [];
if (strpos($callable, ':') !== false) {
list($callable, $argsString) = explode(':', $callable);
$args = explode(',', $argsString);
}
return [$callable, $args];
} | php | protected function parseArgs($callable)
{
$args = [];
if (strpos($callable, ':') !== false) {
list($callable, $argsString) = explode(':', $callable);
$args = explode(',', $argsString);
}
return [$callable, $args];
} | [
"protected",
"function",
"parseArgs",
"(",
"$",
"callable",
")",
"{",
"$",
"args",
"=",
"[",
"]",
";",
"if",
"(",
"strpos",
"(",
"$",
"callable",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"callable",
",",
"$",
"argsString",
")",
... | Split provided string into callable and arguments.
@param string $callable
@return array | [
"Split",
"provided",
"string",
"into",
"callable",
"and",
"arguments",
"."
] | c2d361e8b2a7ae6aaa2324b78b401e944ef3bc69 | https://github.com/jarektkaczyk/eloquence-mutable/blob/c2d361e8b2a7ae6aaa2324b78b401e944ef3bc69/src/Mutator/Mutator.php#L90-L101 |
42,168 | jarektkaczyk/eloquence-mutable | src/Mutator/Mutator.php | Mutator.parseClassMethod | protected function parseClassMethod($userCallable)
{
list($class) = explode('@', $userCallable);
$callable = str_replace('@', '::', $userCallable);
try {
$method = new ReflectionMethod($callable);
$class = new ReflectionClass($class);
} catch (ReflectionException $e) {
throw new InvalidCallableException($e->getMessage());
}
return ($method->isStatic()) ? $callable : $this->getInstanceMethod($class, $method);
} | php | protected function parseClassMethod($userCallable)
{
list($class) = explode('@', $userCallable);
$callable = str_replace('@', '::', $userCallable);
try {
$method = new ReflectionMethod($callable);
$class = new ReflectionClass($class);
} catch (ReflectionException $e) {
throw new InvalidCallableException($e->getMessage());
}
return ($method->isStatic()) ? $callable : $this->getInstanceMethod($class, $method);
} | [
"protected",
"function",
"parseClassMethod",
"(",
"$",
"userCallable",
")",
"{",
"list",
"(",
"$",
"class",
")",
"=",
"explode",
"(",
"'@'",
",",
"$",
"userCallable",
")",
";",
"$",
"callable",
"=",
"str_replace",
"(",
"'@'",
",",
"'::'",
",",
"$",
"us... | Extract and validate class method.
@param string $userCallable
@return callable
@throws \Sofa\Eloquence\Mutator\InvalidCallableException | [
"Extract",
"and",
"validate",
"class",
"method",
"."
] | c2d361e8b2a7ae6aaa2324b78b401e944ef3bc69 | https://github.com/jarektkaczyk/eloquence-mutable/blob/c2d361e8b2a7ae6aaa2324b78b401e944ef3bc69/src/Mutator/Mutator.php#L111-L126 |
42,169 | jarektkaczyk/eloquence-mutable | src/Mutator/Mutator.php | Mutator.getInstanceMethod | protected function getInstanceMethod(ReflectionClass $class, ReflectionMethod $method)
{
if (!$method->isPublic()) {
throw new InvalidCallableException("Instance method [{$class}@{$method->getName()}] is not public.");
}
if (!$this->canInstantiate($class)) {
throw new InvalidCallableException("Can't instantiate class [{$class->getName()}].");
}
return [$class->newInstance(), $method->getName()];
} | php | protected function getInstanceMethod(ReflectionClass $class, ReflectionMethod $method)
{
if (!$method->isPublic()) {
throw new InvalidCallableException("Instance method [{$class}@{$method->getName()}] is not public.");
}
if (!$this->canInstantiate($class)) {
throw new InvalidCallableException("Can't instantiate class [{$class->getName()}].");
}
return [$class->newInstance(), $method->getName()];
} | [
"protected",
"function",
"getInstanceMethod",
"(",
"ReflectionClass",
"$",
"class",
",",
"ReflectionMethod",
"$",
"method",
")",
"{",
"if",
"(",
"!",
"$",
"method",
"->",
"isPublic",
"(",
")",
")",
"{",
"throw",
"new",
"InvalidCallableException",
"(",
"\"Insta... | Get instance callable.
@param \ReflectionMethod $method
@return callable
@throws \Sofa\Eloquence\Mutator\InvalidCallableException | [
"Get",
"instance",
"callable",
"."
] | c2d361e8b2a7ae6aaa2324b78b401e944ef3bc69 | https://github.com/jarektkaczyk/eloquence-mutable/blob/c2d361e8b2a7ae6aaa2324b78b401e944ef3bc69/src/Mutator/Mutator.php#L136-L147 |
42,170 | jarektkaczyk/eloquence-mutable | src/Mutator/Mutator.php | Mutator.canInstantiate | protected function canInstantiate(ReflectionClass $class)
{
if (!$class->isInstantiable()) {
return false;
}
$constructor = $class->getConstructor();
return is_null($constructor) || 0 === $constructor->getNumberOfRequiredParameters();
} | php | protected function canInstantiate(ReflectionClass $class)
{
if (!$class->isInstantiable()) {
return false;
}
$constructor = $class->getConstructor();
return is_null($constructor) || 0 === $constructor->getNumberOfRequiredParameters();
} | [
"protected",
"function",
"canInstantiate",
"(",
"ReflectionClass",
"$",
"class",
")",
"{",
"if",
"(",
"!",
"$",
"class",
"->",
"isInstantiable",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"constructor",
"=",
"$",
"class",
"->",
"getConstructor",... | Determine whether instance can be instantiated.
@param \ReflectionClass $class
@return boolean | [
"Determine",
"whether",
"instance",
"can",
"be",
"instantiated",
"."
] | c2d361e8b2a7ae6aaa2324b78b401e944ef3bc69 | https://github.com/jarektkaczyk/eloquence-mutable/blob/c2d361e8b2a7ae6aaa2324b78b401e944ef3bc69/src/Mutator/Mutator.php#L155-L164 |
42,171 | jarektkaczyk/eloquence-mutable | src/Mutable.php | Mutable.bootMutable | public static function bootMutable()
{
if (!isset(static::$attributeMutator)) {
if (function_exists('app') && app()->bound('eloquence.mutator')) {
static::setAttributeMutator(app('eloquence.mutator'));
} else {
static::setAttributeMutator(new Mutator);
}
}
$hooks = new Hooks;
foreach (['setAttribute', 'getAttribute', 'toArray'] as $method) {
static::hook($method, $hooks->{$method}());
}
} | php | public static function bootMutable()
{
if (!isset(static::$attributeMutator)) {
if (function_exists('app') && app()->bound('eloquence.mutator')) {
static::setAttributeMutator(app('eloquence.mutator'));
} else {
static::setAttributeMutator(new Mutator);
}
}
$hooks = new Hooks;
foreach (['setAttribute', 'getAttribute', 'toArray'] as $method) {
static::hook($method, $hooks->{$method}());
}
} | [
"public",
"static",
"function",
"bootMutable",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"attributeMutator",
")",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'app'",
")",
"&&",
"app",
"(",
")",
"->",
"bound",
"(",
"'eloquence.... | Register hooks for the trait.
@codeCoverageIgnore
@return void | [
"Register",
"hooks",
"for",
"the",
"trait",
"."
] | c2d361e8b2a7ae6aaa2324b78b401e944ef3bc69 | https://github.com/jarektkaczyk/eloquence-mutable/blob/c2d361e8b2a7ae6aaa2324b78b401e944ef3bc69/src/Mutable.php#L29-L44 |
42,172 | jarektkaczyk/eloquence-mutable | src/Mutable.php | Mutable.mutableAttributesToArray | protected function mutableAttributesToArray(array $attributes)
{
foreach ($attributes as $key => $value) {
if ($this->hasGetterMutator($key)) {
$attributes[$key] = $this->mutableMutate($key, $value, 'getter');
}
}
return $attributes;
} | php | protected function mutableAttributesToArray(array $attributes)
{
foreach ($attributes as $key => $value) {
if ($this->hasGetterMutator($key)) {
$attributes[$key] = $this->mutableMutate($key, $value, 'getter');
}
}
return $attributes;
} | [
"protected",
"function",
"mutableAttributesToArray",
"(",
"array",
"$",
"attributes",
")",
"{",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasGetterMutator",
"(",
"$",
"key",
")",
")"... | Mutate mutable attributes for array conversion.
@param array $attributes
@return array | [
"Mutate",
"mutable",
"attributes",
"for",
"array",
"conversion",
"."
] | c2d361e8b2a7ae6aaa2324b78b401e944ef3bc69 | https://github.com/jarektkaczyk/eloquence-mutable/blob/c2d361e8b2a7ae6aaa2324b78b401e944ef3bc69/src/Mutable.php#L52-L61 |
42,173 | jarektkaczyk/eloquence-mutable | src/Mutable.php | Mutable.mutableMutate | protected function mutableMutate($key, $value, $dir)
{
$mutators = $this->getMutatorsForAttribute($key, $dir);
return static::$attributeMutator->mutate($value, $mutators);
} | php | protected function mutableMutate($key, $value, $dir)
{
$mutators = $this->getMutatorsForAttribute($key, $dir);
return static::$attributeMutator->mutate($value, $mutators);
} | [
"protected",
"function",
"mutableMutate",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"dir",
")",
"{",
"$",
"mutators",
"=",
"$",
"this",
"->",
"getMutatorsForAttribute",
"(",
"$",
"key",
",",
"$",
"dir",
")",
";",
"return",
"static",
"::",
"$",
"a... | Mutate the attribute.
@param string $key
@param string $value
@param string $dir
@return mixed | [
"Mutate",
"the",
"attribute",
"."
] | c2d361e8b2a7ae6aaa2324b78b401e944ef3bc69 | https://github.com/jarektkaczyk/eloquence-mutable/blob/c2d361e8b2a7ae6aaa2324b78b401e944ef3bc69/src/Mutable.php#L93-L98 |
42,174 | austinhyde/IniParser | src/IniParser.php | IniParser.parse | public function parse($file = null) {
if ($file !== null) {
$this->setFile($file);
}
if (empty($this->file)) {
throw new LogicException("Need a file to parse.");
}
$simple_parsed = parse_ini_file($this->file, true);
$inheritance_parsed = $this->parseSections($simple_parsed);
return $this->parseKeys($inheritance_parsed);
} | php | public function parse($file = null) {
if ($file !== null) {
$this->setFile($file);
}
if (empty($this->file)) {
throw new LogicException("Need a file to parse.");
}
$simple_parsed = parse_ini_file($this->file, true);
$inheritance_parsed = $this->parseSections($simple_parsed);
return $this->parseKeys($inheritance_parsed);
} | [
"public",
"function",
"parse",
"(",
"$",
"file",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"file",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"setFile",
"(",
"$",
"file",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"file",
")",
"... | Parses an INI file
@param string $file
@return array | [
"Parses",
"an",
"INI",
"file"
] | 3b5a925ac99619d198d8ff93958913ca3311f266 | https://github.com/austinhyde/IniParser/blob/3b5a925ac99619d198d8ff93958913ca3311f266/src/IniParser.php#L82-L93 |
42,175 | austinhyde/IniParser | src/IniParser.php | IniParser.process | public function process($src) {
$simple_parsed = parse_ini_string($src, true);
$inheritance_parsed = $this->parseSections($simple_parsed);
return $this->parseKeys($inheritance_parsed);
} | php | public function process($src) {
$simple_parsed = parse_ini_string($src, true);
$inheritance_parsed = $this->parseSections($simple_parsed);
return $this->parseKeys($inheritance_parsed);
} | [
"public",
"function",
"process",
"(",
"$",
"src",
")",
"{",
"$",
"simple_parsed",
"=",
"parse_ini_string",
"(",
"$",
"src",
",",
"true",
")",
";",
"$",
"inheritance_parsed",
"=",
"$",
"this",
"->",
"parseSections",
"(",
"$",
"simple_parsed",
")",
";",
"r... | Parses a string with INI contents
@param string $src
@return array | [
"Parses",
"a",
"string",
"with",
"INI",
"contents"
] | 3b5a925ac99619d198d8ff93958913ca3311f266 | https://github.com/austinhyde/IniParser/blob/3b5a925ac99619d198d8ff93958913ca3311f266/src/IniParser.php#L102-L106 |
42,176 | austinhyde/IniParser | src/IniParser.php | IniParser.parseSections | private function parseSections(array $simple_parsed) {
// do an initial pass to gather section names
$sections = array();
$globals = array();
foreach ($simple_parsed as $k => $v) {
if (is_array($v)) {
// $k is a section name
$sections[$k] = $v;
} else {
$globals[$k] = $v;
}
}
// now for each section, see if it uses inheritance
$output_sections = array();
foreach ($sections as $k => $v) {
$sects = array_map('trim', array_reverse(explode(':', $k)));
$root = array_pop($sects);
$arr = $v;
foreach ($sects as $s) {
if ($s === '^') {
$arr = array_merge($globals, $arr);
} elseif (array_key_exists($s, $output_sections)) {
$arr = array_merge($output_sections[$s], $arr);
} elseif (array_key_exists($s, $sections)) {
$arr = array_merge($sections[$s], $arr);
} else {
throw new UnexpectedValueException("IniParser: In file '{$this->file}', section '{$root}': Cannot inherit from unknown section '{$s}'");
}
}
if ($this->include_original_sections) {
$output_sections[$k] = $v;
}
$output_sections[$root] = $arr;
}
return $globals + $output_sections;
} | php | private function parseSections(array $simple_parsed) {
// do an initial pass to gather section names
$sections = array();
$globals = array();
foreach ($simple_parsed as $k => $v) {
if (is_array($v)) {
// $k is a section name
$sections[$k] = $v;
} else {
$globals[$k] = $v;
}
}
// now for each section, see if it uses inheritance
$output_sections = array();
foreach ($sections as $k => $v) {
$sects = array_map('trim', array_reverse(explode(':', $k)));
$root = array_pop($sects);
$arr = $v;
foreach ($sects as $s) {
if ($s === '^') {
$arr = array_merge($globals, $arr);
} elseif (array_key_exists($s, $output_sections)) {
$arr = array_merge($output_sections[$s], $arr);
} elseif (array_key_exists($s, $sections)) {
$arr = array_merge($sections[$s], $arr);
} else {
throw new UnexpectedValueException("IniParser: In file '{$this->file}', section '{$root}': Cannot inherit from unknown section '{$s}'");
}
}
if ($this->include_original_sections) {
$output_sections[$k] = $v;
}
$output_sections[$root] = $arr;
}
return $globals + $output_sections;
} | [
"private",
"function",
"parseSections",
"(",
"array",
"$",
"simple_parsed",
")",
"{",
"// do an initial pass to gather section names",
"$",
"sections",
"=",
"array",
"(",
")",
";",
"$",
"globals",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"simple_parsed"... | Parse sections and inheritance.
@param array $simple_parsed
@return array Parsed sections | [
"Parse",
"sections",
"and",
"inheritance",
"."
] | 3b5a925ac99619d198d8ff93958913ca3311f266 | https://github.com/austinhyde/IniParser/blob/3b5a925ac99619d198d8ff93958913ca3311f266/src/IniParser.php#L127-L166 |
42,177 | austinhyde/IniParser | src/IniParser.php | IniParser.parseValue | protected function parseValue($value) {
switch ($this->array_literals_behavior) {
case self::PARSE_JSON:
if (in_array(substr($value, 0, 1), array('[', '{')) && in_array(substr($value, -1), array(']', '}'))) {
if (defined('JSON_BIGINT_AS_STRING')) {
$output = json_decode($value, true, 512, JSON_BIGINT_AS_STRING);
} else {
$output = json_decode($value, true);
}
if ($output !== NULL) {
return $output;
}
}
// fallthrough
// try regex parser for simple estructures not JSON-compatible (ex: colors = [blue, green, red])
case self::PARSE_SIMPLE:
// if the value looks like [a,b,c,...], interpret as array
if (preg_match('/^\[\s*.*?(?:\s*,\s*.*?)*\s*\]$/', trim($value))) {
return array_map('trim', explode(',', trim(trim($value), '[]')));
}
break;
}
return $value;
} | php | protected function parseValue($value) {
switch ($this->array_literals_behavior) {
case self::PARSE_JSON:
if (in_array(substr($value, 0, 1), array('[', '{')) && in_array(substr($value, -1), array(']', '}'))) {
if (defined('JSON_BIGINT_AS_STRING')) {
$output = json_decode($value, true, 512, JSON_BIGINT_AS_STRING);
} else {
$output = json_decode($value, true);
}
if ($output !== NULL) {
return $output;
}
}
// fallthrough
// try regex parser for simple estructures not JSON-compatible (ex: colors = [blue, green, red])
case self::PARSE_SIMPLE:
// if the value looks like [a,b,c,...], interpret as array
if (preg_match('/^\[\s*.*?(?:\s*,\s*.*?)*\s*\]$/', trim($value))) {
return array_map('trim', explode(',', trim(trim($value), '[]')));
}
break;
}
return $value;
} | [
"protected",
"function",
"parseValue",
"(",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"array_literals_behavior",
")",
"{",
"case",
"self",
"::",
"PARSE_JSON",
":",
"if",
"(",
"in_array",
"(",
"substr",
"(",
"$",
"value",
",",
"0",
",",
... | Parses and formats the value in a key-value pair
@param string $value
@return mixed | [
"Parses",
"and",
"formats",
"the",
"value",
"in",
"a",
"key",
"-",
"value",
"pair"
] | 3b5a925ac99619d198d8ff93958913ca3311f266 | https://github.com/austinhyde/IniParser/blob/3b5a925ac99619d198d8ff93958913ca3311f266/src/IniParser.php#L238-L262 |
42,178 | awjudd/l4-feed-reader | src/FeedReader.php | FeedReader.read | public function read($url, $configuration = 'default')
{
// Setup the object
$sp = new SimplePie();
// Configure it
if(($cache = $this->setup_cache_directory($configuration)) !== false)
{
// Enable caching, and set the folder
$sp->enable_cache(true);
$sp->set_cache_location($cache);
$sp->set_cache_duration($this->read_config($configuration, 'cache.duration', 3600));
}
else
{
// Disable caching
$sp->enable_cache(false);
}
// Whether or not to force the feed reading
$sp->force_feed($this->read_config($configuration, 'force-feed', false));
// Should we be ordering the feed by date?
$sp->enable_order_by_date($this->read_config($configuration, 'order-by-date', false));
// Set the feed URL
$sp->set_feed_url($url);
// Grab it
$sp->init();
// We are done, so return it
return $sp;
} | php | public function read($url, $configuration = 'default')
{
// Setup the object
$sp = new SimplePie();
// Configure it
if(($cache = $this->setup_cache_directory($configuration)) !== false)
{
// Enable caching, and set the folder
$sp->enable_cache(true);
$sp->set_cache_location($cache);
$sp->set_cache_duration($this->read_config($configuration, 'cache.duration', 3600));
}
else
{
// Disable caching
$sp->enable_cache(false);
}
// Whether or not to force the feed reading
$sp->force_feed($this->read_config($configuration, 'force-feed', false));
// Should we be ordering the feed by date?
$sp->enable_order_by_date($this->read_config($configuration, 'order-by-date', false));
// Set the feed URL
$sp->set_feed_url($url);
// Grab it
$sp->init();
// We are done, so return it
return $sp;
} | [
"public",
"function",
"read",
"(",
"$",
"url",
",",
"$",
"configuration",
"=",
"'default'",
")",
"{",
"// Setup the object",
"$",
"sp",
"=",
"new",
"SimplePie",
"(",
")",
";",
"// Configure it",
"if",
"(",
"(",
"$",
"cache",
"=",
"$",
"this",
"->",
"se... | Used to parse an RSS feed.
@return \SimplePie | [
"Used",
"to",
"parse",
"an",
"RSS",
"feed",
"."
] | 83c67b4140680192df93ae47fa88ff39414e40fd | https://github.com/awjudd/l4-feed-reader/blob/83c67b4140680192df93ae47fa88ff39414e40fd/src/FeedReader.php#L19-L52 |
42,179 | awjudd/l4-feed-reader | src/FeedReader.php | FeedReader.setup_cache_directory | private function setup_cache_directory($configuration)
{
// Check if caching is enabled
$cache_enabled = $this->read_config($configuration, 'cache.enabled', false);
// Is caching enabled?
if(!$cache_enabled)
{
// It is disabled, so skip it
return false;
}
// Grab the cache location
$cache_location = storage_path($this->read_config($configuration, 'cache.location', 'rss-feeds'));
// Is the last character a slash?
if(substr($cache_location, -1) != DIRECTORY_SEPARATOR)
{
// Add in the slash at the end
$cache_location .= DIRECTORY_SEPARATOR;
}
// Check if the folder is available
if(!file_exists($cache_location))
{
// It didn't, so make it
mkdir($cache_location, 0777);
// Also add in a .gitignore file
file_put_contents($cache_location . '.gitignore', '!.gitignore' . PHP_EOL . '*');
}
return $cache_location;
} | php | private function setup_cache_directory($configuration)
{
// Check if caching is enabled
$cache_enabled = $this->read_config($configuration, 'cache.enabled', false);
// Is caching enabled?
if(!$cache_enabled)
{
// It is disabled, so skip it
return false;
}
// Grab the cache location
$cache_location = storage_path($this->read_config($configuration, 'cache.location', 'rss-feeds'));
// Is the last character a slash?
if(substr($cache_location, -1) != DIRECTORY_SEPARATOR)
{
// Add in the slash at the end
$cache_location .= DIRECTORY_SEPARATOR;
}
// Check if the folder is available
if(!file_exists($cache_location))
{
// It didn't, so make it
mkdir($cache_location, 0777);
// Also add in a .gitignore file
file_put_contents($cache_location . '.gitignore', '!.gitignore' . PHP_EOL . '*');
}
return $cache_location;
} | [
"private",
"function",
"setup_cache_directory",
"(",
"$",
"configuration",
")",
"{",
"// Check if caching is enabled",
"$",
"cache_enabled",
"=",
"$",
"this",
"->",
"read_config",
"(",
"$",
"configuration",
",",
"'cache.enabled'",
",",
"false",
")",
";",
"// Is cach... | Used in order to setup the cache directory for future use.
@param string The configuration to use
@return string The folder that is being cached to | [
"Used",
"in",
"order",
"to",
"setup",
"the",
"cache",
"directory",
"for",
"future",
"use",
"."
] | 83c67b4140680192df93ae47fa88ff39414e40fd | https://github.com/awjudd/l4-feed-reader/blob/83c67b4140680192df93ae47fa88ff39414e40fd/src/FeedReader.php#L60-L93 |
42,180 | gliterd/flysystem-backblaze | src/BackblazeAdapter.php | BackblazeAdapter.getFileInfo | protected function getFileInfo($file)
{
$normalized = [
'type' => 'file',
'path' => $file->getName(),
'timestamp' => substr($file->getUploadTimestamp(), 0, -3),
'size' => $file->getSize(),
];
return $normalized;
} | php | protected function getFileInfo($file)
{
$normalized = [
'type' => 'file',
'path' => $file->getName(),
'timestamp' => substr($file->getUploadTimestamp(), 0, -3),
'size' => $file->getSize(),
];
return $normalized;
} | [
"protected",
"function",
"getFileInfo",
"(",
"$",
"file",
")",
"{",
"$",
"normalized",
"=",
"[",
"'type'",
"=>",
"'file'",
",",
"'path'",
"=>",
"$",
"file",
"->",
"getName",
"(",
")",
",",
"'timestamp'",
"=>",
"substr",
"(",
"$",
"file",
"->",
"getUplo... | Get file info.
@param $file
@return array | [
"Get",
"file",
"info",
"."
] | 42549be7b3e6f372c824896ccd1d901052cb6d8c | https://github.com/gliterd/flysystem-backblaze/blob/42549be7b3e6f372c824896ccd1d901052cb6d8c/src/BackblazeAdapter.php#L255-L265 |
42,181 | baidubce/bce-sdk-php | src/BaiduBce/Services/Bos/BosClient.php | BosClient.generatePreSignedUrl | public function generatePreSignedUrl($bucketName, $key, $options = array())
{
list(
$config,
$headers,
$params,
$signOptions
) = $this->parseOptions(
$options,
BosOptions::CONFIG,
BosOptions::HEADERS,
BosOptions::PARAMS,
BosOptions::SIGN_OPTIONS
);
if(is_null($config)) {
$config = $this->config;
} else {
$config = array_merge($this->config, $config);
}
if(is_null($params)) {
$params = array();
}
if(is_null($headers)) {
$headers = array();
}
$path = $this->getPath($bucketName, $key);
list($hostUrl, $hostHeader) =
HttpUtils::parseEndpointFromConfig($config);
$headers[HttpHeaders::HOST] = $hostHeader;
$auth = $this->signer->sign(
$config[BceClientConfigOptions::CREDENTIALS],
HttpMethod::GET,
$path,
$headers,
$params,
$signOptions
);
$params['authorization'] = $auth;
$url = $hostUrl . HttpUtils::urlEncodeExceptSlash($path);
$queryString = HttpUtils::getCanonicalQueryString($params, false);
if ($queryString !== '') {
$url .= "?$queryString";
}
return $url;
} | php | public function generatePreSignedUrl($bucketName, $key, $options = array())
{
list(
$config,
$headers,
$params,
$signOptions
) = $this->parseOptions(
$options,
BosOptions::CONFIG,
BosOptions::HEADERS,
BosOptions::PARAMS,
BosOptions::SIGN_OPTIONS
);
if(is_null($config)) {
$config = $this->config;
} else {
$config = array_merge($this->config, $config);
}
if(is_null($params)) {
$params = array();
}
if(is_null($headers)) {
$headers = array();
}
$path = $this->getPath($bucketName, $key);
list($hostUrl, $hostHeader) =
HttpUtils::parseEndpointFromConfig($config);
$headers[HttpHeaders::HOST] = $hostHeader;
$auth = $this->signer->sign(
$config[BceClientConfigOptions::CREDENTIALS],
HttpMethod::GET,
$path,
$headers,
$params,
$signOptions
);
$params['authorization'] = $auth;
$url = $hostUrl . HttpUtils::urlEncodeExceptSlash($path);
$queryString = HttpUtils::getCanonicalQueryString($params, false);
if ($queryString !== '') {
$url .= "?$queryString";
}
return $url;
} | [
"public",
"function",
"generatePreSignedUrl",
"(",
"$",
"bucketName",
",",
"$",
"key",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"list",
"(",
"$",
"config",
",",
"$",
"headers",
",",
"$",
"params",
",",
"$",
"signOptions",
")",
"=",
"$",... | Get an authorization url with expire time
@param string $bucketName The bucket name.
@param string $object_name The object path.
@param number $timestamp
@param number $expiration_in_seconds The valid time in seconds.
@param mixed $options The extra Http request headers or params.
@return string | [
"Get",
"an",
"authorization",
"url",
"with",
"expire",
"time"
] | c3164434c8f0fe53b6ffe4479def893465137282 | https://github.com/baidubce/bce-sdk-php/blob/c3164434c8f0fe53b6ffe4479def893465137282/src/BaiduBce/Services/Bos/BosClient.php#L74-L122 |
42,182 | baidubce/bce-sdk-php | src/BaiduBce/Services/Bos/BosClient.php | BosClient.listBuckets | public function listBuckets($options = array())
{
list($config) = $this->parseOptions($options, BosOptions::CONFIG);
return $this->sendRequest(
HttpMethod::GET,
array(
BosOptions::CONFIG => $config
)
);
} | php | public function listBuckets($options = array())
{
list($config) = $this->parseOptions($options, BosOptions::CONFIG);
return $this->sendRequest(
HttpMethod::GET,
array(
BosOptions::CONFIG => $config
)
);
} | [
"public",
"function",
"listBuckets",
"(",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"list",
"(",
"$",
"config",
")",
"=",
"$",
"this",
"->",
"parseOptions",
"(",
"$",
"options",
",",
"BosOptions",
"::",
"CONFIG",
")",
";",
"return",
"$",
"thi... | List buckets of user.
@param array $options Supported options:
<ul>
<li>config: The optional bce configuration, which will overwrite
the default client configuration that was passed in constructor.
</li>
</ul>
@return object the server response. | [
"List",
"buckets",
"of",
"user",
"."
] | c3164434c8f0fe53b6ffe4479def893465137282 | https://github.com/baidubce/bce-sdk-php/blob/c3164434c8f0fe53b6ffe4479def893465137282/src/BaiduBce/Services/Bos/BosClient.php#L135-L145 |
42,183 | baidubce/bce-sdk-php | src/BaiduBce/Services/Bos/BosClient.php | BosClient.createBucket | public function createBucket($bucketName, $options = array())
{
list($config) = $this->parseOptions($options, BosOptions::CONFIG);
return $this->sendRequest(
HttpMethod::PUT,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName
)
);
} | php | public function createBucket($bucketName, $options = array())
{
list($config) = $this->parseOptions($options, BosOptions::CONFIG);
return $this->sendRequest(
HttpMethod::PUT,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName
)
);
} | [
"public",
"function",
"createBucket",
"(",
"$",
"bucketName",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"list",
"(",
"$",
"config",
")",
"=",
"$",
"this",
"->",
"parseOptions",
"(",
"$",
"options",
",",
"BosOptions",
"::",
"CONFIG",
")",
... | Create a new bucket.
@param string $bucketName The bucket name.
@param array $options Supported options:
<ul>
<li>config: The optional bce configuration, which will overwrite
the default client configuration that was passed in constructor.
</li>
</ul>
@return \stdClass | [
"Create",
"a",
"new",
"bucket",
"."
] | c3164434c8f0fe53b6ffe4479def893465137282 | https://github.com/baidubce/bce-sdk-php/blob/c3164434c8f0fe53b6ffe4479def893465137282/src/BaiduBce/Services/Bos/BosClient.php#L159-L170 |
42,184 | baidubce/bce-sdk-php | src/BaiduBce/Services/Bos/BosClient.php | BosClient.listObjects | public function listObjects($bucketName, $options = array())
{
list($config, $maxKeys, $prefix, $marker, $delimiter) =
$this->parseOptions(
$options,
BosOptions::CONFIG,
BosOptions::MAX_KEYS,
BosOptions::PREFIX,
BosOptions::MARKER,
BosOptions::DELIMITER
);
$params = array();
if ($maxKeys !== null) {
if (is_numeric($maxKeys)) {
$maxKeys = number_format($maxKeys);
$maxKeys = str_replace(',','',$maxKeys);
}
$params[BosOptions::MAX_KEYS] = $maxKeys;
}
if ($prefix !== null) {
$params[BosOptions::PREFIX] = $prefix;
}
if ($marker !== null) {
$params[BosOptions::MARKER] = $marker;
}
if ($delimiter !== null) {
$params[BosOptions::DELIMITER] = $delimiter;
}
return $this->sendRequest(
HttpMethod::GET,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName,
'params' => $params
)
);
} | php | public function listObjects($bucketName, $options = array())
{
list($config, $maxKeys, $prefix, $marker, $delimiter) =
$this->parseOptions(
$options,
BosOptions::CONFIG,
BosOptions::MAX_KEYS,
BosOptions::PREFIX,
BosOptions::MARKER,
BosOptions::DELIMITER
);
$params = array();
if ($maxKeys !== null) {
if (is_numeric($maxKeys)) {
$maxKeys = number_format($maxKeys);
$maxKeys = str_replace(',','',$maxKeys);
}
$params[BosOptions::MAX_KEYS] = $maxKeys;
}
if ($prefix !== null) {
$params[BosOptions::PREFIX] = $prefix;
}
if ($marker !== null) {
$params[BosOptions::MARKER] = $marker;
}
if ($delimiter !== null) {
$params[BosOptions::DELIMITER] = $delimiter;
}
return $this->sendRequest(
HttpMethod::GET,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName,
'params' => $params
)
);
} | [
"public",
"function",
"listObjects",
"(",
"$",
"bucketName",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"list",
"(",
"$",
"config",
",",
"$",
"maxKeys",
",",
"$",
"prefix",
",",
"$",
"marker",
",",
"$",
"delimiter",
")",
"=",
"$",
"this... | Get Object Information of bucket.
@param string $bucketName The bucket name.
@param mixed $options The optional bce configuration, which will overwrite the
default configuration that was passed while creating BosClient instance.
@property number $maxKeys The default value is 1000.
@property string $prefix The default value is null.
@property string $marker The default value is null.
@property string $delimiter The default value is null.
@property mixed $config The optional bce configuration, which will overwrite the
default configuration that was passed while creating BosClient instance.
@return mixed | [
"Get",
"Object",
"Information",
"of",
"bucket",
"."
] | c3164434c8f0fe53b6ffe4479def893465137282 | https://github.com/baidubce/bce-sdk-php/blob/c3164434c8f0fe53b6ffe4479def893465137282/src/BaiduBce/Services/Bos/BosClient.php#L186-L223 |
42,185 | baidubce/bce-sdk-php | src/BaiduBce/Services/Bos/BosClient.php | BosClient.doesBucketExist | public function doesBucketExist($bucketName, $options = array())
{
list($config) = $this->parseOptions($options, BosOptions::CONFIG);
try {
$this->sendRequest(
HttpMethod::HEAD,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName
)
);
return true;
} catch (BceServiceException $e) {
if ($e->getStatusCode() === 403) {
return true;
}
if ($e->getStatusCode() === 404) {
return false;
}
throw $e;
}
} | php | public function doesBucketExist($bucketName, $options = array())
{
list($config) = $this->parseOptions($options, BosOptions::CONFIG);
try {
$this->sendRequest(
HttpMethod::HEAD,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName
)
);
return true;
} catch (BceServiceException $e) {
if ($e->getStatusCode() === 403) {
return true;
}
if ($e->getStatusCode() === 404) {
return false;
}
throw $e;
}
} | [
"public",
"function",
"doesBucketExist",
"(",
"$",
"bucketName",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"list",
"(",
"$",
"config",
")",
"=",
"$",
"this",
"->",
"parseOptions",
"(",
"$",
"options",
",",
"BosOptions",
"::",
"CONFIG",
")"... | Check whether there is some user access to this bucket.
@param string $bucketName The bucket name.
@param mixed $options The optional bce configuration, which will overwrite the
default configuration that was passed while creating BosClient instance.
@return boolean true means the bucket does exists. | [
"Check",
"whether",
"there",
"is",
"some",
"user",
"access",
"to",
"this",
"bucket",
"."
] | c3164434c8f0fe53b6ffe4479def893465137282 | https://github.com/baidubce/bce-sdk-php/blob/c3164434c8f0fe53b6ffe4479def893465137282/src/BaiduBce/Services/Bos/BosClient.php#L233-L255 |
42,186 | baidubce/bce-sdk-php | src/BaiduBce/Services/Bos/BosClient.php | BosClient.deleteBucket | public function deleteBucket($bucketName, $options = array())
{
list($config) = $this->parseOptions($options, BosOptions::CONFIG);
return $this->sendRequest(
HttpMethod::DELETE,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName
)
);
} | php | public function deleteBucket($bucketName, $options = array())
{
list($config) = $this->parseOptions($options, BosOptions::CONFIG);
return $this->sendRequest(
HttpMethod::DELETE,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName
)
);
} | [
"public",
"function",
"deleteBucket",
"(",
"$",
"bucketName",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"list",
"(",
"$",
"config",
")",
"=",
"$",
"this",
"->",
"parseOptions",
"(",
"$",
"options",
",",
"BosOptions",
"::",
"CONFIG",
")",
... | Delete a Bucket
Must delete all the bbjects in this bucket before call this api
@param string $bucketName The bucket name.
@param mixed $options The optional bce configuration, which will overwrite the
default configuration that was passed while creating BosClient instance.
@return mixed | [
"Delete",
"a",
"Bucket",
"Must",
"delete",
"all",
"the",
"bbjects",
"in",
"this",
"bucket",
"before",
"call",
"this",
"api"
] | c3164434c8f0fe53b6ffe4479def893465137282 | https://github.com/baidubce/bce-sdk-php/blob/c3164434c8f0fe53b6ffe4479def893465137282/src/BaiduBce/Services/Bos/BosClient.php#L266-L277 |
42,187 | baidubce/bce-sdk-php | src/BaiduBce/Services/Bos/BosClient.php | BosClient.getBucketAcl | public function getBucketAcl($bucketName, $options = array())
{
list($config) = $this->parseOptions($options, BosOptions::CONFIG);
return $this->sendRequest(
HttpMethod::GET,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName,
'params' => array(
BosOptions::ACL => '',
)
)
);
} | php | public function getBucketAcl($bucketName, $options = array())
{
list($config) = $this->parseOptions($options, BosOptions::CONFIG);
return $this->sendRequest(
HttpMethod::GET,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName,
'params' => array(
BosOptions::ACL => '',
)
)
);
} | [
"public",
"function",
"getBucketAcl",
"(",
"$",
"bucketName",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"list",
"(",
"$",
"config",
")",
"=",
"$",
"this",
"->",
"parseOptions",
"(",
"$",
"options",
",",
"BosOptions",
"::",
"CONFIG",
")",
... | Get Access Control Level of bucket
@param string $bucketName The bucket name.
@param mixed $options The optional bce configuration, which will overwrite the
default configuration that was passed while creating BosClient instance.
@return mixed | [
"Get",
"Access",
"Control",
"Level",
"of",
"bucket"
] | c3164434c8f0fe53b6ffe4479def893465137282 | https://github.com/baidubce/bce-sdk-php/blob/c3164434c8f0fe53b6ffe4479def893465137282/src/BaiduBce/Services/Bos/BosClient.php#L344-L358 |
42,188 | baidubce/bce-sdk-php | src/BaiduBce/Services/Bos/BosClient.php | BosClient.getBucketLocation | public function getBucketLocation($bucketName, $options = array())
{
list($config) = $this->parseOptions($options, BosOptions::CONFIG);
$response = $this->sendRequest(
HttpMethod::GET,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName,
'params' => array(
BosOptions::LOCATION => '',
),
)
);
return $response->locationConstraint;
} | php | public function getBucketLocation($bucketName, $options = array())
{
list($config) = $this->parseOptions($options, BosOptions::CONFIG);
$response = $this->sendRequest(
HttpMethod::GET,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName,
'params' => array(
BosOptions::LOCATION => '',
),
)
);
return $response->locationConstraint;
} | [
"public",
"function",
"getBucketLocation",
"(",
"$",
"bucketName",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"list",
"(",
"$",
"config",
")",
"=",
"$",
"this",
"->",
"parseOptions",
"(",
"$",
"options",
",",
"BosOptions",
"::",
"CONFIG",
"... | Get Region of bucket
@param string $bucketName The bucket name.
@param mixed $options The optional bce configuration, which will overwrite the
default configuration that was passed while creating BosClient instance.
@return mixed | [
"Get",
"Region",
"of",
"bucket"
] | c3164434c8f0fe53b6ffe4479def893465137282 | https://github.com/baidubce/bce-sdk-php/blob/c3164434c8f0fe53b6ffe4479def893465137282/src/BaiduBce/Services/Bos/BosClient.php#L368-L382 |
42,189 | baidubce/bce-sdk-php | src/BaiduBce/Services/Bos/BosClient.php | BosClient.putObjectFromString | public function putObjectFromString(
$bucketName,
$key,
$data,
$options = array()
) {
return $this->putObject(
$bucketName,
$key,
$data,
strlen($data),
base64_encode(md5($data, true)),
$options
);
} | php | public function putObjectFromString(
$bucketName,
$key,
$data,
$options = array()
) {
return $this->putObject(
$bucketName,
$key,
$data,
strlen($data),
base64_encode(md5($data, true)),
$options
);
} | [
"public",
"function",
"putObjectFromString",
"(",
"$",
"bucketName",
",",
"$",
"key",
",",
"$",
"data",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"putObject",
"(",
"$",
"bucketName",
",",
"$",
"key",
",",
"$"... | Create object and put content of string to the object
@param string $bucketName The bucket name.
@param string $key The object path.
@param string $data The object content.
@param mixed $options The optional bce configuration, which will overwrite the
default configuration that was passed while creating BosClient instance.
@return mixed | [
"Create",
"object",
"and",
"put",
"content",
"of",
"string",
"to",
"the",
"object"
] | c3164434c8f0fe53b6ffe4479def893465137282 | https://github.com/baidubce/bce-sdk-php/blob/c3164434c8f0fe53b6ffe4479def893465137282/src/BaiduBce/Services/Bos/BosClient.php#L395-L409 |
42,190 | baidubce/bce-sdk-php | src/BaiduBce/Services/Bos/BosClient.php | BosClient.putObjectFromFile | public function putObjectFromFile(
$bucketName,
$key,
$filename,
$options = array()
) {
if (!isset($options[BosOptions::CONTENT_TYPE])) {
$options[BosOptions::CONTENT_TYPE] = MimeTypes::guessMimeType(
$filename
);
}
list($contentLength, $contentMd5) = $this->parseOptionsIgnoreExtra(
$options,
BosOptions::CONTENT_LENGTH,
BosOptions::CONTENT_MD5
);
if ($contentLength === null) {
$contentLength = filesize($filename);
} else {
if (!is_int($contentLength) && !is_long($contentLength)) {
throw new \InvalidArgumentException(
'$contentLength should be int or long.'
);
}
unset($options[BosOptions::CONTENT_LENGTH]);
}
$fp = fopen($filename, 'rb');
if ($contentMd5 === null) {
$contentMd5 = base64_encode(HashUtils::md5FromStream($fp, 0, $contentLength));
} else {
unset($options[BosOptions::CONTENT_MD5]);
}
try {
$response = $this->putObject(
$bucketName,
$key,
$fp,
$contentLength,
$contentMd5,
$options);
//streams are close in the destructor of stream object in guzzle
if (is_resource($fp)) {
fclose($fp);
}
return $response;
} catch (\Exception $e) {
if (is_resource($fp)) {
fclose($fp);
}
throw $e;
}
} | php | public function putObjectFromFile(
$bucketName,
$key,
$filename,
$options = array()
) {
if (!isset($options[BosOptions::CONTENT_TYPE])) {
$options[BosOptions::CONTENT_TYPE] = MimeTypes::guessMimeType(
$filename
);
}
list($contentLength, $contentMd5) = $this->parseOptionsIgnoreExtra(
$options,
BosOptions::CONTENT_LENGTH,
BosOptions::CONTENT_MD5
);
if ($contentLength === null) {
$contentLength = filesize($filename);
} else {
if (!is_int($contentLength) && !is_long($contentLength)) {
throw new \InvalidArgumentException(
'$contentLength should be int or long.'
);
}
unset($options[BosOptions::CONTENT_LENGTH]);
}
$fp = fopen($filename, 'rb');
if ($contentMd5 === null) {
$contentMd5 = base64_encode(HashUtils::md5FromStream($fp, 0, $contentLength));
} else {
unset($options[BosOptions::CONTENT_MD5]);
}
try {
$response = $this->putObject(
$bucketName,
$key,
$fp,
$contentLength,
$contentMd5,
$options);
//streams are close in the destructor of stream object in guzzle
if (is_resource($fp)) {
fclose($fp);
}
return $response;
} catch (\Exception $e) {
if (is_resource($fp)) {
fclose($fp);
}
throw $e;
}
} | [
"public",
"function",
"putObjectFromFile",
"(",
"$",
"bucketName",
",",
"$",
"key",
",",
"$",
"filename",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"BosOptions",
"::",
"CONTENT_TYPE",
"]",... | Put object and copy content of file to the object
@param string $bucketName The bucket name.
@param string $key The object path.
@param string $filename The absolute file path.
@param mixed $options The optional bce configuration, which will overwrite the
default configuration that was passed while creating BosClient instance.
@return mixed | [
"Put",
"object",
"and",
"copy",
"content",
"of",
"file",
"to",
"the",
"object"
] | c3164434c8f0fe53b6ffe4479def893465137282 | https://github.com/baidubce/bce-sdk-php/blob/c3164434c8f0fe53b6ffe4479def893465137282/src/BaiduBce/Services/Bos/BosClient.php#L422-L477 |
42,191 | baidubce/bce-sdk-php | src/BaiduBce/Services/Bos/BosClient.php | BosClient.putObject | public function putObject(
$bucketName,
$key,
$data,
$contentLength,
$contentMd5,
$options = array()
) {
if (empty($key)) {
throw new \InvalidArgumentException('$key should not be empty or null.');
}
if (!is_int($contentLength) && !is_long($contentLength)) {
throw new \InvalidArgumentException(
'$contentLength should be int or long.'
);
}
if ($contentLength < 0) {
throw new \InvalidArgumentException(
'$contentLength should not be negative.'
);
}
if (empty($contentMd5)) {
throw new \InvalidArgumentException(
'$contentMd5 should not be empty or null.'
);
}
$this->checkData($data);
$headers = array();
$headers[HttpHeaders::CONTENT_MD5] = $contentMd5;
$headers[HttpHeaders::CONTENT_LENGTH] = $contentLength;
$this->populateRequestHeadersWithOptions($headers, $options);
list($config) = $this->parseOptions($options, BosOptions::CONFIG);
return $this->sendRequest(
HttpMethod::PUT,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName,
'key' => $key,
'body' => $data,
'headers' => $headers,
)
);
} | php | public function putObject(
$bucketName,
$key,
$data,
$contentLength,
$contentMd5,
$options = array()
) {
if (empty($key)) {
throw new \InvalidArgumentException('$key should not be empty or null.');
}
if (!is_int($contentLength) && !is_long($contentLength)) {
throw new \InvalidArgumentException(
'$contentLength should be int or long.'
);
}
if ($contentLength < 0) {
throw new \InvalidArgumentException(
'$contentLength should not be negative.'
);
}
if (empty($contentMd5)) {
throw new \InvalidArgumentException(
'$contentMd5 should not be empty or null.'
);
}
$this->checkData($data);
$headers = array();
$headers[HttpHeaders::CONTENT_MD5] = $contentMd5;
$headers[HttpHeaders::CONTENT_LENGTH] = $contentLength;
$this->populateRequestHeadersWithOptions($headers, $options);
list($config) = $this->parseOptions($options, BosOptions::CONFIG);
return $this->sendRequest(
HttpMethod::PUT,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName,
'key' => $key,
'body' => $data,
'headers' => $headers,
)
);
} | [
"public",
"function",
"putObject",
"(",
"$",
"bucketName",
",",
"$",
"key",
",",
"$",
"data",
",",
"$",
"contentLength",
",",
"$",
"contentMd5",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"key",
")",
")",
... | Upload a object to one bucket
@param string $bucketName The bucket name.
@param string $key The object path.
@param string|resource $data The object content, which can be a string or a resource.
@param int $contentLength
@param string $contentMd5
@param mixed $options The optional bce configuration, which will overwrite the
default configuration that was passed while creating BosClient instance.
@return mixed | [
"Upload",
"a",
"object",
"to",
"one",
"bucket"
] | c3164434c8f0fe53b6ffe4479def893465137282 | https://github.com/baidubce/bce-sdk-php/blob/c3164434c8f0fe53b6ffe4479def893465137282/src/BaiduBce/Services/Bos/BosClient.php#L490-L534 |
42,192 | baidubce/bce-sdk-php | src/BaiduBce/Services/Bos/BosClient.php | BosClient.getObject | public function getObject(
$bucketName,
$key,
$outputStream,
$options = array()
) {
list($config, $range) = $this->parseOptions(
$options,
BosOptions::CONFIG,
BosOptions::RANGE
);
$headers = array();
if ($range !== null) {
switch(gettype($range)) {
case 'array':
if (!isset($range[0]) || !(is_int($range[0]) || is_long($range[0]))) {
throw new \InvalidArgumentException(
'range[0] is not defined.'
);
}
if (!isset($range[1]) || !(is_int($range[1]) || is_long($range[1]))) {
throw new \InvalidArgumentException(
'range[1] is not defined.'
);
}
$range = sprintf('%d-%d', $range[0], $range[1]);
break;
case 'string':
break;
default:
throw new \InvalidArgumentException(
'Option "range" should be either an array of two '
. 'integers or a string'
);
}
$headers[HttpHeaders::RANGE] = sprintf('bytes=%s', $range);
}
$response = $this->sendRequest(
HttpMethod::GET,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName,
'key' => $key,
'headers' => $headers,
'outputStream' => $outputStream,
'parseUserMetadata' => true
)
);
return $response;
} | php | public function getObject(
$bucketName,
$key,
$outputStream,
$options = array()
) {
list($config, $range) = $this->parseOptions(
$options,
BosOptions::CONFIG,
BosOptions::RANGE
);
$headers = array();
if ($range !== null) {
switch(gettype($range)) {
case 'array':
if (!isset($range[0]) || !(is_int($range[0]) || is_long($range[0]))) {
throw new \InvalidArgumentException(
'range[0] is not defined.'
);
}
if (!isset($range[1]) || !(is_int($range[1]) || is_long($range[1]))) {
throw new \InvalidArgumentException(
'range[1] is not defined.'
);
}
$range = sprintf('%d-%d', $range[0], $range[1]);
break;
case 'string':
break;
default:
throw new \InvalidArgumentException(
'Option "range" should be either an array of two '
. 'integers or a string'
);
}
$headers[HttpHeaders::RANGE] = sprintf('bytes=%s', $range);
}
$response = $this->sendRequest(
HttpMethod::GET,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName,
'key' => $key,
'headers' => $headers,
'outputStream' => $outputStream,
'parseUserMetadata' => true
)
);
return $response;
} | [
"public",
"function",
"getObject",
"(",
"$",
"bucketName",
",",
"$",
"key",
",",
"$",
"outputStream",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"list",
"(",
"$",
"config",
",",
"$",
"range",
")",
"=",
"$",
"this",
"->",
"parseOptions",
... | Get the object from a bucket.
@param string $bucketName The bucket name.
@param string $key The object path.
@param resource $outputStream
@param mixed $options The optional bce configuration, which will overwrite the
default configuration that was passed while creating BosClient instance.
@return mixed | [
"Get",
"the",
"object",
"from",
"a",
"bucket",
"."
] | c3164434c8f0fe53b6ffe4479def893465137282 | https://github.com/baidubce/bce-sdk-php/blob/c3164434c8f0fe53b6ffe4479def893465137282/src/BaiduBce/Services/Bos/BosClient.php#L546-L596 |
42,193 | baidubce/bce-sdk-php | src/BaiduBce/Services/Bos/BosClient.php | BosClient.getObjectAsString | public function getObjectAsString(
$bucketName,
$key,
$options = array()
) {
$outputStream = fopen('php://memory', 'r+');
try {
$this->getObject($bucketName, $key, $outputStream, $options);
rewind($outputStream);
$result = stream_get_contents($outputStream);
if (is_resource($outputStream)) {
fclose($outputStream);
}
return $result;
} catch (\Exception $e) {
if (is_resource($outputStream)) {
fclose($outputStream);
}
throw $e;
}
} | php | public function getObjectAsString(
$bucketName,
$key,
$options = array()
) {
$outputStream = fopen('php://memory', 'r+');
try {
$this->getObject($bucketName, $key, $outputStream, $options);
rewind($outputStream);
$result = stream_get_contents($outputStream);
if (is_resource($outputStream)) {
fclose($outputStream);
}
return $result;
} catch (\Exception $e) {
if (is_resource($outputStream)) {
fclose($outputStream);
}
throw $e;
}
} | [
"public",
"function",
"getObjectAsString",
"(",
"$",
"bucketName",
",",
"$",
"key",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"outputStream",
"=",
"fopen",
"(",
"'php://memory'",
",",
"'r+'",
")",
";",
"try",
"{",
"$",
"this",
"->",
... | Get the object cotent as string
@param string $bucketName The bucket name.
@param string $key The object path.
@param string $range If specified, only get the range part.
@param mixed $options The optional bce configuration, which will overwrite the
default configuration that was passed while creating BosClient instance.
@return mixed | [
"Get",
"the",
"object",
"cotent",
"as",
"string"
] | c3164434c8f0fe53b6ffe4479def893465137282 | https://github.com/baidubce/bce-sdk-php/blob/c3164434c8f0fe53b6ffe4479def893465137282/src/BaiduBce/Services/Bos/BosClient.php#L608-L628 |
42,194 | baidubce/bce-sdk-php | src/BaiduBce/Services/Bos/BosClient.php | BosClient.getObjectToFile | public function getObjectToFile(
$bucketName,
$key,
$filename,
$options = array()
)
{
$outputStream = fopen($filename, 'w+');
try {
$response = $this->getObject(
$bucketName,
$key,
$outputStream,
$options
);
if(is_resource($outputStream)) {
fclose($outputStream);
}
return $response;
} catch (\Exception $e) {
if(is_resource($outputStream)) {
fclose($outputStream);
}
throw $e;
}
} | php | public function getObjectToFile(
$bucketName,
$key,
$filename,
$options = array()
)
{
$outputStream = fopen($filename, 'w+');
try {
$response = $this->getObject(
$bucketName,
$key,
$outputStream,
$options
);
if(is_resource($outputStream)) {
fclose($outputStream);
}
return $response;
} catch (\Exception $e) {
if(is_resource($outputStream)) {
fclose($outputStream);
}
throw $e;
}
} | [
"public",
"function",
"getObjectToFile",
"(",
"$",
"bucketName",
",",
"$",
"key",
",",
"$",
"filename",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"outputStream",
"=",
"fopen",
"(",
"$",
"filename",
",",
"'w+'",
")",
";",
"try",
"{",... | Get Content of Object and Put Content to File
@param string $bucketName The bucket name.
@param string $key The object path.
@param string $filename The destination file name.
@param string $range The HTTP 'Range' header.
@param mixed $options The optional bce configuration, which will overwrite the
default configuration that was passed while creating BosClient instance.
@return mixed | [
"Get",
"Content",
"of",
"Object",
"and",
"Put",
"Content",
"to",
"File"
] | c3164434c8f0fe53b6ffe4479def893465137282 | https://github.com/baidubce/bce-sdk-php/blob/c3164434c8f0fe53b6ffe4479def893465137282/src/BaiduBce/Services/Bos/BosClient.php#L642-L667 |
42,195 | baidubce/bce-sdk-php | src/BaiduBce/Services/Bos/BosClient.php | BosClient.getObjectMetadata | public function getObjectMetadata($bucketName, $key, $options = array())
{
list($config) = $this->parseOptions($options, BosOptions::CONFIG);
$response = $this->sendRequest(
HttpMethod::HEAD,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName,
'key' => $key,
'parseUserMetadata' => true
)
);
return $response->metadata;
} | php | public function getObjectMetadata($bucketName, $key, $options = array())
{
list($config) = $this->parseOptions($options, BosOptions::CONFIG);
$response = $this->sendRequest(
HttpMethod::HEAD,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName,
'key' => $key,
'parseUserMetadata' => true
)
);
return $response->metadata;
} | [
"public",
"function",
"getObjectMetadata",
"(",
"$",
"bucketName",
",",
"$",
"key",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"list",
"(",
"$",
"config",
")",
"=",
"$",
"this",
"->",
"parseOptions",
"(",
"$",
"options",
",",
"BosOptions",
... | Get Object meta information
@param string $bucketName The bucket name.
@param string $key The object path.
@param mixed $options The optional bce configuration, which will overwrite the
default configuration that was passed while creating BosClient instance.
@return mixed | [
"Get",
"Object",
"meta",
"information"
] | c3164434c8f0fe53b6ffe4479def893465137282 | https://github.com/baidubce/bce-sdk-php/blob/c3164434c8f0fe53b6ffe4479def893465137282/src/BaiduBce/Services/Bos/BosClient.php#L706-L721 |
42,196 | baidubce/bce-sdk-php | src/BaiduBce/Services/Bos/BosClient.php | BosClient.copyObject | public function copyObject(
$sourceBucketName,
$sourceKey,
$targetBucketName,
$targetKey,
$options = array()
) {
if (empty($sourceBucketName)) {
throw new \InvalidArgumentException(
'$sourceBucketName should not be empty or null.'
);
}
if (empty($sourceKey)) {
throw new \InvalidArgumentException(
'$sourceKey should not be empty or null.'
);
}
if (empty($targetBucketName)) {
throw new \InvalidArgumentException(
'$targetBucketName should not be empty or null.'
);
}
if (empty($targetKey)) {
throw new \InvalidArgumentException(
'$targetKey should not be empty or null.'
);
}
list($config, $userMetadata, $etag, $storageClass) = $this->parseOptions(
$options,
BosOptions::CONFIG,
BosOptions::USER_METADATA,
BosOptions::ETAG,
BosOptions::STORAGE_CLASS
);
$headers = array();
$headers[HttpHeaders::BCE_COPY_SOURCE] =
HttpUtils::urlEncodeExceptSlash(
sprintf("/%s/%s", $sourceBucketName, $sourceKey)
);
if ($etag !== null) {
$etag = trim($etag, '"');
$headers[HttpHeaders::BCE_COPY_SOURCE_IF_MATCH] = '"' . $etag . '"';
}
if ($userMetadata === null) {
$headers[HttpHeaders::BCE_COPY_METADATA_DIRECTIVE] = 'copy';
} else {
$headers[HttpHeaders::BCE_COPY_METADATA_DIRECTIVE] = 'replace';
$this->populateRequestHeadersWithUserMetadata(
$headers,
$userMetadata
);
}
if ($storageClass !== null) {
$headers[HttpHeaders::BCE_STORAGE_CLASS] = $storageClass;
} else {
$headers[HttpHeaders::BCE_STORAGE_CLASS] = StorageClass::STANDARD;
}
return $this->sendRequest(
HttpMethod::PUT,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $targetBucketName,
'key' => $targetKey,
'headers' => $headers,
)
);
} | php | public function copyObject(
$sourceBucketName,
$sourceKey,
$targetBucketName,
$targetKey,
$options = array()
) {
if (empty($sourceBucketName)) {
throw new \InvalidArgumentException(
'$sourceBucketName should not be empty or null.'
);
}
if (empty($sourceKey)) {
throw new \InvalidArgumentException(
'$sourceKey should not be empty or null.'
);
}
if (empty($targetBucketName)) {
throw new \InvalidArgumentException(
'$targetBucketName should not be empty or null.'
);
}
if (empty($targetKey)) {
throw new \InvalidArgumentException(
'$targetKey should not be empty or null.'
);
}
list($config, $userMetadata, $etag, $storageClass) = $this->parseOptions(
$options,
BosOptions::CONFIG,
BosOptions::USER_METADATA,
BosOptions::ETAG,
BosOptions::STORAGE_CLASS
);
$headers = array();
$headers[HttpHeaders::BCE_COPY_SOURCE] =
HttpUtils::urlEncodeExceptSlash(
sprintf("/%s/%s", $sourceBucketName, $sourceKey)
);
if ($etag !== null) {
$etag = trim($etag, '"');
$headers[HttpHeaders::BCE_COPY_SOURCE_IF_MATCH] = '"' . $etag . '"';
}
if ($userMetadata === null) {
$headers[HttpHeaders::BCE_COPY_METADATA_DIRECTIVE] = 'copy';
} else {
$headers[HttpHeaders::BCE_COPY_METADATA_DIRECTIVE] = 'replace';
$this->populateRequestHeadersWithUserMetadata(
$headers,
$userMetadata
);
}
if ($storageClass !== null) {
$headers[HttpHeaders::BCE_STORAGE_CLASS] = $storageClass;
} else {
$headers[HttpHeaders::BCE_STORAGE_CLASS] = StorageClass::STANDARD;
}
return $this->sendRequest(
HttpMethod::PUT,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $targetBucketName,
'key' => $targetKey,
'headers' => $headers,
)
);
} | [
"public",
"function",
"copyObject",
"(",
"$",
"sourceBucketName",
",",
"$",
"sourceKey",
",",
"$",
"targetBucketName",
",",
"$",
"targetKey",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"sourceBucketName",
")",
")... | Copy one object to another.
@param string $sourceBucketName The source bucket name.
@param string $sourceKey The source object path.
@param string $targetBucketName The target bucket name.
@param string $targetKey The target object path.
@param mixed $options The optional bce configuration, which will overwrite the
default configuration that was passed while creating BosClient instance.
@return mixed | [
"Copy",
"one",
"object",
"to",
"another",
"."
] | c3164434c8f0fe53b6ffe4479def893465137282 | https://github.com/baidubce/bce-sdk-php/blob/c3164434c8f0fe53b6ffe4479def893465137282/src/BaiduBce/Services/Bos/BosClient.php#L735-L805 |
42,197 | baidubce/bce-sdk-php | src/BaiduBce/Services/Bos/BosClient.php | BosClient.initiateMultipartUpload | public function initiateMultipartUpload(
$bucketName,
$key,
$options = array()
) {
list($config, $storageClass) = $this->parseOptions(
$options,
BosOptions::CONFIG,
BosOptions::STORAGE_CLASS);
$headers = array(
HttpHeaders::CONTENT_TYPE => HttpContentTypes::OCTET_STREAM,
);
if ($storageClass !== null) {
$headers[HttpHeaders::BCE_STORAGE_CLASS] = $storageClass;
} else {
$headers[HttpHeaders::BCE_STORAGE_CLASS] = StorageClass::STANDARD;
}
return $this->sendRequest(
HttpMethod::POST,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName,
'key' => $key,
'headers' => $headers,
'params' => array('uploads' => ''),
)
);
} | php | public function initiateMultipartUpload(
$bucketName,
$key,
$options = array()
) {
list($config, $storageClass) = $this->parseOptions(
$options,
BosOptions::CONFIG,
BosOptions::STORAGE_CLASS);
$headers = array(
HttpHeaders::CONTENT_TYPE => HttpContentTypes::OCTET_STREAM,
);
if ($storageClass !== null) {
$headers[HttpHeaders::BCE_STORAGE_CLASS] = $storageClass;
} else {
$headers[HttpHeaders::BCE_STORAGE_CLASS] = StorageClass::STANDARD;
}
return $this->sendRequest(
HttpMethod::POST,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName,
'key' => $key,
'headers' => $headers,
'params' => array('uploads' => ''),
)
);
} | [
"public",
"function",
"initiateMultipartUpload",
"(",
"$",
"bucketName",
",",
"$",
"key",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"list",
"(",
"$",
"config",
",",
"$",
"storageClass",
")",
"=",
"$",
"this",
"->",
"parseOptions",
"(",
"$"... | Initialize multi_upload_file.
@param string $bucketName The bucket name.
@param string $key The object path.
@param mixed $options The optional bce configuration, which will overwrite the
default configuration that was passed while creating BosClient instance.
@return mixed | [
"Initialize",
"multi_upload_file",
"."
] | c3164434c8f0fe53b6ffe4479def893465137282 | https://github.com/baidubce/bce-sdk-php/blob/c3164434c8f0fe53b6ffe4479def893465137282/src/BaiduBce/Services/Bos/BosClient.php#L817-L846 |
42,198 | baidubce/bce-sdk-php | src/BaiduBce/Services/Bos/BosClient.php | BosClient.abortMultipartUpload | public function abortMultipartUpload(
$bucketName,
$key,
$uploadId,
$options = array()
) {
list($config) = $this->parseOptions($options, BosOptions::CONFIG);
return $this->sendRequest(
HttpMethod::DELETE,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName,
'key' => $key,
'params' => array('uploadId' => $uploadId),
)
);
} | php | public function abortMultipartUpload(
$bucketName,
$key,
$uploadId,
$options = array()
) {
list($config) = $this->parseOptions($options, BosOptions::CONFIG);
return $this->sendRequest(
HttpMethod::DELETE,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName,
'key' => $key,
'params' => array('uploadId' => $uploadId),
)
);
} | [
"public",
"function",
"abortMultipartUpload",
"(",
"$",
"bucketName",
",",
"$",
"key",
",",
"$",
"uploadId",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"list",
"(",
"$",
"config",
")",
"=",
"$",
"this",
"->",
"parseOptions",
"(",
"$",
"op... | Abort upload a part which is being uploading.
@param string $bucketName The bucket name.
@param string $key The object path.
@param string $uploadId The uploadId returned by initiateMultipartUpload.
@param mixed $options The optional bce configuration, which will overwrite the
default configuration that was passed while creating BosClient instance.
@return mixed | [
"Abort",
"upload",
"a",
"part",
"which",
"is",
"being",
"uploading",
"."
] | c3164434c8f0fe53b6ffe4479def893465137282 | https://github.com/baidubce/bce-sdk-php/blob/c3164434c8f0fe53b6ffe4479def893465137282/src/BaiduBce/Services/Bos/BosClient.php#L859-L876 |
42,199 | baidubce/bce-sdk-php | src/BaiduBce/Services/Bos/BosClient.php | BosClient.uploadPart | public function uploadPart(
$bucketName,
$key,
$uploadId,
$partNumber,
$contentLength,
$contentMd5,
$data,
$options = array()
) {
if (empty($bucketName)) {
throw new \InvalidArgumentException(
'$bucketName should not be empty or null.'
);
}
if (empty($key)) {
throw new \InvalidArgumentException(
'$key should not be empty or null.'
);
}
if (!is_int($contentLength) && !is_long($contentLength)) {
throw new \InvalidArgumentException(
'$contentLength should be int or long.'
);
}
if ($partNumber < BosClient::MIN_PART_NUMBER
|| $partNumber > BosClient::MAX_PART_NUMBER
) {
throw new \InvalidArgumentException(
sprintf(
'Invalid $partNumber %d. The valid range is from %d to %d.',
$partNumber,
BosClient::MIN_PART_NUMBER,
BosClient::MAX_PART_NUMBER
)
);
}
if ($contentMd5 === null) {
throw new \InvalidArgumentException(
'$contentMd5 should not be null.'
);
}
$this->checkData($data);
list($config) = $this->parseOptions($options, BosOptions::CONFIG);
$headers = array();
$headers[HttpHeaders::CONTENT_MD5] = $contentMd5;
$headers[HttpHeaders::CONTENT_LENGTH] = $contentLength;
$headers[HttpHeaders::CONTENT_TYPE] = HttpContentTypes::OCTET_STREAM;
return $this->sendRequest(
HttpMethod::PUT,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName,
'key' => $key,
'body' => $data,
'params' => array(
'partNumber' => $partNumber,
'uploadId' => $uploadId
),
'headers' => $headers,
)
);
} | php | public function uploadPart(
$bucketName,
$key,
$uploadId,
$partNumber,
$contentLength,
$contentMd5,
$data,
$options = array()
) {
if (empty($bucketName)) {
throw new \InvalidArgumentException(
'$bucketName should not be empty or null.'
);
}
if (empty($key)) {
throw new \InvalidArgumentException(
'$key should not be empty or null.'
);
}
if (!is_int($contentLength) && !is_long($contentLength)) {
throw new \InvalidArgumentException(
'$contentLength should be int or long.'
);
}
if ($partNumber < BosClient::MIN_PART_NUMBER
|| $partNumber > BosClient::MAX_PART_NUMBER
) {
throw new \InvalidArgumentException(
sprintf(
'Invalid $partNumber %d. The valid range is from %d to %d.',
$partNumber,
BosClient::MIN_PART_NUMBER,
BosClient::MAX_PART_NUMBER
)
);
}
if ($contentMd5 === null) {
throw new \InvalidArgumentException(
'$contentMd5 should not be null.'
);
}
$this->checkData($data);
list($config) = $this->parseOptions($options, BosOptions::CONFIG);
$headers = array();
$headers[HttpHeaders::CONTENT_MD5] = $contentMd5;
$headers[HttpHeaders::CONTENT_LENGTH] = $contentLength;
$headers[HttpHeaders::CONTENT_TYPE] = HttpContentTypes::OCTET_STREAM;
return $this->sendRequest(
HttpMethod::PUT,
array(
BosOptions::CONFIG => $config,
'bucket_name' => $bucketName,
'key' => $key,
'body' => $data,
'params' => array(
'partNumber' => $partNumber,
'uploadId' => $uploadId
),
'headers' => $headers,
)
);
} | [
"public",
"function",
"uploadPart",
"(",
"$",
"bucketName",
",",
"$",
"key",
",",
"$",
"uploadId",
",",
"$",
"partNumber",
",",
"$",
"contentLength",
",",
"$",
"contentMd5",
",",
"$",
"data",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"if... | Upload a part from a file handle
@param string $bucketName The bucket name.
@param string $key The object path.
@param string $uploadId The uploadId returned by initiateMultipartUpload.
@param int $partNumber The part index, 1-based.
@param int $contentLength The uploaded part size.
@param string $contentMd5 The part md5 check sum.
@param string $data The file pointer.
@param mixed $options The optional bce configuration, which will overwrite the
default configuration that was passed while creating BosClient instance.
@return mixed | [
"Upload",
"a",
"part",
"from",
"a",
"file",
"handle"
] | c3164434c8f0fe53b6ffe4479def893465137282 | https://github.com/baidubce/bce-sdk-php/blob/c3164434c8f0fe53b6ffe4479def893465137282/src/BaiduBce/Services/Bos/BosClient.php#L893-L960 |
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.