A version of `connectionFromArraySlice` that takes a promised array slice,
and returns a promised connection.

@param mixed          $dataPromise a promise
@param array|Argument $args
@param array          $meta

@return mixed a promise
495905
public function connectionFromPromisedArraySlice($dataPromise, $args, array $meta)
    {
        $this->checkPromise($dataPromise);

        return $dataPromise->then(function ($arraySlice) use ($args, $meta) {
            return $this->connectionFromArraySlice($arraySlice, $args, $meta);
        });
    }
259751
function(args, connectionInfo) {
  // args.consignmentIdToProductIdMap.value MUST already be set by the caller
  // args.consignmentProductId.value MUST be set for the very first call
  args.arrayIndex = {value: 0};
  args.consignmentProductId = {value: args.consignmentIdToProductIdMap.value[args.arrayIndex.value].productId};
  args.getArray = function(){
    return this.consignmentIdToProductIdMap.value;
  };
  args.getArrayIndex = function(){
    return this.arrayIndex.value;
  };

  // iterate serially through a promise chain for all args.consignmentIds.value
  return utils.processPromisesSerially(
    args.getArray(),
    args.getArrayIndex(),
    args,
    function mergeStrategy(newData, previousData, args){
      log.debug('resolveMissingSuppliers - inside mergeStrategy()');
      var product = newData.products[0];
      //log.silly('newData: ', newData);
      //log.silly('product: ', product);
      var updateMe = args.getArray()[args.getArrayIndex()];
      updateMe.supplier = product.supplier_name || product.supplier_code;
      log.debug('updated consignmentIdToProductIdMap: ', args.getArray()[args.getArrayIndex()]);

      previousData = args.getArray();
      return Promise.resolve(previousData); // why do we need a promise?
    },
    function setupNext(updateArgs){
      log.debug('resolveMissingSuppliers - inside setupNext()');
      updateArgs.arrayIndex.value = updateArgs.getArrayIndex() + 1;
      if (updateArgs.getArrayIndex() < updateArgs.getArray().length) {
        updateArgs.consignmentProductId.value = updateArgs.getArray()[updateArgs.getArrayIndex()].productId;
        log.debug('resolveMissingSuppliers - next is consignmentId: ' + updateArgs.consignmentProductId.value);
      }
      else {
        updateArgs.consignmentProductId.value = null;
        log.debug('resolveMissingSuppliers - finished iterating through all the consignmentIds');
      }
      return updateArgs;
    },
    function executeNext(updatedArgs){
      log.debug('resolveMissingSuppliers - inside executeNext()');
      log.debug('resolveMissingSuppliers - executing for consignmentProductId: ' + updatedArgs.consignmentProductId.value);
      //log.silly('updatedArgs: ', updatedArgs);
      var args = argsForInput.products.fetchById();
      args.apiId.value = updatedArgs.consignmentProductId.value;
      return product.endpoints.fetchProduct(args, connectionInfo);
    }
  );
}
622826
public function selectList($meta, ...$args)
    {
        if (!$args) {
            throw new \InvalidArgumentException();
        }
        
        $fields = null;
        $query = null;
        if (!isset($args[1]) && $args[0] instanceof Query\Select) {
            $query = $args[0];
        }
        elseif ((is_array($args[0]) || is_string($args[0])) && !isset($args[2])) {
            $fields = $args[0];
            $query = isset($args[1]) ? $args[1] : null;
        }
        else {
            throw new \InvalidArgumentException();
        }

        $query = $query instanceof Query\Select ? $query : Query\Select::fromParamArgs([$query]);
        if ($fields) {
            $query->fields = $fields;
        }
        if (!$query->fields) {
            throw new \InvalidArgumentException();
        }
        $singleMode = false;
        if (is_string($query->fields)) {
            $singleMode = true;
            $query->fields = [$query->fields];
        }

        $mapper = $this->mapper;
        $meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;

        list ($sql, $params, $props) = $query->buildQuery($meta);
        if ($props) {
            $params = $this->mapper->formatParams($meta, $props, $params);
        }

        $stmt = $this->getConnector()->prepare($sql)->execute($params);

        $mappedRows = [];
        while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
            $mappedRow = $mapper->mapRowToProperties($meta, $row);
            if ($singleMode) {
                $mappedRows[] = current($mappedRow);
            } else {
                $mappedRows[] = $mappedRow;
            }
        }

        return $mappedRows;
    }
638267
public function postConnect(ConnectionEventArgs $args)
    {
        $db = $args->getConnection();
        $platform = $args->getDatabasePlatform();
        $platformName = $platform->getName();

        if ($platformName === 'sqlite') {
            $db->query('PRAGMA synchronous = OFF');
        } elseif ($platformName === 'mysql') {
            /** @see http://docs.doctrine-project.org/en/latest/cookbook/mysql-enums.html */
            $platform->registerDoctrineTypeMapping('enum', 'string');

            // Set database character set & collation as configured
            $charset = $this->config->get('general/database/charset');
            $collation = $this->config->get('general/database/collate');
            $db->executeQuery('SET NAMES ? COLLATE ?', [$charset, $collation], [PDO::PARAM_STR]);

            // Increase group_concat_max_len to 100000. By default, MySQL
            // sets this to a low value – 1024 – which causes issues with
            // certain Bolt content types – particularly repeaters – where
            // the outcome of a GROUP_CONCAT() query will be more than 1024 bytes.
            // See also: http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_group_concat_max_len
            $groupConcatMaxLen = $this->config->get('general/database/group_concat_max_len', 100000);
            $db->executeQuery('SET SESSION group_concat_max_len = ?', [$groupConcatMaxLen], [PDO::PARAM_INT]);
        } elseif ($platformName === 'postgresql') {
            /** @see https://github.com/doctrine/dbal/pull/828 */
            $db->executeQuery("SET NAMES 'utf8'");
        }
    }
827638
public function insert($args) {
        if (empty($args)) {
            Garp_Cli::errorOut('Please provide a model');
            return false;
        }

        $className = "Model_{$args[0]}";
        $model = new $className();
        $fields = $model->getConfiguration('fields');
        $fields = array_filter($fields, not(propertyEquals('name', 'id')));

        $mode = $this->_getInsertionMode();
        if ($mode === 'g') {
            $newData = $this->_createGibberish($fields);
        } else {
            $newData = array_reduce(
                $fields,
                function ($acc, $cur) {
                    $acc[$cur['name']] = Garp_Cli::prompt($cur['name']) ?: null;
                    return $acc;
                },
                array()
            );
        }

        $id = $model->insert($newData);
        Garp_Cli::lineOut("Record created: #{$id}");
        return true;
    }
297862
function forEachPromise(items, fn) {
  return items.reduce(
    (promise, item) => promise
      .then(() => fn(item))
      .catch((error) => { throw error; }),
    Promise.resolve()
  );
}
516161
protected function preserialiseDateFields (array $args = array()) {
		$data = array();

		if (Entity::argIsTrue($args, "entity.include_meta_dates")) {
			$data["date_created"] = $this -> date_created -> getTimestamp();
			$data["date_updated"] = $this -> date_updated -> getTimestamp();
		}

		return $data;
	}
