All Projects → juliangut → slim-doctrine

juliangut / slim-doctrine

Licence: BSD-3-Clause license
Slim-Doctrine managers integration

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to slim-doctrine

UnityLauncherPro
Unity Hub Alternative Project Launcher with time saving features!
Stars: ✭ 226 (+1312.5%)
Mutual labels:  manager
KoiCatalog
A card manager for Koikatu. View, search, and sort your collection of character cards.
Stars: ✭ 18 (+12.5%)
Mutual labels:  manager
modules
Java & REST API's for creating and running integrations
Stars: ✭ 16 (+0%)
Mutual labels:  integration
FractionalCalculus.jl
FractionalCalculus.jl: A Julia package for high performance, fast convergence and high precision numerical fractional calculus computing.
Stars: ✭ 22 (+37.5%)
Mutual labels:  integration
petstore
A simple skeleton to build api's based on the chubbyphp-framework, mezzio (former zend-expressive) or slim.
Stars: ✭ 34 (+112.5%)
Mutual labels:  doctrine
InitKit
Neo-InitWare is a modular, cross-platform reimplementation of the systemd init system. It is experimental.
Stars: ✭ 364 (+2175%)
Mutual labels:  manager
integreat-cms
Simplified content management back end for the Integreat App - a multilingual information platform for newcomers
Stars: ✭ 46 (+187.5%)
Mutual labels:  integration
Odin
manage model revisions with ease
Stars: ✭ 60 (+275%)
Mutual labels:  manager
mail2most
watch emails and send them to mattermost
Stars: ✭ 54 (+237.5%)
Mutual labels:  integration
bynder-php-sdk
SDK in PHP for integration with Bynder
Stars: ✭ 14 (-12.5%)
Mutual labels:  integration
jquery.filebrowser
File browser jQuery plugin
Stars: ✭ 29 (+81.25%)
Mutual labels:  manager
one-sdk-js
1️⃣ One Node.js SDK for all the APIs you want to integrate with
Stars: ✭ 41 (+156.25%)
Mutual labels:  integration
Passky-Desktop
Desktop application for Passky (password manager)
Stars: ✭ 47 (+193.75%)
Mutual labels:  manager
ghidra-r2web
Ghidra plugin to start an r2 webserver to let r2 interact with it
Stars: ✭ 38 (+137.5%)
Mutual labels:  integration
UrlManager
Javascript class for getting and setting url parameters
Stars: ✭ 15 (-6.25%)
Mutual labels:  manager
nette-oauth2-server-doctrine
Integration of The League of Extraordinary Packages' OAuth 2.0 Server into Nette Framework- Kdyby/Doctrine storage implementation
Stars: ✭ 13 (-18.75%)
Mutual labels:  doctrine
vue2-element
基于vue2 + vue-router2 + element-ui + vuex2 + fetch + webpack2 企业级后台管理系统最佳实践
Stars: ✭ 115 (+618.75%)
Mutual labels:  manager
reference-methodology
Integration projects today follow a time-consuming waterfall model, ill-suited to solving complex integration challenges. In response, WSO2 has developed organizational, project management, and technical expertise to help IT organizations transform integration projects to a more efficient and scalable continuous agile approach.
Stars: ✭ 46 (+187.5%)
Mutual labels:  integration
meilisearch-symfony
Seamless integration of Meilisearch into your Symfony project.
Stars: ✭ 65 (+306.25%)
Mutual labels:  integration
MDSL-Specification
A domain-specific language to specify (micro-)service contracts, data representations and endpoints.
Stars: ✭ 35 (+118.75%)
Mutual labels:  integration

PHP version Latest Version License

Build Status Style Check Code Quality Code Coverage

Total Downloads Monthly Downloads

Slim integration with Doctrine managers

Easy Slim framework integration with Doctrine's Entity Manager, MongoDB Document Manager and CouchDB Document Manager.

Important note

The latest version of slim-doctrine is focused only on Slim framework and Doctrine integration, and thus using the manager builders as stand alone is not possible.

That same functionality can be achieved by using juliangut/doctrine-manager-builder which is not tied to Slim framework.

Installation

Best way to install is using Composer:

composer require juliangut/slim-doctrine

Then require_once the autoload file:

require_once './vendor/autoload.php';

Configuration

Each kind of manager has its configurations stored on a key in the settings array

  • ManagerBuilder::DEFAULT_RELATIONAL_MANAGER_KEY ("entity_manager") for ORM
  • ManagerBuilder::DEFAULT_MONGODB_MANAGER_KEY ("mongodb_document_manager") for MongoDB ODM
  • ManagerBuilder::DEFAULT_COUCHDB_MANAGER_KEY ("couchdb_document_manager") for CouchDB ODM
[
    ManagerBuilder::DEFAULT_RELATIONAL_MANAGER_KEY => [
        'manager1_name' => <relational_manager_builder_configuration>,
        'manager2_name' => <relational_manager_builder_configuration>,
        ...
    ],
    ManagerBuilder::DEFAULT_MONGODB_MANAGER_KEY => [
        'manager3_name' => <mongodb_manager_builder_configuration>,
        'manager4_name' => <mongodb_manager_builder_configuration>,
        ...
    ],
    ManagerBuilder::DEFAULT_COUCHDB_MANAGER_KEY => [
        'manager5_name' => <couchdb_manager_builder_configuration>,
        'manager6_name' => <couchdb_manager_builder_configuration>,
        ...
    ],
]

