Skip to content

Instantly share code, notes, and snippets.

@j
Created June 15, 2011 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j/1026584 to your computer and use it in GitHub Desktop.
Save j/1026584 to your computer and use it in GitHub Desktop.
The Error
Fatal error: method_exists(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "Proxies\JStoutMainBundleEntityLocationProxy" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in /www/jstout/vendor/doctrine/lib/Doctrine/ORM/UnitOfWork.php on line 2266 Call Stack: 0.0001 622816 1. {main}() /www/jstout/web/app_dev.php:0 0.0120 1391096 2. Symfony\Component\HttpKernel\Kernel->handle() /www/jstout/web/app_dev.php:21 0.0155 1643168 3. Symfony\Bundle\FrameworkBundle\HttpKernel->handle() /www/jstout/app/bootstrap.php.cache:612 0.0155 1643888 4. Symfony\Component\HttpKernel\HttpKernel->handle() /www/jstout/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php:44 0.0155 1643888 5. Symfony\Component\HttpKernel\HttpKernel->handleRaw() /www/jstout/app/bootstrap.php.cache:416 0.0808 3808568 6. call_user_func_array() /www/jstout/app/bootstrap.php.cache:438 0.0808 3808816 7. JStout\MainBundle\Controller\VendorController->signupAction() /www/jstout/app/bootstrap.php.cache:0 0.1496 5248224 8. JStout\MainBundle\Form\Vendor\SignupHandler->process() /www/jstout/src/JStout/MainBundle/Controller/VendorController.php:55 0.1994 6163232 9. Doctrine\ORM\EntityManager->flush() /www/jstout/src/JStout/MainBundle/Form/Vendor/SignupHandler.php:57 0.1994 6163232 10. Doctrine\ORM\UnitOfWork->commit() /www/jstout/vendor/doctrine/lib/Doctrine/ORM/EntityManager.php:328 0.1994 6163232 11. Doctrine\ORM\UnitOfWork->computeChangeSets() /www/jstout/vendor/doctrine/lib/Doctrine/ORM/UnitOfWork.php:249 0.1998 6187424 12. Doctrine\ORM\UnitOfWork->computeChangeSet() /www/jstout/vendor/doctrine/lib/Doctrine/ORM/UnitOfWork.php:505 0.2000 6196648 13. Doctrine\ORM\UnitOfWork->computeAssociationChanges() /www/jstout/vendor/doctrine/lib/Doctrine/ORM/UnitOfWork.php:490 0.2000 6221624 14. Doctrine\ORM\UnitOfWork::objToStr() /www/jstout/vendor/doctrine/lib/Doctrine/ORM/UnitOfWork.php:572 0.2000 6221752 15. method_exists() /www/jstout/vendor/doctrine/lib/Doctrine/ORM/UnitOfWork.php:2266
<?php
namespace JStout\MainBundle\Form\Vendor;
use JStout\MainBundle\Component\Form\FormHandlerInterface,
Symfony\Component\Form\Form,
Symfony\Component\HttpFoundation\Request,
Doctrine\ORM\EntityManager,
JStout\MainBundle\Entity,
Symfony\Component\Security\Acl\Domain\ObjectIdentity,
Symfony\Component\Security\Acl\Domain\UserSecurityIdentity,
Symfony\Component\Security\Acl\Permission\MaskBuilder;
class SignupHandler implements FormHandlerInterface
{
protected $form;
protected $request;
protected $entityManager;
public function buildFormHandler(Form $form, Request $request, EntityManager $entityManager)
{
$this->form = $form;
$this->request = $request;
$this->entityManager = $entityManager;
}
public function process(array $extras)
{
if ('POST' == $this->request->getMethod()) {
// bind form data
$this->form->bindRequest($this->request);
// If form is valid
if ($this->form->isValid() && ($vendor = $this->form->getData()) instanceOf Entity\Vendor) {
// If owner is valid, create user
if ($vendor->getOwner() instanceOf Entity\User) {
$encoder = $extras['encoderFactory']->getEncoder($vendor->getOwner());
$salt = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
$vendor->getOwner()->setSalt($salt);
$vendor->getOwner()->setPassword($encoder->encodePassword($vendor->getOwner()->getPlainPassword(), $salt));
$vendor->getOwner()->setEnabled(1);
$vendor->getOwner()->addRole('USER_VENDOR');
}
// persist vendor
$this->entityManager->persist($vendor);
$this->entityManager->flush();
// create acl
$acl = $extras['aclProvider']->createAcl(ObjectIdentity::fromDomainObject($vendor));
// grant owner access
$acl->insertObjectAce(UserSecurityIdentity::fromAccount($vendor->getOwner()), MaskBuilder::MASK_OWNER);
// update acl
$extras['aclProvider']->updateAcl($acl);
return $vendor;
}
}
return false;
}
}
<?php
namespace JStout\MainBundle\Form\Vendor;
use Symfony\Component\Form\AbstractType,
Symfony\Component\Form\FormBuilder,
JStout\MainBundle\Form\User\SignupType as UserType,
JStout\MainBundle\Form\Common\LocationType;
class SignupType extends AbstractType
{
protected $loggedIn = false;
public function __constructor($security)
{
$this->loggedIn = $security->isGranted('ROLE_USER');
}
public function buildForm(FormBuilder $builder, array $options)
{
if (false === $this->isLoggedIn()) {
$builder->add('owner', new UserType());
}
$builder
->add('name')
->add('website')
->add('phone')
->add('phoneExt')
->add('description')
->add('locations', new VendorLocationType());
}
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'JStout\MainBundle\Entity\Vendor'
);
}
protected function isLoggedIn()
{
return $this->loggedIn;
}
}
<?php
namespace JStout\MainBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller,
Sensio\Bundle\FrameworkExtraBundle\Configuration as Extra,
JStout\MainBundle\Component\Form\FormHandlerInterface,
JStout\MainBundle\Entity\User,
JStout\MainBundle\Entity\Vendor,
JStout\MainBundle\Entity\Location,
JStout\MainBundle\Form\Vendor\SignupType,
JStout\MainBundle\Form\Vendor\SignupHandler;
/**
* @Extra\Route("/vendor")
*/
class VendorController extends Controller
{
/**
* @Extra\Route(name="vendor_index")
* @Extra\Template()
*/
public function indexAction()
{
return array();
}
/**
* @Extra\Route("/sign-up", name="vendor_signup")
* @Extra\Template()
*/
public function signupAction()
{
// initialize new vendor
$vendor = new Vendor();
if (($user = $this->get('request')->getSession()->get('user')) instanceOf User) {
$vendor->setOwner($user);
}
// get vendor signup form
$form = $this->get('form.factory')->create(new SignupType(), $vendor);
// get form handler for vendor form
$formHandler = $this->get('form.handler')->create(new SignupHandler(), $form);
// extra data for form handler
$extras = array(
'encoderFactory' => $this->get('security.encoder_factory'),
'aclProvider' => $this->get('security.acl.provider')
);
// redirect if form submission was valid
if (($vendor = $formHandler->process($extras)) instanceOf Vendor) {
return $this->redirect($this->generateUrl('vendor_index'));
}
return array(
'form' => $form->createView()
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment