The annotation "#ODM\Document" in class ... was never imported - mongodb

Annotation doesn't work any more after upgrading php7.4 to 8.1.
I upgrade a php7.4 project to php8.1.9, then annotations don't work:
The annotation "#ODM\Document" in class ... was never imported.
Some examples of annotations are:
use Zend\Form\Annotation;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
/**
* #ODM\Document
* #Annotation\Name("client")
* #Annotation\Attributes({"novalidate": "true"})
*/
I have checked the above two classes exist under vendor/.
I have also run composer dumpautoload.
There also exist AnnotationDriver of Doctrine:
vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/AnnotationDriver.php;
vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/AnnotationDriver.php
In addition, the version of their packages are not changed.
My questions:
Firstly what's the most effective way to make the system work or identify problems ?
I'm considering, do I have to replace all the annotations to PHP8 attributes ? But this doesn't look necessary or practical. There're huge amount of annotations. Even if I can replace those annotations of my project, the vendor packages still use annotations and definitely I can't change them.
Just wondering, which version of Doctrine Mongodb ODM support PHP8 attributes ?
Just guessing, is it because PHP8 makes the current Zend framework 2 and Doctrine ODM broken and thus causing annotation not work any more? If so, how to fix?
The related packages are as the following:
"zendframework/zendframework" : "2.3.10"
"doctrine/annotations" : "1.2.8",
"doctrine/mongodb": "1.2.2" (There's no version for PHP8, so I have to install it as github VCS package )
"mongodb/mongodb" : "^1.0.1",
"doctrine/mongodb-odm" : "1.0.0-BETA14",
"doctrine/doctrine-mongo-odm-module" : "0.8.0",
"doctrine/annotations" : "1.2.8",
"doctrine/common": "2.4.4",
"doctrine/doctrine-module": "0.8.2",
If you need further resources, please let me know. Thanks!

Related

TYPO3 queryBuilder, how to let PhpStorm recognise methods?

For example
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$queryBuilder = $connectionPool->getQueryBuilderForTable($table);
$statement = $queryBuilder
->select('uid')
->from($table)
->orderBy('start_date', 'DESC')
->where(
$queryBuilder->expr()->lte('start_date', $queryBuilder->createNamedParameter($startDate, \PDO::PARAM_INT)),
$queryBuilder->expr()->neq('uid', $queryBuilder->createNamedParameter($currentUid, \PDO::PARAM_INT))
)
->setMaxResults(1)
->execute();
while ($row = $statement->fetch()) {
$prevs[] = $row;
}
How can one let PhpStorm recognise the methods select, expr, createNamedParameter, fetch etc.
PhpStorm doesn't automatically know what class $connectionPool is and so can't know what class everything derived from that is. You can tell PhpStorm what class $connectionPool is by adding an annotation:
/** #var ConnectionPool $connectionPool */
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
If you use the TYPO3 Plugin for PhpStorm, it's able to get the correct information from makeInstance() (and many more features).
https://plugins.jetbrains.com/plugin/9496-typo3-cms-plugin
You can do 2 steps to help PhpStorm recognise functions outside of your project:
Annotate the variables with their respective namespace:
/** #var $queryBuilder \TYPO3\CMS\Core\Database\Query\QueryBuilder **/
$queryBuilder = $connectionPool->getQueryBuilderForTable($table);
You can shorten the above when used multiple time with declaring:
use \TYPO3\CMS\Core\Database\Query\QueryBuilder;
at the top of your file, the you would just need
/** #var $queryBuilder QueryBuilder **/
As a second step include the Typo3 sources to your project (if they are not inclued in your project files already) so PhpStorm will be able to index them
I find that adding annotations for the variable type is unnecessary and just clutters up the source code.
In general, for PhpStorm to find the classes, methods etc. you have to include the TYPO3 source in your project.
You can create a PHP project which includes your entire web root (typically "public" folder), but excludes directories like filadmin, uploads, typo3temp etc. It is important to exclude these directories so PhpStorm does not unnecessarily scan them. (In particular if you run the core functional tests this is very much recommended.) I find this is the most practical approach and also useful for debugging and core development
You can create a PhpStorm project for your extension and include your TYPO3 source as well. Don't know about this off the top of my head, but should be possible.
Once you do this and PhpStorm scanned your files, it should be possible to do any of the following:
Auto-expand class and function names
Add use statements automatically (see PhpStorm help for more)
etc.
See also DynamicReturnType plugin and other plugins recommended for TYPO3 core development. The DynamicReturnType plugin along with the file dynamicReturnTypeMeta.json shipped with the core should give PhpStorm enough information for return type of classes instantiated with makeInstance for example.

Symfony2.5 softDeleted with mongodb

How to make the symfony doctrine extension 'SoftDeleted' works with mongoDb? (doctrine-mongo-odm). The plugin says 'only works for ORM'...And is there any other solutions ?
DoctrineExtensions for ODM currently doesn't support Softdeletable.
List of extensions which support ODM
Translatable
Sluggable
Timestampable
Blameable
Loggable
Translator
Tree (Materialized Path strategy for now)
References
Sortable
See the documentation on Github for more informations.
Edit: scratch that. Just found this https://github.com/Atlantic18/DoctrineExtensions/pull/877
Edit 2: https://github.com/Atlantic18/DoctrineExtensions/blob/master/lib/Gedmo/SoftDeleteable/Filter/ODM/SoftDeleteableFilter.php
It seems to work like the normal ORM annotation. To set it up with symfony just follow the usual documentation (not the one on that Repo).
Config:
doctrine_mongodb:
...
document_managers:
default:
[.....]
filters:
soft-deleteable:
class: Gedmo\SoftDeleteable\Filter\ODM\SoftDeleteableFilter
enabled: true
Edit 3 Updated the code above again, because I'm stupid

Symfony2: problems rendering the translation-form with A2lixTranslationFormBundle and Gedmo\DoctrineExtensions Translatable

I'm using gedmo/doctrine-translations and a2lix/translation-form-bundle: 2.*#dev to translate my entities.
The translation form always renders a Field and Content but my entity itself doesn't contain a Field or Content field.
The form type
$builder->add('translations', 'a2lix_translations');
The 2.0 version of the TranslationFormBundle
isn't compatible with the current gedmo/doctrine-extensions version.
See the bundle's upgrade notes.
You'll need to use the currently unstable branches wip-v2.4.0 and .
solution:
Either update gedmo/doctrine-extensions ...
composer require gedmo/doctrine-extensions:wip-v2.4.0#dev
composer update gedmo/doctrine-extensions
... or downgrade your a2lix/translation-form-bundle version:
composer require a2lix/translation-form-bundle:~1.2
composer update a2lix/translation-form-bundle
important notice for the 1.x version of a2lix/TranslationFormBundle:
You need to use the a2lix_translations_gedmo field-type as described in the documentation.
Further you need to specify the translatable class in the options-array like this:
$builder->add('translations', 'a2lix_translations_gedmo', array(
'translatable_class' => "Your\Entity"
);

Laravel 4 using vendor classes

I have installed Laravel 4 after using 3, love it.
I used to be able to use the Zend framework as such:
$yt = new Zend_Gdata_YouTube();
for instance
I have used composer to install Zend and everything is installed in the Vendor folder..
Problem:
How to address the individual classes i.e. Zend Gdata etc.
I can't find any documentation on calling classes from a vendor in L4.
Any help is appreciated.
Take a look at your vendor\composer\autoload_classmap.php file. In there you will find a list of all vendor classes that are being autoloaded. I think all classes will have to be called using their full namespaced name.
E.g.
I'm using Zizaco's Entrust package. This is what it looks like in the vendor\composer\autoload_classmap.php file.
'Zizaco\\Entrust\\Entrust' => $vendorDir . /zizaco/entrust/src/Zizaco/Entrust/Entrust.php',
If I wanted to access the Entrust.php class I have to call
$en = new Zizaco\Entrust\Entrust();
Alternatively you could alias certain classes in your app\config\app.php file.
E.g.
'Ent' => 'Zizaco\Entrust\Entrust'
In your case you'll need to do something like this:
$yt = new Zend\namespace\Zend_Gdata_YouTube();

zend + doctrine 2 doctrine manager, where is it?

i see everyone using this:
Doctrine_Manager::getInstance()
when i do this, its error is:
Class 'Doctrine_Manager' not found
how do i load this ?so that i can start get instances from doctrine manager?
i want to load this:
$con = Doctrine_Manager::getInstance()->connection();
$st = $con->execute("...............");
$result = $st->fetchAll();
where can autoload this , so i can call the getInstance() function from anywhere?
thanks...
Doctrine_Manager is part of version 1.2, not 2. If you are actually using 1.2, you need to let the autoloader know to load classes under the Doctrine_ prefix.
To do so, add this to your application configuration file...
autoloaderNamespaces.Doctrine = "Doctrine_"
You also need to ensure the doctrine classes can be found on the include path. If they aren't in your "library" folder or otherwise part of the include_path directive, add this...
includePaths.Doctrine = "/path/to/Doctrine-1.2/lib"
I think you might be looking for the EntityManager?
If so, here you can find a tutorial how to configure.
Also there is a library call Bisna for integrating ZF+Doctrine2, here is a good tutorial video for configuring it