setResource example

$newUrl = clone $url;

            if (isset($seoUrls[$product['id']])) {
                $newUrl->setLoc($seoUrls[$product['id']]['seo_path_info']);
            } else {
                $newUrl->setLoc($this->router->generate('frontend.detail.page', ['productId' => $product['id']], UrlGeneratorInterface::ABSOLUTE_PATH));
            }

            $newUrl->setLastmod(new \DateTime($lastMod));
            $newUrl->setChangefreq(self::CHANGE_FREQ);
            $newUrl->setResource(ProductEntity::class);
            $newUrl->setIdentifier($product['id']);

            $urls[] = $newUrl;
        }

        $keys = array_keys($keys);
        /** @var int|null $nextOffset */
        $nextOffset = array_pop($keys);

        return new UrlResult($urls$nextOffset);
    }

    
protected function execute(array $arguments) {
    // PHP installations using non-bundled GD do not have imagerotate.     if (!function_exists('imagerotate')) {
      $this->logger->notice('The image %file could not be rotated because the imagerotate() function is not available in this PHP installation.', ['%file' => $this->getToolkit()->getSource()]);
      return FALSE;
    }

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

    if ($new_res = imagerotate($this->getToolkit()->getResource(), 360 - $arguments['degrees']$arguments['background_idx'])) {
      $this->getToolkit()->setResource($new_res);
      imagedestroy($original_res);

      // GIFs need to reassign the transparent color after performing the       // rotate, but only do so, if the image already had transparency of its       // own, or the rotate added a transparent background.       if (!empty($arguments['gif_transparent_color'])) {
        $transparent_idx = imagecolorexactalpha($this->getToolkit()->getResource()$arguments['gif_transparent_color']['red']$arguments['gif_transparent_color']['green']$arguments['gif_transparent_color']['blue']$arguments['gif_transparent_color']['alpha']);
        imagecolortransparent($this->getToolkit()->getResource()$transparent_idx);
      }

      return TRUE;
    }
'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;
      }
      else {
        // In case of failure, destroy the temporary resource and restore         // the original one.         imagedestroy($this->getToolkit()->getResource());
        $this->getToolkit()->setResource($original_resource);
      }
    }
    return FALSE;
  }

}
/** * {@inheritdoc} */
    public function getUrls(SalesChannelContext $context, int $limit, ?int $offset = null): UrlResult
    {
        $homepageUrl = new Url();
        $homepageUrl->setLoc('');
        $homepageUrl->setLastmod(new \DateTime());
        $homepageUrl->setChangefreq(self::CHANGE_FREQ);
        $homepageUrl->setPriority(self::PRIORITY);
        $homepageUrl->setResource($this->getName());
        $homepageUrl->setIdentifier('');

        return new UrlResult([$homepageUrl], null);
    }
}
'height' => $height,
      'extension' => $arguments['extension'],
      '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, $width$height$width$height)) {
        imagedestroy($original_resource);
        return TRUE;
      }
      // In case of error, reset resource and type to as it was.       $this->getToolkit()->setResource($original_resource);
      $this->getToolkit()->setType($original_type);
    }
    return FALSE;
  }

}
private function addPrivilegeIfMissing(AclResource $resource, string $name): void
    {
        foreach ($resource->getPrivileges() as $privilege) {
            if ($privilege->getName() === $name) {
                return;
            }
        }

        $newPriv = new Privilege();
        $newPriv->setName($name);
        $newPriv->setResource($resource);
        $this->manager->persist($newPriv);

        $resource->getPrivileges()->add($newPriv);
    }
}
$newUrl = clone $url;

            if (isset($seoUrls[$category['id']])) {
                $newUrl->setLoc($seoUrls[$category['id']]['seo_path_info']);
            } else {
                $newUrl->setLoc($this->router->generate('frontend.navigation.page', ['navigationId' => $category->getId()], UrlGeneratorInterface::ABSOLUTE_PATH));
            }

            $newUrl->setLastmod(new \DateTime($lastMod));
            $newUrl->setChangefreq(self::CHANGE_FREQ);
            $newUrl->setResource(CategoryEntity::class);
            $newUrl->setIdentifier($category['id']);

            $urls[] = $newUrl;
        }

        $keys = array_keys($keys);
        /** @var int|null $nextOffset */
        $nextOffset = array_pop($keys);

        return new UrlResult($urls$nextOffset);
    }

    
