2016-08-10
@used-by b()
@used-by f()
@used-by i()
@used-by nat()
@used-by nat0()
@param callable $f
@param mixed|null $d [optional]
@param string|null $k [optional]
@return mixed
511251
private function filter(callable $f, $d = null, $k = null) {return 
		dfc($this, function($f, $d, $k) {return
			call_user_func($f, $this->v($d, $k))
		;}, [$f, $d, $k ?: df_caller_f(1)])
	;}
138427
public function get($k)
	{
		try
		{
			$this->_qst->execute(array($this->_prefix . $k));
			$value = $this->_qst->fetchColumn(0);
			if ( $value === FALSE )
				throw new \Exception("Config value '$k' does not exist");
			
			return $value;
		}
		catch (\PDOException $e)
		{
			throw new \Exception("Config value '$k' can't be read (SQL error {$e->getMessage()})");
		}		
	}
1305115
protected function buildSubquery(callable $f)
    {
        $query = new SelectQuery();
        $query->getSelect()->clearFields();
        $f($query);
        $sql = $query->build();
        $this->values = array_merge($this->values, $query->getValues());

        return '('.$sql.')';
    }
125234
final static function s($m, C $c) {return dfcf(function($m, C $c) {
		/**
		 * 2017-07-19
		 * Unable to reduce the implementation to:
		 * 		df_new(df_con_hier($m, self::class), $c);
		 * because @uses __construct() is protected.
		 * It is similar to @see \Df\Payment\Facade::s()
		 * https://github.com/mage2pro/core/blob/2.8.25/Payment/Facade.php#L75-L87
		 */
		$class = df_con_hier($m, self::class); /** @var string $class */
		return new $class($c);
	}, func_get_args());}
1012958
final protected function resPath($k) {$this->addFilterResAV(function(array $a) use($k) {return
		dfa_deep($a, $k, $a)
	;});}
461080
public static function get( $key, $default = null ) {
        if ( ! self::has($key) ) {
            if ( $default instanceof FrameworkException ) throw $default;
            return $default;
        }
        
        $key_array = preg_split('/\./', $key );
        $return = self::$data;

        foreach($key_array as $k)
            $return = $return[$k];

        return $return;
    }
555590
function dfl(a, b, c) {
        switch (arguments.length) {
            case 2: return a != null ? a : b;
            case 3: return a != null ? a : b != null ? b : c;
            default: throw new Error("Implement me");
        }
    }
1099882
public function orElse(callable $f) {
        if( $this->value !== null ) return $this;
        if( $this->error !== null ) return $f($this->error);
        throw new \LogicException("Value and error cannot both be null");
    }
300123
public function toMicros($d)  
    {
        $v = $this->getValue();
        if ($v < self::MICROSECONDS) {
            return $d/($this->c1/$this->c0);
        } else {
            return $this->x($d, $this->{'c'.$v}/$this->c1, PHP_INT_MAX/($this->{'c'.$v})/$this->c1);
        }
    }
908659
protected function getIfSet($key, stdClass $data = null)
    {
        if (empty($data)) {
            $data = $this->data;
        }

        if (isset($data->$key)) {
            return $data->$key;
        }
    }
126588
public static function getVariable(string $name): stdClass
    {
        self::loadData();
        if (isset(Search::$data->vars->{$name})) {
            return Search::$data->vars->{$name};
        } else {
            throw new KBException("$name does not exist !");
        }
    }
1203561
public function get($k)
	{
		if ( !property_exists($this->_object, $k) )
			throw new \Exception("Config value '$k' does not exist");

		return $this->_object->{$k};
	}
206539
protected function _function($fct, $what=null, $group_by=null) {
		if($what === null)
			$what = '*';
		$fct = strtoupper($fct);

		$clone = clone $this;
		if($fct === 'COUNT') {
			$clone->offset(null);
			$clone->limit(null);
		}

		$alias = strtolower($fct);
		if($group_by) {
			$dal = new static($this->db);
			$dal->select($group_by.' groupby, '.$fct.'('.$what.') '.$alias)
			    ->groupBy($group_by)
			    ->from($clone, 's');
			$res = [];
			foreach($dal->get() as $v)
				$res[$v['groupby']] = $v[$alias];
			return $res;
		}
		else {
			$dal = new static($this->db);
			$dal->select($fct.'('.$what.') '.$alias)
			    ->from($clone, 's');
			return \Asgard\Common\ArrayUtils::array_get($dal->first(), $alias);
		}
	}
429366
public function check($k,$v)
    {
      $this->get($this->id);

      if ($this->$k == $v)
      return TRUE;

      return FALSE;
    }
294834
final static function request(M $m) {
		$i = df_new(df_con_heir($m, __CLASS__), $m); /** @var self $i */
		$r = df_clean_keys([
			$i->k_Description() => $i->customerName(), $i->k_Email() => $i->customerEmail()
		], $i->k_Excluded()); /** @var array(string => mixed) $r */
		/**
		 * 2017-07-30
		 * I placed it here in a separate condition branch
		 * because some payment modules (Moip) implement non-card payment options.
		 * A similar code block is here: @see \Df\StripeClone\P\Charge::request()
		 */
		if ($k = $i->k_CardId()/** string|null */) {
			$r[$k] = $i->v_CardId(Token::get($i->ii()));
		}
		return $r + $i->p();
	}
1130678
public function map(callable $f) : NestableResult
    {
        return new self(
            $this->outer->map($f),
            array_map($f, $this->inner)
        );
    }
556363
public static function objectToArray($d)
    {
        if (is_object($d)) {
            $d = get_object_vars($d);
        }
        if (!is_array($d)) {
            return $d;
        }
        return array_map(array(__CLASS__, __FUNCTION__), $d); // recursive
    }