Executes the webhook effectively. Resolves with an instance of Message.
@param array  $opts
@param array  $files
@return \React\Promise\ExtendedPromiseInterface
@internal
976255
protected function executeWebhook(array $opts, array $files) {
        return $this->client->apimanager()->endpoints->webhook->executeWebhook($this->id, $this->token, $opts, $files, array('wait' => true))->then(function ($data) {
            $channel = $this->client->channels->get($this->channelID);
            if($channel instanceof \CharlotteDunois\Yasmin\Interfaces\TextChannelInterface) {
                return $channel->_createMessage($data);
            }
            
            return $data;
        });
    }
537793
public function read(array $opts) {
        $translatorevents = [];

        $feedback = parent::parseFeedback($opts);

        // Push question statements to $translatorevents['events'].
        foreach ($feedback->questions as $questionId => $questionAttempt) {
            array_push(
                $translatorevents,
                $this->questionStatement(
                    parent::read($opts)[0],
                    $questionAttempt
                )
            );
        }

        return $translatorevents;
    }
522935
private function parseYamlOptions(array $opts = [])
    {
        if (is_file($this->runner->pwd.'/.phillip.yml')) {
            $options = Yaml::parseFile($this->runner->pwd.'/.phillip.yml');

            return array_merge($opts, $options);
        }

        return $opts;
    }
1186560
function (opts) {
  var paths = es.through();
  var files = es.through();
  
  paths.pipe(es.writeArray(function (err, srcs) {
    gulp.src(srcs, opts).pipe(files);
  }));
  
  return es.duplex(paths, files);
}
331900
public function scan(array $paths, array $options = []): ScanResult
    {
        $this->options = $this->resolveOptions($options);

        try {
            return $this->scanArray($paths);
        } catch (AdapterException $e) {
            // TODO: log virus scanner exception
            return new ScanResult(); // silently fail
        }
    }
598680
function (opts) {
    this.options = opts || {};
    this.pattern = null;
    this.middleware = {};
    this.includes = {};
    this.excludes = {};
    this.files = [];
    this.fns = [];

    options(this);
    iterators(this);
    symlinks(this);
    readers(this);
  }
5847
public function read(array $opts) {
        return array_merge(parent::read($opts), [
            'object' => $this->readModule($opts),
            'context' => [
                'contextActivities' => [
                    'grouping' => [
                        $this->readCourse($opts),
                        $this->readScormScoes($opts),
                    ],
                ],
            ],
        ]);
    }
1318951
private function resolveFile(\DirectoryIterator $file, array &$files)
    {
        if ($file->isDir() && !$file->isDot()) {
            $files = Tools::resolvePath($files, $this->getFileNames());
        }

        if ($file->isFile() && !$file->isLink() && $file->isReadable()) {
            $files = Tools::resolvePath($files, $file->getRealPath());
        }
    }
568924
public function mount(array $opts) {
		if (!isset($opts['path']) || $opts['path'] === '') {
			return $this->setError('Path undefined.');;
		}
		
		$this->options = array_merge($this->options, $opts);
		$this->id = $this->driverId.(!empty($this->options['id']) ? $this->options['id'] : elFinder::$volumesCnt++).'_';
		$this->root = $this->normpathCE($this->options['path']);
		$this->separator = isset($this->options['separator']) ? $this->options['separator'] : DIRECTORY_SEPARATOR;
		
		// set server encoding
		if (!empty($this->options['encoding']) && strtoupper($this->options['encoding']) !== 'UTF-8') {
			$this->encoding = $this->options['encoding'];
		} else {
			$this->encoding = null;
		}
		
		$argInit = ($_SERVER['REQUEST_METHOD'] === 'POST')? !empty($_POST['init']) : !empty($_GET['init']);
		
		// session cache
		if ($argInit || ! isset($_SESSION[elFinder::$sessionCacheKey][$this->id])) {
			$_SESSION[elFinder::$sessionCacheKey][$this->id] = array();
		}
		$this->sessionCache = &$_SESSION[elFinder::$sessionCacheKey][$this->id];
		
		// default file attribute
		$this->defaults = array(
			'read'    => isset($this->options['defaults']['read'])  ? !!$this->options['defaults']['read']  : true,
			'write'   => isset($this->options['defaults']['write']) ? !!$this->options['defaults']['write'] : true,
			'locked'  => isset($this->options['defaults']['locked']) ? !!$this->options['defaults']['locked'] : false,
			'hidden'  => isset($this->options['defaults']['hidden']) ? !!$this->options['defaults']['hidden'] : false
		);

		// root attributes
		$this->attributes[] = array(
			'pattern' => '~^'.preg_quote(DIRECTORY_SEPARATOR).'$~',
			'locked'  => true,
			'hidden'  => false
		);
		// set files attributes
		if (!empty($this->options['attributes']) && is_array($this->options['attributes'])) {
			
			foreach ($this->options['attributes'] as $a) {
				// attributes must contain pattern and at least one rule
				if (!empty($a['pattern']) || count($a) > 1) {
					$this->attributes[] = $a;
				}
			}
		}

		if (!empty($this->options['accessControl']) && is_callable($this->options['accessControl'])) {
			$this->access = $this->options['accessControl'];
		}
		
		$this->today     = mktime(0,0,0, date('m'), date('d'), date('Y'));
		$this->yesterday = $this->today-86400;
		
		// debug($this->attributes);
		if (!$this->init()) {
			return false;
		}
		
		// check some options is arrays
		$this->uploadAllow = isset($this->options['uploadAllow']) && is_array($this->options['uploadAllow'])
			? $this->options['uploadAllow']
			: array();
			
		$this->uploadDeny = isset($this->options['uploadDeny']) && is_array($this->options['uploadDeny'])
			? $this->options['uploadDeny']
			: array();

		if (is_string($this->options['uploadOrder'])) { // telephat_mode on, compatibility with 1.x
			$parts = explode(',', isset($this->options['uploadOrder']) ? $this->options['uploadOrder'] : 'deny,allow');
			$this->uploadOrder = array(trim($parts[0]), trim($parts[1]));
		} else { // telephat_mode off
			$this->uploadOrder = $this->options['uploadOrder'];
		}
			
		if (!empty($this->options['uploadMaxSize'])) {
			$size = ''.$this->options['uploadMaxSize'];
			$unit = strtolower(substr($size, strlen($size) - 1));
			$n = 1;
			switch ($unit) {
				case 'k':
					$n = 1024;
					break;
				case 'm':
					$n = 1048576;
					break;
				case 'g':
					$n = 1073741824;
			}
			$this->uploadMaxSize = intval($size)*$n;
		}
			
		$this->disabled = isset($this->options['disabled']) && is_array($this->options['disabled'])
			? $this->options['disabled']
			: array();
		
		$this->cryptLib   = $this->options['cryptLib'];
		$this->mimeDetect = $this->options['mimeDetect'];

		// find available mimetype detect method
		$type = strtolower($this->options['mimeDetect']);
		$type = preg_match('/^(finfo|mime_content_type|internal|auto)$/i', $type) ? $type : 'auto';
		$regexp = '/text\/x\-(php|c\+\+)/';
	
		if (($type == 'finfo' || $type == 'auto') 
		&& class_exists('finfo')) {
			$tmpFileInfo = @explode(';', @finfo_file(finfo_open(FILEINFO_MIME), __FILE__));
		} else {
			$tmpFileInfo = false;
		}
	
		if ($tmpFileInfo && preg_match($regexp, array_shift($tmpFileInfo))) {
			$type = 'finfo';
			$this->finfo = finfo_open(FILEINFO_MIME);
		} elseif (($type == 'mime_content_type' || $type == 'auto') 
		&& function_exists('mime_content_type')
		&& preg_match($regexp, array_shift(explode(';', mime_content_type(__FILE__))))) {
			$type = 'mime_content_type';
		} else {
			$type = 'internal';
		}
		$this->mimeDetect = $type;

		// load mimes from external file for mimeDetect == 'internal'
		// based on Alexey Sukhotin idea and patch: http://elrte.org/redmine/issues/163
		// file must be in file directory or in parent one 
		if ($this->mimeDetect == 'internal' && !self::$mimetypesLoaded) {
			self::$mimetypesLoaded = true;
			$this->mimeDetect = 'internal';
			$file = false;
			if (!empty($this->options['mimefile']) && file_exists($this->options['mimefile'])) {
				$file = $this->options['mimefile'];
			} elseif (file_exists(dirname(__FILE__).DIRECTORY_SEPARATOR.'mime.types')) {
				$file = dirname(__FILE__).DIRECTORY_SEPARATOR.'mime.types';
			} elseif (file_exists(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'mime.types')) {
				$file = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'mime.types';
			}

			if ($file && file_exists($file)) {
				$mimecf = file($file);

				foreach ($mimecf as $line_num => $line) {
					if (!preg_match('/^\s*#/', $line)) {
						$mime = preg_split('/\s+/', $line, -1, PREG_SPLIT_NO_EMPTY);
						for ($i = 1, $size = count($mime); $i < $size ; $i++) {
							if (!isset(self::$mimetypes[$mime[$i]])) {
								self::$mimetypes[$mime[$i]] = $mime[0];
							}
						}
					}
				}
			}
		}

		$this->rootName = empty($this->options['alias']) ? $this->basenameCE($this->root) : $this->options['alias'];

		// This get's triggered if $this->root == '/' and alias is empty.
		// Maybe modify _basename instead?
		if ($this->rootName === '') $this->rootName = $this->separator;

		$root = $this->stat($this->root);
		
		if (!$root) {
			return $this->setError('Root folder does not exists.');
		}
		if (!$root['read'] && !$root['write']) {
			return $this->setError('Root folder has not read and write permissions.');
		}
		
		// debug($root);
		
		if ($root['read']) {
			// check startPath - path to open by default instead of root
			if ($this->options['startPath']) {
				$start = $this->stat($this->options['startPath']);
				if (!empty($start)
				&& $start['mime'] == 'directory'
				&& $start['read']
				&& empty($start['hidden'])
				&& $this->inpathCE($this->options['startPath'], $this->root)) {
					$this->startPath = $this->options['startPath'];
					if (substr($this->startPath, -1, 1) == $this->options['separator']) {
						$this->startPath = substr($this->startPath, 0, -1);
					}
				}
			}
		} else {
			$this->options['URL']     = '';
			$this->options['tmbURL']  = '';
			$this->options['tmbPath'] = '';
			// read only volume
			array_unshift($this->attributes, array(
				'pattern' => '/.*/',
				'read'    => false
			));
		}
		$this->treeDeep = $this->options['treeDeep'] > 0 ? (int)$this->options['treeDeep'] : 1;
		$this->tmbSize  = $this->options['tmbSize'] > 0 ? (int)$this->options['tmbSize'] : 48;
		$this->URL      = $this->options['URL'];
		if ($this->URL && preg_match("|[^/?&=]$|", $this->URL)) {
			$this->URL .= '/';
		}

		$this->tmbURL   = !empty($this->options['tmbURL']) ? $this->options['tmbURL'] : '';
		if ($this->tmbURL && preg_match("|[^/?&=]$|", $this->tmbURL)) {
			$this->tmbURL .= '/';
		}
		
		$this->nameValidator = !empty($this->options['acceptedName']) && (is_string($this->options['acceptedName']) || is_callable($this->options['acceptedName']))
			? $this->options['acceptedName']
			: '';

		$this->_checkArchivers();
		// manual control archive types to create
		if (!empty($this->options['archiveMimes']) && is_array($this->options['archiveMimes'])) {
			foreach ($this->archivers['create'] as $mime => $v) {
				if (!in_array($mime, $this->options['archiveMimes'])) {
					unset($this->archivers['create'][$mime]);
				}
			}
		}
		
		// manualy add archivers
		if (!empty($this->options['archivers']['create']) && is_array($this->options['archivers']['create'])) {
			foreach ($this->options['archivers']['create'] as $mime => $conf) {
				if (strpos($mime, 'application/') === 0 
				&& !empty($conf['cmd']) 
				&& isset($conf['argc']) 
				&& !empty($conf['ext'])
				&& !isset($this->archivers['create'][$mime])) {
					$this->archivers['create'][$mime] = $conf;
				}
			}
		}
		
		if (!empty($this->options['archivers']['extract']) && is_array($this->options['archivers']['extract'])) {
			foreach ($this->options['archivers']['extract'] as $mime => $conf) {
				if (strpos($mime, 'application/') === 0
				&& !empty($conf['cmd']) 
				&& isset($conf['argc']) 
				&& !empty($conf['ext'])
				&& !isset($this->archivers['extract'][$mime])) {
					$this->archivers['extract'][$mime] = $conf;
				}
			}
		}

		$this->configure();
		// echo $this->uploadMaxSize;
		// echo $this->options['uploadMaxSize'];
		return $this->mounted = true;
	}
511691
public function migrateCleanup($opts = ['migrations' => '']) {
    if ($opts['migrations'] && ($this->migrationSourceFolder() || $this->usesMigrationPlugins)) {
      $migrations = explode(',', $opts['migrations']);
      $project_properties = $this->getProjectProperties();

      foreach ($migrations as $migration) {
        $this->taskExec('drush mrs ' . $migration)
          ->dir($project_properties['web_root'])
          ->run();
      }
    }
    if ($this->migrationSourceFolder()) {
      $this->taskExec('drush mr --all && drush cim --partial --source=' . $this->migrationSourceFolder() . ' -y && drush ms')
        ->dir($project_properties['web_root'])
        ->run();
    }
    else if ($this->usesMigrationPlugins) {
      $this->taskExec('drush cr && drush mr --all && drush ms')
        ->dir($project_properties['web_root'])
        ->run();
    }
    else {
      $this->say('No migration sources configured.');
      $this->say('To use this command, you must either return a folder path from the migrationSourceFolder() method or set $usesMigrationPlugins to TRUE in your project\'s RoboFile.php.');
      return FALSE;
    }
  }
1072299
public function build($array, $opts = array())
	{
		$this->debug->groupCollapsed(__CLASS__.'->'.__FUNCTION__);
		$opts = array_merge(array(
			'xml_tag'		=> false,
			'xml_version'	=> '1.0',
			'xml_encoding'	=> 'utf-8',
			'empty_tags'	=> false,
			'empty_attribs' => false,
			'indent'		=> "\t",
			'wrap_tag'		=> null,
			'wrap_attribs'	=> array(),
			'debug_group'	=> false,
		), $opts);
		$w = new \XMLWriter();
		$w->openMemory();
		if ($opts['indent']) {
			$w->setIndent(true);
			$w->setIndentString("\t");
		}
		if ($opts['xml_tag']) {
			$w->startDocument($opts['xml_version'], $opts['xml_encoding']);
		}
		if ($opts['wrap_tag']) {
			$w->startElement($opts['wrap_tag']);
			foreach ($opts['wrap_attribs'] as $k => $v) {
				$w->writeAttribute($k, $v);
			}
		}
		$path = array();
		$levels = array(
			array(
				'startElement'		=> false,
				'keys'				=> array_keys($array),
				'pointer_source'	=> &$array,
			),
		);
		while (!empty($levels)) {
			$level =& $levels[count($levels)-1];
			if (empty($level['prepped'])) {
				#$this->debug->log('prepping');
				$level['prepped'] = true;
				#$this->debug->log('path', implode('/', $path));
				// make sure attribs is first in keys
				$key = array_search('attribs', $level['keys']);
				if ($key > 0) {
					unset($level['keys'][$key]);
					array_unshift($level['keys'], 'attribs');
				}
			}
			if (!empty($level['keys'])) {
				$key = array_shift($level['keys']);
				$val = &$level['pointer_source'][$key];
				$name = $key;
				if (is_int($key)) {
					$name = is_array($val) && isset($val['tag'])
						? $val['tag']
						: $path[count($path)-1];
				}
				#$this->debug->log('name a',$name);
				$collapsed = true;
				if (is_array($val)) {
					foreach ($val as $k => $v) {
						if (substr($k, 0, 1) == '_' && $k != '_text') {
							$k2 = substr($k, 1);
							$level['pointer_source'][$key]['attribs'][$k2] = $v;
							unset($level['pointer_source'][$key][$k]);
						}
					}
					if (isset($val['tag']) || isset($val['nodes']) || isset($val['text'])) {
						$collapsed = false;
						if (isset($val['tag'])) {
							$name = $val['tag'];
						}
						if (isset($val['prefix'])) {
							$name = $val['prefix'].':'.$name;
						}
					}
				}
				#$this->debug->log('name b',$name);
				if ($val === null || $val === array() || $val === '') {
					if ($opts['empty_tags']) {
						$w->writeElement($name, $val);
					}
					// else
					//	$this->debug->log('skip '.$key);
				} elseif (is_string($val) && $key === 'text') {
					$val = Str::toUtf8($val);
					$w->text($val);
				} elseif (is_array($val) && $key === 'attribs') {
					foreach ($val as $k => $v) {
						if (is_null($v)) {
							continue;
						}
						$w->writeAttribute($k, $v);
					}
				} elseif (is_array($val)) {
					if ($opts['debug_group']) {
						$this->debug->groupCollapsed($key);
					}
					#$this->debug->log('collapsed', $collapsed);
					if ($collapsed) {
						$level_new = array(
							'startElement'		=> ArrayUtil::isHash($val),
							'keys'				=> array_keys($val),
							'pointer_source'	=> &$level['pointer_source'][$key],
						);
					} else {
						$level_new = array(
							'startElement'		=> true,
							'keys'				=> !empty($val['nodes'])
														? array_keys($val['nodes'])
														: array(),
							'pointer_source'	=> isset($val['text'])
														? $val['text']
														: null,
						);
						if (!empty($val['nodes'])) {
							$level_new['pointer_source'] =& $level['pointer_source'][$key]['nodes'];
						}
					}
					#$this->debug->log('level_new', $level_new);
					$levels[] = $level_new;
					$path[] = $key;
					if ($level_new['startElement']) {
						$w->startElement($name);
						if (!$collapsed && !empty($val['attribs'])) {
							foreach ($val['attribs'] as $k => $v) {
								$w->writeAttribute($k, $v);
							}
						}
						if (empty($level_new['keys']) && isset($level_new['pointer_source']) && $level_new['pointer_source'] !== '') {
							$w->text($level_new['pointer_source']);
						}
					}
				} else {
					if ($name == '_text') {
						$name = 'text';
					}
					$val = Str::toUtf8($val);
					$w->writeElement($name, $val);
				}
			} else {
				array_pop($levels);
				$p = array_pop($path);
				if ($level['startElement']) {
					$w->endElement();
				}
				if ($opts['debug_group'] && $p !== null) {
					$this->debug->groupEnd();
				}
			}
		}
		if ($opts['wrap_tag']) {
			$w->endElement();
		}
		if ($opts['xml_tag']) {
			$w->endDocument();
		}
		$xml = $w->flush();
		if (!$opts['empty_tags']) {
			$xml = preg_replace('#'.$opts['indent'].'*<[\w:]+/>\n#', '', $xml);
		}
		$this->debug->groupEnd();
		return $xml;
	}
861387
public function requireFiles($path, array $files)
    {
        foreach ($files as $file) {
            $this->files->requireOnce($path .DS .$file .'.php');
        }
    }
1222166
public function execute($files)
  {
    printLn('=> PageWriter.');
    $pages = Application::db()->retrieve('page_list');

    $writer = new DataWriter();

    foreach($pages as $page) {
      $tmpl = $this->make_data($page);
      $writer->write($tmpl['slug'], 'index.html', $tmpl['html']);
    }
  }
1287912
private static function call(array $files, $folder, $ext = 'php')
    {
        foreach ($files as $file) {
            static::need($folder.$file.'.'.$ext);
        }
    }
49525
public function send($uri, $method, array $headers = [], $datas = [], array $files = [])
    {
        return $this->sendRequest($this->getConfiguration()->getMessageFactory()->createInternalRequest(
            $uri,
            $method,
            $this->getConfiguration()->getProtocolVersion(),
            $headers,
            $datas,
            $files
        ));
    }
601912
static function resolveMessageOptionsFiles(array $options) {
        if(empty($options['files'])) {
            return \React\Promise\resolve(array());
        }
        
        $promises = array();
        foreach($options['files'] as $file) {
            if($file instanceof \CharlotteDunois\Yasmin\Models\MessageAttachment) {
                $file = $file->_getMessageFilesArray();
            }
            
            if(\is_string($file)) {
                if(\filter_var($file, \FILTER_VALIDATE_URL)) {
                    $promises[] = \CharlotteDunois\Yasmin\Utils\URLHelpers::resolveURLToData($file)->then(function ($data) use ($file) {
                        return array('name' => \basename($file), 'data' => $data);
                    });
                } elseif(\realpath($file)) {
                    $promises[] = \CharlotteDunois\Yasmin\Utils\FileHelpers::resolveFileResolvable($file)->then(function ($data) use ($file) {
                        return array('name' => \basename($file), 'data' => $data);
                    });
                } else {
                    $promises[] = \React\Promise\resolve(array('name' => 'file-'.\bin2hex(\random_bytes(3)).'.jpg', 'data' => $file));
                }
                
                continue;
            }
            
            if(!\is_array($file)) {
                continue;
            }
            
            if(!isset($file['data']) && !isset($file['path'])) {
                throw new \InvalidArgumentException('Invalid file array passed, missing data and path, one is required');
            }
            
            if(!isset($file['name'])) {
                if(isset($file['path'])) {
                    $file['name'] = \basename($file['path']);
                } else {
                    $file['name'] = 'file-'.\bin2hex(\random_bytes(3)).'.jpg';
                }
            }
            
            if(isset($file['path'])) {
                if(filter_var($file['path'], \FILTER_VALIDATE_URL)) {
                    $promises[] = \CharlotteDunois\Yasmin\Utils\URLHelpers::resolveURLToData($file['path'])->then(function ($data) use ($file) {
                        $file['data'] = $data;
                        return $file;
                    });
                } elseif(\CharlotteDunois\Yasmin\Utils\FileHelpers::getFilesystem()) {
                    $promises[] = \CharlotteDunois\Yasmin\Utils\FileHelpers::getFilesystem()->getContents($file['path'])->then(function ($data) use ($file) {
                        $file['data'] = $data;
                        return $file;
                    });
                } else {
                    $file['data'] = \file_get_contents($file['path']);
                    $promises[] = \React\Promise\resolve($file);
                }
            } else {
                $promises[] = \React\Promise\resolve($file);
            }
        }
        
        return \React\Promise\all($promises);
    }
424837
public function options($uri, array $headers = [], $datas = [], array $files = [])
    {
        return $this->send($uri, InternalRequestInterface::METHOD_OPTIONS, $headers, $datas, $files);
    }