Symfony 4.1 ReflectionException : Class does not exist - symfony

I keep getting error "ReflectionException : Class does not exist" when access
$em = $args->getEntityManager()
$obj = $args->getEntity()
$meta = $em->getClassMetadata((new \ReflectionClass($obj))->getName());
When I print $meta and exit the process, it seems OK and returns value.
I already tried some solutions: dump autoload, require symfony/form and symfony/config. But I still have no clue.

Related

Facebook CrashReporter Error detected api facebook-business-php

I started with facebook business sdk for php. Was following this doc: https://developers.facebook.com/docs/business-sdk/getting-started/ installed without trouble, then tried testing as they instructed, created src/test.php
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use FacebookAds\Api;
use FacebookAds\Logger\CurlLogger;
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Campaign;
use FacebookAds\Object\Fields\CampaignFields;
$app_id = "{app-id}";
$app_secret = "{appsecret}";
$access_token = "{access-token}";
$account_id = "act_{{adaccount-id}}";
Api::init($app_id, $app_secret, $access_token);
$account = new AdAccount($account_id);
$cursor = $account->getCampaigns();
// Loop over objects
foreach ($cursor as $campaign) {
echo $campaign->{CampaignFields::NAME}.PHP_EOL;
}
filled in the required values. and ran the file. Getting this:
FacebookAds\CrashReporter : Enabled
FacebookAds\CrashReporter : Error detected!
PHP Catchable fatal error: Argument 1 passed to FacebookAds\CrashReporter::buildParamsFromException() must be an instance of Throwable, instance of ErrorException given, called in /var/www/clients/client1/web1/web/vendor/facebook/php-business-sdk/src/FacebookAds/CrashReporter.php on line 146 and defined in /var/www/clients/client1/web1/web/vendor/facebook/php-business-sdk/src/FacebookAds/CrashReporter.php on line 167
Not sure what I am doing wrong. Didnt find much by searching. Can anyone please help?

How do I call the basic WordPress header files?

I'm making a custom form action.php and currently it looks like this:
<?php
// Collect Data
$first = $_POST["first_name"];
$last = $_POST["last_name"];
$email = $_POST["email"];
$pass = $_POST["password"];
$pass2 = $_POST["confirm_password"];
$cat = $_POST["category"];
$tAndC = $_POST["terms_and_conditions"];
$privacy = $_POST["privacy_policy"];
$newsletter = $_POST["newsletter"];
die();
?>
Essentially nothing going on - the problem though is when I want to call a WordPress hook such as something like this:
$user_name = $email;
$user_id = username_exists( $user_name );
it returns an error:
Fatal error: Call to undefined function username_exists()...
I'm aware that there are probably header files I am not calling for the 'undefined function' to actually run.
I have tried adding at the top of the page: wp_head(); - but I get the following error:
Fatal error: Call to undefined function wp_head()
Include
$base_dir = dirname(dirname(__FILE__));
require_once($base_dir."/wp-load.php");
With your desired path and check
Include wp-load.php file (in the root of your wordpress installation) in your php script file like so,
require_once("/path/to/wordpress/wp-load.php");
you will have to provide the abspath of the wp-load file, now you can use all the functions of wordpress in your php script.

get entity from user name FosuserBundle Symfony

i have entity Collab that extend from Fos\UserBundle\Model\User, i want to get the entity from the username that i login .
i my controller :
echo $this->getUser();
$collab->get('collab.collaborateurservice')->findCollaborateurByUserName($this->getUser());
echo $this->getEmailCollaborateur();
in my manager i defined i method :
public function findCollaborateurByUserName ($username){
return $this->getRepository()->findOneBy(array('username'=>$username));
}
i get this exception :
FatalErrorException: Error: Call to a member function get() on a non-object in
how can get this entity??
Your problem is in this lines:
return $this->getRepository()->findOneBy(array('username'=>$username));
$collab->get('collab.collaborateurservice')->findCollaborateurByUserName($this->getUser());
It should be:
return $this->getDoctrine()->getRepository('YourBundleNamespace:Collab')->findOneBy(array('username'=>$username));
$collab = $this->get('collab.collaborateurservice')->findCollaborateurByUserName($this->getUser()->getUsername());
What is $collab? You're getting Fatal Error trying to call get method on variable that was not properly initialized (non-object).

Symfony2 error : Case mismatch between loaded and declared class names:

