Sometimes you need to put a constraint on a whole class, rather than a single value. Duplicate usernames are a good example of this – you don’t want to be able to set a username to one that is already in use – but if it is in use with the user you are currently working on, you don’t want to flag it up as an error!
Lets use that as an example. You have a Username constraint and a UsernameValidator object to do the actual validation. We need to supply the validator an object, so we need to put the following method inside the Username object.
public function getTargets()
{
return self::CLASS_CONSTRAINT;
}
This will turn the first parameter in our isValid function in the UsernameValidator class to an object.
public function isValid($user, Constraint $constraint)
Finally, you can call the constraint from your YAML validation file.
User:
constraints:
- nocs:UniqueUsername: ~
Normally, under user you would have getters and properties – but here we’re adding a new section named “constraints” which lists all the class constraints.
Often, our society fails to give scientists the credit they deserve.
Take homo erectus for example. A lot of scientists have had a lot of laughs out of the fact that they managed to convince the world that homo erectus was the name of an evolutionary step (which it is of course) and not just a really silly name they thought they would try their luck with.
But nowhere is it more clear than the people who study using the many telescopes located in Hawaii.
At some point in human history, a scientist when to a grant panel, and the grant panel asked them where the best place to put a telescope would be. Said scientist must have then looked at them slowly and sensing they trusted their judgement, decided to try their luck once again.
“Hawaii!” the scientist would have said, trying to sound more confident than they really were.
“Hawaii?” the chair of the grant panel would have enquired. “Why would Hawaii be the best place to put a telescope?”
“Well…” replies the scientist, trying to think on their feet as fast as they possibly could. “It’s the altitude you see!” “The altitude? Hawaii is an island, surely it is at sea level?” “Yes… but those mountains are very tall! Very tall indeed!”
“Seems like there would be a lot of places at high altitude. Are you sure you’re not just making this up so you can go live on a tropical island and go surfing every day?” “No, no” replies the scientist, “Hawaii has the tallest mountains and the clearest skies – it has to be Hawaii.”
“Well then”, says the grant panel chair, slamming down his approved stamp, “I guess that is that.” Thus began a golden age for science…
If you’re interested in good user experience design (and who isn’t, right!) then it might be good to get the perspective of someone who actually studies users – someone like a psychologist for example. Luckily, one such psychologist is interested in such matters and has written rather a good article about it.
Over at UX Magazine, Susan Weinschenk has written The Psychologist’s View of UX Design and it provides a very useful breakdown of a lot of UX areas and how she views them. Well worth a read.
Recently, I finished reading the complete Harry Potter series. Well, listening in any case.
I had read the first three and a half books as a child, and they were quite entertaining, so when I found out that I could have over one hundred hours of Steven Fry’s voice in my ears, I decided it was definitely worth a listen. That isn’t to say I didn’t agree with Stewart Lee’s take on the whole series.
But having got through them all, I’m now a sold up Potter fan! Rowling’s exploration of the magical world is entertaining, enthralling and all-round good escapism. It seems unlikely that at 26 I’ll be getting my letter from Hogwarts – but I can dream!
While some of the value is certainly lost on the adult audience – Harry’s dealings with the fairer sex for example, most of it was retained sufficiently to keep my entertained through all seven books.
I’m pleased to report that White Rose Speakers experienced great success with our Open Meeting last week!
The agenda finally came together, albeit with only one prepared speech as the other speaker dropped out on the morning of the event and included lots of our regular members returning as well as a visit from our Area Governor Shelagh, who it is always a pleasure to have along.
More importantly however, we signed up two brand new members and one-relapsed member, giving a positive boost to our numbers. We have lots more exciting plans in the works too, so the future for the club is looking bright.
But he has done what some might consider the next best thing – and produced not one, but two lists of documentaries that he thinks are awesome. I haven’t checked any of them out yet, but I plan to. You can find the lists here and here.
Having been struck down with the flu most of last week, I’ve been spending a lot of time in bed, watching Jonathan Creek.
It’s actually not that old, the first episode was broadcast in 1997, but it’s certainly starting to show its age. Floppy disks, VHS cassettes, an age before you could and would look up everything on the internet – it feels like a historial drama now. Not to mention that the first few episodes weren’t even in widescreen.
It also left me with a very torn feeling – I don’t want to move out of the city but at the same time, I now have a strong desire to live in a windmill. Tough call.
I’m also very pleased to see that they are making a brand new episode of Jonathan Creek, that will appear this Easter as a one off feature length episode!
Just need a new Louis Theroux documentary now and it will be the best Easter ever…
Want to use the Validation module in your Symfony2 unit tests? No problem, thanks to the ValidatorFactory, it’s relatively straight forward.
use Symfony\Component\Validator\ValidatorFactory;
class ExampleTest extends \PHPUnit_Framework_TestCase
{
public function testSomething()
{
$validator = ValidatorFactory::buildDefault()->getValidator();
}
}
Simply include the ValidatorFactory namespace and then use the class and it’s default values method to deliver you a validator, which you can then validate your objects against just as if it was in a controller.
Last month, I had the opportunity to take the Toastmaster role at Leeds City, for the third month in a row.
That means that out of the last six meetings Leeds City has held, I’ve been Toastmaster three times, I’ve taken two best speaker ribbons (one each time I gave a prepared speech) and done a timekeeper role to ensure we were finished in time for the Christmas party (that I organised).
So what was my theme for the evening? You get out what you put in!
As I pointed out – most of the other members of the club are currently subsidising my education. We all pay the same monthly dues whether you don’t turn up at all – or whether you turn up every meeting and work your way round all the roles. Toastmasters is about getting stuck in, and if you don’t embrace that, you’re never going to get your full value.