/** * 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); }
/** * Constructor * * @param @inject ConfigInterface $config * @param @inject TimerInterface $timer */ public function __construct(ConfigInterface $config, TimerInterface $timer) { $this->machine = $config->getMachine(); if (!is_int($this->machine) || $this->machine < 0 || $this->machine > 1023) { throw new \InvalidArgumentException('Machine identifier invalid -- must be 10 bit integer (0 to 1023)'); } $this->timer = $timer; }
/** * @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; }
/** * Zumba\Swivel\Manager. * * @param ConfigInterface $config */ public function __construct(ConfigInterface $config) { $this->setLogger($config->getLogger()); $this->setBucket($config->getBucket()); if ($metrics = $config->getMetrics()) { $this->setMetrics($metrics); } $this->logger->debug('Swivel - Manager created.'); }
/** * Regenerate indexes for all invalid indexers * * @return void */ public function reindexAllInvalid() { foreach (array_keys($this->config->getIndexers()) as $indexerId) { $indexer = $this->indexerFactory->create(); $indexer->load($indexerId); if ($indexer->isInvalid()) { $indexer->reindexAll(); } } }
/** * 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; } }
/** * 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); }
/** * Dispatch event * * Calls all observer callbacks registered for this event * and multiple observers matching event name pattern * * @param string $eventName * @param array $data * @return void */ public function dispatch($eventName, array $data = array()) { \Magento\Framework\Profiler::start('EVENT:' . $eventName, array('group' => 'EVENT', 'name' => $eventName)); foreach ($this->_eventConfig->getObservers($eventName) as $observerConfig) { $event = new \Magento\Framework\Event($data); $event->setName($eventName); $wrapper = new Observer(); $wrapper->setData(array_merge(array('event' => $event), $data)); \Magento\Framework\Profiler::start('OBSERVER:' . $observerConfig['name']); $this->_invoker->dispatch($observerConfig, $wrapper); \Magento\Framework\Profiler::stop('OBSERVER:' . $observerConfig['name']); } \Magento\Framework\Profiler::stop('EVENT:' . $eventName); }
/** * {@inheritdoc} */ public function validate($postcode, $countryId) { $postCodes = $this->postCodesConfig->getPostCodes(); if (isset($postCodes[$countryId]) && is_array($postCodes[$countryId])) { $patterns = $postCodes[$countryId]; foreach ($patterns as $pattern) { preg_match('/' . $pattern['pattern'] . '/', $postcode, $matches); if (count($matches)) { return true; } } return false; } throw new \InvalidArgumentException('Provided countryId does not exist.'); }
public function dispatch($eventName, array $data = []) { \Magento\Framework\Profiler::start('EVENT:' . $eventName, ['group' => 'EVENT', 'name' => $eventName]); foreach ($this->_eventConfig->getObservers($eventName) as $observerConfig) { $event = new \Magento\Framework\Event($data); $event->setName($eventName); $wrapper = new \Magento\Framework\Event\Observer(); $wrapper->setData(array_merge(['event' => $event], $data)); \Magento\Framework\Profiler::start('OBSERVER:' . $observerConfig['name']); $this->_invoker->dispatch($observerConfig, $wrapper); $observerConfig['method'] = 'execute'; $this->_devHelper->setObserverDetails($observerConfig, $eventName); \Magento\Framework\Profiler::stop('OBSERVER:' . $observerConfig['name']); } \Magento\Framework\Profiler::stop('EVENT:' . $eventName); }
protected function parseFixers() { if (null !== $this->options['fixers']) { return array_map('trim', explode(',', $this->options['fixers'])); } if (null === $this->options['level']) { return $this->config->getFixers(); } return; }
/** * Check whether the session is expired * * @return bool */ public function isSessionExpired() { $lifetime = $this->securityConfig->getAdminSessionLifetime(); $currentTime = $this->dateTime->gmtTimestamp(); $lastUpdatedTime = $this->getUpdatedAt(); if (!is_numeric($lastUpdatedTime)) { $lastUpdatedTime = strtotime($lastUpdatedTime); } return $lastUpdatedTime <= $currentTime - $lifetime ? true : false; }
/** * Fill indexer data from config * * @param string $indexerId * @return IndexerInterface * @throws \InvalidArgumentException */ public function load($indexerId) { $indexer = $this->config->getIndexer($indexerId); if (empty($indexer) || empty($indexer['indexer_id']) || $indexer['indexer_id'] != $indexerId) { throw new \InvalidArgumentException("{$indexerId} indexer does not exist."); } $this->setId($indexerId); $this->setData($indexer); return $this; }
/** * Fill view data from config * * @param string $viewId * @return ViewInterface * @throws \InvalidArgumentException */ public function load($viewId) { $view = $this->config->getView($viewId); if (empty($view) || empty($view['view_id']) || $view['view_id'] != $viewId) { throw new \InvalidArgumentException("{$viewId} view does not exist."); } $this->setId($viewId); $this->setData($view); return $this; }
/** * Get the set of required options. * * @since 0.1.0 * * @return array|null */ public function getRequiredOptions() { if (!$this->required) { return null; } if ($this->required instanceof ConfigInterface) { return $this->required->getArrayCopy(); } return (array) $this->required; }
/** * Whether a configuration switch for a module output permits output or not * * @param string $moduleName Fully-qualified module name * @return boolean */ protected function _isCustomOutputConfigEnabled($moduleName) { if (isset($this->_outputConfigPaths[$moduleName])) { $configPath = $this->_outputConfigPaths[$moduleName]; if (defined($configPath)) { $configPath = constant($configPath); } return $this->_outputConfig->isSetFlag($configPath); } return true; }
/** * Return merged assets, if merging is enabled for a given content type * * @param MergeableInterface[] $assets * @param string $contentType * @return array|\Iterator * @throws \InvalidArgumentException */ public function getMergedAssets(array $assets, $contentType) { $isCss = $contentType == 'css'; $isJs = $contentType == 'js'; if (!$isCss && !$isJs) { throw new \InvalidArgumentException("Merge for content type '{$contentType}' is not supported."); } $isCssMergeEnabled = $this->config->isMergeCssFiles(); $isJsMergeEnabled = $this->config->isMergeJsFiles(); if ($isCss && $isCssMergeEnabled || $isJs && $isJsMergeEnabled) { if ($this->state->getMode() == \Magento\Framework\App\State::MODE_PRODUCTION) { $mergeStrategyClass = 'Magento\\Framework\\View\\Asset\\MergeStrategy\\FileExists'; } else { $mergeStrategyClass = 'Magento\\Framework\\View\\Asset\\MergeStrategy\\Checksum'; } $mergeStrategy = $this->objectManager->get($mergeStrategyClass); $assets = $this->objectManager->create('Magento\\Framework\\View\\Asset\\Merged', array('assets' => $assets, 'mergeStrategy' => $mergeStrategy)); } return $assets; }
/** * Get an address for the given request. * * @param AddressRequestInterface $request * @return AddressInterface[] * @throws InvalidAddressException when an adapter returned an invalid * address entity. * @throws AddressNotFoundException when no address can be found. */ public function getAddresses(AddressRequestInterface $request) { $adapter = null; $adapters = $this->adapterFactory->create($request); $addresses = []; foreach ($adapters as $adapter) { $addresses = $adapter->getAddresses($request); if (!empty($addresses)) { break; } } if (empty($addresses)) { throw new AddressNotFoundException('Could not find an address for the given request.'); } foreach ($addresses as $address) { if (!$address instanceof AddressInterface) { throw new InvalidAddressException(sprintf('Invalid address %s supplied by adapter: %s', get_class($address), get_class($adapter))); } } return array_slice($addresses, 0, $this->config->getMaxSuggestions()); }
/** * Get minification adapter by specified content type * * @param string $contentType * @return \Magento\Framework\Code\Minifier\AdapterInterface * @throws \Magento\Framework\Exception */ protected function getAdapter($contentType) { if (!isset($this->adapters[$contentType])) { $adapterClass = $this->config->getAssetMinificationAdapter($contentType); if (!$adapterClass) { throw new \Magento\Framework\Exception("Minification adapter is not specified for '{$contentType}' content type"); } $adapter = $this->objectManager->get($adapterClass); if (!$adapter instanceof \Magento\Framework\Code\Minifier\AdapterInterface) { $type = get_class($adapter); throw new \Magento\Framework\Exception("Invalid adapter: '{$type}'. Expected: \\Magento\\Framework\\Code\\Minifier\\AdapterInterface"); } $this->adapters[$contentType] = $adapter; } return $this->adapters[$contentType]; }
/** * Merge all chunks to single file * * @param string $destination final file location * * * @throws FileLockException * @throws FileOpenException * @throws \Exception * * @return bool indicates if file was saved */ public function save($destination) { $fh = fopen($destination, 'wb'); if (!$fh) { throw new FileOpenException('failed to open destination file: ' . $destination); } if (!flock($fh, LOCK_EX | LOCK_NB, $blocked)) { // @codeCoverageIgnoreStart if ($blocked) { // Concurrent request has requested a lock. // File is being processed at the moment. // Warning: lock is not checked in windows. return false; } // @codeCoverageIgnoreEnd throw new FileLockException('failed to lock file: ' . $destination); } $totalChunks = $this->request->getTotalChunks(); try { $preProcessChunk = $this->config->getPreprocessCallback(); for ($i = 1; $i <= $totalChunks; $i++) { $file = $this->getChunkPath($i); $chunk = fopen($file, "rb"); if (!$chunk) { throw new FileOpenException('failed to open chunk: ' . $file); } if ($preProcessChunk !== null) { call_user_func($preProcessChunk, $chunk); } stream_copy_to_stream($chunk, $fh); fclose($chunk); } } catch (\Exception $e) { flock($fh, LOCK_UN); fclose($fh); throw $e; } if ($this->config->getDeleteChunksOnSave()) { $this->deleteChunks(); } flock($fh, LOCK_UN); fclose($fh); return true; }
/** * @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; }
/** * 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()); }
/** * Extend a config by merging configuration data * * Note that this modifies the original config as opposed to creating a new config. * The config returned will be the same one you called `extend()` on but will have a * modified data and types. * * @access public * @param ConfigInterface $config The config with which to extend this one * @return Config the extended config */ public function extend(ConfigInterface $config) { $this->types = array_unique(array_merge($this->getTypes(), $config->getTypes())); $this->data = array_replace_recursive($this->getData(), $config->getData()); }
/** * Configure di instance * * @param array $configuration * @return void */ public function configure(array $configuration) { $this->_config->extend($configuration); }
/** * Load config by file * * @param string $filePath */ public function load($filePath) { parent::load($filePath); $this->config = $this->parse(include_once $filePath); }
/** * Constructor * * @param ConfigInterface $config */ public function __construct(ConfigInterface $config = null) { if ($config) { $config->configureServiceManager($this); } }
/** * Constructor * * @param \Magento\Framework\ObjectManager $objectManager * @param ConfigInterface $config */ public function __construct(\Magento\Framework\ObjectManager $objectManager, ConfigInterface $config) { $this->_objectManager = $objectManager; $this->_types = $config->getFileTypes(); }