Skip to content

Commit

Permalink
#29 add library
Browse files Browse the repository at this point in the history
  • Loading branch information
haringsrob committed Jan 13, 2017
1 parent b01cc96 commit c8cdb82
Show file tree
Hide file tree
Showing 35 changed files with 2,785 additions and 10 deletions.
10 changes: 0 additions & 10 deletions modules/integration_migrate/integration_migrate.info

This file was deleted.

8 changes: 8 additions & 0 deletions modules/integration_migrate/integration_migrate.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type: module
name: Integration Migrate
description: Contains stand-alone components for Migrate integration.
core: 8.x
package: Integration

dependencies:
- migrate
165 changes: 165 additions & 0 deletions src/Backend/AbstractBackend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?php

/**
* @file
* Contains \Drupal\integration\Backend\AbstractBackend.
*/

namespace Drupal\integration\Backend;

use Drupal\integration\Backend\Authentication\AuthenticationInterface;
use Drupal\integration\ConfigurablePluginInterface;
use Drupal\integration\Configuration\AbstractConfiguration;
use Drupal\integration\Exceptions\BackendException;
use Drupal\integration\ResourceSchema\ResourceSchemaFactory;

/**
* Class AbstractBackend.
*
* @package Drupal\integration\Backend
*/
abstract class AbstractBackend implements BackendInterface, ConfigurablePluginInterface {

/**
* Configuration component.
*
* @var Configuration\BackendConfiguration
*/
private $configuration;

/**
* Formatter component.
*
* @var Formatter\FormatterInterface
*/
private $formatter;

/**
* Authentication component.
*
* @var AuthenticationInterface
*/
private $authentication;

/**
* Constructor.
*
* @param Configuration\BackendConfiguration $configuration
* Configuration object.
* @param Formatter\FormatterInterface $formatter
* Formatter object.
* @param AuthenticationInterface $authentication
* Authentication handler object.
*/
public function __construct(Configuration\BackendConfiguration $configuration, Formatter\FormatterInterface $formatter, AuthenticationInterface $authentication) {
$this->setConfiguration($configuration);
$this->setFormatterHandler($formatter);
$this->setAuthenticationHandler($authentication);
}

/**
* {@inheritdoc}
*/
public function getConfiguration() {
return $this->configuration;
}

/**
* {@inheritdoc}
*/
public function setConfiguration(AbstractConfiguration $configuration) {
$this->configuration = $configuration;
}

/**
* {@inheritdoc}
*/
public function getFormatterHandler() {
return isset($this->formatter) ? $this->formatter : '';
}

/**
* {@inheritdoc}
*/
public function setFormatterHandler(Formatter\FormatterInterface $formatter) {
$this->formatter = $formatter;
}

/**
* {@inheritdoc}
*/
public function getAuthenticationHandler() {
return $this->authentication;
}

/**
* {@inheritdoc}
*/
public function setAuthenticationHandler(AuthenticationInterface $authentication) {
$this->authentication = $authentication;
}

/**
* Set backend setting value given its name and value.
*
* @param string $name
* Plugin setting name.
* @param mixed $value
* Plugin setting value.
*
* @return $this
*/
public function setBackendSetting($name, $value) {
$this->getConfiguration()->setPluginSetting("backend.$name", $value);
return $this;
}

/**
* Set resource schemas supported by this backend.
*
* @param string $resource_schema
* Resource schema machine name.
*
* @return $this
*/
public function setResourceSchema($resource_schema) {
$values = $this->getConfiguration()->getPluginSetting('resource_schemas');
$values[] = $resource_schema;
$this->getConfiguration()->setPluginSetting('resource_schemas', $values);
return $this;
}

/**
* Ser resource schema setting.
*
* @param string $resource_schema
* Resource schema machine name.
* @param string $name
* Setting name.
* @param string $value
* Setting name.
*
* @return $this
*/
public function setResourceSchemaSetting($resource_schema, $name, $value) {
$this->getConfiguration()->setPluginSetting("resource_schema.$resource_schema.$name", $value);
return $this;
}

/**
* {@inheritdoc}
*/
public function validateResourceSchema($machine_name) {
// Load configuration, throws and exception if not found.
ResourceSchemaFactory::getInstance($machine_name);

$values = $this->getConfiguration()->getPluginSetting('resource_schemas');
if (!in_array($machine_name, $values)) {
throw new BackendException(t('Resource schema "@machine_name" not supported by "@backend" backend.', [
'@machine_name' => $machine_name,
'@backend' => $this->getConfiguration()->getMachineName(),
]));
}
}

}
71 changes: 71 additions & 0 deletions src/Backend/Authentication/AbstractAuthentication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/**
* @file
* Contains \Drupal\integration\Backend\Authentication\AbstractAuthentication.
*/

namespace Drupal\integration\Backend\Authentication;

use Drupal\integration\Configuration\AbstractConfiguration;

/**
* Class AbstractAuthentication.
*
* @package Drupal\integration\Backend\Authentication
*/
abstract class AbstractAuthentication implements AuthenticationInterface {

/**
* Configuration object.
*
* @var AbstractConfiguration
*/
private $configuration;

/**
* Context data which will be passed to the authentication callback.
*
* @var array
*/
private $context;

/**
* AbstractAuthentication constructor.
*
* @param \Drupal\integration\Configuration\AbstractConfiguration $configuration
* AbstractConfiguration Class instance.
*/
public function __construct(AbstractConfiguration $configuration) {
$this->configuration = $configuration;
}

/**
* {@inheritdoc}
*/
public function getConfiguration() {
return $this->configuration;
}

/**
* {@inheritdoc}
*/
public function setConfiguration(AbstractConfiguration $configuration) {
$this->configuration = $configuration;
}

/**
* {@inheritdoc}
*/
public function getContext() {
return $this->context;
}

/**
* {@inheritdoc}
*/
public function setContext(array $context) {
$this->context = $context;
}

}
42 changes: 42 additions & 0 deletions src/Backend/Authentication/AuthenticationInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* @file
* Contains \Drupal\integration\Backend\Authentication\AuthenticationInterface.
*/

namespace Drupal\integration\Backend\Authentication;
use Drupal\integration\ConfigurablePluginInterface;

/**
* Interface AuthenticationInterface.
*
* @package Drupal\integration\Backend\Authentication
*/
interface AuthenticationInterface extends ConfigurablePluginInterface {

/**
* Authenticates and provides an authentication result.
*
* @return bool
* TRUE if authenticated, FALSE otherwise
*/
public function authenticate();

/**
* Get context data.
*
* @return array
* Context data array.
*/
public function getContext();

/**
* Set context data.
*
* @param array $context
* Context data array.
*/
public function setContext(array $context);

}
32 changes: 32 additions & 0 deletions src/Backend/Authentication/HttpAuthentication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* @file
* Contains \Drupal\integration\Backend\Authentication\HttpAuthentication.
*/

namespace Drupal\integration\Backend\Authentication;

/**
* Class HttpAuthentication.
*
* @package Drupal\integration\Backend\Authentication
*/
class HttpAuthentication extends AbstractAuthentication {

/**
* {@inheritdoc}
*/
public function authenticate() {
$configuration = $this->getConfiguration();
$username = $configuration->getComponentSetting('authentication_handler', 'username');
$password = $configuration->getComponentSetting('authentication_handler', 'password');

$context = $this->getContext();
list($protocol, $uri) = explode('://', $context['url']);
$context['url'] = "$protocol://$username:$password@$uri";
$this->setContext($context);
return TRUE;
}

}
24 changes: 24 additions & 0 deletions src/Backend/Authentication/NoAuthentication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* @file
* Contains \Drupal\integration\Backend\Authentication\NoAuthentication.
*/

namespace Drupal\integration\Backend\Authentication;

/**
* Class NoAuthentication.
*
* @package Drupal\integration\Backend\Authentication
*/
class NoAuthentication extends AbstractAuthentication {

/**
* {@inheritdoc}
*/
public function authenticate() {
return TRUE;
}

}
Loading

0 comments on commit c8cdb82

Please sign in to comment.