Skip to content

Instantly share code, notes, and snippets.

@aderuwe
Created December 31, 2012 13:30
Show Gist options
  • Save aderuwe/4419771 to your computer and use it in GitHub Desktop.
Save aderuwe/4419771 to your computer and use it in GitHub Desktop.
Using a data_class for the heck of it?
<?php
namespace Comforce\Bundle\ImmoforceBundle\Model;
use Comforce\Bundle\GeoPostcodeBundle\Entity\Province;
class ProvinceSelector
{
private $province;
/**
* @param Province $province
* @return $this
*/
public function setProvince(Province $province)
{
$this->province = $province;
return $this;
}
/**
* @return Province|null
*/
public function getProvince()
{
return $this->province;
}
}
/*
Just to be able to do:
$selector = new ProvinceSelector();
$form = $this->createForm(new ProspectingProvinceType(), $selector);
if ($request->isMethod('post')) {
$form->bind($request);
if ($form->isValid()) {
$province = $selector->getProvince()
}
}
*/
/*
Alternatively, I could skip the class and do:
$form = $this->createForm(new ProspectingProvinceType());
if ($request->isMethod('post')) {
$form->bind($request);
if ($form->isValid()) {
$data = $form->getData();
$province = $data['province'];
}
}
But I feel this is ugly...
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment