/**
  * Returns true if the <i>$object</i> has the right data type assigned in 
  * the construct, otherwise false.
  * 
  * @param mixed $object
  * @return boolean
  */
 public function isValidType($object)
 {
     if ($this->type == null || $object == null) {
         return true;
     }
     if (is_object($object) && get_class($object) == $this->type) {
         return true;
     }
     return MDataType::getType($object) == $this->type;
 }
 public function delete($userId = null, $providerId = null, $providerUserId = null)
 {
     MDataType::mustBeNullableInt($userId);
     MDataType::mustBeNullableInt($providerId);
     MDataType::mustBeNullableString($providerUserId);
     $sql = "CALL mt_provider_user_delete(?,?, ?);";
     $query = new MPDOQuery($sql, $this->connection);
     $query->bindValue($userId);
     $query->bindValue($providerId);
     $query->bindValue($providerUserId);
     $queryResult = $query->exec();
     if ($queryResult == false) {
         throw new DeleteProviderException($query->getLastError());
     }
 }
 /**
  * @param int $providerId
  * @return ProviderInfo[]
  * @throws \Exception
  */
 public function get($providerId = null)
 {
     MDataType::mustBe(array(MDataType::INT));
     $toReturn = array();
     $sql = "CALL mt_provider_get(?);";
     $query = new MPDOQuery($sql, $this->connection);
     $query->bindValue($providerId);
     $queryResult = $query->exec();
     if ($queryResult == false || $query->getResult()->rowCount() <= 0) {
         return $toReturn;
     }
     foreach ($query->getResult() as $row) {
         $userLogins = new ProviderInfo();
         $userLogins->setName($row['name'])->setAppKey($row['app_key'])->setSecretKey($row['secret_key'])->setId((int) $row['id']);
         $toReturn[] = $userLogins;
     }
     return $toReturn;
 }
Exemple #4
0
 /**
  * @param boolean $enabled
  * @return User
  */
 public function setEnabled($enabled)
 {
     MDataType::mustBe(array(MDataType::BOOLEAN));
     $this->enabled = $enabled;
     return $this;
 }
 /**
  * The method returns the visibility of the controller.
  * 
  * @param bool $isVisible
  * @return \MToolkit\Controller\MAbstractViewController
  */
 public function setIsVisible($isVisible)
 {
     MDataType::mustBeBoolean($isVisible);
     $this->isVisible = $isVisible;
     return $this;
 }
Exemple #6
0
 /**
  * @param int $start
  * @param int $end
  * @return \MToolkit\Core\MList
  */
 public function slice($start, $end)
 {
     MDataType::mustBe(array(MDataType::INT, MDataType::INT));
     $list = array_slice($this->list, $start, $end);
     return new MList($list);
 }
Exemple #7
0
 /**
  * If enable is true, enables caching of file information. If enable is 
  * false caching is disabled.<br />
  * <br />
  * When caching is enabled, MFileInfo reads the file information from the 
  * file system the first time it's needed, but generally not later.<br />
  * <br />
  * Caching is enabled by default.
  * 
  * @param boolean $caching
  * @return \MToolkit\Core\MFileInfo
  */
 public function setCaching($caching)
 {
     MDataType::mustBeBoolean($caching);
     $this->caching = $caching;
     return $this;
 }
Exemple #8
0
 /**
  * @param string $text
  * @return string
  */
 public function getHash($text)
 {
     MDataType::mustBe(array(MDataType::STRING));
     return hash($this->hashAlgorithm, $text);
 }
