1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222:
<?php
/**
* This file is part of the Lean Mapper library (http://www.leanmapper.com)
*
* Copyright (c) 2013 Vojtěch Kohout (aka Tharos)
*
* For the full copyright and license information, please view the file
* license-mit.txt that was distributed with this source code.
*/
namespace LeanMapper\Reflection;
use LeanMapper\Exception\InvalidMethodCallException;
use LeanMapper\Relationship\BelongsToMany;
use LeanMapper\Relationship\BelongsToOne;
use LeanMapper\Relationship\HasMany;
use LeanMapper\Relationship\HasOne;
/**
* Entity property (field) reflection
*
* @author Vojtěch Kohout
*/
class Property
{
/** @var string */
private $name;
/** @var string|null */
private $column;
/** @var PropertyType */
private $type;
/** @var bool */
private $isWritable;
/** @var bool */
private $isNullable;
/** @var bool */
private $containsCollection;
/** @var HasOne|HasMany|BelongsToOne|BelongsToMany|null */
private $relationship;
/** @var PropertyFilters|null */
private $propertyFilters;
/** @var PropertyValuesEnum|null */
private $propertyValuesEnum;
/** @var string|null */
private $extra;
/**
* @param string $name
* @param string|null $column
* @param PropertyType $type
* @param bool $isWritable
* @param bool $isNullable
* @param bool $containsCollection
* @param HasOne|HasMany|BelongsToOne|BelongsToMany|null $relationship
* @param PropertyFilters|null $propertyFilters
* @param PropertyValuesEnum|null $propertyValuesEnum
* @param string|null $extra
*/
public function __construct($name, $column, PropertyType $type, $isWritable, $isNullable, $containsCollection, $relationship = null, PropertyFilters $propertyFilters = null, PropertyValuesEnum $propertyValuesEnum = null, $extra = null)
{
$this->name = $name;
$this->column = $column;
$this->type = $type;
$this->isWritable = $isWritable;
$this->isNullable = $isNullable;
$this->containsCollection = $containsCollection;
$this->relationship = $relationship;
$this->propertyFilters = $propertyFilters;
$this->propertyValuesEnum = $propertyValuesEnum;
$this->extra = $extra;
}
/**
* Returns property name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Returns property column
*
* @return string|null
*/
public function getColumn()
{
return $this->column;
}
/**
* Tells whether property is assumed to contain collection
*
* @return bool
*/
public function containsCollection()
{
return $this->containsCollection;
}
/**
* Returns property type
*
* @return string
*/
public function getType()
{
return $this->type->getType();
}
/**
* Tells whether property type is basic type (boolean|integer|float|string|array)
*
* @return bool
*/
public function isBasicType()
{
return $this->type->isBasicType();
}
/**
* Tells whether property is writable
*
* @return bool
*/
public function isWritable()
{
return $this->isWritable;
}
/**
* Tells whether property can be null
*
* @return bool
*/
public function isNullable()
{
return $this->isNullable;
}
/**
* Tells whether property represents relationship
*
* @return bool
*/
public function hasRelationship()
{
return $this->relationship !== null;
}
/**
* Returns relationship that property represents
*
* @return BelongsToMany|BelongsToOne|HasMany|HasOne|null
*/
public function getRelationship()
{
return $this->relationship;
}
/**
* Returns property filters
*
* @param int|null $index
* @return string[]|null
*/
public function getFilters($index = null)
{
return $this->propertyFilters !== null ? $this->propertyFilters->getFilters($index) : null;
}
/**
* Tells whether property contains enumeration
*
* @return bool
*/
public function containsEnumeration()
{
return $this->propertyValuesEnum !== null;
}
/**
* Tells wheter given value is from enumeration of possible values
*
* @param mixed $value
* @return bool
* @throws InvalidMethodCallException
*/
public function isValueFromEnum($value)
{
if (!$this->containsEnumeration()) {
throw new InvalidMethodCallException("It doesn't make sense to call this method on property that doesn't contain enumeration");
}
return $this->propertyValuesEnum->isValueFromEnum($value);
}
/**
* Returns value of m:extra flag (if given)
*
* @return string|null
*/
public function getExtra()
{
return $this->extra;
}
}