public function isEquals(Number $n) { if ($this->getValue() == $n->getValue() && $this->isExtra() == $n->isExtra()) { return true; } return false; }
public function multiply(Number $precision, $scale = null) { $scale = $this->scale($scale); $result = bcmul($this->value, $precision->getValue(), self::MAX_PRECISION); $diff = $this->round($result, $scale); return new self($diff, $scale); }
public static function echo_test() { $featureCode = new FeatureCode(); $featureCode['name'] = 'Echo Test'; $featureCode['registry'] = array('feature' => 'echo'); $featureCode->save(); try { $location = Doctrine::getTable('Location')->findAll(); if (!$location->count()) { throw Exception('Could not find location id'); } $location_id = arr::get($location, 0, 'location_id'); $number = new Number(); $number['user_id'] = users::getAttr('user_id'); $number['number'] = '9999'; $number['location_id'] = $location_id; $number['registry'] = array('ignoreFWD' => '0', 'ringtype' => 'ringing', 'timeout' => 20); $dialplan = array('terminate' => array('transfer' => 0, 'voicemail' => 0, 'action' => 'hangup')); $number['dialplan'] = $dialplan; $number['class_type'] = 'FeatureCodeNumber'; $number['foreign_id'] = $featureCode['feature_code_id']; $context = Doctrine::getTable('Context')->findOneByName('Outbound Routes'); $number['NumberContext']->fromArray(array(0 => array('context_id' => $context['context_id']))); $numberType = Doctrine::getTable('NumberType')->findOneByClass('FeatureCodeNumber'); if (empty($numberType['number_type_id'])) { return FALSE; } $number['NumberPool']->fromArray(array(0 => array('number_type_id' => $numberType['number_type_id']))); $number->save(); return $number['number_id']; } catch (Exception $e) { kohana::log('error', 'Unable to initialize device number: ' . $e->getMessage()); throw $e; } }
/** * String multiplication. * this is repeated other times * * @param Number $other the number of times to repeat this * @return SassString the string result * @throws StringException */ public function op_times($other) { if (!$other instanceof Number || !$other->isUnitless()) { throw new StringException('Value must be a unitless number', \PHPSass\Script\Parser::$context->node); } $this->value = str_repeat($this->value, $other->value); return $this; }
/** * @param \KataBank\Number $number * @return int */ private function checksum(Number $number) { $checksum = 0; $numberOfDigit = count($number->digits()); foreach ($number->digits() as $digit) { $checksum += $numberOfDigit * $digit->value(); $numberOfDigit--; } return $checksum; }
/** * Returns the simplified standard notation format for the given float, decimal number. * * @param Number $number * @return string */ public function format(Number $number) { /** * Move the decimal point to the right for positive exponents of 10. * Move the decimal point to the left for negative exponents of 10. */ $coefficient = (string) $number->getCoefficient(); $decimalPointPosition = strpos($coefficient, "."); if ($decimalPointPosition === false) { $decimalPointPosition = 1; } $coefficientWithoutDecimal = str_replace(".", "", $coefficient); $newDecimalPointPosition = $decimalPointPosition + $number->getExponent(); if ($number->getExponent() == 0) { // no change to be made from coefficient return (string) $number->getCoefficient(); } else { if ($number->getExponent() >= 0 && $newDecimalPointPosition - $decimalPointPosition < $number->getSignificantDigits()) { // move decimal point for number > 1 return substr($coefficientWithoutDecimal, 0, $newDecimalPointPosition) . '.' . substr($coefficientWithoutDecimal, $newDecimalPointPosition); } else { if ($newDecimalPointPosition > 0) { // pad number > 1 with zeros on the right return str_pad($coefficientWithoutDecimal, $newDecimalPointPosition - $number->getSignificantDigits() + 1, "0", STR_PAD_RIGHT); } else { // new decimal point position is less than or equal to zero // pad number < 1 with zeros on the left return "0." . str_pad($coefficientWithoutDecimal, abs($newDecimalPointPosition - $number->getSignificantDigits()), "0", STR_PAD_LEFT); } } } }
public function getPrimeFactors() { $value = $this->getValue(); for ($i = 2; $i <= floor(sqrt($value)); $i++) { if ($value % $i == 0) { $newNumber = new Number($value / $i); return array_merge(array($i), $newNumber->getPrimeFactors()); } } return array($value); }
public function testValidateType() { $field = new Number("test", "Test"); $result = $field->validateType("a string"); $this->assertFalse($result); $result = $field->validateType("11"); $this->assertTrue($result); $result = $field->validateType(20); $this->assertTrue($result); $result = $field->validateType(20.5); $this->assertTrue($result); }
/** * @param $expression * @return bool */ public static function translate($expression) { if ((String::isValid($expression) || Number::isValid($expression)) && Collection::existsKey(self::$translationMapping, $expression)) { $expression = self::$translationMapping[$expression]; } return $expression; }
public function __construct($value) { parent::__construct($value, 9); if (!preg_match('/^[0-9]{9}$/', (string) $value)) { throw new InvalidFieldException('Routing "' . $value . '" must be a 9 digit number.'); } }
/** * Formata o valor * @param mixed $value * @param string $type * @param boolean $formatar * @return mixed */ function formatValue($value, $type, $formatar) { switch (strtolower($type)) { case 'data': case 'dt': case 'date': $value = Date::data((string) $value); return $formatar ? Date::formatData($value) : $value; break; case 'timestamp': case 'datatime': $value = Date::timestamp((string) $value); return $formatar ? Date::formatDataTime($value) : $value; break; case 'real': return $formatar ? Number::real($value) : Number::float($value, 2); case 'hide': return $formatar ? null : $value; break; case 'array': return $formatar ? stringToArray($value) : arrayToString($value); break; default: return $value; } }
public static function breakUp($expressie) { $parts = array_reverse(str_split($expressie)); $expressions = []; $number = false; while (!empty($parts)) { $part = array_pop($parts); switch ($part) { case preg_match('/[0-9.]/', $part) ? true : false: if (!$number) { $expressions[] = $number = new Number(); } $number->add($part); break; case preg_match('/[+-\\/*]/', $part) ? true : false: $expressions[] = SolverFactory::buildSolver($part); break; case preg_match('/[\\[\\]]/', $part) ? true : false: $expressions[] = new Bracket(); break; default: $number = false; } } return $expressions; }
public function validate($value) { parent::validate($value); if (!is_integer($value)) { throw new ErrorException("Value has to be integer!"); } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $number = Number::where('number', $id)->first(); if ($number->delete()) { return array(); } return $this->response->errorInternal(); }
/** * Create a new instance * * @param float $val Value of this float */ public function __construct($val) { parent::__construct($val); // Validate... if (!is_float($this->val)) { return $this->panic(); } }
public function __construct($value) { parent::__construct($value, 1); $valid = [self::PREPARED_BY_OPERATOR, self::ORIGINATOR_IS_FI, self::ORIGINATOR_IS_EXEMPT, self::ORIGINATOR_IS_FED]; if (!in_array($value, $valid)) { throw new InvalidFieldException('Invalid originator status code "' . $value . '".'); } }
public function __construct($value) { parent::__construct($value, 2); $valid = [self::CHECKING_DEPOSIT, self::CHECKING_CREDIT_PRENOTIFICATION, self::CHECKING_ZERO_DOLLAR, self::CHECKING_DEBIT, self::CHECKING_DEBIT_PRENOTIFICATION, self::CHECKING_DEBIT_ZERO_DOLLAR, self::SAVINGS_DEPOSIT, self::SAVINGS_CREDIT_PRENOTIFICATION, self::SAVINGS_CREDIT_ZERO_DOLLAR, self::SAVINGS_DEBIT, self::SAVINGS_DEBIT_PRENOTIFICATION, self::SAVINGS_DEBIT_ZERO_DOLLAR, self::GL_CREDIT, self::GL_DEBIT, self::GL_CREDIT_PRENOTIFICATION, self::LOAN_CREDIT, self::LOAN_REVERSAL, self::LOAN_CREDIT_PRENOTIFICATION]; if (!in_array($value, $valid)) { throw new InvalidFieldException('Invalid transaction code "' . $value . '".'); } }
protected function validate($value) : bool { if (!parent::validate($value)) { return false; } $intval = (int) $value; return $intval == $value; }
public function postSetupNexmo() { $nexmo_key = Input::get('nexmo_key'); $nexmo_secret = Input::get('nexmo_secret'); $nexmo = new NexmoAccount($nexmo_key, $nexmo_secret); try { // check nexmo credentials $credit_balance = $nexmo->getBalance(); // check db connection DB::connection()->getDatabaseName(); // migrate db Artisan::call('migrate'); // truncate number table DB::table('number')->truncate(); // set nexmo credentials to env Cache::forever('NEXMO_KEY', $nexmo_key); Cache::forever('NEXMO_SECRET', $nexmo_secret); // add numbers to db $numbers = $nexmo->getInboundNumbers(); if ($numbers['count'] > 0) { foreach ($numbers['numbers'] as $num) { $number = new Number(); $number->number = $num['msisdn']; $number->country_code = $num['country']; $number->type = $num['type']; $number->features = $num['features']; $number->voice_callback_type = $num['voiceCallbackType']; $number->voice_callback_value = $num['voiceCallbackValue']; $number->save(); } } // set dn callback url // $nexmo->updateAccountSettings(array('drCallBackUrl' => url('callback/dn'))); Queue::getIron()->addSubscriber('setupDnCallbackUrl', array('url' => url('queue/receive'))); Queue::push('HomeController@setupDnCallbackUrl', array('nexmo_key' => $nexmo_key, 'nexmo_secret' => $nexmo_secret), 'setupDnCallbackUrl'); // set balance to cache Cache::put('nexmo', $credit_balance, 10); if (Auth::check()) { return Redirect::to('/'); } return Redirect::to('/register'); } catch (Exception $e) { return Redirect::to('start')->with('message', $e->__toString()); } }
/** * Validate input and set value * @param mixed * @return mixed */ public function validator($varInput) { try { $varInput = Number::create($varInput)->getAmount(); } catch (\InvalidArgumentException $e) { $this->addError($GLOBALS['TL_LANG']['ERR']['numberInputNotAllowed']); } return parent::validator($varInput); }
/** * Prototype resources to object * * @param mixed|optional $value * An optional value to be used by prototyped resource */ protected function prototype($i = NULL) { // Copying parent's prototypes parent::prototype($i); if (!is_null($i)) { $this->implement('convert', function ($from, $to) use($i) { return new String(base_convert($i, $from, $to)); }); } }
public static function merge($default_params, $input_params) { foreach ($default_params as $key => $value) { if (empty($input_params[$key])) { continue; } else { $value = $input_params[$key]; } switch ($key) { case "min_price": if (Number::isNatural($value)) { $default_params[$key] = $value; } break; case "max_price": if (Number::isNatural($value)) { $default_params[$key] = $value; } break; case "page": if (Number::isNatural($value)) { $default_params[$key] = $value; } break; case "limit": if (Number::isNatural($value) && $value < MAX_LIMIT) { $default_params[$key] = $value; } break; case "sort": if ($value == "+price" || $value == "+id" || $value == "-price" || $value == "-id") { $default_params[$key] = $value; } break; case "category_id": if (Number::isNatural($value)) { $default_params[$key] = $value; } break; case "id": if (Number::isNatural($value)) { $default_params[$key] = $value; } break; case "keyword": $default_params[$key] = $value; break; default: // other params will be dropped.. break; } } return $default_params; }
public function __construct($value) { // float value, preserve decimal places $value = number_format((double) $value, 2, '.', ''); // remove dots $value = str_replace('.', '', $value); if (strlen($value) > 10) { throw new InvalidFieldException('Amount "' . $value . '" is too large.'); } parent::__construct($value, 10); }
public static function realExtenso($valor = 0, $maiusculas = false) { $valor = Number::float($valor, 2); # verifica se tem virgula decimal if (strpos($valor, ",") > 0) { # retira o ponto de milhar, se tiver $valor = str_replace(".", "", $valor); # troca a virgula decimal por ponto decimal $valor = str_replace(",", ".", $valor); } $singular = array("centavo", "real", "mil", "milhão", "bilhão", "trilhão", "quatrilhão"); $plural = array("centavos", "reais", "mil", "milhões", "bilhões", "trilhões", "quatrilhões"); $c = array("", "cem", "duzentos", "trezentos", "quatrocentos", "quinhentos", "seiscentos", "setecentos", "oitocentos", "novecentos"); $d = array("", "dez", "vinte", "trinta", "quarenta", "cinquenta", "sessenta", "setenta", "oitenta", "noventa"); $d10 = array("dez", "onze", "doze", "treze", "quatorze", "quinze", "dezesseis", "dezesete", "dezoito", "dezenove"); $u = array("", "um", "dois", "três", "quatro", "cinco", "seis", "sete", "oito", "nove"); $z = 0; $valor = number_format($valor, 2, ".", "."); $inteiro = explode(".", $valor); $cont = count($inteiro); for ($i = 0; $i < $cont; $i++) { for ($ii = strlen($inteiro[$i]); $ii < 3; $ii++) { $inteiro[$i] = "0" . $inteiro[$i]; } } $fim = $cont - ($inteiro[$cont - 1] > 0 ? 1 : 2); for ($i = 0; $i < $cont; $i++) { $valor = $inteiro[$i]; $rc = $valor > 100 && $valor < 200 ? "cento" : $c[$valor[0]]; $rd = $valor[1] < 2 ? "" : $d[$valor[1]]; $ru = $valor > 0 ? $valor[1] == 1 ? $d10[$valor[2]] : $u[$valor[2]] : ""; $r = $rc . ($rc && ($rd || $ru) ? " e " : "") . $rd . ($rd && $ru ? " e " : "") . $ru; $t = $cont - 1 - $i; $r .= $r ? " " . ($valor > 1 ? $plural[$t] : $singular[$t]) : ""; if ($valor == "000") { $z++; } elseif ($z > 0) { $z--; } if ($t == 1 && $z > 0 && $inteiro[0] > 0) { $r .= ($z > 1 ? " de " : "") . $plural[$t]; } if ($r) { $rt = @$rt . ($i > 0 && $i <= $fim && $inteiro[0] > 0 && $z < 1 ? $i < $fim ? ", " : " e " : " ") . $r; } } if (!$maiusculas) { return trim($rt ? $rt : "zero"); } elseif ($maiusculas == "2") { return trim(strtoupper($rt) ? strtoupper($rt) : "Zero"); } else { return trim(ucwords($rt) ? ucwords($rt) : "Zero"); } }
public function setUp() { parent::setUp(); $this->setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_ALL ^ Doctrine::EXPORT_CONSTRAINTS); /* * Relationships */ // Relate the conference (conference_id) with a generic number identifier (foreign_id) in the Number class. // Note carefully that this only works because this model is related to Number // The Number class has some "magic" that auto relates the class $this->hasOne('System as Destination', array('local' => 'foreign_id', 'foreign' => 'system_id', 'owningSide' => TRUE)); }
protected function getDefaultErrorMessage($fieldName, $subRuleFlag = NULL, $threshold = NULL) { switch ($subRuleFlag) { case '.=': return "{$fieldName} must have {$threshold} digits after the decimal point."; case '.>': case '.>=': return "{$fieldName} must have {$threshold} or more digits after the decimal point."; default: return empty($subRuleFlag) ? "{$fieldName} must be an decimal." : parent::getDefaultErrorMessage($fieldName, $subRuleFlag, $threshold); } }
public function setUp() { parent::setUp(); $this->setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_ALL ^ Doctrine::EXPORT_CONSTRAINTS); $this->hasOne('AutoAttendant as Destination', array('local' => 'foreign_id', 'foreign' => 'auto_attendant_id')); foreach (get_declared_classes() as $class) { if (is_subclass_of($class, 'Number') or $class == 'Number') { $numberTable = Doctrine::getTable($class); $numberTable->bind(array('AutoAttendant', array('local' => 'foreign_id', 'foreign' => 'auto_attendant_id')), Doctrine_Relation::ONE); } } $this->actAs('TelephonyEnabled'); }
public function dnCallback($job, $outbound_chunk_id) { $client = new Client(); $outbound_chunk = OutboundChunk::find($outbound_chunk_id); $number = Number::where('number', $outbound_chunk->outbound->from)->first(); if (filter_var($number->own_callback_url, FILTER_VALIDATE_URL) !== FALSE) { try { $client->post($number->own_callback_url, array('headers' => array('Content-Type' => 'application/x-www-form-urlencoded'), 'body' => array_merge($outbound_chunk->toArray(), $outbound_chunk->outbound->toArray(), array('callback_type' => 'dn')))); } catch (Exception $e) { } } $job->delete(); }
public function setUp() { parent::setUp(); $this->setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_NONE); $this->hasOne('FaxProfile as Destination', array('local' => 'foreign_id', 'foreign' => 'fxp_id', 'owningSide' => FALSE)); foreach (get_declared_classes() as $class) { if (is_subclass_of($class, 'Number') or $class == 'Number') { $deviceTable = Doctrine::getTable($class); $deviceTable->bind(array('FaxProfile', array('local' => 'foreign_id', 'foreign' => 'fxp_id')), Doctrine_Relation::ONE); } } $this->actAs('TelephonyEnabled'); }
/** * value の内容を解釈してその結果を $result に格納します. * * <pre> * value = false / null / true / object / array / number / string * </pre> * * @param Context $context */ public function handle(Context $context) { $current = $context->current(); if ($current === "-" || Number::checkDigit($context)) { $number = new Number(); $number->handle($context); $this->result = $number->getResult(); return; } switch ($current) { case "f": $this->decodeLiteral($context, "false", false); break; case "n": $this->decodeLiteral($context, "null", null); break; case "t": $this->decodeLiteral($context, "true", true); break; case "[": $array = new ArrayExpr(); $array->handle($context); $this->result = $array->getResult(); break; case "{": $object = new ObjectExpr(); $object->handle($context); $this->result = $object->getResult(); break; case '"': $string = new StringExpr(); $string->handle($context); $this->result = $string->getResult(); break; default: $context->throwException("Invalid value format"); } }