Get the string value of a field on this object that has been suitable escaped to be inserted directly into a
template.

@param string $field
@param array $arguments
@param bool $cache
@return string
430984
public function XML_val($field, $arguments = [], $cache = false)
    {
        $result = $this->obj($field, $arguments, $cache);
        // Might contain additional formatting over ->XML(). E.g. parse shortcodes, nl2br()
        return $result->forTemplate();
    }
951660
@SuppressWarnings("unchecked")
  public static <T> T getFieldValue(Object object, String fieldName) {
    Field field = CACHE.getUnchecked(object.getClass().getName() + '#' + fieldName);
    if (field == null) {
      throw new IllegalArgumentException("Could not find field [" + fieldName + "] on target [" + object + "]");
    }

    Object result = null;
    try {
      result = field.get(object);
    } catch (IllegalAccessException ignored) {
    }
    return (T) result;
  }
1150442
protected function getAddressFieldValue($field)
    {
        if ($field instanceof \Closure) {
            return call_user_func($field, $this);
        }

        if (is_array($field)) {
            return $this->getRelationalField($field);
        }

        return $this->{$field};
    }
604479
protected function prepareWhereIn($field, array $values = [], $cacheKey)
    {
        if (is_array($field)) {
            foreach ($field as $name => $values) {
                $this->prepareWhereIn($name, $values, $cacheKey);
            }
        } elseif (count($values)) {

            if ($field === '_id') {
                foreach ($values as $key => $value) {
                    $values[ $key ] = new \MongoDb\BSON\ObjectID($value);
                }
            }

            $this->builderCache->store($cacheKey, [$field => $values]);
        }
    }
551181
public function getField($row, array $templates = []): string
    {
        $value = $this->attributes['field']($row, $this, $templates);

        if ($value instanceof Renderable) {
            return $value->render();
        }

        return $value;
    }
499841
protected function getEntityAttributeValue($entity, $field)
    {
        $functionName = 'get'.ucfirst($field);

        $fieldValue = call_user_func([$entity, $functionName]);

        return $fieldValue;
    }
1061076
function hasValue($field, $arguments = null, $cache = true) {
		return ($this->value || $this->value == '0') || ( !$this->nullifyEmpty && $this->value === '');
	}
452518
public function getValue(ServerRequestInterface $request, $argument = null)
    {
        $url = $request->getUri();
        $return = $url->getPath();
        if ($url->getQuery()) {
            $return .= '?' . $url->getQuery();
        }
        if ($url->getFragment()) {
            $return .= '#' . $url->getFragment();
        }

        return $return;
    }
632167
protected function parseFieldName($field, $table = false){
		// preg_replace callback behaviour
		if(is_array($field))
			$field = $field[0];
		if($field instanceof Literal)
			return $field->value;

		$field = trim($field);

		if($field === '*')
			return $field;

		if(strpos($field, ' '))
			return $field;

		$field = str_replace(':', '', $field);

		if(strpos($field, '.') !== false || $table === true){
			$prefix = $this->stmt->getConnection()->getPrefix();
			$field = $prefix . $field;
		}

		return $this->stmt->getConnection()->getDriver()->escape($field, Manager::IDENTIFIER);
	}
37826
public static function ArgString($arg){

		$type = gettype($arg);

		if( $type === 'object'){
			$string = $arg->cache_string;
			unset($arg->cache_string);
			return $string;

		}elseif( $type === 'array' ){
			$string = ' Array(';
			foreach($arg as $k => $a){
				$string .= var_export($k,true).' => '.self::ArgString($a).',';
			}
			return $string . ')';
		}

		return var_export($arg,true);
	}
709235
protected function escapeValue($gridField, $value)
    {
        if (!$escape = $gridField->FieldEscape) {
            return $value;
        }

        foreach ($escape as $search => $replace) {
            $value = str_replace($search, $replace, $value);
        }
        return $value;
    }
1050760
public static function getByField($field, $value, $cacheIndex = false)
    {
        $record = static::getRecordByField($field, $value, $cacheIndex);

        return static::instantiateRecord($record);
    }
1011677
private function escape(array $arguments)
    {
        $args = array();
        foreach ($arguments as $k => $v) {
            if (is_array($v)) {
                $args[$k] = $this->escape($v);
            } elseif (is_string($v)) {
                $args[$k] = str_replace('%', '%%', $v);
            } else {
                $args[$k] = $v;
            }
        }

        return $args;
    }