Exemple #9
0
 /**
  * Checks the type of the arguments of the method caller with the type passed
  * in <i>$dataTypes</i>.<br>
  * If the number of elements in <i>$dataTypes</i> isn't the same of the number
  * of the arguments of the caller, it will throw an exception.<br>
  * If the type mismatch then it will be throw a {@link MWrongTypeException MWrongTypeException}.
  *
  * @param array|int $dataTypes,... unlimited OPTIONAL The possible values of the elements of the array are: case
  *                                 MDataType::INT, MDataType::LONG, MDataType::BOOLEAN, MDataType::FLOAT: return
  *                                 "MDataType::FLOAT, MDataType::DOUBLE, MDataType::STRING, MDataType::NULL,
  *                                 MDataType::__ARRAY, MDataType::OBJECT, MDataType::RESOURCE, MDataType::MIXED
  * @throws \Exception|MWrongTypeException
  */
 public static function mustBe($dataTypes)
 {
     $params = func_get_args();
     if (isset($params[0]) && is_array($params[0])) {
         $dataTypeArray = $params[0];
     } else {
         $dataTypeArray = $params;
     }
     $trace = debug_backtrace();
     $caller = $trace[1];
     $args = $caller["args"];
     for ($i = 0; $i < count($args); $i++) {
         $dataType = $dataTypeArray[$i];
         if ($dataType === MDataType::MIXED || $dataType === MDataType::OBJECT) {
             continue;
         }
         if ($dataType & MDataType::getType($args[$i])) {
             continue;
         }
         $callerName = isset($caller["class"]) ? $caller["class"] . "::" . $caller["function"] : $caller["function"];
         $mustBe = MDataType::getTypeName($dataType);
         $itIs = MDataType::getTypeName(MDataType::getType($args[$i]));
         $message = "Argument " . ($i + 1) . " passed to " . $callerName . " must be of the type " . $mustBe . ", " . $itIs . " given, called in " . $caller["file"] . " on line " . $caller["line"] . " and defined";
         throw new MWrongTypeException($message);
     }
 }
 /**
  * @param int $pageSize
  * @return Pagination
  */
 public function setPageSize($pageSize)
 {
     MDataType::mustBe(MDataType::INT);
     $this->pageSize = $pageSize;
     return $this;
 }
Exemple #11
0
 /**
  * Returns true if the directory <i>$path</i> is relative; otherwise returns 
  * false. (Under Unix a path is relative if it does not start with a "/").
  * 
  * @param string $path
  * @return boolean
  */
 public function isRelativePath($path)
 {
     MDataType::mustBeString($path);
     $fileInfo = new MFileInfo($path);
     return $fileInfo->isAbsolute() === false;
 }
Exemple #12
0
 /**
  * Constructs a time with hour <i>$h</i>, minute <i>$m</i>, seconds <i>$s</i> and milliseconds <i>ms</i>.
  *
  * @param int $h
  * @param int $m
  * @param int $s
  * @param int $ms
  */
 public function __construct($h = 0, $m = 0, $s = 0, $ms = 0)
 {
     MDataType::mustBe(array(MDataType::INT, MDataType::INT, MDataType::INT, MDataType::INT));
     $this->setHMS($h, $m, $s, $ms);
 }
 /**
  * @param string $output
  * @return \MToolkit\Controller\MAbstractHttpHandler
  */
 public function setOutput($output)
 {
     MDataType::mustBeNullableString($output);
     $this->output = $output;
     return $this;
 }
Exemple #14
0
 /**
  * @param string $className
  * @return MPDOResult
  */
 public function setClassName($className)
 {
     MDataType::mustBeNullableString($className);
     $this->className = $className;
     return $this;
 }
 /**
  * @param string $output
  * @return MHttpResponse
  */
 public function appendOutput($output)
 {
     MDataType::mustBe(array(MDataType::STRING));
     $this->output .= $output;
     return $this;
 }
Exemple #16
0
 /**
  * @param int|null $userId
  * @param string|null $username
  * @param string|null $email
  * @return User[]
  * @throws \Exception
  */
 public function get($userId = null, $username = null, $email = null)
 {
     MDataType::mustBeNullableInt($userId);
     MDataType::mustBeNullableString($username);
     MDataType::mustBeNullableString($email);
     $userList = array();
     $sql = "CALL mt_user_get(?, ?, ?);";
     $query = new MPDOQuery($sql, $this->connection);
     $query->bindValue($userId);
     $query->bindValue($username);
     $query->bindValue($email);
     $queryResult = $query->exec();
     if ($queryResult == false || $query->getResult()->rowCount() <= 0) {
         return $userList;
     }
     foreach ($query->getResult() as $row) {
         $user = new User();
         $enabledDate = \DateTime::createFromFormat('Y-m-d H:i:s', $row['enabled_date']);
         $user->setId((int) $row['id'])->setEmail($row['email'])->setPassword($row['password'])->setPhoneNumber($row['phone_number'])->setTwoFactorEnabled($row['two_factor_enabled'] == 1 ? true : false)->setEnabledDate($enabledDate)->setEnabled($row['enabled'] == 1 ? true : false)->setAccessFailedCount((int) $row['access_failed_count'])->setUserName($row['username'])->setRoleList($this->roleBook->get((int) $row['id']))->setProviderUserList($this->providerUserBook->get((int) $row['id']));
         $userList[] = $user;
     }
     return $userList;
 }
Exemple #17
0
 /**
  * If param <i>$name</i> is an int: returns the field at position index. 
  * If the index is out of range, function returns a null 
  * value. <br />
  * <br />
  * If param <i>$name</i> is a string: returns the field called name.
  * 
  * @param int|string $name
  * @return MSqlField|null
  */
 public function getField($name)
 {
     if ($this->contains($name) === false) {
         return null;
     }
     $value = $this->record[$name];
     $type = MDataType::getType($value);
     $field = new MSqlField($name, $type);
     $field->setValue($value);
     return $field;
 }
Exemple #18
0
 public function getValueByType($key, $type, $defaultValue = null)
 {
     $value = $this->getValue($key, $defaultValue);
     if (isset($value) === false) {
         return $defaultValue;
     }
     return MDataType::convert($value, $type);
 }
Exemple #19
0
 /**
  * @param string $name
  * @return Provider
  */
 public function setName($name)
 {
     MDataType::mustBe(array(MDataType::STRING));
     $this->name = $name;
     return $this;
 }
 /**
  * @param string $id
  * @return MAbstractController
  */
 protected function getControl($id)
 {
     MDataType::mustBeString($id);
     return $this->controls->getValue($id);
 }
 /**
  * @param int $ttl
  * @return MCacheItem
  */
 public function setTtl($ttl)
 {
     MDataType::mustBe(MDataType::INT);
     $this->ttl = $ttl;
     return $this;
 }
Exemple #22
0
 /**
  * @param int $offset
  */
 public function offsetUnset($offset)
 {
     MDataType::mustBe(array(MDataType::INT));
     if ($this->offsetExists($offset)) {
         unset($this->vector[$offset]);
     }
 }
Exemple #23
0
 /**
  * @param int|null $userId
  * @return array
  * @throws \Exception
  */
 public function get($userId = null)
 {
     MDataType::mustBeNullableInt($userId);
     $toReturn = array();
     $sql = "CALL mt_role_get(?);";
     $query = new MPDOQuery($sql, $this->connection);
     $query->bindValue($userId);
     $queryResult = $query->exec();
     if ($queryResult == false || $query->getResult()->rowCount() <= 0) {
         return $toReturn;
     }
     foreach ($query->getResult() as $row) {
         $role = new Role();
         $role->setId($row['id'])->setName($row['name']);
         $toReturn[] = $role;
     }
     return $toReturn;
 }
Exemple #24
0
 /**
  * Appends the string <i>$str</i> at the end of this string. It is possible to use <i>$args</i>.<br>
  * Example:
  * <pre>
  *  $helloWorld = new MString();
  *  $helloWorld->append('Hello world %s', 'user');
  *  echo $helloWorld;
  * </pre>
  *
  * @param string $str
  * @param mixed $args [optional]
  * @return MString
  */
 public function append($str, $args = null)
 {
     MDataType::mustBeString($str);
     $this->text .= sprintf($str, $args);
     return new MString($this->text);
 }
 /**
  * @param string $tableName
  * @return MMySQLCacheManager
  */
 private function setTableName($tableName)
 {
     MDataType::mustBe(MDataType::STRING);
     $this->tableName = $tableName;
     return $this;
 }
 public function offsetGet_string($offset)
 {
     MDataType::mustBe(MDataType::STRING);
     if ($this->offsetExists_string($offset)) {
         return $this->record[$offset];
     }
     return null;
 }
 /**
  * @param string $path
  * @return void
  */
 private function removeFolder($path)
 {
     MDataType::mustBe(MDataType::STRING);
     if (!file_exists($path)) {
         return;
     }
     if (!is_dir($path)) {
         unlink($path);
     }
     foreach (scandir($path) as $item) {
         if ($item == '.' || $item == '..') {
             continue;
         }
         $this->removeFolder($path . DIRECTORY_SEPARATOR . $item);
     }
     rmdir($path);
 }
Exemple #28
0
 public function setSelected($selected)
 {
     MDataType::mustBeBoolean($selected);
     $this->selected = $selected;
     return $this;
 }