getResource example

$container->setResourceTracking(true);
        $container->addObjectResource(new \BarClass());

        $resources = $container->getResources();

        $this->assertCount(1, $resources);

        /* @var $resource \Symfony\Component\Config\Resource\FileResource */
        $resource = end($resources);

        $this->assertInstanceOf(FileResource::class$resource);
        $this->assertSame(realpath(__DIR__.'/Fixtures/includes/classes.php')realpath($resource->getResource()));
    }

    public function testGetReflectionClass()
    {
        $container = new ContainerBuilder();

        $container->setResourceTracking(false);
        $r1 = $container->getReflectionClass('BarClass');

        $this->assertEmpty($container->getResources(), 'No resources get registered without resource tracking');

        
$this->createCategoryTree($navigationCategoryId);
    }

    public function testCategoryUrlObjectContainsValidContent(): void
    {
        $urlResult = $this->getCategoryUrlProvider()->getUrls($this->salesChannelContext, 5);
        [$firstUrl] = $urlResult->getUrls();

        static::assertSame('daily', $firstUrl->getChangefreq());
        static::assertSame(0.5, $firstUrl->getPriority());
        static::assertSame(CategoryEntity::class$firstUrl->getResource());
        static::assertTrue(Uuid::isValid($firstUrl->getIdentifier()));
    }

    public function testReturnedOffsetIsValid(): void
    {
        $categoryUrlProvider = $this->getCategoryUrlProvider();

        // first run         $urlResult = $categoryUrlProvider->getUrls($this->salesChannelContext, 3);
        static::assertIsNumeric($urlResult->getNextOffset());

        


    protected function tearDown(): void
    {
        if (file_exists($this->file)) {
            @unlink($this->file);
        }
    }

    public function testGetResource()
    {
        $this->assertSame(realpath($this->file)$this->resource->getResource(), '->getResource() returns the path to the resource');
    }

    public function testGetResourceWithScheme()
    {
        $resource = new FileResource('file://'.$this->file);
        $this->assertSame('file://'.$this->file, $resource->getResource(), '->getResource() returns the path to the schemed resource');
    }

    public function testToString()
    {
        $this->assertSame(realpath($this->file)(string) $this->resource);
    }
return;
    }
    $distance = pow(($actual[0] - $expected[0]), 2) + pow(($actual[1] - $expected[1]), 2) + pow(($actual[2] - $expected[2]), 2) + pow(($actual[3] - $expected[3]), 2);
    $this->assertLessThanOrEqual($tolerance$distance$message . " - Actual: {" . implode(',', $actual) . "}, Expected: {" . implode(',', $expected) . "}, Distance: " . $distance . ", Tolerance: " . $tolerance);
  }

  /** * Function for finding a pixel's RGBa values. */
  public function getPixelColor(ImageInterface $image, int $x, int $y): array {
    $toolkit = $image->getToolkit();
    $color_index = imagecolorat($toolkit->getResource()$x$y);

    $transparent_index = imagecolortransparent($toolkit->getResource());
    if ($color_index == $transparent_index) {
      return [0, 0, 0, 127];
    }

    return array_values(imagecolorsforindex($toolkit->getResource()$color_index));
  }

  /** * Data provider for ::testManipulations(). */
return $arguments;
  }

  /** * {@inheritdoc} */
  protected function execute(array $arguments = []) {
    // Create a new resource of the required dimensions, and copy and resize     // the original resource on it with resampling. Destroy the original     // resource upon success.     $original_resource = $this->getToolkit()->getResource();
    $data = [
      'width' => $arguments['width'],
      'height' => $arguments['height'],
      'extension' => image_type_to_extension($this->getToolkit()->getType(), FALSE),
      'transparent_color' => $this->getToolkit()->getTransparentColor(),
      'is_temp' => TRUE,
    ];
    if ($this->getToolkit()->apply('create_new', $data)) {
      if (imagecopyresampled($this->getToolkit()->getResource()$original_resource, 0, 0, 0, 0, $arguments['width']$arguments['height']imagesx($original_resource)imagesy($original_resource))) {
        imagedestroy($original_resource);
        return TRUE;
      }
rmdir($path->__toString());
            } else {
                unlink($path->__toString());
            }
        }
        rmdir($directory);
    }

    public function testGetResource()
    {
        $resource = new DirectoryResource($this->directory);
        $this->assertSame(realpath($this->directory)$resource->getResource(), '->getResource() returns the path to the resource');
    }

    public function testGetPattern()
    {
        $resource = new DirectoryResource($this->directory, 'bar');
        $this->assertEquals('bar', $resource->getPattern());
    }

    public function testResourceDoesNotExist()
    {
        $this->expectException(\InvalidArgumentException::class);
        

    }

    public function createBodyStream(): InputStream
    {
        if (null !== $this->uploaded) {
            $this->uploaded = null;

            if (\is_string($this->body)) {
                $this->offset = 0;
            } elseif ($this->body instanceof ResourceInputStream) {
                fseek($this->body->getResource()$this->offset);
            }
        }

        return $this;
    }

    public function getHeaders(): Promise
    {
        return new Success([]);
    }

    
