symfony2在prod中抛出PHP异常但在dev

时间:2017-10-18 11:17:47

标签: php symfony doctrine

当我登录我的Symfony 2.7应用程序(最近从Symfony 2.3升级)时,它在开发模式下工作正常(app_dev.php),我无法看到使用该探查器的任何实体有任何问题,但是当我尝试prod模式(使用app.php)时,我只进入登录表单屏幕。在=之后我遇到了500 HTTP错误(大概是loginCheck)。下面是我得到的唯一3个日志条目(我认为第一个只是暂停的结果,而不是问题的根源,第二个只是告诉我我在哪条路上,所以第三条消息是我的错误) :

  

[2017-10-18 11:29:46] request.ERROR:未捕获PHP异常Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException:"找不到" GET /favicon.ico&#的路由34; (来自" http://localhost/zign/web/login")" at /Users/mattias/Documents/www/zign/app/cache/apache2handler/prod/classes.php 2079行{" exception":" [object](Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException(代码:0):找不到\" GET /favicon.ico\"(来自\" http://localhost/zign/web/login \")/ 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:匹配路线" fos_user_security_check"。 {" route_parameters" {" _controller":" BizTV \ UserBundle \控制器\ SecurityController :: checkAction"" _route":&#34 ; fos_user_security_check"}," request_uri":" http://localhost/zign/web/login_check"} []

这是我的主要错误:

  

[2017-10-18 11:29:58] request.CRITICAL:未捕获PHP异常Symfony \ Component \ Debug \ Exception \ FatalErrorException:"编译错误:require():打开所需的失败' /Users/mattias/Documents/www/zign/app/cache/apache2handler/prod/doctrine/orm/Proxies/__CG__BizTVBackendBundleEntityCompany.php' (包含路径=':/应用程序/ MAMP / bin中/ PHP / php5.6.27 / LIB / PHP')" at /Users/mattias/Documents/www/zign/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php 209行{"例外":" [对象](Symfony \ Component \ Debug \ Exception \ FatalErrorException(代码:0):编译错误:require():无法打开所需' / 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')/ Users / mattias / Documents / www / zign / vendor / doctrine / common / lib / Doctrine / Common / Proxy / AbstractProxyFactory.php:209)"} []

我正在使用 FOSUserBundle 并在检查器中添加了一些自定义逻辑(见下文),但错误消息似乎是指我的实体公司,尽管在开发模式下根据探查器没有配置,并且一切运行良好(并且始终与以前版本的PHP一起使用)。

这是我的自定义用户检查程序:

<?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);
        }

    }
}

也许是$user->getCompany()我出于某种原因遇到了错误?就像我说的,它以前一直有效,在以前版本的PHP中使用早期版本的Symfony 2,它仍然可以正常运行app_dev.php

公司实体如下所示:

<?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;
    }
}

我刚刚想到我没有对fos_user_security_check路由进行概要分析,因为它在成功loginChec k后重定向到仪表板页面。如果我可以在那里创建一个断点,那么看看开发模式中的探查器有什么意义可能会很有趣,另一方面,我 HAVE 筛选了dev.log文件,并且它没有任何PHP异常。所以,很奇怪prod日志有一个。 app.phpapp_dev.php的行为方式不同吗?

0 个答案:

没有答案