Realiza el parse de un string para traducirlo
validators.sale.registration.code_quantity_min::{"%n%":2}::validators seria un ejemplo
validators.sale.registration.code_quantity_min::{}::validators seria un ejemplo
@param type $id
160842
protected function parseTrans($id, array $parameters = [], $domain = "flashes") {
        $text = $id;
        $separator = "::";
        $subSeparator = ";;";

        $textExplode = explode($separator, $id);
        if (is_array($textExplode)) {
            //id a traducir
            if (isset($textExplode[0])) {
                $text = $textExplode[0];
            }
            //Parametros de la traduccion
            if (isset($textExplode[1])) {
                $paramsString = $textExplode[1];
//                var_dump($paramsString);
                $parametersParsed = json_decode($paramsString, true);
                if (is_array($parametersParsed)) {
                    $this->parseScenarioParameters($parametersParsed);
                    foreach ($parametersParsed as $x => $v) {
                        if (strpos($v, $subSeparator) !== false) {
                            $v = str_replace($subSeparator, $separator, $v);
                            $parametersParsed[$x] = $this->parseTrans($v);
                        }
                    }
//                    var_dump($parametersParsed);
                    $parameters = $parametersParsed;
                }
            }
            //Dominio e la traduccion
            if (isset($textExplode[2])) {
                $domain = $textExplode[2];
            }
        }
        if (strpos($text, "|") && isset($parameters["{{ limit }}"])) {
            $trans = $this->container->get('translator')->transChoice($text, (int) $parameters["{{ limit }}"], $parameters, $domain);
        } else {
            $trans = $this->trans($text, $parameters, $domain);
        }
        return $trans;
    }
