本文整理汇总了PHP中lithium\util\Set::combine方法的典型用法代码示例。如果您正苦于以下问题:PHP Set::combine方法的具体用法?PHP Set::combine怎么用?PHP Set::combine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lithium\util\Set
的用法示例。
在下文中一共展示了Set::combine方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadMetadataForClass
public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
{
if (!$metadata->reflClass instanceof SchemaReflection) {
$metadata->reflClass = new SchemaReflection(get_class($metadata));
}
$metadata->primaryTable['name'] = $className::meta('source');
$primaryKey = $className::meta('key');
$bindings = static::bindings($className);
$relations = array();
if (!empty($bindings)) {
foreach ($bindings as $type => $set) {
foreach ($set as $key => $relation) {
$mapping = array('fetch' => \Doctrine\ORM\Mapping\AssociationMapping::FETCH_EAGER, 'fieldName' => $relation['fieldName'], 'sourceEntity' => $className, 'targetEntity' => $relation['class'], 'mappedBy' => null, 'cascade' => !empty($relation['dependent']) ? array('remove') : array(), 'optional' => $type != 'belongsTo');
if (in_array($type, array('hasOne', 'hasMany'))) {
$inverse = $type == 'belongsTo';
$mapping['joinColumns'][] = array('fieldName' => !$inverse ? $relation['key'] : $relation['fieldName'], 'name' => !$inverse ? $relation['fieldName'] : $relation['key'], 'referencedColumnName' => $relation['class']::meta('key'));
}
if (in_array($type, array('belongsTo', 'hasOne', 'hasMany'))) {
$mapping['mappedBy'] = static::_fieldName($mapping);
}
$relations[$type][$key] = $mapping;
}
}
}
$schema = (array) $className::schema();
$metadata->reflClass->setRelations($relations);
$metadata->reflClass->setSchema($schema);
$belongsToFields = !empty($bindings['belongsTo']) ? Set::combine(array_values($bindings['belongsTo']), '/key', '/fieldName') : array();
foreach ($schema as $field => $column) {
$mapping = array_merge(array('id' => $field == $primaryKey, 'fieldName' => !empty($belongsToFields[$field]) ? $belongsToFields[$field] : $field, 'columnName' => $field), (array) $column);
$metadata->mapField($mapping);
if ($mapping['id']) {
$metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_AUTO);
}
}
foreach ($relations as $type => $set) {
foreach ($set as $key => $mapping) {
$metadata->{static::$_bindingMapping[$type]}($mapping);
$mapping = $metadata->associationMappings[$mapping['fieldName']];
}
}
}
示例2: testCombine
public function testCombine() {
$result = Set::combine(array(), '/User/id', '/User/Data');
$this->assertFalse($result);
$result = Set::combine('', '/User/id', '/User/Data');
$this->assertFalse($result);
$a = array(
array('User' => array('id' => 2, 'group_id' => 1,
'Data' => array('user' => 'mariano.iglesias','name' => 'Mariano Iglesias'))),
array('User' => array('id' => 14, 'group_id' => 2,
'Data' => array('user' => 'jperras', 'name' => 'Joel Perras'))),
array('User' => array('id' => 25, 'group_id' => 1,
'Data' => array('user' => 'gwoo','name' => 'The Gwoo'))));
$result = Set::combine($a, '/User/id');
$expected = array(2 => null, 14 => null, 25 => null);
$this->assertIdentical($expected, $result);
$result = Set::combine($a, '/User/id', '/User/non-existant');
$expected = array(2 => null, 14 => null, 25 => null);
$this->assertIdentical($expected, $result);
$result = Set::combine($a, '/User/id', '/User/Data/.');
$expected = array(
2 => array('user' => 'mariano.iglesias', 'name' => 'Mariano Iglesias'),
14 => array('user' => 'jperras', 'name' => 'Joel Perras'),
25 => array('user' => 'gwoo', 'name' => 'The Gwoo'));
$this->assertIdentical($expected, $result);
$result = Set::combine($a, '/User/id', '/User/Data/name/.');
$expected = array(
2 => 'Mariano Iglesias',
14 => 'Joel Perras',
25 => 'The Gwoo');
$this->assertIdentical($expected, $result);
$result = Set::combine($a, '/User/id', '/User/Data/.', '/User/group_id');
$expected = array(
1 => array(
2 => array('user' => 'mariano.iglesias', 'name' => 'Mariano Iglesias'),
25 => array('user' => 'gwoo', 'name' => 'The Gwoo')),
2 => array(
14 => array('user' => 'jperras', 'name' => 'Joel Perras')));
$this->assertIdentical($expected, $result);
$result = Set::combine($a, '/User/id', '/User/Data/name/.', '/User/group_id');
$expected = array(
1 => array(
2 => 'Mariano Iglesias',
25 => 'The Gwoo'),
2 => array(
14 => 'Joel Perras'));
$this->assertIdentical($expected, $result);
$result = Set::combine(
$a,
'/User/id',
array('{0}: {1}', '/User/Data/user', '/User/Data/name'),
'/User/group_id'
);
$expected = array(
1 => array(2 => 'mariano.iglesias: Mariano Iglesias', 25 => 'gwoo: The Gwoo'),
2 => array(14 => 'jperras: Joel Perras')
);
$this->assertIdentical($expected, $result);
$result = Set::combine(
$a,
array('{0}: {1}', '/User/Data/user', '/User/Data/name'),
'/User/id'
);
$expected = array(
'mariano.iglesias: Mariano Iglesias' => 2,
'jperras: Joel Perras' => 14,
'gwoo: The Gwoo' => 25
);
$this->assertIdentical($expected, $result);
$result = Set::combine(
$a,
array('{1}: {0}', '/User/Data/user', '/User/Data/name'),
'/User/id'
);
$expected = array(
'Mariano Iglesias: mariano.iglesias' => 2,
'Joel Perras: jperras' => 14,
'The Gwoo: gwoo' => 25
);
$this->assertIdentical($expected, $result);
$result = Set::combine($a, array(
'%1$s: %2$d', '/User/Data/user', '/User/id'), '/User/Data/name'
);
$expected = array(
'mariano.iglesias: 2' => 'Mariano Iglesias',
'jperras: 14' => 'Joel Perras',
'gwoo: 25' => 'The Gwoo'
);
$this->assertIdentical($expected, $result);
$result = Set::combine($a, array(
//.........这里部分代码省略.........
示例3: fields
/**
*
*/
public function fields($fields, $query)
{
$columns = array();
if (!empty($fields)) {
$columns = $this->schema($query);
if (!empty($columns)) {
$belongsToFields = array();
foreach ($columns as $key => $currentFields) {
$className = is_string($key) ? $key : $query->model();
$belongsTo = ModelDriver::bindings($className, 'belongsTo');
$belongsToFields = !empty($belongsTo) ? Set::combine(array_values($belongsTo), '/key', '/fieldName') : array();
foreach ($fields as $i => $field) {
if (!empty($belongsToFields[$field])) {
unset($fields[$i]);
$fields[] = $belongsToFields[$field];
}
}
$columns[$key] = array_unique($fields);
}
}
}
return $columns;
}