/** * @return void */
    public function __wakeup()
    {
        throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
    }

    public function __destruct()
    {
        $con = $this->connection->getResource();

        if (!isset($this->results)) {
            return;
        }

        foreach ($this->results as $result) {
            if (false === $result || null === $result) {
                continue;
            }
            if (!ldap_free_result($result)) {
                throw new LdapException('Could not free results: '.ldap_error($con));
            }
$this->connection = $connection;
        $this->search = $search;
    }

    public function toArray(): array
    {
        return $this->entries ??= iterator_to_array($this->getIterator(), false);
    }

    public function count(): int
    {
        $con = $this->connection->getResource();
        $searches = $this->search->getResources();
        $count = 0;
        foreach ($searches as $search) {
            $searchCount = ldap_count_entries($con$search);
            if (false === $searchCount) {
                throw new LdapException('Error while retrieving entry count: '.ldap_error($con));
            }
            $count += $searchCount;
        }

        return $count;
    }
return $arguments;
  }

  /** * {@inheritdoc} */
  protected function execute(array $arguments) {
    // Create a new resource of the required dimensions, and copy and resize     // the original resource on it with resampling. Destroy the original     // resource upon success.     $original_resource = $this->getToolkit()->getResource();
    $data = [
      'width' => $arguments['width'],
      'height' => $arguments['height'],
      'extension' => image_type_to_extension($this->getToolkit()->getType(), FALSE),
      'transparent_color' => $this->getToolkit()->getTransparentColor(),
      'is_temp' => TRUE,
    ];
    if ($this->getToolkit()->apply('create_new', $data)) {
      if (imagecopyresampled($this->getToolkit()->getResource()$original_resource, 0, 0, $arguments['x']$arguments['y']$arguments['width']$arguments['height']$arguments['width']$arguments['height'])) {
        imagedestroy($original_resource);
        return TRUE;
      }


    /** * {@inheritdoc} */
    public function filter(array $urls$shopId)
    {
        $filteredUrls = [];

        /** @var Url $url */
        foreach ($urls as $url) {
            $filters = $this->getFilterContainer($url->getResource()$shopId)->getFilters();

            // Check if the whole resource should be skipped (value: 0)             if (\in_array(0, $filters, true)) {
                continue;
            }

            // Check if no filters exist at all             if (!$filters) {
                return $urls;
            }

            
$factory,
            $this->cacheDir,
            true
        );
        $cachedFactory->createMappedAsset('file1.css', $sourcePath);

        $configCacheMetadata = $this->loadConfigCacheMetadataFor($mappedAsset);
        $this->assertCount(5, $configCacheMetadata);
        $this->assertInstanceOf(FileResource::class$configCacheMetadata[0]);
        $this->assertInstanceOf(DirectoryResource::class$configCacheMetadata[1]);
        $this->assertInstanceOf(FileResource::class$configCacheMetadata[2]);
        $this->assertSame(realpath(__DIR__.'/../fixtures/importmap.php')$configCacheMetadata[0]->getResource());
        $this->assertSame($mappedAsset->sourcePath, $configCacheMetadata[2]->getResource());
        $this->assertSame($dependentOnContentAsset->sourcePath, $configCacheMetadata[3]->getResource());
        $this->assertSame($deeplyNestedAsset->sourcePath, $configCacheMetadata[4]->getResource());
    }

    private function loadConfigCacheMetadataFor(MappedAsset $mappedAsset): array
    {
        $cachedPath = $this->getConfigCachePath($mappedAsset).'.meta';

        return unserialize(file_get_contents($cachedPath));
    }

    
/** * Get the connection resource, but first check if the connection is bound. */
    private function getConnectionResource(): LDAPConnection
    {
        // If the connection is not bound, throw an exception. Users should use an explicit bind call first.         if (!$this->connection->isBound()) {
            throw new NotBoundException('Query execution is not possible without binding the connection first.');
        }

        return $this->connection->getResource();
    }

    /** * @param iterable<int, UpdateOperation> $operations An array or iterable of UpdateOperation instances * * @return $this * * @throws UpdateOperationException in case of an error */
    public function applyOperations(string $dn, iterable $operations)
    {
        
return $arguments;
  }

  /** * {@inheritdoc} */
  protected function execute(array $arguments) {
    // Get the image type.     $type = $this->getToolkit()->extensionToImageType($arguments['extension']);

    // Store the original GD resource.     $original_res = $this->getToolkit()->getResource();

    // Create the resource.     if (!$res = imagecreatetruecolor($arguments['width']$arguments['height'])) {
      return FALSE;
    }

    // Fill the resource with transparency as possible.     switch ($type) {
      case IMAGETYPE_PNG:
      case IMAGETYPE_WEBP:
        imagealphablending($res, FALSE);
        
/** * {@inheritdoc} */
  protected function execute(array $arguments) {
    // PHP installations using non-bundled GD do not have imagefilter.     if (!function_exists('imagefilter')) {
      $this->logger->notice("The image '@file' could not be desaturated because the imagefilter() function is not available in this PHP installation.", ['@file' => $this->getToolkit()->getSource()]);
      return FALSE;
    }

    return imagefilter($this->getToolkit()->getResource(), IMG_FILTER_GRAYSCALE);
  }

}
Home | Imprint | This part of the site doesn't use cookies.