Giter Site home page Giter Site logo

dflydev-doctrine-orm-service-provider's People

Contributors

andrewshell avatar arsfeld avatar bc-luke avatar damiankloip avatar ftaiolivista avatar iolloyd avatar lauris avatar localheinz avatar marabesi avatar marcojanssen avatar mintbridge avatar mrkrstphr avatar simensen avatar straccio avatar taluu avatar uuf6429 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dflydev-doctrine-orm-service-provider's Issues

Compatibility with silex 2

This service provider seems to be not compatible with silex 2 because of requirement of pimple version 1.

Is there a plan to upgrade?

Provider is not compattible with last Silex

Hi,

When I'm trying to install ORM provider I'm getting an error:
Catchable fatal error: Argument 1 passed to Silex\Application::register() must implement interface Silex\ServiceProviderInterface, instance of Dflydev\Pimple\Provider\DoctrineOrm\DoctrineOrmServiceProvider given

Is there a chance for fix this problem? Thank you!

custom hydration not working

Hi! I wrote code for a custom hydrator, but following your steps, it still produces an error, saying that my hydrator is an invalid one. Upon dumping orm.em, I found that customHydrationModes array is empty.

Problem with 1.0.*@dev

This is the stacktrace:

/mnt/workspace/bitbucket/qnoow/brain/vendor/pimple/pimple/lib/Pimple.php 78 Identifier "default" is not defined.
#0 /mnt/workspace/bitbucket/qnoow/brain/vendor/dflydev/doctrine-orm-service-provider/src/Dflydev/Pimple/Provider/DoctrineOrm/DoctrineOrmServiceProvider.php(107): Pimple->offsetGet('default')
#1 /mnt/workspace/bitbucket/qnoow/brain/vendor/pimple/pimple/lib/Pimple.php(126): Dflydev\Pimple\Provider\DoctrineOrm\DoctrineOrmServiceProvider->Dflydev\Pimple\Provider\DoctrineOrm\{closure}(Object(Pimple))
...

Setting required version to @stable fixed the issue. May be an config issue?

Simple annotation entity, porting to Symfony

Hi,
This is really not an issue or bug. I am trying to port a silex simple annotation entities without changing any code or "use" statement by importing all the annotation to a Symfony application.

Is there any we can do that ?

question : how to set redis options ?

Hi,

I try to set this redis option in my provider declaration :

  • host
  • port
  • password
    but It doesn't work, I got this error

Uncaught exception 'RuntimeException' with message 'Host and port options need to be specified for redis cache'

Where I have to set this option ?
Thanks for your answers.

I try this :

$app->register(new DoctrineOrmServiceProvider(), array(
    'orm.proxies_dir' => __DIR__."/../../cache/doctrineProxies",
    'orm.proxies_namespace' => $app['env'],
    'orm.auto_generate_proxies' => $app['debug'],
    'orm.default_cache' => getenv('REDIS_CACHE') ? 'redis' : 'array',
    'host' => getenv('REDIS_HOST'),
    'port' => getenv('REDIS_PORT'),
    'password' => getenv('REDIS_PASSWORD'),
    'orm.em.options' => array(
        'cache_namespace' => $app['env'].'_',
        'mappings' => array(
            array(
                'type' => 'annotation',
                'namespace' => 'Models',
                'path' => '',
            ),
        ),
    ),
));

also this

$app->register(new DoctrineOrmServiceProvider(), array(
    'orm.proxies_dir' => __DIR__."/../../cache/doctrineProxies",
    'orm.proxies_namespace' => $app['env'],
    'orm.auto_generate_proxies' => $app['debug'],
    'orm.default_cache' => getenv('REDIS_CACHE') ? 'redis' : 'array',
    'orm.em.options' => array(
        'cache_namespace' => $app['env'].'_',
        'host' => getenv('REDIS_HOST'),
        'port' => getenv('REDIS_PORT'),
        'password' => getenv('REDIS_PASSWORD'),
        'mappings' => array(
            array(
                'type' => 'annotation',
                'namespace' => 'Models',
                'path' => '',
            ),
        ),
    ),
));

Question: Adding validation annotations in a Doctrine entity

Hi!

I am trying to use vahlidation annotations in a Doctrine entity, but when I want to generate entities it fails. If I remove the validation annotations the entity and repository are generated correctly.

May be an config issue? Or isn't possible to use validation annotations in a Doctrine entity with Silex?

Thank you!

This is the code/configuration/output:

Entity with validation annotations

<?php

namespace Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Constraints\Email;


/**
 * @ORM\Entity
 * @ORM\Table(name="users")
 * @ORM\Entity(repositoryClass="Entity\UserRepository")
 */
class User
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string $email
     *
     * @ORM\Column(name="email", type="string", length=255, unique=true)
     * @Assert\Email()
     */
    private $email;

    /**
     * @var string $password
     *
     * @ORM\Column(name="password", type="string", length=255)
     */
    private $password;

    /**
     * @var string $salt
     *
     * @ORM\Column(name="salt", type="string", length=255)
     */
    protected $salt;

    /**
     * @var array $roles
     * 
     * @ORM\Column(name="roles", type="array")
     */
    private $roles;

Doctrine ORM configuration

<?php

...

// Doctrine ORM
$app["orm.em.options"] = array(
    "mappings" => array(
        array(
            'type' => 'annotation',
            "namespace" => "Entity",
            'path' => __DIR__ .'/Entity',
            'use_simple_annotation_reader' => false
        ),
    ),
);

Console command

php bin/console orm:generate-entities src/

Output

[Doctrine\Common\Annotations\AnnotationException]
[Semantical Error] The annotation "@Symfony\Component\Validator\Constraints\Email" in property Entity\User::$email does not exist, or could not be auto-loaded.

Problem with metadata entities

I'm using version 1.0.5 and when run generate-entities, display No metadata process. My paths are correct.
I use composer e my directory is src/JS/Entity

$app->register(new DoctrineOrmServiceProvider, array(
    "orm.em.options" => array(
        "mappings" => array(
            array(
                "type" => "annotation",
                "namespace" => "JS\Entity",
                "path" => __DIR__ ."/JS/Entity"
                ),
            ),
        )
    ));
$ormConfig = $app['orm.em']->getConfiguration();

$ormConfig->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader(), [
            __DIR__ ."/JS/Entity"
        ]));

shema upbdate problem

i use for updating the schema doctrine:schema:update
error : No Metadata Classes to process.

here is my Entity code
`<?php
/**

Created by PhpStorm.
User: jamel_pc
Date: 2016-11-27
Time: 9:16 PM
*/
namespace Esprit\ParcBundle\Entity;
use Doctrine\ORM\Mapping as ORM;

/**

Class Modele

@Package ParcBundle\Entity

@Orm\Entity

@Orm\Table(name="Modele")
/
class Modele{
/*
*@Orm\GeneratedValue(strategy="Auto")
*@Orm\Id
@Orm\Column(type="integer")
/
private $id;
/

@Orm\Column(type="string",length=255)
*/

private $Libelle;
/**

@Orm\Column(type="string",length=255)
/
private $Pays;
/
*

@Orm\Column(type="string",length=255)
/
/
*

@return mixed
/
public function getLibelle()
{
return $this->Libelle;
}
/
*

@param mixed $Libelle
/
public function setLibelle($Libelle)
{
$this->Libelle = $Libelle;
}
/
*

@return mixed
/
public function getId()
{
return $this->id;
}
/
*

@param mixed $id
/
public function setId($id)
{
$this->id = $id;
}
/
*

@return mixed
/
public function getPays()
{
return $this->Pays;
}
/
*

@param mixed $Pays
*/
public function setPays($Pays)
{
$this->Pays = $Pays;
}
`

Question: No Metadata Classes to process.

I'm trying to get this working in Silex but struggling when setting it up.

I get "No Metadata Classes to process." when trying to create the schema through my console app.

