public function testIgnoredAttributes() { $this->normalizer->setIgnoredAttributes(array('foo', 'bar', 'camelCase')); $obj = new GetSetDummy(); $obj->setFoo('foo'); $obj->setBar('bar'); $this->assertEquals(array('fooBar' => 'foobar'), $this->normalizer->normalize($obj, 'any')); }
public function userDataAction() { $user = $this->get('security.context')->getToken()->getUser(); $normalizer = new GetSetMethodNormalizer(); $normalizer->setIgnoredAttributes(array('password', 'roles', 'salt')); $serializer = new Serializer(array($normalizer), array(new JsonEncoder())); $json = $serializer->serialize($user, 'json'); return new Response($json); }
/** * @param Pool $adminPool * @param EngineInterface $templating * @param CategoryManager $categoryManager * @param TransactionManager $transactionManager */ public function __construct(Pool $adminPool, EngineInterface $templating, CategoryManager $categoryManager, TransactionManager $transactionManager) { parent::__construct($adminPool, $templating); $this->categoryManager = $categoryManager; $this->transactionManager = $transactionManager; $normalizer = new GetSetMethodNormalizer(); $normalizer->setIgnoredAttributes(['category']); $this->serializer = new Serializer([$normalizer], [new JsonEncoder()]); }
/** * Lists all Task entities. * */ public function listAction() { $user = $this->get('security.context')->getToken()->getUser(); $em = $this->getDoctrine()->getManager(); $tasks = $em->getRepository('STMSBundle:Task')->findBy(array('user' => $user)); $normalizer = new GetSetMethodNormalizer(); $normalizer->setIgnoredAttributes(array('user')); $normalizer->setCallbacks(array('date' => function ($dateTime) { return $dateTime->format("Y-m-d"); })); $serializer = new Serializer(array($normalizer), array(new JsonEncoder())); $json = $serializer->serialize($tasks, 'json'); $response = new Response($json); $response->headers->set('Content-Type', 'application/json'); return $response; }
/** * @param string $bundleComposer * * @return bool|Bundle */ private function getBundle($bundleComposer) { if (!file_exists($bundleComposer)) { return false; } $bundleComposerData = file_get_contents($bundleComposer); $normalizer = new GetSetMethodNormalizer(); $normalizer->setIgnoredAttributes(array('require', 'keywords')); $encoder = new JsonEncoder(); $serializer = new Serializer(array($normalizer), array($encoder)); $bundle = $serializer->deserialize($bundleComposerData, 'CampaignChain\\CoreBundle\\Entity\\Bundle', 'json'); // Set the version of the installed bundle. $version = $this->packageService->getVersion($bundle->getName()); /* * If version does not exist, this means two things: * * 1) Either, it is a package in require-dev of composer.json, but * CampaignChain is not in dev mode. Then we don't add this package. * * 2) Or it is a bundle in Symfony's src/ directory. Then we want to * add it. */ if (!$version) { // Check if bundle is in src/ dir. $bundlePath = str_replace($this->rootDir . DIRECTORY_SEPARATOR, '', $bundleComposer); if (strpos($bundlePath, 'src' . DIRECTORY_SEPARATOR) !== 0) { // Not in src/ dir, so don't add this bundle. return false; } else { $version = 'dev-master'; } } $bundle->setVersion($version); // Set relative path of bundle. $bundle->setPath(str_replace($this->rootDir . DIRECTORY_SEPARATOR, '', str_replace(DIRECTORY_SEPARATOR . 'composer.json', '', $bundleComposer))); return $bundle; }