1324142
public function run($args)
	{
		if(!isset($args[0]))
		{
			echo "Error: data model class is required.\n";
			echo $this->getHelp();
			return 1;
		}
		$module=Yii::app();
		$modelClass=$args[0];
		if(($pos=strpos($modelClass,'.'))===false)
			$modelClass='application.models.'.$modelClass;
		else
		{
			$id=substr($modelClass,0,$pos);
			if(($m=Yii::app()->getModule($id))!==null)
				$module=$m;
		}
		$modelClass=Yii::import($modelClass);

		if(isset($args[1]))
		{
			$controllerID=$args[1];
			if(($pos=strrpos($controllerID,'/'))===false)
			{
				$controllerClass=ucfirst($controllerID).'Controller';
				$controllerFile=$module->controllerPath.DIRECTORY_SEPARATOR.$controllerClass.'.php';
				$controllerID[0]=strtolower($controllerID[0]);
			}
			else
			{
				$last=substr($controllerID,$pos+1);
				$last[0]=strtolower($last);
				$pos2=strpos($controllerID,'/');
				$first=substr($controllerID,0,$pos2);
				$middle=$pos===$pos2?'':substr($controllerID,$pos2+1,$pos-$pos2);

				$controllerClass=ucfirst($last).'Controller';
				$controllerFile=($middle===''?'':$middle.'/').$controllerClass.'.php';
				$controllerID=$middle===''?$last:$middle.'/'.$last;
				if(($m=Yii::app()->getModule($first))!==null)
					$module=$m;
				else
				{
					$controllerFile=$first.'/'.$controllerFile;
					$controllerID=$first.'/'.$controllerID;
				}

				$controllerFile=$module->controllerPath.DIRECTORY_SEPARATOR.str_replace('/',DIRECTORY_SEPARATOR,$controllerFile);
			}
		}
		else
		{
			$controllerID=$modelClass;
			$controllerClass=ucfirst($controllerID).'Controller';
			$controllerFile=$module->controllerPath.DIRECTORY_SEPARATOR.$controllerClass.'.php';
			$controllerID[0]=strtolower($controllerID[0]);
		}

		$templatePath=$this->templatePath===null?YII_PATH.'/cli/views/shell/crud':$this->templatePath;
		$functionalTestPath=$this->functionalTestPath===null?Yii::getPathOfAlias('application.tests.functional'):$this->functionalTestPath;

		$viewPath=$module->viewPath.DIRECTORY_SEPARATOR.str_replace('.',DIRECTORY_SEPARATOR,$controllerID);
		$fixtureName=$this->pluralize($modelClass);
		$fixtureName[0]=strtolower($fixtureName);
		$list=array(
			basename($controllerFile)=>array(
				'source'=>$templatePath.'/controller.php',
				'target'=>$controllerFile,
				'callback'=>array($this,'generateController'),
				'params'=>array($controllerClass,$modelClass),
			),
		);

		if($functionalTestPath!==false)
		{
			$list[$modelClass.'Test.php']=array(
				'source'=>$templatePath.'/test.php',
				'target'=>$functionalTestPath.DIRECTORY_SEPARATOR.$modelClass.'Test.php',
				'callback'=>array($this,'generateTest'),
				'params'=>array($controllerID,$fixtureName,$modelClass),
			);
		}

		foreach($this->actions as $action)
		{
			$list[$action.'.php']=array(
				'source'=>$templatePath.'/'.$action.'.php',
				'target'=>$viewPath.'/'.$action.'.php',
				'callback'=>array($this,'generateView'),
				'params'=>$modelClass,
			);
		}

		$this->copyFiles($list);

		if($module instanceof CWebModule)
			$moduleID=$module->id.'/';
		else
			$moduleID='';

		echo "\nCrud '{$controllerID}' has been successfully created. You may access it via:\n";
		echo "http://hostname/path/to/index.php?r={$moduleID}{$controllerID}\n";
	}
1063817
public function jQueryDataTablesStandaloneFunction(array $args = []) {
        return $this->jQueryDataTablesStandalone(ArrayHelper::get($args, "selector", ".table"), ArrayHelper::get($args, "language"), ArrayHelper::get($args, "options", []));
    }
1092103
public function ListDatabases(\Google\Cloud\Spanner\Admin\Database\V1\ListDatabasesRequest $argument,
      $metadata = [], $options = []) {
        return $this->_simpleRequest('/google.spanner.admin.database.v1.DatabaseAdmin/ListDatabases',
        $argument,
        ['\Google\Cloud\Spanner\Admin\Database\V1\ListDatabasesResponse', 'decode'],
        $metadata, $options);
    }
1288354
function createOneMetaRecordStream(metaFilePath) {
  // All of these arguments are optional.
  const options = {
    escapeChar : '"', // default is an empty string
    enclosedChar : '"' // default is an empty string
  };

  return fs.createReadStream(metaFilePath)
    .pipe(parseMetaFiles.create());
}
718913
public function GetDataSource(\Google\Cloud\BigQuery\DataTransfer\V1\GetDataSourceRequest $argument,
      $metadata = [], $options = []) {
        return $this->_simpleRequest('/google.cloud.bigquery.datatransfer.v1.DataTransferService/GetDataSource',
        $argument,
        ['\Google\Cloud\BigQuery\DataTransfer\V1\DataSource', 'decode'],
        $metadata, $options);
    }
