本文整理汇总了PHP中Type::getName方法的典型用法代码示例。如果您正苦于以下问题:PHP Type::getName方法的具体用法?PHP Type::getName怎么用?PHP Type::getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Type
的用法示例。
在下文中一共展示了Type::getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getName
/**
* Gets the string representation of this type.
* If key and value are mixed, "array" is returned.
* If only key is mixed, "T[]" is returned, where T is the name of the value type.
* Otherwise, "array<K, V>" is returned, where K is the name of the key type.
*
* @return string The string representation.
*/
public function getName(array $options = array())
{
if ($this->keyType === Type::ofMixed()) {
if ($this->itemType === Type::ofMixed()) {
return "array";
}
return $this->itemType->getName() . "[]";
}
return "array<" . $this->keyType->getName() . "," . $this->itemType->getName() . ">";
}
示例2: findByOwnerAndFilterWithPercents
/**
* Metodo que calcula el porcentaje de los tipos de gasto del usuario pasado
* como parametro en funcion del rango de fechas pasado como parametro.
* Para realizar el calculo, primero obtiene todos los gastos y la cantidad
* numerica de gasto que representan. Despues se invoca a un metodo privado
* para conocer el total de gasto del usuario y se calculan los porcentajes
* de cada tipo de gasto. Finalmente, se crea un tipo de gasto especial que
* representa el porcentaje de gasto de aquellos gastos que no tengan ningun
* tipo de gasto asignado.
*/
public function findByOwnerAndFilterWithPercents($owner, $startDate, $endDate)
{
$stmt = $this->db->prepare("SELECT SUM(s.quantity) as 'spending.quantity',\n t.idType as 'type.id',\n t.name as 'type.name'\n FROM SPENDING s LEFT JOIN TYPE_SPENDING ts ON s.idSpending = ts.spending LEFT JOIN TYPE t on ts.type = t.idType\n WHERE s.owner = ? AND s.dateSpending BETWEEN ? AND ? AND ts.spending IS NOT NULL GROUP BY ts.type");
$stmt->execute(array($owner, $startDate, $endDate));
$types_db = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (sizeof($types_db)) {
$total = $this->getTotal($owner, $startDate, $endDate);
$types = [];
foreach ($types_db as $type_loop) {
$type = new Type();
$type->setName($type_loop['type.name']);
$percent = $type_loop["spending.quantity"] * 100 / $total;
array_push($types, array("typename" => $type->getName(), "percent" => round($percent, 2), "total" => (double) $type_loop["spending.quantity"]));
}
$totalWithoutType = $this->getTotalSpendingsWithoutType($owner, $startDate, $endDate);
if ($totalWithoutType != 0) {
$percentSpecialType = $totalWithoutType * 100 / $total;
$specialType = new Type();
$specialType->setName("Without category");
array_push($types, array("typename" => $specialType->getName(), "percent" => round($percentSpecialType, 2), "total" => (double) $totalWithoutType));
}
return $types;
} else {
return NULL;
}
}
示例3: isInstanceOf
/**
* @param Type $OtherType
* @return bool
*/
public function isInstanceOf(Type $OtherType)
{
$thisTypeName = $this->getName();
$otherTypeName = $OtherType->getName();
if ($thisTypeName === $otherTypeName) {
return true;
}
return (new \ReflectionClass($thisTypeName))->isSubclassOf($otherTypeName);
}
示例4: store
/**
* @param Type $type
*
* @return string
* @throws exceptions\DBDuplicateEntryException
* @throws exceptions\DBForeignKeyException
*/
public function store(Type $type)
{
$query = 'INSERT INTO types (name, description) VALUES (:name, :description);';
$this->db->prepare($query);
$this->db->bindValue(':name', $type->getName());
$this->db->bindValue(':description', $type->getDescription());
$this->db->execute();
return $this->db->lastInsertId();
}
示例5: isAssignableFrom
/**
* Checks whether the provided type equals this type or is a subtype of this type.
*
* @param Type $type
* @return boolean
*/
public function isAssignableFrom(Type $type)
{
if ($type->getName() === $this->getName()) {
return true;
}
if (!$type instanceof ClassType) {
return false;
}
return $type->isSubtypeOf($this);
}
示例6: __construct
public function __construct($reactionID)
{
$dbMgr = new DatabaseManager(true);
$objectData = $dbMgr->getReactionData($reactionID);
$this->reactionID = $objectData['reactionID'];
$this->reactionType = $objectData['reactionType'];
$this->inputs = $dbMgr->getReactionInputs($this->reactionID);
$objectFactory = new ObjectFactory();
foreach ($this->inputs as $input) {
$inputType = $objectFactory->create(ObjectFactory::TYPE, $input['typeID']);
$inputVolume = $inputType->getVolume() * $input['inputQty'];
$this->inputVolume += $inputVolume;
}
$this->output = $objectFactory->create(ObjectFactory::TYPE, $objectData['typeID']);
$this->outputQty = $objectData['outputQty'];
$this->outputVolume = $this->outputQty * $this->output->getVolume();
$this->reactionName = $this->output->getName();
if ($this->reactionType == 3) {
$this->reactionName += " Alchemy";
}
$dbMgr = null;
}
示例7: isAssignableFrom
/**
* Checks whether the provided type is either an interface that is equal to or extends this interface
* or is a class that implements this interface.
*
* @param Type $type
* @return boolean
*/
public function isAssignableFrom(Type $type)
{
if ($type->getName() === $this->getName()) {
return true;
}
if ($type instanceof InterfaceType) {
return $type->isSubtypeOf($this);
} else {
if ($type instanceof ClassType) {
return $type->isImplementorOf($this);
}
}
return false;
}
示例8: log
/**
* log an error of the given type
* @param string $message
* @param string $file
* @param int $line
* @param int $type
* @throws \Exception
*/
public function log($message, $file, $line, $type = E_ERROR)
{
if (!empty($this->_fileName) && ($fh = fopen($this->_fileName, 'a'))) {
if ($message instanceof \Exception) {
$eClass = get_class($message);
$eMessage = $eClass . ' with message: "' . $message->getMessage() . ' Code: ' . $message->getCode() . '"' . PHP_EOL . 'in ' . $message->getFile() . ' on line ' . $message->getLine() . PHP_EOL . 'Stack-Trace' . PHP_EOL . ' ';
$eMessage .= str_replace(PHP_EOL, PHP_EOL . ' ', $message->getTraceAsString());
$message = $eMessage;
}
fwrite($fh, sprintf('[' . date('r') . '] [' . Type::getName($type) . '] %s in %s on line %s' . PHP_EOL, $message, $file, $line));
fclose($fh);
} else {
throw new \Exception('No Log-File specified or file not accessible!');
}
}
示例9: __construct
/**
* ctor
* @param array $config
*/
public function __construct($config = [])
{
$this->_config = $config;
// callback for set_error_handler/set_exception_handler
$this->_callable = function () {
$args = func_get_args();
if ($fh = fopen($this->_fileName, 'a')) {
if (5 == count($args)) {
// Error-Handling
if (isset($args[4])) {
if (isset($args[4]['e']) && $args[4]['e'] instanceof \Exception) {
// caught Exception
/** @var \Exception $exc */
$exc = $args[4]['e'];
unset($args[4]['e']);
// todo - ? $source = array_shift($args[4]); ?
$args[0] = Type::E_USER_EXCEPTION;
$args[1] = get_class($exc) . ': ' . $exc->getMessage();
$args[2] = $exc->getFile();
$args[3] = $exc->getLine();
$args[4] = $exc->getTraceAsString();
$this->_keys[] = 'trace';
} else {
unset($args[4]);
}
}
} elseif (1 == count($args) && $args[0] instanceof \Exception) {
// Exception-Handling
// todo sanitize method-args
/** @var \Exception $exc */
$exc = array_shift($args);
$args[0] = Type::E_USER_CATCHABLE;
$args[1] = 'Uncaught ' . get_class($exc) . ': ' . $exc->getMessage();
$args[2] = $exc->getFile();
$args[3] = $exc->getLine();
$args[4] = $exc->getTraceAsString();
$this->_keys[] = 'trace';
}
// create log-message
$args = array_combine($this->_keys, $args);
$args['code'] = Type::getName($args['code']);
$args['date'] = date('r');
fwrite($fh, !in_array('trace', $this->_keys) ? $this->_getMessage($args) : $this->_getTraceMessage($args));
fclose($fh);
}
};
}
示例10: testCreate
/**
* @covers \Weasel\JsonMarshaller\Config\Annotations\JsonSubTypes\Type
*/
public function testCreate()
{
$test = new Type("testValue", "testName");
$this->assertEquals("testValue", $test->getValue());
$this->assertEquals("testName", $test->getName());
}
示例11: addType
/**
* @param Type $type
*/
public function addType(Type $type)
{
$this->types[$type->getName()] = $type;
}
示例12: registerType
public function registerType(Type $type)
{
$this->types[$type->getName()] = $type;
}
示例13: defineColumn
protected function defineColumn(Type $type)
{
return \sprintf('`%s` %s', $type->getName(), $type->getDataType());
}
示例14: testGetName
public function testGetName()
{
$this->assertSame(self::$name, $this->parameter->getName());
}
示例15: register
/**
* Registers a data type.
*
* @param \WordPress\Data\Type $type
*
* @return \WordPress\Data\Manager
*/
public function register(Type $type)
{
$this->types[$type->getName()] = $type;
return $this;
}