我如何使用$ sessData,这是一个blob?
示例实体
<?php
namespace Acme\DemoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Session
*
* @ORM\Table(name="sessions")
* @ORM\Entity
*/
class Session
{
/**
* @var string
*
* @ORM\Column(name="sess_id", type="string", length=128)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $sessId;
/**
* @var string
*
* @ORM\Column(name="sess_data", type="blob", length=65535, nullable=false)
*/
private $sessData;
/**
* @var integer
*
* @ORM\Column(name="sess_time", type="integer", nullable=false, options={"unsigned"=true})
*/
private $sessTime;
/**
* @var integer
*
* @ORM\Column(name="sess_lifetime", type="integer", nullable=false)
*/
private $sessLifetime;
}
示例命令。
<?php
namespace Acme\UserBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Acme\UserBundle\Entity\Session;
/**
* Class ClearSessionsCommand
* @package Acme\UserBundle\Command
*/
class ClearSessionsCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('acme:clear:sessions')
->setDescription('Deletes old sessions from database')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var \Doctrine\Bundle\DoctrineBundle\Registry $doctrine */
$doctrine = $this->getContainer()->get('doctrine');
$repository = $doctrine->getManager()->getRepository('AcmeUserBundle:Session');
$sessions = $repository->findAll();
foreach($sessions as $session)
{
/** @var Session $session */
var_dump($session->getSessData());
}
}
}
这就是输出。
class Acme\UserBundle\Entity\Session#460 (4) {
private $sessId => string(26) "5v0as58i11vgikih7rb0b7fg41"
private $sessData => resource(419) of type (stream)
private $sessTime => int(1421508757)
private $sessLifetime => int(1440)
}
我希望你能帮助我。
我也尝试使用&#34; array&#34;,&#34; simple_array&#34;和&#34; json_array&#34;。 但是如果我用纯文本查看值,我会有这样的格式。
_sf2_attributes|a:2:{s:18:"_csrf/authenticate";s:43:"esEvNzkJgkPN3JcgVWO71ArAHnoMxK_ChC1qdXT4bM4";s:14:"_security_main";s:691:"C:74:"Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken":603:{a:3:{i:0;N;i:1;s:4:"main";i:2;s:563:"a:4:{i:0;C:26:"Acme\UserBundle\Entity\User":227:{a:9:{i:0;s:88:"4T+akBl30pcGyIDl3MB64TT/o4izQZ/CA/JDHurok50o33g3L0bEgDYMj+itI5G6JWQmzH7gHTrDmLeE7I9yeQ==";i:1;s:31:"cljvnnze8jwo8ck4og8gcg08c4o0ww4";i:2;s:8:"max";i:3;s:8:"Max";i:4;b:0;i:5;b:0;i:6;b:0;i:7;b:1;i:8;i:1;}}i:1;b:1;i:2;a:2:{i:0;O:41:"Symfony\Component\Security\Core\Role\Role":1:{s:47:"
我不知道这可能是一种格式。
如果我删除_sf2_attributes|
,则可能会将其序列化。
我会删除所有超过一天且未使用记住选项登录的会话。
提前致谢!