Format a mask using the standard format given a callable

Ex: if you have attributes with handles `student_first_name` and `student_last_name`
`%student_last_name%, %student_first_name%`

@param $mask
@param callable $matchHandler
@return mixed
16749
public function format($mask, callable $matchHandler)
    {
        try {
            // Run a regular expression to match the mask
            return preg_replace_callback('/%(.*?)%/i', function ($matches) use ($matchHandler) {
                // Return the result returned from the matchHandler
                return $this->getResult($matches[1], $matchHandler) ?: '';
            }, $mask);
        } catch (\Exception $e) {
            // Log any failures
            $this->logger->debug(
                'Failed to format express mask "{mask}": {message}',
                ['mask' => $mask, 'message' => $e->getMessage(), 'exception' => $e]
            );
        }
    }
152178
function ( mask ) {

        if ( mask && ( mask instanceof RegExp ) !== true ) {

            throw { type: 'getURLs', message: 'First argument must be RegExp' };

        }

        return urls.map( function ( value ) {

            return _getURLValue( value );

        } ).filter( function ( value, pos, self ) {

            var unique = self.indexOf( value ) === pos;

            if ( mask && unique ) {

                return mask.test( value );

            } else {

                return unique;

            }

        } );

    }
947065
private function resolveNamespace($parameters, $handler, $matches)
    {
        if (isset($handler['module'])) {
            $moduleName = $handler['module'];
            if ($this->isPlaceholder($moduleName)) {
                foreach ($handler as $target => $placeholder) {
                    foreach ($parameters as $key => $parameterName) {
                        if ($parameterName[0][0] == $placeholder) {
                            if ($target == 'module') {
                                $moduleName = $matches[$key];
                            }
                        }
                    }
                }
            }

            return implode(
                '\\',
                [
                    $this->baseNamespace,
                    $this->moduleName,
                    $moduleName,
                    $this->controllerName
                ]
            );
        }

        return $this->baseNamespace.'\\'.$this->controllerName;
    }
463793
public function mask($data, $mask)
    {
        for ($i = 0, $l = mb_orig_strlen($data), $ml = mb_orig_strlen($mask); $i < $l; $i++) {
            $data[$i] = $data[$i] ^ $mask[$i % $ml];
        }
        return $data;
    }
606958
public function write($mask = '%s')
    {
        $str='';
        foreach ($this->cleanStack($this->get(), 'path') as $entry) {
            $tag_attrs = array(
                'type'=>'text/javascript',
                'src'=>$entry['path']
            );
            $str .= sprintf($mask, Html::writeHtmlTag('script', null, $tag_attrs));
        }
        return $str;
    }
470401
public function uriMatch($pattern, callable $handler)
    {
        if (preg_match($pattern, $this->getCleanUri(), $matches)) {
            return $handler($this->getCleanUri(), $matches);
        }
    }
468582
public static function maskToArray($mask)
    {
        $array = array();

        if (empty($mask) || !is_int($mask)) {
            return $array;
        }

        if ($mask & self::GET_MASK) {
            $array[] = self::GET;
        }
        if ($mask & self::POST_MASK) {
            $array[] = self::POST;
        }
        if ($mask & self::PUT_MASK) {
            $array[] = self::PUT;
        }
        if ($mask & self::PATCH_MASK) {
            $array[] = self::PATCH;
        }
        if ($mask & self::DELETE_MASK) {
            $array[] = self::DELETE;
        }
        if ($mask & self::OPTIONS_MASK) {
            $array[] = self::OPTIONS;
        }
        if ($mask & self::HEAD_MASK) {
            $array[] = self::HEAD;
        }
        if ($mask & self::COPY_MASK) {
            $array[] = self::COPY;
        }
        if ($mask & self::TRACE_MASK) {
            $array[] = self::TRACE;
        }
        if ($mask & self::CONNECT_MASK) {
            $array[] = self::CONNECT;
        }

        return $array;
    }
182053
protected function prepareHandler(HandlerInterface $handler, array $config = [])
    {
        if (! isset($config['formatter'])) {
            $handler->setFormatter($this->formatter());
        } elseif ($config['formatter'] !== 'default') {
            $handler->setFormatter($this->app->make($config['formatter'], $config['formatter_with'] ?? []));
        }

        return $handler;
    }
