My Internet conexion is useless to install a symphony 2 dependency with composer as far as I can say. Is there a way to install a third party bundle manually? I have been looking in Google and I did not find any useful thing so far. About my connection issue, I started this thread to try and find a solution to install within this connection. here I am trying to find clues to a solution to install manually.
Regards
1 Create under vendor directory the path for bundle :
/*like mycompany*/ /*like product-bundle*/ /*like MyCompany*/
vendor/yourbundlenamespace/your-bundle-name-bundle/YourBundleNameSpace/
2 Go to in the new path and put the content of budle (or clone from github).
3* #deprecated
Load the reference path on autoload, so go to in
vendor/composer/autoload_namespaces.php
and put in the array
'YourBundleNameSpace\\YourBundleNameBundle' => array($vendorDir . '/yourbundlenamespace/your-bundle-name-bundle');
4 Register bundle: go to in
app/AppKernel.php
and put in the array $bundles the new bundle:
```
public function registerBundles()
{
$bundles = array(
//...
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
//...
// this is our bundle :)
$bundles[] = new YourBundleNameSpace\YourBundleNameBundle\YourBundleNameBundle();
}
```
UPDATE
Point 3: this method is not performance because when update via composer is overwrite, instead, you should do:
-go to on app/autoload.php
and put following code after $loader definition
```
//add customs classes
$loader->add('YourBundleNameSpace\\YourBundleNameBundle','vendor//yourbundlenamespace/your-bundle-name-bundle');
```
Related
I'm trying to use Doctrine MongoDB ODM 2.0 beta on a project with the Yii2 framework, with composer version 1.8.4 and PHP 7.2, but I keep getting the error Fatal error: Uncaught Error: Call to a member function add() on boolean where the code runs $loader->add('Documents', __DIR__);
bootstrap.php file (in DIR/bootstrap.php):
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\ODM\MongoDB\Configuration;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
if ( ! file_exists($file = 'C:/path/to/vendor/autoload.php')) {
throw new RuntimeException('Install dependencies to run this script.');
}
$loader = require_once $file;
$loader->add('Documents', __DIR__);
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
$config = new Configuration();
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Proxies');
$config->setHydratorDir(__DIR__ . '/Hydrators');
$config->setHydratorNamespace('Hydrators');
$config->setDefaultDB('fsa');
$config->setMetadataDriverImpl(AnnotationDriver::create(__DIR__ . '/Documents'));
$dm = DocumentManager::create(null, $config);
I already tried looking at How to properly Autoload Doctrine ODM annotations? and Laravel & Couchdb-ODM - The annotation "#Doctrine\ODM\CouchDB\Mapping\Annotations\Document" does not exist, or could not be auto-loaded and a host of other threads I can't quite recall for help, but I couldn't figure out a solution.
I also tried commenting out the lines below
if ( ! file_exists($file = 'C:/path/to/vendor/autoload.php')) {
throw new RuntimeException('Install dependencies to run this script.');
}
$loader = require_once $file;
$loader->add('Documents', __DIR__);
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
and ran composer dump-autoload and on command line it returned Generated autoload files containing 544 classes, but then I got the problem
[Semantical Error] The annotation "#Doctrine\ODM\MongoDB\Mapping\Annotations\Document" in class Documents\Message does not exist, or could not be auto-loaded.
So the annotations are not auto-loading, and I have no idea how to fix that.
In the model I have:
<?php
namespace Documents;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use \Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
/** #ODM\Document */
class Message
{
/** #ODM\Id */
private $id;
/** #ODM\Field(type="int") */
private $sender_id;
...
I also posted a thread on github at https://github.com/doctrine/mongodb-odm/issues/1976. One commenter stated that "By default, the composer autoload file returns the autoloader in question, which seems to not be the case for you." How can I fix that? The only information I can find online is to put (inside composer.json) the lines:
"autoload": {
"psr-4": {
"Class\\": "src/"
}
},
but then what class should I be loading?
I'm very confused and being pretty new to all these tools (mongodb, yii2, etc.) doesn't help at all. I'm not sure what other information would be helpful else I would post it.
Thanks in advance.
So turns out that the problem (as was mentioned in https://github.com/doctrine/mongodb-odm/issues/1976) was that autoload.php was required twice - once in bootstrap.php and once in web/index.php (of the framework). After the require line in index.php was removed, everything worked fine.
We're working with Sylius and trying to create new bundles. Through the console using php bin/console generate:bundle a new bundle is easily createable. however when we try to run the site we get the error: ClassNotFoundException in AppKernel.php line 36: We are registering our new bundle in the AppKernel.php file, and editing the composer.json file to autoload the new bundle but nothing seems to work. We have tried every solution mentioned on SO without luck. Can anyone point us in the right direction?
MUCH APPRECIATED-!
public function registerBundles()
{
$bundles = [
new \Sylius\Bundle\AdminBundle\SyliusAdminBundle(),
new \Sylius\Bundle\ShopBundle\SyliusShopBundle(),
new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle(),
new \FOS\OAuthServerBundle\FOSOAuthServerBundle(), // Required by SyliusApiBundle
new \Sylius\Bundle\ApiBundle\SyliusApiBundle(),
new \AppBundle\AppBundle(),
//NEW BUNDLE
new TGB\AmazonBundle\AmazonBundle(),
];
return array_merge(parent::registerBundles(), $bundles);
}
from our composer.json file
"autoload": {
"psr-4": {
"AppBundle\\": "src/AppBundle/",
"TGB\\AmazonBundle\\": "src/TGB/AmazonBundle/"
},
"classmap": ["app/AppKernel.php", "app/AppCache.php"]
},
Found the answer, we needed to run composer dump-autoload it was caching and wouldn't go look for the new classes that it needed to load.
I'm trying to make my website live but keep getting the same error...I've tried looking everywhere and using everyone solution with no luck.
Error
ClassNotFoundException: Attempted to load class "DestinationAppBundle" from namespace "Destination\AppBundle" in /home/dcms/public/html/dcms/apha/app/AppKernel.php line 19. Do you need to "use" it from another namespace?
AppKernel.php
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Destination\AppBundle\DestinationAppBundle(),
new Destination\Auth\HashInterfaceBundle\DestinationHashInterfaceBundle(),
);
File Structure
src
Destination
AppBundle
Any ideas?
first: check if the file src\Destination\AppBundle\DestinationAppBundle.php does exist
second: open DestinationAppBundle.php and chek if the namespace is Destination\AppBundle
third: check if the classname declaration is the same as the filename (in your case : DestinationAppBundle)
Update composer.json like this:
"psr-4": {
"AppBundle\\": "src/AppBundle",
"UserBundle\\": "src/UserBundle"
},
After edit composer.json YOU MUST RUN composer dump-autoload
Verify in AppKernel.php the use of this class DestinationAppBundle
And the namespace in the class DestinationAppBundle
What is the namespace in your DestinationAppBundle.php ?
It should be :
<?php
namespace Destination\AppBundle;
If you are sure the namespace and service definition are right you can try:
Upgrade Symfony version. I had an strange issue with Symfony 2.8.11, new services added gave me a ClassNotFoundException. Upgrading to 2.8.17 solved it.
Try remove app/cache/* contents
Check if you are using a pre-generated boostrap cached file without the "--no-dev" option (composer dump-autoload --optimize --no-dev --classmap-authoritative) and launch command again.
Symfony uses PSR autoload.
You need to configure autoload in the composer.json file:
"autoload": {
"psr-4": {
"": "src/"
},
This will include all files and folders under the \src folder
i`m trying to generate CRUD for some entities in Symfony 2, apparently the
generate:doctrine:crud command is unavailable.
[InvalidArgumentException]
Command "generate:doctrine:crud" is not defined.
also , in the list for available commands, I only get one command.
generate
generate:doctrine:entities Generates entity classes and method stubs from your mapping information
is there a bundle or something in the configuration missing, or what is the cause for not having this functionality.
Addition:
The doctrine:generate:crud command is provided by the SensioGeneratorBundle
Please also make sure you have the bundle available and registered in your app/AppKernel.php like this:
class AppKernel extends Kernel
{
public function registerBundles()
{
// ...
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
// ...
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
// ...
}
As in my example the command is also normally only available in the dev environment. Therefore ...
php app/console --env=prod doctrine:generate:crud
.. or any other configuration that uses production enviroment won't work.
doctrine:generate:crud is the command you should use
You can see a list of commands using php app/console list
I wish to install the bundle into my symfony project. However, I am coming across a few issues. Please accept my ignorance if the answer is trivial but I've tried searching for a solution but alas, I've found nothing.
In my deps file, I have:
[doctrine-couchdb]
git=http://github.com/doctrine/couchdb-odm.git
[DoctrineCouchDBBundle]
git=http://github.com/doctrine/DoctrineCouchDBBundle.git
target=/bundles/Symfony/Bundle/DoctrineCouchDBBundle
I run the bin/vendors install command
In my autoload.php file I have:
'Doctrine\\ODM\\CouchDB'=> __DIR__.'/../vendor/doctrine-couchdb/lib',
I've registered the bundle:
new Doctrine\Bundle\CouchDBBundle\DoctrineCouchDBBundle()
When I run php app/console I get the error:
Fatal error: Class 'Doctrine\Bundle\CouchDBBundle\DoctrineCouchDBBundle' not found in /var/www/symfony2.test/app/AppKernel.php on line 22
I've noticed that for MongoDB ODM you have:
[doctrine-mongodb]
git=http://github.com/doctrine/mongodb.git
is there not a doctrine-couchdb repo? Have you used this bundle?
I changed target to
target= /bundles/Doctrine/Bundle/CouchDBBundle
so now looks like this
[DoctrineCouchDBBundle]
git=http://github.com/doctrine/DoctrineCouchDBBundle.git
target=/bundles/Doctrine/Bundle/CouchDBBundle
because I noticed that name space for couchdb bundle is
namespace Doctrine\Bundle\CouchDBBundle;
therefore adding
new Doctrine\Bundle\CouchDBBundle\DoctrineCouchDBBundle()
to AppKernel will fail, if installation location does not match namespace/class_name.
Detailed setup and configuration here DoctrineCouchDBBundle Git Hub Issue Log
For those that are new to Symfony 2 bundling architecture, you probably wonder what configuration keys are mandatory and available for bundles. Info can be obtained from:
bundle_dir/bundle_name/.../configuration.php
Update :
1.) Check that you also have installed and autoloaded Doctrine\CouchDB
2.) in your git installation
target=/bundles/Symfony/Bundle/DoctrineCouchDBBundle should probably be
target=/bundles/Doctrine/Bundle/DoctrineCouchDBBundle (notice Symfony => Doctrine)
3.) Then change
'Doctrine' => __DIR__.'/../vendor/doctrine/lib',
to
'Doctrine' => array(__DIR__.'/../vendor/doctrine/lib', __DIR__.'/../vendor/bundles'),
Off the top of my head I'd assume either these things:
1.) Cache
2.) 'Doctrine\\ODM\\CouchDB'=> __DIR__.'/../vendor/doctrine-couchdb/lib',
should be above any higher level namespaces ('Doctrine', 'Doctrine\Common')
so it should look like this:
'Doctrine\\ODM\\CouchDB'=> __DIR__.'/../vendor/doctrine-couchdb/lib',
'Doctrine\\DBAL' => __DIR__.'/../vendor/doctrine-dbal/lib',
'Doctrine' => __DIR__.'/../vendor/doctrine/lib',
3.) some configuration missing in config.yml