Adds the key_storage node with validation rules

key_storage MUST:
* implement Bitpay\Storage\StorageInterface
* be a class that can be loaded
558650
protected function addKeyStorageNode()
    {
        $builder = new TreeBuilder();
        $node    = $builder->root('key_storage', 'scalar');

        $node
            ->info('Class that is used to store your keys')
            ->defaultValue('Bitpay\Storage\EncryptedFilesystemStorage')
            ->validate()
                ->always()
                ->then(function ($value) {
                    if (!class_exists($value)) {
                        throw new \Exception(
                            sprintf(
                                'Could not find class "%s".',
                                $value
                            )
                        );
                    }

                    // requires PHP >= 5.3.7
                    if (!is_subclass_of($value, 'Bitpay\Storage\StorageInterface')) {
                        throw new \Exception(
                            sprintf(
                                '"%s" does not implement "Bitpay\Storage\StorageInterface"',
                                $value
                            )
                        );
                    }

                    return $value;
                })
            ->end();

        return $node;
    }
475642
public function addMessage($key, $message)
    {
        // Create Array for this key
        if (!isset($this->storage[$this->storageKey][$key])) {
            $this->storage[$this->storageKey][$key] = [];
        }

        // Push onto the array
        $this->storage[$this->storageKey][$key][] = $message;
    }
963267
public void addValidation(Object key, Validation validation){
        initMapOnce();
        validations.put(key, validation);
        // update aggregated value
        passedAll = passedAll && validation.passed();
    }
827103
protected function addExtraFormConstraintsNode()
    {
        $builder = new TreeBuilder();
        $node = $builder->root('constraints');

        $node
            ->defaultValue(array())
            ->useAttributeAsKey('id')
            ->prototype('array')
                ->children()
                    ->scalarNode('class')->isRequired()->end()
                    ->scalarNode('description')->defaultNull()->end()
                    ->arrayNode('extra_form_options')
                        ->defaultValue(array())
                        ->useAttributeAsKey('name')
                        ->prototype('array')
                            ->children()
                                ->scalarNode('extra_form_type')->isRequired()->end()
                                ->arrayNode('options')
                                    ->defaultValue(array())->useAttributeAsKey('id')->prototype('variable')->end()
                                ->end()
                            ->end()
                        ->end()
                    ->end()
                ->end()
            ->end()
        ;

        return $node;
    }
218802
protected static function init()
    {
        self::$_useDevelopmentStorageSetting = self::setting(
            Resources::USE_DEVELOPMENT_STORAGE_NAME,
            'true'
        );

        self::$_developmentStorageProxyUriSetting = self::settingWithFunc(
            Resources::DEVELOPMENT_STORAGE_PROXY_URI_NAME,
            Validate::getIsValidUri()
        );

        self::$_defaultEndpointsProtocolSetting = self::setting(
            Resources::DEFAULT_ENDPOINTS_PROTOCOL_NAME,
            'http', 'https'
        );

        self::$_accountNameSetting = self::setting(Resources::ACCOUNT_NAME_NAME);

        self::$_accountKeySetting = self::settingWithFunc(
            Resources::ACCOUNT_KEY_NAME,
            // base64_decode will return false if the $key is not in base64 format.
            function ($key) {
                $isValidBase64String = base64_decode($key, true);
                if ($isValidBase64String) {
                    return true;
                } else {
                    throw new \RuntimeException(
                        sprintf(Resources::INVALID_ACCOUNT_KEY_FORMAT, $key)
                    );
                }
            }
        );

        self::$_blobEndpointSetting = self::settingWithFunc(
            Resources::BLOB_ENDPOINT_NAME,
            Validate::getIsValidUri()
        );

        self::$_queueEndpointSetting = self::settingWithFunc(
            Resources::QUEUE_ENDPOINT_NAME,
            Validate::getIsValidUri()
        );

        self::$_tableEndpointSetting = self::settingWithFunc(
            Resources::TABLE_ENDPOINT_NAME,
            Validate::getIsValidUri()
        );

        self::$validSettingKeys[] = Resources::USE_DEVELOPMENT_STORAGE_NAME;
        self::$validSettingKeys[] = Resources::DEVELOPMENT_STORAGE_PROXY_URI_NAME;
        self::$validSettingKeys[] = Resources::DEFAULT_ENDPOINTS_PROTOCOL_NAME;
        self::$validSettingKeys[] = Resources::ACCOUNT_NAME_NAME;
        self::$validSettingKeys[] = Resources::ACCOUNT_KEY_NAME;
        self::$validSettingKeys[] = Resources::BLOB_ENDPOINT_NAME;
        self::$validSettingKeys[] = Resources::QUEUE_ENDPOINT_NAME;
        self::$validSettingKeys[] = Resources::TABLE_ENDPOINT_NAME;
    }