The schema validates fine if I run orm:validate-schema

Below is my config. Example\Api\Entities is mapped to "src/Example/Api/Entities" in my composer.json file (similar namespaces are working)

"orm.em.options" => array(
    "mappings" => array(
        // Using actual filesystem paths
        array(
            "type" => "annotation",
            "namespace" => "Example\Api\Entities",
            "path" => __DIR__."/../src/Example/Api/Entities",
        ),
    ),
),

Changing the path to a none existant path breaks validate-schema as expected.

This is my entity file

<?php

namespace Example\Api\Entities;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="example")
 */
class Example
{
/**
 * @ORM\Column(type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\Column(type="string", length=100)
 */
protected $name;

/**
 * @ORM\Column(type="decimal", scale=2)
 */
protected $price;

/**
 * @ORM\Column(type="text")
 */
protected $description;
}

I'm not really sure how to fix this. Any help would be greatly appreciated.

Registering an entity listener

Hi, and thanks in advance for reading this and responding!

I would like to register an entity listener. Here is how I have tried to accomplish this:

$app->register(
    new \Dflydev\Provider\DoctrineOrm\DoctrineOrmServiceProvider(),
    [
        'orm.proxies_dir' => __DIR__.'/../var/cache/doctrine/orm/Proxies',
        'orm.em.options' => [
            'mappings' => [
                [
                    'type' => 'annotation',
                    'use_simple_annotation_reader' => false,
                    'namespace' => 'ImpactApi\Model',
                    'path' => __DIR__.'/../lib/ImpactApi/Model'
                ],
            ],
        ]
    ]
);
$app['orm.em']
    ->getConfiguration()
    ->getEntityListenerResolver()
    ->register(new \ImpactApi\EventListener\UserTicketListener());

My Listener looks like this:

class UserTicketListener
{
    /**
     * @param EventUserTicket $userTicket
     * @param PreFlushEventArgs $args
     * @return null
     * @ORM\PreFlush
     */
    public function preFlush(EventUserTicket $userTicket, PreFlushEventArgs $args)
    {
        $history = new UserTicketHistory(
            $userTicket->getUser(),
            $userTicket->getPrice(),
            $userTicket->getState()
        );

        $em = $args->getEntityManager();
        $em->persist($history);
        $em->flush($history);
        return null;
    }
}

And finally...

/**
 * @ORM\Entity
 * @ORM\EntityListeners({ "ImpactApi\EventListener\UserTicketListener" })
 */
class UserTicketHistory

I have also tried:

// index.php
$app['user_ticket.entity_listener'] = function () use ($app) {
    return new \ImpactApi\EventListener\UserTicketListener();
}
$app['orm.em']
    ->getConfiguration()
    ->getEntityListenerResolver()
    ->register($app['user_ticket.entity_listener']);

and finally...

// index.php
$app['orm.entity_listener_resolver']->register($app['user_ticket.entity_listener']);

What am I doing wrong here?

Do I need to instantiate the OrmServiceProvider, then register the listener, and then register that object on $app? e.g.

$ormServiceProvider = new \Dflydev\Provider\DoctrineOrm\DoctrineOrmServiceProvider();
$ormServiceProvider['orm.entity_listener_resolver']->register($app['user_ticket.entity_listener']);

$app->register($ormServiceProvider, [ /* other options */ ]);