1086661
public function get( $args, $assoc_args ) {
		list( $object_id, $meta_key ) = $args;

		$object_id = $this->check_object_id( $object_id );

		$value = $this->get_metadata( $object_id, $meta_key, true );

		if ( '' === $value ) {
			die( 1 );
		}

		WP_CLI::print_value( $value, $assoc_args );
	}
1302968
public function deleteTable($meta, ...$args)
    {
        if (!isset($args[0])) {
            throw new \InvalidArgumentException("Cannot delete from table without a condition (pass the string '1=1' if you really meant to do this)");
        }
        $meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;
        if (!$meta->canDelete) {
            throw new Exception("Meta {$meta->id} prohibits update");
        }
        $query = Query\Criteria::fromParamArgs($args);
        return $this->executeDelete($meta, $query); 
    }
1192957
public function RunQuery(\Google\Cloud\Datastore\V1\RunQueryRequest $argument,
      $metadata = [], $options = []) {
        return $this->_simpleRequest('/google.datastore.v1.Datastore/RunQuery',
        $argument,
        ['\Google\Cloud\Datastore\V1\RunQueryResponse', 'decode'],
        $metadata, $options);
    }
38518
public function afterFetch(Array &$args) {
        $model = $args[0];
        $results = $args[1];
        $table = $model->getName();
        $view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view');

        if (!$results instanceof Garp_Db_Table_Rowset) {
            $results = array($results);
        }

        $url = $this->_url;
        $params = (array)$this->_params;
        // set sensible defaults
        if (!$url) {
            // non-intelligent route existence check:
            if (strpos(file_get_contents(APPLICATION_PATH.'/configs/routes.ini'),
                       '/'.$model->getName().'/:slug')
               ) {
                $url = '/'.$model->getName().'/%s';
                $params = array('slug');
            } else {
                throw new Garp_Model_Behavior_Exception('Route discovery failed. Please add "/'.$model->getName().'/:slug" to'.
                                    ' routes.ini or give a proper URL configuration to the behavior.');
            }
        }

        foreach ($results as $row) {
            if (!$row) {
                continue;
            }
            // Maps parameters to column values. $params should contain column names.
            $columnToValue = function($column) use ($row) {
                try {
                    return $row->{$column};
                } catch (Exception $e) {
                    return '';
                }
            };

            $values = array_map($columnToValue, $params);
            array_unshift($values, $url);
            $theUrl = call_user_func_array('sprintf', $values);
            $theUrl = $view->fullUrl($theUrl);

            $row->setVirtual(
                self::VIRTUAL_COLUMN_NAME,
                $theUrl
            );
        }

        // return the pointer to 0
        if ($results instanceof Garp_Db_Table_Rowset) {
            $results->rewind();
        } else {
        // also, return results to the original format if it was no Rowset to begin with.
            $results = $results[0];
        }
    }
664890
public function col_term_meta( $meta_key, array $args, $term_id ) {

		$vals = get_term_meta( $term_id, $meta_key, false );
		$echo = [];
		sort( $vals );

		if ( isset( $args['date_format'] ) ) {

			if ( true === $args['date_format'] ) {
				$args['date_format'] = get_option( 'date_format' );
			}

			foreach ( $vals as $val ) {

				if ( is_numeric( $val ) ) {
					$echo[] = date( $args['date_format'], $val );
				} elseif ( ! empty( $val ) ) {
					$echo[] = mysql2date( $args['date_format'], $val );
				}
			}
		} else {

			foreach ( $vals as $val ) {

				if ( ! empty( $val ) || ( '0' === $val ) ) {
					$echo[] = $val;
				}
			}
		}

		if ( empty( $echo ) ) {
			echo '&#8212;';
		} else {
			echo esc_html( implode( ', ', $echo ) );
		}

	}