476422
public function addMapping(string $entity, string $storage, callable $toEntityCb = null, callable $toStorageCb = null): StorageReflection
	{
		if (isset($this->mappings[self::TO_ENTITY][$storage])) {
			throw new InvalidStateException("Mapping for $storage column is already defined.");
		} elseif (isset($this->mappings[self::TO_STORAGE][$entity])) {
			throw new InvalidStateException("Mapping for $entity property is already defined.");
		}

		$this->mappings[self::TO_ENTITY][$storage] = [$entity, $toEntityCb];
		$this->mappings[self::TO_STORAGE][$entity] = [$storage, $toStorageCb];
		return $this;
	}
506305
void addToInvalidates(Block b, DatanodeInfo n, boolean ackRequired) {
    addToInvalidatesNoLog(b, n, ackRequired);
    if (isInitialized && !isInSafeModeInternal()) {
      // do not log in startup phase
      NameNode.stateChangeLog.info("BLOCK* NameSystem.addToInvalidates: "
        + b.getBlockName() + " is added to invalidSet of " + n.getName());
    }
  }
185725
protected function insertNode()
    {
        $descendant = $this->getKey();
        $ancestor = (isset($this->parent_id) ? $this->parent_id : $descendant);

        $this->closure->insertNode($ancestor, $descendant);
    }
1336639
private function validateNode($node, CustomArrayObject $schema, $element = [])
    {
        $nodeSchema = new CustomArrayObject($schema[$node]);

        foreach ($nodeSchema->getArrayKeys() as $key) {
            $this->currentNode = $node . '.' . $key;
            $this->getLogger()->info("We are in element: {$this->currentNode}");

            $nodeData = isset($element[$key]) ? $element[$key] : null;


            $this->validateTypeFieldIsPresent($nodeSchema[$key]);

            $validator = $this->getClassValidator($nodeSchema[$key]);
            $validator->setParams($this->params);

            $isRequired = $this->requiredMode ? $validator->isRequired() : false;

            if ($isRequired === false && empty($nodeData)) {
                $this->getLogger()->info("Element: {$this->currentNode} has empty non-required data. We skip other check");
                continue;
            }

            $this->validateRequiredFieldIsPresent($nodeData);

            $this->validateExcessiveKeys($validator, new CustomArrayObject($nodeSchema[$key]), $nodeData);

            $this->validateNodeValue($validator, $nodeData);

            $this->validateNesting($validator, $nodeData);

            if ($validator->isNested()) {
                $this->getLogger()->info("Element: {$this->currentNode} has children");

                foreach ($nodeData as $record) {
                    $this->validateNode($key, $nodeSchema, $record);
                }
            } else {
                $this->validateNode($key, $nodeSchema, $nodeData);
            }

            $this->getLogger()->info("Element: {$this->currentNode} finished checking successfully.");
        }
    }
506541
protected function addExtraFormTypesNode()
    {
        $builder = new TreeBuilder();
        $node = $builder->root('types');

        $node
            ->defaultValue(array())
            ->useAttributeAsKey('id')
            ->prototype('array')
                ->children()
                    ->scalarNode('parent')->defaultNull()->end()
                    ->scalarNode('form_type')->isRequired()->end()
                    ->booleanNode('abstract')->defaultFalse()->end()
                    ->scalarNode('description')->defaultNull()->end()
                    ->scalarNode('icon')->defaultNull()->end()
                    ->arrayNode('extra_form_options')
                        ->defaultValue(array())
                        ->useAttributeAsKey('id')
                        ->prototype('array')
                            ->children()
                                ->scalarNode('extra_form_type')->isRequired()->end()
                                ->arrayNode('options')
                                    ->defaultValue(array())->useAttributeAsKey('id')->prototype('variable')->end()
                                ->end()
                            ->end()
                        ->end()
                    ->end()
                ->end()
            ->end()
        ;

        return $node;
    }
