Skip to content

Instantly share code, notes, and snippets.

View baldurrensch's full-sized avatar

Baldur Rensch baldurrensch

  • Sourceability LLC
  • Irvine, CA
View GitHub Profile
@baldurrensch
baldurrensch / gist:3318103
Created August 10, 2012 21:23
HalResource Interface
<?php
namespace Hautelook\ApiBundle\Entity;
/**
* Hautelook\MainBundle\Entity\HalResource
* This interface should be implemented by all entities that are used in a Hal enabled JSON response.
* It standardizes the way to specify the resource rel and the links that should be added to the entities.
*
* @author Baldur Rensch <baldur.rensch@hautelook.com>
@baldurrensch
baldurrensch / gist:3363685
Created August 15, 2012 21:05
Credit Card Model class
<?php
namespace Acme\DV2Bundle\Model;
use Acme\DV2Bundle\Exception\UnsupportedCreditCardTypeException;
use Acme\DV2Bundle\Exception\UnknownCreditCardTypeException;
/**
* Acme\DV2Bundle\Entity\CreditCard
*/
@baldurrensch
baldurrensch / gist:3363726
Created August 15, 2012 21:12
Credit Card Unit Tests
<?php
namespace Acme\DV2Bundle\Tests\Model;
use Acme\DV2Bundle\Model\CreditCard;
class CreditCardTest extends \PHPUnit_Framework_TestCase
{
public function testMod10()
{
@baldurrensch
baldurrensch / gist:3363772
Created August 15, 2012 21:21
Credit Card Validation
Acme\DV2Bundle\Model\CreditCard:
properties:
creditCardNumber:
- NotBlank: { groups: [flow_checkoutForm_step2]}
- MinLength: {limit: 15, groups: [flow_checkoutForm_step2]}
- MaxLength: {limit: 16, groups: [flow_checkoutForm_step2]}
creditCardCVV:
- NotBlank: { groups: [flow_checkoutForm_step2]}
- Regex: { pattern: "/^\d{3,4}$/", message: "Invalid CVV code", groups: [flow_checkoutForm_step2] }
getters:
{% form_theme form 'AcmeBundle:Default:designFormDesignOptionsTemplate.html.twig' %}
<fieldset>
<legend>Options</legend>
{{ form_errors(form.designOptions) }}
{{ form_widget(form.designOptions) }}
</fieldset>
{% block choice_widget %}
{% spaceless %}
<div class="control-group">
{% for child in form %}
{{ form_label(child) }}
{{ form_widget(child) }}</label>
{% endfor %}
</div>
public function set(array $params)
{
foreach ($params as $key => $value) {
$this->$key = $value;
}
}
@baldurrensch
baldurrensch / gist:3669417
Created September 7, 2012 20:38
Simple field example
<?php
// Of course you also need your Doctrine Annotations
class Example
{
protected $firstName;
protected $lastName;
protected $username;
public function setFirstName($firstName)
@baldurrensch
baldurrensch / feistel.php
Created September 12, 2012 22:58
Feistel Hash
<?php
/**
* This function computes a hash of an integer. This can be used to not expose values to a customer, such as
* not giving them the id value for passing them to URLs. This algorithm is a bidirectional encryption (Feistel cipher) that maps
* the integer space onto itself.
*
* @link http://wiki.postgresql.org/wiki/Pseudo_encrypt Algorithm used
* @link http://en.wikipedia.org/wiki/Feistel_cipher Wikipedia page about Feistel ciphers
* @param int $value
@baldurrensch
baldurrensch / KernelAwareTest.php
Created September 17, 2012 16:32 — forked from jakzal/KernelAwareTest.php
KernelAwareTest
<?php
require_once dirname(__DIR__).'/../../../../app/AppKernel.php';
/**
* Test case class helpful with Entity tests requiring the database interaction.
* For regular entity tests it's better to extend standard \PHPUnit_Framework_TestCase instead.
*/
abstract class KernelAwareTest extends \PHPUnit_Framework_TestCase
{