doctrine / common Goto Github PK
View Code? Open in Web Editor NEWDoctrine Common
Home Page: https://www.doctrine-project.org/projects/common.html
License: MIT License
Doctrine Common
Home Page: https://www.doctrine-project.org/projects/common.html
License: MIT License
Jira issue originally created by user matthieu:
Sorry for the vague title of the issue, but here is the problem:
$classLoader = new ClassLoader('Tests', '/basePath/tests');
If I want to autoload \Tests\Class1
*, it will look for */basePath/tests/Tests/Class1.php
.
I would like it to load: /basePath/tests/Class1.php
. i.e., the namespace registered is removed from the path.
Do you see what I mean ? Zend Framework autoloader allow this behavior, I am surprised the Doctrine autoloader doesn't allow that.
Thanks
Jira issue originally created by user chebba:
The problem is that we need to load all annnotation classes before we read annotations from the target class.
So we need to require_once them at target class source, or just before reading.
It's not cool.
The reason of this, is a fix of bug #77
http://www.doctrine-project.org/jira/browse/[DDC-77](http://www.doctrine-project.org/jira/browse/DDC-77)
and class_exists(..., false).
Solutions:
May be there are some another, better solutions.
Jira issue originally created by user sebastian.hoitz:
The method getIds() in MemcacheCache relies on the old "cachedump" stat type.
But as you can read here: http://de2.php.net/manual/en/memcache.getextendedstats.php this has been removed due to security reasons.
Jira issue originally created by user @beberlei:
Since we are still at a point were bc breaks are potentially not so harming:
We need a slice() method on the Collection for forward compatibility, the support for large and very large collections using FETCH_EXTRA would heavily benefit from a method like this.
/****
* Extract a slice of $length elements starting at position $offset from the Collection.
*
* If $length is null it returns all elements from $offset to the end of the Collection.
* Keys have to be preserved by this method.
*
* @param int $offset
* @param int $length
* @return array
*/
public function slice($offset, $length = null);
The ArrayCollection implement would be:
public function slice($offset, $length = null);
{
return array*slice($this->*elements, $offset, $length, true); // preserve keys
}
Jira issue originally created by user floeh:
My tld contains a number at the beginning (8points.de).
I'm not able to use it in the @author section (@author Florian Preusner [email protected]) cause after the "@" the next letter is a number.
Exception:
AnnotationException: [Syntax Error] Expected Doctrine\Common\Annotations\Lexer::T_IDENTIFIER, got '8' at position 118 in method Blog\MainBundle\Controller\MainController::indexAction().
n /var/www/floeh/vendor/doctrine-common/lib/Doctrine/Common/Annotations/AnnotationException.php at line 41
I think this is a bug?!
Jira issue originally created by user johannes:
So, this is another improvement that I'd like to make. Right now all annotations are indexed by their name which has the limitation that on the top level annotations with the same name are only gathered once.
/****
* @param mixed $a
* @param mixed $a
* @param mixed $a
*/
function ($a, $b, $c) { }
In the above case the annotation parser would only pick up one "param" annotation. My guess is that this was done for fast lookups, but I think we need to make this configurable (I know you hate this word :)) as the workaround here is needlessly bloated.
/****
* @params({@param, @param, @param})
*/
function($a, $b, $c) {}
This only requires two lines to be changed/made conditional, see
https://github.com/schmittjoh/SecurityExtraBundle/blob/master/Mapping/Driver/AnnotationParser.php#L63
https://github.com/schmittjoh/SecurityExtraBundle/blob/master/Mapping/Driver/AnnotationParser.php#L72
p.s. If you want me to provide a patch for this, just tell me.
Jira issue originally created by user otaviofff:
Doctrine should be able to retrieve stats from cache providers, such as Memcache and APC. Stats may list cache hits, cache misses, memory, and so forth.
Jira issue originally created by user henrikbjorn:
Add a ObjectManager interface so it is possible to write code that supports the EntityManager and DocumentManager at the same time.
Ornicar (Thibault Duplessis) did this gist: http://gist.github.com/545320
Jira issue originally created by user omega:
I noticed that prior to the require function call in loadClass(), no attempt is made to see if the file can be loaded, or to trap the result of the require attempt.
This means that when I chain together class loaders on the autoload stack, the first one that specifies a namespace of null effectively terminates the process, preventing any others from being run.
Jira issue originally created by user merk:
@nonalias:Annot results in a php notice.
Jira issue originally created by user felicitus:
In the documentation on http://www.doctrine-project.org/projects/common/2.0/docs/reference/annotations/en#setup-and-configuration:namespace-aliases I'm given the following example:
$reader->setAnnotationNamespaceAlias('MyCompany\Annotations', 'my');
However, this only works here if I do it that way:
$reader->setAnnotationNamespaceAlias('MyCompany\Annotations\\', 'my');
If the latter one is correct, it should be documented as such.
Jira issue originally created by user mridgway:
This is a rather trivial issue: I'd like to add a function to the Common\ClassLoader called getClassPath($className) or something named similarly so that we are able to find where an autoloader will look for the specified class. The autoloader doesn't check for file existence normally (as it shouldn't) but there are cases where the developer does need to make sure that the file exists before a class is attempted to be loaded.
I've attached a patch for the changes that I'm proposing.
Jira issue originally created by user jkleijn:
Take a look at lib/Doctrine/Common/Annotations/AnnotationReader.php:137
/****
* Gets the annotations applied to a class.
*
* @param string|ReflectionClass $class The name or ReflectionClass of the class from which
* the class annotations should be read.
* @return array An array of Annotations.
*/
public function getClassAnnotations(ReflectionClass $class)
{
$cacheKey = $class->getName() . self::$CACHE_SALT;
// Attempt to grab data from cache
if (($data = $this->cache->fetch($cacheKey)) !== false) {
return $data;
}
$annotations = $this->parser->parse($class->getDocComment(), 'class ' . $class->getName());
$this->cache->save($cacheKey, $annotations, null);
return $annotations;
}
It uses the class name and a static salt to create a cache key. Actually, everything in that class uses a class name to assemble a cache key.
This makes it impossible to have mulitple instances of the same application in different states. Practically: it makes it impossible to have testing and staging, or staging and production versions on the same host if they use the same type of caching (which you sort of need in a staging environment).
Jira issue originally created by user @guilhermeblanco:
Currently the overall code to instantiate Cache drivers cannot be generic.
This can be noticed when you compare APCCache and MemcacheCache drivers.
The first one is simply a no argument instantiation. The second, even after isntantiation, it still requires you to call a method (->setMemcache) in order to work.
This is not optimal for generic approaches, creating unreliable conditional situations. Also it is not extendable, allowing user to build his own driver.
Please consider these sample codes:
http://pastie.org/1103439
http://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php#L419
A suggested approach could be a CacheManager as a fatory.
Another one would be Cache interface assigning a contract to receive an array of options.
Anyway, this should be fixed VERY soon.
Jira issue originally created by user @beberlei:
It return the element, not true.
Jira issue originally created by user bas:
Instantiating a fully qualified namespace (with a prefixed ) will not autoload modules, even while the canLoadClass reports it can and loadClass will load it...
Will NOT work
$classLoader = new \Doctrine\Common\ClassLoader('\Application\Models', '/some/path');
$classLoader->register();
new \Application\Models\SomeClass();
Will work
$classLoader = new \Doctrine\Common\ClassLoader('Application\Models', '/some/path');
$classLoader->register();
new \Application\Models\SomeClass();
Some sanitization or an exception on this would improve things a bit.
Jira issue originally created by user johannes:
Right now, it is only possible to register one namespace per annotation alias. This might lead to problems since we now throw exceptions if an annotation is not found in that namespace (8967f47).
This improvement would be a necessary first step in order to overcome the problem we talked about on IRC (FrameworkExtra/SecurityExtra both using the "extra" alias).
Jira issue originally created by user obrys:
CLI doctrine tool fails when parsing entity sources (for example: doctrine orm:validate-schema) by following error:
Fatal error: Class 'throws\MemberAccessException' not found in /usr/share/php/Doctrine/Common/Annotations/Parser.php on line 272
exception 'FatalErrorException' with message 'Class 'throws\MemberAccessException' not found' in /usr/share/php/Doctrine/Common/Annotations/Parser.php:272
This error appears when @HasLifecycleCallbacks annotation is added into entity.
The solution is adding "@throws" annotation into strippedTags into Doctrine/Common/Annotations/Parser.php
Jira issue originally created by user mac_nibblet:
In the upgrade from DC2 beta1 to beta2 the annonation mapper now starts to try and parse a some of the PHPDocblock annotations such as @Package @subpackage but also the email adress in @author
Example of docblock
/****
* @author Antoine Hedgecock <[email protected]>
* @version 1.0.0
*/
/****
* @package Models
* @subpackage Default
*
* @Entity(repositoryClass="Default*Model_Mapper*Category")
* @Table(name="categories")
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorColumn(name="type", type="smallint")
* @DiscriminatorMap({
* "0" = "Project*Model*Category"
* })
*/
will cause it to try and load
{quote}
Doctrine/ORM/Mapping/package.php
Doctrine/ORM/Mapping/subpackage.php
Doctrine/ORM/Mapping/pmg.php
{quote}
note pmg because its in the email of the author annotation
Jira issue originally created by user @beberlei:
If we know that an annotation is namespaced and that the namespace exists we should throw an exception if the annotation specified does not exist, currently its just skipped which can be very nasty to debug.
Jira issue originally created by user fabpot:
The creation of the Annotation class is done at the end in Parser::Annotation(). It assumes that the Annotation class constructor takes an array of values. But if this is not the case, you are out of luck. So, I propose to move the logic of Annotation creation to is own method for better flexibility.
Jira issue originally created by user bschussek:
The EBNF allows passing multiple comma-separated annotations to an annotation:
Annotation ::= "@" AnnotationName ["(" [Values] ")"]
Values ::= Array | Value {"," Value}*
Value ::= PlainValue | FieldAssignment
PlainValue ::= integer | string | float | boolean | Array | Annotation
Therefore the following should be possible.
/*** @Name(@Foo, @Bar) **/
This results in an error though.
IMO,
/*** @Name(@Foo, @Bar) **/
should be equivalent to
/*** @Name({@Foo, @Bar}) **/
just like
/*** @Name(foo = "foo", bar = "bar") **/
is equivalent to
/*** @Name({foo = "foo", bar = "bar"}) **/
Jira issue originally created by user thomasez:
Needed a sort function in ArrayCollection, made it. Simple but works for me at least.
Pull request: #12
Jira issue originally created by user merk:
In the function Annotation() in \Doctrine\Common\Annotations\Parser.php (~line 225)
There is a check for how many $nameParts there are, and the doctrine code will only append the namespace aliases if there are no namespace separators.
There is also an argument against modification since the user of the code could just define more namespace aliases, but I feel that it should be able to cope with a namespace alias and a namespace separator at the same time.
Jira issue originally created by user chebba:
class Annotation extends \Doctrine\Common\Annotations\Annotation
{
private $someProperty;
public function **set($name, $value)
{
$setMethod = 'set' . ucfirst($name);
if (method_exists($this, $setMethod)) {
return $this->{$setMethod}($value);
}
return parent::**set($name, $value);
}
public function **get($name)
{
$getMethod = 'get' . ucfirst($name);
if (method_exists($this, $getMethod)) {
return $this->{$getMethod}();
}
return parent::**get($name);
}
public function getSomeProperty()
{
//some logic
return $this->someProperty;
}
protected function setSomeProperty($someProperty)
{
//some logic
$this->someProperty = $someProperty;
}
}
Jira issue originally created by user xlite:
The methods deleteByPrefix() / deleteByRegExp() / deleteBySuffix() are based on the method getIds(), which returns unique identifiers with an added namespace in the front. That is why to be able to delete cells using these three methods, you have to know the namespace.
Example:
$cacheDriver->setNamespace('ns');
$cacheDriver->save('data', 'name');
$cacheDriver->deleteByPrefix('data');
In this example the cell will not be deleted.
It seems the tag 2.0.2 misses Persistence dir. Is that ok? I'm using it in a Sf2 beta1 project which involves phpcr and i'm getting this error:
Fatal error: Interface 'Doctrine\Common\Persistence\Mapping\ClassMetadata' not found in /Users/micheleorselli/workspace/www/ideato-website/vendor/doctrine-phpcr-odm/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataInfo.php on line 48
Jira issue originally created by user kanundrum:
In documentation it says that cascade needs be set to persist for transitive persistence to work (http://www.doctrine-project.org/projects/orm/2.0/docs/reference/working-with-associations/en#transitive-persistence-/-cascade-operations:persistence-by-reachability:-cascade-persist) , but since "all" setting is a superset of "persist" it should work for that setting as well (but it doesn't )
Jira issue originally created by user gediminasm:
ClassLoader::classExists($class); will fail if different class loader is used which does not return any boolean value. This includes Symfony2 UniversalClassLoader
I have never used this function before because native PHP method class_exits($class, true) first will try to autoload. But if the class does not exist
and you are using Doctrine\Common::ClassLoader and you call class_exists($class) it will trigger fatal error. This behavior makes it impossible to make code compatible
with different class loading mechanisms for Doctrine2
Jira issue originally created by user @jwage:
Jira issue originally created by user @guilhermeblanco:
Our current AnnotationReader::$_CACHE_SALT conflicts with Symfony2 Console.
The solution is to change the CACHE_SALT from:
private static $CACHE_SALT = '@<Annot>';
To:
private static $CACHE_SALT = '@[Annot]';
Jira issue originally created by user fabpot:
If you have an annotation that uses an alias that is not registered like:
/****
* @foo:SomeAnnot
*/
...
Then, the Parser will throw a PHP Notice:
Notice: Undefined index: foo in .../lib/Doctrine/Common/Annotations/Parser.php line 317
Jira issue originally created by user hashinp:
When I try to set setAutoloadAnnotationClasses(true) gives me a fatal error, call to undefined method
PHP Fatal error: Call to undefined method Doctrine\Common\Annotations\AnnotationReader::setAutoloadAnnotationClasses()
Jira issue originally created by user ratius:
Consider the following code snippet:
$loader = new ClassLoader('DoctrineExtensions',
"/path/to/vendor/doctrine2-extensions-beberlei/lib");
$loader->register();
$loader = new ClassLoader('DoctrineExtensions',
"/path/to/vendor/doctrine2-extensions-srosato/lib");
$loader->register();
The latter will not be able to be loaded since the documentation specifies (with good reason) that class loaders do not fail silently. Is there a workaround for this issue?
Jira issue originally created by user ratius:
I did not know where to issue that component, but since this extension using the Doctrine Common namespace I thought it relevant to issue the bug here.
Consider the following shared fixures (as stated on jwage's github repo here: https://github.com/doctrine/data-fixtures)
{quote}
In case if fixture objects have relations to other fixtures, it is now possible to easily add a reference to that object by name and later reference it to form a relation. Here is an example fixtures for Role and User relation
{quote}
namespace MyDataFixtures;
use Doctrine\Common\DataFixtures\AbstractFixture;
class LoadUserRoleData extends AbstractFixture
{
public function load($manager)
{
$adminRole = new Role();
$adminRole->setName('admin');
$anonymousRole = new Role;
$anonymousRole->setName('anonymous');
$manager->persist($adminRole);
$manager->persist($anonymousRole);
$manager->flush();
// store reference to admin role for User relation to Role
$this->addReference('admin-role', $adminRole);
}
}
namespace MyDataFixtures;
use Doctrine\Common\DataFixtures\AbstractFixture;
class LoadUserData extends AbstractFixture
{
public function load($manager)
{
$user = new User();
$user->setUsername('jwage');
$user->setPassword('test');
$user->setRole(
$this->getReference('admin-role') // load the stored reference
);
$manager->persist($user);
$manager->flush();
// store reference of admin-user for other Fixtures
$this->addReference('admin-user', $user);
}
}
This will not use the last reference as a MANAGED entity but whether as a NEW one since the manager gets cleared (thus the unit of work) on each call to load() for the AbstractExecutor and thus marking any new references to the 'admin-user' considered a NEW entity, which should not be the case.
The current workaround is to directly fetch the entity using the EM's find() function, but that completely eliminates the main goal SharedFixtures' references are bringing.
I have provided the small patch that adress this issue, tests still pass.
Jira issue originally created by user cicovec:
Hi,
I posted this question in doctrine user group(https://groups.google.com/forum/?fromgroups#!topic/doctrine-user/QhAz-Yr70T0), but with no response, so I'd like to open it up here as the solution is trivial and would save me either a lot of sub-classing or prevent me from changing the doctrine library files.
This annotationclass SomeGrid { /**** * @GRID:Column(header="Reg. plate", width=80, editable=TRUE, hidden=FALSE, tooltip="Registration plate", align="left", sortable=TRUE) */ public $regPlate; }
produces the following object:
(object) Grid\Annotations\Column {
"header" => (string) "Reg. plate"
"width" => (string) "80"
"editable" => (bool) true
"hidden" => (bool) false
"tooltip" => (string) "Registration plate"
"align" => (string) "left"
"sortable" => (bool) true
}
You can see the value of the width property is string even I didn't use quotes in the annotation.
The same happens with float values, but true and false values become, correctly, bool.
I found this happens because of the following fragment of code in \Doctrine\Common\Annotations\Parser and could be easily corrected by prefixing the value with the corresponding type cast (marked in red).
case Lexer::T_STRING:
$this->match(Lexer::T_STRING);
return $this->lexer->token['value'];
case Lexer::T_INTEGER:
$this->match(Lexer::T_INTEGER);
return (int)$this->lexer->token['value'];
case Lexer::T_FLOAT:
$this->match(Lexer::T_FLOAT);
return (float)$this->lexer->token['value'];
case Lexer::T_TRUE:
$this->match(Lexer::T_TRUE);
return true;
case Lexer::T_FALSE:
$this->match(Lexer::T_FALSE);
return false;
The point is, in our app, some of the values go directly to browser and are processed by JavaScript. Having those values as strings breaks all kinds of mathematical operations on the client or would require additional (unnecessary) string to int/float conversions.
Jira issue originally created by user blt04:
It is currently impossible to skip annotations of the form:
@annotation(
When a doc block comment begins with an "@" and has an open parenthesis it is assumed to be an exist annotation even if the corresponding annotation class doesn't exist or can't be autoloaded. If you are trying to use the AnnotationReader on a file, you have to make sure all annotations are loaded or can be autoloaded - even the ones you don't care about
In a comment to DCOM-2, Roman stated that his recommended way to load annotations is to load them manually via a require call. This is done in Doctrine ORM and is absolutely necessary because ORM annotations are stored in an autoloader unfriendly way (multiple classes per file and namespace path different from filesystem path).
So, if I want to add my own annotations and store them in a non-autoloader friendly way as Doctrine ORM does, I need to ensure that every AnnotationReader acting on that file knows about my annotations. This is not always possible or desirable.
Removing the parenthesis check and relying solely on class_exists fixes this problem.
Jira issue originally created by user benoit:
I use Doctrine\Common\Util\Debug::dump() for debugging my entities, but original method call strip_tags from the output generated by var_dump, so i got a nasty debug which is a very long line not formatted.
I commented the strip_tags call, so my debug is more human readable.
Is it possible to remove the strip_tags call, or let the developper to choose if debug method should call it or not ?
Jira issue originally created by user mdhooge:
The PhpParser makes a too optimistic assumption about code convention...
If you have the word 'class' or 'interface' in the comment before the class definition, preg_match_all finds wrong slice of code and PHP complains with a Warning about "Unterminated comment". This occurs only once after the cache is cleared.
Jira issue originally created by user margus:
$reader = new Doctrine\Common\Annotations\AnnotationReader();
$reader->setAutoloadAnnotationClasses(true);
above code is trying use default parser's setAutoloadAnnotationClasses-method, which isn't found, instead parser has setAutoloadAnnotations.
Jira issue originally created by user felicitus:
When calling setAutoloadAnnotationClasses() from within AnnotationReader, it fails because setAutoloadAnnotationClasses() is not implemented in Doctrine\Common\Annotations\Parser.
This should be fixed, or at least a FeatureNotImplementedException or such.
Jira issue originally created by user margus:
$reader->setDefaultAnnotationNamespace('Doctrine\Common\Annotations');
I used above code to test annotations without namespaces just to find out that there there is missing \ (or 2 if you count escaping) at the end of that string.
This works: $reader->setDefaultAnnotationNamespace('Doctrine\Common\Annotations');
reference guide where I found error is here: http://www.doctrine-project.org/projects/common/2.0/docs/reference/annotations/en#setup-and-configuration:default-namespace
Jira issue originally created by user seldaek:
It'd be great to support single quotes, this limitation doesn't make sense from a user point of view and in php context single quotes are so commonly used that it's easy to slip and then get some funny Exception message out of it.
Jira issue originally created by user kriswallsmith:
I would like to declare my default annotation namespace and namespace aliases in my class' doc comment. This will ensure my class can be understood by the annotation reader regardless of its configuration.
An example of how I would use this:
https://gist.github.com/821412
Jira issue originally created by user mneuhaus:
If i add the Annotation Tag @ignore to my model the Parser tries to load the Mapping class for that property. Since this class doesn't exist it fails with a fatal error.
I attached the stripped down Entity with the @ignore annotation, the Error Text and a Possible Solution
Greetings Marc
Jira issue originally created by user uopjohnson:
orm:convert-d1-schema /schema.yml yml /newyml returns The helper "em" is not defined
Jira issue originally created by user hgirardi:
I think this method needs to return something...
/****
* Moves the internal iterator position to the next element.
*
* @return mixed
*/
public function next()
{
next($this->_elements);
}
doctrine-common/lib/Doctrine/Common/Collections/ArrayCollection.php
Jira issue originally created by user johannes:
From an initial look that I had at the annotation parser, it simply search for anything starting with an "@" somewhere in the doc comment and assumes that it is an annotation. Now, if someone uses the @ somewhere in his doc comment but not as an annotation, the parser breaks.
An example for this can be found in the Doctrine code base, the following comment will result in a parse error:
/****
* Annotation ::= "@" AnnotationName ["(" [Values] ")"]
* AnnotationName ::= QualifiedName | SimpleName | AliasedName
** QualifiedName ::= NameSpacePart "\" {NameSpacePart "\"}** SimpleName
* AliasedName ::= Alias ":" SimpleName
* NameSpacePart ::= identifier
* SimpleName ::= identifier
* Alias ::= identifier
*
* @return mixed False if it is not a valid annotation.
*/
Obviously the first @ is not used to refer to an annotation here. I think it makes sense to allow new annotations only to start at a new line, what do you think?
Jira issue originally created by user @beberlei:
I discussed this with jwage on symfony day cologne and this also came up during discussions with @dzuelke at IPC yesterday. So i hacked up a first patch for discussion that adds a Doctrine\Common\Persistance namespace and extracts the functionality all our 3 layers implement with regards to EntityManager/EntityRepository (and equivalents).
Additionally i think it might make sense to also add an interface "ObjectMetadata" that has several getters-only that allow access to the field, identifier and association mapping information. This stuff is not necessarly compatible across layers when returned as its "array" representation, but for libraries hooking into the metadata (symfony admin generator) this might not even be necessary.
Jira issue originally created by user cobby:
Doctrine\Common\Util\Debug has code to deal with Proxy objects from the ORM, but nothing for other Doctrine projects.
Maybe the Common package should introduce a base Proxy interface so the Debug class isn't dependant on the ORM? This would also mean standardising Proxy objects, particularly the private property names...
ORM proxy objects have $_identifier and
I suppose the team is wait for Doctrine ODM to become stable before changing this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.