In the UnitOfWork->commit function, it checks the event manager for preFlush listeners:

    public function commit($entity = null)
    {
        // Raise preFlush
        if ($this->evm->hasListeners(Events::preFlush)) {
            $this->evm->dispatchEvent(Events::preFlush, new PreFlushEventArgs($this->em));
        }

I threw a die statement in the conditional and it's just not being hit.

Any advice would be appreciated. Thanks!

Uncaught exception 'InvalidArgumentException' with message 'Identifier "default" is not defined.

Hi people,
It's been a few days trying to setup correctly the package and still have problems. After setting all the configuration and console tools, I'm getting this error and I cannot find the way to fix it.

The error is : PHP Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Identifier "default" is not defined.' in /Users/Marcos/Documents/vagrant-starter/public/Malendar/vendor/pimple/pimple/lib/Pimple.php:78

And the strack trace: #0 /Users/Marcos/Documents/vagrant-starter/public/Malendar/vendor/dflydev/doctrine-orm-service-provider/src/Dflydev/Pimple/Provider/DoctrineOrm/DoctrineOrmServiceProvider.php(107): Pimple->offsetGet('default')

In my app.php code I got the following:

$app->register(new DoctrineServiceProvider(), array(
    'dbs.options' => array(
        'db' => array(
            'driver'   => 'pdo_mysql',
            'dbname'   => 'world',
            'host'     => 'localhost',
            'user'     => 'root',
            'password' => '****',
            'charset'  => 'utf8',
        ),
    )
));

$app->register(new DoctrineOrmServiceProvider, array(
    "orm.proxies_dir" => __DIR__ . "/var/cache/doctrine/proxy",
    "orm.em.options" => array(
        "mappings" => array(
            array(
                "type" => "yml",
                "namespace" => 'Malendar\Domain\Entities',
                "path" => __DIR__ . "/../src/Application/Resources/config/yaml/",
            ),
        ),
    ),
));

Also as I'm running ' php app/bin/console orm:validate-schema'
Therefore in the console.php got the following:

....
//DOCTRINE
$console->setHelperSet(new Symfony\Component\Console\Helper\HelperSet(array(
    'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($app["db"]),
    'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($app["orm.em"])
)));
$console->addCommands(array(
    new \Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand,
    new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand,
    new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand,
    new \Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand,
    new \Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand,
    new \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand,
    new \Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand,
    new \Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand,
    new \Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand,
    new \Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand,
    new \Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand,
    new \Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand,
    new \Doctrine\ORM\Tools\Console\Command\InfoCommand,
    new \Doctrine\ORM\Tools\Console\Command\RunDqlCommand,
    new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand,
    new \Doctrine\DBAL\Tools\Console\Command\ImportCommand,
    new \Doctrine\DBAL\Tools\Console\Command\ReservedWordsCommand,
    new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand
));
.....

I got the repo in https://github.com/MarcosSegovia/malendar, if there is something left you want to know.

I appreciate your time =D

lazyload connect to redis?

Not really an issue, just a question:

Concerning this line: https://github.com/dflydev/dflydev-doctrine-orm-service-provider/blob/master/src/Dflydev/Provider/DoctrineOrm/DoctrineOrmServiceProvider.php#L304

I want to generate proxies using a container that has no link to a Redis container. In my config I have configured a redis cache with host and port which results in the orm.cache.factory.redis to automatically try and call ->connect() and ->auth() on the Redis instance.

Is there a way to only call connect() and auth() when needed?

How do I install this?

I can't get this provider to install with Silex:

$ composer require silex/silex dflydev/doctrine-orm-service-provider
Using version ~1.2 for silex/silex
Using version ~2.0 for dflydev/doctrine-orm-service-provider
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: don't install pimple/pimple v1.1.1
    - Conclusion: don't install silex/silex v1.2.3
    - Conclusion: don't install silex/silex v1.2.2
    - Conclusion: don't install silex/silex v1.2.1
    - Installation request for silex/silex ~1.2 -> satisfiable by silex/silex[v1.2.0, v1.2.1, v1.2.2, v1.2.3].
    - Conclusion: don't install pimple/pimple v3.0.0
    - Conclusion: don't install pimple/pimple v1.0.1|install pimple/pimple v3.0.0
    - Installation request for dflydev/doctrine-orm-service-provider ~2.0 -> satisfiable by dflydev/doctrine-orm-service-provider[v2.0.0].
    - Conclusion: don't install pimple/pimple v1.0.2|install pimple/pimple v3.0.0
    - dflydev/doctrine-orm-service-provider v2.0.0 requires pimple/pimple >=2.1,<4 -> satisfiable by pimple/pimple[v2.1.0, v2.1.1, v3.0.0].
    - Can only install one of: pimple/pimple[v2.1.0, 1.0.0].
    - Can only install one of: pimple/pimple[v2.1.1, 1.0.0].
    - silex/silex v1.2.0 requires pimple/pimple ~1.0 -> satisfiable by pimple/pimple[1.0.0, v1.0.1, v1.0.2, v1.1.0, v1.1.1].
    - Conclusion: don't install pimple/pimple v1.1.0|install pimple/pimple v3.0.0

What am I doing wrong?

Issue with mappings

Hi,
I'm working on using two mappings in app.php, see below

$app->register(new DoctrineOrmServiceProvider, [
  'orm.proxies_dir' => __DIR__.'/../var/cache/doctrine/Proxy',
  'orm.em.options' => [
    'mappings' => [
      // Using actual filesystem paths
      [
        'type' => 'annotation',
        'use_simple_annotation_reader' => false,
        'namespace' => 'Auth\entities',
        'path' => __DIR__.'/auth/entities',
      ],
      [
        'type' => 'annotation',
        'use_simple_annotation_reader' => false,
        'namespace' => 'Profile\entities',
        'path' => __DIR__.'/profile/entities',
      ],
    ],
  ],
]);

my entities are

<?php
namespace Auth\entities;

use Doctrine\ORM\Mapping;
use Doctrine\Common\Annotations\Annotation;

use Symfony\Component\Security\Core\User\AdvancedUserInterface;

use Profile\entities\Profile;

/**
* @Mapping\Entity(repositoryClass="Auth\entities\repositories\UserRepository")
* @Mapping\Table(name="users")
* @Mapping\HasLifecycleCallbacks()
*/
class User implements AdvancedUserInterface, \JsonSerializable {

  public $name = 'Auth\entities\User';
  /**
   * @Mapping\Id @Mapping\Column(type="integer")
   * @Mapping\GeneratedValue
  */
  protected $id;

  /**
   * @Mapping\Column(type="string", unique=true)
   */
  protected $email;

  /** @Mapping\Column(type="string") */
  protected $password;

  /** @Mapping\Column(type="string") */
  protected $salt;

  /** @Mapping\Column(type="array") */
  protected $roles;

  /**
   * @Mapping\OneToOne(targetEntity="\Profile\entities\Profile", mappedBy="user")
   * @var Profile
  **/
  protected $profile;

the other entity is

namespace Profile\entities;

use Doctrine\ORM\Mapping;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Mapping\ClassMetadata;

use Auth\Entities\User;

/**
* @Mapping\Entity(repositoryClass="Profile\entities\repositories\ProfileRepository")
* @Mapping\Table(name="profiles")
*/
class Profile implements \JsonSerializable {
  /**
   * @Mapping\Id @Mapping\Column(type="integer")
   * @Mapping\GeneratedValue
  */
  protected $id;

  /** @Mapping\Column(type="string", nullable=true) */
  protected $salutation;

  /** @Mapping\Column(type="string", name="first_name") */
  protected $firstName;

  /** @Mapping\Column(type="string", name="last_name") */
  protected $lastName;

  /** @Mapping\OneToOne(targetEntity="Auth\Entities\User", inversedBy="profile") */
  protected $user;

but when I try to get any of these entities, an error returns

{
  "error": true,
  "statusCode": 500,
  "message": "An exception occurred while executing 'SELECT t0.id AS id_1, t0.email AS email_2, t0.password AS password_3, t0.salt AS salt_4, t0.roles AS roles_5, t0.imageUrl AS imageUrl_6, t0.domain_slug AS domain_slug_7, t0.enabled AS enabled_8, t0.not_expired AS not_expired_9, t0.valid_credentials AS valid_credentials_10, t0.not_locked AS not_locked_11, t0.invite_token AS invite_token_12, t0.invited AS invited_13, t0.access_token AS access_token_14, t0.confirmation_token AS confirmation_token_15, t0.last_password_updated AS last_password_updated_16, t0.created_at AS created_at_17, t0.updated_at AS updated_at_18, t0.type_id AS type_id_19, t20.id AS id_21, t20.salutation AS salutation_22, t20.first_name AS first_name_23, t20.last_name AS last_name_24, t20.gender AS gender_25, t20.birthdate AS birthdate_26, t20.created_at AS created_at_27, t20.updated_at AS updated_at_28, t20.user_id AS user_id_29, t20.church_id AS church_id_30, t20.cell_id AS cell_id_31 FROM users t0 LEFT JOIN profiles t20 ON t20.user_id = t32.id WHERE t0.access_token = ? LIMIT 1' with params [\"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6ImNoYXJsZXNAZ21haWwuY29tIiwicGFzc3dvcmQiOiJsMnVaMnowblRGZ1pOakZyT0g5Y3FJQlwvamxOWmhkSStEY1lITCtBcUh4R25pZnhnbzNvVkYrVHdvVTJZY09lK24wRm1wOTdJQXRPakpGQUhOZUNCSEE9PSIsInJvbGVzIjpbIlJPTEVfU1RBUlRFUiIsIlJPTEVfU1VQRVJfQURNSU4iLCJST0xFX1VTRVIiXSwidGltZSI6eyJkYXRlIjoiMjAxNS0xMC0wOCAwNzo1MDowMy4wMDAwMDAiLCJ0aW1lem9uZV90eXBlIjozLCJ0aW1lem9uZSI6IkFmcmljYVwvTGFnb3MifX0.PCqwqTvcK83lRUnOfHkN4b3eQ_iAaFkJ7JaLStGopfc\"]:\n\nSQLSTATE[42S22]: Column not found: 1054 Unknown column 't32.id' in 'on clause'"
}

The sql is incorrectly trying to reference a column that does not exist.
Is there a way to use two mappings or I'm i stuck with one?

Pimple requirement conflicts with silex

I'm not sure how this problem came up. Probably no one's been testing this on silex, or something similar.

So, basically, if you install silex (latest stable => 1.3) and then try to install this, composer will complain that pimple used by silex is v1.x whereas a v3.x is required.

Some quick research seems to point out that silex 2 (currently in dev) requires pimple v3.

What I find weird in this situation is that both this repository's readme as well as silex's 3rd party providers page say that this should work (note that there is a dedicated page for 3rd party providers for silex 2).

This might not be a bug per se, but I'd like to see some clarifications (and maybe a documentation update - maybe from my side).

Change the AnnotationReader used for annotations

Hi,

While I was developing and using your provider, I encountered an error : if, on my entities, i'm using a namespace (like use \Doctrine\ORM\Mapping as ORM, then use @ORM\Entity, @ORM\Table, ...) instead of the regulars @Entity, @Table, ...

The thing is, if i'm using the alias for this namespace, the AnnotationReader tries (and fails) to load \Doctrine\ORM\Mapping\ORM\Entity, which is not really the expected behavior.... As it is declared, if the second argument is true (which is, per default) of the newDefaultAnnotationDriver method of the configurator on line 122, for the AnnotationDriver.

Would there be a way to allow the developper, when using your provider, to choose if we can use the simple or standard mode for annotations ? I could do a PR if you want.

Thanks ! :)

Cache namespace configuration

When you have many web applications in the same server, it is necessary to configure a suffix in the APC cache in order to avoid cache conficts between applications.

   $app['orm.cache.factory.apc'] = $app->protect(function() {
        $cache = new ApcCache();
        $cache->setNamespace("namespace_");
        return $cache;
    });

As a possible solution, it will be great to have the option to define a cache_namespace or to inject an APC instance to the configuration, in example

     "query_cache" => $app["apc_instance"],

The method setNamespace is implemented in Doctrine\Common\Cache\AbstractCache so it can solve conflicts in any shared cache implementation.

Thanks for this cool SilexProvider!

Best Regards

Could you do an example with mysql connection?

I have this @simensen @dominikzogg @straccio:

$app->register(new Silex\Provider\DoctrineServiceProvider(), array(

        'dbs.options' => array(
            'db' => array(
                'driver'   => 'pdo_mysql',
                'dbname'   => 'mydbname',
                'host'     => 'iphost',
                'user'     => 'user',
                'password' => 'password',
                'charset'  => 'utf8',
            ),
        )
));

//Is it correct? Or Have I to set up something?
$app->register(new Dflydev\Silex\Provider\DoctrineOrm\DoctrineOrmServiceProvider, array(
    "orm.em.options" => array(
        "mappings" => array(
        array(
                "type" => "annotation",
                "namespace" => "Entities",
                "path" => __DIR__.'/../Entities',
            )
        ),
     ),
));

//Is it correct? Or Have I to set up something?
$app['orm.ems.default'] = 'mysql';
$app['orm.ems.options'] = array(
   'mysql' => array(
       'connection' => 'mysql',
       'mappings' => array(), 
   ),
);

$article = new Entities\Test();
$article->setContent('Hello world!');
$app['orm.em']->persist($article);
$app['orm.em']->flush();
<?php
namespace Entities;

/**
 * @Entity
 */
class Test {

    /** 
     * @Id @Column(type="integer")
     * @GeneratedValue
     */
    private $id;

    /** @Column(type="text") */
    private $content;

    public function setContent($content)
    {
        $this->content = $content;
    }
}

And it always crash!

Documentation, show defaults

Hello simensen

Probably it's a good idea to document the defaults.

use_simple_annotation_reader (default: true):

instead of

use_simple_annotation_reader:

What do you think about?

custom mapping (postgis)

Hello,
I'm trying to use this orm with potsgis database.
(https://github.com/djlambert/doctrine2-spatial)
I can added new types as:

"orm.em.options" => array(
    "mappings" => array(
        array(
            "type" => "yml",
            "namespace" => "I3dat",
            "path" => realpath(__DIR__ . "/doctrine")
        )
    ),
    'doctrine_type_mappings' => array(
        '_text' => 'string'
    ),
    'types' => array(
        'point2' => 'CrEOF\Spatial\DBAL\Types\Geometry\LineStringType',
        'geometry' => 'CrEOF\Spatial\DBAL\Types\GeometryType',
        'point' => 'CrEOF\Spatial\DBAL\Types\Geometry\PointType',
        'polygon' => 'CrEOF\Spatial\DBAL\Types\Geometry\PolygonType',
        'linestring' => 'CrEOF\Spatial\DBAL\Types\Geometry\LineStringType',
    )

),
'orm.custom.functions.numeric' => array(
    'st_contains' => 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STContains',
    'st_distance' => 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STDistance',
    'st_area' => 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STArea',
    'st_length' => 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STLength',
    'st_geomfromtext' => 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STGeomFromText'
)

But, this provider ignores doctrine_type_mapping config.

Doctrine doc:
https://github.com/doctrine/DoctrineORMModule/blob/master/docs/configuration.md#how-to-register-type-mapping

Running php console orm:schema-tool:update returns:
[Doctrine\DBAL\DBALException]
Unknown database type _text requested, Doctrine\DBAL\Platforms\PostgreSqlPlatform may not support it.

Workarounds for fix it? Thank you!

(Edit)Aclration: ORM is working well loading geometry/points objects, using criteria etc.. but i can't update database schema automatically.

Question: Adding the Doctorine CLI to Silex Console App

First of all thanks for putting this out there @dflydev. I am lost as to adding the Doctrine CLI functions to my applications console to be able to create the Doctrine schema. I am using lyrixx/Silex-Kitchen-Edition to structure the application. They have already included a nice symfony/Console component, so my question is how I can integration the Doctrine ORM Service provider there to be able to handle generating the entity tabels.

PHP compatibility version

This package is setted as PHP 5.3+.

One of it's dependencies Doctrine ~2.3, installs Doctrine 2.5 that is 5.4+

I suggest to change the Doctrine version to 2.4.* to remain 5.3+ compatible.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.