Skip to content

[VarDumper] Added support for SplFileInfo #14424

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

Merged
merged 2 commits into from
Apr 22, 2015

Conversation

lyrixx
Copy link
Member

@lyrixx lyrixx commented Apr 20, 2015

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets ~
License MIT
Doc PR ~

Before:

SplFileInfo {#3}

After:

SplFileInfo {#3
  path: "/home/greg/dev/github.com/lyrixx/gaga-photo/fixtures"
  filename: "grisou.jpg"
  basename: "grisou.jpg"
  pathname: "/home/greg/dev/github.com/lyrixx/gaga-photo/fixtures/grisou.jpg"
  extension: "jpg"
  realPath: "/home/greg/dev/github.com/lyrixx/gaga-photo/fixtures/grisou.jpg"
  aTime: 2015-04-20 23:21:15
  mTime: 2014-08-17 15:37:36
  cTime: 2015-04-20 23:09:51
  inode: 12197643
  size: 966553
  perms: 0100750
  owner: 1000
  group: 1000
  type: "file"
  writable: true
  readable: true
  executable: true
  file: true
  dir: false
  link: false
}

For a link:

SplFileInfo {#3
  path: ""
  filename: "link"
  basename: "link"
  pathname: "link"
  extension: ""
  realPath: "/home/greg/dev/github.com/symfony/var-dumper/composer.json"
  aTime: 2015-04-20 23:39:15
  mTime: 2015-04-20 23:39:15
  cTime: 2015-04-20 23:39:15
  inode: 11272232
  size: 967
  perms: 0100644
  owner: 1000
  group: 1000
  type: "link"
  writable: true
  readable: true
  executable: false
  file: true
  dir: false
  link: true
  linkTarget: "composer.json"
}

For a remote file:

SplFileInfo {#3
  path: "http://google.com"
  filename: "foobar.php"
  basename: "foobar.php"
  pathname: "http://google.com/foobar.php"
  extension: "php"
  realPath: false
  writable: false
  readable: false
  executable: false
  file: false
  dir: false
  link: false
}

For a CSV:

SplFileObject {#3
  path: ""
  filename: "test.csv"
  basename: "test.csv"
  pathname: "test.csv"
  extension: "csv"
  realPath: "/home/greg/dev/github.com/symfony/var-dumper/test.csv"
  aTime: 2015-04-21 12:55:07
  mTime: 2015-04-21 12:55:07
  cTime: 2015-04-21 12:55:07
  inode: 11272237
  size: 0
  perms: 0100644
  owner: 1000
  group: 1000
  type: "file"
  writable: true
  readable: true
  executable: false
  file: true
  dir: false
  link: false
  csvControl: array:2 [
    0 => ","
    1 => """
  ]
  flags: SKIP_EMPTY|READ_CSV
  maxLineLen: 0
  fstat: array:7 [
    "dev" => 64513
    "ino" => 11272237
    "nlink" => 1
    "rdev" => 0
    "blksize" => 4096
    "blocks" => 0
    "…" => "…20"
  ]
  eof: false
  key: 0
}

@dunglas
Copy link
Member

dunglas commented Apr 21, 2015

👍

@lyrixx
Copy link
Member Author

lyrixx commented Apr 21, 2015

I also added support for SplFileObject

@stof
Copy link
Member

stof commented Apr 21, 2015

What about tests ?

@javiereguiluz
Copy link
Member

👍 this is great @lyrixx!

I have a proposal: could it be possible to show some of the information in a human-friendly way? Example:

Symfony\Component\Finder\SplFileInfo {#69
  basename: "grisou.jpg"
  filename: "grisou.jpg"
  extension: "jpg"
  path: "fixtures"
  pathname: "fixtures/grisou.jpg"
  realPath: "/home/greg/dev/github.com/lyrixx/gaga-photo/fixtures/grisou.jpg"
  perms: 33256 (rwxr-xr-x)
  inode: 12197643
  size: 966553 bytes (0.96 MB)
  owner: 1000
  group: 1000
  aTime: 1429564875 (April 20, 2015 23:21:15)
  mTime: 1408282656 (August 17, 2014 15:37:36)
  cTime: 1429564191 (April 20, 2015 23:09:51)
  type: "file"
  writable: true
  readable: true
  executable: true
  file: true
  dir: false
  link: false
}

Changes:

  • All the filename, extension, path, etc. properties are grouped at the beginning.
  • File size is showed in the original bytes length and in the "human size" (MB, KB, etc.)
  • Dates are displayed in the original timestamp and in understandable format.
  • Perms are also transformed to the usual human format.

@lyrixx
Copy link
Member Author

lyrixx commented Apr 21, 2015

@javiereguiluz Oups, I did not updated the "sample" but most of your comments are already addressed.

@Green-Cat
Copy link

👍

@javiereguiluz
Copy link
Member

@lyrixx awesome! Thanks.

@lyrixx
Copy link
Member Author

lyrixx commented Apr 21, 2015

@javiereguiluz I updated the description, and move some "property"

@lyrixx lyrixx force-pushed the vd-SplFileInfo branch 2 times, most recently from cd4c132 to 8c21de4 Compare April 21, 2015 10:38
@aitboudad
Copy link
Contributor

👍

@lyrixx lyrixx force-pushed the vd-SplFileInfo branch 2 times, most recently from 3783f52 to 07d8151 Compare April 21, 2015 10:53
@lyrixx
Copy link
Member Author

lyrixx commented Apr 21, 2015

I had to rework the implementation to not throw exception when the file is special (link a remote file)

@stof
Copy link
Member

stof commented Apr 21, 2015

-1 until tests are not added (I'm putting an explicit -1 vote here as other voters seems to validate it without tests, which is not a good idea).

Otherwise, the idea is good

@lyrixx
Copy link
Member Author

lyrixx commented Apr 21, 2015

@stof you should be happy now ;)

@lyrixx
Copy link
Member Author

lyrixx commented Apr 21, 2015

Travis is green, but fabbot is KO...

@nicolas-grekas
Copy link
Member

👍

@stof
Copy link
Member

stof commented Apr 21, 2015

@lyrixx it would be great to avoid setting non-working links in the fabbot commit status for pending builds (either not setting the URL if Travis supports it, or making the page valid, saying that the inspection is in progress)

@stof
Copy link
Member

stof commented Apr 21, 2015

👍

@lyrixx what about adding the support for Symfony\Component\Finder\SplFileInfo too, which adds the relative path too ?

@lyrixx
Copy link
Member Author

lyrixx commented Apr 21, 2015

@stof It's already supported because the VarDumper is awesome ;)
(It starts by casting the "higher" extended class to finish by the current class, and because the Symfony\Component\Finder\SplFileInfo is "just" a regular class with private attribute, it just works)

<?php

require __DIR__.'/vendor/autoload.php';

$f = new Symfony\Component\Finder\SplFileInfo(__FILE__, 'relativePath', 'relativePathname');
die(dump($f));

=>

Symfony\Component\Finder\SplFileInfo {#4
  -relativePath: "relativePath"
  -relativePathname: "relativePathname"
  path: "/home/greg/dev/github.com/symfony/symfony"
  filename: "test.php"
  basename: "test.php"
  pathname: "/home/greg/dev/github.com/symfony/symfony/test.php"
  extension: "php"
  realPath: "/home/greg/dev/github.com/symfony/symfony/test.php"
  aTime: 2015-04-21 20:05:29
  mTime: 2015-04-21 20:05:27
  cTime: 2015-04-21 20:05:27
  inode: 12851779
  size: 157
  perms: 0100644
  owner: 1000
  group: 1000
  type: "file"
  writable: true
  readable: true
  executable: false
  file: true
  dir: false
  link: false
}

@nicolas-grekas
Copy link
Member

Thank you @lyrixx.

@nicolas-grekas nicolas-grekas merged commit e75c233 into symfony:2.8 Apr 22, 2015
nicolas-grekas added a commit that referenced this pull request Apr 22, 2015
This PR was merged into the 2.8 branch.

Discussion
----------

[VarDumper] Added support for SplFileInfo

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | ~
| License       | MIT
| Doc PR        | ~

Before:
```
SplFileInfo {#3}
```

After:
```
SplFileInfo {#3
  path: "/home/greg/dev/github.com/lyrixx/gaga-photo/fixtures"
  filename: "grisou.jpg"
  basename: "grisou.jpg"
  pathname: "/home/greg/dev/github.com/lyrixx/gaga-photo/fixtures/grisou.jpg"
  extension: "jpg"
  realPath: "/home/greg/dev/github.com/lyrixx/gaga-photo/fixtures/grisou.jpg"
  aTime: 2015-04-20 23:21:15
  mTime: 2014-08-17 15:37:36
  cTime: 2015-04-20 23:09:51
  inode: 12197643
  size: 966553
  perms: 0100750
  owner: 1000
  group: 1000
  type: "file"
  writable: true
  readable: true
  executable: true
  file: true
  dir: false
  link: false
}
```

For a link:

```
SplFileInfo {#3
  path: ""
  filename: "link"
  basename: "link"
  pathname: "link"
  extension: ""
  realPath: "/home/greg/dev/github.com/symfony/var-dumper/composer.json"
  aTime: 2015-04-20 23:39:15
  mTime: 2015-04-20 23:39:15
  cTime: 2015-04-20 23:39:15
  inode: 11272232
  size: 967
  perms: 0100644
  owner: 1000
  group: 1000
  type: "link"
  writable: true
  readable: true
  executable: false
  file: true
  dir: false
  link: true
  linkTarget: "composer.json"
}
```

For a remote file:

```
SplFileInfo {#3
  path: "http://google.com"
  filename: "foobar.php"
  basename: "foobar.php"
  pathname: "http://google.com/foobar.php"
  extension: "php"
  realPath: false
  writable: false
  readable: false
  executable: false
  file: false
  dir: false
  link: false
}
```

For a CSV:
```
SplFileObject {#3
  path: ""
  filename: "test.csv"
  basename: "test.csv"
  pathname: "test.csv"
  extension: "csv"
  realPath: "/home/greg/dev/github.com/symfony/var-dumper/test.csv"
  aTime: 2015-04-21 12:55:07
  mTime: 2015-04-21 12:55:07
  cTime: 2015-04-21 12:55:07
  inode: 11272237
  size: 0
  perms: 0100644
  owner: 1000
  group: 1000
  type: "file"
  writable: true
  readable: true
  executable: false
  file: true
  dir: false
  link: false
  csvControl: array:2 [
    0 => ","
    1 => """
  ]
  flags: SKIP_EMPTY|READ_CSV
  maxLineLen: 0
  fstat: array:7 [
    "dev" => 64513
    "ino" => 11272237
    "nlink" => 1
    "rdev" => 0
    "blksize" => 4096
    "blocks" => 0
    "…" => "…20"
  ]
  eof: false
  key: 0
}

Commits
-------

e75c233 [VarDumper] Added support for SplFileObject
eb50b13 [VarDumper] Added support for SplFileInfo
@lyrixx lyrixx deleted the vd-SplFileInfo branch April 22, 2015 09:43
@fabpot fabpot mentioned this pull request Nov 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants