Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented HttpAdapter with guzzle #178

Closed
wants to merge 1 commit into from
Closed

Implemented HttpAdapter with guzzle #178

wants to merge 1 commit into from

Conversation

hgraca
Copy link

@hgraca hgraca commented Jun 9, 2014

I'm gonna add some comments to the code, would like for you guys to let me know what you think about it.

* @return array
*/
public function getMimetype($path)
{
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this implementation: We are actually fetching the metadata from the remote location, but this might already be cached and we don't use the cached version.
Any suggestions on how to improve this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually fine, I have to go over the other things first to see if everything is correct though. The caching mechanism makes sure that every bit of metadata returned is cached and it doesn't cache by call but by normalised key. So if you've fetched all the meta-data you won't have to refetch it when just asking for the timestamp or mime-type. The mimetype key will just be fetched from cache.

@GrahamCampbell
Copy link
Member

Why not guzzle 4? It's not recommended by the guzzle team to write new code with a deprecated version. Also, you are missing the composer additions. Also, why the extra block comments? They are not consistent with the rest of this repo.

@hgraca
Copy link
Author

hgraca commented Jun 10, 2014

Because I did not notice it was not on Composer, I just used the version that was already in the vendors. I've updated composer.json, composer.json.hhvm, and the code. However the tests are failing in PHP 5.3 because guzzle4 requires PHP 5.4. How do you want me to fix this? Shall I add the php 5.4 requirement to composer.json and update the branch-alias ?

The extra block comments are my default setup, I find that it makes the class MUCH more readable. I do not consider consistency to be a relevant point in this case, because consistency should not be a reason to block change when it is considered beneficial, which you could consider, but obviously don't. Anyway, I removed the evil comments as per your request. ;)

I noticed that composer.lock is in gitignore. Do you think that is wise? Shouldn't we, by default, install versions of the libraries, tested with Flysystem, instead of the latest versions (which might not have been tested with Flysystem)?

@GrahamCampbell
Copy link
Member

For the php 5.4 stuff, maybe we could swap out the composer.json file like we do for hhvm and skip the guzzle dependant tests?

As for the block comments, I think you should remove them, then add them everywhere in a different pull to keep consistency within the code base, but it's not my call. Ping @FrenkyNet.

Nah, the composer.lock isn't really needed as far as I can see. I think the idea here is just to fire the tests off against the latest versions to check flysystem is working ok with them.

@frankdejonge
Copy link
Member

@GrahamCampbell @hgraca I'm thinking of raising the minimum php version to 5.4 anyway, I just have to determine the right time for that. It seems like other packages and frameworks are making the same move. Laravel, Guzzle, FuelPHP, and CakePHP even are making that move, so might be the right time now. This would eliminate that problem entirely.

@GrahamCampbell
Copy link
Member

@FrenkyNet Should @hgraca just bump the min php version to 5.4 in this pull, and remove 5.3 from travis then?

@GrahamCampbell
Copy link
Member

@hgraca If you can rebase against the latest changes on the master, the php 5.3 issue has been resolved. Basically, it's been removed from travis.yml and php 5.4 has been added as a min version to composer.

@hgraca
Copy link
Author

hgraca commented Jun 13, 2014

Ok, cool!
I will do it when I have some time, probably during the weekend.

@GrahamCampbell
Copy link
Member

Sounds great. Thanks.

@hgraca
Copy link
Author

hgraca commented Jun 17, 2014

Updated the PR, you can take a look to see it's ok.

<?php

namespace League\Flysystem\Adapter;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be one new line here, not 2.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAANNN!!! You are very pickyyyy!!! :D But I will change it anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@GrahamCampbell
Copy link
Member

What happened to all the docblock parameter types?

@hgraca
Copy link
Author

hgraca commented Jun 18, 2014

@GrahamCampbell I don't understand what you are referring to, can you elaborate, please?

* Write a file
* It's not possible to write to HTTP so it will always do nothing and return false
*
* @param $path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I mean. We've lost the string.

@hgraca
Copy link
Author

hgraca commented Jun 18, 2014

@GrahamCampbell Got it. Updated all docblocks.

*
* @return array|bool
*/
public function readStream($path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you not using guzzle in this function? It's possible to get the stream from a request body like so:

$stream = $response->getBody()->getStream();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, if you convert it to use guzzle you can also get the other meta-data from the call which is good for performance in the broader spectrum.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I do "$response->getBody()->" I don't get any "getStream()" function.
I did see it in the previous version of guzzle, but not in the latest one.

How would we pass the fetched metadata to the caching system?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might have to add a method to pipe the response body (which implements the guzzle/streams' StreamInterface to a tmpfile stream. Something along the lines of this:

protected function streamToResource(StreamInterface $stream, $length = 1024)
{
    $resource = tmpfile();

    while ( ! $stream->oef()) {
        fwrite($resource, $stream->read($length));
    }

    return $resource;
}

Also, when the adapters the same thing as the read method does, returning an array with all the data including the stream, the Filesystem class will make sure the caching receives that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then, won't we be downloading the whole file?
Doesn't that defeat part of the purpose of having a stream?
Also, as I understand, the caching (in the Filesystem class) will use the stream to get the metadata. So if we provide a stream to the tmp file, wont the metadata be wrong?

There must be a more elegant way of doing this... I will ask the guzzle project about it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For when you've got more time to deal with this, this is what we'll need to use in order to convert the StreamInterface to a resource: https://github.com/guzzle/streams/blob/master/src/GuzzleStreamWrapper.php#L27

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I did in my last pull request :)
I'm starting to review the comments on that PR now.

@hgraca
Copy link
Author

hgraca commented Jul 8, 2014

I finally found a nice way of doing this and updated the pull request.
Can you guys take another look at it, please?
tkx

*
* @return self
*/
public function setClient(Client $client)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it important to set the Client later on...? I think it should be required while creation/instantiation -> Immutability

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to typehint it as ClientInterface anyway.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staabm I think that the fact that we cant think of a reason now, doesn't mean there won't be a reason to do it at some point. I agree that it is indeed unlikely, but nevertheless... Also, I'm using it inside the constructor, and I don't like accessing properties directly, even if inside the own class.

@GrahamCampbell You are totally right, I will change it.

@GrahamCampbell
Copy link
Member

Should we really be typehinting the GuzzleHttp\Client as GuzzleHttp\ClientInterface where relevant?


EDIT: typewriting => typehinting

@staabm
Copy link

staabm commented Jul 8, 2014

since GuzzleHttp\ClientInterface is provided by guzzle we should use it. I don't think the interface itself does make much sense but thats another story.

@hgraca
Copy link
Author

hgraca commented Jul 22, 2014

Its a good practice to depend on abstractions whenever possible...
I've made some comments and updated the pull request.

@hgraca
Copy link
Author

hgraca commented Aug 21, 2014

@FrenkyNet
How is this one? Do you want me to change something, or can it be merged?

@GrahamCampbell
Copy link
Member

This needs rebasing.

$timestamp = $response->getHeader('Last-Modified');
$contentType = $response->getHeader('Content-Type');

$size = "unknown";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This default value should be removed, it won't be added to the return value if you use compact instead of making the array yourself.

@frankdejonge
Copy link
Member

@hgraca it'll need a rebase before I can merge. I think the rest looks good. We can improve stuff over time to. Like supports for writes.

@GrahamCampbell
Copy link
Member

I'm assuming this new feature will make the next release 0.6.0.

@frankdejonge
Copy link
Member

@GrahamCampbell because it's still a 0.x release cycle this won't be needed. It won't break any integrations. As soon as we hit 1.x, which I want to work to in the near future.

@GrahamCampbell
Copy link
Member

Even during 0.x you're meant to bump the minor version if you add features. aren't you? The only difference with 0.x is that bumping the minor version also is allowed to introduce bc breaks.

@frankdejonge
Copy link
Member

@GrahamCampbell the versioning all moves up a dot, which would make this not a minor, but a patch release. I've maintained pretty strict versioning for Flysystem as a 0.x package, wouldn't you agree? ;)

@GrahamCampbell
Copy link
Member

Semantic versioning says:

Major version zero (0.y.z) is for initial development. Anything may change at any time. The public API should not be considered stable.

Minor version Y (x.Y.z | x > 0) MUST be incremented if new, backwards compatible functionality is introduced to the public API. It MUST be incremented if any public API functionality is marked as deprecated. It MAY be incremented if substantial new functionality or improvements are introduced within the private code. It MAY include patch level changes. Patch version MUST be reset to 0 when minor version is incremented.

What I get from that is that 0.6.0 is needed now?

@frankdejonge
Copy link
Member

What I get from that is that there are no actual rules, with an added adapter the public API doesn't change.

@GrahamCampbell
Copy link
Member

Yeh, it does say MAY rather than MUST, so I guess it's your choice. Can I suggest you change the branch alias back to 0.5 in the composer.json?

@frankdejonge
Copy link
Member

@GrahamCampbell agreed, will do that.

@hgraca
Copy link
Author

hgraca commented Sep 2, 2014

Great, i will try to do that during the weekend. I haven't had the time to follow upon this, was on vacations and i am now on a job quest. 

Enviado de Samsung Mobile

-------- Mensagem original --------
De : Frank de Jonge notifications@github.com
Data:02/09/2014 11:55 (GMT+01:00)
Para: thephpleague/flysystem flysystem@noreply.github.com
Cc: Herberto Graça herberto.graca@gmail.com
Assunto: Re: [flysystem] Implemented HttpAdapter with guzzle (#178)

@hgraca it'll need a rebase before I can merge. I think the rest looks good. We can improve stuff over time to. Like supports for writes.


Reply to this email directly or view it on GitHub.

@GrahamCampbell
Copy link
Member

If you like, I can rebase this and send another pull, retaining your name on the commit?

@hgraca
Copy link
Author

hgraca commented Sep 2, 2014

If you have the time for it, please do.
I am completely overwhelmed by my agenda!! :(

Thank you.

Herberto Graça


http://pt.linkedin.com/pub/herberto-gra%C3%A7a/8/10/b32

2014-09-02 15:21 GMT+02:00 Graham Campbell notifications@github.com:

If you like, I can rebase this and send another pull, retaining your name
on the commit?


Reply to this email directly or view it on GitHub
#178 (comment)
.

@GrahamCampbell
Copy link
Member

I'll have a look at it asap.

@GrahamCampbell
Copy link
Member

@hgraca have you changed your github email address? Github is no longer reconsigning you on any commits.

@GrahamCampbell
Copy link
Member

lkcyrmv

@hgraca
Copy link
Author

hgraca commented Sep 3, 2014

Hi,

That is my account with my current employer, I hadn't set it up with my
account.
It's fixed now.

Herberto Graça


http://pt.linkedin.com/pub/herberto-gra%C3%A7a/8/10/b32

2014-09-02 22:55 GMT+02:00 Graham Campbell notifications@github.com:

[image: lkcyrmv]
https://cloud.githubusercontent.com/assets/2829600/4125614/6f4dd1de-32e3-11e4-98f7-a25a3f2509a5.png


Reply to this email directly or view it on GitHub
#178 (comment)
.

@frankdejonge
Copy link
Member

Merged this into a feature branch.

@hgraca
Copy link
Author

hgraca commented Sep 6, 2014

Cool!
@GrahamCampbell https://github.com/GrahamCampbell Thanks again for
getting this off my shoulders.

Herberto Graça


http://pt.linkedin.com/pub/herberto-gra%C3%A7a/8/10/b32

2014-09-06 12:03 GMT+02:00 Frank de Jonge notifications@github.com:

Closed #178 #178.


Reply to this email directly or view it on GitHub
#178 (comment).

@frankdejonge
Copy link
Member

@hgraca something went weirdly wrong in merging it into a feature branch, I've pulled it out and put it in a feature branch manually, sorry for the inconvenience.

@GrahamCampbell GrahamCampbell mentioned this pull request Jul 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants