/** * Returns an array containing all of the result set rows. * * @param integer|null $fetchMode * @param mixed $fetchArgument * * @return array An array containing all of the remaining rows in the result set. */ public function fetchAll($fetchMode = null, $fetchArgument = 0) { if ($fetchArgument !== 0) { return $this->stmt->fetchAll($fetchMode, $fetchArgument); } return $this->stmt->fetchAll($fetchMode); }
/** * Load data if it hasn't been loaded yet */ protected function loadData() { if (null === $this->data) { $this->stmt->execute(); $this->data = $this->stmt->fetchAll(\PDO::FETCH_ASSOC); } }
public function fetchAll($fetchMode = null, $columnIndex = 0) { $fetchMode = $fetchMode ?: $this->defaultFetchMode; if ($columnIndex != 0) { $rows = $this->stmt->fetchAll($fetchMode, $columnIndex); } else { $rows = $this->stmt->fetchAll($fetchMode); } $iterateRow = $this->portability & (Connection::PORTABILITY_EMPTY_TO_NULL | Connection::PORTABILITY_RTRIM); $fixCase = !is_null($this->case) && ($fetchMode == PDO::FETCH_ASSOC || $fetchMode == PDO::FETCH_BOTH) && $this->portability & Connection::PORTABILITY_FIX_CASE; if (!$iterateRow && !$fixCase) { return $rows; } foreach ($rows as $num => $row) { $rows[$num] = $this->fixRow($row, $iterateRow, $fixCase); } return $rows; }
/** * This method is called to hydrate ACLs and ACEs. * * This method was designed for performance; thus, a lot of code has been * inlined at the cost of readability, and maintainability. * * Keep in mind that changes to this method might severely reduce the * performance of the entire ACL system. * * @param Statement $stmt * @param array $oidLookup * @param array $sids * @throws \RuntimeException * @return \SplObjectStorage */ protected function hydrateObjectIdentities(Statement $stmt, array $oidLookup, array $sids) { $parentIdToFill = new \SplObjectStorage(); $acls = $aces = $emptyArray = array(); $oidCache = $oidLookup; $result = new \SplObjectStorage(); $loadedAces =& $this->loadedAces; $loadedAcls =& $this->loadedAcls; $permissionGrantingStrategy = $this->permissionGrantingStrategy; // we need these to set protected properties on hydrated objects $aclReflection = new \ReflectionClass('Symfony\\Component\\Security\\Acl\\Domain\\Acl'); $aclClassAcesProperty = $aclReflection->getProperty('classAces'); $aclClassAcesProperty->setAccessible(true); $aclClassFieldAcesProperty = $aclReflection->getProperty('classFieldAces'); $aclClassFieldAcesProperty->setAccessible(true); $aclObjectAcesProperty = $aclReflection->getProperty('objectAces'); $aclObjectAcesProperty->setAccessible(true); $aclObjectFieldAcesProperty = $aclReflection->getProperty('objectFieldAces'); $aclObjectFieldAcesProperty->setAccessible(true); $aclParentAclProperty = $aclReflection->getProperty('parentAcl'); $aclParentAclProperty->setAccessible(true); // fetchAll() consumes more memory than consecutive calls to fetch(), // but it is faster foreach ($stmt->fetchAll(\PDO::FETCH_NUM) as $data) { list($aclId, $objectIdentifier, $parentObjectIdentityId, $entriesInheriting, $classType, $aceId, $objectIdentityId, $fieldName, $aceOrder, $mask, $granting, $grantingStrategy, $auditSuccess, $auditFailure, $username, $securityIdentifier) = $data; // has the ACL been hydrated during this hydration cycle? if (isset($acls[$aclId])) { $acl = $acls[$aclId]; } else { if (isset($loadedAcls[$classType][$objectIdentifier])) { $acl = $loadedAcls[$classType][$objectIdentifier]; // keep reference in local array (saves us some hash calculations) $acls[$aclId] = $acl; // attach ACL to the result set; even though we do not enforce that every // object identity has only one instance, we must make sure to maintain // referential equality with the oids passed to findAcls() if (!isset($oidCache[$objectIdentifier . $classType])) { $oidCache[$objectIdentifier . $classType] = $acl->getObjectIdentity(); } $result->attach($oidCache[$objectIdentifier . $classType], $acl); } else { // create object identity if we haven't done so yet $oidLookupKey = $objectIdentifier . $classType; if (!isset($oidCache[$oidLookupKey])) { $oidCache[$oidLookupKey] = new ObjectIdentity($objectIdentifier, $classType); } $acl = new Acl((int) $aclId, $oidCache[$oidLookupKey], $permissionGrantingStrategy, $emptyArray, !!$entriesInheriting); // keep a local, and global reference to this ACL $loadedAcls[$classType][$objectIdentifier] = $acl; $acls[$aclId] = $acl; // try to fill in parent ACL, or defer until all ACLs have been hydrated if (null !== $parentObjectIdentityId) { if (isset($acls[$parentObjectIdentityId])) { $aclParentAclProperty->setValue($acl, $acls[$parentObjectIdentityId]); } else { $parentIdToFill->attach($acl, $parentObjectIdentityId); } } $result->attach($oidCache[$oidLookupKey], $acl); } } // check if this row contains an ACE record if (null !== $aceId) { // have we already hydrated ACEs for this ACL? if (!isset($aces[$aclId])) { $aces[$aclId] = array($emptyArray, $emptyArray, $emptyArray, $emptyArray); } // has this ACE already been hydrated during a previous cycle, or // possible been loaded from cache? // It is important to only ever have one ACE instance per actual row since // some ACEs are shared between ACL instances if (!isset($loadedAces[$aceId])) { if (!isset($sids[$key = ($username ? '1' : '0') . $securityIdentifier])) { if ($username) { $sids[$key] = new UserSecurityIdentity(substr($securityIdentifier, 1 + ($pos = strpos($securityIdentifier, '-'))), substr($securityIdentifier, 0, $pos)); } else { $sids[$key] = new RoleSecurityIdentity($securityIdentifier); } } if (null === $fieldName) { $loadedAces[$aceId] = new Entry((int) $aceId, $acl, $sids[$key], $grantingStrategy, (int) $mask, !!$granting, !!$auditFailure, !!$auditSuccess); } else { $loadedAces[$aceId] = new FieldEntry((int) $aceId, $acl, $fieldName, $sids[$key], $grantingStrategy, (int) $mask, !!$granting, !!$auditFailure, !!$auditSuccess); } } $ace = $loadedAces[$aceId]; // assign ACE to the correct property if (null === $objectIdentityId) { if (null === $fieldName) { $aces[$aclId][0][$aceOrder] = $ace; } else { $aces[$aclId][1][$fieldName][$aceOrder] = $ace; } } else { if (null === $fieldName) { $aces[$aclId][2][$aceOrder] = $ace; } else { $aces[$aclId][3][$fieldName][$aceOrder] = $ace; } } } } // We do not sort on database level since we only want certain subsets to be sorted, // and we are going to read the entire result set anyway. // Sorting on DB level increases query time by an order of magnitude while it is // almost negligible when we use PHPs array sort functions. foreach ($aces as $aclId => $aceData) { $acl = $acls[$aclId]; ksort($aceData[0]); $aclClassAcesProperty->setValue($acl, $aceData[0]); foreach (array_keys($aceData[1]) as $fieldName) { ksort($aceData[1][$fieldName]); } $aclClassFieldAcesProperty->setValue($acl, $aceData[1]); ksort($aceData[2]); $aclObjectAcesProperty->setValue($acl, $aceData[2]); foreach (array_keys($aceData[3]) as $fieldName) { ksort($aceData[3][$fieldName]); } $aclObjectFieldAcesProperty->setValue($acl, $aceData[3]); } // fill-in parent ACLs where this hasn't been done yet cause the parent ACL was not // yet available $processed = 0; foreach ($parentIdToFill as $acl) { $parentId = $parentIdToFill->offsetGet($acl); // let's see if we have already hydrated this if (isset($acls[$parentId])) { $aclParentAclProperty->setValue($acl, $acls[$parentId]); $processed += 1; continue; } } // reset reflection changes $aclClassAcesProperty->setAccessible(false); $aclClassFieldAcesProperty->setAccessible(false); $aclObjectAcesProperty->setAccessible(false); $aclObjectFieldAcesProperty->setAccessible(false); $aclParentAclProperty->setAccessible(false); // this should never be true if the database integrity hasn't been compromised if ($processed < count($parentIdToFill)) { throw new \RuntimeException('Not all parent ids were populated. This implies an integrity problem.'); } return $result; }
/** * Stores a query result into an array. * * @author Olivier Brouckaert * @param Statement $result - the return value of the query * @param string $option BOTH, ASSOC, or NUM * * @return array - the value returned by the query */ public static function store_result(Statement $result, $option = 'BOTH') { return $result->fetchAll(self::customOptionToDoctrineOption($option)); }
public function fetchAll($fetchMode = null) { $return = $this->wrapped->fetchAll($fetchMode); $this->rows += count($return); return $return; }
/** * Validate the connection resource and store the query string * * @param DoctrineStatement $statement The database statement * @param string $strQuery The query string * * @todo Try to find a solution that works without fetchAll(). */ public function __construct(DoctrineStatement $statement, $strQuery) { $this->resResult = $statement; $this->strQuery = $strQuery; $this->resultSet = $statement->fetchAll(\PDO::FETCH_ASSOC); }
/** * Stores a query result into an array. * @param Statement $result - the return value of the query * @param option BOTH, ASSOC, or NUM * @return array - the value returned by the query */ public static function store_result(Statement $result, $option = 'BOTH') { return $result->fetchAll(self::customOptionToDoctrineOption($option)); /* var_dump($a ); $array = array(); if ($result !== false) { // For isolation from database engine's behaviour. while ($row = self::fetch_array($result, $option)) { $array[] = $row; } } return $array;*/ }
/** * Hydrates fetched result of allowed entries * * @param Statement $stmt statement * * @return array */ private function hydrateAllowedEntriesResult(Statement $stmt) { $result = []; foreach ($stmt->fetchAll() as $data) { $classType = $data['class_type']; if (!empty($data['object_identifier'])) { if (!empty($data['field_name'])) { // object field ace if (!isset($result[$classType]['object_field_access'])) { $result[$classType]['object_field_access'] = array(); } if (!isset($result[$classType]['object_field_access'][$data['object_identifier']])) { $result[$classType]['object_field_access'][$data['object_identifier']] = array(); } $result[$classType]['object_field_access'][$data['object_identifier']][] = $data['field_name']; } else { if (!isset($result[$classType]['object_access'])) { $result[$classType]['object_access'] = array(); } // object ace if (!in_array($data['object_identifier'], $result[$classType]['object_access'])) { $result[$classType]['object_access'][] = $data['object_identifier']; } } } else { if (!empty($data['field_name'])) { // class field ace if (!isset($result[$classType]['class_field_access'])) { $result[$classType]['class_field_access'] = array(); } if (!in_array($data['field_name'], $result[$classType]['class_field_access'])) { $result[$classType]['class_field_access'][] = $data['field_name']; } } else { // class ace $result[$classType]['class_access'] = true; } } } return $result; }
function it_counts_complete_products_per_channels(Statement $statement) { $statement->execute()->willReturn(null); $statement->fetchAll()->willReturn(array(array('locale' => 'en_US', 'label' => 'ECommerce', 'total' => 0), array('locale' => 'fr_FR', 'label' => 'ECommerce', 'total' => 1), array('locale' => 'en_US', 'label' => 'Mobile', 'total' => 2))); $this->getCompleteProductsCountPerChannels()->shouldReturn(array(array('locale' => 'en_US', 'label' => 'ECommerce', 'total' => 0), array('locale' => 'fr_FR', 'label' => 'ECommerce', 'total' => 1), array('locale' => 'en_US', 'label' => 'Mobile', 'total' => 2))); }