/** * Creates a stream context based on the provided configuration. * * @param ConfigInterface $config The configuration. * * @return resource A stream context based on the provided configuration. */ public function create(ConfigInterface $config) { $streamContextOptions = $config->get('streamContextOptions'); $soapOptions = $config->get('soapClientOptions'); if (isset($soapOptions['stream_context'])) { throw new \UnexpectedValueException("Please use the 'streamContextOptions' setting to configure the soap client stream context."); } $headers = array(); $proxy = $config->get('proxy'); if (is_array($proxy)) { $streamContextOptions = array_merge_recursive($streamContextOptions, array('http' => array('proxy' => $proxy['proxy_host'] . ':' . $proxy['proxy_port']))); if (isset($proxy['proxy_login']) && isset($proxy['proxy_password'])) { // Support for proxy authentication is untested. The current implementation is based on // http://php.net/manual/en/function.stream-context-create.php#74431. $headers[] = 'Proxy-Authorization: Basic ' . base64_encode($proxy['proxy_login'] . ':' . $proxy['proxy_password']); } } if ((!isset($soapOptions['authentication']) || $soapOptions['authentication'] === SOAP_AUTHENTICATION_BASIC) && isset($soapOptions['login']) && isset($soapOptions['password'])) { $headers[] = 'Authorization: Basic ' . base64_encode($soapOptions['login'] . ':' . $soapOptions['password']); } if (count($headers) > 0) { $streamContextOptions['http']['header'] = $headers; } return stream_context_create($streamContextOptions); }
/** * Creates a stream context based on the provided configuration. * * @param ConfigInterface $config The configuration. * * @return resource A stream context based on the provided configuration. */ public function create(ConfigInterface $config) { $options = array(); $headers = array(); $proxy = $config->get('proxy'); if (is_array($proxy)) { $options = array('http' => array('proxy' => $proxy['proxy_host'] . ':' . $proxy['proxy_port'])); if (isset($proxy['proxy_login']) && isset($proxy['proxy_password'])) { // Support for proxy authentication is untested. The current implementation is based on // http://php.net/manual/en/function.stream-context-create.php#74431. $headers[] = 'Proxy-Authorization: Basic ' . base64_encode($proxy['proxy_login'] . ':' . $proxy['proxy_password']); } } $soapOptions = $config->get('soapClientOptions'); if ((!isset($soapOptions['authentication']) || $soapOptions['authentication'] === SOAP_AUTHENTICATION_BASIC) && isset($soapOptions['login']) && isset($soapOptions['password'])) { $headers[] = 'Authorization: Basic ' . base64_encode($soapOptions['login'] . ':' . $soapOptions['password']); } if (count($headers) > 0) { $options['http']['header'] = $headers; } // If we already created a stream context, make sure we use the same options. if (isset($soapOptions['stream_context'])) { $options = array_merge($options, stream_context_get_options($soapOptions['stream_context'])); } return stream_context_create($options); }
/** * Queries storage for a value mapped to a key. * * @param string $key */ public function get($key) { if (!isset($this->config)) { throw new ConfigException('Cfg neeeds a set Config object.'); } if (!isset($this->storage_name)) { throw new ConfigException('No storage name set.'); } return $this->config->get($this->storage_name, $key); }
/** * Retrieve the module's configuration container, or one of its entry. * * If a key is provided, return the configuration key value instead of the full object. * * @param string $key Optional. If provided, the config key value will be returned, instead of the full object. * @throws InvalidArgumentException If a config has not been defined. * @return \Charcoal\Config\ConfigInterface */ public function config($key = null) { if ($this->config === null) { throw new InvalidArgumentException('Configuration not set.'); } if ($key !== null) { return $this->config->get($key); } else { return $this->config; } }
/** * @param ConfigInterface $config * * @return DirectiveInterface * @throws Exception */ public function mergeInto(ConfigInterface $config) : DirectiveInterface { $identifier = static::class; $currentValue = $this->mergePolicy ? [] : $config->get($identifier, []); $currentValue[] = $this->value; $config->set($identifier, $currentValue); return $this; }
/** * Creates a stream context based on the provided configuration. * * @param ConfigInterface $config The configuration. * * @return resource A stream context based on the provided configuration. */ public function create(ConfigInterface $config) { $options = array(); $proxy = $config->get('proxy'); if (is_array($proxy)) { $options = array('http' => array('proxy' => $proxy['proxy_host'] . ':' . $proxy['proxy_port'])); if (isset($proxy['proxy_login']) && isset($proxy['proxy_password'])) { // Support for proxy authentication is untested. The current implementation is based on // http://php.net/manual/en/function.stream-context-create.php#74431. $options['http']['header'] = array('Proxy-Authorization: Basic ' . base64_encode($proxy['proxy_login'] . ':' . $proxy['proxy_password'])); } } return stream_context_create($options); }
/** * Merge the configuration from the other Config * @param \Packfire\Config\ConfigInterface $config The configuration to merge in * @since 1.2.0 */ public function merge(ConfigInterface $config) { $this->data = ArrayUtility::mergeRecursiveDistinct($this->data, $config->get()); }
/** * @param array $schema * A configuration schema from one or more Backup and Migrate plugins. * @param \BackupMigrate\Core\Config\ConfigInterface $config * @return array */ public static function buildFormFromSchema($schema, ConfigInterface $config, $parents = []) { $form = array(); foreach ($schema as $plugin_key => $plugin_schema) { // Get the configuration for the plugin to use as the form default values. $plugin_config = $config->get($plugin_key); // Add the specified groups. foreach ($plugin_schema['groups'] as $group_key => $item) { if (!isset($form[$group_key])) { $form[$group_key] = ['#type' => 'fieldset', '#title' => $item['title'], '#tree' => FALSE]; } } // Add each of the fields. foreach ($plugin_schema['fields'] as $field_key => $item) { $form_item = array(); $value = $plugin_config->get($field_key); switch ($item['type']) { case 'text': $form_item['#type'] = 'textfield'; if (!empty($item['multiple'])) { $form_item['#type'] = 'textarea'; $form_item['#description'] .= ' ' . t('Add one item per line.'); $form_item['#element_validate'] = [[new DrupalConfigHelper(), 'validateMultiText']]; $value = implode("\n", $plugin_config->get($field_key)); } if (!empty($item['multiline'])) { $form_item['#type'] = 'textarea'; } break; case 'password': $form_item['#type'] = 'password'; break; case 'number': $form_item['#type'] = 'textfield'; $form_item['#size'] = 5; if (!empty($item['max'])) { $form_item['#size'] = strlen((string) $item['max']) + 3; } break; case 'boolean': $form_item['#type'] = 'checkbox'; break; case 'enum': $form_item['#type'] = 'select'; $form_item['#multiple'] = !empty($item['multiple']); if (empty($item['#required']) && empty($item['multiple'])) { $item['options'] = array('' => '--' . t('None') . '--') + $item['options']; } $form_item['#options'] = $item['options']; break; } // If there is a form item add it to the form. if ($form_item) { // Add the common form elements. $form_item['#title'] = $item['title']; $form_item['#parents'] = array_merge($parents, array($plugin_key, $field_key)); $form_item['#required'] = !empty($item['required']); $form_item['#default_value'] = $value; if (!empty($item['description'])) { $form_item['#description'] = $item['description']; } // Add the field to it's group or directly to the top level of the form. if (!empty($item['group'])) { $form[$item['group']][$field_key] = $form_item; } else { $form[$field_key] = $form_item; } } } } return $form; }