/**
  * 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
0
 /**
  * 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
0
文件: Type.php 项目: tueena/core
 /**
  * @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
0
 /**
  * @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();
 }
 /**
  * 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);
 }
 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;
 }
 /**
  * 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
0
文件: Logger.php 项目: robotr/mvcDemo
 /**
  * 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
0
 /**
  * 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
0
 /**
  * @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
0
 /**
  * @param Type $type
  */
 public function addType(Type $type)
 {
     $this->types[$type->getName()] = $type;
 }
示例#12
0
 public function registerType(Type $type)
 {
     $this->types[$type->getName()] = $type;
 }
示例#13
0
 protected function defineColumn(Type $type)
 {
     return \sprintf('`%s` %s', $type->getName(), $type->getDataType());
 }
示例#14
0
文件: TypeTest.php 项目: emarref/jwt
 public function testGetName()
 {
     $this->assertSame(self::$name, $this->parameter->getName());
 }
示例#15
0
 /**
  * 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;
 }
示例#16
0
 /**
  * @return string
  */
 public function getType()
 {
     return $this->type->getName();
 }