If a manager is not given a name then a default one will be used:

  • ManagerBuilder::DEFAULT_RELATIONAL_MANAGER_NAME ("entityManager) for ORM
  • ManagerBuilder::DEFAULT_MONGODB_MANAGER_NAME ("mongoDocumentManager") for MongoDB ODM
  • ManagerBuilder::DEFAULT_COUCHDB_MANAGER_NAME ("couchDocumentManager") for CouchDB ODM

Options

ManagerBuilder's default keys and manager names can be modified providing constructor with an options array to change any of them

$options = [
    ManagerBuilder::RELATIONAL_MANAGER_KEY => 'entity_manager',
    ManagerBuilder::MONGODB_MANAGER_KEY => 'mongodb_document_manager',
    ManagerBuilder::COUCHDB_MANAGER_KEY => 'couchdb_document_manager',
    ManagerBuilder::RELATIONAL_MANAGER_NAME => 'entityManager',
    ManagerBuilder::MONGODB_MANAGER_NAME => 'mongoDocumentManager',
    ManagerBuilder::COUCHDB_MANAGER_NAME => 'couchDocumentManager',
];
$managerBuilder = new ManagerBuilder($options);

Manager builders

In order to configure the different Doctrine manager builders head to juliangut/doctrine-manager-builder which is used in this package.

Usage

Register managers in the DI container as any other service.

use Jgut\Slim\Doctrine\ManagerBuilder;
use Slim\App;

// Loaded from a file
$settings = [
    'my_custom_key' => [
        'annotation_autoloaders' => ['class_exists'],
        'connection' => [
            'driver' => 'pdo_sqlite',
            'memory' => true,
        ],
        'metadata_mapping' => [
            [
                'type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION,
                'path' => 'path/to/annotation/mappings',
            ],
        ],
    ],
];

$managerBuilder = new ManagerBuilder([ManagerBuilder::RELATIONAL_MANAGER_KEY => 'my_custom_key']);
$managerBuilder->loadSettings($settings);

// Create Slim app and fetch DI Container
$app = new App();
$container = $app->getContainer();

// Register every manager in the container
foreach ($managerBuilder->getManagers() as $name => $manager) {
    $container[$name] = $manager;
}

// Use managers
$app->get('/', function () {
    $this->entityManager->persist(new \Entity);
    $this->entityManager->flush();
});

Register manager builder in the DI container to delegate managers creation.

use Jgut\Slim\Doctrine\ManagerBuilder;
use Interop\Container\ContainerInterface;
use Slim\App;

// Probably loaded from a file...
$settings = [
    'settings.doctrineManagers' => [
        ManagerBuilder::DEFAULT_RELATIONAL_MANAGER_KEY => [
            'mainDocumentManager' => [
                'connection' => [
                    'server' => 'mongodb://localhost:27017',
                ],
                'metadata_mapping' => [
                    [
                        'type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION,
                        'path' => 'path/to/annotation/mappings',
                    ],
                ],
            ],
            'secondaryDocumentManager' => [
                'annotation_autoloaders' => ['class_exists'],
                'connection' => [
                    'server' => 'mongodb://localhost:27017',
                ],
                'metadata_mapping' => [
                    [
                        'type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION,
                        'path' => 'path/to/annotation/mappings',
                    ],
                ],
            ],
        ],
    ],
];

// Create Slim app and fetch DI Container
$app = new App($settings);
$container = $app->getContainer();

// Register manager builder fetching settings from container
$container['manager_builder'] => function (ContainerInterface $container) {
    return (new ManagerBuilder())->loadSettings($container->get('settings.doctrineManagers'));
};

// Register managers by pulling them from the builder
$container['mainDocumentManager'] => function (ContainerInterface $container) {
    return $container->get('manager_builder')->getManager('mainDocumentManager');
};
$container['secondaryDocumentManager'] => function (ContainerInterface $container) {
    return $container->get('manager_builder')->getManager('secondaryDocumentManager');
};

// Use managers
$app->get('/', function () {
    $this->mainDocumentManager->persist(new \Document);
    $this->mainDocumentManager->flush();
});

CLI Application builder

doctrine-manager is a CLI tool that is installed with this package. It provides the same functionality that Doctrine's ORM doctrine CLI tool does but it does not need ORM to be installed. Additionally doctrine-manager allows you to have numerous managers configured thanks to prepending manager name.

The way to using doctrine-manager is the same as with doctrine by creating a cli-config.php file returning a Symfony\Component\Console\Application

require __DIR__ . '/vendor/autoload.php';

use Jgut\Slim\Doctrine\ManagerBuilder;

$settings = require 'configurations.php';

$managerBuilder = (new ManagerBuilder())->loadSettings($settings);

return $managerBuilder->getCLIApplication();

Contributing

Found a bug or have a feature request? Please open a new issue. Have a look at existing issues before

See file CONTRIBUTING.md

Contributors

License

See file LICENSE included with the source code for a copy of the license terms

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].