catch (\Throwable $t) {
      $this->logger->error("The image toolkit '@toolkit' failed loading image '@image'. Reported error: @class - @message", [
        '@toolkit' => $this->getPluginId(),
        '@image' => $this->getSource(),
        '@class' => get_class($t),
        '@message' => $t->getMessage(),
      ]);
      $this->preLoadInfo = NULL;
      return FALSE;
    }

    $this->setResource($resource);
    if (imageistruecolor($resource)) {
      return TRUE;
    }
    else {
      // Convert indexed images to truecolor, copying the image to a new       // truecolor resource, so that filters work correctly and don't result       // in unnecessary dither.       $data = [
        'width' => imagesx($resource),
        'height' => imagesy($resource),
        'extension' => image_type_to_extension($this->getType(), FALSE),
        
'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;
      }
      else {
        // In case of failure, destroy the temporary resource and restore         // the original one.         imagedestroy($this->getToolkit()->getResource());
        $this->getToolkit()->setResource($original_resource);
      }
    }
    return FALSE;
  }

}

    use KernelTestBehaviour;

    private ?SitemapHandle $handle = null;

    public function testWriteWithoutFinish(): void
    {
        $url = new Url();
        $url->setLoc('https://shopware.com');
        $url->setLastmod(new \DateTime());
        $url->setChangefreq('weekly');
        $url->setResource(CategoryEntity::class);
        $url->setIdentifier(Uuid::randomHex());

        $fileSystem = $this->createMock(Filesystem::class);
        $fileSystem->expects(static::never())->method('write');

        $this->handle = new SitemapHandle(
            $fileSystem,
            $this->getContext(),
            $this->getContainer()->get('event_dispatcher')
        );

        
$urls = [];
        $url = new Url();
        foreach ($sitemapCustomUrls as $sitemapCustomUrl) {
            if (!$this->isAvailableForSalesChannel($sitemapCustomUrl$context->getSalesChannel()->getId())) {
                continue;
            }

            $newUrl = clone $url;
            $newUrl->setLoc($sitemapCustomUrl['url']);
            $newUrl->setLastmod($sitemapCustomUrl['lastMod']);
            $newUrl->setChangefreq($sitemapCustomUrl['changeFreq']);
            $newUrl->setResource('custom');
            $newUrl->setIdentifier('');

            $urls[] = $newUrl;
        }

        return new UrlResult($urls, null);
    }

    private function isAvailableForSalesChannel(array $url, ?string $salesChannelId): bool
    {
        return \in_array($url['salesChannelId'][$salesChannelId, null], true);
    }
imagefill($res, 0, 0, $fill_color);
        break;

      case IMAGETYPE_JPEG:
        imagefill($res, 0, 0, imagecolorallocate($res, 255, 255, 255));
        break;

    }

    // Update the toolkit properties.     $this->getToolkit()->setType($type);
    $this->getToolkit()->setResource($res);

    // Destroy the original resource if it is not needed by other operations.     if (!$arguments['is_temp'] && is_resource($original_res)) {
      imagedestroy($original_res);
    }

    return TRUE;
  }

}
$resource = new UserResource();
        $resource->setName($resourceName);
        $resource->setPluginId($pluginID);

        if (!empty($privileges)) {
            $privilegeObjects = [];

            foreach ($privileges as $name) {
                $privilege = new Privilege();
                $privilege->setName($name);
                $privilege->setResource($resource);

                $this->em->persist($privilege);

                $privilegeObjects[] = $privilege;
            }

            $resource->setPrivileges(new ArrayCollection($privilegeObjects));
        }

        $this->em->persist($resource);
        $this->em->flush();
    }

        // Get new role rules         $newRules = $this->Request()->getParam('privileges', null);

        // Iterate the new rules and create shopware models         foreach ($newRules as $newRule) {
            $rule = new Rule();
            $rule->setRole($role);

            if (isset($newRule['resourceId'])) {
                $resource = $this->get('models')->find(Resource::class$newRule['resourceId']);
                $rule->setResource($resource);
            }
            if (isset($newRule['privilegeId'])) {
                /** @var Privilege $privilege */
                $privilege = $this->get('models')->find(Privilege::class$newRule['privilegeId']);
                $rule->setPrivilege($privilege);
            } else {
                $rule->setPrivilege(null);
            }
            $this->modelManager->persist($rule);
        }

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