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

Get object of vfsStreamFile to get the file content #48

Closed
harikt opened this issue Nov 17, 2012 · 5 comments
Closed

Get object of vfsStreamFile to get the file content #48

harikt opened this issue Nov 17, 2012 · 5 comments

Comments

@harikt
Copy link

harikt commented Nov 17, 2012

I have created a directory structure like

$structure = array(
    'tmp' => array(
        // put an inner view in 'foo'
        'foo' => array(
            'inner_view.php' => '<strong><?= $this->inner_var; ?></strong>'
        ),
        'bar',
        // put an outer view in 'baz'
        'baz' => array(
            'outer_view.php' => '<div><?php echo $this->outer_var . " " . $this->__raw()->inner_view; ?></div>'
         ),
     )
);

    $this->root = vfsStream::setup('root', null, $structure);

Now how can I get the content. I am seeing the vfsStreamFile class. But wondering how is the way I can get the object of it from the directory . Didn't noticed any :( .

@mikey179
Copy link
Member

Hm, what do you want to achieve? You can get the file content either via

file_get_contents(vfsStream::url('root/tmp/foo/inner_view.php'))

or via

$this->root->getChild('tmp/foo/inner_view.php')->getContent()

@harikt
Copy link
Author

harikt commented Nov 19, 2012

Thank you @mikey179 . That was a great help. I spend sometime to figure it. But I failed to get it also :) .

What I was trying to achieve is for Aura.View auraphp/Aura.View#8 .

Currently we have a getRealPath() issue and also there is a require in fetch method which seems will not work.

Do you have any suggestions for it?

@mikey179
Copy link
Member

Unfortunately I can't do anything about the realpath issue, it's a limitation of PHP. I would be glad if I could add support for this. The only recommendation I can give is to mock the whole fileExists() method with a partial mock of the class.

The require should actually work. It may depend on your PHP ini configuration, probably you need to allow including files via vfs:// protocol.

@harikt
Copy link
Author

harikt commented Nov 20, 2012

Thank you @mikey179 for your tips. @pmjones has fixed it.
Thanks once again for the awesome tool. I will try to understand more and come up with something :) ,
Closing the issue as things got resolved.

@harikt harikt closed this as completed Nov 20, 2012
@harikt
Copy link
Author

harikt commented Nov 20, 2012

What we did was we changed to is_readable check for fileExists .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants