Skip to content

Instantly share code, notes, and snippets.

@tentacode
Created January 13, 2012 09:46
Show Gist options
  • Save tentacode/1605324 to your computer and use it in GitHub Desktop.
Save tentacode/1605324 to your computer and use it in GitHub Desktop.
Simple PropelFormatter independant of PropelCollection
<?php
class FusionArrayFormatter extends PropelFormatter
{
/**
* @param PDOStatement $stmt
* @return array
*/
public function format(PDOStatement $stmt)
{
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
/**
* @param PDOStatement $stmt
* @return mixed|null
*/
public function formatOne(PDOStatement $stmt)
{
$results = $this->format($stmt);
if(sizeof($results) > 0)
{
if(sizeof($results[0]) == 1)
{
return array_pop($results[0]);
}
return $results[0];
}
return null;
}
/**
* @return bool
*/
public function isObjectFormatter()
{
return false;
}
/**
* @param ModelCriteria|null $criteria
*/
public function __construct(ModelCriteria $criteria = null)
{
if (null !== $criteria)
{
$this->init($criteria);
}
}
/**
* @param ModelCriteria $criteria
* @return FusionArrayFormatter
*/
public function init(ModelCriteria $criteria)
{
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment