When I log into my Symfony 2.7 app (recently upgraded from Symfony 2.3) it works fine in dev mode (app_dev.php
), and I can't see anything wrong with any entities using the profiler, but when I try in prod mode (using app.php
) I only get to the login form screen. After= that I am hit with a 500 HTTP error (presumably upon loginCheck
). Below are the only 3 log entries I get (the first one I think is only a consequence of the halt, not the root of the problem, and the second just tells me what route I am on, so the third message is my error):
[2017-10-18 11:29:46] request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /favicon.ico" (from "http://localhost/zign/web/login")" at /Users/mattias/Documents/www/zign/app/cache/apache2handler/prod/classes.php line 2079 {"exception":"[object] (Symfony\Component\HttpKernel\Exception\NotFoundHttpException(code: 0): No route found for \"GET /favicon.ico\" (from \"http://localhost/zign/web/login\") at /Users/mattias/Documents/www/zign/app/cache/apache2handler/prod/classes.php:2079, Symfony\Component\Routing\Exception\ResourceNotFoundException(code: 0): at /Users/mattias/Documents/www/zign/app/cache/apache2handler/prod/appProdProjectContainerUrlMatcher.php:1169)"} []
[2017-10-18 11:29:57] request.INFO: Matched route "fos_user_security_check". {"route_parameters":{"_controller":"BizTV\UserBundle\Controller\SecurityController::checkAction","_route":"fos_user_security_check"},"request_uri":"http://localhost/zign/web/login_check"} []
This is my main error:
[2017-10-18 11:29:58] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalErrorException: "Compile Error: require(): Failed opening required '/Users/mattias/Documents/www/zign/app/cache/apache2handler/prod/doctrine/orm/Proxies/__CG__BizTVBackendBundleEntityCompany.php' (include_path='.:/Applications/MAMP/bin/php/php5.6.27/lib/php')" at /Users/mattias/Documents/www/zign/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php line 209 {"exception":"[object] (Symfony\Component\Debug\Exception\FatalErrorException(code: 0): Compile Error: require(): Failed opening required '/Users/mattias/Documents/www/zign/app/cache/apache2handler/prod/doctrine/orm/Proxies/__CG__BizTVBackendBundleEntityCompany.php' (include_path='.:/Applications/MAMP/bin/php/php5.6.27/lib/php') at /Users/mattias/Documents/www/zign/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php:209)"} []
I am using FOSUserBundle and have added some custom logic in the checker (see below), but the error message seems to refer to my entity Company, although no config according to the profiler in dev mode, and everything works well (and always has with previous versions of PHP).
Here is my custom user checker:
<?php
namespace BizTV\UserBundle\Controller;
use Symfony\Component\Security\Core\User\UserCheckerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\Exception\CredentialsExpiredException;
use Symfony\Component\Security\Core\Exception\LockedException;
use Symfony\Component\Security\Core\Exception\DisabledException;
use Symfony\Component\Security\Core\Exception\AccountExpiredException;
class UserCheckerNew implements UserCheckerInterface
{
protected $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public function checkPreAuth(UserInterface $user)
{
if (!$user instanceof AdvancedUserInterface) {
return;
}
if (!$user->isCredentialsNonExpired()) {
throw new CredentialsExpiredException('User credentials have expired.', $user);
}
}
/**
* {@inheritdoc}
*/
public function checkPostAuth(UserInterface $user)
{
//Validate HOST here, make it look as though account doesn't exist if on wrong host (ie. trying to log into quickstore from login.branded.se)
$host = $this->container->get('request')->getHost();
if ($host != "localhost") { //bypass all checks when on localhost
$brandedHost = $user->getCompany()->getBrandedHost();
if ( $brandedHost == "" ) { //if unset assume zign
$brandedHost = "login.zign.se";
}
if ( $host != $brandedHost ) {
throw new LockedException('Invalid username or password.');
}
}
// end of host validation
//Test for companylock...
if ( !$user->getCompany()->getActive() ) {
throw new LockedException('The company of this user is locked.');
}
if ( $user->getLocked() ) {
throw new LockedException('The admin of this company has locked this user.');
}
if (!$user instanceof AdvancedUserInterface) {
return;
}
if (!$user->isAccountNonLocked()) {
throw new LockedException('User account is locked.', $user);
}
if (!$user->isEnabled()) {
throw new DisabledException('User account is disabled.', $user);
}
if (!$user->isAccountNonExpired()) {
throw new AccountExpiredException('User account has expired.', $user);
}
}
}
Is it perhaps on the $user->getCompany()
I hit an error for some reason? Like I said, it has always worked before, in previous versions of PHP with an earlier version of Symfony 2, and it still works fine running through app_dev.php
The Company entity looks like this:
<?php
namespace BizTV\BackendBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* BizTV\BackendBundle\Entity\Company
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="BizTV\BackendBundle\Entity\companyRepository")
* @UniqueEntity(fields = "company_name", message = "Ett företag med det namnet finns redan, försök igen.")
*/
class Company
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string $company_name
* @Assert\NotBlank(message = "Du måste ange ett namn för företaget")
* @Assert\Regex(
* pattern="/^[a-z0-9_]+$/",
* match=true,
* message="Företagsnamnet får bestå av små bokstäver (a-z) och får inte innehålla några specialtecken utom understreck (_)"
* )
* @ORM\Column(name="company_name", unique=true, type="string", length=255)
*/
private $company_name;
/**
* @var boolean $active
*
* @ORM\Column(name="active", type="boolean")
*/
private $active;
/**
* @var boolean $backgroundMusic
*
* @ORM\Column(name="backgroundMusic", type="boolean")
*/
private $backgroundMusic;
/**
* @var integer $mediaSpace
*
* @ORM\Column(name="media_space", type="integer")
*/
private $mediaSpace;
/**
* @ORM\ManyToMany(targetEntity="BizTV\ContentManagementBundle\Entity\Template", mappedBy="companies")
*/
private $templatePermissions;
/**
* @ORM\ManyToMany(targetEntity="BizTV\LayoutManagementBundle\Entity\LayoutTemplate", mappedBy="companies")
*/
private $layoutTemplatePermissions;
/**
* @var integer $width
*
* @ORM\Column(name="width", type="integer", nullable=true)
*/
private $width;
/**
* @var integer $height
*
* @ORM\Column(name="height", type="integer", nullable=true)
*/
private $height;
/**
* @var string $brandedToken
*
* @ORM\Column(name="branded_token", type="string", length=255)
*
*/
private $brandedToken;
/**
* @var string $brandedTitle
*
* @ORM\Column(name="branded_title", type="string", length=255)
*
*/
private $brandedTitle;
/**
* @var string $brandedHost
*
* @ORM\Column(name="branded_host", type="string", length=255)
*
*/
private $brandedHost;
/**
* @var object BizTV\UserBundle\Entity\UserGroup
*
* @ORM\OneToMany(targetEntity="BizTV\UserBundle\Entity\UserGroup", mappedBy="company")
*/
protected $userGroups;
public function __construct()
{
$this->active = true;
$this->templatePermissions = new \Doctrine\Common\Collections\ArrayCollection();
$this->layoutTemplatePermissions = new \Doctrine\Common\Collections\ArrayCollection();
$this->userGroups = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set company_name
*
* @param string $companyName
*/
public function setCompanyName($companyName)
{
$this->company_name = $companyName;
}
/**
* Get company_name
*
* @return string
*/
public function getCompanyName()
{
return $this->company_name;
}
/**
* Set active
*
* @param boolean $active
*/
public function setActive($active)
{
$this->active = $active;
}
/**
* Get active
*
* @return boolean
*/
public function getActive()
{
return $this->active;
}
/**
* Add templatePermissions
*
* @param BizTV\ContentManagementBundle\Entity\Template $templatePermissions
*/
public function addTemplate(\BizTV\ContentManagementBundle\Entity\Template $templatePermissions)
{
$this->templatePermissions[] = $templatePermissions;
}
/**
* Get templatePermissions
*
* @return Doctrine\Common\Collections\Collection
*/
public function getTemplatePermissions()
{
return $this->templatePermissions;
}
/**
* Add layoutTemplatePermissions
*
* @param BizTV\LayoutManagementBundle\Entity\LayoutTemplate $layoutTemplatePermissions
*/
public function addLayoutTemplate(\BizTV\LayoutManagementBundle\Entity\LayoutTemplate $layoutTemplatePermissions)
{
$this->layoutTemplatePermissions[] = $layoutTemplatePermissions;
}
/**
* Get layoutTemplatePermissions
*
* @return Doctrine\Common\Collections\Collection
*/
public function getLayoutTemplatePermissions()
{
return $this->layoutTemplatePermissions;
}
/**
* Set backgroundMusic
*
* @param boolean $backgroundMusic
*/
public function setBackgroundMusic($backgroundMusic)
{
$this->backgroundMusic = $backgroundMusic;
}
/**
* Get backgroundMusic
*
* @return boolean
*/
public function getBackgroundMusic()
{
return $this->backgroundMusic;
}
public function getCompanyNameLength() {
return strlen( utf8_decode( $this->getCompanyName() ) );
}
/**
* Set mediaSpace
*
* @param integer $mediaSpace
*/
public function setMediaSpace($mediaSpace)
{
$this->mediaSpace = $mediaSpace;
}
/**
* Get mediaSpace
*
* @return integer
*/
public function getMediaSpace()
{
return $this->mediaSpace;
}
/**
* Set width
*
* @param integer $width
*/
public function setWidth($width = null)
{
$this->width = $width;
}
/**
* Get width
*
* @return integer
*/
public function getWidth()
{
return $this->width;
}
/**
* Set height
*
* @param integer $height
*/
public function setHeight($height = null)
{
$this->height = $height;
}
/**
* Get height
*
* @return integer
*/
public function getHeight()
{
return $this->height;
}
/**
* Set brandedTitle
*
* @param string $brandedTitle
* @return company
*/
public function setBrandedTitle($brandedTitle="")
{
$this->brandedTitle = $brandedTitle;
return $this;
}
/**
* Get brandedTitle
*
* @return string
*/
public function getBrandedTitle()
{
return $this->brandedTitle;
}
/**
* Set brandedHost
*
* @param string $brandedHost
* @return company
*/
public function setBrandedHost($brandedHost="")
{
$this->brandedHost = $brandedHost;
return $this;
}
/**
* Get brandedHost
*
* @return string
*/
public function getBrandedHost()
{
return $this->brandedHost;
}
/**
* Add templatePermissions
*
* @param \BizTV\ContentManagementBundle\Entity\Template $templatePermissions
* @return company
*/
public function addTemplatePermission(\BizTV\ContentManagementBundle\Entity\Template $templatePermissions)
{
$this->templatePermissions[] = $templatePermissions;
return $this;
}
/**
* Remove templatePermissions
*
* @param \BizTV\ContentManagementBundle\Entity\Template $templatePermissions
*/
public function removeTemplatePermission(\BizTV\ContentManagementBundle\Entity\Template $templatePermissions)
{
$this->templatePermissions->removeElement($templatePermissions);
}
/**
* Add layoutTemplatePermissions
*
* @param \BizTV\LayoutManagementBundle\Entity\LayoutTemplate $layoutTemplatePermissions
* @return company
*/
public function addLayoutTemplatePermission(\BizTV\LayoutManagementBundle\Entity\LayoutTemplate $layoutTemplatePermissions)
{
$this->layoutTemplatePermissions[] = $layoutTemplatePermissions;
return $this;
}
/**
* Remove layoutTemplatePermissions
*
* @param \BizTV\LayoutManagementBundle\Entity\LayoutTemplate $layoutTemplatePermissions
*/
public function removeLayoutTemplatePermission(\BizTV\LayoutManagementBundle\Entity\LayoutTemplate $layoutTemplatePermissions)
{
$this->layoutTemplatePermissions->removeElement($layoutTemplatePermissions);
}
/**
* Set brandedToken
*
* @param string $brandedToken
* @return company
*/
public function setBrandedToken($brandedToken="")
{
$this->brandedToken = $brandedToken;
return $this;
}
/**
* Get brandedToken
*
* @return string
*/
public function getBrandedToken()
{
return $this->brandedToken;
}
/**
* Add userGroups
*
* @param \BizTV\UserBundle\Entity\UserGroup $userGroups
* @return company
*/
public function addUserGroup(\BizTV\UserBundle\Entity\UserGroup $userGroups)
{
$this->userGroups[] = $userGroups;
return $this;
}
/**
* Remove userGroups
*
* @param \BizTV\UserBundle\Entity\UserGroup $userGroups
*/
public function removeUserGroup(\BizTV\UserBundle\Entity\UserGroup $userGroups)
{
$this->userGroups->removeElement($userGroups);
}
/**
* Get userGroups
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getUserGroups()
{
return $this->userGroups;
}
}
It just occurred to me that I have not been profiling the fos_user_security_check
route, because it redirects to the dashboard page upon successful loginChec
k. Perhaps it would be interesting to see what the profiler in dev mode has to say if I could create a breakpoint there, on the other hand I HAVE screened the dev.log file and it has no PHP exceptions anyways. So, it is curious how the prod log has one. Do app.php
and app_dev.php
behave differently?