elFinder\elFinder::exec PHP Method

exec() public method

Exec command and return result
Author: Dmitry (dio) Levashov
public exec ( string $cmd, array $args ) : array
$cmd string command name
$args array command arguments
return array
    public function exec($cmd, $args)
    {
        if (!$this->loaded) {
            return array('error' => $this->error(self::ERROR_CONF, self::ERROR_CONF_NO_VOL));
        }
        if (!$this->commandExists($cmd)) {
            return array('error' => $this->error(self::ERROR_UNKNOWN_CMD));
        }
        if (!empty($args['mimes']) && is_array($args['mimes'])) {
            foreach ($this->volumes as $id => $v) {
                $this->volumes[$id]->setMimesFilter($args['mimes']);
            }
        }
        $result = $this->{$cmd}($args);
        if (isset($result['removed'])) {
            foreach ($this->volumes as $volume) {
                $result['removed'] = array_merge($result['removed'], $volume->removed());
                $volume->resetRemoved();
            }
        }
        // call handlers for this command
        if (!empty($this->listeners[$cmd])) {
            foreach ($this->listeners[$cmd] as $handler) {
                if (call_user_func($handler, $cmd, $result, $args, $this)) {
                    // handler return true to force sync client after command completed
                    $result['sync'] = true;
                }
            }
        }
        // replace removed files info with removed files hashes
        if (!empty($result['removed'])) {
            $removed = array();
            foreach ($result['removed'] as $file) {
                $removed[] = $file['hash'];
            }
            $result['removed'] = array_unique($removed);
        }
        // remove hidden files and filter files by mimetypes
        if (!empty($result['added'])) {
            $result['added'] = $this->filter($result['added']);
        }
        // remove hidden files and filter files by mimetypes
        if (!empty($result['changed'])) {
            $result['changed'] = $this->filter($result['changed']);
        }
        if ($this->debug || !empty($args['debug'])) {
            $result['debug'] = array('connector' => 'php', 'phpver' => PHP_VERSION, 'time' => $this->utime() - $this->time, 'memory' => (function_exists('memory_get_peak_usage') ? ceil(memory_get_peak_usage() / 1024) . 'Kb / ' : '') . ceil(memory_get_usage() / 1024) . 'Kb / ' . ini_get('memory_limit'), 'upload' => $this->uploadDebug, 'volumes' => array(), 'mountErrors' => $this->mountErrors);
            foreach ($this->volumes as $id => $volume) {
                $result['debug']['volumes'][] = $volume->debug();
            }
        }
        foreach ($this->volumes as $volume) {
            $volume->umount();
        }
        return $result;
    }