Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
What's wrong with \File class or with me?
  • I want to make some class that uses \File, but it has own config. So, I tried to use dynamic config of my area as it shown on this page https://fuelphp.com/docs/classes/file/advanced.html

    public function dir($path)
    {
            $upload_dir = $this->_config['upload_dir'];
            $config = [
                'basedir'   => $upload_dir,
                'use_locks' => true
            ];

            $area = \File::forge($config);

            $files = $area->read_dir($path, 1, null);
    ...
    }

    Then I expected to get $files as array and use

    foreach ($files as $dir => $file) { ... }

    but iteration does not perform. Furthermore $files is instance of File_Handler_Directory class... another $files->read() returns again instance of File_Handler_Directory... So, how can I get array finally?

    Thank you.
  • It's closed circuit... In class File_Area:

    public function read_dir($path, $depth = 0, $filter = null)
        {
            $content = \File::read_dir($path, $depth, $filter, $this);
            return $this->get_handler($path, array(), $content);
        }

    we get the handler (File_Handler_Directory in my case).

    In class File_Handler_Directory:

    public function read($depth = 0, $filters = null)
        {
            return $this->area->read_dir($this->path, $depth, $filters, $this->area);
        }

    we again call read_dir from File_Area and again get the handler. It is strange as for me...

    But I found the solution, how to use it:

    public function dir($path)
    {
            $upload_dir = $this->_config['upload_dir'];
            $config = [
                'basedir'   => $upload_dir,
                'use_locks' => true
            ];

            $area = \File::forge($config);

            $files = \File::read_dir($path, 1, null, $area);
    ....
    }

    It works...
  • Harro VertonHarro Verton
    Accepted Answer
    The short answer: I have absolutely now clue.

    I can see that the array is created, and is passed to File_Handler_Directory, where it is stored in the "content" property. But there is no code in that class that does anything with that property?

    From what it looks like, someone has started work encapsulating results in an object instead of returning an array. The File_Handler_File class doesn't even store the content passed, so that is useless to.

    Interesting that after 8 years someone bumps into this... ;-)

    I think the Area class should be changed to:

    public function read_dir($path, $depth = 0, $filter = null)
    {
    return \File::read_dir($path, $depth, $filter, $this);
    }

    so it works again as originally intended.

    I've created https://github.com/fuel/core/issues/2123 to have a look at this.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion