public static function getFromRouter(Router $router) { $mode = $router->getMode(); $parameters = []; $path = preg_replace_callback('/\\/\\${.*}/U', function ($matches) use(&$parameters) { $parameters[] = preg_replace('/\\/|\\$|\\{|\\}/', '', $matches[0]); return ''; }, $router->getPath()); $patharr = array_merge(explode('/', $router->getBase()), explode('/', $path)); $path = array_filter(array_map(function ($p) { return \camelCase($p, true, '-'); }, $patharr)); if ($mode === Router::MOD_RESTFUL) { $request = $router->getRequest(); $method = strtoupper($_POST['_method'] ?? $request->getMethod()); $action = $router->getActionOfRestful($method); if ($action === null) { throw new \Leno\Http\Exception(501); } } else { $action = preg_replace_callback('/^[A-Z]/', function ($matches) { if (isset($matches[0])) { return strtolower($matches[0]); } }, preg_replace('/\\..*$/', '', array_pop($path))); } try { return (new self(implode('\\', $path) . 'Controller'))->setMethod($action)->setParameters($parameters); } catch (\Exception $ex) { logger()->err((string) $ex); throw new \Leno\Http\Exception(404); } }
private function generateDoc($input, $output, $namespace = "") { if (!is_dir($input)) { $this->error($input . " Is Not A Directory"); return; } $dir_handler = opendir($input); if (!is_dir($output)) { mkdir($output, 0755, true); } while ($filename = readdir($dir_handler)) { if ($filename === '.' || $filename === '..') { continue; } $pathfile = $input . '/' . $filename; if (is_dir($pathfile)) { $outputdir = $output . $filename; $namespace = implode('\\', [$namespace, camelCase($filename)]); $this->generateDoc($pathfile, $outputdir, $namespace); continue; } if (preg_match('/\\.php$/', $filename)) { $className = $namespace . '\\' . preg_replace('/\\.php$/', '', $filename); try { $doc = new ClassDoc($className); } catch (\Exception $ex) { continue; } $doc->setOutType(Out::TYPE_MD)->setOutDir($output)->setOutName($filename)->execute(); } } }
private function parseMethod($method) { if (empty($method)) { return 'Index'; } return camelCase($method); }
public static function parse($app, $schemas, $tables = "all", $exclude_meta = false) { $result = array(); foreach ($schemas as $table => $schema) { if (!$table) { continue; } if ($tables !== "all" && !in_array($table, $tables)) { continue; } $fields = array(); $ignore = array('$meta', 'company', '_trashed', '_rate'); foreach ($schema as $field => $option) { if (in_array($field, $ignore)) { continue; } $fields[$field] = self::deal_with_field_config($field, (array) $option); } $meta = $schema['$meta']; $meta['list_display'] = array(); // 处理foreignKey foreach ($meta["foreign"] as $foreign_table => $foreign_option) { $foreign_field = $foreign_option['foreign_key'] ? $foreign_option['foreign_key'] : $foreign_table . '_id'; $fields[$foreign_table] = array("map" => $foreign_field, "field" => $foreign_field, "type" => "foreign", "data_source" => $foreign_table); } // print_r($fields);exit; /* * 数据模型字段 * 会覆盖默认数据表中数据 * */ $data_model_service = D("DataModel/DataModelField", "Service"); $module = sprintf('%s.%s', lcfirst($app), lcfirst(camelCase($table))); $extra_fields = $data_model_service->get_fields_by_module($module); $efs = array(); foreach ($extra_fields as $ef) { // $fields[$ef['alias']] = array( // 'label' => $ef['label'], // 'type' => $ef['data_type'], // 'widget'=> $ef['widget'], // 'value' => $ef['default'], // 'limit' => $ef['limit'], // 'blank' => $ef['blank'] // ); $efs[] = $ef['id']; $fields[$field] = self::deal_with_field_config($ef['alias'], (array) $ef); //list_display if ($ef['list_display']) { $meta['list_display'][] = $ef['alias']; } } if ($efs) { $fields['_data_model_fields_'] = array('field' => "_data_model_fields_", 'widget' => 'hidden', 'type' => 'hidden', 'value' => implode(',', $efs), 'required' => false); } $result[$table] = $meta; $result[$table]["structure"] = reIndex($fields); } return $result; }
function prepareForExtract(array $array) { $output = array(); foreach ($array as $key => $value) { $key = preg_replace('/[^0-9a-zA-Z_ ]/', '', $key); // $key = preg_replace('/[A-Z]/', ' \\0', $key); // makes acronyms like ISI weird, $iSI rather than $isi $key = camelCase($key); if ($key === '') { continue; } if (is_numeric($key[0])) { $key = '_' . $key; } $output[$key] = $value; } return $output; }
function excelToJson() { $objPHPExcel = PHPExcel_IOFactory::load("Dragons.xlsx"); $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true); /** @var Dragon[] $dragons */ $dragons = []; $names = array_shift($sheetData); //translate column names foreach ($sheetData as $index => $array) { $sheetData[$index] = []; foreach ($array as $key => $value) { $sheetData[$index][camelCase($names[$key])] = $value; } } foreach ($sheetData as $dragonData) { $dragons[$dragonData["name"]] = new Dragon($dragonData); } file_put_contents('dragonsTemp.json', json_encode($sheetData, JSON_PRETTY_PRINT)); file_put_contents('dragon_info.json', json_encode($dragons, JSON_PRETTY_PRINT)); }
function getPhpDocForFile($fileName) { global $nClasses, $nClassesTotal; $phpdoc = ""; $file = str_replace("\r", "", str_replace("\t", " ", file_get_contents($fileName, true))); $classes = match('#\\n(?:abstract )?class (?<name>\\w+) extends .+\\{(?<content>.+)\\n\\}(\\n|$)#', $file); foreach ($classes as &$class) { $gets = match('#\\* @return (?<type>\\w+)(?: (?<comment>(?:(?!\\*/|\\* @).)+?)(?:(?!\\*/).)+|[\\s\\n]*)\\*/' . '[\\s\\n]{2,}public function (?<kind>get)(?<name>\\w+)\\((?:,? ?\\$\\w+ ?= ?[^,]+)*\\)#', $class['content']); $sets = match('#\\* @param (?<type>\\w+) \\$\\w+(?: (?<comment>(?:(?!\\*/|\\* @).)+?)(?:(?!\\*/).)+|[\\s\\n]*)\\*/' . '[\\s\\n]{2,}public function (?<kind>set)(?<name>\\w+)\\(\\$\\w+(?:, ?\\$\\w+ ?= ?[^,]+)*\\)#', $class['content']); $acrs = array_merge($gets, $sets); //print_r($acrs); continue; $props = array(); foreach ($acrs as &$acr) { $acr['name'] = camelCase($acr['name']); $acr['comment'] = trim(preg_replace('#(^|\\n)\\s+\\*\\s?#', '$1 * ', $acr['comment'])); $props[$acr['name']][$acr['kind']] = array('type' => $acr['type'], 'comment' => fixSentence($acr['comment'])); } /*foreach ($props as $propName => &$prop) // I don't like write-only props... if (!isset($prop['get'])) unset($props[$propName]);*/ if (count($props) > 0) { $phpdoc .= "\n" . $class['name'] . ":\n"; $phpdoc .= " *\n"; foreach ($props as $propName => &$prop) { $phpdoc .= ' * @'; /*if (isset($prop['get']) && isset($prop['set'])) // Few IDEs support complex syntax $phpdoc .= 'property'; elseif (isset($prop['get'])) $phpdoc .= 'property-read'; elseif (isset($prop['set'])) $phpdoc .= 'property-write';*/ $phpdoc .= 'property'; $phpdoc .= ' ' . getPropParam($prop, 'type') . " \${$propName} " . getPropParam($prop, 'comment') . "\n"; } $phpdoc .= " *\n"; $nClasses++; } $nClassesTotal++; } return $phpdoc; }
private function getEntities($entity_dir, $namespace) { if (!is_dir($entity_dir)) { $this->error($entity_dir . ' Is Not A Dir'); return; } $dir_handler = opendir($entity_dir); while ($filename = readdir($dir_handler)) { if ($filename === '.' || $filename === '..') { continue; } $pathfile = $entity_dir . '/' . $filename; if (is_dir($pathfile)) { $the_namespace = implode('\\', [$namespace, camelCase($filename)]); $this->entities += $this->getEntities($pathfile, $the_namespace); continue; } if (preg_match('/\\.php$/', $filename)) { $className = $namespace . '\\' . preg_replace('/\\.php$/', '', $filename); if (!class_exists($className)) { continue; } $re = new \ReflectionClass($className); $re->hasMethod('getTableName') && ($table = $re->getMethod('getTableName')->invoke(null)); $re->hasMethod('getAttributes') && ($attr = $re->getMethod('getAttributes')->invoke(null)); if (!($table ?? false) || !($attr ?? false)) { continue; } $this->entities[$className] = $re; $table = null; $attr = null; } } return $this->entities; }
case "winningstad": $venue = "Winningstad Theater"; break; case "world_trade_center": $venue = "World Trade Center Theater"; break; case "ifcc": $venue = "Interstate Firehouse Cultural Center"; break; default: $venue = "Imago Theater"; } /* get the $venue name */ switch ($show_type) { case "main_stage": $svg = camelCase(get_the_title()); $class = 'main-stage'; break; case "nt_live": $svg = "ntLive"; $class = 'hi-def-screening'; break; case "branagh": $svg = "btLive"; $class = 'hi-def-screening'; break; case "wild_card": $svg = "wildCard"; $class = 'wild-card'; break; case "bloody_sunday":
private function getTarget() { foreach (self::$namespaces as $namespace) { $class = preg_replace_callback('/^\\w|\\.\\w/', function ($matches) { return strtoupper(str_replace('.', '\\', $matches[0])); }, $namespace . '.' . camelCase($this->command)); if (class_exists($class)) { return new \ReflectionClass($class); } } throw new \Exception('target \'' . $this->command . '\' not exists'); }
static function create($name, $multiple) { $instance = new static(); $instance->name = camelCase($name); if ($name === "Users") { echo "asd"; } $instance->apiName = $name; $instance->multiple = $multiple; return $instance; }
public static function storeExportFile($original_filename, $file_content, $archiveFile = false, $dateShiftDates = false) { global $edoc_storage_option; ## Create the stored name of the file as it wll be stored in the file system $stored_name = date('YmdHis') . "_pid" . PROJECT_ID . "_" . generateRandomHash(6) . getFileExt($original_filename, true); $file_extension = getFileExt($original_filename); $mime_type = strtolower($file_extension) == 'csv' ? 'application/csv' : 'application/octet-stream'; // If file is UTF-8 encoded, then add BOM // Do NOT use addBOMtoUTF8() on Stata syntax file (.do) because BOM causes issues in syntax file if (strtolower($file_extension) != 'do') { $file_content = addBOMtoUTF8($file_content); } // If Gzip enabled, then gzip the file and append filename with .gz extension list($file_content, $stored_name, $gzipped) = gzip_encode_file($file_content, $stored_name); // Get file size in bytes $docs_size = strlen($file_content); // Add file to file system if ($edoc_storage_option == '0') { // Store locally $fp = fopen(EDOC_PATH . $stored_name, 'w'); if ($fp !== false && fwrite($fp, $file_content) !== false) { // Close connection fclose($fp); } else { // Send error response return false; } // Add file to S3 } elseif ($edoc_storage_option == '2') { global $amazon_s3_key, $amazon_s3_secret, $amazon_s3_bucket; $s3 = new S3($amazon_s3_key, $amazon_s3_secret, SSL); if (!$s3->putObject($file_content, $amazon_s3_bucket, $stored_name, S3::ACL_PUBLIC_READ_WRITE)) { // Send error response return false; } } else { // Store using WebDAV require_once APP_PATH_CLASSES . "WebdavClient.php"; require APP_PATH_WEBTOOLS . 'webdav/webdav_connection.php'; $wdc = new WebdavClient(); $wdc->set_server($webdav_hostname); $wdc->set_port($webdav_port); $wdc->set_ssl($webdav_ssl); $wdc->set_user($webdav_username); $wdc->set_pass($webdav_password); $wdc->set_protocol(1); // use HTTP/1.1 $wdc->set_debug(false); // enable debugging? if (!$wdc->open()) { // Send error response return false; } if (substr($webdav_path, -1) != '/') { $webdav_path .= '/'; } $http_status = $wdc->put($webdav_path . $stored_name, $file_content); $wdc->close(); } ## Add file info to edocs_metadata table // If not archiving file in File Repository, then set to be deleted in 1 hour $delete_time = $archiveFile ? "" : NOW; // Add to table $sql = "insert into redcap_edocs_metadata (stored_name, mime_type, doc_name, doc_size, file_extension, project_id, \n\t\t\t\tstored_date, delete_date, gzipped) values ('" . prep($stored_name) . "', '{$mime_type}', '" . prep($original_filename) . "', \n\t\t\t\t'" . prep($docs_size) . "', '" . prep($file_extension) . "', " . PROJECT_ID . ", '" . NOW . "', " . checkNull($delete_time) . ", {$gzipped})"; if (!db_query($sql)) { // Send error response return false; } // Get edoc_id $edoc_id = db_insert_id(); ## Add to doc_to_edoc table // Set flag if data is date shifted $dateShiftFlag = $dateShiftDates ? "DATE_SHIFT" : ""; // Set "comment" in docs table if (strtolower($file_extension) == 'csv') { $docs_comment = "Data export file created by " . USERID . " on " . date("Y-m-d-H-i-s"); } else { if ($file_extension == 'sps') { $stats_package_name = 'Spss'; } elseif ($file_extension == 'do') { $stats_package_name = 'Stata'; } else { $stats_package_name = camelCase($file_extension); } $docs_comment = "{$stats_package_name} syntax file created by " . USERID . " on " . date("Y-m-d-H-i-s"); } // Archive in redcap_docs table $sql = "INSERT INTO redcap_docs (project_id, docs_name, docs_file, docs_date, docs_size, docs_comment, docs_type, \n\t\t\t\tdocs_rights, export_file, temp) VALUES (" . PROJECT_ID . ", '" . prep($original_filename) . "', NULL, '" . TODAY . "', \n\t\t\t\t'{$docs_size}', '" . prep($docs_comment) . "', '{$mime_type}', " . checkNull($dateShiftFlag) . ", 1, \n\t\t\t\t" . checkNull($archiveFile ? "0" : "1") . ")"; if (db_query($sql)) { $docs_id = db_insert_id(); // Add to redcap_docs_to_edocs also $sql = "insert into redcap_docs_to_edocs (docs_id, doc_id) values ({$docs_id}, {$edoc_id})"; db_query($sql); } else { // Could not store in table, so remove from edocs_metadata also db_query("delete from redcap_edocs_metadata where doc_id = {$edoc_id}"); return false; } // Return successful response of docs_id from redcap_docs table return $docs_id; }
* if the result is excluded or has a query history, ignore it */ if (!$result['exclude']) { d($history); //$data_row['monitor'] = $result['record'] & 1 ? 'dianne_mattingly' : 'wendy_robertson'; $data_row['subjid'] = quote_wrap($result['record']); $data_row['usubjid'] = quote_wrap(get_single_field($result['record'], PROJECT_ID, $Proj->firstEventId, 'dm_usubjid', '')); $data_row['event'] = quote_wrap(REDCap::getEventNames(false, false, $result['event_id'])); //$data_row['field'] = quote_wrap($Proj->metadata[$field]['element_label']); //$data_row['data'] = quote_wrap(strip_tags(str_replace('<br>', ', ', $result['data_display']))); foreach ($data_array AS $key => $val) { $data_row[quote_wrap($Proj->metadata[$key]['element_label'] . " [$key]")] = quote_wrap($val); } $data_row['description'] = quote_wrap($rule_info['name']); $data_row["Queries on $field"] = quote_wrap(count($history)); $row_csv = implode(',', $data_row) . "\n"; $table_csv .= $row_csv; } } } $headers = implode(',', array_keys($data_row)) . "\n"; if (!$debug) { create_download($lang, $app_title, $userid, $headers, $user_rights, $table_csv, $clean_fields, null, $project_id, substr(camelCase($rule_info['name']), 0, 20) . "_REPORT_", $debug, $rule_info['name']); } d($headers); d($table_csv); } $timer['main_end'] = microtime(true); $init_time = benchmark_timing($timer); echo $init_time;
private function getClass($command) { return __NAMESPACE__ . '\\' . ucfirst(camelCase(basename($command))); }
public function getStub() { return camelCase($this->displayName); }
/** * Creates global variables for each of an array of key=>value pairs. Numeric * keys are prepended with an underscore like this: '_2'. * @global mixed $name A variable is made with each key and set to its value. * @param array $array The array of variables. * @param bool $overwrite Set to 'true' to allow overwriting existing values. */ function createAliases(array $array, $overwrite = false) { foreach ($array as $rawName => $tempVal) { // remove any unwanted characters $strippedName = preg_replace('/[^0-9a-zA-Z_]/', '', $rawName); // break apart any camel case into spaced strings $brokenName = preg_replace('/[A-Z]/', ' \\0', $strippedName); // rejoin all as single camel case string $name = camelCase($brokenName); // handle illegal characters if ($name === '') { // variable had no name or had no legal characters continue; } if (is_numeric($name[0])) { // variable is numeric, format to a legal name $name = '_' . $name; } // create the global variable from the legal name and set the value global ${$name}; if (!isset(${$name}) or $overwrite) { ${$name} = $tempVal; } } }
protected function minify($files) { // store the individual results into the results array $this->results = ['success' => [], 'error' => []]; // loop through the files foreach ($files as $from => $to) { if (!isset($this->minifier)) { // check filetype based on the extension $extension = strtolower(pathinfo($from, PATHINFO_EXTENSION)); // set the default minifiers based on the extension switch ($extension) { case 'png': $minifier = 'optipng'; break; case 'jpg': case 'jpeg': $minifier = 'jpegtran'; break; case 'gif': $minifier = 'gifsicle'; break; case 'svg': $minifier = 'svgo'; break; } } else { if (!in_array($this->minifier, $this->minifiers, true) && !is_callable(strtr($this->minifier, '-', '_'))) { $message = sprintf('Invalid minifier %s!', $this->minifier); return Result::error($this, $message); } $minifier = $this->minifier; } // Convert minifier name to camelCase (e.g. jpeg-recompress) $funcMinifier = camelCase($minifier); // call the minifier method which prepares the command if (is_callable($funcMinifier)) { $command = call_user_func($funcMinifier, $from, $to, $this->minifierOptions); } elseif (method_exists($this, $funcMinifier)) { $command = $this->{$funcMinifier}($from, $to); } else { $message = sprintf('Minifier method <info>%s</info> cannot be found!', $funcMinifier); return Result::error($this, $message); } // launch the command $this->printTaskInfo('Minifying {filepath} with {minifier}', ['filepath' => $from, 'minifier' => $minifier]); $result = $this->executeCommand($command); // check the return code if ($result->getExitCode() == 127) { $this->printTaskError('The {minifier} executable cannot be found', ['minifier' => $minifier]); // try to install from imagemin repository if (array_key_exists($minifier, $this->imageminRepos)) { $result = $this->installFromImagemin($minifier); if ($result instanceof Result) { if ($result->wasSuccessful()) { $this->printTaskSuccess($result->getMessage()); // retry the conversion with the downloaded executable if (is_callable($minifier)) { $command = call_user_func($minifier, $from, $to, $minifierOptions); } elseif (method_exists($this, $minifier)) { $command = $this->{$minifier}($from, $to); } // launch the command $this->printTaskInfo('Minifying {filepath} with {minifier}', ['filepath' => $from, 'minifier' => $minifier]); $result = $this->executeCommand($command); } else { $this->printTaskError($result->getMessage()); // the download was not successful return $result; } } } else { return $result; } } // check the success of the conversion if ($result->getExitCode() !== 0) { $this->results['error'][] = $from; } else { $this->results['success'][] = $from; } } }
* if the result is excluded or has a query history, ignore it */ if (!$result['exclude']) { d($history); //$data_row['monitor'] = $result['record'] & 1 ? 'dianne_mattingly' : 'wendy_robertson'; $data_row['subjid'] = quote_wrap($result['record']); $data_row['usubjid'] = quote_wrap(get_single_field($result['record'], PROJECT_ID, $Proj->firstEventId, 'dm_usubjid', '')); $data_row['event'] = quote_wrap(REDCap::getEventNames(false, false, $result['event_id'])); //$data_row['field'] = quote_wrap($Proj->metadata[$field]['element_label']); //$data_row['data'] = quote_wrap(strip_tags(str_replace('<br>', ', ', $result['data_display']))); foreach ($data_array AS $key => $val) { $data_row[quote_wrap($Proj->metadata[$key]['element_label'] . " [$key]")] = quote_wrap($val); } $data_row['description'] = quote_wrap($rule_info['name']); $data_row["Queries on $field"] = quote_wrap(count($history)); $row_csv = implode(',', $data_row) . "\n"; $table_csv .= $row_csv; } } } $headers = implode(',', array_keys($data_row)) . "\n"; if (!$debug) { create_download($lang, $app_title, $userid, $headers, $user_rights, $table_csv, '', $parent_chkd_flds, $project_id, substr(camelCase($rule_info['name']), 0, 20) . "_REPORT_", $debug, $rule_info['name']); } d($headers); d($table_csv); } $timer['main_end'] = microtime(true); $init_time = benchmark_timing($timer); echo $init_time;
} $graph->addNode($nodeName, array('label' => $nodeLabel, 'shape' => 'octagon', 'fontsize' => '8')); if (sizeof($contact->relations) > 0) { foreach ($contact->relations as $relation) { if ($relation->meetInPerson) { $colorRelation = 'black'; } else { $colorRelation = 'grey'; } if (strlen($relation->nombre) > 0) { $nodeNameRelation = camelCase($relation->nombre); $nodeLabelRelation = $relation->nombre; if (strlen($relation->empresa) > 0) { $nodeLabelRelation .= "\n" . $relation->empresa; } } elseif (strlen($relation->empresa) > 0) { $nodeNameRelation = camelCase($relation->empresa); $nodeLabelRelation = $relation->empresa; } else { $nodeNameRelation = "node{$i}"; $nodeLabelRelation = '(nada)'; } if (!$graph->hasNode($nodeNameRelation)) { $graph->addNode($nodeNameRelation, array('label' => $nodeLabelRelation)); } $graph->addEdge(array($nodeName => $nodeNameRelation), array('color' => $colorRelation)); } } $i++; } $graph->image();
// the prefix to use when constructing our #include's. $file = realpath($file); $cwd = realpath(getcwd()) . "/"; for ($i = strlen($cwd); $i >= 0; --$i) { if (strncmp($cwd, $file, $i) === 0) { $file = substr($file, $i); break; } } // Separate bar/quux/blah.idl.json into $prefix (bar/quux) and $name // (blah) for generating the includes below. If a prefix can't be // determined, we assume it is under runtime/ext. preg_match('%^(.*/)?(.*)\\.idl\\.json$%', $file, $matches); $prefix = $matches[1]; $name = $matches[2]; $ucname = $prefix ? camelCase($name) : ucfirst($name); if ($name === 'constants') { // Ignore 'cosntants.idl.json' continue; } switch ($format) { case 'ext': $path = $prefix ? "hphp/{$prefix}" : "hphp/runtime/ext/"; fwrite($f, "#include \"{$path}ext_{$name}.h\"\n"); break; } } switch ($format) { case 'ext': fwrite($f, <<<EOT