230814
public function format()
	{
		foreach($this->matches as $key => $match)
		{
			$potential = str_replace(['[', ']'], '', $match);

			// Seperate by comma
			$potential = explode(',', $potential);

			// Classes can have a dot seperator Class.method
			$mask = $potential[0];
			if(strpos($potential[0], '.') !== false) {
				$parts = explode('.', $potential[0]);
				$mask = $parts[0];
			}

			// The first value will be the mask name
			if($this->collection->getMethod()->has($mask))
			{
				$this->formatted[$mask] = Array();

				// Add the raw match so we can replace this
				$this->formatted[$mask]['raw'] = $match;
				$this->formatted[$mask]['params'] = Array();
				
				// Remove the name from the array
				unset($potential[0]);

				$this->processValues($mask, $potential);
			
			} else {
				
				// This isnt a mask
				unset($this->matches[$key]);
			}
		}	
	}
211356
function mask($pattern,$url=NULL) {
		if (!$url)
			$url=$this->rel($this->hive['URI']);
		$case=$this->hive['CASELESS']?'i':'';
		$wild=preg_quote($pattern,'/');
		$i=0;
		while (is_int($pos=strpos($wild,'\*'))) {
			$wild=substr_replace($wild,'(?P<_'.$i.'>[^\?]*)',$pos,2);
			$i++;
		}
		preg_match('/^'.
			preg_replace(
				'/((\\\{)?@(\w+\b)(?(2)\\\}))/',
				'(?P<\3>[^\/\?]+)',
				$wild).'\/?$/'.$case.'um',$url,$args);
		foreach (array_keys($args) as $key) {
			if (preg_match('/^_\d+$/',$key)) {
				if (empty($args['*']))
					$args['*']=$args[$key];
				else {
					if (is_string($args['*']))
						$args['*']=[$args['*']];
					array_push($args['*'],$args[$key]);
				}
				unset($args[$key]);
			}
			elseif (is_numeric($key) && $key)
				unset($args[$key]);
		}
		return $args;
	}
462532
public static function maskString($val, $mask)
    {
        if (empty($val)) {
            return $val;
        }
        $maskared = '';
        $k = 0;
        if (is_numeric($val)) {
            $val = sprintf('%0' . mb_strlen(preg_replace('/[^#]/', '', $mask)) . 's', $val);
        }
        for ($i = 0; $i <= mb_strlen($mask) - 1; $i++) {
            if ($mask[$i] == '#') {
                if (isset($val[$k])) {
                    $maskared .= $val[$k++];
                }
            } else {
                if (isset($mask[$i])) {
                    $maskared .= $mask[$i];
                }
            }
        }

        return $maskared;
    }
194360
function mask($pattern,$url=NULL) {
		if (!$url)
			$url=$this->rel($this->hive['URI']);
		$case=$this->hive['CASELESS']?'i':'';
		preg_match('/^'.
			preg_replace('/@(\w+\b)/','(?P<\1>[^\/\?]+)',
			str_replace('\*','([^\?]+)',preg_quote($pattern,'/'))).
				'\/?(?:\?.*)?$/'.$case.'um',$url,$args);
		return $args;
	}
228274
private function processMask($mask)
    {
        foreach ($mask as $key => $value) {
            return '.' . $key . (is_array($value) ? $this->processMask($value) : '');
        }
    }
731069
public function decodeMask($mask, Tool $tool)
    {
        $decoders = $this->maskRepo->findMaskDecodersByTool($tool);
        $perms = [];

        foreach ($decoders as $decoder) {
            $perms[$decoder->getName()] = ($mask & $decoder->getValue()) ?
                true :
                false;
        }

        return $perms;
    }
583903
public function replace(string $text, string $mask = '*'): string
    {
        $found = $this->search($text);

        $replace = [];
        foreach ($found as $v) {
            $replace[$v['word']] = $mask;
        }

        return \strtr($text, $replace);
    }
94935
public static function formatMessage($callable, $parameterName)
    {

        switch (true) {
            case is_array($callable):
                $message = sprintf('%s::%s()', get_class($callable[0]), $callable[1]);
                break;
            case is_object($callable):
                $message = get_class($callable);
                break;
            default:
                $message = (string)$callable;
                break;
        }


        return 'Unable to match parameter named [' . $parameterName . '] for the callable [' . $message . ']';
    }
303003
@Override
    public String format(Date date, String mask) {
	DateTime dt = (date instanceof DateTime) ? (DateTime) date : new DateTimeImpl(date.getTime(), false);
	return format(dt, mask, null);
    }