Giter Site home page Giter Site logo

Comments (7)

avalanche123 avatar avalanche123 commented on July 28, 2024

You can get ahold of Imagine service by calling $container->get('imagine'); once you have it, http://imagine.readthedocs.org/en/latest/index.html will help you with how to use it

from avalancheimaginebundle.

stoefln avatar stoefln commented on July 28, 2024

thanks very much!

from avalancheimaginebundle.

jmikola avatar jmikola commented on July 28, 2024

Since I just implemented this last night in JmikolaImagineBundle, I'd suggest something like:

<?php
$box = $image->getSize();
$resizedImage = $image->resize($box->scale(1.5));

That would scale an image by its own dimensions (probably what you want).

from avalancheimaginebundle.

avalanche123 avatar avalanche123 commented on July 28, 2024

may I reiterate:

<?php
$image->resize($image->getSize()->scale(1.5));

from avalancheimaginebundle.

jmikola avatar jmikola commented on July 28, 2024

@avalanche123: I guess you don't care about Law of Demeter anymore :)

from avalancheimaginebundle.

avalanche123 avatar avalanche123 commented on July 28, 2024

@jmikola, do care :) here we're dealing with Box immutable value object (immutable and value object pretty much assumes each other). I feel that law of demeter makes a lot of sense when each method call is returning another object. so if we had A::b() -> B and B::c() -> C then

<?php
$a = new A();
$a->b()->c(); // would be terrible as you'd have to mock the whole chain in tests

while in our case we'd do something like:

<?php
$size = new Box(100, 100);

// stub out initial size
$image->expects($this->once())
    ->method('getSize')
    ->will($this->returnValue($size))
;

$image->expects($this->once())
    ->method('resize')
    ->with(new Box(150, 150))
;

// our filter that executes my above code
$filter->apply($image);

As you can see, mocking value objects is unnecessary as they are easy to construct and have on dependencies on other objects (easy to construct and have no dependencies is pretty much the same thing).

Another example would be PHP's DateTime class, it is globally accessible and easy to construct.

To conclude, don't violate the LOD for service objects, while don't bother with it in cases where object operates on its internal state. For example, builder's fluent interface, but not the factory method...

Cheers! :)

from avalancheimaginebundle.

avalanche123 avatar avalanche123 commented on July 28, 2024

just realized, that the example is talking about and applicable to 'newables' in general and not only value objects

you can read about 'newables' at http://misko.hevery.com/2008/09/30/to-new-or-not-to-new/

from avalancheimaginebundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.