I'm working on Symfony2 and i updated my project with composer.phar update
Now, when i check my site with app_dev.php i always have this error :
Case mismatch between loaded and declared class names: Blu\ProjectBun
dle\Entity\AccountRepository vs Blu\ProjectBundle\Entity\AccountRepos
itory
It's the same when i clear the dev cache, manually or not. I have nothing special in AccountRepository.php..
Any ideas ?
Edit : I already tried to add if ($name !== $class && 0 === strcasecmp($name, $class)) { in DebugClassLoader.php and no effect
Intent to var_dump($name) and var_dump($class) and strcasecmp($name, $class) to see why you enter in the condition.
though the answer was a typo in the class namespace, this errors occurs also if your entity is defined via xml, i.e. User.orm.xml, and you accidentally name the file lower-case, this will drive nuts the xml loader
create FooNamespace\BarBundle\Resources\config\User.orm.xml
create FooNamespace\BarBundle\Entity\User.php (class User { ... })
I had this problem and after trying all the solutions I found, no one of them worked for me. I am working with Symfony 2.8, Doctrine ORM and Sonata Admin Bundle and this exception appeared when I added an admin class (for a class related with the class showed in the exception message) and I tried to open it.
My mistake was I wrote the name of the database tables in lowercase in Doctrine annotations in the class related, check if you have it in uppercase:
ORM\ManyToOne(targetEntity="Product")
This is a known bug in Symfony2 :
https://github.com/symfony/symfony/commit/8e9cc35
It has been merged in 2.5 but not tagged yet (source)
To check if this is really the case for you, you might want to try modifying the src/Symfony/Component/Debug/DebugClassLoader.php file manually :
// Line 178
if ($name !== $class && 0 === strcasecmp($name, $class)) {
... and check if you still have the problem after clearing your cache
Please Add this if condition in DebugClassLoader.php File at line 177
if ($name === $class) {
if ($name !== $class && 0 === strcasecmp($name, $class)) {
throw new \RuntimeException(sprintf('Case mismatch between loaded and declared class names: %s vs %s', $class, $name));
}
}
It will solve your problem
Location: root\Projectname\Symfony\vendor\symfony\symfony\src\Symfony\Component\Debug
thanks
Your controller name first word is lowercase in your routing.yml
usr_teacher_new:
path: /new
defaults: { _controller: CoreUserBundle:teacher:newteacher }
like teacher..
will be Teacher

Error "Call to a member function on a non-object" when loading Symfony2 fixtures

I'm implementing the classic Blog app with Symfony2, and the "app/console doctrine:fixtures:load" returns an error. My BlogFixtures.php file is like this:
<?php
namespace MGF\Bundles\WebBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use MGF\Bundles\WebBundle\Entity\Blog;
use MGF\Bundles\CRMBundle\Util\Util;
class BlogFixtures extends AbstractFixture implements FixtureInterface
{
public function load(ObjectManager $em)
{
$blog1 = new Blog();
$title = 'First post';
$blog1->setTitle($title);
$slug1 = Util::getSlug($title);
$blog1->setSlug($slug1);
$blog1->setImage('beach.jpg');
$blog1->setTags('symfony2, php, paradise, symblog');
$blog1->setCreated(new \DateTime('now'));
$blog1->setUpdated($blog1->getCreated());
$em->persist($blog1);
$author1 = $em->getRepository('MGFBCBundle:User')->findOneByUser('sarah');
$author1->addBlog($blog1);
$em->persist($author1);
$em->flush();
}
}
And the error:
app/console doctrine:fixtures:load
Careful, database will be purged. Do you want to continue Y/N ?Y
> purging database
> loading MGF\Bundles\WebBundle\DataFixtures\ORM\BlogFixtures
PHP Fatal error: Call to a member function addBlog() on a non-object in /var/www/METRO/src/MGF/Bundles/WebBundle/DataFixtures/ORM/BlogFixtures.php on line 33
Fatal error: Call to a member function addBlog() on a non-object in /var/www/METRO/src/MGF/Bundles/WebBundle/DataFixtures/ORM/BlogFixtures.php on line 33
I don't see where I go wrong. Any hints?
Thanks in advance.
The problem was that even though the user 'sarah' exists in the db from the fixtures, when trying to load fixtures again, db gets purged. So I needed to reference my users when created from the fixtures, and retrieve them by their reference, as explained here:
http://symfony.com/doc/master/bundles/DoctrineFixturesBundle/index.html#sharing-objects-between-fixtures
Fixtures loading is working again.

Resources