本文整理汇总了PHP中Cake\ORM\Association::type方法的典型用法代码示例。如果您正苦于以下问题:PHP Association::type方法的具体用法?PHP Association::type怎么用?PHP Association::type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\ORM\Association
的用法示例。
在下文中一共展示了Association::type方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: associatedEntityTypeToHintType
/**
* Converts an entity class type to its DocBlock hint type counterpart.
*
* @param string $type The entity class type (a fully qualified class name).
* @param \Cake\ORM\Association $association The association related to the entity class.
* @return string The DocBlock type
*/
public function associatedEntityTypeToHintType($type, Association $association)
{
if ($association->type() === Association::MANY_TO_MANY || $association->type() === Association::ONE_TO_MANY) {
return $type . '[]';
}
return $type;
}
示例2: _marshalAssociation
/**
* Create a new sub-marshaller and marshal the associated data.
*
* @param \Cake\ORM\Association $assoc The association to marshall
* @param array $value The data to hydrate
* @param array $options List of options.
* @return mixed
*/
protected function _marshalAssociation($assoc, $value, $options)
{
if (!is_array($value)) {
return null;
}
$targetTable = $assoc->target();
$marshaller = $targetTable->marshaller();
$types = [Association::ONE_TO_ONE, Association::MANY_TO_ONE];
if (in_array($assoc->type(), $types)) {
return $marshaller->one($value, (array) $options);
}
if ($assoc->type() === Association::ONE_TO_MANY || $assoc->type() === Association::MANY_TO_MANY) {
$hasIds = array_key_exists('_ids', $value);
$onlyIds = array_key_exists('onlyIds', $options) && $options['onlyIds'];
if ($hasIds && is_array($value['_ids'])) {
return $this->_loadAssociatedByIds($assoc, $value['_ids']);
}
if ($hasIds || $onlyIds) {
return [];
}
}
if ($assoc->type() === Association::MANY_TO_MANY) {
return $marshaller->_belongsToMany($assoc, $value, (array) $options);
}
return $marshaller->many($value, (array) $options);
}
示例3: _marshalAssociation
/**
* Create a new sub-marshaller and marshal the associated data.
*
* @param \Cake\ORM\Association $assoc The association to marshall
* @param array $value The data to hydrate
* @param array $options List of options.
* @return mixed
*/
protected function _marshalAssociation($assoc, $value, $options)
{
$targetTable = $assoc->target();
$marshaller = $targetTable->marshaller();
$types = [Association::ONE_TO_ONE, Association::MANY_TO_ONE];
if (in_array($assoc->type(), $types)) {
return $marshaller->one($value, (array) $options);
}
if ($assoc->type() === Association::MANY_TO_MANY) {
return $marshaller->_belongsToMany($assoc, $value, (array) $options);
}
return $marshaller->many($value, (array) $options);
}