Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade 5.4 symfony and pull out EntityMapper #63

Merged
merged 3 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions ApixMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Islandora\Crayfish\Commons;

use Islandora\Chullo\IFedoraApi;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -21,12 +22,12 @@ class ApixMiddleware implements EventSubscriberInterface
/**
* @var \Islandora\Chullo\IFedoraApi
*/
protected $api;
protected IFedoraApi $api;

/**
* @var null|\Psr\Log\LoggerInterface
*/
protected $log;
protected ?LoggerInterface $log;

/**
* ApixFedoraResourceRetriever constructor.
Expand All @@ -42,7 +43,7 @@ public function __construct(
}

/**
*
* The steps to take when a subscribed request comes in.
* @param \Symfony\Component\HttpKernel\Event\RequestEvent $event
*/
public function before(RequestEvent $event)
Expand Down Expand Up @@ -91,7 +92,12 @@ public function before(RequestEvent $event)
$request->attributes->set('fedora_resource', $fedora_resource);
}

protected function getFedoraResource(Request $request)
/**
* Get the Fedora Resource defined in the Request.
* @param \Symfony\Component\HttpFoundation\Request $request The request.
* @return \Psr\Http\Message\ResponseInterface The response with the resource.
*/
protected function getFedoraResource(Request $request): ResponseInterface
{
// Pass along auth headers if present.
$headers = [];
Expand All @@ -108,9 +114,9 @@ protected function getFedoraResource(Request $request)
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public static function getSubscribedEvents()
public static function getSubscribedEvents(): array
{
return [
KernelEvents::REQUEST => [
Expand Down
10 changes: 6 additions & 4 deletions CmdExecuteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@ class CmdExecuteService
{

/**
* The logger.
* @var null|\Psr\Log\LoggerInterface
*/
protected $log;
protected ?LoggerInterface $log;

/**
* The output stream resource.
* @var resource
*/
protected $output;

/**
* Executor constructor.
* @param LoggerInterface $log
* @param \Psr\Log\LoggerInterface|null $log
*/
public function __construct(LoggerInterface $log = null)
{
Expand Down Expand Up @@ -52,7 +54,7 @@ public function getOutputStream()
* @return \Closure
* Closure that streams the output of the command.
*/
public function execute($cmd, $data)
public function execute($cmd, $data): \Closure
{
// Use pipes for STDIN, STDOUT, and STDERR
$descr = array(
Expand Down Expand Up @@ -132,7 +134,7 @@ public function execute($cmd, $data)
};
}

protected function cleanup($pipes, $process)
protected function cleanup($pipes, $process): void
{
// Close STDERR
fclose($pipes[2]);
Expand Down
4 changes: 2 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Configuration implements ConfigurationInterface
{

/**
* {@inheritdoc}
* @inheritDoc
*/
public function getConfigTreeBuilder()
{
Expand All @@ -18,7 +18,7 @@ public function getConfigTreeBuilder()
$root->addDefaultsIfNotSet()
->children()
->scalarNode('fedora_base_uri')->cannotBeEmpty()->defaultValue('http://localhost:8080/fcrepo/rest')->end()
->scalarNode('syn_config')->defaultValue(__DIR__ . '/../Resources/default_syn.xml')->end()
->booleanNode('apix_middleware_enabled')->defaultTrue()->end()
->end();

return $treeBuilder;
Expand Down
33 changes: 3 additions & 30 deletions DependencyInjection/CrayfishCommonsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,9 @@
namespace Islandora\Crayfish\Commons\DependencyInjection;

use Islandora\Chullo\IFedoraApi;
use Islandora\Crayfish\Commons\Client\GeminiClient;
use Islandora\Crayfish\Commons\CmdExecuteService;
use Islandora\Crayfish\Commons\EntityMapper\EntityMapper;
use Islandora\Crayfish\Commons\Syn\JwtAuthenticator;
use Islandora\Crayfish\Commons\Syn\JwtFactory;
use Islandora\Crayfish\Commons\Syn\JwtUserProvider;
use Islandora\Crayfish\Commons\Syn\SettingsParser;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class CrayfishCommonsExtension extends Extension
Expand All @@ -31,33 +23,14 @@ public function load(array $configs, ContainerBuilder $container)
);
$loader->load('crayfish_commons.yaml');

if (!$container->has('Islandora\Crayfish\Commons\Syn\SettingsParser')) {
if (file_exists($config['syn_config'])) {
$xml = file_get_contents($config['syn_config']);
} else {
throw new IOException("Security configuration not found. ${config['syn_config']}");
}

$container->register('Islandora\Crayfish\Commons\Syn\SettingsParser', SettingsParser::class)
->setArgument('$xml', $xml);
}

if (!$container->has('Islandora\Crayfish\Commons\Syn\JwtUserProvider')) {
$container->register('Islandora\Crayfish\Commons\Syn\JwtUserProvider', JwtUserProvider::class);
}
if (!$container->has('Islandora\Crayfish\Commons\Syn\JwtFactory')) {
$container->register('Islandora\Crayfish\Commons\Syn\JwtFactory', JwtFactory::class);
}
if (!$container->has('Islandora\Crayfish\Commons\Syn\JwtAuthenticator')) {
$container->register('Islandora\Crayfish\Commons\Syn\JwtAuthenticator', JwtAuthenticator::class)
->setAutowired(true);
}

if (!$container->has('Islandora\Chullo\IFedoraApi')) {
$container->register('Islandora\Chullo\IFedoraApi', IFedoraApi::class)
->setFactory('Islandora\Chullo\FedoraApi::create')
->setArgument('$fedora_rest_url', $config['fedora_base_uri']);
$container->setAlias('Islandora\Chullo\FedoraApi', 'Islandora\Chullo\IFedoraApi');
}
if ($config['apix_middleware_enabled'] === false && $container->has('Islandora\Crayfish\Commons\ApixMiddleware')) {
$container->removeDefinition('Islandora\Crayfish\Commons\ApixMiddleware');
}
}
}
37 changes: 0 additions & 37 deletions EntityMapper/EntityMapper.php

This file was deleted.

22 changes: 0 additions & 22 deletions EntityMapper/EntityMapperInterface.php

This file was deleted.

21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
![Crayfish](https://user-images.githubusercontent.com/2371345/48163075-11c6cf80-e2b5-11e8-8b5b-991b366014a5.png)
# Crayfish Commons

[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.3-8892BF.svg?style=flat-square)](https://php.net/)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.4-8892BF.svg?style=flat-square)](https://php.net/)
[![Build Status](https://github.com/islandora/crayfish-commons/actions/workflows/build-2.x.yml/badge.svg)](https://github.com/Islandora/crayfish-commons/actions)
[![Contribution Guidelines](http://img.shields.io/badge/CONTRIBUTING-Guidelines-blue.svg)](./CONTRIBUTING.md)
[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](./LICENSE)
Expand All @@ -13,30 +13,29 @@

Crayfish Commons is a library housing shared code for Crayfish microservices.
Shared Classes include:
* GeminiClient
* IslandoraServiceProvider
* YamlConfigServiceProvider
* JwtAuthenticator
* JwtFactory
* JwtUser
* SettingsParser
* ApixMiddleware
* CmdExecuteService

## Requirements

* PHP 7.2+
* PHP 7.4+
* [Composer](https://getcomposer.org/)

## Installation
Crayfish-commons can be installed with composer like `composer require islandora/crayfish-commons`

## Configuration
There is no related configuration as it serves as a dependency for microservices.
To configure this bundle in your Symfony application, add a file in the `config/packages` or
`config/packages/(prod|dev|test)` folder called `crayfish_commons.yaml`. The contents of this file will be
```yaml
crayfish_commons:
fedora_base_uri: 'http://your-fedora-base-uri'
apix_middleware_enabled: true
```

## Documentation

Further documentation for this module is available on the [Islandora 8 documentation site](https://islandora.github.io/documentation/).
Further documentation for this module is available on the [Islandora documentation site](https://islandora.github.io/documentation/).


## Troubleshooting/Issues
Expand Down
6 changes: 0 additions & 6 deletions Resources/config/crayfish_commons.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ services:
# Other services are loaded in the CrayfishCommonsExtension class.
Islandora\Crayfish\Commons\CmdExecuteService: ~

Islandora\Crayfish\Commons\EntityMapper\:
resource: '../../EntityMapper/*'

Islandora\Crayfish\Commons\ApixMiddleware:
tags:
- { name: kernel.event_subscriber, event: kernel.request }
Expand All @@ -20,6 +17,3 @@ services:
# in CrayfishCommonsExtension class
crayfish.cmd_execute_service:
alias: Islandora\Crayfish\Commons\CmdExecuteService

# Map the concrete class to the interface.
Islandora\Crayfish\Commons\EntityMapper\EntityMapperInterface: '@Islandora\Crayfish\Commons\EntityMapper\EntityMapper'
4 changes: 0 additions & 4 deletions Resources/default_syn.xml

This file was deleted.

Loading