Exemple #1
0
 /**
  * @param  Array $args
  * @return String $id
  */
 public function save($args = array(), $id = null)
 {
     /**
      * This funciton inserts the record in the table. HOwever
      * if $id is set; it will result in an update query
      * $id primay key value
      */
     if (isset($id)) {
         $sql = $this->update($args, $id);
         $stmt = $this->dbcon->prepare($sql);
         foreach ($args as $key => &$value) {
             $stmt->bindParam(":{$key}", $value);
         }
         $stmt->execute();
         if (!$stmt->rowCount()) {
             throw InvalidArgumentException();
         }
         return true;
     }
     // do Insert
     $sql = $this->insert($args);
     $stmt = $this->dbcon->prepare($sql);
     foreach ($args as $key => &$value) {
         $stmt->bindParam(":{$key}", $value);
     }
     $stmt->execute();
     if (!$stmt->rowCount()) {
         throw new InvalidArgumentException();
     }
     return $this->dbcon->lastInsertId();
 }
Exemple #2
0
 public function get($config)
 {
     if (!isset($this->_config[$config])) {
         throw InvalidArgumentException($config . ' not found');
     }
     return $this->_config[$config];
 }
Exemple #3
0
 public static function __callStatic($method, $arguments)
 {
     switch (true) {
         case 0 === strpos($method, 'findBy'):
             $by = substr($method, 6);
             $method = 'findBy';
             break;
         case 0 === strpos($method, 'findOneBy'):
             $by = substr($method, 9);
             $method = 'findOneBy';
             break;
         default:
             throw new \BadMethodCallException("Undefined method '{$method}'. The method name must start with either findBy or findOneBy!");
     }
     if (empty($arguments)) {
         throw \InvalidArgumentException('The method ' . $method . $by . ' requires parameters');
     }
     $fieldName = lcfirst($by);
     if (property_exists(get_called_class(), $fieldName)) {
         switch (count($arguments)) {
             case 1:
                 return self::$method(array($fieldName => $arguments[0]));
             case 2:
                 return self::$method(array($fieldName => $arguments[0]), $arguments[1]);
             case 3:
                 return self::$method(array($fieldName => $arguments[0]), $arguments[1], $arguments[2]);
             case 4:
                 return self::$method(array($fieldName => $arguments[0]), $arguments[1], $arguments[2], $arguments[3]);
             default:
                 // Do nothing
         }
     }
     throw new \BadMethodCallException('Unexisting method: ' . $method . $by);
 }
 /**
  * Sets operator and value in the filter
  *
  * @param string $operator
  * @param string $value
  */
 public function filter($operator, $value)
 {
     $dropdowns = $this->findAll('css', '.dropdown-toggle');
     $operatorDropdown = $this->decorate($dropdowns[0], ['Pim\\Behat\\Decorator\\Grid\\Filter\\OperatorDecorator']);
     $currencyDropdown = $dropdowns[1];
     // Split '10.5 EUR' -> $data = 10.5; $currency = 'EUR'
     $value = '' !== $value ? explode(' ', $value) : [];
     switch (count($value)) {
         case 0:
         case 1:
             list($data, $currency) = ['', reset($value)];
             break;
         case 2:
             list($data, $currency) = $value;
             break;
         default:
             throw \InvalidArgumentException('You must specify a currency and a value');
             break;
     }
     // Set the value:
     $this->find('css', 'input[name="value"]')->setValue($data);
     $currencyDropdown->click();
     $currencyChoice = $currencyDropdown->getParent()->find('css', sprintf('.dropdown-menu .choice_value[data-value="%s"]', $currency));
     if (null === $currencyChoice) {
         throw new \Exception(sprintf('Cannot find the choice for currency %s', $currency));
     }
     $currencyChoice->click();
     // Change the operator
     $operatorDropdown->setValue($operator);
     // Update the filter
     $this->spin(function () {
         $this->find('css', '.filter-update')->click();
         return true;
     }, 'Cannot update the filter');
 }
Exemple #5
0
/**
 * Define an arbitrary relationship between two entities.
 * This relationship could be a friendship, a group membership or a site membership.
 *
 * This function lets you make the statement "$guid_one is a $relationship of $guid_two".
 *
 * @param int    $guid_one     First GUID
 * @param string $relationship Relationship name
 * @param int    $guid_two     Second GUID
 *
 * @return bool
 * @throws InvalidArgumentException
 */
function add_entity_relationship($guid_one, $relationship, $guid_two)
{
    global $CONFIG;
    if (strlen($relationship) > ElggRelationship::RELATIONSHIP_LIMIT) {
        $msg = "relationship name cannot be longer than " . ElggRelationship::RELATIONSHIP_LIMIT;
        throw InvalidArgumentException($msg);
    }
    $guid_one = (int) $guid_one;
    $relationship = sanitise_string($relationship);
    $guid_two = (int) $guid_two;
    $time = time();
    // Check for duplicates
    if (check_entity_relationship($guid_one, $relationship, $guid_two)) {
        return false;
    }
    $id = insert_data("INSERT INTO {$CONFIG->dbprefix}entity_relationships\n\t\t(guid_one, relationship, guid_two, time_created)\n\t\tVALUES ({$guid_one}, '{$relationship}', {$guid_two}, {$time})");
    if ($id !== false) {
        $obj = get_relationship($id);
        // this event has been deprecated in 1.9. Use 'create', 'relationship'
        $result_old = elgg_trigger_event('create', $relationship, $obj);
        $result = elgg_trigger_event('create', 'relationship', $obj);
        if ($result && $result_old) {
            return true;
        } else {
            delete_relationship($result);
        }
    }
    return false;
}
	/**
	 * Given some pre-defined modules, return the filesystem path of the module.
	 * @param string $name Name of module to find path of
	 * @return string
	 */
	public static function ModulePath($name) {
		if(isset(self::$modules[$name])) {
			return self::$modules[$name];
		} else {
			throw InvalidArgumentException(sprintf('%s is not a supported argument. Possible values: %s', $name, implode(', ', self::$modules)));
		}
	}
Exemple #7
0
 public function parse($number, $parseDecimal = true, $joinWith = 'con', $integerUnit = '', $decimalUnit = '')
 {
     if (!is_numeric($number)) {
         throw \InvalidArgumentException("Not a number.");
     }
     $numbers = explode('.', $number);
     $string = $numbers[0];
     if (strlen($string) > 12) {
         throw \InvalidArgumentException("Can't convert 12 digits or more.");
     }
     $text = $this->translate($string);
     if (!empty($integerUnit)) {
         $text .= ' ' . $integerUnit;
     }
     if (isset($numbers[1])) {
         $decimal = $parseDecimal ? $this->translate($numbers[1]) : $numbers[1];
         if (!empty($joinWith)) {
             $joinWith .= ' ';
         }
         $text .= ' ' . $joinWith . $decimal;
         if (!empty($decimalUnit)) {
             $text .= ' ' . $decimalUnit;
         }
     }
     return ucfirst($text);
 }
 /**
  * Form setter.
  * 
  * @param  Form  $form 
  */
 public function setForm(Form $form)
 {
     if (null === $form) {
         throw InvalidArgumentException('Form is null!');
     }
     $this->form = $form;
 }
 public static function getExporterClass($a_type)
 {
     /**
      * @var $objDefinition ilObjectDefinition
      */
     global $objDefinition;
     if ($objDefinition->isPlugin($a_type)) {
         $classname = 'il' . $objDefinition->getClassName($a_type) . 'Exporter';
         $location = $objDefinition->getLocation($a_type);
         if (include_once $location . '/class.' . $classname . '.php') {
             return $classname;
         }
     } else {
         $comp = $objDefinition->getComponentForType($a_type);
         $c = explode("/", $comp);
         $class = "il" . $c[1] . "Exporter";
         // the next line had a "@" in front of the include_once
         // I removed this because it tages ages to track down errors
         // if the include class contains parse errors.
         // Alex, 20 Jul 2012
         if (include_once "./" . $comp . "/classes/class." . $class . ".php") {
             return $class;
         }
     }
     throw InvalidArgumentException('Invalid exporter type given');
 }
Exemple #10
0
 /**
  * Prepare listing instance from Doctrine ORM Query or QueryBuilder.
  * 
  * Sets 'order by' only for QueryBuilder.
  * 
  * @param Query|QueryBuilder
  * @param boolean
  * @param boolean
  * @param boolean
  * @return self
  * @see Paginator
  */
 public function setQuery($query, $fetchJoinCollection = false, $appendLimit = true, $appendOrder = true)
 {
     if ($query instanceof QueryBuilder) {
         $order = $this->order();
         if ($appendOrder && $order) {
             if (is_array($order)) {
                 call_user_func_array([$query, 'orderBy'], $order);
             } else {
                 $query->add('orderBy', $order);
             }
         }
         $query = $query->getQuery();
     }
     if (!$query instanceof Query) {
         throw \InvalidArgumentException('Instance of Doctrine\\ORM\\Query or Doctrine\\ORM\\QueryBuilder required!');
     }
     if ($appendLimit) {
         $paginator = new Paginator($query, $fetchJoinCollection);
         $this->setCount($paginator->count());
         $query->setFirstResult($this->offset())->setMaxResults($this->limit());
         $this->setItems($paginator);
     } else {
         $this->setItems($query->getResult());
     }
     return $this;
 }
 /** @brief Constructs new search connector.
  *
  * All parameter values should have been provided by Antidot.
  *
  * @param $host [in] server hosting the required service.
  * @param $service [in] Antidot service (see @a AfsService).
  * @param $scheme [in] Scheme for the connection URL see
  *        @ref uri_scheme (default: @a AFS_SCHEME_HTTP).
  *
  * @exception InvalidArgumentException invalid scheme parameter provided.
  */
 public function __construct($host, AfsService $service, $scheme = AFS_SCHEME_HTTP, SAI_CurlInterface $curlConnector = null)
 {
     parent::__construct($host, $service, $scheme, $curlConnector);
     if ($scheme != AFS_SCHEME_HTTP) {
         throw InvalidArgumentException('Search connector support only HTTTP connection');
     }
 }
Exemple #12
0
 public function calculate(array $sequenceA, array $sequenceB)
 {
     $sizeA = count($sequenceA);
     $sizeB = count($sequenceB);
     if ($sizeA === 0 || $sizeB === 0 || $sizeA !== $sizeB) {
         throw InvalidArgumentException();
     }
     $averageA = array_sum($sequenceA) / $sizeA;
     $averageB = array_sum($sequenceB) / $sizeB;
     $numerator = 0;
     for ($i = 0; $i < $sizeA; ++$i) {
         $numerator += ($sequenceA[$i] - $averageA) * ($sequenceB[$i] - $averageB);
     }
     $x = 0;
     for ($i = 0; $i < $sizeA; ++$i) {
         $value = $sequenceA[$i] - $averageA;
         $x += $value * $value;
     }
     $y = 0;
     for ($i = 0; $i < $sizeB; ++$i) {
         $value = $sequenceB[$i] - $averageB;
         $y += $value * $value;
     }
     return in_array(0, [$x, $y]) ? NAN : $numerator / (sqrt($x) * sqrt($y));
 }
function adder($a, $b)
{
    if (!is_int($a) || !is_int($b)) {
        throw \InvalidArgumentException('ints only, buddy');
    }
    return $a + $b;
}
 public function add(Entry $entry)
 {
     if (!$entry instanceof Entry) {
         throw InvalidArgumentException('引数の型が不正です');
     }
     $this->directory[] = $entry;
     $entry->setParent($this);
 }
Exemple #15
0
 /**
  * @param array $params  Additional configuration parameters:
  * <pre>
  *   - predis: (Predis\Client) [REQUIRED] Predis client object.
  * </pre>
  */
 public function __construct(array $params = array())
 {
     if (!isset($params['predis'])) {
         throw InvalidArgumentException('Missing predis parameter.');
     }
     parent::__construct($params);
     register_shutdown_function(array($this, 'shutdown'));
 }
 /**
  * @param string $value
  * @return string
  */
 public function getCategoryName($id)
 {
     if (!preg_match('/^[0-9]+$/', $id)) {
         throw InvalidArgumentException("IDではない値が指定されました");
     }
     $entity = $this->em->getRepository('AtwTestBundle:Category')->find($id);
     return is_null($entity) ? null : $entity->getName();
 }
 public function getImageUrl($image_name)
 {
     if (isset($image_name) || $image_name === "") {
         $imageFolderPath = $this->app->config()->get("RootImageFolderPath");
         return $imageFolderPath . $image_name;
     }
     throw InvalidArgumentException("Missing Image name!");
 }
Exemple #18
0
 public function __construct(Reducer $next_reducer, $batch_size)
 {
     if (!is_int($batch_size)) {
         throw \InvalidArgumentException('argument #2 of Batching::__construct must be an integer');
     }
     $this->batch_size = $batch_size;
     $this->next_reducer = $next_reducer;
 }
Exemple #19
0
 public function __construct($host, AfsService $service, $scheme = AFS_SCHEME_HTTP)
 {
     parent::__construct($host, $service, $scheme);
     if ($scheme != AFS_SCHEME_HTTP) {
         throw InvalidArgumentException('ACP connector support only HTTP connection');
     }
     $this->build_reply_as_associative_array();
 }
 /**
  * Setup
  *
  * @param object AppModel
  * @param array $config
  */
 public function setup(Model $Model, $config = array())
 {
     $settings = array_merge($this->_defaults, $config);
     $this->settings[$Model->alias] = $settings;
     if (empty($this->settings[$Model->alias]['fields'])) {
         throw InvalidArgumentException(__d('utils', 'You need to define at least one field to be toggleable.'), E_USER_ERROR);
     }
 }
Exemple #21
0
 /**
  * __construct
  *
  * @param string $name
  * @param string $type
  * @param boolean $isIdentifier
  * @access public
  */
 public function __construct($name, $type = 'string', $isIdentifier = false)
 {
     if (empty($name)) {
         throw \InvalidArgumentException('attribute name must be set');
     }
     $this->name = $name;
     $this->type = $type;
     $this->isIdentifier = $isIdentifier;
 }
Exemple #22
0
 public function save($fileName, $formatOutput = true)
 {
     try {
         $this->xml->formatOutput = $formatOutput;
         $this->xml->save($fileName);
     } catch (Exception $ex) {
         throw InvalidArgumentException("Unable to Save Feed in {$fileName}");
     }
 }
Exemple #23
0
 public function count($id, $field, $diff)
 {
     $fields = array('likeNum');
     if (!in_array($field, $fields)) {
         throw \InvalidArgumentException(sprintf("%s字段不允许增减,只有%s才被允许增减", $field, implode(',', $fields)));
     }
     $sql = "UPDATE {$this->table} SET {$field} = {$field} + ? WHERE id = ? LIMIT 1";
     return $this->getConnection()->executeQuery($sql, array($diff, $id));
 }
 public function waveClassroom($id, $field, $diff)
 {
     $fields = array('hitNum', 'auditorNum', 'studentNum', 'courseNum', 'lessonNum', 'threadNum', 'postNum', 'noteNum');
     if (!in_array($field, $fields)) {
         throw \InvalidArgumentException(sprintf("%s字段不允许增减,只有%s才被允许增减", $field, implode(',', $fields)));
     }
     $sql = "UPDATE {$this->table} SET {$field} = {$field} + ? WHERE id = ? LIMIT 1";
     $this->clearCached();
     return $this->getConnection()->executeQuery($sql, array($diff, $id));
 }
 public function waveThread($id, $field, $diff)
 {
     $fields = array('postNum', 'hitNum');
     if (!in_array($field, $fields)) {
         throw \InvalidArgumentException(sprintf("%s字段不允许增减,只有%s才被允许增减", $field, implode(',', $fields)));
     }
     $currentTime = time();
     $sql = "UPDATE {$this->table} SET {$field} = {$field} + ?, updatedTime = {$currentTime} WHERE id = ? LIMIT 1";
     return $this->getConnection()->executeQuery($sql, array($diff, $id));
 }
 public function __construct($bannerId)
 {
     if (is_null($bannerId)) {
         throw InvalidArgumentException('Missing id.');
     } else {
         $this->bannerId = $bannerId;
     }
     $this->assignmentHistory = array();
     $this->init();
 }
Exemple #27
0
 public function waveGroup($id, $field, $diff)
 {
     $fields = array('postNum', 'threadNum', 'memberNum');
     if (!in_array($field, $fields)) {
         throw \InvalidArgumentException(sprintf("%s字段不允许增减,只有%s才被允许增减", $field, implode(',', $fields)));
     }
     $sql = "UPDATE {$this->table} SET {$field} = {$field} + ? WHERE id = ? LIMIT 1";
     $result = $this->getConnection()->executeQuery($sql, array($diff, $id));
     $this->clearCached();
     return $result;
 }
Exemple #28
0
 public function __construct($userId)
 {
     if (!$userId) {
         throw \InvalidArgumentException('user id cannot null.');
     }
     $this->userId = $userId;
     $this->objMdlCart = app::get('systrade')->model('cart');
     $this->objLibItemInfo = kernel::single('sysitem_item_info');
     $this->objMath = kernel::single('ectools_math');
     $this->__instance();
 }
Exemple #29
0
 protected function setUrl($url)
 {
     if (!filter_var($url, FILTER_VALIDATE_URL)) {
         throw \InvalidArgumentException("Invalid URL: {$url}");
     }
     $this->url = $url;
     if (empty($this->id)) {
         $this->id = $url;
     }
     return $this;
 }
Exemple #30
0
 /**
  * 取得云平台的操作模块
  *
  * @param string $module
  *
  * @return mixed
  * @throws \InvalidArgumentException
  */
 public static function getCloudModule($module)
 {
     if (!self::$cloudEngine) {
         throw new \InvalidArgumentException('cloudEngine does not init properly');
     }
     $module = self::$cloudEngine->getCloudModule($module);
     if (!$module) {
         throw \InvalidArgumentException('get module [' . $module . '] failed from engine [' . get_class(self::$cloudEngine) . ']');
     }
     return $module;
 }