1104755
private static function getTagContent($arguments, bool $hasContent)
    {
        $content = '';
        if (\is_array($arguments) && isset($arguments[0]) && $hasContent === true) {
            $content = $arguments[0];
        }
        return $content;
    }
308811
private function templateFieldValues($fields)
    {
        $result = [];
        foreach ($fields as $field) {
            if (!$this->test && (isset($field->test_only) ? $field->test_only : false)) {
                // Skip this field as it is for test mode only.
                continue;
            }
            $key = isset($field->key) ? trim($field->key) : '';
            if ('' === $key) {
                // Skip if we have an empty key.
                continue;
            }
            // Exclude default_value (may add this functionality in the future if desired).
            $valueSources = ['value', 'default_value'];
            if ($this->test) {
                $valueSources = ['test_value', 'value', 'default_value'];
            }
            $value = null;
            foreach ($valueSources as $valueSource) {
                if (isset($field->{$valueSource}) && null !== $field->{$valueSource} && '' !== $field->{$valueSource}) {
                    $value = $this->renderTokens($field->{$valueSource});
                    if (null !== $value && '' !== $value) {
                        break;
                    }
                }
            }
            if (null === $value || '' === $value) {
                // The field value is empty.
                if (true === (isset($field->required) ? $field->required : false)) {
                    // The field is required. Abort.
                    throw new ContactClientException(
                        'A required Client template field is empty: '.$field->value.' ('.$field->key.' in client configuration)',
                        0,
                        null,
                        Stat::TYPE_FIELDS,
                        false,
                        $field->key
                    );
                }
            }
            $result[$key] = $value;

            // Support pure mustache tags as keys as well (for templates only).
            if (1 === preg_match('/^{{\s*[\w\.]+\s*}}$/', trim($field->value))) {
                $mustacheTag = trim(str_replace(['{', '}'], '', $field->value));
                if (empty($result[$mustacheTag])) {
                    $result[$mustacheTag] = $value;
                }
            }
        }

        return $result;
    }
651374
protected function getArgValue($data, $arg, $annotation, $includeAnnotationProperty = true)
    {
        if(!is_string($arg))
        {
            return $arg;
        }
        else if(preg_match('/\{:([^\}]+)\}/', $arg, $matches) > 0)
        {
            $argName = $matches[1];
            if('value' === $argName)
            {
                return ObjectArrayHelper::get($data, $annotation->name);
            }
            $list = explode('.', $argName, 2);
            if('data' === $list[0])
            {
                if(isset($list[1]))
                {
                    return ObjectArrayHelper::get($data, $list[1]);
                }
                else
                {
                    return $data;
                }
            }
        }
        else if($includeAnnotationProperty && preg_match('/\{([^\}]+)\}/', $arg, $matches) > 0)
        {
            $argName = $matches[1];
            return ObjectArrayHelper::get($annotation, $argName);
        }
        else
        {
            return $arg;
        }
    }
