sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
private function getResourceOnly() { $name = $this->getArgumentResource(); if (!str_contains($name, '.')) { return $name; } return substr($name, strripos($name, '.') + 1); }
If there are '.' in the name, get the last occurence @return string
entailment
protected function getErrorFromFault(\SoapFault $fault) { $error = $this->getErrorByCode($fault->faultcode, $fault->faultstring); if (empty($error->getMessage())) { $error->setMessage(isset($fault->detail) ? $fault->detail->message : $fault->faultstring); } return $error; }
Get error from Fault Exception. @param \SoapFault $fault @return Error
entailment
protected function getErrorByCode($code, $optional = '') { $error = new Error($code); $code = preg_replace(self::NUMBER_PATTERN, '', $code); $message = ''; if (empty($code) && $optional) { $code = preg_replace(self::NUMBER_PATTERN, '', $optional); } if ($code) { $message = $this->getMessageError($code); $error->setCode($code); } return $error->setMessage($message); }
@param string $code @param string $optional intenta obtener el codigo de este parametro sino $codigo no es válido @return Error
entailment
protected function compress($filename, $xml) { if (!$this->compressor) { $this->compressor = new ZipFly(); } return $this->compressor->compress($filename, $xml); }
@param string $filename @param string $xml @return string
entailment
protected function extractResponse($zipContent) { if (!$this->cdrReader) { $this->cdrReader = new DomCdrReader(new XmlReader()); } $xml = $this->getXmlResponse($zipContent); return $this->cdrReader->getCdrResponse($xml); }
@param $zipContent @return \Greenter\Model\Response\CdrResponse
entailment
public function confirm($returnUrl, $message = null) { if (empty($message)) { $message = 'Thank you, your transaction has been processed. You are being redirected...'; } echo '<meta http-equiv="refresh" content="2;url='.$returnUrl.'" /><p>'.$message.'</p>'; exit; }
Optional step: Redirect the customer back to your own domain. This is achieved by returning a HTML string containing a meta-redirect which is displayed by WorldPay to the customer. This is far from ideal, but apparently (according to their support) this is the only method currently available. @param string $returnUrl The URL to forward the customer to. @param string|null $message Optional message to display to the customer before they are redirected.
entailment
public function range(int $start, int $length): string { if (!$length) { return "0"; } if ($start + $length > $this->numBits()) { throw new \OutOfBoundsException("Not enough bits."); } $bits = gmp_init(0); $idx = $start; $end = $start + $length; while (true) { $bit = $this->testBit($idx) ? 1 : 0; $bits |= $bit; if (++$idx >= $end) { break; } $bits <<= 1; } return gmp_strval($bits, 10); }
Get range of bits. @param int $start Index of first bit @param int $length Number of bits in range @throws \OutOfBoundsException @return string Integer of $length bits
entailment
public function withoutTrailingZeroes(): self { // if bit string was empty if (!strlen($this->_string)) { return new self(""); } $bits = $this->_string; // count number of empty trailing octets $unused_octets = 0; for ($idx = strlen($bits) - 1; $idx >= 0; --$idx, ++$unused_octets) { if ($bits[$idx] != "\x0") { break; } } // strip trailing octets if ($unused_octets) { $bits = substr($bits, 0, -$unused_octets); } // if bit string was full of zeroes if (!strlen($bits)) { return new self(""); } // count number of trailing zeroes in the last octet $unused_bits = 0; $byte = ord($bits[strlen($bits) - 1]); while (!($byte & 0x01)) { $unused_bits++; $byte >>= 1; } return new self($bits, $unused_bits); }
Get a copy of the bit string with trailing zeroes removed. @return self
entailment
private static function _decodeDefiniteLength(string $data, int &$offset, int $length): ElementBase { $idx = $offset; $end = $idx + $length; $elements = []; while ($idx < $end) { $elements[] = Element::fromDER($data, $idx); // check that element didn't overflow length if ($idx > $end) { throw new DecodeException( "Structure's content overflows length."); } } $offset = $idx; // return instance by static late binding return new static(...$elements); }
Decode elements for a definite length. @param string $data DER data @param int $offset Offset to data @param int $length Number of bytes to decode @throws DecodeException @return ElementBase
entailment
private static function _decodeIndefiniteLength(string $data, int &$offset): ElementBase { $idx = $offset; $elements = []; $end = strlen($data); while (true) { if ($idx >= $end) { throw new DecodeException( 'Unexpected end of data while decoding indefinite length structure.'); } $el = Element::fromDER($data, $idx); if ($el->isType(self::TYPE_EOC)) { break; } $elements[] = $el; } $offset = $idx; $type = new static(...$elements); $type->_indefiniteLength = true; return $type; }
Decode elements for an indefinite length. @param string $data DER data @param int $offset Offset to data @throws DecodeException @return ElementBase
entailment
public static function explodeDER(string $data): array { $offset = 0; $identifier = Identifier::fromDER($data, $offset); if (!$identifier->isConstructed()) { throw new DecodeException("Element is not constructed."); } $length = Length::expectFromDER($data, $offset); if ($length->isIndefinite()) { throw new DecodeException( 'Explode not implemented for indefinite length encoding.'); } $end = $offset + $length->intLength(); $parts = []; while ($offset < $end) { // start of the element $idx = $offset; // skip identifier Identifier::fromDER($data, $offset); // decode element length $length = Length::expectFromDER($data, $offset)->intLength(); // extract der encoding of the element $parts[] = substr($data, $idx, $offset - $idx + $length); // update offset over content $offset += $length; } return $parts; }
Explode DER structure to DER encoded components that it contains. @param string $data @throws DecodeException @return string[]
entailment
public function withReplaced(int $idx, Element $el): self { if (!isset($this->_elements[$idx])) { throw new \OutOfBoundsException( "Structure doesn't have element at index $idx."); } $obj = clone $this; $obj->_elements[$idx] = $el; return $obj; }
Get self with an element at the given index replaced by another. @param int $idx Element index @param Element $el New element to insert into the structure @throws \OutOfBoundsException @return self
entailment
public function withInserted(int $idx, Element $el): self { if (count($this->_elements) < $idx || $idx < 0) { throw new \OutOfBoundsException("Index $idx is out of bounds."); } $obj = clone $this; array_splice($obj->_elements, $idx, 0, [$el]); return $obj; }
Get self with an element inserted before the given index. @param int $idx Element index @param Element $el New element to insert into the structure @throws \OutOfBoundsException @return self
entailment
public function withAppended(Element $el): self { $obj = clone $this; array_push($obj->_elements, $el); return $obj; }
Get self with an element appended to the end. @param Element $el Element to insert into the structure @return self
entailment
public function withPrepended(Element $el): self { $obj = clone $this; array_unshift($obj->_elements, $el); return $obj; }
Get self with an element prepended in the beginning. @param Element $el Element to insert into the structure @return self
entailment
public function withoutElement(int $idx): self { if (!isset($this->_elements[$idx])) { throw new \OutOfBoundsException( "Structure doesn't have element at index $idx."); } $obj = clone $this; array_splice($obj->_elements, $idx, 1); return $obj; }
Get self with an element at the given index removed. @param int $idx Element index @throws \OutOfBoundsException @return self
entailment
public function elements(): array { if (!isset($this->_unspecifiedTypes)) { $this->_unspecifiedTypes = array_map( function (Element $el) { return new UnspecifiedType($el); }, $this->_elements); } return $this->_unspecifiedTypes; }
Get elements in the structure. @return UnspecifiedType[]
entailment
public function has(int $idx, $expectedTag = null): bool { if (!isset($this->_elements[$idx])) { return false; } if (isset($expectedTag)) { if (!$this->_elements[$idx]->isType($expectedTag)) { return false; } } return true; }
Check whether the structure has an element at the given index, optionally satisfying given tag expectation. @param int $idx Index 0..n @param int|null $expectedTag Optional type tag expectation @return bool
entailment
public function at(int $idx, $expectedTag = null): UnspecifiedType { if (!isset($this->_elements[$idx])) { throw new \OutOfBoundsException( "Structure doesn't have an element at index $idx."); } $element = $this->_elements[$idx]; if (isset($expectedTag)) { $element->expectType($expectedTag); } return new UnspecifiedType($element); }
Get the element at the given index, optionally checking that the element has a given tag. <strong>NOTE!</strong> Expectation checking is deprecated and should be done with <code>UnspecifiedType</code>. @param int $idx Index 0..n @param int|null $expectedTag Optional type tag expectation @throws \OutOfBoundsException If element doesn't exists @throws \UnexpectedValueException If expectation fails @return UnspecifiedType
entailment
public function hasTagged(int $tag): bool { // lazily build lookup map if (!isset($this->_taggedMap)) { $this->_taggedMap = []; foreach ($this->_elements as $element) { if ($element->isTagged()) { $this->_taggedMap[$element->tag()] = $element; } } } return isset($this->_taggedMap[$tag]); }
Check whether the structure contains a context specific element with a given tag. @param int $tag Tag number @return bool
entailment
public function getTagged(int $tag): TaggedType { if (!$this->hasTagged($tag)) { throw new \LogicException("No tagged element for tag $tag."); } return $this->_taggedMap[$tag]; }
Get a context specific element tagged with a given tag. @param int $tag @throws \LogicException If tag doesn't exists @return TaggedType
entailment
public function handle() { $this->meta = (new NameParser)->parse($this->argumentName()); $name = $this->qualifyClass($this->getNameInput()); $path = $this->getPath($name); if ($this->files->exists($path) && $this->optionForce() === false) { return $this->error($this->type . ' already exists!'); } $this->makeDirectory($path); $this->files->put($path, $this->buildClass($name)); $this->info($this->type . ' created successfully.'); $this->info('- ' . $path); // if model is required if ($this->optionModel() === true || $this->optionModel() === 'true') { $this->call('generate:model', [ 'name' => $this->getModelName(), '--plain' => $this->optionPlain(), '--force' => $this->optionForce(), '--schema' => $this->optionSchema() ]); } }
Execute the console command. @return mixed
entailment
protected function buildClass($name) { $stub = $this->files->get($this->getStub()); $this->replaceNamespace($stub, $name); $this->replaceClassName($stub); $this->replaceSchema($stub); $this->replaceTableName($stub); return $stub; }
Build the class with the given name. @param string $name @return string
entailment
protected function replaceClassName(&$stub) { $className = ucwords(camel_case($this->argumentName())); $stub = str_replace('{{class}}', $className, $stub); return $this; }
Replace the class name in the stub. @param string $stub @return $this
entailment
protected function replaceSchema(&$stub) { $schema = ''; if (!$this->optionPlain()) { if ($schema = $this->optionSchema()) { $schema = (new SchemaParser)->parse($schema); } $schema = (new SyntaxBuilder)->create($schema, $this->meta); } $stub = str_replace(['{{schema_up}}', '{{schema_down}}'], $schema, $stub); return $this; }
Replace the schema for the stub. @param string $stub @return $this
entailment
protected function getModelName($name = null) { $name = str_singular($this->meta['table']); $model = ''; $pieces = explode('_', $name); foreach ($pieces as $k => $str) { $model = $model . ucwords($str); } return $model; }
Get the class name for the Eloquent model generator. @param null $name @return string
entailment
protected function getStub() { return config('generators.' . strtolower($this->type) . ($this->input->hasOption('plain') && $this->option('plain') ? '_plain' : '') . '_stub'); }
Get the stub file for the generator. @return string
entailment
protected function getOptions() { return array_merge([ ['model', 'm', InputOption::VALUE_OPTIONAL, 'Want a model for this table?', true], ['schema', 's', InputOption::VALUE_OPTIONAL, 'Optional schema to be attached to the migration', null], ], parent::getOptions()); }
Get the console command options. @return array
entailment
public static function fromElementBase(ElementBase $el): self { // if element is already wrapped if ($el instanceof self) { return $el; } return new self($el->asElement()); }
Initialize from ElementBase interface. @param ElementBase $el @return self
entailment
public function asTagged(): TaggedType { if (!$this->_element instanceof TaggedType) { throw new \UnexpectedValueException( "Tagged element expected, got " . $this->_typeDescriptorString()); } return $this->_element; }
Get the wrapped element as a context specific tagged type. @throws \UnexpectedValueException If the element is not tagged @return TaggedType
entailment
public function asApplication(): Tagged\ApplicationType { if (!$this->_element instanceof Tagged\ApplicationType) { throw new \UnexpectedValueException( "Application type expected, got " . $this->_typeDescriptorString()); } return $this->_element; }
Get the wrapped element as an application specific type. @throws \UnexpectedValueException If element is not application specific @return \ASN1\Type\Tagged\ApplicationType
entailment
public function asPrivate(): Tagged\PrivateType { if (!$this->_element instanceof Tagged\PrivateType) { throw new \UnexpectedValueException( "Private type expected, got " . $this->_typeDescriptorString()); } return $this->_element; }
Get the wrapped element as a private tagged type. @throws \UnexpectedValueException If element is not using private tagging @return \ASN1\Type\Tagged\PrivateType
entailment
public function asBoolean(): Primitive\Boolean { if (!$this->_element instanceof Primitive\Boolean) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_BOOLEAN)); } return $this->_element; }
Get the wrapped element as a boolean type. @throws \UnexpectedValueException If the element is not a boolean @return \ASN1\Type\Primitive\Boolean
entailment
public function asInteger(): Primitive\Integer { if (!$this->_element instanceof Primitive\Integer) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_INTEGER)); } return $this->_element; }
Get the wrapped element as an integer type. @throws \UnexpectedValueException If the element is not an integer @return \ASN1\Type\Primitive\Integer
entailment
public function asBitString(): Primitive\BitString { if (!$this->_element instanceof Primitive\BitString) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_BIT_STRING)); } return $this->_element; }
Get the wrapped element as a bit string type. @throws \UnexpectedValueException If the element is not a bit string @return \ASN1\Type\Primitive\BitString
entailment
public function asOctetString(): Primitive\OctetString { if (!$this->_element instanceof Primitive\OctetString) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_OCTET_STRING)); } return $this->_element; }
Get the wrapped element as an octet string type. @throws \UnexpectedValueException If the element is not an octet string @return \ASN1\Type\Primitive\OctetString
entailment
public function asNull(): Primitive\NullType { if (!$this->_element instanceof Primitive\NullType) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_NULL)); } return $this->_element; }
Get the wrapped element as a null type. @throws \UnexpectedValueException If the element is not a null @return \ASN1\Type\Primitive\NullType
entailment
public function asObjectIdentifier(): Primitive\ObjectIdentifier { if (!$this->_element instanceof Primitive\ObjectIdentifier) { throw new \UnexpectedValueException( $this->_generateExceptionMessage( Element::TYPE_OBJECT_IDENTIFIER)); } return $this->_element; }
Get the wrapped element as an object identifier type. @throws \UnexpectedValueException If the element is not an object identifier @return \ASN1\Type\Primitive\ObjectIdentifier
entailment
public function asObjectDescriptor(): Primitive\ObjectDescriptor { if (!$this->_element instanceof Primitive\ObjectDescriptor) { throw new \UnexpectedValueException( $this->_generateExceptionMessage( Element::TYPE_OBJECT_DESCRIPTOR)); } return $this->_element; }
Get the wrapped element as an object descriptor type. @throws \UnexpectedValueException If the element is not an object descriptor @return \ASN1\Type\Primitive\ObjectDescriptor
entailment
public function asReal(): Primitive\Real { if (!$this->_element instanceof Primitive\Real) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_REAL)); } return $this->_element; }
Get the wrapped element as a real type. @throws \UnexpectedValueException If the element is not a real @return \ASN1\Type\Primitive\Real
entailment
public function asEnumerated(): Primitive\Enumerated { if (!$this->_element instanceof Primitive\Enumerated) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_ENUMERATED)); } return $this->_element; }
Get the wrapped element as an enumerated type. @throws \UnexpectedValueException If the element is not an enumerated @return \ASN1\Type\Primitive\Enumerated
entailment
public function asUTF8String(): Primitive\UTF8String { if (!$this->_element instanceof Primitive\UTF8String) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_UTF8_STRING)); } return $this->_element; }
Get the wrapped element as a UTF8 string type. @throws \UnexpectedValueException If the element is not a UTF8 string @return \ASN1\Type\Primitive\UTF8String
entailment
public function asRelativeOID(): Primitive\RelativeOID { if (!$this->_element instanceof Primitive\RelativeOID) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_RELATIVE_OID)); } return $this->_element; }
Get the wrapped element as a relative OID type. @throws \UnexpectedValueException If the element is not a relative OID @return \ASN1\Type\Primitive\RelativeOID
entailment
public function asSequence(): Constructed\Sequence { if (!$this->_element instanceof Constructed\Sequence) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_SEQUENCE)); } return $this->_element; }
Get the wrapped element as a sequence type. @throws \UnexpectedValueException If the element is not a sequence @return \ASN1\Type\Constructed\Sequence
entailment
public function asSet(): Constructed\Set { if (!$this->_element instanceof Constructed\Set) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_SET)); } return $this->_element; }
Get the wrapped element as a set type. @throws \UnexpectedValueException If the element is not a set @return \ASN1\Type\Constructed\Set
entailment
public function asNumericString(): Primitive\NumericString { if (!$this->_element instanceof Primitive\NumericString) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_NUMERIC_STRING)); } return $this->_element; }
Get the wrapped element as a numeric string type. @throws \UnexpectedValueException If the element is not a numeric string @return \ASN1\Type\Primitive\NumericString
entailment
public function asPrintableString(): Primitive\PrintableString { if (!$this->_element instanceof Primitive\PrintableString) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_PRINTABLE_STRING)); } return $this->_element; }
Get the wrapped element as a printable string type. @throws \UnexpectedValueException If the element is not a printable string @return \ASN1\Type\Primitive\PrintableString
entailment
public function asT61String(): Primitive\T61String { if (!$this->_element instanceof Primitive\T61String) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_T61_STRING)); } return $this->_element; }
Get the wrapped element as a T61 string type. @throws \UnexpectedValueException If the element is not a T61 string @return \ASN1\Type\Primitive\T61String
entailment
public function asVideotexString(): Primitive\VideotexString { if (!$this->_element instanceof Primitive\VideotexString) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_VIDEOTEX_STRING)); } return $this->_element; }
Get the wrapped element as a videotex string type. @throws \UnexpectedValueException If the element is not a videotex string @return \ASN1\Type\Primitive\VideotexString
entailment
public function asIA5String(): Primitive\IA5String { if (!$this->_element instanceof Primitive\IA5String) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_IA5_STRING)); } return $this->_element; }
Get the wrapped element as a IA5 string type. @throws \UnexpectedValueException If the element is not a IA5 string @return \ASN1\Type\Primitive\IA5String
entailment
public function asUTCTime(): Primitive\UTCTime { if (!$this->_element instanceof Primitive\UTCTime) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_UTC_TIME)); } return $this->_element; }
Get the wrapped element as an UTC time type. @throws \UnexpectedValueException If the element is not a UTC time @return \ASN1\Type\Primitive\UTCTime
entailment
public function asGeneralizedTime(): Primitive\GeneralizedTime { if (!$this->_element instanceof Primitive\GeneralizedTime) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_GENERALIZED_TIME)); } return $this->_element; }
Get the wrapped element as a generalized time type. @throws \UnexpectedValueException If the element is not a generalized time @return \ASN1\Type\Primitive\GeneralizedTime
entailment
public function asGraphicString(): Primitive\GraphicString { if (!$this->_element instanceof Primitive\GraphicString) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_GRAPHIC_STRING)); } return $this->_element; }
Get the wrapped element as a graphic string type. @throws \UnexpectedValueException If the element is not a graphic string @return \ASN1\Type\Primitive\GraphicString
entailment
public function asVisibleString(): Primitive\VisibleString { if (!$this->_element instanceof Primitive\VisibleString) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_VISIBLE_STRING)); } return $this->_element; }
Get the wrapped element as a visible string type. @throws \UnexpectedValueException If the element is not a visible string @return \ASN1\Type\Primitive\VisibleString
entailment
public function asGeneralString(): Primitive\GeneralString { if (!$this->_element instanceof Primitive\GeneralString) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_GENERAL_STRING)); } return $this->_element; }
Get the wrapped element as a general string type. @throws \UnexpectedValueException If the element is not general string @return \ASN1\Type\Primitive\GeneralString
entailment
public function asUniversalString(): Primitive\UniversalString { if (!$this->_element instanceof Primitive\UniversalString) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_UNIVERSAL_STRING)); } return $this->_element; }
Get the wrapped element as a universal string type. @throws \UnexpectedValueException If the element is not a universal string @return \ASN1\Type\Primitive\UniversalString
entailment
public function asCharacterString(): Primitive\CharacterString { if (!$this->_element instanceof Primitive\CharacterString) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_CHARACTER_STRING)); } return $this->_element; }
Get the wrapped element as a character string type. @throws \UnexpectedValueException If the element is not a character string @return \ASN1\Type\Primitive\CharacterString
entailment
public function asBMPString(): Primitive\BMPString { if (!$this->_element instanceof Primitive\BMPString) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_BMP_STRING)); } return $this->_element; }
Get the wrapped element as a BMP string type. @throws \UnexpectedValueException If the element is not a bmp string @return \ASN1\Type\Primitive\BMPString
entailment
public function asString(): StringType { if (!$this->_element instanceof StringType) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_STRING)); } return $this->_element; }
Get the wrapped element as any string type. @throws \UnexpectedValueException If the element is not a string @return StringType
entailment
public function asTime(): TimeType { if (!$this->_element instanceof TimeType) { throw new \UnexpectedValueException( $this->_generateExceptionMessage(Element::TYPE_TIME)); } return $this->_element; }
Get the wrapped element as any time type. @throws \UnexpectedValueException If the element is not a time @return TimeType
entailment
private function _generateExceptionMessage(int $tag): string { return sprintf("%s expected, got %s.", Element::tagToName($tag), $this->_typeDescriptorString()); }
Generate message for exceptions thrown by <code>as*</code> methods. @param int $tag Type tag of the expected element @return string
entailment
private function _typeDescriptorString(): string { $type_cls = $this->_element->typeClass(); $tag = $this->_element->tag(); if ($type_cls == Identifier::CLASS_UNIVERSAL) { return Element::tagToName($tag); } return Identifier::classToName($type_cls) . " TAG $tag"; }
Get textual description of the wrapped element for debugging purposes. @return string
entailment
public function handle() { // setup $this->setSettings(); $this->getResourceName($this->getUrl(false)); // check the path where to create and save file $path = $this->getPath(''); if ($this->files->exists($path) && $this->optionForce() === false) { return $this->error($this->type . ' already exists!'); } // make all the directories $this->makeDirectory($path); // build file and save it at location $this->files->put($path, $this->buildClass($this->argumentName())); // output to console $this->info(ucfirst($this->option('type')) . ' created successfully.'); $this->info('- ' . $path); // if we need to run "composer dump-autoload" if ($this->settings['dump_autoload'] === true) { if ($this->confirm("Run 'composer dump-autoload'?")) { $this->composer->dumpAutoloads(); } } }
Execute the console command. @return void
entailment
protected function buildClass($name) { $stub = $this->files->get($this->getStub()); // examples used for the placeholders is for 'foo.bar' // App\Foo $stub = str_replace('{{namespace}}', $this->getNamespace($name), $stub); // App\ $stub = str_replace('{{rootNamespace}}', $this->getAppNamespace(), $stub); // Bar $stub = str_replace('{{class}}', $this->getClassName(), $stub); $url = $this->getUrl(); // /foo/bar // /foo/bar $stub = str_replace('{{url}}', $this->getUrl(), $stub); // bars $stub = str_replace('{{collection}}', $this->getCollectionName(), $stub); // Bars $stub = str_replace('{{collectionUpper}}', $this->getCollectionUpperName(), $stub); // Bar $stub = str_replace('{{model}}', $this->getModelName(), $stub); // Bar $stub = str_replace('{{resource}}', $this->resource, $stub); // bar $stub = str_replace('{{resourceLowercase}}', $this->resourceLowerCase, $stub); // ./resources/views/foo/bar.blade.php $stub = str_replace('{{path}}', $this->getPath(''), $stub); // foos.bars $stub = str_replace('{{view}}', $this->getViewPath($this->getUrl(false)), $stub); // foos.bars (remove admin or website if first word) $stub = str_replace('{{viewPath}}', $this->getViewPathFormatted($this->getUrl(false)), $stub); // bars $stub = str_replace('{{table}}', $this->getTableName($url), $stub); // console command name $stub = str_replace('{{command}}', $this->option('command'), $stub); // contract file name $stub = str_replace('{{contract}}', $this->getContractName(), $stub); // contract namespace $stub = str_replace('{{contractNamespace}}', $this->getContractNamespace(), $stub); return $stub; }
Build the class with the given name. @param string $name @return string
entailment
private static function _encodePositiveInteger(\GMP $num): string { $bin = gmp_export($num, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN); // if first bit is 1, prepend full zero byte // to represent positive two's complement if (ord($bin[0]) & 0x80) { $bin = chr(0x00) . $bin; } return $bin; }
Encode positive integer to DER content. @param \GMP $num @return string
entailment
private static function _encodeNegativeInteger(\GMP $num): string { $num = gmp_abs($num); // compute number of bytes required $width = 1; if ($num > 128) { $tmp = $num; do { $width++; $tmp >>= 8; } while ($tmp > 128); } // compute two's complement 2^n - x $num = gmp_pow("2", 8 * $width) - $num; $bin = gmp_export($num, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN); // if first bit is 0, prepend full inverted byte // to represent negative two's complement if (!(ord($bin[0]) & 0x80)) { $bin = chr(0xff) . $bin; } return $bin; }
Encode negative integer to DER content. @param \GMP $num @return string
entailment
private static function _validateNumber($num): bool { if (is_int($num)) { return true; } if (is_string($num) && preg_match('/-?\d+/', $num)) { return true; } return false; }
Test that number is valid for this context. @param mixed $num @return bool
entailment
public function boot() { $this->loadTranslationsFrom(__DIR__ . '/../lang', 'image-validator'); $messages = trans('image-validator::validation'); $this->app->bind(ImageValidator::class, function($app) use ($messages) { $validator = new ImageValidator($app['translator'], [], [], $messages); if (isset($app['validation.presence'])) { $validator->setPresenceVerifier($app['validation.presence']); } return $validator; }); $this->addNewRules(); }
Bootstrap the application events. @return void
entailment
protected function extendValidator($rule) { $method = studly_case($rule); $translation = $this->app['translator']->trans('image-validator::validation.' . $rule); $this->app['validator']->extend($rule, 'Cviebrock\ImageValidator\ImageValidator@validate' . $method, $translation); $this->app['validator']->replacer($rule, 'Cviebrock\ImageValidator\ImageValidator@replace' . $method); }
Extend the validator with new rules. @param string $rule @return void
entailment
public function add($subaccount_username, $subaccount_password, $subaccount_id, $params = array()) { $params = array_merge(array( 'subaccount_username' => $subaccount_username, 'subaccount_password' => $subaccount_password, 'subaccount_id' => $subaccount_id ), $params); return $this->master->call('subaccounts/add', $params); }
Creating new subaccount @param string $subaccount_username @param string $subaccount_password @param int $subaccount_id Subaccount ID, which is template of powers @param object $params @option string "name" @option string "phone" @option string "email" @return type
entailment
public function limit($id, $type, $value) { $params = array( 'id' => $id, 'type' => $type, 'value' => $value ); return $this->master->call('subaccounts/limit', $params); }
Setting the limit on subaccount @param int $id @param string $type Message type: eco|full|voice|mms|hlr @param int $value @return object @option bool "success" @option int "id"
entailment
public static function fromDER(string $data, int &$offset = null): Identifier { $idx = $offset ?? 0; $datalen = strlen($data); if ($idx >= $datalen) { throw new DecodeException("Invalid offset."); } $byte = ord($data[$idx++]); // bits 8 and 7 (class) // 0 = universal, 1 = application, 2 = context-specific, 3 = private $class = (0b11000000 & $byte) >> 6; // bit 6 (0 = primitive / 1 = constructed) $pc = (0b00100000 & $byte) >> 5; // bits 5 to 1 (tag number) $tag = (0b00011111 & $byte); // long-form identifier if (0x1f == $tag) { $tag = self::_decodeLongFormTag($data, $idx); } if (isset($offset)) { $offset = $idx; } return new self($class, $pc, $tag); }
Decode identifier component from DER data. @param string $data DER encoded data @param int|null $offset Reference to the variable that contains offset into the data where to start parsing. Variable is updated to the offset next to the parsed identifier. If null, start from offset 0. @throws DecodeException If decoding fails @return self
entailment
private static function _decodeLongFormTag(string $data, int &$offset): string { $datalen = strlen($data); $tag = gmp_init(0, 10); while (true) { if ($offset >= $datalen) { throw new DecodeException( "Unexpected end of data while decoding" . " long form identifier."); } $byte = ord($data[$offset++]); $tag <<= 7; $tag |= 0x7f & $byte; // last byte has bit 8 set to zero if (!(0x80 & $byte)) { break; } } return gmp_strval($tag, 10); }
Parse long form tag. @param string $data DER data @param int $offset Reference to the variable containing offset to data @throws DecodeException If decoding fails @return string Tag number
entailment
public function withTag($tag): Identifier { $obj = clone $this; $obj->_tag = new BigInt($tag); return $obj; }
Get self with given type tag. @param int|string $tag Tag number @return self
entailment
public function add($name, $text) { $params = array( 'name' => $name, 'text' => $text ); return $this->master->call('templates/add', $params); }
Adding new template @param string $name @param string $text @return object @option object @option bool "success" @option int "id"
entailment
public function getCdrResponse($xml) { $this->reader->loadXpath($xml); $cdr = $this->createCdr(); return $cdr; }
Get Cdr using DomDocument. @param string $xml @return CdrResponse
entailment
private function getNotes() { $xpath = $this->reader->getXpath(); $nodes = $xpath->query($this->reader->getRoot().'/cbc:Note'); $notes = []; if ($nodes->length === 0) { return $notes; } /** @var \DOMElement $node */ foreach ($nodes as $node) { $notes[] = $node->nodeValue; } return $notes; }
Get Notes if exist. @return string[]
entailment
public function getType($value) { $doc = $this->reader->parseToDocument($value); $name = $doc->documentElement->localName; switch ($name) { case 'Invoice': return Invoice::class; case 'CreditNote': case 'DebitNote': return Note::class; case 'Perception': return Perception::class; case 'Retention': return Retention::class; case 'SummaryDocuments': return Summary::class; case 'VoidedDocuments': $this->reader->loadXpathFromDoc($doc); $id = $this->reader->getValue('cbc:ID'); return 'RA' === substr($id, 0, 2) ? Voided::class : Reversion::class; } return ''; }
@param \DOMDocument|string $value @return string
entailment
protected function argumentName() { if ($this->settings) { return str_replace($this->settings['postfix'], '', $this->argument('name')); } return $this->argument('name'); }
Get the argument name of the file that needs to be generated If settings exist, remove the postfix from the file
entailment
public function send($filename, $content) { $client = $this->getClient(); $result = new BillResult(); try { $zipContent = $this->compress($filename.'.xml', $content); $params = [ 'fileName' => $filename.'.zip', 'contentFile' => $zipContent, ]; $response = $client->call('sendBill', ['parameters' => $params]); $cdrZip = $response->applicationResponse; $result ->setCdrResponse($this->extractResponse($cdrZip)) ->setCdrZip($cdrZip) ->setSuccess(true); } catch (\SoapFault $e) { $result->setError($this->getErrorFromFault($e)); } return $result; }
@param string $filename @param string $content @return BillResult
entailment
public function add($type, $params) { $params = array_merge(array('type' => $type), $params); return $this->master->call('files/add', $params); }
Add new file @param string $type - mms|voice @param array $params @option string "url" URL address to file @option resource "file" A file handler (only for MMS) @return object @option bool "success" @option string "id"
entailment
public function view($id, $type) { $params = array( 'id' => $id, 'type' => $type ); return $this->master->call('files/view', $params); }
View file @param string $id @param string $type - mms|voice @return object @option string "id" @option string "name" @option int "size" @option string "type" - mms|voice @option string "date"
entailment
public function delete($id, $type) { $params = array( 'id' => $id, 'type' => $type ); return $this->master->call('files/delete', $params); }
Deleting a file @param string $id @param string $type - mms|voice @return object @option bool "success"
entailment
public function getFilename($content) { $doc = $this->reader->parseToDocument($content); $this->reader->loadXpathFromDoc($doc); $nameType = $doc->documentElement->localName; $ruc = $this->getRuc($nameType); $document = $this->reader->getValue('cbc:ID'); $type = $this->getTypeFromDoc($nameType); if (empty($type)) { return $ruc.self::CONCAT_CHR.$document; } return implode(self::CONCAT_CHR, [$ruc, $type, $document]); }
@param \DOMDocument|string $content @return string @throws \Exception
entailment
public function setSettings() { $type = $this->option('type'); $options = config('generators.settings'); $found = false; // loop through the settings and find the type key foreach ($options as $key => $settings) { if ($type == $key) { $found = true; break; } } if ($found === false) { $this->error('Oops!, no settings key by the type name provided'); exit; } // set the default keys and values if they do not exist $defaults = config('generators.defaults'); foreach ($defaults as $key => $value) { if (!isset($settings[$key])) { $settings[$key] = $defaults[$key]; } } $this->settings = $settings; }
Find the type's settings and set local var
entailment
public function settingsKey($key) { if (is_array($this->settings) == false || isset($this->settings[$key]) == false) { return false; } return $this->settings[$key]; }
Return false or the value for given key from the settings @param $key @return bool
entailment
public static function fromBitString(BitString $bs, int $width): self { $num_bits = $bs->numBits(); $num = gmp_import($bs->string(), 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN); $num >>= $bs->unusedBits(); if ($num_bits < $width) { $num <<= ($width - $num_bits); } return new self(gmp_strval($num, 10), $width); }
Initialize from BitString. @param BitString $bs @param int $width @return self
entailment
public function number(): string { $num = gmp_import($this->_flags, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN); $last_octet_bits = $this->_width % 8; $unused_bits = $last_octet_bits ? 8 - $last_octet_bits : 0; $num >>= $unused_bits; return gmp_strval($num, 10); }
Get flags as a base 10 integer. @return string Integer as a string
entailment
public function bitString(): BitString { $last_octet_bits = $this->_width % 8; $unused_bits = $last_octet_bits ? 8 - $last_octet_bits : 0; return new BitString($this->_flags, $unused_bits); }
Get flags as a BitString. Unused bits are set accordingly. Trailing zeroes are not stripped. @return BitString
entailment
public static function fromDER(string $data, int &$offset = null): self { $idx = $offset ?? 0; $datalen = strlen($data); if ($idx >= $datalen) { throw new DecodeException( "Unexpected end of data while decoding length."); } $indefinite = false; $byte = ord($data[$idx++]); // bits 7 to 1 $length = (0x7f & $byte); // long form if (0x80 & $byte) { if (!$length) { $indefinite = true; } else { if ($idx + $length > $datalen) { throw new DecodeException( "Unexpected end of data while decoding long form length."); } $length = self::_decodeLongFormLength($length, $data, $idx); } } if (isset($offset)) { $offset = $idx; } return new self($length, $indefinite); }
Decode length component from DER data. @param string $data DER encoded data @param int|null $offset Reference to the variable that contains offset into the data where to start parsing. Variable is updated to the offset next to the parsed length component. If null, start from offset 0. @throws DecodeException If decoding fails @return self
entailment
private static function _decodeLongFormLength(int $length, string $data, int &$offset): string { // first octet must not be 0xff (spec 8.1.3.5c) if ($length == 127) { throw new DecodeException("Invalid number of length octets."); } $num = gmp_init(0, 10); while (--$length >= 0) { $byte = ord($data[$offset++]); $num <<= 8; $num |= $byte; } return gmp_strval($num); }
Decode long form length. @param int $length Number of octets @param string $data Data @param int $offset Reference to the variable containing offset to the data. @throws DecodeException If decoding fails @return string Integer as a string
entailment
public static function expectFromDER(string $data, int &$offset, int $expected = null): self { $idx = $offset; $length = self::fromDER($data, $idx); // if certain length was expected if (isset($expected)) { if ($length->isIndefinite()) { throw new DecodeException('Expected length %d, got indefinite.', $expected); } if ($expected != $length->intLength()) { throw new DecodeException( sprintf("Expected length %d, got %d.", $expected, $length->intLength())); } } // check that enough data is available if (!$length->isIndefinite() && strlen($data) < $idx + $length->intLength()) { throw new DecodeException( sprintf("Length %d overflows data, %d bytes left.", $length->intLength(), strlen($data) - $idx)); } $offset = $idx; return $length; }
Decode length from DER. Throws an exception if length doesn't match with expected or if data doesn't contain enough bytes. Requirement of definite length is relaxed contrary to the specification (sect. 10.1). @see self::fromDER @param string $data DER data @param int $offset Reference to the offset variable @param int|null $expected Expected length, null to bypass checking @throws DecodeException If decoding or expectation fails @return self
entailment
public function send($phone, $text, $gate, $id) { $params = array( 'phone' => $phone, 'text' => $text, 'gate' => $gate, 'id' => $id ); return $this->master->call('premium/send', $params); }
Sending replies for received SMS Premium @param string $phone @param string $text Message @param string $gate Premium number @param int $id ID received SMS Premium @return object @option bool "success"
entailment
public function edit($id, $name) { $params = array( 'id' => $id, 'name' => $name ); return $this->master->call('groups/edit', $params); }
Editing a group @param int $id @param string $name @return object @option bool "success" @option int "id"
entailment
protected static function _decodeFromDER(Identifier $identifier, string $data, int &$offset): ElementBase { throw new \BadMethodCallException( __METHOD__ . " must be implemented in derived class."); }
Decode type-specific element from DER. @param Identifier $identifier Pre-parsed identifier @param string $data DER data @param int $offset Offset in data to the next byte after identifier @throws DecodeException If decoding fails @return ElementBase
entailment
public static function fromDER(string $data, int &$offset = null): ElementBase { $idx = $offset ?? 0; // decode identifier $identifier = Identifier::fromDER($data, $idx); // determine class that implements type specific decoding $cls = self::_determineImplClass($identifier); try { // decode remaining element $element = $cls::_decodeFromDER($identifier, $data, $idx); } catch (\LogicException $e) { // rethrow as a RuntimeException for unified exception handling throw new DecodeException( sprintf("Error while decoding %s.", self::tagToName($identifier->intTag())), 0, $e); } // if called in the context of a concrete class, check // that decoded type matches the type of a calling class $called_class = get_called_class(); if (self::class != $called_class) { if (!$element instanceof $called_class) { throw new \UnexpectedValueException( sprintf("%s expected, got %s.", $called_class, get_class($element))); } } // update offset for the caller if (isset($offset)) { $offset = $idx; } return $element; }
Decode element from DER data. @param string $data DER encoded data @param int|null $offset Reference to the variable that contains offset into the data where to start parsing. Variable is updated to the offset next to the parsed element. If null, start from offset 0. @throws DecodeException If decoding fails @throws \UnexpectedValueException If called in the context of an expected type, but decoding yields another type @return ElementBase
entailment
private function _isConcreteType(int $tag): bool { // if tag doesn't match if ($this->tag() != $tag) { return false; } // if type is universal check that instance is of a correct class if ($this->typeClass() == Identifier::CLASS_UNIVERSAL) { $cls = self::_determineUniversalImplClass($tag); if (!$this instanceof $cls) { return false; } } return true; }
Check whether the element is a concrete type of a given tag. @param int $tag @return bool
entailment
private function _isPseudoType(int $tag): bool { switch ($tag) { case self::TYPE_STRING: return $this instanceof StringType; case self::TYPE_TIME: return $this instanceof TimeType; } return false; }
Check whether the element is a pseudotype. @param int $tag @return bool
entailment
public function withIndefiniteLength(bool $indefinite = true): self { $obj = clone $this; $obj->_indefiniteLength = $indefinite; return $obj; }
Get self with indefinite length encoding set. @param bool $indefinite True for indefinite length, false for definite length @return self
entailment
protected static function _determineImplClass(Identifier $identifier): string { switch ($identifier->typeClass()) { case Identifier::CLASS_UNIVERSAL: return self::_determineUniversalImplClass($identifier->intTag()); case Identifier::CLASS_CONTEXT_SPECIFIC: return ContextSpecificType::class; case Identifier::CLASS_APPLICATION: return ApplicationType::class; case Identifier::CLASS_PRIVATE: return PrivateType::class; } throw new \UnexpectedValueException( sprintf("%s %d not implemented.", Identifier::classToName($identifier->typeClass()), $identifier->tag())); }
Determine the class that implements the type. @param Identifier $identifier @return string Class name
entailment