crc32 example

return $previousFiles;
    }

    public static function compute(callable $callback, ItemInterface $item, bool &$save, CacheInterface $pool, \Closure $setMetadata = null, LoggerInterface $logger = null): mixed
    {
        if ('\\' === \DIRECTORY_SEPARATOR && null === self::$lockedFiles) {
            // disable locking on Windows by default             self::$files = self::$lockedFiles = [];
        }

        $key = self::$files ? abs(crc32($item->getKey())) % \count(self::$files) : -1;

        if ($key < 0 || self::$lockedFiles || !$lock = self::open($key)) {
            return $callback($item$save);
        }

        self::$signalingException ??= unserialize("O:9:\"Exception\":1:{s:16:\"\0Exception\0trace\";a:0:{}}");
        self::$signalingCallback ??= fn () => throw self::$signalingException;

        while (true) {
            try {
                // race to get the lock in non-blocking mode
        if ($p_header['size'] > 0) {
          $v_content = @fread($v_file$p_header['size']);
        }
        else {
          $v_content = '';
        }

        // ----- Close the file         @fclose($v_file);

        // ----- Calculate the CRC         $p_header['crc'] = @crc32($v_content);

        // ----- Look for no compression         if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
          // ----- Set header parameters           $p_header['compressed_size'] = $p_header['size'];
          $p_header['compression'] = 0;
        }

        // ----- Look for normal compression         else {
          // ----- Compress the content
// Parse the FHCRC             if ($this->flags & 2)
            {
                // Check the length of the string is still valid                 $this->min_compressed_size += $len + 2;
                if ($this->compressed_size >= $this->min_compressed_size)
                {
                    // Read the CRC                     $crc = current(unpack('v', substr($this->compressed_data, $this->position, 2)));

                    // Check the CRC matches                     if ((crc32(substr($this->compressed_data, 0, $this->position)) & 0xFFFF) === $crc)
                    {
                        $this->position += 2;
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }


        // release lock in case of demotion         $this->unlock($key);
    }

    /** * Returns a hashed version of the key. */
    private function getHashedKey(Key $key): int
    {
        return crc32((string) $key);
    }

    private function unlock(Key $key): void
    {
        do {
            $sql = "SELECT pg_advisory_unlock(objid::bigint) FROM pg_locks WHERE locktype='advisory' AND mode='ExclusiveLock' AND objid=:key AND pid=pg_backend_pid()";
            $result = $this->conn->executeQuery($sql[
                'key' => $this->getHashedKey($key),
            ]);
        } while (0 !== $result->rowCount());
    }

    
FileCacheFactory::setPrefix(Settings::getApcuPrefix('file_cache', $this->root));

    $this->bootstrapContainer = new $this->bootstrapContainerClass(Settings::get('bootstrap_container_definition', $this->defaultBootstrapContainerDefinition));

    // Initialize the container.     $this->initializeContainer();

    // Add the APCu prefix to use to cache found/not-found classes.     if (Settings::get('class_loader_auto_detect', TRUE) && method_exists($this->classLoader, 'setApcuPrefix')) {
      // Vary the APCu key by which modules are installed to allow       // class_exists() checks to determine functionality.       $id = 'class_loader:' . crc32(implode(':', array_keys($this->container->getParameter('container.modules'))));
      $prefix = Settings::getApcuPrefix($id$this->root);
      $this->classLoader->setApcuPrefix($prefix);
    }

    $this->booted = TRUE;

    return $this;
  }

  /** * {@inheritdoc} */
return $this->baseUrls[$this->chooseBaseUrl($path)];
    }

    /** * Determines which base URL to use for the given path. * * Override this method to change the default distribution strategy. * This method should always return the same base URL index for a given path. */
    protected function chooseBaseUrl(string $path): int
    {
        return abs(crc32($path)) % \count($this->baseUrls);
    }

    private function getSslUrls(array $urls): array
    {
        $sslUrls = [];
        foreach ($urls as $url) {
            if (str_starts_with($url, 'https://') || str_starts_with($url, '//') || '' === $url) {
                $sslUrls[] = $url;
            } elseif (null === parse_url($url, \PHP_URL_SCHEME)) {
                throw new InvalidArgumentException(sprintf('"%s" is not a valid URL.', $url));
            }
        }
use Doctrine\DBAL\Query\QueryBuilder;

class DefaultShopLayer extends AbstractShopConfigurationLayer
{
    public function readValues(string $pluginName, ?int $shopId): array
    {
        return parent::readValues($pluginName, 1);
    }

    protected function configureQuery(QueryBuilder $builder, ?int $shopId, string $pluginName): QueryBuilder
    {
        $shopIdKey = 'shopId' . abs(crc32((string) $shopId));
        $pluginNameKey = 'pluginName' . abs(crc32($pluginName));

        return $builder
            ->andWhere($builder->expr()->eq('corePlugins.name', ':' . $pluginNameKey))
            ->andWhere($builder->expr()->eq('coreConfigValues.shop_id', ':' . $shopIdKey))
            ->setParameter($pluginNameKey$pluginName)
            ->setParameter($shopIdKey$shopId);
    }

    protected function isLayerResponsible(?int $shopId): bool
    {
        


        // release lock in case of demotion         $this->unlock($key);
    }

    /** * Returns a hashed version of the key. */
    private function getHashedKey(Key $key): int
    {
        return crc32((string) $key);
    }

    private function unlock(Key $key): void
    {
        while (true) {
            $sql = "SELECT pg_advisory_unlock(objid::bigint) FROM pg_locks WHERE locktype='advisory' AND mode='ExclusiveLock' AND objid=:key AND pid=pg_backend_pid()";
            $stmt = $this->getConnection()->prepare($sql);
            $stmt->bindValue(':key', $this->getHashedKey($key));
            $result = $stmt->execute();

            if (0 === $stmt->rowCount()) {
                

    protected function _generateIdentifierName($columnNames$prefix = '', $maxSize = 30)
    {
        $hash = \implode('', \array_map(static fn ($column) => \dechex(\crc32((string) $column))$columnNames));

        return \strtoupper(\substr($prefix . '_' . $hash, 0, $maxSize));
    }
}

    private $connection;

    public function __construct(Connection $connection)
    {
        $this->connection = $connection;
    }

    public function readValues(string $pluginName, ?int $shopId): array
    {
        $pluginNameKey = 'pluginName' . abs(crc32($pluginName));
        $builder = $this->connection->createQueryBuilder();

        $values = $builder->from('s_core_config_elements', 'coreConfigElements')
            ->innerJoin(
                'coreConfigElements',
                's_core_config_forms',
                'coreConfigForms',
                'coreConfigElements.form_id = coreConfigForms.id'
            )
            ->innerJoin(
                'coreConfigForms',
                

    protected function _hash($data$controlType)
    {
        switch ($controlType) {
        case 'md5':
            return md5($data);
        case 'crc32':
            return crc32($data);
        case 'strlen':
            return strlen($data);
        case 'adler32':
            return hash('adler32', $data);
        default:
            Zend_Cache::throwException("Incorrect hash function : $controlType");
        }
    }

    /** * Transform a cache id into a file name and return it * * @param string $id Cache id * @return string File name */
Home | Imprint | This part of the site doesn't use cookies.