本文整理汇总了PHP中InvalidArgumentException函数的典型用法代码示例。如果您正苦于以下问题:PHP InvalidArgumentException函数的具体用法?PHP InvalidArgumentException怎么用?PHP InvalidArgumentException使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了InvalidArgumentException函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* @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();
}
示例2: get
public function get($config)
{
if (!isset($this->_config[$config])) {
throw InvalidArgumentException($config . ' not found');
}
return $this->_config[$config];
}
示例3: __callStatic
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);
}
示例4: filter
/**
* 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');
}
示例5: add_entity_relationship
/**
* 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;
}
示例6: ModulePath
/**
* 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)));
}
}
示例7: parse
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);
}
示例8: setForm
/**
* Form setter.
*
* @param Form $form
*/
public function setForm(Form $form)
{
if (null === $form) {
throw InvalidArgumentException('Form is null!');
}
$this->form = $form;
}
示例9: getExporterClass
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');
}
示例10: setQuery
/**
* 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;
}
示例11: __construct
/** @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');
}
}
示例12: calculate
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));
}
示例13: adder
function adder($a, $b)
{
if (!is_int($a) || !is_int($b)) {
throw \InvalidArgumentException('ints only, buddy');
}
return $a + $b;
}
示例14: add
public function add(Entry $entry)
{
if (!$entry instanceof Entry) {
throw InvalidArgumentException('引数の型が不正です');
}
$this->directory[] = $entry;
$entry->setParent($this);
}
示例15: __construct
/**
* @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'));
}