Move all files to old/drupal/

This commit is contained in:
Oliver Davies 2025-10-02 07:57:25 +01:00
parent 8203e983d5
commit 7d76bf2968
468 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace Drupal\opdavies_blog\Service\PostPusher;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\opdavies_blog\Entity\Node\Post;
use Drupal\opdavies_blog\UseCase\ConvertPostToTweet;
use GuzzleHttp\ClientInterface;
use Webmozart\Assert\Assert;
final class IftttPostPusher extends WebhookPostPusher {
use StringTranslationTrait;
private ConfigFactoryInterface $configFactory;
public function __construct(
ConvertPostToTweet $convertPostToTweet,
ClientInterface $client,
ConfigFactoryInterface $configFactory
) {
$this->convertPostToTweet = $convertPostToTweet;
$this->configFactory = $configFactory;
parent::__construct($convertPostToTweet, $client);
}
public function push(Post $post): void {
$url = $this->configFactory
->get('opdavies_blog.settings')
->get('post_tweet_webhook_url');
Assert::notNull($url, 'Cannot push the post if there is no URL.');
$this->client->post($url, [
'form_params' => [
'value1' => $this->t('Blogged: @text', ['@text' => ($this->convertPostToTweet)($post)])
->render(),
],
]);
}
}

View file

@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace Drupal\opdavies_blog\Service\PostPusher;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\opdavies_blog\Entity\Node\Post;
use Drupal\opdavies_blog\UseCase\ConvertPostToTweet;
use GuzzleHttp\ClientInterface;
use Webmozart\Assert\Assert;
final class IntegromatPostPusher extends WebhookPostPusher {
use StringTranslationTrait;
private ConfigFactoryInterface $configFactory;
public function __construct(
ConvertPostToTweet $convertPostToTweet,
ClientInterface $client,
ConfigFactoryInterface $configFactory
) {
$this->convertPostToTweet = $convertPostToTweet;
$this->configFactory = $configFactory;
parent::__construct($convertPostToTweet, $client);
}
public function push(Post $post): void {
$url = $this->configFactory
->get('opdavies_blog.settings')
->get('integromat_webhook_url');
Assert::notNull($url, 'Cannot push the post if there is no URL.');
$this->client->post($url, [
'form_params' => [
'text' => $this->t('@text', ['@text' => ($this->convertPostToTweet)($post)])
->render(),
],
]);
}
}

View file

@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace Drupal\opdavies_blog\Service\PostPusher;
use Drupal\opdavies_blog\Entity\Node\Post;
final class NullPostPusher implements PostPusher {
public function push(Post $post): void {}
}

View file

@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace Drupal\opdavies_blog\Service\PostPusher;
use Drupal\opdavies_blog\Entity\Node\Post;
interface PostPusher {
public function push(Post $post): void;
}

View file

@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace Drupal\opdavies_blog\Service\PostPusher;
use Drupal\opdavies_blog\UseCase\ConvertPostToTweet;
use GuzzleHttp\ClientInterface;
abstract class WebhookPostPusher implements PostPusher {
protected ConvertPostToTweet $convertPostToTweet;
protected ClientInterface $client;
public function __construct(
ConvertPostToTweet $convertPostToTweet,
ClientInterface $client
) {
$this->convertPostToTweet = $convertPostToTweet;
$this->client = $client;
}
}