349144
public function execute($query, $args) {
		/*
		 * INITIALIZE
		 */
		
		//validate query
		if (!is_string($query) || empty($query))
			throw new \InvalidArgumentException("Query is not a valid string");

		//open connection
		$this->driver->connect();
		
		/*
		 * CACHE CONTROL
		 */
		
		$cachedValue = $resultMap = null;
		$cacheable = false; //if mapped value is cacheable
		
		//check if there is a value stored in cache with the given key
		if (array_key_exists('cache.key', $this->config) && isset($this->cacheProvider)) {
			//build cache key
			$cacheKey = (new CacheKeyFormatter($this->typeManager))->format($this->config['cache.key'], $args, $this->config);

			//check if key is present
			if ($this->cacheProvider->exists($cacheKey)) {
				$cachedValue = $this->cacheProvider->fetch($cacheKey);
				
				if (is_array($cachedValue) || is_object($cachedValue)) {
					//get cache metadata
					$cacheMeta = $this->extractCacheMetadata($this->config['cache.metakey'], $cachedValue);
					
					//no metadata, we didn't stored it
					if (is_null($cacheMeta)) 
						return $cachedValue;
					
					//create mapper instance
					$mapper = (new \ReflectionClass($cacheMeta->class))->newInstance($this->driver->buildTypeManager(), $cacheMeta->resultMap);
					
					if (!empty($cacheMeta->groups))
						$mapper->setGroupKeys($cacheMeta->groups);
					
					//build mapping callback (method tells if this is a list or a single row)
					$mappingCallback = [$mapper, $cacheMeta->method];
					
					//set resultmap (allows further processing)
					$resultMap = $cacheMeta->resultMap;
				}
				else
					return $cachedValue;
			}
		}
		
		if (is_null($cachedValue)) {
			/*
			 * GENERATE QUERY
			 */
				
			//build statement
			$stmt = $this->driver->buildStatement($this->typeManager)->format($query, $args, $this->config);
			
			//debug query
			if (array_key_exists('callback.debug', $this->config)) 
				call_user_func($this->config['callback.debug'], $stmt);
			
			/*
			 * PARSE MAPPING EXPRESSION
			 */
	
			//build mapping callback
			if (array_key_exists('map.type', $this->config)) {
				//get mapping type
				$mappingType = $this->config['map.type'];
				
				//object mapping type: object, object:class, object[column], object[column:type], etc
				if (preg_match(self::OBJECT_TYPE_REGEX, $mappingType, $matches)) {
					//get class, if any
					if (empty($matches[1])) { //no class defined, use default
						$defaultClass = 'stdClass';
						$resultMap = array_key_exists('map.result', $this->config) ? $this->config['map.result'] : null; //obtain result map
						$mapper = new StdClassMapper($this->typeManager, $resultMap);
					}
					else {
						//remove leading ':'
						$defaultClass = strtolower($matches[1]);
						$resultMap = array_key_exists('map.result', $this->config) ? $this->config['map.result'] : null;
						
						//get mapping class
						if ($defaultClass == 'stdclass')
							$mapper = new StdClassMapper($this->typeManager, $resultMap);
						elseif ($defaultClass == 'arrayobject')
							$mapper = new ArrayObjectMapper($this->typeManager, $resultMap);
						elseif (Profiler::getClassProfile($matches[1])->isEntity()) { //check if defined class is an entity
							$mapper = new EntityMapper($this->typeManager, $matches[1]);
							$resultMap = $matches[1];
						}
						else {
							$mapper = new ObjectMapper($this->typeManager, $matches[1]);
							$resultMap = null;
						}
					}
					
					//generate a new object mapper object
					$group = $groupType = $index = $indexType = null;
					
					if (count($matches) > 2) {
						$mappingCallback = [$mapper, 'mapList'];
					
						//obtain group
						if (array_key_exists('callback.group', $this->config)) {
							$group = $this->config['callback.group'];
							$groupType = 'callable';
						}
						elseif (isset($matches[2]) && ($matches[2] == '0' || !empty($matches[2]))) {
							$group = $matches[2];
							$groupType = (isset($matches[3]) && !empty($matches[3])) ? $matches[3] : null;
						}
					
						//obtain index
						if (array_key_exists('callback.index', $this->config)) {
							$index = $this->config['callback.index'];
							$indexType = 'callable';
						}
						elseif (isset($matches[5]) && ($matches[5] == '0' || !empty($matches[5]))) {
							$index = $matches[5];
							$indexType = (isset($matches[6]) && !empty($matches[6])) ? $matches[6] : null;
						}
					
						//add index and group to mapper parameters
						$mappingParams = [$index, $indexType, $group, $groupType];
					}
					else
						$mappingCallback = [$mapper, 'mapResult']; //set default method
				}
				//array mapping type: array, array[], array[column], array[column:type]
				elseif (preg_match(self::ARRAY_TYPE_REGEX, $mappingType, $matches)) {
					//obtain result map
					$resultMap = array_key_exists('map.result', $this->config) ? $this->config['map.result'] : null;
						
					//generate a new array mapper object
					$mapper = new ArrayMapper($this->typeManager, $resultMap);
					
					if (count($matches) > 1) {
						$mappingCallback = [$mapper, 'mapList'];
						$group = $groupType = $index = $indexType = null;
					
						//obtain group and group type
						if (array_key_exists('callback.group', $this->config)) {
							$group = $this->config['callback.group'];
							$groupType = 'callable';
						}
						elseif (isset($matches[1]) && ($matches[1] == '0' || !empty($matches[1]))) {
							$group = $matches[1];
							$groupType = (isset($matches[2]) && !empty($matches[2])) ? $matches[2] : null;
						}
					
						//obtain index and index type
						if (array_key_exists('callback.index', $this->config)) {
							$index = $this->config['callback.index'];
							$indexType = 'callable';
						}
						elseif (isset($matches[4]) && ($matches[4] == '0' || !empty($matches[4]))) {
							$index = $matches[4];
							$indexType = (isset($matches[5]) && !empty($matches[5])) ? $matches[5] : null;
						}
							
						//add index and group to mapper parameters
						$mappingParams = [$index, $indexType, $group, $groupType];
					}
					else
						$mappingCallback = [$mapper, 'mapResult'];
				}
				//simple mapping type: integer, string, float, etc
				elseif (preg_match(self::SIMPLE_TYPE_REGEX, $mappingType, $matches)) {					
					//get type handler
					$typeHandler = $this->typeManager->getTypeHandler($matches[1]);
					
					if ($typeHandler === false)
						throw new \InvalidArgumentException("Unknown type '{$matches[1]}'");
						
					//create mapper instance
					$mapper = new ScalarTypeMapper($typeHandler);
						
					//set mapping callback
					$mappingCallback = [$mapper, empty($matches[2]) ? 'mapResult' : 'mapList'];
				}
				else
					throw new \InvalidArgumentException("Unrecognized mapping expression '$mappingType'");
			}
			else {
				//obtain result map
				$resultMap = array_key_exists('map.result', $this->config) ? $this->config['map.result'] : null;
					
				//generate mapper
				$mapper = new ArrayMapper($this->typeManager, $resultMap);
					
				//use default mapping type
				$mappingCallback = [$mapper, 'mapList'];
				
				//check for group callback
				if (array_key_exists('callback.group', $this->config)) {
					$group = $this->config['callback.group'];
					$groupType = 'callable';
				}
				else
					$group = $groupType = null;
				
				//check for index callback
				if (array_key_exists('callback.index', $this->config)) {
					$index = $this->config['callback.index'];
					$indexType = 'callable';
				}
				else
					$index = $indexType = null;
				
				$mappingParams = [$index, $indexType, $group, $groupType];
			}
			
			/*
			 * EXECUTE QUERY
			 */
				
			//run query
			$result = $this->driver->query($stmt);
				
			//check query execution
			if ($result === false)
				$this->driver->throwQueryException($stmt);
			
			//check if result is successful
			if ($result === true) {
				//free result
				$this->driver->freeResult($result);
				return true;
			}
			
			/*
			 * INVOKE EMPTY RESULT CALLBACK
			 */
				
			$ri = $this->driver->buildResultIterator($result);
				
			//check if result is empty
			if ($ri->countRows() === 0) {
				if (array_key_exists('callback.empty', $this->config))
					return call_user_func($this->config['callback.empty'], $result);
			}
			else
				$cacheable = true;
			
			/*
			 * ADD CUSTOM MAPPING OPTIONS
			 */
				
			//add defined mapping parameters
			if (array_key_exists('map.params', $this->config)) {
				if (!empty($mappingParams))
					$mappingParams = array_merge($mappingParams, $this->config['map.params']);
				else
					$mappingParams = $this->config['map.params'];
			}
				
			//build mapping callback parameters
			if (isset($mappingParams))
				array_unshift($mappingParams, $ri);
			else
				$mappingParams = [$ri];
			
			/*
			 * MAP RESULT
			 */
				
			//call mapping callback
			$mappedResult = call_user_func_array($mappingCallback, $mappingParams);
				
			//free result
			$this->driver->freeResult($result);
			
			/*
			 * CACHEABLE ATTRIBUTES
			 */
			
			if (isset($resultMap)) {
				$copy = $this->__copy(); //clone current instance
				
				if ($mappingCallback[1] == 'mapList') { //list of rows
					if ($mapper->hasGroupKeys()) { //grouped
						foreach ($mapper->getGroupKeys() as $group) {
							foreach (array_keys($mappedResult[$group]) as $k)
								$mapper->evaluateAttributes($mappedResult[$group][$k], $copy);
						}
					}
					else { //list
						foreach (array_keys($mappedResult) as $k)
							$mapper->evaluateAttributes($mappedResult[$k], $copy);
					}
				}
				else //single row
					$mapper->evaluateAttributes($mappedResult, $copy);
			}
			
			/*
			 * CACHE STORE
			 */
			
			//check if obtained value can be stored
			if (isset($this->cacheProvider) && $cacheable) {
				//build value wrapper
				if ($mapper instanceof ComplexMapper)
					$this->injectCacheMetadata($this->config['cache.metakey'], $mappedResult, get_class($mapper), $mappingCallback[1], $mapper->getGroupKeys(), $resultMap);
				
				//store value
				if (array_key_exists('cache.ttl', $this->config))
					$this->cacheProvider->store($cacheKey, $mappedResult, intval($this->config['cache.ttl']));
				else
					$this->cacheProvider->store($cacheKey, $mappedResult);
			}
		}
		
		/*
		 * DYNAMIC ATTRIBUTES
		 */

		if (!empty($resultMap) && $this->config['depth.limit'] > $this->config['depth.current']) {
			$icopy = $this->__icopy();			
			
			if ($mappingCallback[1] == 'mapList' && !empty($mappedResult)) {
				if ($mapper->hasGroupKeys()) {
					foreach ($mapper->getGroupKeys() as $group) {
						foreach (array_keys($mappedResult[$group]) as $k) {
							$mapper->evaluateDynamicAttributes($mappedResult[$group][$k], $icopy);
							$mapper->evaluateAssociations($mappedResult[$group][$k], $icopy);
						}
					}
				}
				else {
					foreach (array_keys($mappedResult) as $k) {
						$mapper->evaluateDynamicAttributes($mappedResult[$k], $icopy);
						$mapper->evaluateAssociations($mappedResult[$k], $icopy);
					}
				}
			}
			elseif ($mappingCallback[1] != 'mapList' && !is_null($mappedResult)) {
				$mapper->evaluateDynamicAttributes($mappedResult, $icopy);
				$mapper->evaluateAssociations($mappedResult, $icopy);
			}
		}
		
		/*
		 * TRAVERSING CALLBACK
		 */
		
		if (array_key_exists('callback.each', $this->config)) {
			$eachCallback = $this->config['callback.each'];
			$copy = isset($copy) ? $copy : $this->__copy();
		
			if ($eachCallback instanceof \Closure) {
				//check if mapped result is a list
				if ($mappingCallback[1] == 'mapList' && !empty($mappedResult)) {
					if ($mapper instanceof ComplexMapper && $mapper->hasGroupKeys()) {
						foreach ($mapper->getGroupKeys() as $group) {
							foreach (array_keys($mappedResult[$group]) as $k)
								$eachCallback->__invoke($mappedResult[$group][$k], $copy);
						}
					}
					else {
						foreach (array_keys($mappedResult) as $k)
							$eachCallback->__invoke($mappedResult[$k], $copy);
					}
				}
				elseif (!is_null($mappedResult))
					$eachCallback->__invoke($mappedResult, $copy);
			}
			else {
				//this closure avoids getting "expected to be a reference"-style messages
				$c = function (&$mappedResult) use ($eachCallback) {
					call_user_func($eachCallback, $mappedResult, $copy);
				};
		
				//call traverse callback
				if ($mappingCallback[1] == 'mapList' && !empty($mappedResult)) {
					if ($mapper instanceof ComplexMapper && $mapper->hasGroupKeys()) {
						foreach ($mapper->getGroupKeys() as $group) {
							foreach (array_keys($mappedResult[$group]) as $k)
								$c->__invoke($mappedResult[$group][$k]);
						}
					}
					else {
						foreach (array_keys($mappedResult) as $k)
							$c->__invoke($mappedResult[$k]);
					}
				}
				elseif (!is_null($mappedResult))
					$c->__invoke($mappedResult);
			}
		}
		
		/*
		 * FILTER CALLBACK
		 */
		
		//apply filter
		if (array_key_exists('callback.filter', $this->config)) {
			$filterCallback = $this->config['callback.filter'];
		
			//check if mapped result is a list
			if ($mappingCallback[1] == 'mapList' && !empty($mappedResult)) {
				if ($mapper instanceof ComplexMapper && $mapper->hasGroupKeys()) {
					foreach ($mapper->getGroupKeys() as $group)
						$mappedResult[$group] = array_filter($mappedResult[$group], $filterCallback);
				}
				else
					$mappedResult = array_filter($mappedResult, $filterCallback);
			}
			elseif (!is_null($mappedResult)) {
				if (!call_user_func($filterCallback, $mappedResult))
					$mappedResult = null;
			}
		}
		
		return $mappedResult;
	}