/** * @param array $data * @return void */ public function __invoke($data) { $data = Arr::flatten($data); $data = array_unique($data); $this->outPorts['out']->send($data); $this->outPorts['out']->disconnect(); }
public function __invoke($data) { lineOut(__METHOD__); lineOut('ReplaceMarkupClasses'); // lineOut('data:'); lineOut($data); lineOut('this content:'); lineOut($this->content); // (?:\s|\") #'/(?<=class\=)(?:\"|\')(?:[a-zA-Z0-9\s]*?)\b('.$data['original'].')\b(?=\"|\'|\s)/s', // could match them all, explode it, make a copy, replace it... $content = (string) $data['content']; preg_match_all('/(?<=class\\=\\")([a-zA-Z0-9-\\s]*)(?=\\")/s', $content, $matches); $matches = Arr::flatten($matches); $matchCopy = ""; // echo "CLEAN UP MATCH: ". __METHOD__; foreach ($matches as $match) { $matchesExploded = explode(" ", $match); foreach ($matchesExploded as $key => $subMatch) { $matchesExploded[$key] = str_replace($data['original'], $data['new'], $subMatch); } $matchesImploded = implode(" ", $matchesExploded); $content = str_replace($match, $matchesImploded, $content); } $data['content']->setContent($content); /* $data['content']->setContent(preg_replace( '/(?<=class\=)(?:\"|\')(?:[a-zA-Z0-9\s]*?)\b('.$data['original'].')\b(?:\"|\')(?:[a-zA-Z0-9\s]*?)(?=\"|\'|\s)/', $data['new'], $data['content'])); */ // $this->content = $data['content']; $this->sendIfAttached('out', $data['content']); }
public static function buildSource($raw, $argument) { preg_match_all('/[(]+[A-Za-z]+[)]/', $raw, $matches); $matches = Arr::flatten($matches); foreach ($matches as $match) { $method = preg_replace('/[()]/', '', $match); $name = forward_static_call(['self', $method], $argument); $raw = str_replace($match, $name, $raw); } return $raw; }
/** * Write the stored logs. * * @return array */ public function write() { foreach ($this->logs as $file => $entries) { $entries = Arr::flatten($entries); if (!$this->files->exists($file)) { $this->createLogsFile($file); } $this->files->put($file, implode(PHP_EOL, $entries)); } return array_keys($this->logs); }
/** * @param mixed $data * @return void */ public function output($data) { if (is_array($data)) { lineOut(__METHOD__); $dataString = Arr::flatten($data); $dataString = array_unique($dataString); $dataString = implode(",", $dataString); Emitter::emit('test.output', $dataString); lineOut($dataString); } lineOut(__METHOD__ . ' - original;'); lineOut($data); }
/** * @uses $this->regex * @param mixed $data * @return array matches */ protected function get($data) { $dataExtended = $data; if (is_array($data)) { $dataExtended = implode(" ", $data); } $matches = pregMatchAll($dataExtended, $this->regex); if (is_array($matches)) { $matches = Arr::flatten($matches); } if (is_array($matches) && count($matches) === 0 && $this->outPorts['error']->isAttached()) { $this->outPorts['error']->send($matches); } Emitter::emit('regex.inout', $matches, static::class); return $matches; }
/** * Process data to output on browser * * @param bool $object * @return array */ public function process($object = false) { $this->output = []; foreach ($this->results as $row) { $data = Helper::convertToArray($row); $value = $this->addColumns($data, $row); $value = $this->editColumns($value, $row); $value = $this->setupRowVariables($value, $row); if (!$object) { $value = Arr::flatten($this->removeExcessColumns($value)); } else { $value = $this->removeExcessColumns($value); } $this->output[] = $value; } return $this->output; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param string $target_field * @param string $glue * @param string,... $source_field * @return mixed */ public function handle($request, Closure $next, $target_field, $glue = 'COMMA', $source_field = null) { //Commas can’t be used by \Illuminate\Pipeline\Pipeline::parsePipeString $glue = str_replace('COMMA', ',', $glue); $source_fields = array_slice(func_get_args(), 4); $concat_values = []; if (count($source_fields)) { foreach ($source_fields as $source_field) { $source_value = $request->input($source_field); if (is_array($source_value) or strlen($source_value)) { $concat_values[] = $source_value; } else { //This value is empty so stop here and only concatenate the collected values break; } } } else { $concat_values = (array) $request->input($target_field); } $concat_values = Arr::flatten($concat_values); $this->setRequestInput($request, $target_field, implode($glue, $concat_values)); return $next($request); }
/** * Get a flattened array of the items in the collection. * * @param int $depth * @return static */ public function flatten($depth = INF) { return new static(Arr::flatten($this->items, $depth)); }
/** * Flatten a multi-dimensional array into a single level. * * @param array $array * @param int $depth * @return array */ function array_flatten($array, $depth = INF) { return Arr::flatten($array, $depth); }
/** * Get sColumns output * * @return array */ private function getOutputColumns() { $columns = array_merge($this->useDataColumns(), $this->sColumns); $columns = array_diff($columns, $this->excess_columns); return Arr::flatten($columns); }
/** * Get the current query value bindings in a flattened array. * * @return array */ public function getBindings() { return Arr::flatten($this->bindings); }
/** * Get all relations of model from callable. * * @return array */ public function getRelations() { $relations = $columns = []; foreach ($this->builder->fields() as $field) { $columns[] = $field->column(); } foreach (Arr::flatten($columns) as $column) { if (Str::contains($column, '.')) { list($relation) = explode('.', $column); if (method_exists($this->model, $relation) && $this->model->{$relation}() instanceof Relation) { $relations[] = $relation; } } elseif (method_exists($this->model, $column)) { $relations[] = $column; } } return array_unique($relations); }
/** * Flatten a multi-dimensional array into a single level. * * @param array $array * @return array */ function array_flatten($array) { return Arr::flatten($array); }
/** * Prepare the bindings for an update statement. * * @param array $bindings * @param array $values * @return array */ public function prepareBindingsForUpdate(array $bindings, array $values) { $bindingsWithoutJoin = Arr::except($bindings, 'join'); return array_values(array_merge($values, $bindings['join'], Arr::flatten($bindingsWithoutJoin))); }
/** * Get sColumns output. * * @return array */ public function getOutputColumns() { $columns = array_merge($this->columns, $this->sColumns); $columns = array_diff($columns, $this->excess_columns); return Arr::flatten($columns); }
/** * Get a flattened array of the items in the collection. * * @return static */ public function flatten() { return new static(Arr::flatten($this->items)); }
/** * Get custom required fields from the configs * so that we can automatically bind them to the model * fillable property. * * @return mixed */ public function getCustomFillableFields() { if (function_exists('app') && app() instanceof Container) { return Arr::flatten(config('notifynder.additional_fields', [])); } return []; }
public function __invoke($data) { lineOut(__METHOD__); $content = (string) $data['content']; if (is_array($this->matches)) { for ($i = 0; $i <= count($this->matches) / 2; $i++) { unset($this->matches[$i]); } } if (!is_array($this->matches)) { $this->matches = array($this->matches); } foreach ($this->matches as $key => $match) { # with and without `.` & `#` #" match " #"match" #"match " // ([a-zA-Z0-9-\s]*) preg_match_all('/(?<=\'|")(.*?)(?=\'|\\")/', $match, $matches); // echo "MATCHES"; // dump($matches); $matches = $matches[1]; $matches = Arr::flatten($matches); $matchCopy = ""; foreach ($matches as $match2) { // if we remove the original, is there leftover? if so, it may be part of something else. // if (strlen(str_replace($data['original'], "", $match2))) // we do not want to replace it if there are letters or numbers or - or _ before or after it // we do want to replace it if any other character is right before or after it $originalLength = strlen($data['original']); // what we want to replace is longer than the match, not possible. if ($originalLength > strlen($match2)) { continue; } $positions = substringAll($match2, $data['original']); $disallowedChars = array_merge(range('a', 'z'), range('A', 'Z'), range('0', '9'), ['-', '_', '+']); // ECHO "<H1>LINEOUT</H1>"; // dump($positions); if (!empty($positions)) { foreach ($positions as $position) { // starting one character before, and going one character longer // ECHO "<H1>positionPlusMinusOnePos</H1>"; // dump($position); $startingPosition = $position === 0 ? $position : $position - 1; $positionPlusMinusOne = substr($match2, $startingPosition, $originalLength + 1); $endOfPositionMinusOne = substr($positionPlusMinusOne, -1); $endOfDataOriginal = substr($data['original'], -1); // they are the same length as the original or match, nothing different. // we know they are the same value, nothing different if (strlen($positionPlusMinusOne) === $originalLength && $positionPlusMinusOne === strlen($match2) && $data['original'] === $positionPlusMinusOne) { $replaced = str_replace($data['original'], $data['new'], $match2); $content = str_replace($match2, $replaced, $content); // $data['content']->setContent($content); //dump($data); continue; } /* ECHO "<H1>positionPlusMinusOne</H1>"; dump($positionPlusMinusOne); dump($data['original']); dump($originalLength + 1); dump($position); dump($startingPosition); dump($match2); dump($content); */ // we know the first char of both are not the same so we check if ($data['original'][0] !== $positionPlusMinusOne[0]) { if (containsAnySubStrings($positionPlusMinusOne[0], $disallowedChars)) { // ECHO "<H1>IT HAS SOME SHIT in [0]</H1>"; // dump($positionPlusMinusOne[0]); continue; } } if ($endOfDataOriginal !== $endOfPositionMinusOne) { if (containsAnySubStrings($endOfPositionMinusOne, $disallowedChars)) { // ECHO "<H1>IT HAS SOME SHIT in end</H1>"; // dump($endOfPositionMinusOne); continue; } } $replaced = str_replace($data['original'], $data['new'], $match2); $content = str_replace('"' . $match2 . '"', '"' . $replaced . '"', $content); $content = str_replace("'" . $match2 . "'", "'" . $replaced . "'", $content); $data['content']->setContent($content); // echo("<h3>JAVASCRIPT replaced: </h3>"); // dump($replaced); // dump($replaced); //dump($data); /* ECHO "<H1>positionPlusMinusOne</H1>"; dump($positionPlusMinusOne); dump($data['original']); dump($originalLength + 1); dump($position); dump($startingPosition); dump($match2); */ } } /*else { $replaced = str_replace($data['original'], $data['new'], $match2); $content = str_replace($match2, $replaced, $content); echo("<h3> elsed</h3>"); dump($data['original']); dump($data['new']); dump($match2); dump($replaced); dump($data); // dump($content); }*/ } $data['content']->setContent($content); // echo("<h3>JAVASCRIPT match: </h3>"); // dump($match2); // dump($data); } $this->sendIfAttached('out', $data['content']); }