Created
January 13, 2012 09:46
-
-
Save tentacode/1605324 to your computer and use it in GitHub Desktop.
Simple PropelFormatter independant of PropelCollection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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