1183274
public function canDeleteLanguage($id)
    {
        $query = $this->dbHandler->createSelectQuery();
        $query->select(
            $query->alias($query->expr->count('*'), 'count')
        )->from(
            $this->dbHandler->quoteTable('ezcobj_state')
        )->where(
            $query->expr->lOr(
                $query->expr->eq(
                    $this->dbHandler->quoteColumn('default_language_id'),
                    $query->bindValue($id, null, \PDO::PARAM_INT)
                ),
                $query->expr->gt(
                    $query->expr->bitAnd(
                        $this->dbHandler->quoteColumn('language_mask'),
                        $query->bindValue($id, null, \PDO::PARAM_INT)
                    ),
                    0
                )
            )
        );

        $statement = $query->prepare();
        $statement->execute();

        if ($statement->fetchColumn() > 0) {
            return false;
        }

        $query = $this->dbHandler->createSelectQuery();
        $query->select(
            $query->alias($query->expr->count('*'), 'count')
        )->from(
            $this->dbHandler->quoteTable('ezcobj_state_group')
        )->where(
            $query->expr->lOr(
                $query->expr->eq(
                    $this->dbHandler->quoteColumn('default_language_id'),
                    $query->bindValue($id, null, \PDO::PARAM_INT)
                ),
                $query->expr->gt(
                    $query->expr->bitAnd(
                        $this->dbHandler->quoteColumn('language_mask'),
                        $query->bindValue($id, null, \PDO::PARAM_INT)
                    ),
                    0
                )
            )
        );

        $statement = $query->prepare();
        $statement->execute();

        if ($statement->fetchColumn() > 0) {
            return false;
        }

        $query = $this->dbHandler->createSelectQuery();
        $query->select(
            $query->alias($query->expr->count('*'), 'count')
        )->from(
            $this->dbHandler->quoteTable('ezcobj_state_group_language')
        )->where(
            $query->expr->gt(
                $query->expr->bitAnd(
                    $this->dbHandler->quoteColumn('language_id'),
                    $query->bindValue($id, null, \PDO::PARAM_INT)
                ),
                0
            )
        );

        $statement = $query->prepare();
        $statement->execute();

        if ($statement->fetchColumn() > 0) {
            return false;
        }

        $query = $this->dbHandler->createSelectQuery();
        $query->select(
            $query->alias($query->expr->count('*'), 'count')
        )->from(
            $this->dbHandler->quoteTable('ezcobj_state_language')
        )->where(
            $query->expr->gt(
                $query->expr->bitAnd(
                    $this->dbHandler->quoteColumn('language_id'),
                    $query->bindValue($id, null, \PDO::PARAM_INT)
                ),
                0
            )
        );

        $statement = $query->prepare();
        $statement->execute();

        if ($statement->fetchColumn() > 0) {
            return false;
        }

        $query = $this->dbHandler->createSelectQuery();
        $query->select(
            $query->alias($query->expr->count('*'), 'count')
        )->from(
            $this->dbHandler->quoteTable('ezcontentclass')
        )->where(
            $query->expr->lOr(
                $query->expr->eq(
                    $this->dbHandler->quoteColumn('initial_language_id'),
                    $query->bindValue($id, null, \PDO::PARAM_INT)
                ),
                $query->expr->gt(
                    $query->expr->bitAnd(
                        $this->dbHandler->quoteColumn('language_mask'),
                        $query->bindValue($id, null, \PDO::PARAM_INT)
                    ),
                    0
                )
            )
        );

        $statement = $query->prepare();
        $statement->execute();

        if ($statement->fetchColumn() > 0) {
            return false;
        }

        $query = $this->dbHandler->createSelectQuery();
        $query->select(
            $query->alias($query->expr->count('*'), 'count')
        )->from(
            $this->dbHandler->quoteTable('ezcontentclass_name')
        )->where(
            $query->expr->gt(
                $query->expr->bitAnd(
                    $this->dbHandler->quoteColumn('language_id'),
                    $query->bindValue($id, null, \PDO::PARAM_INT)
                ),
                0
            )
        );

        $statement = $query->prepare();
        $statement->execute();

        if ($statement->fetchColumn() > 0) {
            return false;
        }

        $query = $this->dbHandler->createSelectQuery();
        $query->select(
            $query->alias($query->expr->count('*'), 'count')
        )->from(
            $this->dbHandler->quoteTable('ezcontentobject')
        )->where(
            $query->expr->lOr(
                $query->expr->eq(
                    $this->dbHandler->quoteColumn('initial_language_id'),
                    $query->bindValue($id, null, \PDO::PARAM_INT)
                ),
                $query->expr->gt(
                    $query->expr->bitAnd(
                        $this->dbHandler->quoteColumn('language_mask'),
                        $query->bindValue($id, null, \PDO::PARAM_INT)
                    ),
                    0
                )
            )
        );

        $statement = $query->prepare();
        $statement->execute();

        if ($statement->fetchColumn() > 0) {
            return false;
        }

        $query = $this->dbHandler->createSelectQuery();
        $query->select(
            $query->alias($query->expr->count('*'), 'count')
        )->from(
            $this->dbHandler->quoteTable('ezcontentobject_attribute')
        )->where(
            $query->expr->gt(
                $query->expr->bitAnd(
                    $this->dbHandler->quoteColumn('language_id'),
                    $query->bindValue($id, null, \PDO::PARAM_INT)
                ),
                0
            )
        );

        $statement = $query->prepare();
        $statement->execute();

        if ($statement->fetchColumn() > 0) {
            return false;
        }

        $query = $this->dbHandler->createSelectQuery();
        $query->select(
            $query->alias($query->expr->count('*'), 'count')
        )->from(
            $this->dbHandler->quoteTable('ezcontentobject_name')
        )->where(
            $query->expr->gt(
                $query->expr->bitAnd(
                    $this->dbHandler->quoteColumn('language_id'),
                    $query->bindValue($id, null, \PDO::PARAM_INT)
                ),
                0
            )
        );

        $statement = $query->prepare();
        $statement->execute();

        if ($statement->fetchColumn() > 0) {
            return false;
        }

        $query = $this->dbHandler->createSelectQuery();
        $query->select(
            $query->alias($query->expr->count('*'), 'count')
        )->from(
            $this->dbHandler->quoteTable('ezcontentobject_version')
        )->where(
            $query->expr->lOr(
                $query->expr->eq(
                    $this->dbHandler->quoteColumn('initial_language_id'),
                    $query->bindValue($id, null, \PDO::PARAM_INT)
                ),
                $query->expr->gt(
                    $query->expr->bitAnd(
                        $this->dbHandler->quoteColumn('language_mask'),
                        $query->bindValue($id, null, \PDO::PARAM_INT)
                    ),
                    0
                )
            )
        );

        $statement = $query->prepare();
        $statement->execute();

        if ($statement->fetchColumn() > 0) {
            return false;
        }

        $query = $this->dbHandler->createSelectQuery();
        $query->select(
            $query->alias($query->expr->count('*'), 'count')
        )->from(
            $this->dbHandler->quoteTable('ezurlalias_ml')
        )->where(
            $query->expr->gt(
                $query->expr->bitAnd(
                    $this->dbHandler->quoteColumn('lang_mask'),
                    $query->bindValue($id, null, \PDO::PARAM_INT)
                ),
                0
            )
        );

        $statement = $query->prepare();
        $statement->execute();

        return $statement->fetchColumn() == 0;
    }
490481
public function id($id)
    {
        $parts = array_merge(array($this->namespace), func_get_args());
        return trim(implode(self::$namespaceSeparator, $parts), self::$namespaceSeparator);
    }
1096507
function card($id) {
		$id=preg_replace('/[^\d]/','',$id);
		if ($this->mod10($id)) {
			if (preg_match('/^3[47][0-9]{13}$/',$id))
				return 'American Express';
			if (preg_match('/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/',$id))
				return 'Diners Club';
			if (preg_match('/^6(?:011|5[0-9][0-9])[0-9]{12}$/',$id))
				return 'Discover';
			if (preg_match('/^(?:2131|1800|35\d{3})\d{11}$/',$id))
				return 'JCB';
			if (preg_match('/^5[1-5][0-9]{14}$|'.
				'^(222[1-9]|2[3-6]\d{2}|27[0-1]\d|2720)\d{12}$/',$id))
				return 'MasterCard';
			if (preg_match('/^4[0-9]{12}(?:[0-9]{3})?$/',$id))
				return 'Visa';
		}
		return FALSE;
	}
839355
public function edit(string $id = null)
    {
        $translation = $this->Translations->get($id, [
            'contain' => ['Languages']
        ]);
        if ($this->request->is(['patch', 'post', 'put'])) {
            $data = is_array($this->request->getData()) ? $this->request->getData() : [];
            $translation = $this->Translations->patchEntity($translation, $data);
            if ($this->Translations->save($translation)) {
                $this->Flash->success((string)__('The translation has been saved.'));

                return $this->redirect(['action' => 'index']);
            }
            $this->Flash->error((string)__('The translation could not be saved. Please, try again.'));
        }
        $languages = $this->Translations->Languages->find('list', ['limit' => 200]);
        $this->set(compact('translation', 'languages'));
        $this->set('_serialize', ['translation']);
    }
361605
function counter_value($id = self::DEFAULT_COUNTER, $type = "decimal") {
    $type = mb_strtolower($type);
    
    if ( !isset($this->_counters[$id]) ) {
      $value = $this->_counters[$id] = 0;
    }
    else {
      $value = $this->_counters[$id];
    }
    
    switch ($type) {

    default:
    case "decimal":
      return $value;

    case "decimal-leading-zero":
      return str_pad($value, 2, "0");

    case "lower-roman":
      return dec2roman($value);

    case "upper-roman":
      return mb_strtoupper(dec2roman($value));

    case "lower-latin":
    case "lower-alpha":
      return chr( ($value % 26) + ord('a') - 1);

    case "upper-latin":
    case "upper-alpha":
      return chr( ($value % 26) + ord('A') - 1);

    case "lower-greek":
      return unichr($value + 944);

    case "upper-greek":
      return unichr($value + 912);
    }
  }
629262
public function transChoice(
        $id,
        $number,
        array $parameters = [],
        $domain = null,
        $locale = null
    ) {
        $domain = $domain ?? $this->config->getDefaultDomain();
        $locale = $locale ?? $this->locale;

        try {
            $message = $this->get($locale, $domain, $id);

            $pluralized = $this->identityTranslator->trans(
                $message,
                ['%count%' => $number],
                null,
                $locale
            );
        } catch (\InvalidArgumentException $e) {
            //Wrapping into more explanatory exception
            throw new PluralizationException($e->getMessage(), $e->getCode(), $e);
        }

        if (empty($parameters['n']) && is_numeric($number)) {
            $parameters['n'] = $number;
        }

        return self::interpolate($pluralized, $parameters);
    }
147288
function calcular_total($id = null){
		if (!empty($id)) $this->id = $id;

		$subtotal = $this->calcular_subtotal();
		$totalPorcentajeDescuento = $this->calcular_descuentos();

		$conversionDescuento = 1-($totalPorcentajeDescuento/100);

		$total = cqs_round(  $subtotal * $conversionDescuento );

		return $total;
	}
184803
public function validateId($id)
    {
        if (null === $id) {
            throw new \InvalidArgumentException('Category id missing');
        } elseif (!is_numeric($id) || (int)$id != $id) {
            throw new \InvalidArgumentException('Invalid data type for category id');
        }
    }
913433
protected function parserValidationRules($rules, $id = null)
    {

        if($id === null)
        {
            return $rules;
        }

        array_walk($rules, function(&$rules, $field) use ($id)
        {
            if(!is_array($rules))
            {
                $rules = explode("|", $rules);
            }

            foreach($rules as $ruleIdx => $rule)
            {
                // get name and parameters
                @list($name, $params) = array_pad(explode(":", $rule), 2, null);

                // only do someting for the unique rule
                if(strtolower($name) != "unique") {
                    continue; // continue in foreach loop, nothing left to do here
                }

                $p = array_map("trim", explode(",", $params));

                // set field name to rules key ($field) (laravel convention)
                if(!isset($p[1])) {
                    $p[1] = $field;
                }

                // set 3rd parameter to id given to getValidationRules()
                $p[2] = $id;

                $params = implode(",", $p);
                $rules[$ruleIdx] = $name.":".$params;
            }
        });

        return $rules;
    }
508748
public function define($id, $type)
    {
        $id = (string) $id;

        $this->validateName($id);

        if ($type[0] == ':') {
            $expectedType = substr($type, 1);
            $allowedTypes = (array) $this->getAllowedTypes();
            if (!in_array($expectedType, $allowedTypes)) {
                throw new InvalidArgumentException(sprintf('Cannot use type %s to define item "%s" in %s container. Allowed types are: %s.',
                    $expectedType, $id, $this->name, join(', ', $allowedTypes)));
            }
        } else {
            if (!class_exists($type)) {
                throw new InvalidArgumentException(sprintf('Cannot use non-existing class %s as type to define item "%s" in %s container.',
                    $type, $id, $this->name));
            }
        }

        $this->typemap[$id] = $type;
    }
1309480
public function encode($id, $type = '')
    {
        if (!isset($this->_keys[$type])) {
            if ($this->_key === null) {
                $this->_key = $this->crypt->getDerivedKey('secint');
            }

            $this->_keys[$type] = md5($this->_key . $type, true);
        }

        while (true) {
            $rand = mt_rand() & 0xFFFF0000;
            $r = base64_encode(mcrypt_encrypt(MCRYPT_XTEA, $this->_keys[$type], pack('VV', $id, $rand), MCRYPT_MODE_ECB));
            if (strcspn($r, '+/') === 12) {
                return substr($r, 0, -1);
            }
        }

        return $id;
    }
503014
public function isValid($id)
    {
        // 基础验证
        $code = $this->_checkIdArgument($id);
        if (empty($code)) {
            return false;
        }

        // 分别验证：*地址码*、*出生日期码*和*顺序码*
        if (!$this->_checkAddressCode($code['addressCode'], $code['birthdayCode']) || !$this->_checkBirthdayCode($code['birthdayCode']) || !$this->_checkOrderCode($code['order'])) {
            return false;
        }

        // 15位身份证不含校验码
        if ($code['type'] === 15) {
            return true;
        }

        // 验证：校验码
        $checkBit = $this->_generatorCheckBit($code['body']);

        // 检查校验码
        return $checkBit == $code['checkBit'];
    }
215988
public function delete(string $id = null)
    {
        $this->request->allowMethod(['post', 'delete']);
        $translation = $this->Translations->get($id);
        if ($this->Translations->delete($translation)) {
            $this->Flash->success((string)__('The translation has been deleted.'));
        } else {
            $this->Flash->error((string)__('The translation could not be deleted. Please, try again.'));
        }

        return $this->redirect(['action' => 'index']);
    }
1208424
protected function getValidationMessage($id)
    {
        switch ($id) {
            case 'required':
                $text = $this->show_field_title_in_messages
                    ? Swat::_('%s is required.')
                    : Swat::_('This field is required.');

                break;
            case 'too-long':
                $text = $this->show_field_title_in_messages
                    ? Swat::_(
                        'The %%s field can be at most %s characters long.'
                    )
                    : Swat::_('This field can be at most %s characters long.');

                break;
            default:
                $text = $this->show_field_title_in_messages
                    ? Swat::_('There is a problem with the %s field.')
                    : Swat::_('There is a problem with this field.');

                break;
        }

        $message = new SwatMessage($text, 'error');
        return $message;
    }
512133
public function validateId($id)
    {
        $id_string = $id->toString();
        $this->context[] = "id '$id_string'";
        if (!$id instanceof HTMLPurifier_ConfigSchema_Interchange_Id) {
            // handled by InterchangeBuilder
            $this->error(false, 'is not an instance of HTMLPurifier_ConfigSchema_Interchange_Id');
        }
        // keys are now unconstrained (we might want to narrow down to A-Za-z0-9.)
        // we probably should check that it has at least one namespace
        $this->with($id, 'key')
            ->assertNotEmpty()
            ->assertIsString(); // implicit assertIsString handled by InterchangeBuilder
        array_pop($this->context);
    }
497890
protected static function storeId($id)
    {
        $tokens    =  explode('-', $id);
        $container =& self::$ids;

        do {
            $token = array_shift($tokens);
            if (!isset($container[$token])) {
                $container[$token] = array();
            }
            $container =& $container[$token];
        } while (!empty($tokens));
    }