repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
orangehill/iseed
src/Orangehill/Iseed/IseedCommand.php
IseedCommand.generateFileName
protected function generateFileName($table, $prefix=null, $suffix=null) { if (!\Schema::connection($this->option('database') ? $this->option('database') : config('database.default'))->hasTable($table)) { throw new TableNotFoundException("Table $table was not found."); } // Generate class name and file name $className = app('iseed')->generateClassName($table, $prefix, $suffix); $seedPath = base_path() . config('iseed::config.path'); return [$seedPath . '/' . $className . '.php', $className . '.php']; }
php
protected function generateFileName($table, $prefix=null, $suffix=null) { if (!\Schema::connection($this->option('database') ? $this->option('database') : config('database.default'))->hasTable($table)) { throw new TableNotFoundException("Table $table was not found."); } // Generate class name and file name $className = app('iseed')->generateClassName($table, $prefix, $suffix); $seedPath = base_path() . config('iseed::config.path'); return [$seedPath . '/' . $className . '.php', $className . '.php']; }
[ "protected", "function", "generateFileName", "(", "$", "table", ",", "$", "prefix", "=", "null", ",", "$", "suffix", "=", "null", ")", "{", "if", "(", "!", "\\", "Schema", "::", "connection", "(", "$", "this", "->", "option", "(", "'database'", ")", "?", "$", "this", "->", "option", "(", "'database'", ")", ":", "config", "(", "'database.default'", ")", ")", "->", "hasTable", "(", "$", "table", ")", ")", "{", "throw", "new", "TableNotFoundException", "(", "\"Table $table was not found.\"", ")", ";", "}", "// Generate class name and file name", "$", "className", "=", "app", "(", "'iseed'", ")", "->", "generateClassName", "(", "$", "table", ",", "$", "prefix", ",", "$", "suffix", ")", ";", "$", "seedPath", "=", "base_path", "(", ")", ".", "config", "(", "'iseed::config.path'", ")", ";", "return", "[", "$", "seedPath", ".", "'/'", ".", "$", "className", ".", "'.php'", ",", "$", "className", ".", "'.php'", "]", ";", "}" ]
Generate file name, to be used in test wether seed file already exist @param string $table @return string
[ "Generate", "file", "name", "to", "be", "used", "in", "test", "wether", "seed", "file", "already", "exist" ]
38b9cdc74af79a605ad5110d7ce60e34f3e1f3bf
https://github.com/orangehill/iseed/blob/38b9cdc74af79a605ad5110d7ce60e34f3e1f3bf/src/Orangehill/Iseed/IseedCommand.php#L201-L211
train
orangehill/iseed
src/Orangehill/Iseed/Iseed.php
Iseed.generateSeed
public function generateSeed($table, $prefix=null, $suffix=null, $database = null, $max = 0, $chunkSize = 0, $exclude = null, $prerunEvent = null, $postrunEvent = null, $dumpAuto = true, $indexed = true, $orderBy = null, $direction = 'ASC') { if (!$database) { $database = config('database.default'); } $this->databaseName = $database; // Check if table exists if (!$this->hasTable($table)) { throw new TableNotFoundException("Table $table was not found."); } // Get the data $data = $this->getData($table, $max, $exclude, $orderBy, $direction); // Repack the data $dataArray = $this->repackSeedData($data); // Generate class name $className = $this->generateClassName($table, $prefix, $suffix); // Get template for a seed file contents $stub = $this->readStubFile($this->getStubPath() . '/seed.stub'); // Get a seed folder path $seedPath = $this->getSeedPath(); // Get a app/database/seeds path $seedsPath = $this->getPath($className, $seedPath); // Get a populated stub file $seedContent = $this->populateStub( $className, $stub, $table, $dataArray, $chunkSize, $prerunEvent, $postrunEvent, $indexed ); // Save a populated stub $this->files->put($seedsPath, $seedContent); // Run composer dump-auto if ($dumpAuto) { $this->composer->dumpAutoloads(); } // Update the DatabaseSeeder.php file return $this->updateDatabaseSeederRunMethod($className) !== false; }
php
public function generateSeed($table, $prefix=null, $suffix=null, $database = null, $max = 0, $chunkSize = 0, $exclude = null, $prerunEvent = null, $postrunEvent = null, $dumpAuto = true, $indexed = true, $orderBy = null, $direction = 'ASC') { if (!$database) { $database = config('database.default'); } $this->databaseName = $database; // Check if table exists if (!$this->hasTable($table)) { throw new TableNotFoundException("Table $table was not found."); } // Get the data $data = $this->getData($table, $max, $exclude, $orderBy, $direction); // Repack the data $dataArray = $this->repackSeedData($data); // Generate class name $className = $this->generateClassName($table, $prefix, $suffix); // Get template for a seed file contents $stub = $this->readStubFile($this->getStubPath() . '/seed.stub'); // Get a seed folder path $seedPath = $this->getSeedPath(); // Get a app/database/seeds path $seedsPath = $this->getPath($className, $seedPath); // Get a populated stub file $seedContent = $this->populateStub( $className, $stub, $table, $dataArray, $chunkSize, $prerunEvent, $postrunEvent, $indexed ); // Save a populated stub $this->files->put($seedsPath, $seedContent); // Run composer dump-auto if ($dumpAuto) { $this->composer->dumpAutoloads(); } // Update the DatabaseSeeder.php file return $this->updateDatabaseSeederRunMethod($className) !== false; }
[ "public", "function", "generateSeed", "(", "$", "table", ",", "$", "prefix", "=", "null", ",", "$", "suffix", "=", "null", ",", "$", "database", "=", "null", ",", "$", "max", "=", "0", ",", "$", "chunkSize", "=", "0", ",", "$", "exclude", "=", "null", ",", "$", "prerunEvent", "=", "null", ",", "$", "postrunEvent", "=", "null", ",", "$", "dumpAuto", "=", "true", ",", "$", "indexed", "=", "true", ",", "$", "orderBy", "=", "null", ",", "$", "direction", "=", "'ASC'", ")", "{", "if", "(", "!", "$", "database", ")", "{", "$", "database", "=", "config", "(", "'database.default'", ")", ";", "}", "$", "this", "->", "databaseName", "=", "$", "database", ";", "// Check if table exists", "if", "(", "!", "$", "this", "->", "hasTable", "(", "$", "table", ")", ")", "{", "throw", "new", "TableNotFoundException", "(", "\"Table $table was not found.\"", ")", ";", "}", "// Get the data", "$", "data", "=", "$", "this", "->", "getData", "(", "$", "table", ",", "$", "max", ",", "$", "exclude", ",", "$", "orderBy", ",", "$", "direction", ")", ";", "// Repack the data", "$", "dataArray", "=", "$", "this", "->", "repackSeedData", "(", "$", "data", ")", ";", "// Generate class name", "$", "className", "=", "$", "this", "->", "generateClassName", "(", "$", "table", ",", "$", "prefix", ",", "$", "suffix", ")", ";", "// Get template for a seed file contents", "$", "stub", "=", "$", "this", "->", "readStubFile", "(", "$", "this", "->", "getStubPath", "(", ")", ".", "'/seed.stub'", ")", ";", "// Get a seed folder path", "$", "seedPath", "=", "$", "this", "->", "getSeedPath", "(", ")", ";", "// Get a app/database/seeds path", "$", "seedsPath", "=", "$", "this", "->", "getPath", "(", "$", "className", ",", "$", "seedPath", ")", ";", "// Get a populated stub file", "$", "seedContent", "=", "$", "this", "->", "populateStub", "(", "$", "className", ",", "$", "stub", ",", "$", "table", ",", "$", "dataArray", ",", "$", "chunkSize", ",", "$", "prerunEvent", ",", "$", "postrunEvent", ",", "$", "indexed", ")", ";", "// Save a populated stub", "$", "this", "->", "files", "->", "put", "(", "$", "seedsPath", ",", "$", "seedContent", ")", ";", "// Run composer dump-auto", "if", "(", "$", "dumpAuto", ")", "{", "$", "this", "->", "composer", "->", "dumpAutoloads", "(", ")", ";", "}", "// Update the DatabaseSeeder.php file", "return", "$", "this", "->", "updateDatabaseSeederRunMethod", "(", "$", "className", ")", "!==", "false", ";", "}" ]
Generates a seed file. @param string $table @param string $prefix @param string $suffix @param string $database @param int $max @param string $prerunEvent @param string $postunEvent @return bool @throws Orangehill\Iseed\TableNotFoundException
[ "Generates", "a", "seed", "file", "." ]
38b9cdc74af79a605ad5110d7ce60e34f3e1f3bf
https://github.com/orangehill/iseed/blob/38b9cdc74af79a605ad5110d7ce60e34f3e1f3bf/src/Orangehill/Iseed/Iseed.php#L64-L117
train
orangehill/iseed
src/Orangehill/Iseed/Iseed.php
Iseed.getData
public function getData($table, $max, $exclude = null, $orderBy = null, $direction = 'ASC') { $result = \DB::connection($this->databaseName)->table($table); if (!empty($exclude)) { $allColumns = \DB::connection($this->databaseName)->getSchemaBuilder()->getColumnListing($table); $result = $result->select(array_diff($allColumns, $exclude)); } if($orderBy) { $result = $result->orderBy($orderBy, $direction); } if ($max) { $result = $result->limit($max); } return $result->get(); }
php
public function getData($table, $max, $exclude = null, $orderBy = null, $direction = 'ASC') { $result = \DB::connection($this->databaseName)->table($table); if (!empty($exclude)) { $allColumns = \DB::connection($this->databaseName)->getSchemaBuilder()->getColumnListing($table); $result = $result->select(array_diff($allColumns, $exclude)); } if($orderBy) { $result = $result->orderBy($orderBy, $direction); } if ($max) { $result = $result->limit($max); } return $result->get(); }
[ "public", "function", "getData", "(", "$", "table", ",", "$", "max", ",", "$", "exclude", "=", "null", ",", "$", "orderBy", "=", "null", ",", "$", "direction", "=", "'ASC'", ")", "{", "$", "result", "=", "\\", "DB", "::", "connection", "(", "$", "this", "->", "databaseName", ")", "->", "table", "(", "$", "table", ")", ";", "if", "(", "!", "empty", "(", "$", "exclude", ")", ")", "{", "$", "allColumns", "=", "\\", "DB", "::", "connection", "(", "$", "this", "->", "databaseName", ")", "->", "getSchemaBuilder", "(", ")", "->", "getColumnListing", "(", "$", "table", ")", ";", "$", "result", "=", "$", "result", "->", "select", "(", "array_diff", "(", "$", "allColumns", ",", "$", "exclude", ")", ")", ";", "}", "if", "(", "$", "orderBy", ")", "{", "$", "result", "=", "$", "result", "->", "orderBy", "(", "$", "orderBy", ",", "$", "direction", ")", ";", "}", "if", "(", "$", "max", ")", "{", "$", "result", "=", "$", "result", "->", "limit", "(", "$", "max", ")", ";", "}", "return", "$", "result", "->", "get", "(", ")", ";", "}" ]
Get the Data @param string $table @return Array
[ "Get", "the", "Data" ]
38b9cdc74af79a605ad5110d7ce60e34f3e1f3bf
https://github.com/orangehill/iseed/blob/38b9cdc74af79a605ad5110d7ce60e34f3e1f3bf/src/Orangehill/Iseed/Iseed.php#L133-L151
train
orangehill/iseed
src/Orangehill/Iseed/Iseed.php
Iseed.repackSeedData
public function repackSeedData($data) { if (!is_array($data)) { $data = $data->toArray(); } $dataArray = array(); if (!empty($data)) { foreach ($data as $row) { $rowArray = array(); foreach ($row as $columnName => $columnValue) { $rowArray[$columnName] = $columnValue; } $dataArray[] = $rowArray; } } return $dataArray; }
php
public function repackSeedData($data) { if (!is_array($data)) { $data = $data->toArray(); } $dataArray = array(); if (!empty($data)) { foreach ($data as $row) { $rowArray = array(); foreach ($row as $columnName => $columnValue) { $rowArray[$columnName] = $columnValue; } $dataArray[] = $rowArray; } } return $dataArray; }
[ "public", "function", "repackSeedData", "(", "$", "data", ")", "{", "if", "(", "!", "is_array", "(", "$", "data", ")", ")", "{", "$", "data", "=", "$", "data", "->", "toArray", "(", ")", ";", "}", "$", "dataArray", "=", "array", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "data", ")", ")", "{", "foreach", "(", "$", "data", "as", "$", "row", ")", "{", "$", "rowArray", "=", "array", "(", ")", ";", "foreach", "(", "$", "row", "as", "$", "columnName", "=>", "$", "columnValue", ")", "{", "$", "rowArray", "[", "$", "columnName", "]", "=", "$", "columnValue", ";", "}", "$", "dataArray", "[", "]", "=", "$", "rowArray", ";", "}", "}", "return", "$", "dataArray", ";", "}" ]
Repacks data read from the database @param array|object $data @return array
[ "Repacks", "data", "read", "from", "the", "database" ]
38b9cdc74af79a605ad5110d7ce60e34f3e1f3bf
https://github.com/orangehill/iseed/blob/38b9cdc74af79a605ad5110d7ce60e34f3e1f3bf/src/Orangehill/Iseed/Iseed.php#L158-L174
train
orangehill/iseed
src/Orangehill/Iseed/Iseed.php
Iseed.populateStub
public function populateStub($class, $stub, $table, $data, $chunkSize = null, $prerunEvent = null, $postrunEvent = null, $indexed = true) { $chunkSize = $chunkSize ?: config('iseed::config.chunk_size'); $inserts = ''; $chunks = array_chunk($data, $chunkSize); foreach ($chunks as $chunk) { $this->addNewLines($inserts); $this->addIndent($inserts, 2); $inserts .= sprintf( "\DB::table('%s')->insert(%s);", $table, $this->prettifyArray($chunk, $indexed) ); } $stub = str_replace('{{class}}', $class, $stub); $prerunEventInsert = ''; if ($prerunEvent) { $prerunEventInsert .= "\$response = Event::until(new $prerunEvent());"; $this->addNewLines($prerunEventInsert); $this->addIndent($prerunEventInsert, 2); $prerunEventInsert .= 'if ($response === false) {'; $this->addNewLines($prerunEventInsert); $this->addIndent($prerunEventInsert, 3); $prerunEventInsert .= 'throw new Exception("Prerun event failed, seed wasn\'t executed!");'; $this->addNewLines($prerunEventInsert); $this->addIndent($prerunEventInsert, 2); $prerunEventInsert .= '}'; } $stub = str_replace( '{{prerun_event}}', $prerunEventInsert, $stub ); if (!is_null($table)) { $stub = str_replace('{{table}}', $table, $stub); } $postrunEventInsert = ''; if ($postrunEvent) { $postrunEventInsert .= "\$response = Event::until(new $postrunEvent());"; $this->addNewLines($postrunEventInsert); $this->addIndent($postrunEventInsert, 2); $postrunEventInsert .= 'if ($response === false) {'; $this->addNewLines($postrunEventInsert); $this->addIndent($postrunEventInsert, 3); $postrunEventInsert .= 'throw new Exception("Seed was executed but the postrun event failed!");'; $this->addNewLines($postrunEventInsert); $this->addIndent($postrunEventInsert, 2); $postrunEventInsert .= '}'; } $stub = str_replace( '{{postrun_event}}', $postrunEventInsert, $stub ); $stub = str_replace('{{insert_statements}}', $inserts, $stub); return $stub; }
php
public function populateStub($class, $stub, $table, $data, $chunkSize = null, $prerunEvent = null, $postrunEvent = null, $indexed = true) { $chunkSize = $chunkSize ?: config('iseed::config.chunk_size'); $inserts = ''; $chunks = array_chunk($data, $chunkSize); foreach ($chunks as $chunk) { $this->addNewLines($inserts); $this->addIndent($inserts, 2); $inserts .= sprintf( "\DB::table('%s')->insert(%s);", $table, $this->prettifyArray($chunk, $indexed) ); } $stub = str_replace('{{class}}', $class, $stub); $prerunEventInsert = ''; if ($prerunEvent) { $prerunEventInsert .= "\$response = Event::until(new $prerunEvent());"; $this->addNewLines($prerunEventInsert); $this->addIndent($prerunEventInsert, 2); $prerunEventInsert .= 'if ($response === false) {'; $this->addNewLines($prerunEventInsert); $this->addIndent($prerunEventInsert, 3); $prerunEventInsert .= 'throw new Exception("Prerun event failed, seed wasn\'t executed!");'; $this->addNewLines($prerunEventInsert); $this->addIndent($prerunEventInsert, 2); $prerunEventInsert .= '}'; } $stub = str_replace( '{{prerun_event}}', $prerunEventInsert, $stub ); if (!is_null($table)) { $stub = str_replace('{{table}}', $table, $stub); } $postrunEventInsert = ''; if ($postrunEvent) { $postrunEventInsert .= "\$response = Event::until(new $postrunEvent());"; $this->addNewLines($postrunEventInsert); $this->addIndent($postrunEventInsert, 2); $postrunEventInsert .= 'if ($response === false) {'; $this->addNewLines($postrunEventInsert); $this->addIndent($postrunEventInsert, 3); $postrunEventInsert .= 'throw new Exception("Seed was executed but the postrun event failed!");'; $this->addNewLines($postrunEventInsert); $this->addIndent($postrunEventInsert, 2); $postrunEventInsert .= '}'; } $stub = str_replace( '{{postrun_event}}', $postrunEventInsert, $stub ); $stub = str_replace('{{insert_statements}}', $inserts, $stub); return $stub; }
[ "public", "function", "populateStub", "(", "$", "class", ",", "$", "stub", ",", "$", "table", ",", "$", "data", ",", "$", "chunkSize", "=", "null", ",", "$", "prerunEvent", "=", "null", ",", "$", "postrunEvent", "=", "null", ",", "$", "indexed", "=", "true", ")", "{", "$", "chunkSize", "=", "$", "chunkSize", "?", ":", "config", "(", "'iseed::config.chunk_size'", ")", ";", "$", "inserts", "=", "''", ";", "$", "chunks", "=", "array_chunk", "(", "$", "data", ",", "$", "chunkSize", ")", ";", "foreach", "(", "$", "chunks", "as", "$", "chunk", ")", "{", "$", "this", "->", "addNewLines", "(", "$", "inserts", ")", ";", "$", "this", "->", "addIndent", "(", "$", "inserts", ",", "2", ")", ";", "$", "inserts", ".=", "sprintf", "(", "\"\\DB::table('%s')->insert(%s);\"", ",", "$", "table", ",", "$", "this", "->", "prettifyArray", "(", "$", "chunk", ",", "$", "indexed", ")", ")", ";", "}", "$", "stub", "=", "str_replace", "(", "'{{class}}'", ",", "$", "class", ",", "$", "stub", ")", ";", "$", "prerunEventInsert", "=", "''", ";", "if", "(", "$", "prerunEvent", ")", "{", "$", "prerunEventInsert", ".=", "\"\\$response = Event::until(new $prerunEvent());\"", ";", "$", "this", "->", "addNewLines", "(", "$", "prerunEventInsert", ")", ";", "$", "this", "->", "addIndent", "(", "$", "prerunEventInsert", ",", "2", ")", ";", "$", "prerunEventInsert", ".=", "'if ($response === false) {'", ";", "$", "this", "->", "addNewLines", "(", "$", "prerunEventInsert", ")", ";", "$", "this", "->", "addIndent", "(", "$", "prerunEventInsert", ",", "3", ")", ";", "$", "prerunEventInsert", ".=", "'throw new Exception(\"Prerun event failed, seed wasn\\'t executed!\");'", ";", "$", "this", "->", "addNewLines", "(", "$", "prerunEventInsert", ")", ";", "$", "this", "->", "addIndent", "(", "$", "prerunEventInsert", ",", "2", ")", ";", "$", "prerunEventInsert", ".=", "'}'", ";", "}", "$", "stub", "=", "str_replace", "(", "'{{prerun_event}}'", ",", "$", "prerunEventInsert", ",", "$", "stub", ")", ";", "if", "(", "!", "is_null", "(", "$", "table", ")", ")", "{", "$", "stub", "=", "str_replace", "(", "'{{table}}'", ",", "$", "table", ",", "$", "stub", ")", ";", "}", "$", "postrunEventInsert", "=", "''", ";", "if", "(", "$", "postrunEvent", ")", "{", "$", "postrunEventInsert", ".=", "\"\\$response = Event::until(new $postrunEvent());\"", ";", "$", "this", "->", "addNewLines", "(", "$", "postrunEventInsert", ")", ";", "$", "this", "->", "addIndent", "(", "$", "postrunEventInsert", ",", "2", ")", ";", "$", "postrunEventInsert", ".=", "'if ($response === false) {'", ";", "$", "this", "->", "addNewLines", "(", "$", "postrunEventInsert", ")", ";", "$", "this", "->", "addIndent", "(", "$", "postrunEventInsert", ",", "3", ")", ";", "$", "postrunEventInsert", ".=", "'throw new Exception(\"Seed was executed but the postrun event failed!\");'", ";", "$", "this", "->", "addNewLines", "(", "$", "postrunEventInsert", ")", ";", "$", "this", "->", "addIndent", "(", "$", "postrunEventInsert", ",", "2", ")", ";", "$", "postrunEventInsert", ".=", "'}'", ";", "}", "$", "stub", "=", "str_replace", "(", "'{{postrun_event}}'", ",", "$", "postrunEventInsert", ",", "$", "stub", ")", ";", "$", "stub", "=", "str_replace", "(", "'{{insert_statements}}'", ",", "$", "inserts", ",", "$", "stub", ")", ";", "return", "$", "stub", ";", "}" ]
Populate the place-holders in the seed stub. @param string $class @param string $stub @param string $table @param string $data @param int $chunkSize @param string $prerunEvent @param string $postunEvent @return string
[ "Populate", "the", "place", "-", "holders", "in", "the", "seed", "stub", "." ]
38b9cdc74af79a605ad5110d7ce60e34f3e1f3bf
https://github.com/orangehill/iseed/blob/38b9cdc74af79a605ad5110d7ce60e34f3e1f3bf/src/Orangehill/Iseed/Iseed.php#L223-L284
train
orangehill/iseed
src/Orangehill/Iseed/Iseed.php
Iseed.prettifyArray
protected function prettifyArray($array, $indexed = true) { $content = ($indexed) ? var_export($array, true) : preg_replace("/[0-9]+ \=\>/i", '', var_export($array, true)); $lines = explode("\n", $content); $inString = false; $tabCount = 3; for ($i = 1; $i < count($lines); $i++) { $lines[$i] = ltrim($lines[$i]); //Check for closing bracket if (strpos($lines[$i], ')') !== false) { $tabCount--; } //Insert tab count if ($inString === false) { for ($j = 0; $j < $tabCount; $j++) { $lines[$i] = substr_replace($lines[$i], $this->indentCharacter, 0, 0); } } for ($j = 0; $j < strlen($lines[$i]); $j++) { //skip character right after an escape \ if ($lines[$i][$j] == '\\') { $j++; } //check string open/end else if ($lines[$i][$j] == '\'') { $inString = !$inString; } } //check for openning bracket if (strpos($lines[$i], '(') !== false) { $tabCount++; } } $content = implode("\n", $lines); return $content; }
php
protected function prettifyArray($array, $indexed = true) { $content = ($indexed) ? var_export($array, true) : preg_replace("/[0-9]+ \=\>/i", '', var_export($array, true)); $lines = explode("\n", $content); $inString = false; $tabCount = 3; for ($i = 1; $i < count($lines); $i++) { $lines[$i] = ltrim($lines[$i]); //Check for closing bracket if (strpos($lines[$i], ')') !== false) { $tabCount--; } //Insert tab count if ($inString === false) { for ($j = 0; $j < $tabCount; $j++) { $lines[$i] = substr_replace($lines[$i], $this->indentCharacter, 0, 0); } } for ($j = 0; $j < strlen($lines[$i]); $j++) { //skip character right after an escape \ if ($lines[$i][$j] == '\\') { $j++; } //check string open/end else if ($lines[$i][$j] == '\'') { $inString = !$inString; } } //check for openning bracket if (strpos($lines[$i], '(') !== false) { $tabCount++; } } $content = implode("\n", $lines); return $content; }
[ "protected", "function", "prettifyArray", "(", "$", "array", ",", "$", "indexed", "=", "true", ")", "{", "$", "content", "=", "(", "$", "indexed", ")", "?", "var_export", "(", "$", "array", ",", "true", ")", ":", "preg_replace", "(", "\"/[0-9]+ \\=\\>/i\"", ",", "''", ",", "var_export", "(", "$", "array", ",", "true", ")", ")", ";", "$", "lines", "=", "explode", "(", "\"\\n\"", ",", "$", "content", ")", ";", "$", "inString", "=", "false", ";", "$", "tabCount", "=", "3", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<", "count", "(", "$", "lines", ")", ";", "$", "i", "++", ")", "{", "$", "lines", "[", "$", "i", "]", "=", "ltrim", "(", "$", "lines", "[", "$", "i", "]", ")", ";", "//Check for closing bracket", "if", "(", "strpos", "(", "$", "lines", "[", "$", "i", "]", ",", "')'", ")", "!==", "false", ")", "{", "$", "tabCount", "--", ";", "}", "//Insert tab count", "if", "(", "$", "inString", "===", "false", ")", "{", "for", "(", "$", "j", "=", "0", ";", "$", "j", "<", "$", "tabCount", ";", "$", "j", "++", ")", "{", "$", "lines", "[", "$", "i", "]", "=", "substr_replace", "(", "$", "lines", "[", "$", "i", "]", ",", "$", "this", "->", "indentCharacter", ",", "0", ",", "0", ")", ";", "}", "}", "for", "(", "$", "j", "=", "0", ";", "$", "j", "<", "strlen", "(", "$", "lines", "[", "$", "i", "]", ")", ";", "$", "j", "++", ")", "{", "//skip character right after an escape \\", "if", "(", "$", "lines", "[", "$", "i", "]", "[", "$", "j", "]", "==", "'\\\\'", ")", "{", "$", "j", "++", ";", "}", "//check string open/end", "else", "if", "(", "$", "lines", "[", "$", "i", "]", "[", "$", "j", "]", "==", "'\\''", ")", "{", "$", "inString", "=", "!", "$", "inString", ";", "}", "}", "//check for openning bracket", "if", "(", "strpos", "(", "$", "lines", "[", "$", "i", "]", ",", "'('", ")", "!==", "false", ")", "{", "$", "tabCount", "++", ";", "}", "}", "$", "content", "=", "implode", "(", "\"\\n\"", ",", "$", "lines", ")", ";", "return", "$", "content", ";", "}" ]
Prettify a var_export of an array @param array $array @return string
[ "Prettify", "a", "var_export", "of", "an", "array" ]
38b9cdc74af79a605ad5110d7ce60e34f3e1f3bf
https://github.com/orangehill/iseed/blob/38b9cdc74af79a605ad5110d7ce60e34f3e1f3bf/src/Orangehill/Iseed/Iseed.php#L302-L347
train
orangehill/iseed
src/Orangehill/Iseed/Iseed.php
Iseed.cleanSection
public function cleanSection() { $databaseSeederPath = base_path() . config('iseed::config.path') . '/DatabaseSeeder.php'; $content = $this->files->get($databaseSeederPath); $content = preg_replace("/(\#iseed_start.+?)\#iseed_end/us", "#iseed_start\n\t\t#iseed_end", $content); return $this->files->put($databaseSeederPath, $content) !== false; return false; }
php
public function cleanSection() { $databaseSeederPath = base_path() . config('iseed::config.path') . '/DatabaseSeeder.php'; $content = $this->files->get($databaseSeederPath); $content = preg_replace("/(\#iseed_start.+?)\#iseed_end/us", "#iseed_start\n\t\t#iseed_end", $content); return $this->files->put($databaseSeederPath, $content) !== false; return false; }
[ "public", "function", "cleanSection", "(", ")", "{", "$", "databaseSeederPath", "=", "base_path", "(", ")", ".", "config", "(", "'iseed::config.path'", ")", ".", "'/DatabaseSeeder.php'", ";", "$", "content", "=", "$", "this", "->", "files", "->", "get", "(", "$", "databaseSeederPath", ")", ";", "$", "content", "=", "preg_replace", "(", "\"/(\\#iseed_start.+?)\\#iseed_end/us\"", ",", "\"#iseed_start\\n\\t\\t#iseed_end\"", ",", "$", "content", ")", ";", "return", "$", "this", "->", "files", "->", "put", "(", "$", "databaseSeederPath", ",", "$", "content", ")", "!==", "false", ";", "return", "false", ";", "}" ]
Cleans the iSeed section @return bool
[ "Cleans", "the", "iSeed", "section" ]
38b9cdc74af79a605ad5110d7ce60e34f3e1f3bf
https://github.com/orangehill/iseed/blob/38b9cdc74af79a605ad5110d7ce60e34f3e1f3bf/src/Orangehill/Iseed/Iseed.php#L381-L391
train
infection/infection
src/Mutator/Arithmetic/MinusEqual.php
MinusEqual.mutate
public function mutate(Node $node) { return new Node\Expr\AssignOp\Plus($node->var, $node->expr, $node->getAttributes()); }
php
public function mutate(Node $node) { return new Node\Expr\AssignOp\Plus($node->var, $node->expr, $node->getAttributes()); }
[ "public", "function", "mutate", "(", "Node", "$", "node", ")", "{", "return", "new", "Node", "\\", "Expr", "\\", "AssignOp", "\\", "Plus", "(", "$", "node", "->", "var", ",", "$", "node", "->", "expr", ",", "$", "node", "->", "getAttributes", "(", ")", ")", ";", "}" ]
Replaces "-=" with "+=" @return Node\Expr\AssignOp\Plus
[ "Replaces", "-", "=", "with", "+", "=" ]
f7708dbd35fd39498e25193a88e694549dc8f46c
https://github.com/infection/infection/blob/f7708dbd35fd39498e25193a88e694549dc8f46c/src/Mutator/Arithmetic/MinusEqual.php#L52-L55
train
infection/infection
src/Mutant/MetricsCalculator.php
MetricsCalculator.createFromArray
public static function createFromArray(array $mutantProcesses): self { $self = new self(); foreach ($mutantProcesses as $process) { $self->collect($process); } return $self; }
php
public static function createFromArray(array $mutantProcesses): self { $self = new self(); foreach ($mutantProcesses as $process) { $self->collect($process); } return $self; }
[ "public", "static", "function", "createFromArray", "(", "array", "$", "mutantProcesses", ")", ":", "self", "{", "$", "self", "=", "new", "self", "(", ")", ";", "foreach", "(", "$", "mutantProcesses", "as", "$", "process", ")", "{", "$", "self", "->", "collect", "(", "$", "process", ")", ";", "}", "return", "$", "self", ";", "}" ]
Build a metric calculator with a sub-set of mutators @param MutantProcessInterface[] $mutantProcesses @return MetricsCalculator
[ "Build", "a", "metric", "calculator", "with", "a", "sub", "-", "set", "of", "mutators" ]
f7708dbd35fd39498e25193a88e694549dc8f46c
https://github.com/infection/infection/blob/f7708dbd35fd39498e25193a88e694549dc8f46c/src/Mutant/MetricsCalculator.php#L108-L117
train
infection/infection
src/Mutant/MetricsCalculator.php
MetricsCalculator.getCoverageRate
public function getCoverageRate(): float { $coveredRate = 0; $coveredByTestsTotal = $this->totalMutantsCount - $this->notCoveredByTestsCount; if ($this->totalMutantsCount) { $coveredRate = floor(100 * $coveredByTestsTotal / $this->totalMutantsCount); } return $coveredRate; }
php
public function getCoverageRate(): float { $coveredRate = 0; $coveredByTestsTotal = $this->totalMutantsCount - $this->notCoveredByTestsCount; if ($this->totalMutantsCount) { $coveredRate = floor(100 * $coveredByTestsTotal / $this->totalMutantsCount); } return $coveredRate; }
[ "public", "function", "getCoverageRate", "(", ")", ":", "float", "{", "$", "coveredRate", "=", "0", ";", "$", "coveredByTestsTotal", "=", "$", "this", "->", "totalMutantsCount", "-", "$", "this", "->", "notCoveredByTestsCount", ";", "if", "(", "$", "this", "->", "totalMutantsCount", ")", "{", "$", "coveredRate", "=", "floor", "(", "100", "*", "$", "coveredByTestsTotal", "/", "$", "this", "->", "totalMutantsCount", ")", ";", "}", "return", "$", "coveredRate", ";", "}" ]
Mutation coverage percentage
[ "Mutation", "coverage", "percentage" ]
f7708dbd35fd39498e25193a88e694549dc8f46c
https://github.com/infection/infection/blob/f7708dbd35fd39498e25193a88e694549dc8f46c/src/Mutant/MetricsCalculator.php#L170-L180
train
infection/infection
src/Visitor/MutationsCollectorVisitor.php
MutationsCollectorVisitor.getOuterMostArrayNode
private function getOuterMostArrayNode(Node $node): Node { $outerMostArrayParent = $node; do { if ($node instanceof Node\Expr\Array_) { $outerMostArrayParent = $node; } } while ($node = $node->getAttribute(ParentConnectorVisitor::PARENT_KEY)); return $outerMostArrayParent; }
php
private function getOuterMostArrayNode(Node $node): Node { $outerMostArrayParent = $node; do { if ($node instanceof Node\Expr\Array_) { $outerMostArrayParent = $node; } } while ($node = $node->getAttribute(ParentConnectorVisitor::PARENT_KEY)); return $outerMostArrayParent; }
[ "private", "function", "getOuterMostArrayNode", "(", "Node", "$", "node", ")", ":", "Node", "{", "$", "outerMostArrayParent", "=", "$", "node", ";", "do", "{", "if", "(", "$", "node", "instanceof", "Node", "\\", "Expr", "\\", "Array_", ")", "{", "$", "outerMostArrayParent", "=", "$", "node", ";", "}", "}", "while", "(", "$", "node", "=", "$", "node", "->", "getAttribute", "(", "ParentConnectorVisitor", "::", "PARENT_KEY", ")", ")", ";", "return", "$", "outerMostArrayParent", ";", "}" ]
If the node is part of an array, this will find the outermost array. Otherwise this will return the node itself
[ "If", "the", "node", "is", "part", "of", "an", "array", "this", "will", "find", "the", "outermost", "array", ".", "Otherwise", "this", "will", "return", "the", "node", "itself" ]
f7708dbd35fd39498e25193a88e694549dc8f46c
https://github.com/infection/infection/blob/f7708dbd35fd39498e25193a88e694549dc8f46c/src/Visitor/MutationsCollectorVisitor.php#L168-L179
train
infection/infection
src/Console/Util/PhpProcess.php
PhpProcess.start
public function start(callable $callback = null, array $env = null): void { $phpConfig = new PhpConfig(); $phpConfig->useOriginal(); parent::start($callback, $env ?? []); $phpConfig->usePersistent(); }
php
public function start(callable $callback = null, array $env = null): void { $phpConfig = new PhpConfig(); $phpConfig->useOriginal(); parent::start($callback, $env ?? []); $phpConfig->usePersistent(); }
[ "public", "function", "start", "(", "callable", "$", "callback", "=", "null", ",", "array", "$", "env", "=", "null", ")", ":", "void", "{", "$", "phpConfig", "=", "new", "PhpConfig", "(", ")", ";", "$", "phpConfig", "->", "useOriginal", "(", ")", ";", "parent", "::", "start", "(", "$", "callback", ",", "$", "env", "??", "[", "]", ")", ";", "$", "phpConfig", "->", "usePersistent", "(", ")", ";", "}" ]
Runs a PHP process with xdebug loaded If xdebug was loaded in the main process, it will have been restarted without xdebug and configured to keep xdebug out of PHP sub-processes. This method allows a sub-process to run with xdebug enabled (if it was originally loaded), then restores the xdebug-free environment. This means that we can use xdebug when it is required and not have to worry about it for the bulk of other processes, which do not need it and work better without it. {@inheritdoc}
[ "Runs", "a", "PHP", "process", "with", "xdebug", "loaded" ]
f7708dbd35fd39498e25193a88e694549dc8f46c
https://github.com/infection/infection/blob/f7708dbd35fd39498e25193a88e694549dc8f46c/src/Console/Util/PhpProcess.php#L61-L68
train
infection/infection
src/Visitor/ReflectionVisitor.php
ReflectionVisitor.isInsideFunction
private function isInsideFunction(Node $node): bool { if (!$node->hasAttribute(ParentConnectorVisitor::PARENT_KEY)) { return false; } $parent = $node->getAttribute(ParentConnectorVisitor::PARENT_KEY); if ($parent->getAttribute(self::IS_INSIDE_FUNCTION_KEY)) { return true; } if ($this->isFunctionLikeNode($parent)) { return true; } return $this->isInsideFunction($parent); }
php
private function isInsideFunction(Node $node): bool { if (!$node->hasAttribute(ParentConnectorVisitor::PARENT_KEY)) { return false; } $parent = $node->getAttribute(ParentConnectorVisitor::PARENT_KEY); if ($parent->getAttribute(self::IS_INSIDE_FUNCTION_KEY)) { return true; } if ($this->isFunctionLikeNode($parent)) { return true; } return $this->isInsideFunction($parent); }
[ "private", "function", "isInsideFunction", "(", "Node", "$", "node", ")", ":", "bool", "{", "if", "(", "!", "$", "node", "->", "hasAttribute", "(", "ParentConnectorVisitor", "::", "PARENT_KEY", ")", ")", "{", "return", "false", ";", "}", "$", "parent", "=", "$", "node", "->", "getAttribute", "(", "ParentConnectorVisitor", "::", "PARENT_KEY", ")", ";", "if", "(", "$", "parent", "->", "getAttribute", "(", "self", "::", "IS_INSIDE_FUNCTION_KEY", ")", ")", "{", "return", "true", ";", "}", "if", "(", "$", "this", "->", "isFunctionLikeNode", "(", "$", "parent", ")", ")", "{", "return", "true", ";", "}", "return", "$", "this", "->", "isInsideFunction", "(", "$", "parent", ")", ";", "}" ]
Recursively determine whether the node is inside the function
[ "Recursively", "determine", "whether", "the", "node", "is", "inside", "the", "function" ]
f7708dbd35fd39498e25193a88e694549dc8f46c
https://github.com/infection/infection/blob/f7708dbd35fd39498e25193a88e694549dc8f46c/src/Visitor/ReflectionVisitor.php#L147-L164
train
infection/infection
src/Command/InfectionCommand.php
InfectionCommand.initialize
protected function initialize(InputInterface $input, OutputInterface $output): void { parent::initialize($input, $output); $locator = $this->getContainer()->get('locator'); if ($customConfigPath = $input->getOption('configuration')) { $locator->locate($customConfigPath); } else { $this->runConfigurationCommand($locator); } $this->consoleOutput = $this->getApplication()->getConsoleOutput(); $this->skipCoverage = \strlen(trim($input->getOption('coverage'))) > 0; $this->eventDispatcher = $this->getContainer()->get('dispatcher'); }
php
protected function initialize(InputInterface $input, OutputInterface $output): void { parent::initialize($input, $output); $locator = $this->getContainer()->get('locator'); if ($customConfigPath = $input->getOption('configuration')) { $locator->locate($customConfigPath); } else { $this->runConfigurationCommand($locator); } $this->consoleOutput = $this->getApplication()->getConsoleOutput(); $this->skipCoverage = \strlen(trim($input->getOption('coverage'))) > 0; $this->eventDispatcher = $this->getContainer()->get('dispatcher'); }
[ "protected", "function", "initialize", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", ":", "void", "{", "parent", "::", "initialize", "(", "$", "input", ",", "$", "output", ")", ";", "$", "locator", "=", "$", "this", "->", "getContainer", "(", ")", "->", "get", "(", "'locator'", ")", ";", "if", "(", "$", "customConfigPath", "=", "$", "input", "->", "getOption", "(", "'configuration'", ")", ")", "{", "$", "locator", "->", "locate", "(", "$", "customConfigPath", ")", ";", "}", "else", "{", "$", "this", "->", "runConfigurationCommand", "(", "$", "locator", ")", ";", "}", "$", "this", "->", "consoleOutput", "=", "$", "this", "->", "getApplication", "(", ")", "->", "getConsoleOutput", "(", ")", ";", "$", "this", "->", "skipCoverage", "=", "\\", "strlen", "(", "trim", "(", "$", "input", "->", "getOption", "(", "'coverage'", ")", ")", ")", ">", "0", ";", "$", "this", "->", "eventDispatcher", "=", "$", "this", "->", "getContainer", "(", ")", "->", "get", "(", "'dispatcher'", ")", ";", "}" ]
Run configuration command if config does not exist @throws InfectionException
[ "Run", "configuration", "command", "if", "config", "does", "not", "exist" ]
f7708dbd35fd39498e25193a88e694549dc8f46c
https://github.com/infection/infection/blob/f7708dbd35fd39498e25193a88e694549dc8f46c/src/Command/InfectionCommand.php#L306-L321
train
infection/infection
src/Mutator/Arithmetic/Plus.php
Plus.mutate
public function mutate(Node $node) { return new Node\Expr\BinaryOp\Minus($node->left, $node->right, $node->getAttributes()); }
php
public function mutate(Node $node) { return new Node\Expr\BinaryOp\Minus($node->left, $node->right, $node->getAttributes()); }
[ "public", "function", "mutate", "(", "Node", "$", "node", ")", "{", "return", "new", "Node", "\\", "Expr", "\\", "BinaryOp", "\\", "Minus", "(", "$", "node", "->", "left", ",", "$", "node", "->", "right", ",", "$", "node", "->", "getAttributes", "(", ")", ")", ";", "}" ]
Replaces "+" with "-" @return Node\Expr\BinaryOp\Minus
[ "Replaces", "+", "with", "-" ]
f7708dbd35fd39498e25193a88e694549dc8f46c
https://github.com/infection/infection/blob/f7708dbd35fd39498e25193a88e694549dc8f46c/src/Mutator/Arithmetic/Plus.php#L52-L55
train
infection/infection
src/Mutator/Number/OneZeroInteger.php
OneZeroInteger.mutate
public function mutate(Node $node) { if ($node->value === 0) { return new Node\Scalar\LNumber(1); } return new Node\Scalar\LNumber(0); }
php
public function mutate(Node $node) { if ($node->value === 0) { return new Node\Scalar\LNumber(1); } return new Node\Scalar\LNumber(0); }
[ "public", "function", "mutate", "(", "Node", "$", "node", ")", "{", "if", "(", "$", "node", "->", "value", "===", "0", ")", "{", "return", "new", "Node", "\\", "Scalar", "\\", "LNumber", "(", "1", ")", ";", "}", "return", "new", "Node", "\\", "Scalar", "\\", "LNumber", "(", "0", ")", ";", "}" ]
Replaces "0" with "1" or "1" with "0" @return Node\Scalar\LNumber
[ "Replaces", "0", "with", "1", "or", "1", "with", "0" ]
f7708dbd35fd39498e25193a88e694549dc8f46c
https://github.com/infection/infection/blob/f7708dbd35fd39498e25193a88e694549dc8f46c/src/Mutator/Number/OneZeroInteger.php#L51-L58
train
infection/infection
src/Mutator/Number/OneZeroFloat.php
OneZeroFloat.mutate
public function mutate(Node $node) { if ($node->value === 0.0) { return new Node\Scalar\DNumber(1.0); } return new Node\Scalar\DNumber(0.0); }
php
public function mutate(Node $node) { if ($node->value === 0.0) { return new Node\Scalar\DNumber(1.0); } return new Node\Scalar\DNumber(0.0); }
[ "public", "function", "mutate", "(", "Node", "$", "node", ")", "{", "if", "(", "$", "node", "->", "value", "===", "0.0", ")", "{", "return", "new", "Node", "\\", "Scalar", "\\", "DNumber", "(", "1.0", ")", ";", "}", "return", "new", "Node", "\\", "Scalar", "\\", "DNumber", "(", "0.0", ")", ";", "}" ]
Replaces "0.0" with "1.0" or "1.0" with "0.0" @return Node\Scalar\DNumber
[ "Replaces", "0", ".", "0", "with", "1", ".", "0", "or", "1", ".", "0", "with", "0", ".", "0" ]
f7708dbd35fd39498e25193a88e694549dc8f46c
https://github.com/infection/infection/blob/f7708dbd35fd39498e25193a88e694549dc8f46c/src/Mutator/Number/OneZeroFloat.php#L51-L58
train
infection/infection
src/Mutator/Arithmetic/PlusEqual.php
PlusEqual.mutate
public function mutate(Node $node) { return new Node\Expr\AssignOp\Minus($node->var, $node->expr, $node->getAttributes()); }
php
public function mutate(Node $node) { return new Node\Expr\AssignOp\Minus($node->var, $node->expr, $node->getAttributes()); }
[ "public", "function", "mutate", "(", "Node", "$", "node", ")", "{", "return", "new", "Node", "\\", "Expr", "\\", "AssignOp", "\\", "Minus", "(", "$", "node", "->", "var", ",", "$", "node", "->", "expr", ",", "$", "node", "->", "getAttributes", "(", ")", ")", ";", "}" ]
Replaces "+=" with "-=" @return Node\Expr\AssignOp\Minus
[ "Replaces", "+", "=", "with", "-", "=" ]
f7708dbd35fd39498e25193a88e694549dc8f46c
https://github.com/infection/infection/blob/f7708dbd35fd39498e25193a88e694549dc8f46c/src/Mutator/Arithmetic/PlusEqual.php#L52-L55
train
infection/infection
src/Mutator/FunctionSignature/PublicVisibility.php
PublicVisibility.mutate
public function mutate(Node $node) { /* @var ClassMethod $node */ return new ClassMethod( $node->name, [ 'flags' => ($node->flags & ~Class_::MODIFIER_PUBLIC) | Class_::MODIFIER_PROTECTED, 'byRef' => $node->returnsByRef(), 'params' => $node->getParams(), 'returnType' => $node->getReturnType(), 'stmts' => $node->getStmts(), ], $node->getAttributes() ); }
php
public function mutate(Node $node) { /* @var ClassMethod $node */ return new ClassMethod( $node->name, [ 'flags' => ($node->flags & ~Class_::MODIFIER_PUBLIC) | Class_::MODIFIER_PROTECTED, 'byRef' => $node->returnsByRef(), 'params' => $node->getParams(), 'returnType' => $node->getReturnType(), 'stmts' => $node->getStmts(), ], $node->getAttributes() ); }
[ "public", "function", "mutate", "(", "Node", "$", "node", ")", "{", "/* @var ClassMethod $node */", "return", "new", "ClassMethod", "(", "$", "node", "->", "name", ",", "[", "'flags'", "=>", "(", "$", "node", "->", "flags", "&", "~", "Class_", "::", "MODIFIER_PUBLIC", ")", "|", "Class_", "::", "MODIFIER_PROTECTED", ",", "'byRef'", "=>", "$", "node", "->", "returnsByRef", "(", ")", ",", "'params'", "=>", "$", "node", "->", "getParams", "(", ")", ",", "'returnType'", "=>", "$", "node", "->", "getReturnType", "(", ")", ",", "'stmts'", "=>", "$", "node", "->", "getStmts", "(", ")", ",", "]", ",", "$", "node", "->", "getAttributes", "(", ")", ")", ";", "}" ]
Replaces "public function..." with "protected function ..." @return ClassMethod
[ "Replaces", "public", "function", "...", "with", "protected", "function", "..." ]
f7708dbd35fd39498e25193a88e694549dc8f46c
https://github.com/infection/infection/blob/f7708dbd35fd39498e25193a88e694549dc8f46c/src/Mutator/FunctionSignature/PublicVisibility.php#L55-L69
train
infection/infection
src/Mutator/ReturnValue/IntegerNegation.php
IntegerNegation.mutate
public function mutate(Node $node) { $integerValue = $node->expr instanceof Node\Expr\UnaryMinus ? -$node->expr->expr->value : $node->expr->value; return new Node\Stmt\Return_( new Node\Scalar\LNumber(-1 * $integerValue, $node->getAttributes()) ); }
php
public function mutate(Node $node) { $integerValue = $node->expr instanceof Node\Expr\UnaryMinus ? -$node->expr->expr->value : $node->expr->value; return new Node\Stmt\Return_( new Node\Scalar\LNumber(-1 * $integerValue, $node->getAttributes()) ); }
[ "public", "function", "mutate", "(", "Node", "$", "node", ")", "{", "$", "integerValue", "=", "$", "node", "->", "expr", "instanceof", "Node", "\\", "Expr", "\\", "UnaryMinus", "?", "-", "$", "node", "->", "expr", "->", "expr", "->", "value", ":", "$", "node", "->", "expr", "->", "value", ";", "return", "new", "Node", "\\", "Stmt", "\\", "Return_", "(", "new", "Node", "\\", "Scalar", "\\", "LNumber", "(", "-", "1", "*", "$", "integerValue", ",", "$", "node", "->", "getAttributes", "(", ")", ")", ")", ";", "}" ]
Replaces any integer with negated integer value. Replaces "-5" with "5" @return Node\Stmt\Return_
[ "Replaces", "any", "integer", "with", "negated", "integer", "value", ".", "Replaces", "-", "5", "with", "5" ]
f7708dbd35fd39498e25193a88e694549dc8f46c
https://github.com/infection/infection/blob/f7708dbd35fd39498e25193a88e694549dc8f46c/src/Mutator/ReturnValue/IntegerNegation.php#L53-L62
train
infection/infection
src/Mutator/ReturnValue/FloatNegation.php
FloatNegation.mutate
public function mutate(Node $node) { $floatValue = $node->expr instanceof Node\Expr\UnaryMinus ? -$node->expr->expr->value : $node->expr->value; return new Node\Stmt\Return_( new Node\Scalar\DNumber(-1 * $floatValue, $node->getAttributes()) ); }
php
public function mutate(Node $node) { $floatValue = $node->expr instanceof Node\Expr\UnaryMinus ? -$node->expr->expr->value : $node->expr->value; return new Node\Stmt\Return_( new Node\Scalar\DNumber(-1 * $floatValue, $node->getAttributes()) ); }
[ "public", "function", "mutate", "(", "Node", "$", "node", ")", "{", "$", "floatValue", "=", "$", "node", "->", "expr", "instanceof", "Node", "\\", "Expr", "\\", "UnaryMinus", "?", "-", "$", "node", "->", "expr", "->", "expr", "->", "value", ":", "$", "node", "->", "expr", "->", "value", ";", "return", "new", "Node", "\\", "Stmt", "\\", "Return_", "(", "new", "Node", "\\", "Scalar", "\\", "DNumber", "(", "-", "1", "*", "$", "floatValue", ",", "$", "node", "->", "getAttributes", "(", ")", ")", ")", ";", "}" ]
Replaces any float with negated float Replaces "-33.4" with "33.4" @return Node\Stmt\Return_
[ "Replaces", "any", "float", "with", "negated", "float", "Replaces", "-", "33", ".", "4", "with", "33", ".", "4" ]
f7708dbd35fd39498e25193a88e694549dc8f46c
https://github.com/infection/infection/blob/f7708dbd35fd39498e25193a88e694549dc8f46c/src/Mutator/ReturnValue/FloatNegation.php#L53-L62
train
infection/infection
src/Mutator/Arithmetic/AssignmentEqual.php
AssignmentEqual.mutate
public function mutate(Node $node) { return new Node\Expr\Assign($node->left, $node->right, $node->getAttributes()); }
php
public function mutate(Node $node) { return new Node\Expr\Assign($node->left, $node->right, $node->getAttributes()); }
[ "public", "function", "mutate", "(", "Node", "$", "node", ")", "{", "return", "new", "Node", "\\", "Expr", "\\", "Assign", "(", "$", "node", "->", "left", ",", "$", "node", "->", "right", ",", "$", "node", "->", "getAttributes", "(", ")", ")", ";", "}" ]
Replaces "==" with "=" @return Node\Expr\Assign
[ "Replaces", "==", "with", "=" ]
f7708dbd35fd39498e25193a88e694549dc8f46c
https://github.com/infection/infection/blob/f7708dbd35fd39498e25193a88e694549dc8f46c/src/Mutator/Arithmetic/AssignmentEqual.php#L52-L55
train
themosis/framework
src/Hook/Hook.php
Hook.add
public function add($hooks, $callback, $priority = 10, $accepted_args = 3) { foreach ((array) $hooks as $hook) { $this->addHookEvent($hook, $callback, $priority, $accepted_args); } return $this; }
php
public function add($hooks, $callback, $priority = 10, $accepted_args = 3) { foreach ((array) $hooks as $hook) { $this->addHookEvent($hook, $callback, $priority, $accepted_args); } return $this; }
[ "public", "function", "add", "(", "$", "hooks", ",", "$", "callback", ",", "$", "priority", "=", "10", ",", "$", "accepted_args", "=", "3", ")", "{", "foreach", "(", "(", "array", ")", "$", "hooks", "as", "$", "hook", ")", "{", "$", "this", "->", "addHookEvent", "(", "$", "hook", ",", "$", "callback", ",", "$", "priority", ",", "$", "accepted_args", ")", ";", "}", "return", "$", "this", ";", "}" ]
Wrapper of the "add_action" or "add_filter" functions. Allows a developer to specify a controller class or closure. @param string|array $hooks The action hook name. @param \Closure|string|array $callback The action hook callback instance. @param int $priority The priority order for this action. @param int $accepted_args Default number of accepted arguments. @throws BadMethodCallException @return $this
[ "Wrapper", "of", "the", "add_action", "or", "add_filter", "functions", ".", "Allows", "a", "developer", "to", "specify", "a", "controller", "class", "or", "closure", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Hook/Hook.php#L45-L52
train
themosis/framework
src/Hook/Hook.php
Hook.remove
public function remove($hook, $callback = null, $priority = 10) { // If $callback is null, it means we have chained the methods to // the action/filter instance. If the instance has no callback, return false. if (is_null($callback)) { if (! $callback = $this->getCallback($hook)) { return false; } list($callback, $priority, $accepted_args) = $callback; // Unset the hook. unset($this->hooks[$hook]); } $this->removeAction($hook, $callback, $priority); return $this; }
php
public function remove($hook, $callback = null, $priority = 10) { // If $callback is null, it means we have chained the methods to // the action/filter instance. If the instance has no callback, return false. if (is_null($callback)) { if (! $callback = $this->getCallback($hook)) { return false; } list($callback, $priority, $accepted_args) = $callback; // Unset the hook. unset($this->hooks[$hook]); } $this->removeAction($hook, $callback, $priority); return $this; }
[ "public", "function", "remove", "(", "$", "hook", ",", "$", "callback", "=", "null", ",", "$", "priority", "=", "10", ")", "{", "// If $callback is null, it means we have chained the methods to", "// the action/filter instance. If the instance has no callback, return false.", "if", "(", "is_null", "(", "$", "callback", ")", ")", "{", "if", "(", "!", "$", "callback", "=", "$", "this", "->", "getCallback", "(", "$", "hook", ")", ")", "{", "return", "false", ";", "}", "list", "(", "$", "callback", ",", "$", "priority", ",", "$", "accepted_args", ")", "=", "$", "callback", ";", "// Unset the hook.", "unset", "(", "$", "this", "->", "hooks", "[", "$", "hook", "]", ")", ";", "}", "$", "this", "->", "removeAction", "(", "$", "hook", ",", "$", "callback", ",", "$", "priority", ")", ";", "return", "$", "this", ";", "}" ]
Remove a registered action or filter. @param string $hook @param \Closure|string $callback @param int $priority @return mixed The Hook instance or false.
[ "Remove", "a", "registered", "action", "or", "filter", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Hook/Hook.php#L75-L93
train
themosis/framework
src/Hook/Hook.php
Hook.getCallback
public function getCallback($hook) { if (array_key_exists($hook, $this->hooks)) { return $this->hooks[$hook]; } return null; }
php
public function getCallback($hook) { if (array_key_exists($hook, $this->hooks)) { return $this->hooks[$hook]; } return null; }
[ "public", "function", "getCallback", "(", "$", "hook", ")", "{", "if", "(", "array_key_exists", "(", "$", "hook", ",", "$", "this", "->", "hooks", ")", ")", "{", "return", "$", "this", "->", "hooks", "[", "$", "hook", "]", ";", "}", "return", "null", ";", "}" ]
Return the callback registered with the hook. @param string $hook The hook name. @return array|null
[ "Return", "the", "callback", "registered", "with", "the", "hook", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Hook/Hook.php#L102-L109
train
themosis/framework
src/Hook/Hook.php
Hook.addHookEvent
protected function addHookEvent($hook, $callback, $priority, $accepted_args) { // Check if $callback is a closure. if ($callback instanceof \Closure || is_array($callback)) { $this->addEventListener($hook, $callback, $priority, $accepted_args); } elseif (is_string($callback)) { if (false !== strpos($callback, '@') || class_exists($callback)) { // Return the class responsible to handle the action. $callback = $this->addClassEvent($hook, $callback, $priority, $accepted_args); } else { // Used as a classic callback function. $this->addEventListener($hook, $callback, $priority, $accepted_args); } } return $callback; }
php
protected function addHookEvent($hook, $callback, $priority, $accepted_args) { // Check if $callback is a closure. if ($callback instanceof \Closure || is_array($callback)) { $this->addEventListener($hook, $callback, $priority, $accepted_args); } elseif (is_string($callback)) { if (false !== strpos($callback, '@') || class_exists($callback)) { // Return the class responsible to handle the action. $callback = $this->addClassEvent($hook, $callback, $priority, $accepted_args); } else { // Used as a classic callback function. $this->addEventListener($hook, $callback, $priority, $accepted_args); } } return $callback; }
[ "protected", "function", "addHookEvent", "(", "$", "hook", ",", "$", "callback", ",", "$", "priority", ",", "$", "accepted_args", ")", "{", "// Check if $callback is a closure.", "if", "(", "$", "callback", "instanceof", "\\", "Closure", "||", "is_array", "(", "$", "callback", ")", ")", "{", "$", "this", "->", "addEventListener", "(", "$", "hook", ",", "$", "callback", ",", "$", "priority", ",", "$", "accepted_args", ")", ";", "}", "elseif", "(", "is_string", "(", "$", "callback", ")", ")", "{", "if", "(", "false", "!==", "strpos", "(", "$", "callback", ",", "'@'", ")", "||", "class_exists", "(", "$", "callback", ")", ")", "{", "// Return the class responsible to handle the action.", "$", "callback", "=", "$", "this", "->", "addClassEvent", "(", "$", "hook", ",", "$", "callback", ",", "$", "priority", ",", "$", "accepted_args", ")", ";", "}", "else", "{", "// Used as a classic callback function.", "$", "this", "->", "addEventListener", "(", "$", "hook", ",", "$", "callback", ",", "$", "priority", ",", "$", "accepted_args", ")", ";", "}", "}", "return", "$", "callback", ";", "}" ]
Add an event for the specified hook. @param string $hook The hook name. @param \Closure|string|array $callback The hook callback instance. @param int $priority The priority order. @param int $accepted_args The default number of accepted arguments. @throws BadMethodCallException @return \Closure|array|string
[ "Add", "an", "event", "for", "the", "specified", "hook", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Hook/Hook.php#L135-L151
train
themosis/framework
src/Hook/Hook.php
Hook.addClassEvent
protected function addClassEvent($hook, $class, $priority, $accepted_args) { $callback = $this->buildClassEventCallback($class, $hook); $this->addEventListener($hook, $callback, $priority, $accepted_args); return $callback; }
php
protected function addClassEvent($hook, $class, $priority, $accepted_args) { $callback = $this->buildClassEventCallback($class, $hook); $this->addEventListener($hook, $callback, $priority, $accepted_args); return $callback; }
[ "protected", "function", "addClassEvent", "(", "$", "hook", ",", "$", "class", ",", "$", "priority", ",", "$", "accepted_args", ")", "{", "$", "callback", "=", "$", "this", "->", "buildClassEventCallback", "(", "$", "class", ",", "$", "hook", ")", ";", "$", "this", "->", "addEventListener", "(", "$", "hook", ",", "$", "callback", ",", "$", "priority", ",", "$", "accepted_args", ")", ";", "return", "$", "callback", ";", "}" ]
Prepare the hook callback for use in a class method. @param string $hook @param string $class @param int $priority @param int $accepted_args @throws BadMethodCallException @return array
[ "Prepare", "the", "hook", "callback", "for", "use", "in", "a", "class", "method", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Hook/Hook.php#L165-L172
train
themosis/framework
src/Hook/Hook.php
Hook.buildClassEventCallback
protected function buildClassEventCallback($class, $hook) { list($class, $method) = $this->parseClassEvent($class, $hook); $instance = $this->container->make($class); return [$instance, $method]; }
php
protected function buildClassEventCallback($class, $hook) { list($class, $method) = $this->parseClassEvent($class, $hook); $instance = $this->container->make($class); return [$instance, $method]; }
[ "protected", "function", "buildClassEventCallback", "(", "$", "class", ",", "$", "hook", ")", "{", "list", "(", "$", "class", ",", "$", "method", ")", "=", "$", "this", "->", "parseClassEvent", "(", "$", "class", ",", "$", "hook", ")", ";", "$", "instance", "=", "$", "this", "->", "container", "->", "make", "(", "$", "class", ")", ";", "return", "[", "$", "instance", ",", "$", "method", "]", ";", "}" ]
Build the array in order to call a class method. @param string $class @param string $hook @return array
[ "Build", "the", "array", "in", "order", "to", "call", "a", "class", "method", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Hook/Hook.php#L182-L189
train
themosis/framework
src/Hook/Hook.php
Hook.parseClassEvent
protected function parseClassEvent($class, $hook) { if (str_contains($class, '@')) { return explode('@', $class); } // If no method is defined, use the hook name as the method name. $method = str_contains($hook, '-') ? str_replace('-', '_', $hook) : $hook; return [$class, $method]; }
php
protected function parseClassEvent($class, $hook) { if (str_contains($class, '@')) { return explode('@', $class); } // If no method is defined, use the hook name as the method name. $method = str_contains($hook, '-') ? str_replace('-', '_', $hook) : $hook; return [$class, $method]; }
[ "protected", "function", "parseClassEvent", "(", "$", "class", ",", "$", "hook", ")", "{", "if", "(", "str_contains", "(", "$", "class", ",", "'@'", ")", ")", "{", "return", "explode", "(", "'@'", ",", "$", "class", ")", ";", "}", "// If no method is defined, use the hook name as the method name.", "$", "method", "=", "str_contains", "(", "$", "hook", ",", "'-'", ")", "?", "str_replace", "(", "'-'", ",", "'_'", ",", "$", "hook", ")", ":", "$", "hook", ";", "return", "[", "$", "class", ",", "$", "method", "]", ";", "}" ]
Parse a class name and returns its name and its method. @param string $class @param string $hook @return array
[ "Parse", "a", "class", "name", "and", "returns", "its", "name", "and", "its", "method", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Hook/Hook.php#L199-L209
train
themosis/framework
src/User/Factory.php
Factory.make
public function make(string $username, string $password, string $email): User { $this->validate(compact('username', 'password', 'email')); $user = wp_create_user($username, $password, $email); if (is_a($user, 'WP_Error')) { if ('existing_user_login' === $user->get_error_code()) { throw new DuplicateUserException($user->get_error_message()); } throw new UserException($user->get_error_message()); } return $this->get($user); }
php
public function make(string $username, string $password, string $email): User { $this->validate(compact('username', 'password', 'email')); $user = wp_create_user($username, $password, $email); if (is_a($user, 'WP_Error')) { if ('existing_user_login' === $user->get_error_code()) { throw new DuplicateUserException($user->get_error_message()); } throw new UserException($user->get_error_message()); } return $this->get($user); }
[ "public", "function", "make", "(", "string", "$", "username", ",", "string", "$", "password", ",", "string", "$", "email", ")", ":", "User", "{", "$", "this", "->", "validate", "(", "compact", "(", "'username'", ",", "'password'", ",", "'email'", ")", ")", ";", "$", "user", "=", "wp_create_user", "(", "$", "username", ",", "$", "password", ",", "$", "email", ")", ";", "if", "(", "is_a", "(", "$", "user", ",", "'WP_Error'", ")", ")", "{", "if", "(", "'existing_user_login'", "===", "$", "user", "->", "get_error_code", "(", ")", ")", "{", "throw", "new", "DuplicateUserException", "(", "$", "user", "->", "get_error_message", "(", ")", ")", ";", "}", "throw", "new", "UserException", "(", "$", "user", "->", "get_error_message", "(", ")", ")", ";", "}", "return", "$", "this", "->", "get", "(", "$", "user", ")", ";", "}" ]
Create a WordPress user and save it to the database. @param string $username @param string $password @param string $email @throws UserException @throws DuplicateUserException @return User
[ "Create", "a", "WordPress", "user", "and", "save", "it", "to", "the", "database", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/User/Factory.php#L34-L49
train
themosis/framework
src/User/Factory.php
Factory.validate
protected function validate(array $data) { $validator = $this->validator->make( $data, [ 'username' => 'min:6|max:60', 'password' => 'min:6|max:255', 'email' => 'email|max:100' ] ); if ($validator->fails()) { $message = sprintf( 'Invalid user credentials. %s', implode(' ', $validator->errors()->all()) ); throw new UserException($message); } }
php
protected function validate(array $data) { $validator = $this->validator->make( $data, [ 'username' => 'min:6|max:60', 'password' => 'min:6|max:255', 'email' => 'email|max:100' ] ); if ($validator->fails()) { $message = sprintf( 'Invalid user credentials. %s', implode(' ', $validator->errors()->all()) ); throw new UserException($message); } }
[ "protected", "function", "validate", "(", "array", "$", "data", ")", "{", "$", "validator", "=", "$", "this", "->", "validator", "->", "make", "(", "$", "data", ",", "[", "'username'", "=>", "'min:6|max:60'", ",", "'password'", "=>", "'min:6|max:255'", ",", "'email'", "=>", "'email|max:100'", "]", ")", ";", "if", "(", "$", "validator", "->", "fails", "(", ")", ")", "{", "$", "message", "=", "sprintf", "(", "'Invalid user credentials. %s'", ",", "implode", "(", "' '", ",", "$", "validator", "->", "errors", "(", ")", "->", "all", "(", ")", ")", ")", ";", "throw", "new", "UserException", "(", "$", "message", ")", ";", "}", "}" ]
Validate user credentials. @param array $data @throws UserException
[ "Validate", "user", "credentials", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/User/Factory.php#L82-L100
train
themosis/framework
src/Forms/Resources/Transformers/ChoiceFieldTransformer.php
ChoiceFieldTransformer.getOptions
protected function getOptions(FieldTypeInterface $field) { $options = parent::getOptions($field); $options['choices'] = $this->parseChoices($options['choices']); return $options; }
php
protected function getOptions(FieldTypeInterface $field) { $options = parent::getOptions($field); $options['choices'] = $this->parseChoices($options['choices']); return $options; }
[ "protected", "function", "getOptions", "(", "FieldTypeInterface", "$", "field", ")", "{", "$", "options", "=", "parent", "::", "getOptions", "(", "$", "field", ")", ";", "$", "options", "[", "'choices'", "]", "=", "$", "this", "->", "parseChoices", "(", "$", "options", "[", "'choices'", "]", ")", ";", "return", "$", "options", ";", "}" ]
Return choice field options. @param FieldTypeInterface $field @return array
[ "Return", "choice", "field", "options", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Resources/Transformers/ChoiceFieldTransformer.php#L16-L23
train
themosis/framework
src/Forms/Resources/Transformers/ChoiceFieldTransformer.php
ChoiceFieldTransformer.parseChoices
protected function parseChoices(array $choices) { $items = []; foreach ($choices as $key => $value) { if (is_array($value)) { // Handle options groups data. $items[] = ['key' => $key, 'value' => '', 'type' => 'group']; $items = array_merge($items, $this->parseChoices($value)); } else { $items[] = ['key' => $key, 'value' => $value, 'type' => 'option']; } } return $items; }
php
protected function parseChoices(array $choices) { $items = []; foreach ($choices as $key => $value) { if (is_array($value)) { // Handle options groups data. $items[] = ['key' => $key, 'value' => '', 'type' => 'group']; $items = array_merge($items, $this->parseChoices($value)); } else { $items[] = ['key' => $key, 'value' => $value, 'type' => 'option']; } } return $items; }
[ "protected", "function", "parseChoices", "(", "array", "$", "choices", ")", "{", "$", "items", "=", "[", "]", ";", "foreach", "(", "$", "choices", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "// Handle options groups data.", "$", "items", "[", "]", "=", "[", "'key'", "=>", "$", "key", ",", "'value'", "=>", "''", ",", "'type'", "=>", "'group'", "]", ";", "$", "items", "=", "array_merge", "(", "$", "items", ",", "$", "this", "->", "parseChoices", "(", "$", "value", ")", ")", ";", "}", "else", "{", "$", "items", "[", "]", "=", "[", "'key'", "=>", "$", "key", ",", "'value'", "=>", "$", "value", ",", "'type'", "=>", "'option'", "]", ";", "}", "}", "return", "$", "items", ";", "}" ]
Parse field choices. @param array $choices @return array
[ "Parse", "field", "choices", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Resources/Transformers/ChoiceFieldTransformer.php#L32-L47
train
themosis/framework
src/Forms/Fields/ChoiceList/ChoiceList.php
ChoiceList.format
public function format(): ChoiceListInterface { if (empty($this->choices)) { return $this; } $this->results = $this->parse($this->choices); return $this; }
php
public function format(): ChoiceListInterface { if (empty($this->choices)) { return $this; } $this->results = $this->parse($this->choices); return $this; }
[ "public", "function", "format", "(", ")", ":", "ChoiceListInterface", "{", "if", "(", "empty", "(", "$", "this", "->", "choices", ")", ")", "{", "return", "$", "this", ";", "}", "$", "this", "->", "results", "=", "$", "this", "->", "parse", "(", "$", "this", "->", "choices", ")", ";", "return", "$", "this", ";", "}" ]
Format the choices for use on output. @return ChoiceListInterface
[ "Format", "the", "choices", "for", "use", "on", "output", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Fields/ChoiceList/ChoiceList.php#L31-L40
train
themosis/framework
src/Forms/Fields/ChoiceList/ChoiceList.php
ChoiceList.parse
protected function parse(array $choices) { $items = []; foreach ($choices as $key => $value) { if (is_array($value)) { $items[$key] = $this->parse($value); } else { if (is_int($key)) { $label = ucfirst(str_replace(['-', '_'], ' ', $value)); } else { $label = $key; } $items[$label] = $value; } } return $items; }
php
protected function parse(array $choices) { $items = []; foreach ($choices as $key => $value) { if (is_array($value)) { $items[$key] = $this->parse($value); } else { if (is_int($key)) { $label = ucfirst(str_replace(['-', '_'], ' ', $value)); } else { $label = $key; } $items[$label] = $value; } } return $items; }
[ "protected", "function", "parse", "(", "array", "$", "choices", ")", "{", "$", "items", "=", "[", "]", ";", "foreach", "(", "$", "choices", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "items", "[", "$", "key", "]", "=", "$", "this", "->", "parse", "(", "$", "value", ")", ";", "}", "else", "{", "if", "(", "is_int", "(", "$", "key", ")", ")", "{", "$", "label", "=", "ucfirst", "(", "str_replace", "(", "[", "'-'", ",", "'_'", "]", ",", "' '", ",", "$", "value", ")", ")", ";", "}", "else", "{", "$", "label", "=", "$", "key", ";", "}", "$", "items", "[", "$", "label", "]", "=", "$", "value", ";", "}", "}", "return", "$", "items", ";", "}" ]
Parse the choices and format them. @param array $choices @return array
[ "Parse", "the", "choices", "and", "format", "them", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Fields/ChoiceList/ChoiceList.php#L49-L68
train
themosis/framework
src/Core/Application.php
Application.registerBaseServiceProviders
protected function registerBaseServiceProviders() { $this->register(new EventServiceProvider($this)); $this->register(new LogServiceProvider($this)); $this->register(new RouteServiceProvider($this)); }
php
protected function registerBaseServiceProviders() { $this->register(new EventServiceProvider($this)); $this->register(new LogServiceProvider($this)); $this->register(new RouteServiceProvider($this)); }
[ "protected", "function", "registerBaseServiceProviders", "(", ")", "{", "$", "this", "->", "register", "(", "new", "EventServiceProvider", "(", "$", "this", ")", ")", ";", "$", "this", "->", "register", "(", "new", "LogServiceProvider", "(", "$", "this", ")", ")", ";", "$", "this", "->", "register", "(", "new", "RouteServiceProvider", "(", "$", "this", ")", ")", ";", "}" ]
Register base service providers.
[ "Register", "base", "service", "providers", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Application.php#L165-L170
train
themosis/framework
src/Core/Application.php
Application.rootPath
public function rootPath($path = '') { if (defined('THEMOSIS_ROOT')) { return THEMOSIS_ROOT.($path ? DIRECTORY_SEPARATOR.$path : $path); } return $this->webPath($path); }
php
public function rootPath($path = '') { if (defined('THEMOSIS_ROOT')) { return THEMOSIS_ROOT.($path ? DIRECTORY_SEPARATOR.$path : $path); } return $this->webPath($path); }
[ "public", "function", "rootPath", "(", "$", "path", "=", "''", ")", "{", "if", "(", "defined", "(", "'THEMOSIS_ROOT'", ")", ")", "{", "return", "THEMOSIS_ROOT", ".", "(", "$", "path", "?", "DIRECTORY_SEPARATOR", ".", "$", "path", ":", "$", "path", ")", ";", "}", "return", "$", "this", "->", "webPath", "(", "$", "path", ")", ";", "}" ]
Get the root path of the project. @param string $path @return string
[ "Get", "the", "root", "path", "of", "the", "project", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Application.php#L520-L527
train
themosis/framework
src/Core/Application.php
Application.storagePath
public function storagePath($path = '') { if (defined('THEMOSIS_ROOT')) { return $this->rootPath('storage').($path ? DIRECTORY_SEPARATOR.$path : $path); } return $this->contentPath('storage').($path ? DIRECTORY_SEPARATOR.$path : $path); }
php
public function storagePath($path = '') { if (defined('THEMOSIS_ROOT')) { return $this->rootPath('storage').($path ? DIRECTORY_SEPARATOR.$path : $path); } return $this->contentPath('storage').($path ? DIRECTORY_SEPARATOR.$path : $path); }
[ "public", "function", "storagePath", "(", "$", "path", "=", "''", ")", "{", "if", "(", "defined", "(", "'THEMOSIS_ROOT'", ")", ")", "{", "return", "$", "this", "->", "rootPath", "(", "'storage'", ")", ".", "(", "$", "path", "?", "DIRECTORY_SEPARATOR", ".", "$", "path", ":", "$", "path", ")", ";", "}", "return", "$", "this", "->", "contentPath", "(", "'storage'", ")", ".", "(", "$", "path", "?", "DIRECTORY_SEPARATOR", ".", "$", "path", ":", "$", "path", ")", ";", "}" ]
Get the storage directory path. @param string $path @return string
[ "Get", "the", "storage", "directory", "path", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Application.php#L548-L555
train
themosis/framework
src/Core/Application.php
Application.detectEnvironment
public function detectEnvironment(Closure $callback) { $args = $_SERVER['argv'] ?? null; return $this['env'] = (new EnvironmentDetector())->detect($callback, $args); }
php
public function detectEnvironment(Closure $callback) { $args = $_SERVER['argv'] ?? null; return $this['env'] = (new EnvironmentDetector())->detect($callback, $args); }
[ "public", "function", "detectEnvironment", "(", "Closure", "$", "callback", ")", "{", "$", "args", "=", "$", "_SERVER", "[", "'argv'", "]", "??", "null", ";", "return", "$", "this", "[", "'env'", "]", "=", "(", "new", "EnvironmentDetector", "(", ")", ")", "->", "detect", "(", "$", "callback", ",", "$", "args", ")", ";", "}" ]
Detech application's current environment. @param Closure $callback @return string
[ "Detech", "application", "s", "current", "environment", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Application.php#L678-L683
train
themosis/framework
src/Core/Application.php
Application.isDownForMaintenance
public function isDownForMaintenance() { $filePath = $this->wordpressPath('.maintenance'); if (function_exists('wp_installing') && ! file_exists($filePath)) { return \wp_installing(); } return file_exists($filePath); }
php
public function isDownForMaintenance() { $filePath = $this->wordpressPath('.maintenance'); if (function_exists('wp_installing') && ! file_exists($filePath)) { return \wp_installing(); } return file_exists($filePath); }
[ "public", "function", "isDownForMaintenance", "(", ")", "{", "$", "filePath", "=", "$", "this", "->", "wordpressPath", "(", "'.maintenance'", ")", ";", "if", "(", "function_exists", "(", "'wp_installing'", ")", "&&", "!", "file_exists", "(", "$", "filePath", ")", ")", "{", "return", "\\", "wp_installing", "(", ")", ";", "}", "return", "file_exists", "(", "$", "filePath", ")", ";", "}" ]
Determine if the application is currently down for maintenance. @throws \Illuminate\Container\EntryNotFoundException @return bool
[ "Determine", "if", "the", "application", "is", "currently", "down", "for", "maintenance", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Application.php#L702-L711
train
themosis/framework
src/Core/Application.php
Application.loadPlugin
public function loadPlugin(string $filePath, string $configPath) { $plugin = (new PluginManager($this, $filePath, new ClassLoader()))->load($configPath); $this->instance('wp.plugin.'.$plugin->getHeader('plugin_id'), $plugin); return $plugin; }
php
public function loadPlugin(string $filePath, string $configPath) { $plugin = (new PluginManager($this, $filePath, new ClassLoader()))->load($configPath); $this->instance('wp.plugin.'.$plugin->getHeader('plugin_id'), $plugin); return $plugin; }
[ "public", "function", "loadPlugin", "(", "string", "$", "filePath", ",", "string", "$", "configPath", ")", "{", "$", "plugin", "=", "(", "new", "PluginManager", "(", "$", "this", ",", "$", "filePath", ",", "new", "ClassLoader", "(", ")", ")", ")", "->", "load", "(", "$", "configPath", ")", ";", "$", "this", "->", "instance", "(", "'wp.plugin.'", ".", "$", "plugin", "->", "getHeader", "(", "'plugin_id'", ")", ",", "$", "plugin", ")", ";", "return", "$", "plugin", ";", "}" ]
Bootstrap a Themosis like plugin. @param string $filePath @param string $configPath @return PluginManager
[ "Bootstrap", "a", "Themosis", "like", "plugin", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Application.php#L1172-L1179
train
themosis/framework
src/Core/Application.php
Application.loadPlugins
public function loadPlugins(string $pluginsPath) { $directories = Collection::make((new Filesystem())->directories($this->mupluginsPath())) ->map(function ($directory) { return ltrim(substr($directory, strrpos($directory, DS)), '\/'); })->toArray(); (new PluginsRepository($this, new Filesystem(), $pluginsPath, $this->getCachedPluginsPath())) ->load($directories); }
php
public function loadPlugins(string $pluginsPath) { $directories = Collection::make((new Filesystem())->directories($this->mupluginsPath())) ->map(function ($directory) { return ltrim(substr($directory, strrpos($directory, DS)), '\/'); })->toArray(); (new PluginsRepository($this, new Filesystem(), $pluginsPath, $this->getCachedPluginsPath())) ->load($directories); }
[ "public", "function", "loadPlugins", "(", "string", "$", "pluginsPath", ")", "{", "$", "directories", "=", "Collection", "::", "make", "(", "(", "new", "Filesystem", "(", ")", ")", "->", "directories", "(", "$", "this", "->", "mupluginsPath", "(", ")", ")", ")", "->", "map", "(", "function", "(", "$", "directory", ")", "{", "return", "ltrim", "(", "substr", "(", "$", "directory", ",", "strrpos", "(", "$", "directory", ",", "DS", ")", ")", ",", "'\\/'", ")", ";", "}", ")", "->", "toArray", "(", ")", ";", "(", "new", "PluginsRepository", "(", "$", "this", ",", "new", "Filesystem", "(", ")", ",", "$", "pluginsPath", ",", "$", "this", "->", "getCachedPluginsPath", "(", ")", ")", ")", "->", "load", "(", "$", "directories", ")", ";", "}" ]
Register the framework core "plugin" and auto-load any found mu-plugins after the framework. @param string $pluginsPath @throws \Illuminate\Contracts\Filesystem\FileNotFoundException @throws \Exception
[ "Register", "the", "framework", "core", "plugin", "and", "auto", "-", "load", "any", "found", "mu", "-", "plugins", "after", "the", "framework", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Application.php#L1190-L1199
train
themosis/framework
src/Core/Application.php
Application.registerConfiguredHooks
public function registerConfiguredHooks(string $config = '') { if (empty($config)) { $config = 'app.hooks'; } $hooks = Collection::make($this->config[$config]); (new HooksRepository($this))->load($hooks->all()); }
php
public function registerConfiguredHooks(string $config = '') { if (empty($config)) { $config = 'app.hooks'; } $hooks = Collection::make($this->config[$config]); (new HooksRepository($this))->load($hooks->all()); }
[ "public", "function", "registerConfiguredHooks", "(", "string", "$", "config", "=", "''", ")", "{", "if", "(", "empty", "(", "$", "config", ")", ")", "{", "$", "config", "=", "'app.hooks'", ";", "}", "$", "hooks", "=", "Collection", "::", "make", "(", "$", "this", "->", "config", "[", "$", "config", "]", ")", ";", "(", "new", "HooksRepository", "(", "$", "this", ")", ")", "->", "load", "(", "$", "hooks", "->", "all", "(", ")", ")", ";", "}" ]
Register a list of hookable instances. @param string $config
[ "Register", "a", "list", "of", "hookable", "instances", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Application.php#L1226-L1235
train
themosis/framework
src/Core/Application.php
Application.registerHook
public function registerHook(string $hook) { // Build a "Hookable" instance. // Hookable instances must extend the "Hookable" class. $instance = new $hook($this); $hooks = (array) $instance->hook; if (! method_exists($instance, 'register')) { return; } if (! empty($hooks)) { $this['action']->add($hooks, [$instance, 'register'], $instance->priority); } else { $instance->register(); } }
php
public function registerHook(string $hook) { // Build a "Hookable" instance. // Hookable instances must extend the "Hookable" class. $instance = new $hook($this); $hooks = (array) $instance->hook; if (! method_exists($instance, 'register')) { return; } if (! empty($hooks)) { $this['action']->add($hooks, [$instance, 'register'], $instance->priority); } else { $instance->register(); } }
[ "public", "function", "registerHook", "(", "string", "$", "hook", ")", "{", "// Build a \"Hookable\" instance.", "// Hookable instances must extend the \"Hookable\" class.", "$", "instance", "=", "new", "$", "hook", "(", "$", "this", ")", ";", "$", "hooks", "=", "(", "array", ")", "$", "instance", "->", "hook", ";", "if", "(", "!", "method_exists", "(", "$", "instance", ",", "'register'", ")", ")", "{", "return", ";", "}", "if", "(", "!", "empty", "(", "$", "hooks", ")", ")", "{", "$", "this", "[", "'action'", "]", "->", "add", "(", "$", "hooks", ",", "[", "$", "instance", ",", "'register'", "]", ",", "$", "instance", "->", "priority", ")", ";", "}", "else", "{", "$", "instance", "->", "register", "(", ")", ";", "}", "}" ]
Create and register a hook instance. @param string $hook
[ "Create", "and", "register", "a", "hook", "instance", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Application.php#L1242-L1258
train
themosis/framework
src/Core/Application.php
Application.loadTheme
public function loadTheme(string $dirPath, string $configPath) { $theme = (new ThemeManager($this, $dirPath, new ClassLoader())) ->load($dirPath.'/'.trim($configPath, '\/')); $this->instance('wp.theme', $theme); return $theme; }
php
public function loadTheme(string $dirPath, string $configPath) { $theme = (new ThemeManager($this, $dirPath, new ClassLoader())) ->load($dirPath.'/'.trim($configPath, '\/')); $this->instance('wp.theme', $theme); return $theme; }
[ "public", "function", "loadTheme", "(", "string", "$", "dirPath", ",", "string", "$", "configPath", ")", "{", "$", "theme", "=", "(", "new", "ThemeManager", "(", "$", "this", ",", "$", "dirPath", ",", "new", "ClassLoader", "(", ")", ")", ")", "->", "load", "(", "$", "dirPath", ".", "'/'", ".", "trim", "(", "$", "configPath", ",", "'\\/'", ")", ")", ";", "$", "this", "->", "instance", "(", "'wp.theme'", ",", "$", "theme", ")", ";", "return", "$", "theme", ";", "}" ]
Load current active theme. @param string $dirPath The theme directory path. @param string $configPath The theme relative configuration folder path. @return ThemeManager
[ "Load", "current", "active", "theme", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Application.php#L1268-L1276
train
themosis/framework
src/Core/Application.php
Application.loadConfigurationFiles
public function loadConfigurationFiles(Repository $config, $path = '') { $files = $this->getConfigurationFiles($path); foreach ($files as $key => $path) { $config->set($key, require $path); } return $this; }
php
public function loadConfigurationFiles(Repository $config, $path = '') { $files = $this->getConfigurationFiles($path); foreach ($files as $key => $path) { $config->set($key, require $path); } return $this; }
[ "public", "function", "loadConfigurationFiles", "(", "Repository", "$", "config", ",", "$", "path", "=", "''", ")", "{", "$", "files", "=", "$", "this", "->", "getConfigurationFiles", "(", "$", "path", ")", ";", "foreach", "(", "$", "files", "as", "$", "key", "=>", "$", "path", ")", "{", "$", "config", "->", "set", "(", "$", "key", ",", "require", "$", "path", ")", ";", "}", "return", "$", "this", ";", "}" ]
Load configuration files based on given path. @param Repository $config @param string $path The configuration files folder path. @return Application
[ "Load", "configuration", "files", "based", "on", "given", "path", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Application.php#L1286-L1295
train
themosis/framework
src/Core/Application.php
Application.getConfigurationFiles
protected function getConfigurationFiles($path) { $files = []; foreach (Finder::create()->files()->name('*.php')->in($path) as $file) { $directory = $this->getNestedDirectory($file, $path); $files[$directory.basename($file->getRealPath(), '.php')] = $file->getRealPath(); } ksort($files, SORT_NATURAL); return $files; }
php
protected function getConfigurationFiles($path) { $files = []; foreach (Finder::create()->files()->name('*.php')->in($path) as $file) { $directory = $this->getNestedDirectory($file, $path); $files[$directory.basename($file->getRealPath(), '.php')] = $file->getRealPath(); } ksort($files, SORT_NATURAL); return $files; }
[ "protected", "function", "getConfigurationFiles", "(", "$", "path", ")", "{", "$", "files", "=", "[", "]", ";", "foreach", "(", "Finder", "::", "create", "(", ")", "->", "files", "(", ")", "->", "name", "(", "'*.php'", ")", "->", "in", "(", "$", "path", ")", "as", "$", "file", ")", "{", "$", "directory", "=", "$", "this", "->", "getNestedDirectory", "(", "$", "file", ",", "$", "path", ")", ";", "$", "files", "[", "$", "directory", ".", "basename", "(", "$", "file", "->", "getRealPath", "(", ")", ",", "'.php'", ")", "]", "=", "$", "file", "->", "getRealPath", "(", ")", ";", "}", "ksort", "(", "$", "files", ",", "SORT_NATURAL", ")", ";", "return", "$", "files", ";", "}" ]
Get all configuration files. @param mixed $path @return array
[ "Get", "all", "configuration", "files", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Application.php#L1304-L1316
train
themosis/framework
src/Core/Application.php
Application.getNestedDirectory
protected function getNestedDirectory(SplFileInfo $file, $path) { $directory = $file->getPath(); if ($nested = trim(str_replace($path, '', $directory), DIRECTORY_SEPARATOR)) { $nested = str_replace(DIRECTORY_SEPARATOR, '.', $nested).'.'; } return $nested; }
php
protected function getNestedDirectory(SplFileInfo $file, $path) { $directory = $file->getPath(); if ($nested = trim(str_replace($path, '', $directory), DIRECTORY_SEPARATOR)) { $nested = str_replace(DIRECTORY_SEPARATOR, '.', $nested).'.'; } return $nested; }
[ "protected", "function", "getNestedDirectory", "(", "SplFileInfo", "$", "file", ",", "$", "path", ")", "{", "$", "directory", "=", "$", "file", "->", "getPath", "(", ")", ";", "if", "(", "$", "nested", "=", "trim", "(", "str_replace", "(", "$", "path", ",", "''", ",", "$", "directory", ")", ",", "DIRECTORY_SEPARATOR", ")", ")", "{", "$", "nested", "=", "str_replace", "(", "DIRECTORY_SEPARATOR", ",", "'.'", ",", "$", "nested", ")", ".", "'.'", ";", "}", "return", "$", "nested", ";", "}" ]
Get configuration file nesting path. @param SplFileInfo $file @param string $path @return string
[ "Get", "configuration", "file", "nesting", "path", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Application.php#L1326-L1335
train
themosis/framework
src/Core/Application.php
Application.manage
public function manage(string $kernel, $request) { $kernel = $this->make($kernel); $response = $kernel->handle($request); $response->send(); $kernel->terminate($request, $response); return $this; }
php
public function manage(string $kernel, $request) { $kernel = $this->make($kernel); $response = $kernel->handle($request); $response->send(); $kernel->terminate($request, $response); return $this; }
[ "public", "function", "manage", "(", "string", "$", "kernel", ",", "$", "request", ")", "{", "$", "kernel", "=", "$", "this", "->", "make", "(", "$", "kernel", ")", ";", "$", "response", "=", "$", "kernel", "->", "handle", "(", "$", "request", ")", ";", "$", "response", "->", "send", "(", ")", ";", "$", "kernel", "->", "terminate", "(", "$", "request", ",", "$", "response", ")", ";", "return", "$", "this", ";", "}" ]
Handle incoming request and return a response. Abstract the implementation from the user for easy theme integration. @param string $kernel Application kernel class name. @param \Symfony\Component\HttpFoundation\Request $request @return $this
[ "Handle", "incoming", "request", "and", "return", "a", "response", ".", "Abstract", "the", "implementation", "from", "the", "user", "for", "easy", "theme", "integration", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Application.php#L1387-L1397
train
themosis/framework
src/Core/Application.php
Application.manageAdmin
public function manageAdmin(string $kernel, $request) { if (! $this->isWordPressAdmin() && ! $this->has('action')) { return $this; } $this['action']->add('admin_init', $this->dispatchToAdmin($kernel, $request)); return $this; }
php
public function manageAdmin(string $kernel, $request) { if (! $this->isWordPressAdmin() && ! $this->has('action')) { return $this; } $this['action']->add('admin_init', $this->dispatchToAdmin($kernel, $request)); return $this; }
[ "public", "function", "manageAdmin", "(", "string", "$", "kernel", ",", "$", "request", ")", "{", "if", "(", "!", "$", "this", "->", "isWordPressAdmin", "(", ")", "&&", "!", "$", "this", "->", "has", "(", "'action'", ")", ")", "{", "return", "$", "this", ";", "}", "$", "this", "[", "'action'", "]", "->", "add", "(", "'admin_init'", ",", "$", "this", "->", "dispatchToAdmin", "(", "$", "kernel", ",", "$", "request", ")", ")", ";", "return", "$", "this", ";", "}" ]
Handle WordPress administration incoming request. Only send response headers. @param string $kernel @param \Symfony\Component\HttpFoundation\Request $request @return $this;
[ "Handle", "WordPress", "administration", "incoming", "request", ".", "Only", "send", "response", "headers", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Application.php#L1408-L1417
train
themosis/framework
src/Core/Application.php
Application.dispatchToAdmin
protected function dispatchToAdmin(string $kernel, $request) { return function () use ($kernel, $request) { $kernel = $this->make($kernel); /** @var Response $response */ $response = $kernel->handle($request); if (500 <= $response->getStatusCode()) { // In case of an internal server error, we stop the process // and send full response back to the user. $response->send(); } else { // HTTP OK - Send only the response headers.s $response->sendHeaders(); } }; }
php
protected function dispatchToAdmin(string $kernel, $request) { return function () use ($kernel, $request) { $kernel = $this->make($kernel); /** @var Response $response */ $response = $kernel->handle($request); if (500 <= $response->getStatusCode()) { // In case of an internal server error, we stop the process // and send full response back to the user. $response->send(); } else { // HTTP OK - Send only the response headers.s $response->sendHeaders(); } }; }
[ "protected", "function", "dispatchToAdmin", "(", "string", "$", "kernel", ",", "$", "request", ")", "{", "return", "function", "(", ")", "use", "(", "$", "kernel", ",", "$", "request", ")", "{", "$", "kernel", "=", "$", "this", "->", "make", "(", "$", "kernel", ")", ";", "/** @var Response $response */", "$", "response", "=", "$", "kernel", "->", "handle", "(", "$", "request", ")", ";", "if", "(", "500", "<=", "$", "response", "->", "getStatusCode", "(", ")", ")", "{", "// In case of an internal server error, we stop the process", "// and send full response back to the user.", "$", "response", "->", "send", "(", ")", ";", "}", "else", "{", "// HTTP OK - Send only the response headers.s", "$", "response", "->", "sendHeaders", "(", ")", ";", "}", "}", ";", "}" ]
Manage WordPress Admin Init. Handle incoming request and return a response. @param string $kernel @param $request @return Closure
[ "Manage", "WordPress", "Admin", "Init", ".", "Handle", "incoming", "request", "and", "return", "a", "response", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Application.php#L1428-L1445
train
themosis/framework
src/Core/Application.php
Application.isWordPressAdmin
public function isWordPressAdmin() { if (isset($GLOBALS['current_screen']) && is_a($GLOBALS['current_screen'], 'WP_Screen')) { return $GLOBALS['current_screen']->in_admin(); } elseif (defined('WP_ADMIN')) { return WP_ADMIN; } return false; }
php
public function isWordPressAdmin() { if (isset($GLOBALS['current_screen']) && is_a($GLOBALS['current_screen'], 'WP_Screen')) { return $GLOBALS['current_screen']->in_admin(); } elseif (defined('WP_ADMIN')) { return WP_ADMIN; } return false; }
[ "public", "function", "isWordPressAdmin", "(", ")", "{", "if", "(", "isset", "(", "$", "GLOBALS", "[", "'current_screen'", "]", ")", "&&", "is_a", "(", "$", "GLOBALS", "[", "'current_screen'", "]", ",", "'WP_Screen'", ")", ")", "{", "return", "$", "GLOBALS", "[", "'current_screen'", "]", "->", "in_admin", "(", ")", ";", "}", "elseif", "(", "defined", "(", "'WP_ADMIN'", ")", ")", "{", "return", "WP_ADMIN", ";", "}", "return", "false", ";", "}" ]
Determine if we currently inside the WordPress administration. @return bool
[ "Determine", "if", "we", "currently", "inside", "the", "WordPress", "administration", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Application.php#L1564-L1573
train
themosis/framework
src/Core/Application.php
Application.outputJavascriptGlobal
public function outputJavascriptGlobal(string $name, array $data) { $output = "<script type=\"text/javascript\">\n\r"; $output .= "/* <![CDATA[ */\n\r"; $output .= "var {$name} = {\n\r"; if (! empty($data) && is_array($data)) { foreach ($data as $key => $value) { $output .= $key.': '.json_encode($value).",\n\r"; } } $output .= "};\n\r"; $output .= "/* ]]> */\n\r"; $output .= '</script>'; return $output; }
php
public function outputJavascriptGlobal(string $name, array $data) { $output = "<script type=\"text/javascript\">\n\r"; $output .= "/* <![CDATA[ */\n\r"; $output .= "var {$name} = {\n\r"; if (! empty($data) && is_array($data)) { foreach ($data as $key => $value) { $output .= $key.': '.json_encode($value).",\n\r"; } } $output .= "};\n\r"; $output .= "/* ]]> */\n\r"; $output .= '</script>'; return $output; }
[ "public", "function", "outputJavascriptGlobal", "(", "string", "$", "name", ",", "array", "$", "data", ")", "{", "$", "output", "=", "\"<script type=\\\"text/javascript\\\">\\n\\r\"", ";", "$", "output", ".=", "\"/* <![CDATA[ */\\n\\r\"", ";", "$", "output", ".=", "\"var {$name} = {\\n\\r\"", ";", "if", "(", "!", "empty", "(", "$", "data", ")", "&&", "is_array", "(", "$", "data", ")", ")", "{", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "output", ".=", "$", "key", ".", "': '", ".", "json_encode", "(", "$", "value", ")", ".", "\",\\n\\r\"", ";", "}", "}", "$", "output", ".=", "\"};\\n\\r\"", ";", "$", "output", ".=", "\"/* ]]> */\\n\\r\"", ";", "$", "output", ".=", "'</script>'", ";", "return", "$", "output", ";", "}" ]
Return a Javascript Global variable. @param string $name @param array $data @return string
[ "Return", "a", "Javascript", "Global", "variable", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Application.php#L1583-L1600
train
themosis/framework
src/Core/Support/IncludesFiles.php
IncludesFiles.includes
public function includes($path, string $pattern = '*.php') { foreach (Finder::create()->files()->name($pattern)->in($path)->sortByName() as $file) { /** @var \SplFileInfo $file */ @include $file->getRealPath(); } }
php
public function includes($path, string $pattern = '*.php') { foreach (Finder::create()->files()->name($pattern)->in($path)->sortByName() as $file) { /** @var \SplFileInfo $file */ @include $file->getRealPath(); } }
[ "public", "function", "includes", "(", "$", "path", ",", "string", "$", "pattern", "=", "'*.php'", ")", "{", "foreach", "(", "Finder", "::", "create", "(", ")", "->", "files", "(", ")", "->", "name", "(", "$", "pattern", ")", "->", "in", "(", "$", "path", ")", "->", "sortByName", "(", ")", "as", "$", "file", ")", "{", "/** @var \\SplFileInfo $file */", "@", "include", "$", "file", "->", "getRealPath", "(", ")", ";", "}", "}" ]
Automatically includes all .php files found on a specified directory path. @param string|array $path
[ "Automatically", "includes", "all", ".", "php", "files", "found", "on", "a", "specified", "directory", "path", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Support/IncludesFiles.php#L15-L21
train
themosis/framework
src/Core/Support/WordPressFileHeaders.php
WordPressFileHeaders.headers
public function headers(string $path, array $headers): array { $data = $this->read($path); $properties = []; foreach ($headers as $field => $regex) { if (preg_match('/^[ \t\/*#@]*'.preg_quote($regex, '/').':(.*)$/mi', $data, $match) && $match[1]) { $properties[$field] = trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $match[1])); } else { $properties[$field] = ''; } } return $properties; }
php
public function headers(string $path, array $headers): array { $data = $this->read($path); $properties = []; foreach ($headers as $field => $regex) { if (preg_match('/^[ \t\/*#@]*'.preg_quote($regex, '/').':(.*)$/mi', $data, $match) && $match[1]) { $properties[$field] = trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $match[1])); } else { $properties[$field] = ''; } } return $properties; }
[ "public", "function", "headers", "(", "string", "$", "path", ",", "array", "$", "headers", ")", ":", "array", "{", "$", "data", "=", "$", "this", "->", "read", "(", "$", "path", ")", ";", "$", "properties", "=", "[", "]", ";", "foreach", "(", "$", "headers", "as", "$", "field", "=>", "$", "regex", ")", "{", "if", "(", "preg_match", "(", "'/^[ \\t\\/*#@]*'", ".", "preg_quote", "(", "$", "regex", ",", "'/'", ")", ".", "':(.*)$/mi'", ",", "$", "data", ",", "$", "match", ")", "&&", "$", "match", "[", "1", "]", ")", "{", "$", "properties", "[", "$", "field", "]", "=", "trim", "(", "preg_replace", "(", "\"/\\s*(?:\\*\\/|\\?>).*/\"", ",", "''", ",", "$", "match", "[", "1", "]", ")", ")", ";", "}", "else", "{", "$", "properties", "[", "$", "field", "]", "=", "''", ";", "}", "}", "return", "$", "properties", ";", "}" ]
Return the file headers as an associative array. @param string $path @param array $headers @return array
[ "Return", "the", "file", "headers", "as", "an", "associative", "array", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Support/WordPressFileHeaders.php#L15-L29
train
themosis/framework
src/Core/Support/WordPressFileHeaders.php
WordPressFileHeaders.read
public function read(string $path, int $length = 8192): string { $handle = fopen($path, 'r'); $content = fread($handle, $length); fclose($handle); return str_replace("\r", "\n", $content); }
php
public function read(string $path, int $length = 8192): string { $handle = fopen($path, 'r'); $content = fread($handle, $length); fclose($handle); return str_replace("\r", "\n", $content); }
[ "public", "function", "read", "(", "string", "$", "path", ",", "int", "$", "length", "=", "8192", ")", ":", "string", "{", "$", "handle", "=", "fopen", "(", "$", "path", ",", "'r'", ")", ";", "$", "content", "=", "fread", "(", "$", "handle", ",", "$", "length", ")", ";", "fclose", "(", "$", "handle", ")", ";", "return", "str_replace", "(", "\"\\r\"", ",", "\"\\n\"", ",", "$", "content", ")", ";", "}" ]
Get a partial content of given file. @param string $path @param int $length @return string
[ "Get", "a", "partial", "content", "of", "given", "file", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Support/WordPressFileHeaders.php#L39-L46
train
themosis/framework
src/Support/Section.php
Section.getView
public function getView(bool $prefixed = false): string { if ($prefixed) { return $this->getTheme().'.'.$this->view; } return $this->view; }
php
public function getView(bool $prefixed = false): string { if ($prefixed) { return $this->getTheme().'.'.$this->view; } return $this->view; }
[ "public", "function", "getView", "(", "bool", "$", "prefixed", "=", "false", ")", ":", "string", "{", "if", "(", "$", "prefixed", ")", "{", "return", "$", "this", "->", "getTheme", "(", ")", ".", "'.'", ".", "$", "this", "->", "view", ";", "}", "return", "$", "this", "->", "view", ";", "}" ]
Get the section view file. @param bool $prefixed @return string
[ "Get", "the", "section", "view", "file", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Support/Section.php#L122-L129
train
themosis/framework
src/Support/Section.php
Section.setViewData
public function setViewData(array $data): SectionInterface { $this->data = $data; // Add default variables to the section view. // We provide a copy of the section instance // so we can iterate over its items from the view. $this->data = array_merge($data, [ '__section' => $this ]); return $this; }
php
public function setViewData(array $data): SectionInterface { $this->data = $data; // Add default variables to the section view. // We provide a copy of the section instance // so we can iterate over its items from the view. $this->data = array_merge($data, [ '__section' => $this ]); return $this; }
[ "public", "function", "setViewData", "(", "array", "$", "data", ")", ":", "SectionInterface", "{", "$", "this", "->", "data", "=", "$", "data", ";", "// Add default variables to the section view.", "// We provide a copy of the section instance", "// so we can iterate over its items from the view.", "$", "this", "->", "data", "=", "array_merge", "(", "$", "data", ",", "[", "'__section'", "=>", "$", "this", "]", ")", ";", "return", "$", "this", ";", "}" ]
Set section view data array. @param array $data @return SectionInterface
[ "Set", "section", "view", "data", "array", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Support/Section.php#L162-L174
train
themosis/framework
src/Core/PackageManifest.php
PackageManifest.get
public function get($key = 'aliases') { return collect($this->getManifest())->flatMap(function ($configuration) use ($key) { return (array) ($configuration[$key] ?? []); })->filter()->all(); }
php
public function get($key = 'aliases') { return collect($this->getManifest())->flatMap(function ($configuration) use ($key) { return (array) ($configuration[$key] ?? []); })->filter()->all(); }
[ "public", "function", "get", "(", "$", "key", "=", "'aliases'", ")", "{", "return", "collect", "(", "$", "this", "->", "getManifest", "(", ")", ")", "->", "flatMap", "(", "function", "(", "$", "configuration", ")", "use", "(", "$", "key", ")", "{", "return", "(", "array", ")", "(", "$", "configuration", "[", "$", "key", "]", "??", "[", "]", ")", ";", "}", ")", "->", "filter", "(", ")", "->", "all", "(", ")", ";", "}" ]
Get manifest items by key. @param string $key @throws \Illuminate\Contracts\Filesystem\FileNotFoundException @return array
[ "Get", "manifest", "items", "by", "key", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/PackageManifest.php#L76-L81
train
themosis/framework
src/Metabox/Manager.php
Manager.getFields
public function getFields(MetaboxInterface $metabox, Request $request): MetaboxInterface { foreach ($metabox->repository()->all() as $field) { if (method_exists($field, 'metaboxGet')) { $field->metaboxGet($request->query('post_id')); } } return $metabox; }
php
public function getFields(MetaboxInterface $metabox, Request $request): MetaboxInterface { foreach ($metabox->repository()->all() as $field) { if (method_exists($field, 'metaboxGet')) { $field->metaboxGet($request->query('post_id')); } } return $metabox; }
[ "public", "function", "getFields", "(", "MetaboxInterface", "$", "metabox", ",", "Request", "$", "request", ")", ":", "MetaboxInterface", "{", "foreach", "(", "$", "metabox", "->", "repository", "(", ")", "->", "all", "(", ")", "as", "$", "field", ")", "{", "if", "(", "method_exists", "(", "$", "field", ",", "'metaboxGet'", ")", ")", "{", "$", "field", "->", "metaboxGet", "(", "$", "request", "->", "query", "(", "'post_id'", ")", ")", ";", "}", "}", "return", "$", "metabox", ";", "}" ]
Handle metabox initialization. Set the metabox fields value and return the metabox instance. @param MetaboxInterface $metabox @param Request $request @return MetaboxInterface
[ "Handle", "metabox", "initialization", ".", "Set", "the", "metabox", "fields", "value", "and", "return", "the", "metabox", "instance", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Metabox/Manager.php#L36-L45
train
themosis/framework
src/Metabox/Manager.php
Manager.saveFields
public function saveFields(MetaboxInterface $metabox, Request $request): MetaboxInterface { $post_id = $request->query('post_id'); $data = $this->getMetaboxData(collect($request->get('fields'))); $fields = $metabox->repository()->all(); /** @var $validator Validator */ $validator = $this->factory->make( $data, $this->getMetaboxRules($fields), $this->getMetaboxMessages($fields), $this->getMetaboxPlaceholders($fields) ); $validatedData = $validator->valid(); foreach ($fields as $field) { /** @var FieldTypeInterface|CanHandleMetabox|BaseType $field */ $field->setErrorMessageBag($validator->errors()); if (method_exists($field, 'metaboxSave')) { $value = isset($validatedData[$field->getName()]) ? $validatedData[$field->getName()] : null; $field->metaboxSave($value, $post_id); } else { throw new MetaboxException( 'Unable to save ['.$field->getName().']. The [metaboxSave] method is missing.' ); } } return $metabox; }
php
public function saveFields(MetaboxInterface $metabox, Request $request): MetaboxInterface { $post_id = $request->query('post_id'); $data = $this->getMetaboxData(collect($request->get('fields'))); $fields = $metabox->repository()->all(); /** @var $validator Validator */ $validator = $this->factory->make( $data, $this->getMetaboxRules($fields), $this->getMetaboxMessages($fields), $this->getMetaboxPlaceholders($fields) ); $validatedData = $validator->valid(); foreach ($fields as $field) { /** @var FieldTypeInterface|CanHandleMetabox|BaseType $field */ $field->setErrorMessageBag($validator->errors()); if (method_exists($field, 'metaboxSave')) { $value = isset($validatedData[$field->getName()]) ? $validatedData[$field->getName()] : null; $field->metaboxSave($value, $post_id); } else { throw new MetaboxException( 'Unable to save ['.$field->getName().']. The [metaboxSave] method is missing.' ); } } return $metabox; }
[ "public", "function", "saveFields", "(", "MetaboxInterface", "$", "metabox", ",", "Request", "$", "request", ")", ":", "MetaboxInterface", "{", "$", "post_id", "=", "$", "request", "->", "query", "(", "'post_id'", ")", ";", "$", "data", "=", "$", "this", "->", "getMetaboxData", "(", "collect", "(", "$", "request", "->", "get", "(", "'fields'", ")", ")", ")", ";", "$", "fields", "=", "$", "metabox", "->", "repository", "(", ")", "->", "all", "(", ")", ";", "/** @var $validator Validator */", "$", "validator", "=", "$", "this", "->", "factory", "->", "make", "(", "$", "data", ",", "$", "this", "->", "getMetaboxRules", "(", "$", "fields", ")", ",", "$", "this", "->", "getMetaboxMessages", "(", "$", "fields", ")", ",", "$", "this", "->", "getMetaboxPlaceholders", "(", "$", "fields", ")", ")", ";", "$", "validatedData", "=", "$", "validator", "->", "valid", "(", ")", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "/** @var FieldTypeInterface|CanHandleMetabox|BaseType $field */", "$", "field", "->", "setErrorMessageBag", "(", "$", "validator", "->", "errors", "(", ")", ")", ";", "if", "(", "method_exists", "(", "$", "field", ",", "'metaboxSave'", ")", ")", "{", "$", "value", "=", "isset", "(", "$", "validatedData", "[", "$", "field", "->", "getName", "(", ")", "]", ")", "?", "$", "validatedData", "[", "$", "field", "->", "getName", "(", ")", "]", ":", "null", ";", "$", "field", "->", "metaboxSave", "(", "$", "value", ",", "$", "post_id", ")", ";", "}", "else", "{", "throw", "new", "MetaboxException", "(", "'Unable to save ['", ".", "$", "field", "->", "getName", "(", ")", ".", "']. The [metaboxSave] method is missing.'", ")", ";", "}", "}", "return", "$", "metabox", ";", "}" ]
Handle metabox post meta save. @param MetaboxInterface $metabox @param Request $request @throws MetaboxException @return MetaboxInterface
[ "Handle", "metabox", "post", "meta", "save", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Metabox/Manager.php#L57-L88
train
themosis/framework
src/Metabox/Manager.php
Manager.getMetaboxData
protected function getMetaboxData(Collection $fields) { $data = []; foreach ($fields as $field) { $data[$field['name']] = $field['value']; } return $data; }
php
protected function getMetaboxData(Collection $fields) { $data = []; foreach ($fields as $field) { $data[$field['name']] = $field['value']; } return $data; }
[ "protected", "function", "getMetaboxData", "(", "Collection", "$", "fields", ")", "{", "$", "data", "=", "[", "]", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "$", "data", "[", "$", "field", "[", "'name'", "]", "]", "=", "$", "field", "[", "'value'", "]", ";", "}", "return", "$", "data", ";", "}" ]
Return the metabox data for validation. @param Collection $fields @return array
[ "Return", "the", "metabox", "data", "for", "validation", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Metabox/Manager.php#L97-L106
train
themosis/framework
src/Metabox/Manager.php
Manager.getMetaboxRules
protected function getMetaboxRules(array $fields) { $rules = []; foreach ($fields as $field) { /** @var FieldTypeInterface $field */ $rules[$field->getName()] = $field->getOption('rules'); } return $rules; }
php
protected function getMetaboxRules(array $fields) { $rules = []; foreach ($fields as $field) { /** @var FieldTypeInterface $field */ $rules[$field->getName()] = $field->getOption('rules'); } return $rules; }
[ "protected", "function", "getMetaboxRules", "(", "array", "$", "fields", ")", "{", "$", "rules", "=", "[", "]", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "/** @var FieldTypeInterface $field */", "$", "rules", "[", "$", "field", "->", "getName", "(", ")", "]", "=", "$", "field", "->", "getOption", "(", "'rules'", ")", ";", "}", "return", "$", "rules", ";", "}" ]
Return the metabox rules for validation. @param array $fields @return array
[ "Return", "the", "metabox", "rules", "for", "validation", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Metabox/Manager.php#L115-L125
train
themosis/framework
src/Metabox/Manager.php
Manager.getMetaboxPlaceholders
protected function getMetaboxPlaceholders(array $fields) { $placeholders = []; foreach ($fields as $field) { /** @var FieldTypeInterface $field */ $placeholders[$field->getName()] = $field->getOption('placeholder'); } return $placeholders; }
php
protected function getMetaboxPlaceholders(array $fields) { $placeholders = []; foreach ($fields as $field) { /** @var FieldTypeInterface $field */ $placeholders[$field->getName()] = $field->getOption('placeholder'); } return $placeholders; }
[ "protected", "function", "getMetaboxPlaceholders", "(", "array", "$", "fields", ")", "{", "$", "placeholders", "=", "[", "]", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "/** @var FieldTypeInterface $field */", "$", "placeholders", "[", "$", "field", "->", "getName", "(", ")", "]", "=", "$", "field", "->", "getOption", "(", "'placeholder'", ")", ";", "}", "return", "$", "placeholders", ";", "}" ]
Return the metabox messages placeholders. @param array $fields @return array
[ "Return", "the", "metabox", "messages", "placeholders", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Metabox/Manager.php#L158-L168
train
themosis/framework
src/Route/Middleware/WordPressHeaders.php
WordPressHeaders.handle
public function handle(Request $request, \Closure $next) { $route = $request->route(); $response = $next($request); if (! $route->hasCondition() && function_exists('is_user_logged_in') && ! is_user_logged_in()) { // We're on a custom route. Remove "no-cache" headers added by WordPress: // - Cache-Control // - Expires // - Content-type (provided by the response instance as well) @header_remove('Cache-Control'); @header_remove('Expires'); @header_remove('Content-Type'); } // Set the response cache control to "public" // on pages visited by guest users only. if (function_exists('is_user_logged_in') && ! is_user_logged_in()) { $response->setPublic(); } return $response; }
php
public function handle(Request $request, \Closure $next) { $route = $request->route(); $response = $next($request); if (! $route->hasCondition() && function_exists('is_user_logged_in') && ! is_user_logged_in()) { // We're on a custom route. Remove "no-cache" headers added by WordPress: // - Cache-Control // - Expires // - Content-type (provided by the response instance as well) @header_remove('Cache-Control'); @header_remove('Expires'); @header_remove('Content-Type'); } // Set the response cache control to "public" // on pages visited by guest users only. if (function_exists('is_user_logged_in') && ! is_user_logged_in()) { $response->setPublic(); } return $response; }
[ "public", "function", "handle", "(", "Request", "$", "request", ",", "\\", "Closure", "$", "next", ")", "{", "$", "route", "=", "$", "request", "->", "route", "(", ")", ";", "$", "response", "=", "$", "next", "(", "$", "request", ")", ";", "if", "(", "!", "$", "route", "->", "hasCondition", "(", ")", "&&", "function_exists", "(", "'is_user_logged_in'", ")", "&&", "!", "is_user_logged_in", "(", ")", ")", "{", "// We're on a custom route. Remove \"no-cache\" headers added by WordPress:", "// - Cache-Control", "// - Expires", "// - Content-type (provided by the response instance as well)", "@", "header_remove", "(", "'Cache-Control'", ")", ";", "@", "header_remove", "(", "'Expires'", ")", ";", "@", "header_remove", "(", "'Content-Type'", ")", ";", "}", "// Set the response cache control to \"public\"", "// on pages visited by guest users only.", "if", "(", "function_exists", "(", "'is_user_logged_in'", ")", "&&", "!", "is_user_logged_in", "(", ")", ")", "{", "$", "response", "->", "setPublic", "(", ")", ";", "}", "return", "$", "response", ";", "}" ]
Cleanup response headers. @param Request $request @param \Closure $next @return Response
[ "Cleanup", "response", "headers", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Route/Middleware/WordPressHeaders.php#L18-L40
train
themosis/framework
src/Forms/FormServiceProvider.php
FormServiceProvider.register
public function register() { $this->registerFractalManager(); /** @var \Illuminate\View\Factory $view */ $view = $this->app['view']; $view->addLocation(__DIR__.'/views'); $this->app->singleton('form', function ($app) { return new FormFactory( $app['validator'], $app['view'], $app['league.fractal'], new Factory() ); }); }
php
public function register() { $this->registerFractalManager(); /** @var \Illuminate\View\Factory $view */ $view = $this->app['view']; $view->addLocation(__DIR__.'/views'); $this->app->singleton('form', function ($app) { return new FormFactory( $app['validator'], $app['view'], $app['league.fractal'], new Factory() ); }); }
[ "public", "function", "register", "(", ")", "{", "$", "this", "->", "registerFractalManager", "(", ")", ";", "/** @var \\Illuminate\\View\\Factory $view */", "$", "view", "=", "$", "this", "->", "app", "[", "'view'", "]", ";", "$", "view", "->", "addLocation", "(", "__DIR__", ".", "'/views'", ")", ";", "$", "this", "->", "app", "->", "singleton", "(", "'form'", ",", "function", "(", "$", "app", ")", "{", "return", "new", "FormFactory", "(", "$", "app", "[", "'validator'", "]", ",", "$", "app", "[", "'view'", "]", ",", "$", "app", "[", "'league.fractal'", "]", ",", "new", "Factory", "(", ")", ")", ";", "}", ")", ";", "}" ]
Register our form service.
[ "Register", "our", "form", "service", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/FormServiceProvider.php#L14-L30
train
themosis/framework
src/Asset/Factory.php
Factory.add
public function add(string $handle, string $path, array $dependencies = [], $version = null, $arg = null) { if (empty($handle) || empty($path)) { throw new \InvalidArgumentException('The asset instance expects a handle name and a path or URL.'); } return (new Asset($this->finder->find($path), $this->action, $this->filter, $this->html)) ->setHandle($handle) ->setDependencies($dependencies) ->setVersion($version) ->setArgument($arg); }
php
public function add(string $handle, string $path, array $dependencies = [], $version = null, $arg = null) { if (empty($handle) || empty($path)) { throw new \InvalidArgumentException('The asset instance expects a handle name and a path or URL.'); } return (new Asset($this->finder->find($path), $this->action, $this->filter, $this->html)) ->setHandle($handle) ->setDependencies($dependencies) ->setVersion($version) ->setArgument($arg); }
[ "public", "function", "add", "(", "string", "$", "handle", ",", "string", "$", "path", ",", "array", "$", "dependencies", "=", "[", "]", ",", "$", "version", "=", "null", ",", "$", "arg", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "handle", ")", "||", "empty", "(", "$", "path", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The asset instance expects a handle name and a path or URL.'", ")", ";", "}", "return", "(", "new", "Asset", "(", "$", "this", "->", "finder", "->", "find", "(", "$", "path", ")", ",", "$", "this", "->", "action", ",", "$", "this", "->", "filter", ",", "$", "this", "->", "html", ")", ")", "->", "setHandle", "(", "$", "handle", ")", "->", "setDependencies", "(", "$", "dependencies", ")", "->", "setVersion", "(", "$", "version", ")", "->", "setArgument", "(", "$", "arg", ")", ";", "}" ]
Create and return an Asset instance. @param string $handle @param string $path @param array $dependencies @param null|string|bool $version @param null|string|bool $arg @throws AssetException @return AssetInterface
[ "Create", "and", "return", "an", "Asset", "instance", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Asset/Factory.php#L51-L62
train
themosis/framework
src/Core/HooksRepository.php
HooksRepository.load
public function load(array $hooks) { if (empty($hooks)) { return; } foreach ($hooks as $hook) { $this->app->registerHook($hook); } }
php
public function load(array $hooks) { if (empty($hooks)) { return; } foreach ($hooks as $hook) { $this->app->registerHook($hook); } }
[ "public", "function", "load", "(", "array", "$", "hooks", ")", "{", "if", "(", "empty", "(", "$", "hooks", ")", ")", "{", "return", ";", "}", "foreach", "(", "$", "hooks", "as", "$", "hook", ")", "{", "$", "this", "->", "app", "->", "registerHook", "(", "$", "hook", ")", ";", "}", "}" ]
Load a list of registered hookable instances. @param array $hooks The list of hookable instances.
[ "Load", "a", "list", "of", "registered", "hookable", "instances", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/HooksRepository.php#L24-L33
train
themosis/framework
src/Core/Auth/ResetPasswords.php
ResetPasswords.reset
public function reset(Request $request) { $data = new PasswordResetData(); $form = $this->form(new PasswordResetForm($data)); $form->handleRequest($request); if ($form->isNotValid()) { return back()->withErrors($form->errors()->all()); } $response = $this->broker()->reset( $this->credentials($data), function ($user, $password) { $this->resetPassword($user, $password); } ); return $response == Password::PASSWORD_RESET ? $this->sendResetResponse($request, $response) : $this->sendResetFailedResponse($request, $response); }
php
public function reset(Request $request) { $data = new PasswordResetData(); $form = $this->form(new PasswordResetForm($data)); $form->handleRequest($request); if ($form->isNotValid()) { return back()->withErrors($form->errors()->all()); } $response = $this->broker()->reset( $this->credentials($data), function ($user, $password) { $this->resetPassword($user, $password); } ); return $response == Password::PASSWORD_RESET ? $this->sendResetResponse($request, $response) : $this->sendResetFailedResponse($request, $response); }
[ "public", "function", "reset", "(", "Request", "$", "request", ")", "{", "$", "data", "=", "new", "PasswordResetData", "(", ")", ";", "$", "form", "=", "$", "this", "->", "form", "(", "new", "PasswordResetForm", "(", "$", "data", ")", ")", ";", "$", "form", "->", "handleRequest", "(", "$", "request", ")", ";", "if", "(", "$", "form", "->", "isNotValid", "(", ")", ")", "{", "return", "back", "(", ")", "->", "withErrors", "(", "$", "form", "->", "errors", "(", ")", "->", "all", "(", ")", ")", ";", "}", "$", "response", "=", "$", "this", "->", "broker", "(", ")", "->", "reset", "(", "$", "this", "->", "credentials", "(", "$", "data", ")", ",", "function", "(", "$", "user", ",", "$", "password", ")", "{", "$", "this", "->", "resetPassword", "(", "$", "user", ",", "$", "password", ")", ";", "}", ")", ";", "return", "$", "response", "==", "Password", "::", "PASSWORD_RESET", "?", "$", "this", "->", "sendResetResponse", "(", "$", "request", ",", "$", "response", ")", ":", "$", "this", "->", "sendResetFailedResponse", "(", "$", "request", ",", "$", "response", ")", ";", "}" ]
Handle user password reset request. @param Request $request @return \Illuminate\Http\RedirectResponse
[ "Handle", "user", "password", "reset", "request", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Auth/ResetPasswords.php#L47-L68
train
themosis/framework
src/Core/Auth/ResetPasswords.php
ResetPasswords.credentials
protected function credentials(PasswordResetData $data): array { return [ 'email' => $data->getEmail(), 'password' => $data->getPassword(), 'password_confirmation' => $data->getPasswordConfirmation(), 'token' => $data->getToken() ]; }
php
protected function credentials(PasswordResetData $data): array { return [ 'email' => $data->getEmail(), 'password' => $data->getPassword(), 'password_confirmation' => $data->getPasswordConfirmation(), 'token' => $data->getToken() ]; }
[ "protected", "function", "credentials", "(", "PasswordResetData", "$", "data", ")", ":", "array", "{", "return", "[", "'email'", "=>", "$", "data", "->", "getEmail", "(", ")", ",", "'password'", "=>", "$", "data", "->", "getPassword", "(", ")", ",", "'password_confirmation'", "=>", "$", "data", "->", "getPasswordConfirmation", "(", ")", ",", "'token'", "=>", "$", "data", "->", "getToken", "(", ")", "]", ";", "}" ]
Return password broker expected values. @param PasswordResetData $data @return array
[ "Return", "password", "broker", "expected", "values", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Auth/ResetPasswords.php#L106-L114
train
themosis/framework
src/Taxonomy/Taxonomy.php
Taxonomy.setLabels
public function setLabels(array $labels): TaxonomyInterface { if (isset($this->args['labels'])) { $this->args['labels'] = array_merge($this->args['labels'], $labels); } else { $this->args['labels'] = $labels; } return $this; }
php
public function setLabels(array $labels): TaxonomyInterface { if (isset($this->args['labels'])) { $this->args['labels'] = array_merge($this->args['labels'], $labels); } else { $this->args['labels'] = $labels; } return $this; }
[ "public", "function", "setLabels", "(", "array", "$", "labels", ")", ":", "TaxonomyInterface", "{", "if", "(", "isset", "(", "$", "this", "->", "args", "[", "'labels'", "]", ")", ")", "{", "$", "this", "->", "args", "[", "'labels'", "]", "=", "array_merge", "(", "$", "this", "->", "args", "[", "'labels'", "]", ",", "$", "labels", ")", ";", "}", "else", "{", "$", "this", "->", "args", "[", "'labels'", "]", "=", "$", "labels", ";", "}", "return", "$", "this", ";", "}" ]
Set taxonomy labels. @param array $labels @return TaxonomyInterface
[ "Set", "taxonomy", "labels", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Taxonomy/Taxonomy.php#L74-L83
train
themosis/framework
src/Taxonomy/Taxonomy.php
Taxonomy.setArguments
public function setArguments(array $args): TaxonomyInterface { $this->args = array_merge($this->args, $args); return $this; }
php
public function setArguments(array $args): TaxonomyInterface { $this->args = array_merge($this->args, $args); return $this; }
[ "public", "function", "setArguments", "(", "array", "$", "args", ")", ":", "TaxonomyInterface", "{", "$", "this", "->", "args", "=", "array_merge", "(", "$", "this", "->", "args", ",", "$", "args", ")", ";", "return", "$", "this", ";", "}" ]
Set taxonomy arguments. @param array $args @return TaxonomyInterface
[ "Set", "taxonomy", "arguments", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Taxonomy/Taxonomy.php#L116-L121
train
themosis/framework
src/Taxonomy/Taxonomy.php
Taxonomy.set
public function set(): TaxonomyInterface { if (function_exists('current_filter') && 'init' === $hook = current_filter()) { $this->register(); } else { $this->action->add('init', [$this, 'register']); } return $this; }
php
public function set(): TaxonomyInterface { if (function_exists('current_filter') && 'init' === $hook = current_filter()) { $this->register(); } else { $this->action->add('init', [$this, 'register']); } return $this; }
[ "public", "function", "set", "(", ")", ":", "TaxonomyInterface", "{", "if", "(", "function_exists", "(", "'current_filter'", ")", "&&", "'init'", "===", "$", "hook", "=", "current_filter", "(", ")", ")", "{", "$", "this", "->", "register", "(", ")", ";", "}", "else", "{", "$", "this", "->", "action", "->", "add", "(", "'init'", ",", "[", "$", "this", ",", "'register'", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Register the taxonomy. @return TaxonomyInterface
[ "Register", "the", "taxonomy", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Taxonomy/Taxonomy.php#L152-L161
train
themosis/framework
src/Taxonomy/Taxonomy.php
Taxonomy.register
public function register() { register_taxonomy($this->slug, $this->objects, $this->getArguments()); $this->bind(); }
php
public function register() { register_taxonomy($this->slug, $this->objects, $this->getArguments()); $this->bind(); }
[ "public", "function", "register", "(", ")", "{", "register_taxonomy", "(", "$", "this", "->", "slug", ",", "$", "this", "->", "objects", ",", "$", "this", "->", "getArguments", "(", ")", ")", ";", "$", "this", "->", "bind", "(", ")", ";", "}" ]
Register taxonomy hook callback.
[ "Register", "taxonomy", "hook", "callback", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Taxonomy/Taxonomy.php#L166-L170
train
themosis/framework
src/Taxonomy/Taxonomy.php
Taxonomy.setObjects
public function setObjects($objects): TaxonomyInterface { $this->objects = array_unique(array_merge($this->objects, (array) $objects)); // Check if object have custom post status. // If so, change its default update count callback function. $this->parseObjectsForCustomStatus($this->objects); return $this; }
php
public function setObjects($objects): TaxonomyInterface { $this->objects = array_unique(array_merge($this->objects, (array) $objects)); // Check if object have custom post status. // If so, change its default update count callback function. $this->parseObjectsForCustomStatus($this->objects); return $this; }
[ "public", "function", "setObjects", "(", "$", "objects", ")", ":", "TaxonomyInterface", "{", "$", "this", "->", "objects", "=", "array_unique", "(", "array_merge", "(", "$", "this", "->", "objects", ",", "(", "array", ")", "$", "objects", ")", ")", ";", "// Check if object have custom post status.", "// If so, change its default update count callback function.", "$", "this", "->", "parseObjectsForCustomStatus", "(", "$", "this", "->", "objects", ")", ";", "return", "$", "this", ";", "}" ]
Set taxonomy objects. @param array|string $objects @return TaxonomyInterface
[ "Set", "taxonomy", "objects", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Taxonomy/Taxonomy.php#L190-L199
train
themosis/framework
src/Taxonomy/Taxonomy.php
Taxonomy.parseObjectsForCustomStatus
protected function parseObjectsForCustomStatus(array $objects): TaxonomyInterface { foreach ($objects as $object) { if ($this->container->bound('themosis.posttype.'.$object)) { $postType = $this->container['themosis.posttype.'.$object]; if ($postType->hasStatus()) { $this->setArguments([ 'update_count_callback' => '_update_generic_term_count' ]); break; } } } return $this; }
php
protected function parseObjectsForCustomStatus(array $objects): TaxonomyInterface { foreach ($objects as $object) { if ($this->container->bound('themosis.posttype.'.$object)) { $postType = $this->container['themosis.posttype.'.$object]; if ($postType->hasStatus()) { $this->setArguments([ 'update_count_callback' => '_update_generic_term_count' ]); break; } } } return $this; }
[ "protected", "function", "parseObjectsForCustomStatus", "(", "array", "$", "objects", ")", ":", "TaxonomyInterface", "{", "foreach", "(", "$", "objects", "as", "$", "object", ")", "{", "if", "(", "$", "this", "->", "container", "->", "bound", "(", "'themosis.posttype.'", ".", "$", "object", ")", ")", "{", "$", "postType", "=", "$", "this", "->", "container", "[", "'themosis.posttype.'", ".", "$", "object", "]", ";", "if", "(", "$", "postType", "->", "hasStatus", "(", ")", ")", "{", "$", "this", "->", "setArguments", "(", "[", "'update_count_callback'", "=>", "'_update_generic_term_count'", "]", ")", ";", "break", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Parse attached objects and set default update count callback. @param array $objects @return TaxonomyInterface
[ "Parse", "attached", "objects", "and", "set", "default", "update", "count", "callback", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Taxonomy/Taxonomy.php#L208-L224
train
themosis/framework
src/Metabox/Metabox.php
Metabox.display
public function display($post_type, $post) { if (! is_null($this->capability) && ! current_user_can($this->capability)) { return; } if (! $this->hasTemplateForPost($post)) { return; } $this->filter->add('admin_body_class', function ($classes) { if (false !== strrpos($classes, 'themosis')) { return $classes; } $classes.= ' themosis'; return $classes; }); add_meta_box( $this->getId(), $this->getTitle(), [$this, 'render'], $this->getScreen(), $this->getContext(), $this->getPriority(), $this->getArguments() ); }
php
public function display($post_type, $post) { if (! is_null($this->capability) && ! current_user_can($this->capability)) { return; } if (! $this->hasTemplateForPost($post)) { return; } $this->filter->add('admin_body_class', function ($classes) { if (false !== strrpos($classes, 'themosis')) { return $classes; } $classes.= ' themosis'; return $classes; }); add_meta_box( $this->getId(), $this->getTitle(), [$this, 'render'], $this->getScreen(), $this->getContext(), $this->getPriority(), $this->getArguments() ); }
[ "public", "function", "display", "(", "$", "post_type", ",", "$", "post", ")", "{", "if", "(", "!", "is_null", "(", "$", "this", "->", "capability", ")", "&&", "!", "current_user_can", "(", "$", "this", "->", "capability", ")", ")", "{", "return", ";", "}", "if", "(", "!", "$", "this", "->", "hasTemplateForPost", "(", "$", "post", ")", ")", "{", "return", ";", "}", "$", "this", "->", "filter", "->", "add", "(", "'admin_body_class'", ",", "function", "(", "$", "classes", ")", "{", "if", "(", "false", "!==", "strrpos", "(", "$", "classes", ",", "'themosis'", ")", ")", "{", "return", "$", "classes", ";", "}", "$", "classes", ".=", "' themosis'", ";", "return", "$", "classes", ";", "}", ")", ";", "add_meta_box", "(", "$", "this", "->", "getId", "(", ")", ",", "$", "this", "->", "getTitle", "(", ")", ",", "[", "$", "this", ",", "'render'", "]", ",", "$", "this", "->", "getScreen", "(", ")", ",", "$", "this", "->", "getContext", "(", ")", ",", "$", "this", "->", "getPriority", "(", ")", ",", "$", "this", "->", "getArguments", "(", ")", ")", ";", "}" ]
Handle "add_meta_boxes" hook and display the metabox. @param string $post_type @param \WP_Post $post
[ "Handle", "add_meta_boxes", "hook", "and", "display", "the", "metabox", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Metabox/Metabox.php#L329-L358
train
themosis/framework
src/Metabox/Metabox.php
Metabox.render
public function render(\WP_Post $post, array $args) { $args = array_merge($args['args'], [ 'metabox' => $this, 'post' => $post, 'screen' => $this->getScreen() ]); $response = $this->handleCallback($this->getCallback(), $args); if ($response instanceof Renderable) { echo $response->render(); } elseif ($response instanceof Response) { echo $response->getContent(); } }
php
public function render(\WP_Post $post, array $args) { $args = array_merge($args['args'], [ 'metabox' => $this, 'post' => $post, 'screen' => $this->getScreen() ]); $response = $this->handleCallback($this->getCallback(), $args); if ($response instanceof Renderable) { echo $response->render(); } elseif ($response instanceof Response) { echo $response->getContent(); } }
[ "public", "function", "render", "(", "\\", "WP_Post", "$", "post", ",", "array", "$", "args", ")", "{", "$", "args", "=", "array_merge", "(", "$", "args", "[", "'args'", "]", ",", "[", "'metabox'", "=>", "$", "this", ",", "'post'", "=>", "$", "post", ",", "'screen'", "=>", "$", "this", "->", "getScreen", "(", ")", "]", ")", ";", "$", "response", "=", "$", "this", "->", "handleCallback", "(", "$", "this", "->", "getCallback", "(", ")", ",", "$", "args", ")", ";", "if", "(", "$", "response", "instanceof", "Renderable", ")", "{", "echo", "$", "response", "->", "render", "(", ")", ";", "}", "elseif", "(", "$", "response", "instanceof", "Response", ")", "{", "echo", "$", "response", "->", "getContent", "(", ")", ";", "}", "}" ]
Render the metabox. @param \WP_Post $post @param array $args
[ "Render", "the", "metabox", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Metabox/Metabox.php#L366-L381
train
themosis/framework
src/Metabox/Metabox.php
Metabox.handle
public function handle(array $args) { $this->filter->add('themosis_admin_global', function ($data) use ($args) { if (! isset($data['metabox'])) { $data['metabox'] = [$this->id]; } elseif (isset($data['metabox'])) { $data['metabox'][] = $this->id; } /* * Provides WP_Post data. */ $data['post'] = $args['post']; return $data; }); }
php
public function handle(array $args) { $this->filter->add('themosis_admin_global', function ($data) use ($args) { if (! isset($data['metabox'])) { $data['metabox'] = [$this->id]; } elseif (isset($data['metabox'])) { $data['metabox'][] = $this->id; } /* * Provides WP_Post data. */ $data['post'] = $args['post']; return $data; }); }
[ "public", "function", "handle", "(", "array", "$", "args", ")", "{", "$", "this", "->", "filter", "->", "add", "(", "'themosis_admin_global'", ",", "function", "(", "$", "data", ")", "use", "(", "$", "args", ")", "{", "if", "(", "!", "isset", "(", "$", "data", "[", "'metabox'", "]", ")", ")", "{", "$", "data", "[", "'metabox'", "]", "=", "[", "$", "this", "->", "id", "]", ";", "}", "elseif", "(", "isset", "(", "$", "data", "[", "'metabox'", "]", ")", ")", "{", "$", "data", "[", "'metabox'", "]", "[", "]", "=", "$", "this", "->", "id", ";", "}", "/*\n * Provides WP_Post data.\n */", "$", "data", "[", "'post'", "]", "=", "$", "args", "[", "'post'", "]", ";", "return", "$", "data", ";", "}", ")", ";", "}" ]
Core framework metabox management. Default callback. @param array $args
[ "Core", "framework", "metabox", "management", ".", "Default", "callback", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Metabox/Metabox.php#L388-L404
train
themosis/framework
src/Metabox/Metabox.php
Metabox.add
public function add($field, SectionInterface $section = null): MetaboxInterface { if ($field instanceof SectionInterface) { $section = $field; if ($section->hasItems()) { foreach ($section->getItems() as $item) { /** @var FieldTypeInterface $item */ $item->setOptions([ 'group' => $section->getId() ]); $this->add($item, $section); } } return $this; } $field->setLocale($this->getLocale()); $field->setPrefix($this->getPrefix()); if (is_null($section)) { if ($this->repository()->hasGroup($field->getOption('group'))) { $section = $this->repository()->getGroup($field->getOption('group')); } else { $section = new Section($field->getOption('group')); } $section->addItem($field); } $this->repository()->addField($field, $section); return $this; }
php
public function add($field, SectionInterface $section = null): MetaboxInterface { if ($field instanceof SectionInterface) { $section = $field; if ($section->hasItems()) { foreach ($section->getItems() as $item) { /** @var FieldTypeInterface $item */ $item->setOptions([ 'group' => $section->getId() ]); $this->add($item, $section); } } return $this; } $field->setLocale($this->getLocale()); $field->setPrefix($this->getPrefix()); if (is_null($section)) { if ($this->repository()->hasGroup($field->getOption('group'))) { $section = $this->repository()->getGroup($field->getOption('group')); } else { $section = new Section($field->getOption('group')); } $section->addItem($field); } $this->repository()->addField($field, $section); return $this; }
[ "public", "function", "add", "(", "$", "field", ",", "SectionInterface", "$", "section", "=", "null", ")", ":", "MetaboxInterface", "{", "if", "(", "$", "field", "instanceof", "SectionInterface", ")", "{", "$", "section", "=", "$", "field", ";", "if", "(", "$", "section", "->", "hasItems", "(", ")", ")", "{", "foreach", "(", "$", "section", "->", "getItems", "(", ")", "as", "$", "item", ")", "{", "/** @var FieldTypeInterface $item */", "$", "item", "->", "setOptions", "(", "[", "'group'", "=>", "$", "section", "->", "getId", "(", ")", "]", ")", ";", "$", "this", "->", "add", "(", "$", "item", ",", "$", "section", ")", ";", "}", "}", "return", "$", "this", ";", "}", "$", "field", "->", "setLocale", "(", "$", "this", "->", "getLocale", "(", ")", ")", ";", "$", "field", "->", "setPrefix", "(", "$", "this", "->", "getPrefix", "(", ")", ")", ";", "if", "(", "is_null", "(", "$", "section", ")", ")", "{", "if", "(", "$", "this", "->", "repository", "(", ")", "->", "hasGroup", "(", "$", "field", "->", "getOption", "(", "'group'", ")", ")", ")", "{", "$", "section", "=", "$", "this", "->", "repository", "(", ")", "->", "getGroup", "(", "$", "field", "->", "getOption", "(", "'group'", ")", ")", ";", "}", "else", "{", "$", "section", "=", "new", "Section", "(", "$", "field", "->", "getOption", "(", "'group'", ")", ")", ";", "}", "$", "section", "->", "addItem", "(", "$", "field", ")", ";", "}", "$", "this", "->", "repository", "(", ")", "->", "addField", "(", "$", "field", ",", "$", "section", ")", ";", "return", "$", "this", ";", "}" ]
Add a field to the metabox. @param FieldTypeInterface|SectionInterface $field @param SectionInterface $section @return MetaboxInterface
[ "Add", "a", "field", "to", "the", "metabox", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Metabox/Metabox.php#L516-L550
train
themosis/framework
src/Metabox/Metabox.php
Metabox.addTranslation
public function addTranslation(string $key, string $translation): MetaboxInterface { $this->l10n[$key] = $translation; return $this; }
php
public function addTranslation(string $key, string $translation): MetaboxInterface { $this->l10n[$key] = $translation; return $this; }
[ "public", "function", "addTranslation", "(", "string", "$", "key", ",", "string", "$", "translation", ")", ":", "MetaboxInterface", "{", "$", "this", "->", "l10n", "[", "$", "key", "]", "=", "$", "translation", ";", "return", "$", "this", ";", "}" ]
Add metabox translation. @param string $key @param string $translation @return MetaboxInterface
[ "Add", "metabox", "translation", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Metabox/Metabox.php#L587-L592
train
themosis/framework
src/Metabox/Metabox.php
Metabox.setTemplate
public function setTemplate($template, string $screen = 'page'): MetaboxInterface { $this->template[$screen] = (array) $template; return $this; }
php
public function setTemplate($template, string $screen = 'page'): MetaboxInterface { $this->template[$screen] = (array) $template; return $this; }
[ "public", "function", "setTemplate", "(", "$", "template", ",", "string", "$", "screen", "=", "'page'", ")", ":", "MetaboxInterface", "{", "$", "this", "->", "template", "[", "$", "screen", "]", "=", "(", "array", ")", "$", "template", ";", "return", "$", "this", ";", "}" ]
Set the metabox template. @param array|string $template @param string $screen @return MetaboxInterface
[ "Set", "the", "metabox", "template", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Metabox/Metabox.php#L626-L631
train
themosis/framework
src/Metabox/Metabox.php
Metabox.hasTemplateForPost
private function hasTemplateForPost(\WP_Post $post): bool { $postTemplate = get_post_meta($post->ID, '_wp_page_template', true); $templates = isset($this->template[$post->post_type]) ? $this->template[$post->post_type] : []; if (empty($templates)) { // No templates exist for the current post type so we let // pass through either in order to display the metabox. return true; } return in_array($postTemplate, $templates, true); }
php
private function hasTemplateForPost(\WP_Post $post): bool { $postTemplate = get_post_meta($post->ID, '_wp_page_template', true); $templates = isset($this->template[$post->post_type]) ? $this->template[$post->post_type] : []; if (empty($templates)) { // No templates exist for the current post type so we let // pass through either in order to display the metabox. return true; } return in_array($postTemplate, $templates, true); }
[ "private", "function", "hasTemplateForPost", "(", "\\", "WP_Post", "$", "post", ")", ":", "bool", "{", "$", "postTemplate", "=", "get_post_meta", "(", "$", "post", "->", "ID", ",", "'_wp_page_template'", ",", "true", ")", ";", "$", "templates", "=", "isset", "(", "$", "this", "->", "template", "[", "$", "post", "->", "post_type", "]", ")", "?", "$", "this", "->", "template", "[", "$", "post", "->", "post_type", "]", ":", "[", "]", ";", "if", "(", "empty", "(", "$", "templates", ")", ")", "{", "// No templates exist for the current post type so we let", "// pass through either in order to display the metabox.", "return", "true", ";", "}", "return", "in_array", "(", "$", "postTemplate", ",", "$", "templates", ",", "true", ")", ";", "}" ]
Check if given post should use the template. @param \WP_Post $post @return bool
[ "Check", "if", "given", "post", "should", "use", "the", "template", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Metabox/Metabox.php#L650-L663
train
themosis/framework
src/Forms/DataMappers/DataMapperManager.php
DataMapperManager.mapFromObjectToField
public function mapFromObjectToField($data, FieldTypeInterface $field) { if (! is_object($data)) { $this->triggerException(); } $field->setValue( $this->propertyAccessor->getValue($data, $field->getBaseName()) ); }
php
public function mapFromObjectToField($data, FieldTypeInterface $field) { if (! is_object($data)) { $this->triggerException(); } $field->setValue( $this->propertyAccessor->getValue($data, $field->getBaseName()) ); }
[ "public", "function", "mapFromObjectToField", "(", "$", "data", ",", "FieldTypeInterface", "$", "field", ")", "{", "if", "(", "!", "is_object", "(", "$", "data", ")", ")", "{", "$", "this", "->", "triggerException", "(", ")", ";", "}", "$", "field", "->", "setValue", "(", "$", "this", "->", "propertyAccessor", "->", "getValue", "(", "$", "data", ",", "$", "field", "->", "getBaseName", "(", ")", ")", ")", ";", "}" ]
Map data from object to field. @param mixed $data @param FieldTypeInterface $field
[ "Map", "data", "from", "object", "to", "field", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/DataMappers/DataMapperManager.php#L26-L35
train
themosis/framework
src/Core/Http/Middleware/VerifyCsrfToken.php
VerifyCsrfToken.getTokenFromRequest
protected function getTokenFromRequest(Request $request) { $token = $request->input($this->token) ?: $request->header($this->csrfHeader); if (! $token && $header = $request->header($this->xsrfHeader)) { $token = $this->encrypter->decrypt($header, static::serialized()); } return $token; }
php
protected function getTokenFromRequest(Request $request) { $token = $request->input($this->token) ?: $request->header($this->csrfHeader); if (! $token && $header = $request->header($this->xsrfHeader)) { $token = $this->encrypter->decrypt($header, static::serialized()); } return $token; }
[ "protected", "function", "getTokenFromRequest", "(", "Request", "$", "request", ")", "{", "$", "token", "=", "$", "request", "->", "input", "(", "$", "this", "->", "token", ")", "?", ":", "$", "request", "->", "header", "(", "$", "this", "->", "csrfHeader", ")", ";", "if", "(", "!", "$", "token", "&&", "$", "header", "=", "$", "request", "->", "header", "(", "$", "this", "->", "xsrfHeader", ")", ")", "{", "$", "token", "=", "$", "this", "->", "encrypter", "->", "decrypt", "(", "$", "header", ",", "static", "::", "serialized", "(", ")", ")", ";", "}", "return", "$", "token", ";", "}" ]
Return the CSRF token from request. @param Request $request @return string
[ "Return", "the", "CSRF", "token", "from", "request", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Http/Middleware/VerifyCsrfToken.php#L163-L172
train
themosis/framework
src/Core/Console/PluginInstallCommand.php
PluginInstallCommand.generatePluginHeaders
protected function generatePluginHeaders(string $name) { $description = $this->ask('Description:', ''); $author = $this->ask('Author:', 'Themosis'); $textdomain = $this->ask('Text domain:', trim($name, '\/-_')); $variable = strtoupper($this->ask('Domain variable:', 'PLUGIN_TD')); $prefix = $this->ask('Plugin prefix:', str_replace(['-', ' '], '_', $name)); $namespace = $this->ask('PHP Namespace:', 'Tld\Domain\Plugin'); return [ 'name' => ucwords(str_replace(['-', '_'], ' ', $name)), 'description' => $description, 'author' => $author, 'text_domain' => $textdomain, 'domain_var' => $variable, 'plugin_prefix' => $prefix, 'plugin_namespace' => $namespace, 'plugin_id' => $name ]; }
php
protected function generatePluginHeaders(string $name) { $description = $this->ask('Description:', ''); $author = $this->ask('Author:', 'Themosis'); $textdomain = $this->ask('Text domain:', trim($name, '\/-_')); $variable = strtoupper($this->ask('Domain variable:', 'PLUGIN_TD')); $prefix = $this->ask('Plugin prefix:', str_replace(['-', ' '], '_', $name)); $namespace = $this->ask('PHP Namespace:', 'Tld\Domain\Plugin'); return [ 'name' => ucwords(str_replace(['-', '_'], ' ', $name)), 'description' => $description, 'author' => $author, 'text_domain' => $textdomain, 'domain_var' => $variable, 'plugin_prefix' => $prefix, 'plugin_namespace' => $namespace, 'plugin_id' => $name ]; }
[ "protected", "function", "generatePluginHeaders", "(", "string", "$", "name", ")", "{", "$", "description", "=", "$", "this", "->", "ask", "(", "'Description:'", ",", "''", ")", ";", "$", "author", "=", "$", "this", "->", "ask", "(", "'Author:'", ",", "'Themosis'", ")", ";", "$", "textdomain", "=", "$", "this", "->", "ask", "(", "'Text domain:'", ",", "trim", "(", "$", "name", ",", "'\\/-_'", ")", ")", ";", "$", "variable", "=", "strtoupper", "(", "$", "this", "->", "ask", "(", "'Domain variable:'", ",", "'PLUGIN_TD'", ")", ")", ";", "$", "prefix", "=", "$", "this", "->", "ask", "(", "'Plugin prefix:'", ",", "str_replace", "(", "[", "'-'", ",", "' '", "]", ",", "'_'", ",", "$", "name", ")", ")", ";", "$", "namespace", "=", "$", "this", "->", "ask", "(", "'PHP Namespace:'", ",", "'Tld\\Domain\\Plugin'", ")", ";", "return", "[", "'name'", "=>", "ucwords", "(", "str_replace", "(", "[", "'-'", ",", "'_'", "]", ",", "' '", ",", "$", "name", ")", ")", ",", "'description'", "=>", "$", "description", ",", "'author'", "=>", "$", "author", ",", "'text_domain'", "=>", "$", "textdomain", ",", "'domain_var'", "=>", "$", "variable", ",", "'plugin_prefix'", "=>", "$", "prefix", ",", "'plugin_namespace'", "=>", "$", "namespace", ",", "'plugin_id'", "=>", "$", "name", "]", ";", "}" ]
Generate plugin headers. @param string $name @return array
[ "Generate", "plugin", "headers", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Console/PluginInstallCommand.php#L81-L100
train
themosis/framework
src/Core/Console/PluginInstallCommand.php
PluginInstallCommand.installPlugin
protected function installPlugin(string $name) { $this->info('Downloading plugin...'); $this->files->copy($this->option('url'), $this->temp); if (true !== $this->zip->open($this->temp)) { $this->error('Cannot open plugin zip file.'); return; } $this->zip->extractTo($this->path()); $this->zip->close(); $this->files->move( $this->path($this->option('dir')), $this->path($name) ); $this->files->delete($this->temp); }
php
protected function installPlugin(string $name) { $this->info('Downloading plugin...'); $this->files->copy($this->option('url'), $this->temp); if (true !== $this->zip->open($this->temp)) { $this->error('Cannot open plugin zip file.'); return; } $this->zip->extractTo($this->path()); $this->zip->close(); $this->files->move( $this->path($this->option('dir')), $this->path($name) ); $this->files->delete($this->temp); }
[ "protected", "function", "installPlugin", "(", "string", "$", "name", ")", "{", "$", "this", "->", "info", "(", "'Downloading plugin...'", ")", ";", "$", "this", "->", "files", "->", "copy", "(", "$", "this", "->", "option", "(", "'url'", ")", ",", "$", "this", "->", "temp", ")", ";", "if", "(", "true", "!==", "$", "this", "->", "zip", "->", "open", "(", "$", "this", "->", "temp", ")", ")", "{", "$", "this", "->", "error", "(", "'Cannot open plugin zip file.'", ")", ";", "return", ";", "}", "$", "this", "->", "zip", "->", "extractTo", "(", "$", "this", "->", "path", "(", ")", ")", ";", "$", "this", "->", "zip", "->", "close", "(", ")", ";", "$", "this", "->", "files", "->", "move", "(", "$", "this", "->", "path", "(", "$", "this", "->", "option", "(", "'dir'", ")", ")", ",", "$", "this", "->", "path", "(", "$", "name", ")", ")", ";", "$", "this", "->", "files", "->", "delete", "(", "$", "this", "->", "temp", ")", ";", "}" ]
Install the plugin. @param string $name
[ "Install", "the", "plugin", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Console/PluginInstallCommand.php#L107-L128
train
themosis/framework
src/Core/Console/PluginInstallCommand.php
PluginInstallCommand.setPluginHeaders
protected function setPluginHeaders(string $name, array $headers) { $this->info('Set plugin headers...'); $path = $this->path($name.'/plugin-name.php'); $handle = fopen($path, 'r'); $content = []; while (($line = fgets($handle)) !== false) { $content[] = $this->parseLine($line, $headers); } fclose($handle); $this->files->put($path, implode('', $content), true); }
php
protected function setPluginHeaders(string $name, array $headers) { $this->info('Set plugin headers...'); $path = $this->path($name.'/plugin-name.php'); $handle = fopen($path, 'r'); $content = []; while (($line = fgets($handle)) !== false) { $content[] = $this->parseLine($line, $headers); } fclose($handle); $this->files->put($path, implode('', $content), true); }
[ "protected", "function", "setPluginHeaders", "(", "string", "$", "name", ",", "array", "$", "headers", ")", "{", "$", "this", "->", "info", "(", "'Set plugin headers...'", ")", ";", "$", "path", "=", "$", "this", "->", "path", "(", "$", "name", ".", "'/plugin-name.php'", ")", ";", "$", "handle", "=", "fopen", "(", "$", "path", ",", "'r'", ")", ";", "$", "content", "=", "[", "]", ";", "while", "(", "(", "$", "line", "=", "fgets", "(", "$", "handle", ")", ")", "!==", "false", ")", "{", "$", "content", "[", "]", "=", "$", "this", "->", "parseLine", "(", "$", "line", ",", "$", "headers", ")", ";", "}", "fclose", "(", "$", "handle", ")", ";", "$", "this", "->", "files", "->", "put", "(", "$", "path", ",", "implode", "(", "''", ",", "$", "content", ")", ",", "true", ")", ";", "}" ]
Setup the plugin headers. @param string $name @param array $headers
[ "Setup", "the", "plugin", "headers", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Console/PluginInstallCommand.php#L136-L151
train
themosis/framework
src/Core/Console/PluginInstallCommand.php
PluginInstallCommand.parseLine
protected function parseLine(string $line, array $headers) { foreach ($this->headers as $field => $regex) { if (preg_match('/^[ \t\/*#@]*'.preg_quote($regex, '/').':(.*)$/mi', $line, $match) && $match[0] && isset($headers[$field])) { return preg_replace('/:\s?+.+\s?+/', ': '.$headers[$field], $match[0])."\n"; } } return $line; }
php
protected function parseLine(string $line, array $headers) { foreach ($this->headers as $field => $regex) { if (preg_match('/^[ \t\/*#@]*'.preg_quote($regex, '/').':(.*)$/mi', $line, $match) && $match[0] && isset($headers[$field])) { return preg_replace('/:\s?+.+\s?+/', ': '.$headers[$field], $match[0])."\n"; } } return $line; }
[ "protected", "function", "parseLine", "(", "string", "$", "line", ",", "array", "$", "headers", ")", "{", "foreach", "(", "$", "this", "->", "headers", "as", "$", "field", "=>", "$", "regex", ")", "{", "if", "(", "preg_match", "(", "'/^[ \\t\\/*#@]*'", ".", "preg_quote", "(", "$", "regex", ",", "'/'", ")", ".", "':(.*)$/mi'", ",", "$", "line", ",", "$", "match", ")", "&&", "$", "match", "[", "0", "]", "&&", "isset", "(", "$", "headers", "[", "$", "field", "]", ")", ")", "{", "return", "preg_replace", "(", "'/:\\s?+.+\\s?+/'", ",", "': '", ".", "$", "headers", "[", "$", "field", "]", ",", "$", "match", "[", "0", "]", ")", ".", "\"\\n\"", ";", "}", "}", "return", "$", "line", ";", "}" ]
Parse file header line. @param string $line @param array $headers @return string
[ "Parse", "file", "header", "line", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Console/PluginInstallCommand.php#L161-L172
train
themosis/framework
src/Core/Console/PluginInstallCommand.php
PluginInstallCommand.setPluginRootFile
protected function setPluginRootFile(string $name) { $this->info('Set plugin root file...'); $this->files->move($this->path($name.'/plugin-name.php'), $this->path($name.'/'.$name.'.php')); }
php
protected function setPluginRootFile(string $name) { $this->info('Set plugin root file...'); $this->files->move($this->path($name.'/plugin-name.php'), $this->path($name.'/'.$name.'.php')); }
[ "protected", "function", "setPluginRootFile", "(", "string", "$", "name", ")", "{", "$", "this", "->", "info", "(", "'Set plugin root file...'", ")", ";", "$", "this", "->", "files", "->", "move", "(", "$", "this", "->", "path", "(", "$", "name", ".", "'/plugin-name.php'", ")", ",", "$", "this", "->", "path", "(", "$", "name", ".", "'/'", ".", "$", "name", ".", "'.php'", ")", ")", ";", "}" ]
Set the plugin root file name. @param string $name
[ "Set", "the", "plugin", "root", "file", "name", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Console/PluginInstallCommand.php#L179-L183
train
themosis/framework
src/Core/Console/PluginInstallCommand.php
PluginInstallCommand.setConfigurationFile
protected function setConfigurationFile(string $name, array $headers) { $this->info('Set plugin configuration...'); $prefix = trim($headers['plugin_prefix'], '\/_-'); $from = $this->path($name.'/config/prefix_plugin.php'); $to = $this->path($name.'/config/'.$prefix.'_plugin.php'); $this->files->move($from, $to); $this->replaceFileContent($to, $headers); }
php
protected function setConfigurationFile(string $name, array $headers) { $this->info('Set plugin configuration...'); $prefix = trim($headers['plugin_prefix'], '\/_-'); $from = $this->path($name.'/config/prefix_plugin.php'); $to = $this->path($name.'/config/'.$prefix.'_plugin.php'); $this->files->move($from, $to); $this->replaceFileContent($to, $headers); }
[ "protected", "function", "setConfigurationFile", "(", "string", "$", "name", ",", "array", "$", "headers", ")", "{", "$", "this", "->", "info", "(", "'Set plugin configuration...'", ")", ";", "$", "prefix", "=", "trim", "(", "$", "headers", "[", "'plugin_prefix'", "]", ",", "'\\/_-'", ")", ";", "$", "from", "=", "$", "this", "->", "path", "(", "$", "name", ".", "'/config/prefix_plugin.php'", ")", ";", "$", "to", "=", "$", "this", "->", "path", "(", "$", "name", ".", "'/config/'", ".", "$", "prefix", ".", "'_plugin.php'", ")", ";", "$", "this", "->", "files", "->", "move", "(", "$", "from", ",", "$", "to", ")", ";", "$", "this", "->", "replaceFileContent", "(", "$", "to", ",", "$", "headers", ")", ";", "}" ]
Set the plugin configuration file. @param string $name @param array $headers @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
[ "Set", "the", "plugin", "configuration", "file", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Console/PluginInstallCommand.php#L193-L203
train
themosis/framework
src/Core/Console/PluginInstallCommand.php
PluginInstallCommand.setTranslationFile
protected function setTranslationFile($name, array $headers) { $this->info('Set plugin translation file...'); $textdomain = trim($headers['text_domain'], '\/ _-'); $from = $this->path($name.'/languages/plugin-textdomain-en_US.po'); $to = $this->path($name.'/languages/'.$textdomain.'-en_US.po'); $this->files->move($from, $to); }
php
protected function setTranslationFile($name, array $headers) { $this->info('Set plugin translation file...'); $textdomain = trim($headers['text_domain'], '\/ _-'); $from = $this->path($name.'/languages/plugin-textdomain-en_US.po'); $to = $this->path($name.'/languages/'.$textdomain.'-en_US.po'); $this->files->move($from, $to); }
[ "protected", "function", "setTranslationFile", "(", "$", "name", ",", "array", "$", "headers", ")", "{", "$", "this", "->", "info", "(", "'Set plugin translation file...'", ")", ";", "$", "textdomain", "=", "trim", "(", "$", "headers", "[", "'text_domain'", "]", ",", "'\\/ _-'", ")", ";", "$", "from", "=", "$", "this", "->", "path", "(", "$", "name", ".", "'/languages/plugin-textdomain-en_US.po'", ")", ";", "$", "to", "=", "$", "this", "->", "path", "(", "$", "name", ".", "'/languages/'", ".", "$", "textdomain", ".", "'-en_US.po'", ")", ";", "$", "this", "->", "files", "->", "move", "(", "$", "from", ",", "$", "to", ")", ";", "}" ]
Set the plugin translation file. @param string $name @param array $headers
[ "Set", "the", "plugin", "translation", "file", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Console/PluginInstallCommand.php#L211-L220
train
themosis/framework
src/Core/Console/PluginInstallCommand.php
PluginInstallCommand.setProviders
protected function setProviders(string $name, array $headers) { $this->info('Set default route provider...'); $this->replaceFileContent( $this->path($name.'/resources/Providers/RouteServiceProvider.php'), $headers ); }
php
protected function setProviders(string $name, array $headers) { $this->info('Set default route provider...'); $this->replaceFileContent( $this->path($name.'/resources/Providers/RouteServiceProvider.php'), $headers ); }
[ "protected", "function", "setProviders", "(", "string", "$", "name", ",", "array", "$", "headers", ")", "{", "$", "this", "->", "info", "(", "'Set default route provider...'", ")", ";", "$", "this", "->", "replaceFileContent", "(", "$", "this", "->", "path", "(", "$", "name", ".", "'/resources/Providers/RouteServiceProvider.php'", ")", ",", "$", "headers", ")", ";", "}" ]
Set the content of default route provider. @param string $name @param array $headers @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
[ "Set", "the", "content", "of", "default", "route", "provider", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Console/PluginInstallCommand.php#L230-L238
train
themosis/framework
src/Core/Console/PluginInstallCommand.php
PluginInstallCommand.replaceFileContent
protected function replaceFileContent($path, array $headers) { $content = $this->files->get($path); $this->files->put($path, str_replace([ 'DummyNamespace', 'DummyAutoload', 'dummy_path' ], [ $this->getNamespace($headers['plugin_namespace']), $this->getAutoloadNamespace($headers['plugin_namespace']), $this->getPluginPath() ], $content), true); }
php
protected function replaceFileContent($path, array $headers) { $content = $this->files->get($path); $this->files->put($path, str_replace([ 'DummyNamespace', 'DummyAutoload', 'dummy_path' ], [ $this->getNamespace($headers['plugin_namespace']), $this->getAutoloadNamespace($headers['plugin_namespace']), $this->getPluginPath() ], $content), true); }
[ "protected", "function", "replaceFileContent", "(", "$", "path", ",", "array", "$", "headers", ")", "{", "$", "content", "=", "$", "this", "->", "files", "->", "get", "(", "$", "path", ")", ";", "$", "this", "->", "files", "->", "put", "(", "$", "path", ",", "str_replace", "(", "[", "'DummyNamespace'", ",", "'DummyAutoload'", ",", "'dummy_path'", "]", ",", "[", "$", "this", "->", "getNamespace", "(", "$", "headers", "[", "'plugin_namespace'", "]", ")", ",", "$", "this", "->", "getAutoloadNamespace", "(", "$", "headers", "[", "'plugin_namespace'", "]", ")", ",", "$", "this", "->", "getPluginPath", "(", ")", "]", ",", "$", "content", ")", ",", "true", ")", ";", "}" ]
Replace file content with given headers values. @param string $path @param array $headers @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
[ "Replace", "file", "content", "with", "given", "headers", "values", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Console/PluginInstallCommand.php#L248-L260
train
themosis/framework
src/User/User.php
User.update
public function update(array $data): User { $user = wp_update_user(array_merge($data, [ 'ID' => $this->ID ])); if (is_a($user, 'WP_Error')) { throw new UserException($user->get_error_message()); } return $this; }
php
public function update(array $data): User { $user = wp_update_user(array_merge($data, [ 'ID' => $this->ID ])); if (is_a($user, 'WP_Error')) { throw new UserException($user->get_error_message()); } return $this; }
[ "public", "function", "update", "(", "array", "$", "data", ")", ":", "User", "{", "$", "user", "=", "wp_update_user", "(", "array_merge", "(", "$", "data", ",", "[", "'ID'", "=>", "$", "this", "->", "ID", "]", ")", ")", ";", "if", "(", "is_a", "(", "$", "user", ",", "'WP_Error'", ")", ")", "{", "throw", "new", "UserException", "(", "$", "user", "->", "get_error_message", "(", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Update user properties. @param array $data @throws UserException @return User
[ "Update", "user", "properties", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/User/User.php#L56-L67
train
themosis/framework
src/User/User.php
User.updateMetaData
public function updateMetaData(string $key, string $value): User { $previous = get_user_meta($this->ID, $key, true); if ($previous === $value) { return $this; } $update = update_user_meta($this->ID, $key, $value, $previous); if (false === $update) { throw new UserException("Cannot update user meta data with a key of [$key]"); } return $this; }
php
public function updateMetaData(string $key, string $value): User { $previous = get_user_meta($this->ID, $key, true); if ($previous === $value) { return $this; } $update = update_user_meta($this->ID, $key, $value, $previous); if (false === $update) { throw new UserException("Cannot update user meta data with a key of [$key]"); } return $this; }
[ "public", "function", "updateMetaData", "(", "string", "$", "key", ",", "string", "$", "value", ")", ":", "User", "{", "$", "previous", "=", "get_user_meta", "(", "$", "this", "->", "ID", ",", "$", "key", ",", "true", ")", ";", "if", "(", "$", "previous", "===", "$", "value", ")", "{", "return", "$", "this", ";", "}", "$", "update", "=", "update_user_meta", "(", "$", "this", "->", "ID", ",", "$", "key", ",", "$", "value", ",", "$", "previous", ")", ";", "if", "(", "false", "===", "$", "update", ")", "{", "throw", "new", "UserException", "(", "\"Cannot update user meta data with a key of [$key]\"", ")", ";", "}", "return", "$", "this", ";", "}" ]
Update single user meta data. @param string $key @param string $value @throws UserException @return User
[ "Update", "single", "user", "meta", "data", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/User/User.php#L79-L94
train
themosis/framework
src/Core/Console/DownCommand.php
DownCommand.getDuration
protected function getDuration() { $time = $this->option('time'); return is_numeric($time) && $time > 0 ? (int) ((time() - (10 * 60)) + $time) : 'time()'; }
php
protected function getDuration() { $time = $this->option('time'); return is_numeric($time) && $time > 0 ? (int) ((time() - (10 * 60)) + $time) : 'time()'; }
[ "protected", "function", "getDuration", "(", ")", "{", "$", "time", "=", "$", "this", "->", "option", "(", "'time'", ")", ";", "return", "is_numeric", "(", "$", "time", ")", "&&", "$", "time", ">", "0", "?", "(", "int", ")", "(", "(", "time", "(", ")", "-", "(", "10", "*", "60", ")", ")", "+", "$", "time", ")", ":", "'time()'", ";", "}" ]
Return the maintenance duration. @return int|string
[ "Return", "the", "maintenance", "duration", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Console/DownCommand.php#L41-L46
train
themosis/framework
src/Forms/Fields/FieldsRepository.php
FieldsRepository.addField
public function addField(FieldTypeInterface $field, SectionInterface $group): FieldsRepositoryInterface { // We store all fields together // as well as per group. On each form, // there is a "default" group defined where // all fields are attached to. A user can specify // a form group to the passed options on the "add" // method of the FormBuilder instance. $this->fields[$field->getBaseName()] = $field; $this->groups[$group->getId()] = $group; return $this; }
php
public function addField(FieldTypeInterface $field, SectionInterface $group): FieldsRepositoryInterface { // We store all fields together // as well as per group. On each form, // there is a "default" group defined where // all fields are attached to. A user can specify // a form group to the passed options on the "add" // method of the FormBuilder instance. $this->fields[$field->getBaseName()] = $field; $this->groups[$group->getId()] = $group; return $this; }
[ "public", "function", "addField", "(", "FieldTypeInterface", "$", "field", ",", "SectionInterface", "$", "group", ")", ":", "FieldsRepositoryInterface", "{", "// We store all fields together", "// as well as per group. On each form,", "// there is a \"default\" group defined where", "// all fields are attached to. A user can specify", "// a form group to the passed options on the \"add\"", "// method of the FormBuilder instance.", "$", "this", "->", "fields", "[", "$", "field", "->", "getBaseName", "(", ")", "]", "=", "$", "field", ";", "$", "this", "->", "groups", "[", "$", "group", "->", "getId", "(", ")", "]", "=", "$", "group", ";", "return", "$", "this", ";", "}" ]
Add a field to the form instance. @param FieldTypeInterface $field @param SectionInterface $group @return FieldsRepositoryInterface
[ "Add", "a", "field", "to", "the", "form", "instance", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Fields/FieldsRepository.php#L41-L53
train
themosis/framework
src/Forms/Fields/FieldsRepository.php
FieldsRepository.getField
public function getField(string $name = '', string $group = 'default') { /** @var SectionInterface $section */ $section = $this->groups[$group]; $foundItems = array_filter($section->getItems(), function (FieldTypeInterface $item) use ($name) { return $name === $item->getBaseName(); }); return ! empty($foundItems) ? array_shift($foundItems) : []; }
php
public function getField(string $name = '', string $group = 'default') { /** @var SectionInterface $section */ $section = $this->groups[$group]; $foundItems = array_filter($section->getItems(), function (FieldTypeInterface $item) use ($name) { return $name === $item->getBaseName(); }); return ! empty($foundItems) ? array_shift($foundItems) : []; }
[ "public", "function", "getField", "(", "string", "$", "name", "=", "''", ",", "string", "$", "group", "=", "'default'", ")", "{", "/** @var SectionInterface $section */", "$", "section", "=", "$", "this", "->", "groups", "[", "$", "group", "]", ";", "$", "foundItems", "=", "array_filter", "(", "$", "section", "->", "getItems", "(", ")", ",", "function", "(", "FieldTypeInterface", "$", "item", ")", "use", "(", "$", "name", ")", "{", "return", "$", "name", "===", "$", "item", "->", "getBaseName", "(", ")", ";", "}", ")", ";", "return", "!", "empty", "(", "$", "foundItems", ")", "?", "array_shift", "(", "$", "foundItems", ")", ":", "[", "]", ";", "}" ]
Return the defined field instance based on its basename property. If not set, return all fields from the "default" group. @param string $name @param string $group @return FieldTypeInterface|FieldTypeInterface[]|array
[ "Return", "the", "defined", "field", "instance", "based", "on", "its", "basename", "property", ".", "If", "not", "set", "return", "all", "fields", "from", "the", "default", "group", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Fields/FieldsRepository.php#L64-L74
train
themosis/framework
src/Page/PageFactory.php
PageFactory.make
public function make(string $slug, string $title): PageInterface { $view = (new PageView($this->view)) ->setTheme('themosis.pages') ->setLayout('default') ->setView('page'); $page = new Page($this->action, $this->filter, $view, new PageSettingsRepository(), $this->validator); $page->setSlug($slug) ->setTitle($title) ->setMenu($title); // Store page instance within the service container. $this->view->getContainer()->instance($this->prefix.'.'.$page->getSlug(), $page); return $page; }
php
public function make(string $slug, string $title): PageInterface { $view = (new PageView($this->view)) ->setTheme('themosis.pages') ->setLayout('default') ->setView('page'); $page = new Page($this->action, $this->filter, $view, new PageSettingsRepository(), $this->validator); $page->setSlug($slug) ->setTitle($title) ->setMenu($title); // Store page instance within the service container. $this->view->getContainer()->instance($this->prefix.'.'.$page->getSlug(), $page); return $page; }
[ "public", "function", "make", "(", "string", "$", "slug", ",", "string", "$", "title", ")", ":", "PageInterface", "{", "$", "view", "=", "(", "new", "PageView", "(", "$", "this", "->", "view", ")", ")", "->", "setTheme", "(", "'themosis.pages'", ")", "->", "setLayout", "(", "'default'", ")", "->", "setView", "(", "'page'", ")", ";", "$", "page", "=", "new", "Page", "(", "$", "this", "->", "action", ",", "$", "this", "->", "filter", ",", "$", "view", ",", "new", "PageSettingsRepository", "(", ")", ",", "$", "this", "->", "validator", ")", ";", "$", "page", "->", "setSlug", "(", "$", "slug", ")", "->", "setTitle", "(", "$", "title", ")", "->", "setMenu", "(", "$", "title", ")", ";", "// Store page instance within the service container.", "$", "this", "->", "view", "->", "getContainer", "(", ")", "->", "instance", "(", "$", "this", "->", "prefix", ".", "'.'", ".", "$", "page", "->", "getSlug", "(", ")", ",", "$", "page", ")", ";", "return", "$", "page", ";", "}" ]
Make a new page instance. @param string $slug @param string $title @return PageInterface
[ "Make", "a", "new", "page", "instance", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/PageFactory.php#L55-L71
train