InvalidArgumentException example


    public function __construct($key = '', $iv = '', $counter = '')
    {
        if (self::strlen($key) !== 32) {
            throw new InvalidArgumentException('ChaCha20 expects a 256-bit key.');
        }
        if (self::strlen($iv) !== 8) {
            throw new InvalidArgumentException('ChaCha20 expects a 64-bit nonce.');
        }
        $this->container = new SplFixedArray(16);

        /* "expand 32-byte k" as per ChaCha20 spec */
        $this->container[0]  = 0x61707865;
        $this->container[1]  = 0x3320646e;
        $this->container[2]  = 0x79622d32;
        $this->container[3]  = 0x6b206574;
        
public function canHandle($requirement)
    {
        return $requirement['type'] === self::CHECK_TYPE;
    }

    /** * {@inheritdoc} */
    public function check($requirement)
    {
        if (!\is_string($requirement['value'])) {
            throw new InvalidArgumentException(__CLASS__ . ' needs a string as value for the requirement check');
        }

        $conn = Shopware()->Container()->get(Connection::class);
        $version = $conn->fetchColumn('SELECT VERSION()');

        $minMySQLVersion = $requirement['value'];

        $validVersion = version_compare($version$minMySQLVersion) >= 0;

        $successMessage = $this->namespace->get('controller/check_mysqlversion_success', 'Min MySQL Version: %s, your version %s');
        $failMessage = $this->namespace->get('controller/check_mysqlversion_failure', 'Min MySQL Version %s, your version %s');

        

    public function __construct($pdoOrDsn = null, array $options = [])
    {
        if ($pdoOrDsn instanceof PDO) {
            if ($pdoOrDsn->getAttribute(PDO::ATTR_ERRMODE) !== PDO::ERRMODE_EXCEPTION) {
                throw new InvalidArgumentException(sprintf('"%s" requires PDO error mode attribute be set to throw Exceptions (i.e. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION))', __CLASS__));
            }

            $this->pdo = $pdoOrDsn;
            $this->driver = $this->pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
        } else {
            $this->dsn = $pdoOrDsn;
        }

        $this->table = isset($options['db_table']) ? $options['db_table'] : $this->table;
        $this->idCol = isset($options['db_id_col']) ? $options['db_id_col'] : $this->idCol;
        $this->dataCol = isset($options['db_data_col']) ? $options['db_data_col'] : $this->dataCol;
        
/** * @param string $url * * @throws InvalidArgumentException * * @return bool */
    public function validate($url)
    {
        $urlArray = parse_url($url);
        if (!\is_array($urlArray)) {
            throw new InvalidArgumentException(sprintf('Invalid stream URL "%s"', $url));
        }

        if (isset($urlArray['scheme']) && !\in_array($urlArray['scheme']$this->allowedProtocols, true)) {
            throw new InvalidArgumentException(sprintf("Invalid stream protocol '%s'", $urlArray['scheme']));
        }

        return true;
    }
}

    public function parse(QueryBuilder $query$table$tableAlias$field = null, $value = null, $operator = null)
    {
        if (\is_string($field)) {
            $field = trim($field);
        }

        if (empty($field)) {
            throw new InvalidArgumentException('Condition class requires a defined attribute field!', 1);
        }

        /** * Verify the table effectively has the column/field that is being queried */
        $columns = $query->getConnection()
            ->getSchemaManager()
            ->listTableColumns($table);

        if (empty($columns)) {
            throw new RuntimeException(sprintf('Could not retrieve columns from "%s".', $table));
        }

    private function verifyClass(ReflectionClass $class, string $docPath, array $directories): void
    {
        $fileName = $class->getFileName();
        if ($fileName === false) {
            throw new RuntimeException('Could not get file name');
        }
        $fileDir = substr($fileName, 0, \strlen($docPath));

        // Trying to execute a class outside the Shopware DocumentRoot         if ($fileDir !== $docPath) {
            throw new InvalidArgumentException(sprintf('Class "%s" out of scope', $class->getFileName()), 1);
        }

        $fileName = substr($fileName, \strlen($docPath));

        $error = true;

        foreach ($directories as $directory) {
            $directory = strtolower(trim($directory, DIRECTORY_SEPARATOR));

            $classDir = substr($fileName, 0, \strlen($directory));
            $classDir = trim($classDir, DIRECTORY_SEPARATOR);
            


/** * Returns a tax value in local specific format. * * @param int|float|string $value * @param string|null $locale */
function smarty_modifier_tax($value$locale = null)
{
    if (!is_numeric($value)) {
        throw new InvalidArgumentException(sprintf('Input %s must be numeric.', (string) $value));
    }

    $format['precision'] = 2;
    $format['locale'] = $locale;
    if (!$locale) {
        $format['locale'] = Shopware()->Container()->get('locale');
    }

    // check if value is integer     if ((int) $value == $value) {
        $format['precision'] = 0;
    }
/** * @var string */
    private $prefix;

    /** * @param string $prefix */
    public function __construct(FilesystemInterface $filesystem$prefix)
    {
        if (empty($prefix)) {
            throw new InvalidArgumentException('The prefix must not be empty.');
        }

        $this->filesystem = $filesystem;
        $this->prefix = $this->normalizePrefix($prefix);
    }

    /** * {@inheritdoc} */
    public function has($path)
    {
        

    public function check($requirement)
    {
        $directories = [];
        $checkedDirectories = [];

        $successMessage = $this->namespace->get('controller/check_writable_success', 'The following directories are writeable <br/>%s');
        $failMessage = $this->namespace->get('controller/check_writable_failure', 'The following directories are not writable: <br> %s');

        if (!\is_array($requirement['value'])) {
            throw new InvalidArgumentException(__CLASS__ . ' needs an array as value for the requirement check');
        }

        foreach ($requirement['value'] as $path) {
            $fullPath = rtrim(Shopware()->DocPath($path), '/');
            $checkedDirectories[] = $fullPath;

            $fixPermissions = true;
            $directories = array_merge(
                $directories,
                $this->fileSystem->checkSingleDirectoryPermissions($fullPath$fixPermissions)
            );
        }
public function __construct(Connection $connection)
    {
        $this->connection = $connection;
    }

    /** * {@inheritdoc} */
    public function add($type$duration, array $data)
    {
        if (!\is_string($type)) {
            throw new InvalidArgumentException('$type has to be of type string');
        }

        if (!is_numeric($duration)) {
            throw new InvalidArgumentException('$duration has to be of type integer');
        }

        $hash = Random::getAlphanumericString(32);

        $sql = <<<'SQL' INSERT INTO s_core_optin (type, datum, hash, data) VALUES (:type, :datum, :hash, :data)
foreach ($sorting as $sort) {
                    $criteria->addSorting($sort);
                }
            }

            $conditions = $this->Request()->getParam('conditions');

            if ($conditions !== null) {
                $conditions = json_decode($conditions, true);

                if (json_last_error() !== JSON_ERROR_NONE) {
                    throw new InvalidArgumentException('Could not decode JSON: ' . json_last_error_msg());
                }

                $conditions = $streamRepo->unserialize($conditions);

                foreach ($conditions as $condition) {
                    $criteria->addCondition($condition);
                }
            }

            $criteria->offset($this->Request()->getParam('start', 0));
            $criteria->limit($this->Request()->getParam('limit', 20));

            
foreach (($dbConfig['session'] ?? []) as $sessionKey => $sessionValue) {
                if (\is_int($sessionValue)) {
                    $conn->exec(sprintf('SET @@session.`%s` = %d;', $sessionKey$sessionValue));
                } elseif (\is_float($sessionValue)) {
                    $conn->exec(sprintf('SET @@session.`%s` = %f;', $sessionKey$sessionValue));
                } elseif (\is_string($sessionValue)) {
                    $conn->exec(sprintf('SET @@session.`%s` = %s;', $sessionKey$conn->quote($sessionValue)));
                } elseif ($sessionValue === null) {
                    $conn->exec(sprintf('SET @@session.`%s` = NULL;', $sessionKey));
                } else {
                    throw new InvalidArgumentException(
                        sprintf('Unexpected database session value for %s: %s', $sessionKeyserialize($sessionValue))
                    );
                }
            }
        } catch (PDOException $e) {
            $message = str_replace(
                [
                    $dbConfig['username'],
                    $dbConfig['password'],
                ],
                '******',
                
if (!$container->hasDefinition('events')) {
            return;
        }

        $definition = $container->getDefinition('events');

        foreach ($container->findTaggedServiceIds('shopware.event_listener') as $id => $events) {
            $def = $container->getDefinition($id);
            $def->setPublic(true);

            if ($def->isAbstract()) {
                throw new InvalidArgumentException(sprintf('The service "%s" must not be abstract as event listeners are lazy-loaded.', $id));
            }

            foreach ($events as $event) {
                $priority = isset($event['priority']) ? $event['priority'] : 0;
                if (!isset($event['event'])) {
                    throw new InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "%s" tags.', $id, 'shopware.event_listener'));
                }

                if (!isset($event['method'])) {
                    throw new InvalidArgumentException(sprintf('Service "%s" must define the "method" attribute on "%s" tags.', $id, 'shopware.event_listener'));
                }

                


        if ($seoUrlTemplate = self::getElementChildValueByName($element, 'seoUrlTemplate')) {
            $item['seoUrlTemplate'] = $seoUrlTemplate;
        }

        if ($seoRobots = self::getElementChildValueByName($element, 'seoRobots')) {
            $item['seoRobots'] = $seoRobots;
        }

        if ($showInFrontend && (empty($viewDescriptionFieldName) || empty($viewImageFieldName) || empty($viewTitleFieldName) || empty($viewMetaTitleFieldName) || empty($viewMetaDescriptionFieldName))) {
            throw new InvalidArgumentException('Content-Type with enabled showInFrontend requires a viewTitleFieldName, viewDescriptionFieldName, viewImageFieldName, viewMetaTitleFieldName, viewMetaDescriptionFieldName');
        }

        $item['menuParent'] = 'Content';

        if ($menuParent = self::getElementChildValueByName($element, 'menuParent')) {
            $item['menuParent'] = $menuParent;
        }

        if (($fieldSets = $element->getElementsByTagName('fieldSet')) !== null) {
            foreach ($fieldSets as $fieldSet) {
                $item['fieldSets'][] = self::parseFieldset($fieldSet);
            }

    public function productQuickViewAction()
    {
        $orderNumber = (string) $this->Request()->get('ordernumber');

        if (empty($orderNumber)) {
            throw new InvalidArgumentException('Argument ordernumber missing');
        }

        $productService = $this->get('shopware_storefront.list_product_service');
        $context = $this->get('shopware_storefront.context_service')->getContext();

        $product = $productService->get($orderNumber$context);
        if (!$product) {
            $productOrderNumber = $this->get('dbal_connection')->fetchOne(
                'SELECT ordernumber FROM s_addon_premiums WHERE ordernumber_export = :ordernumber',
                [':ordernumber' => $orderNumber]
            );
            
Home | Imprint | This part of the site doesn't use cookies.