1099943
public function index()
    {
        if (!userHasPermission('admin:cdn:settings:*')) {
            unauthorised();
        }

        $oInput         = Factory::service('Input');
        $oStorageDriver = Factory::service('StorageDriver', 'nails/module-cdn');

        if ($oInput->post()) {

            try {

                $sKeyStorageDriver = $oStorageDriver->getSettingKey();
                $oFormValidation   = Factory::service('FormValidation');
                $oFormValidation->set_rules($sKeyStorageDriver, '', 'required');

                if (!$oFormValidation->run()) {
                    throw new ValidationException(lang('fv_there_were_errors'));
                }

                $oStorageDriver->saveEnabled($oInput->post($sKeyStorageDriver));
                $this->data['success'] = 'CDN settings were saved.';

            } catch (\Exception $e) {
                $this->data['error'] = 'There was a problem saving settings: ' . $e->getMessage();
            }
        }

        // --------------------------------------------------------------------------

        //  Get data
        $this->data['settings'] = appSetting(null, 'nails/module-cdn', true);

        Helper::loadView('index');
    }
1344397
public function build(): SetDOMStorageItemRequest
	{
		$instance = new SetDOMStorageItemRequest();
		if ($this->storageId === null) {
			throw new BuilderException('Property [storageId] is required.');
		}
		$instance->storageId = $this->storageId;
		if ($this->key === null) {
			throw new BuilderException('Property [key] is required.');
		}
		$instance->key = $this->key;
		if ($this->value === null) {
			throw new BuilderException('Property [value] is required.');
		}
		$instance->value = $this->value;
		return $instance;
	}
854154
private function addObjectsSection(ArrayNodeDefinition $node)
    {
        $node
            ->children()
                ->arrayNode('objects')
                    ->addDefaultsIfNotSet()
                    ->children()
                        ->arrayNode('contact')
                            ->addDefaultsIfNotSet()
                            ->children()
                                ->scalarNode('model')->defaultValue(Contact::class)->end()
                                ->scalarNode('repository')->defaultValue(ContactRepository::class)->end()
                            ->end()
                        ->end()
                        ->arrayNode('account')
                            ->addDefaultsIfNotSet()
                            ->children()
                                ->scalarNode('model')->defaultValue(Account::class)->end()
                                ->scalarNode('repository')->defaultValue(AccountRepository::class)->end()
                            ->end()
                        ->end()
                    ->end()
                ->end()
            ->end();
    }
364494
protected function wizardAddCollection()
    {
        $this->validatePrompt('title', $this->text('Title'), 'collection');
        $this->validateMenu('type', $this->text('Type'), 'collection', $this->collection->getTypes());
        $this->validatePrompt('store_id', $this->text('Store'), 'collection');
        $this->validatePrompt('description', $this->text('Description'), 'collection', '');
        $this->validatePrompt('status', $this->text('Status'), 'collection', 0);

        $this->validateComponent('collection');
        $this->addCollection();
    }
107921
public function add()
    {
        $this->request->allowMethod('post');

        $entity = $this->SavedSearches->newEntity();
        $entity = $this->SavedSearches->patchEntity($entity, (array)$this->request->getData());
        $success = (bool)$this->SavedSearches->save($entity);

        $this->set('success', $success);
        $success ?
            $this->set('data', ['id' => $entity->get('id')]) :
            $this->set('error', $entity->getErrors());
        $this->set('_serialize', ['success', 'data', 'error']);
    }
460053
public void addCACertificatesToTrustStore(BufferedInputStream bis) throws CryptoException, InvalidArgumentException {

        if (bis == null) {
            throw new InvalidArgumentException("The certificate stream bis cannot be null");
        }

        try {
            final Collection<? extends Certificate> certificates = cf.generateCertificates(bis);
            for (Certificate certificate : certificates) {
                addCACertificateToTrustStore(certificate);
            }

        } catch (CertificateException e) {
            throw new CryptoException("Unable to add CA certificate to trust store. Error: " + e.getMessage(), e);
        }
    }
940311
def store_with(name, storage_id = nil, &block)
      @storages << get_class_from_scope(Storage, name)
        .new(self, storage_id, &block)
    end