Skip to content

Instantly share code, notes, and snippets.

View bshaffer's full-sized avatar

Brent Shaffer bshaffer

View GitHub Profile
@bshaffer
bshaffer / gist:328103
Created March 10, 2010 17:19
Doctrine_Query_Extra
<?php
/*
* Extended Doctrine Query class providing a few additional functions
* for wrapping your where clauses more efficiently
*/
class Doctrine_Query_Extra extends Doctrine_Query
{
protected $_startClause = false;
/**
@bshaffer
bshaffer / gist:349506
Created March 30, 2010 19:42
Output the actual SQL query from a Doctrine_Query object
public function debug()
{
$sql = $this->getSqlQuery();
$params = $this->getParams();
foreach ($params as $key => $type)
{
foreach ($type as $param)
{
$sql = preg_replace('/\?/', is_int($param) ? $param : "'$param'", $sql, 1);
}
@bshaffer
bshaffer / sfValidatorCCExpirationDate.php
Created April 29, 2010 18:25 — forked from anonymous/gist:179274
sfValidatorCCExpirationDate.php
<?php
/**
* sfValidatorCCExpirationDate validates the expiration date for a credit card.
*
* @author Brent Shaffer <bshafs@gmail.com>
*/
class sfValidatorCCExpirationDate extends sfValidatorDate
{
<?php
/**
* sfProgressBar
*
* Draw a nifty progress bar for command-line tasks
*
* USAGE:
* // Create Progress Bar instance, pass number of increments
* $progressBar = new sfProgressBar($eventDispatcher);
* $progressBar->start($numItems);
@bshaffer
bshaffer / BaseForm.php
Created May 20, 2010 22:36
handy makeReadOnly() function to put in BaseForm
<?php
class BaseForm extends sfFormSymfony
{
public function makeReadOnly($field = null)
{
if ($field instanceof sfWidget)
{
$field->setAttribute('disabled', 'disabled');
<?php
/**
* options:
* * widget: The widget to trigger the ajax event
* * update: A JQuery selector for the DOM element to update with the response
* * url: A url or symfony route to call to update the element above. The selected value of the widget is automatically appended to this url (ex: '@objects?object_id=' will end up calling '@objects?object_id=2' if "2" is the value selected in your widget)
* * on_empty: Text to update the "update" DOM element with if the widget value is empty
* * update_on_load: whether to call the AJAX function on page load
*/
@bshaffer
bshaffer / gist:413227
Created May 25, 2010 15:02
get the duration of a timestamp
<?php
function duration($seconds, $max_periods = 3)
{
$periods = array("year" => 31536000, "month" => 2419200, "week" => 604800, "day" => 86400, "hour" => 3600, "minute" => 60, "second" => 1);
$i = 1;
foreach ( $periods as $period => $period_seconds )
{
$period_duration = floor($seconds / $period_seconds);
$seconds = $seconds % $period_seconds;
@bshaffer
bshaffer / gist:413344
Created May 25, 2010 16:19 — forked from anonymous/gist:234678
PHP Object Oriented Array class
<?php
class A implements ArrayAccess, Iterator, Countable
{
public function __construct($arr) {
$this->arr = is_array($arr) ? $arr : func_get_args();
}
public function __toString() {
return print_r($this->arr, true);
}
@bshaffer
bshaffer / logdebug.sh
Created June 2, 2010 18:05
useful for traversing your symfony log files and debugging them
# The first argument is the application (default: frontend)
export app=$1
if [ ! -n "$app" ]; then
export app="frontend"
fi
# The second argument is the environment. (default: dev)
export env=$2
<?php
/**
*
*/
class sfFactory
{
protected static
$lastRandom = array(),
$lastIncrement = array();