apply example

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

  /** * {@inheritdoc} */
  public function apply($operation, array $arguments = []) {
    return $this->getToolkit()->apply($operation$arguments);
  }

  /** * {@inheritdoc} */
  public function createNew($width$height$extension = 'png', $transparent_color = '#ffffff') {
    return $this->apply('create_new', ['width' => $width, 'height' => $height, 'extension' => $extension, 'transparent_color' => $transparent_color]);
  }

  /** * {@inheritdoc} */
$currentVersion = $this->getCurrentVersion();
        $this->log(sprintf('Current MigrationNumber: %s', $currentVersion));

        $migrations = $this->getMigrationsForVersion($currentVersion);

        $this->log(sprintf('Found %s migrations to apply', \count($migrations)));

        foreach ($migrations as $migration) {
            $this->log(sprintf('Apply MigrationNumber: %s - %s', $migration->getVersion()$migration->getLabel()));
            try {
                $this->apply($migration$modus);
            } catch (Exception $e) {
                $this->log($e->getMessage());
                throw $e;
            }
        }
    }

    protected function loadMigration(array $result, string $migrationPath): AbstractMigration
    {
        $migrationClassName = 'Migrations_Migration' . $result['1'];
        if (!class_exists($migrationClassName, false)) {
            
public function pop(OutputFormatterStyleInterface $style = null): OutputFormatterStyleInterface
    {
        if (!$this->styles) {
            return $this->emptyStyle;
        }

        if (null === $style) {
            return array_pop($this->styles);
        }

        foreach (array_reverse($this->styles, true) as $index => $stackedStyle) {
            if ($style->apply('') === $stackedStyle->apply('')) {
                $this->styles = \array_slice($this->styles, 0, $index);

                return $stackedStyle;
            }
        }

        throw new InvalidArgumentException('Incorrectly nested style tag found.');
    }

    /** * Computes current style with stacks top codes. */
$definition = $this->createSimpleWorkflowDefinition();

        $object = new Subject();

        $logger = new Logger();

        $ed = new EventDispatcher();
        $ed->addSubscriber(new AuditTrailListener($logger));

        $workflow = new Workflow($definitionnew MethodMarkingStore()$ed);

        $workflow->apply($object, 't1');

        $expected = [
            'Leaving "a" for subject of class "Symfony\Component\Workflow\Tests\Subject" in workflow "unnamed".',
            'Transition "t1" for subject of class "Symfony\Component\Workflow\Tests\Subject" in workflow "unnamed".',
            'Entering "b" for subject of class "Symfony\Component\Workflow\Tests\Subject" in workflow "unnamed".',
        ];

        $this->assertSame($expected$logger->logs);
    }
}

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),
        'transparent_color' => $this->getTransparentColor(),
        'is_temp' => TRUE,
      ];
      if ($this->apply('create_new', $data)) {
        imagecopy($this->getResource()$resource, 0, 0, 0, 0, imagesx($resource)imagesy($resource));
        imagedestroy($resource);
      }
    }
    return (bool) $this->getResource();
  }

  /** * {@inheritdoc} */
  public function isValid() {
    

  public function testManipulations(string $file_name, string $test_case, string $operation, array $arguments, array $expected): void {
    // Load up a fresh image.     $image = $this->imageFactory->get('core/tests/fixtures/files/' . $file_name);
    $toolkit = $image->getToolkit();
    $this->assertTrue($image->isValid());
    $image_original_type = $image->getToolkit()->getType();

    $this->assertTrue(imageistruecolor($toolkit->getResource()), "Image '$file_name' after load should be a truecolor image, but it is not.");

    // Perform our operation.     $image->apply($operation$arguments);

    // Flush Image object to disk storage.     $file_path = $this->directory . '/' . $test_case . image_type_to_extension($image->getToolkit()->getType());
    $image->save($file_path);

    // Check that the both the GD object and the Image object have an accurate     // record of the dimensions.     if (isset($expected['height']) && isset($expected['width'])) {
      $this->assertSame($expected['height']imagesy($toolkit->getResource()), "Image '$file_name' after '$test_case' should have a proper height.");
      $this->assertSame($expected['width']imagesx($toolkit->getResource()), "Image '$file_name' after '$test_case' should have a proper width.");
      $this->assertSame($expected['height']$image->getHeight(), "Image '$file_name' after '$test_case' should have a proper height.");
      
                        $this->matched_rule = $match;
                        break;
                    }
                }
            }

            if ( ! empty( $this->matched_rule ) ) {
                // Trim the query of everything up to the '?'.                 $query = preg_replace( '!^.+\?!', '', $query );

                // Substitute the substring matches into the query.                 $query = addslashes( WP_MatchesMapRegex::apply( $query$matches ) );

                $this->matched_query = $query;

                // Parse the query.                 parse_str( $query$perma_query_vars );

                // If we're processing a 404 request, clear the error var since we found something.                 if ( '404' == $error ) {
                    unset( $error$_GET['error'] );
                }
            }

            

  public function applyEffect(ImageInterface $image) {
    $width = $this->configuration['width'];
    $height = $this->configuration['height'];
    $scale = max($width / $image->getWidth()$height / $image->getHeight());

    [$x$y] = explode('-', $this->configuration['anchor']);
    $x = image_filter_keyword($x$image->getWidth() * $scale$width);
    $y = image_filter_keyword($y$image->getHeight() * $scale$height);

    if (!$image->apply('scale_and_crop', ['x' => $x, 'y' => $y, 'width' => $width, 'height' => $height])) {
      $this->logger->error('Image scale and crop failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', ['%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()]);
      return FALSE;
    }
    return TRUE;
  }

  /** * {@inheritdoc} */
  public function getSummary() {
    $summary = [
      
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Color;
use Symfony\Component\Console\Output\AnsiColorMode;
use Symfony\Component\Console\Terminal;

class ColorTest extends TestCase
{
    public function testAnsi4Colors()
    {
        $color = new Color();
        $this->assertSame(' ', $color->apply(' '));

        $color = new Color('red', 'yellow');
        $this->assertSame("\033[31;43m \033[39;49m", $color->apply(' '));

        $color = new Color('bright-red', 'bright-yellow');
        $this->assertSame("\033[91;103m \033[39;49m", $color->apply(' '));

        $color = new Color('red', 'yellow', ['underscore']);
        $this->assertSame("\033[31;43;4m \033[39;49;24m", $color->apply(' '));
    }

    


    public function testCanDoesNotTriggerGuardEventsForNotEnabledTransitions()
    {
        $definition = $this->createComplexWorkflowDefinition();
        $subject = new Subject();

        $dispatchedEvents = [];
        $eventDispatcher = new EventDispatcher();

        $workflow = new Workflow($definitionnew MethodMarkingStore()$eventDispatcher, 'workflow_name');
        $workflow->apply($subject, 't1');
        $workflow->apply($subject, 't2');

        $eventDispatcher->addListener('workflow.workflow_name.guard.t3', function D) use (&$dispatchedEvents) {
            $dispatchedEvents[] = 'workflow_name.guard.t3';
        });
        $eventDispatcher->addListener('workflow.workflow_name.guard.t4', function D) use (&$dispatchedEvents) {
            $dispatchedEvents[] = 'workflow_name.guard.t4';
        });

        $workflow->can($subject, 't3');

        
return (int) $stmt->fetchColumn();
    }

    /** * @param AbstractPluginMigration::MODUS_* $modus */
    public function apply(AbstractMigration $migration$modus = AbstractMigration::MODUS_INSTALL, bool $keepUserData = false): void
    {
        if ($modus === AbstractPluginMigration::MODUS_UNINSTALL) {
            $this->downMigration($migration$keepUserData);
        } else {
            parent::apply($migration$modus);
        }
    }

    public function getMigrationsForDowngrade($currentVersion$limit = null): array
    {
        $regexPattern = '/^([\d]*)-.+\.php$/i';

        $migrationPath = $this->getMigrationPath();

        $directoryIterator = new DirectoryIterator($migrationPath);
        $regex = new RegexIterator($directoryIterator$regexPattern, RecursiveRegexIterator::GET_MATCH);

        
if (!$totalCount) {
            $totalCount = \count($this->migrationManager->getMigrationsForVersion($currentVersion));
        }

        $migration = $this->migrationManager->getNextMigrationForVersion($currentVersion);

        if ($migration === null) {
            return new FinishResult($offset$totalCount);
        }

        try {
            $this->migrationManager->apply($migration, AbstractMigration::MODUS_UPDATE);
        } catch (Exception $e) {
            $reflection = new ReflectionClass(\get_class($migration));
            $classFile = $reflection->getFileName();

            return new ErrorResult($e->getMessage()$e[
                'deltaFile' => $classFile,
                'deltaVersion' => $migration->getVersion(),
                'deltaLabel' => $migration->getLabel(),
            ]);
        }

        
/** * Applies current style from stack to text, if must be applied. */
    private function applyCurrentStyle(string $text, string $current, int $width, int &$currentLineLength): string
    {
        if ('' === $text) {
            return '';
        }

        if (!$width) {
            return $this->isDecorated() ? $this->styleStack->getCurrent()->apply($text) : $text;
        }

        if (!$currentLineLength && '' !== $current) {
            $text = ltrim($text);
        }

        if ($currentLineLength) {
            $prefix = substr($text, 0, $i = $width - $currentLineLength)."\n";
            $text = substr($text$i);
        } else {
            $prefix = '';
        }
/** * Applies current style from stack to text, if must be applied. */
    private function applyCurrentStyle(string $text, string $current, int $width, int &$currentLineLength): string
    {
        if ('' === $text) {
            return '';
        }

        if (!$width) {
            return $this->isDecorated() ? $this->styleStack->getCurrent()->apply($text) : $text;
        }

        if (!$currentLineLength && '' !== $current) {
            $text = ltrim($text);
        }

        if ($currentLineLength) {
            $prefix = substr($text, 0, $i = $width - $currentLineLength)."\n";
            $text = substr($text$i);
        } else {
            $prefix = '';
        }
Home | Imprint | This part of the site doesn't use cookies.