本文整理汇总了PHP中transform函数的典型用法代码示例。如果您正苦于以下问题:PHP transform函数的具体用法?PHP transform怎么用?PHP transform使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了transform函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: getFilteredEntries
public function getFilteredEntries($lastNames)
{
$entries = Entry::with('restorationType')->with('folders')->whereIn('last_name', $lastNames)->get();
//Transform
$resource = createCollection($entries, new EntryTransformer());
return transform($resource)['data'];
}
开发者ID:JennySwift,项目名称:dental,代码行数:7,代码来源:EntriesRepository.php
示例2: __construct
/**
* Change to a static constructor or not, up to you
* @param null $budgets
*/
public function __construct($budgets = NULL)
{
$this->type = Budget::TYPE_FIXED;
$this->budgets = $budgets ?: Budget::forCurrentUser()->whereType(Budget::TYPE_FIXED)->get();
$this->amount = $this->calculate('amount');
$this->remaining = $this->calculate('remaining');
$this->cumulative = $this->calculate('cumulative');
$this->spentBeforeStartingDate = $this->calculate('spentBeforeStartingDate');
$this->spentOnOrAfterStartingDate = $this->calculate('spentOnOrAfterStartingDate');
$this->receivedOnOrAfterStartingDate = $this->calculate('receivedOnOrAfterStartingDate');
//Transform budgets
$resource = createCollection($this->budgets, new BudgetTransformer());
$this->budgets = transform($resource);
}
开发者ID:JennySwift,项目名称:budget,代码行数:18,代码来源:FixedBudgetTotal.php
示例3: gb2312_to_latin
function gb2312_to_latin($string)
{
$output = "";
for ($i = 0; $i < strlen($string); $i++) {
$letter = ord(substr($string, $i, 1));
if ($letter > 160) {
$tmp = ord(substr($string, ++$i, 1));
$letter = $letter * 256 + $tmp - 65536;
// echo "%$letter%";
}
$output .= transform($letter);
}
return $output;
}
开发者ID:Peter2121,项目名称:leonardoxc,代码行数:14,代码来源:convert_gb2312.php
示例4: reverse_recurse
function reverse_recurse($string, $step = 0)
{
global $reverse, $min;
if ($string == 'e') {
if ($step < $min) {
$min = $step;
print "min: {$min}\n";
}
} else {
foreach (transform($reverse, $string) as $reversed) {
reverse_recurse($reversed, $step + 1);
}
}
}
开发者ID:MaMa,项目名称:adventofcode,代码行数:14,代码来源:day19.php
示例5: store
/**
* Insert an exercise entry.
* It can be an exercise set.
* @param Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$exercise = Exercise::find($request->get('exercise_id'));
if ($request->get('exerciseSet')) {
// We are inserting an exercise set
$quantity = $exercise->default_quantity;
$unit = Unit::find($exercise->default_unit_id);
} else {
$quantity = $request->get('quantity');
$unit = Unit::find($request->get('unit_id'));
}
$entry = new Entry(['date' => $request->get('date'), 'quantity' => $quantity]);
$entry->user()->associate(Auth::user());
$entry->exercise()->associate($exercise);
$entry->unit()->associate($unit);
$entry->save();
//Return the entries for the day
$entries = transform(createCollection($this->exerciseEntriesRepository->getEntriesForTheDay($request->get('date')), new ExerciseEntryTransformer()))['data'];
return response($entries, Response::HTTP_CREATED);
}
开发者ID:JennySwift,项目名称:health-tracker,代码行数:26,代码来源:ExerciseEntriesController.php
示例6: responseCreatedWithTransformer
/**
* Return response created code with transformed resource
* @param $resource
* @return mixed
*/
public function responseCreatedWithTransformer($resource, $transformer)
{
//Transform
$resource = createItem($resource, $transformer);
return response(transform($resource), Response::HTTP_CREATED);
/**
* @VP:
* Why do all this stuff when I could just do this:
* return response(transform($resource), Response::HTTP_CREATED);
*/
// $manager = new Manager();
// $manager->setSerializer(new DataArraySerializer);
//
// $manager->parseIncludes(request()->get('includes', []));
//
// return response()->json(
// $manager->createData($resource)->toArray(),
// Response::HTTP_CREATED
// );
}
开发者ID:JennySwift,项目名称:budget,代码行数:25,代码来源:Controller.php
示例7: main
/**
* Main functions. Just decides what mode we are in and calls the
* appropriate methods.
*/
function main()
{
global $info, $config;
$args = Console_Getopt::readPHPArgv();
if (count($args) < 2) {
print_usage_info();
}
if (substr($args[1], 0, 1) == "-" || substr($args[1], 0, 1) == "/") {
print "invalid parameter " . $args[2] . "\n";
print_usage_info();
}
if (substr($args[1], -4) == ".php") {
// mode 2: create zombie app
if (!file_exists($args[1])) {
die("config file " . $args[1] . " does not exist\n");
}
read_config_file($args[1]);
$outdir = ZOMBIE_BASE . '/../' . Horde_String::lower($config['app']);
if (is_dir($outdir) && $args[2] != "-f") {
print "Directory {$outdir} already exists.\nUse -f flag to force overwrite\n";
exit;
}
$n = $config['app'];
print "Creating Horde Application {$n} in directory " . Horde_String::lower($n) . "\n";
transform($outdir);
print "\nHorde Application '{$n}' successfully written. Where to go from here:\n" . "1) Paste content of {$n}/registry.stub to horde/config/registry.php.\n" . " After that, the {$n} should be working!\n" . "2) Replace {$n}.gif with proper application icon\n" . "3) Ensure conf.php is not world-readable as it may contain password data.\n" . "4) Start playing around and enhancing your new horde application. Enjoy!\n";
} else {
// mode 1: create config file
parse_options($args);
print "creating config file for table " . $config['table'] . "\n";
create_table_info();
enhance_info();
print "writing config file to " . $config['file'] . "\n";
dump_config_file();
}
}
开发者ID:Gomez,项目名称:horde,代码行数:40,代码来源:rampage.php
示例8: runit
function runit($title, $tx, $ty)
{
$text = explode("\n", read_from_url($title));
$ret = array();
foreach ($text as $t) {
if (trim(strtolower(substr($t, 0, 6))) == ";data:") {
$r = array();
$t = explode(";", substr($t, 6));
foreach ($t as $s) {
$set = array();
$s = explode(" ", trim($s));
foreach ($s as $part) {
$part = explode(",", $part);
$set[] = transform($part, $tx, $ty);
}
$r[] = implode(" ", $set);
}
$ret[] = ";data:" . implode(";", $r);
} else {
$ret[] = $t;
}
}
return $ret;
}
开发者ID:Tjorriemorrie,项目名称:app,代码行数:24,代码来源:fix_coordinates.php
示例9: getRecipeInfo
/**
* Get recipe contents and steps.
* Contents should include the foods that belong to the recipe,
* along with the description, quantity, and unit
* for the food when used in the recipe (from food_recipe table),
* and with the tags for the recipe.
* Redoing after refactor. Still need description, quantity, unit.
* @param $recipe
* @return array
*/
public function getRecipeInfo($recipe)
{
$recipe = transform(createItem($recipe, new RecipeWithIngredientsTransformer()))['data'];
//For some reason the units for each food aren't being added to the food
//from my IngredientTransformer, so add them here
foreach ($recipe['ingredients']['data'] as $index => $ingredient) {
$units = Food::find($ingredient['food']['data']['id'])->units;
$units = transform(createCollection($units, new UnitTransformer()));
$recipe['ingredients']['data'][$index]['food']['data']['units'] = $units;
}
return $recipe;
}
开发者ID:JennySwift,项目名称:health-tracker,代码行数:22,代码来源:RecipesRepository.php
示例10: transform
<?php
function transform($num)
{
if ($num % 3 == 0 and $num % 5 == 0) {
$num = "MaxGood";
} else {
if ($num % 3 == 0) {
$num = "Max";
} else {
if ($num % 5 == 0) {
$num = "Good";
}
}
}
return $num;
}
for ($i = 1; $i <= 100; $i++) {
echo transform($i) . ', ';
}
开发者ID:parigematria,项目名称:satu,代码行数:20,代码来源:tiga.php
示例11: getExercises
/**
* Get all exercises for the current user,
* along with their tags, default unit name
* and the name of the series each exercise belongs to.
* Order first by series name, then by step number.
* @return mixed
*/
public function getExercises()
{
$exercises = Exercise::forCurrentUser('exercises')->with('defaultUnit')->orderBy('step_number')->with('series')->with('tags')->get();
return transform(createCollection($exercises, new ExerciseTransformer()))['data'];
}
开发者ID:JennySwift,项目名称:health-tracker,代码行数:12,代码来源:ExercisesRepository.php
示例12: fopen
return 4;
case 'five':
return 5;
case 'six':
return 6;
case 'seven':
return 7;
case 'eight':
return 8;
case 'nine':
return 9;
case 'zero':
return 0;
}
}
$fh = fopen($argv[1], "r");
while (!feof($fh)) {
$numbers = fgets($fh);
$numbers = trim($numbers);
$numbers_array = explode(';', $numbers);
if (count($numbers_array) > 20) {
echo "Only 20 numbers are allowed per line";
} else {
foreach ($numbers_array as $number) {
$number = strtolower($number);
$digit = transform($number);
echo $digit;
}
}
echo "\n";
}
开发者ID:kcabading,项目名称:CodeEvalChallenges,代码行数:31,代码来源:wordtodigit.php
示例13: ejecutaConsulta
}
//comprobamos la gente a la que se le ha pasado la fecha de inscripcion
$resultado = ejecutaConsulta("select fechaadmision,correo from usuario where estado=1");
$filas = pg_numrows($resultado);
if ($filas != 0) {
$i = 0;
for ($cont = 0; $cont < $filas; $cont++) {
$correo = pg_result($resultado, $cont, 'correo');
$fechaadmision = pg_result($resultado, $cont, 'fechaadmision');
$date = date("Y-m-d G:i:s");
$admitido = transform($fechaadmision);
$hoy = transform($date);
$dias = ($hoy - $admitido) / 86400;
if ($dias > 3) {
$elementosBorrar[$i] = $correo;
$i = $i + 1;
}
}
$numelem = count($elementosBorrar);
for ($j = 0; $j < $numelem; $j++) {
$correo = $elementosBorrar[$j];
$resultado = ejecutaConsulta("Delete from usuario where correo='{$correo}';");
}
}
$hoy = date("Y-m-d G:i:s");
$ayer = transform(date("Y-m-d G:i:s"));
$ayer = $ayer - 86400;
$ayer = date("Y-m-d G:i:s", $ayer);
$resultado = ejecutaConsulta("Select count(*) from usuario where fechabaja BETWEEN '{$ayer}' and '{$hoy}' and estado=4;");
$contador = pg_result($resultado, 0, 0);
mandarCorreoContadorBaja($contador, $ayer, $hoy);
开发者ID:snake77se,项目名称:jornadasgvsig,代码行数:31,代码来源:aplicacionCron.php
示例14: __
exit;
}
$status = '';
if (isset($_FILES['templateFile']) && $_FILES['templateFile']['error'] == 0 && ($_FILES['templateFile']['type'] = 'text/xml')) {
$result = $template->ImportTemplate($_FILES['templateFile']['tmp_name']);
$status = $result["status"] == "" ? __("Template File Imported") : $result["status"] . '<a id="import_err" style="margin-left: 1em;" title="' . __("View errors") . '" href="#"><img src="images/info.png"></a>';
}
if (isset($_REQUEST['TemplateID']) && $_REQUEST['TemplateID'] > 0) {
//get template
$template->TemplateID = $_REQUEST['TemplateID'];
$template->GetTemplateByID();
$deviceList = Device::GetDevicesByTemplate($template->TemplateID);
}
if (isset($_POST['action'])) {
$template->ManufacturerID = $_POST['ManufacturerID'];
$template->Model = transform($_POST['Model']);
$template->Height = $_POST['Height'];
$template->Weight = $_POST['Weight'];
$template->Wattage = isset($_POST['Wattage']) ? $_POST['Wattage'] : 0;
$template->DeviceType = $_POST['DeviceType'];
$template->PSCount = $_POST['PSCount'];
$template->NumPorts = $_POST['NumPorts'];
$template->ShareToRepo = isset($_POST['ShareToRepo']) ? 1 : 0;
$template->KeepLocal = isset($_POST['KeepLocal']) ? 1 : 0;
$template->Notes = trim($_POST['Notes']);
$template->Notes = $template->Notes == "<br>" ? "" : $template->Notes;
$template->FrontPictureFile = $_POST['FrontPictureFile'];
$template->RearPictureFile = $_POST['RearPictureFile'];
$template->ChassisSlots = $template->DeviceType == "Chassis" ? $_POST['ChassisSlots'] : 0;
$template->RearChassisSlots = $template->DeviceType == "Chassis" ? $_POST['RearChassisSlots'] : 0;
$template->SNMPVersion = $_POST['SNMPVersion'];
开发者ID:actatux,项目名称:openDCIM,代码行数:31,代码来源:device_templates.php
示例15: getFoods
/**
* Get all foods, along with their default unit, default calories,
* and all their units.
* Also, add the calories for each food's units. Todo?
* @return mixed
*/
public function getFoods()
{
$foods = Food::forCurrentUser()->with('defaultUnit')->orderBy('foods.name', 'asc')->get();
$foods = transform(createCollection($foods, new FoodTransformer()));
return $foods['data'];
}
开发者ID:JennySwift,项目名称:health-tracker,代码行数:12,代码来源:FoodsRepository.php
示例16: transform
* and/or modify it under the terms of the Do What the Fuck You Want
* to Public License, Version 2, as published by Sam Hocevar. See
* http://www.wtfpl.net/ for more details.
*/
function transform($tbl, $tx, $ty, $sx, $sy)
{
$result = array();
foreach ($tbl as $pt) {
$result[] = array($pt[0] * $sx + $tx, $pt[1] * $sy + $ty);
}
return $result;
}
if (php_sapi_name() != "cli") {
die("You have to run this program with php-cli!\n");
}
$canvas = caca_create_canvas(0, 0);
$display = caca_create_display($canvas);
if (!$display) {
die("Error while attaching canvas to display\n");
}
$tbl = array(array(5, 2), array(15, 2), array(20, 4), array(25, 2), array(34, 2), array(37, 4), array(36, 9), array(20, 16), array(3, 9), array(2, 4), array(5, 2));
for ($i = 0; $i < 10; $i++) {
caca_set_color_ansi($canvas, 1 + ($color += 4) % 15, CACA_TRANSPARENT);
$scale = caca_rand(4, 10) / 10;
$translate = array(caca_rand(-5, 55), caca_rand(-2, 25));
$pts = transform($tbl, $translate[0], $translate[1], $scale, $scale);
caca_draw_thin_polyline($canvas, $pts);
}
caca_put_str($canvas, 1, 1, "Caca forever...");
caca_refresh_display($display);
caca_get_event($display, CACA_EVENT_KEY_PRESS, 5000000);
开发者ID:dns,项目名称:libcaca,代码行数:31,代码来源:polyline.php
示例17: withData
/**
* Respond with data
* Data parameter: Eloquent/Model, Eloquent/Collection, LengthAwarePaginator, Array, Assoc Array, StndObj
* TransformerClass parameter can be:
* STRING: transformer class in app/transformers
* ARRAY: for field filtering in the form of:
* ['only'=>'field1, field2, field3] OR ['except'=>'field1, field2, field3]
* @param $data
* @param null $transformerClass
* @param null $key
* @return $this
*/
public function withData($data, $transform = null, $key = null)
{
$transformerObj = transform($data);
if (isset($transform) && is_array($transform)) {
foreach ($transform as $k => $v) {
$transformerObj = $transformerObj->{$k}($v);
}
}
$data = $transformerObj->get();
if (isset($data['data'])) {
$meta = array_except($data, 'data');
$data = $data['data'];
}
if (isset($key)) {
$this->data[$key] = $data;
if (isset($meta)) {
$this->meta[$key] = $meta;
}
} else {
$this->data = $data;
if (isset($meta)) {
$this->meta = $meta;
}
}
// if( isset($data['data']) )
// {
// $this->data = $data['data'];
// $this->meta = $data['meta'];
// } else
// $this->data = $data;
return $this;
}
开发者ID:lsrur,项目名称:responder,代码行数:44,代码来源:Responder.php
示例18: fixRepeatingArguments
/**
* Fix elements that should accumulate/increment values.
*/
public function fixRepeatingArguments()
{
$either = array();
foreach (transform($this)->children as $child) {
$either[] = $child->children;
}
foreach ($either as $case) {
$counts = array();
foreach ($case as $child) {
$ser = serialize($child);
if (!isset($counts[$ser])) {
$counts[$ser] = array('cnt' => 0, 'items' => array());
}
$counts[$ser]['cnt']++;
$counts[$ser]['items'][] = $child;
}
$repeatedCases = array();
foreach ($counts as $child) {
if ($child['cnt'] > 1) {
$repeatedCases = array_merge($repeatedCases, $child['items']);
}
}
foreach ($repeatedCases as $e) {
if ($e instanceof Argument || $e instanceof Option && $e->argcount) {
if (!$e->value) {
$e->value = array();
} elseif (!is_array($e->value) && !$e->value instanceof \Traversable) {
$e->value = preg_split('/\\s+/', $e->value);
}
}
if ($e instanceof Command || $e instanceof Option && $e->argcount == 0) {
$e->value = 0;
}
}
}
return $this;
}
开发者ID:rokite,项目名称:docopt.php,代码行数:40,代码来源:docopt.php
示例19: doSql
public function doSql($strSql, $fetchType = Bd_DB::FETCH_ASSOC, $bolUseResult = false)
{
// check the env before do sql query;
//is in transaction is set outer;
if ($this->_bolIsInTransaction) {
if ($this->_intUseConnectionNum > 1) {
return false;
}
$this->_intAffectedRows = 0;
$this->_arrQueryError = array();
$this->_bolIsSqlTransformError = false;
} else {
//clear the last query;
$this->reset();
}
$this->_timer->start();
$arrSql = transform($this->_strDBName, $strSql, $this->_strConfPath, $this->_strConfFilename);
$this->_transTime += $this->_timer->stop();
if (NULL === $arrSql || $arrSql['err_no'] !== 0) {
$this->_bolIsSqlTransformError = true;
Bd_Db_RALLog::warning(RAL_LOG_SUM_FAIL, "SplitDB", $this->_strDBName, 'transform', '', $this->_timer->getTotalTime(Bd_Timer::PRECISION_MS), 0, 0, 0, $this->_transTime, '', $strSql, self::$TRANSFORM_ERRNO, self::$TRANSFORM_ERROR);
return false;
}
//some check before conneciton;
if (BD_DB_SplitDB::SPLITDB_SQL_SELECT === $arrSql['sql_type'] && $bolUseResult === true) {
Bd_Db_RALLog::warning(RAL_LOG_SUM_FAIL, "SplitDB", $this->_strDBName, 'check', '', $this->_timer->getTotalTime(Bd_Timer::PRECISION_MS), 0, 0, 0, 0, '', $strSql, self::$COMMON_ERRNO, "select should be store result");
return false;
}
$arrSplitIndex = $this->analyseSqlTransResult($arrSql, BD_DB_SplitDB::MAX_SQL_SPLIT_COUNT);
if (!$arrSplitIndex || count($arrSplitIndex) <= 0) {
Bd_Db_RALLog::warning(RAL_LOG_SUM_FAIL, "SplitDB", $this->_strDBName, 'check', '', $this->_timer->getTotalTime(Bd_Timer::PRECISION_MS), 0, 0, 0, 0, '', $strSql, self::$COMMON_ERRNO, "splitindex count error");
return false;
}
//open the connection;
if ($this->_bolIsInTransaction) {
// in transaction, only 1 split is ok;
if (count($arrSplitIndex) !== 1) {
Bd_Db_RALLog::warning(RAL_LOG_SUM_FAIL, "SplitDB", $this->_strDBName, 'check', '', $this->_timer->getTotalTime(Bd_Timer::PRECISION_MS), 0, 0, 0, 0, '', $strSql, self::$COMMON_ERRNO, "in transaction split count should be 1");
return false;
}
//in transaction , the new sql split index should be the same as the last one;
if ($this->_intUseConnectionNum === 1) {
if ($arrSplitIndex[0] !== $this->_intLastDBNum) {
Bd_Db_RALLog::warning(RAL_LOG_SUM_FAIL, "SplitDB", $this->_strDBName, 'check', '', $this->_timer->getTotalTime(Bd_Timer::PRECISION_MS), 0, 0, 0, 0, '', $strSql, self::$COMMON_ERRNO, "in transaction connect should be the same");
return false;
}
} else {
if ($arrSplitIndex[0] === -1) {
$strDBInstanceName = $this->_strDBName;
} else {
$strDBInstanceName = $this->_strDBName . $arrSplitIndex[0];
}
if (is_null($this->_arrMysql[$strDBInstanceName])) {
$ret = $this->connect($strDBInstanceName);
if (!$ret) {
$this->_arrQueryError[$strDBInstanceName] = '';
return false;
}
} else {
//echo "connection exist!\n";
}
$this->_arrMysql[$strDBInstanceName]->query('START TRANSACTION');
$this->_intLastDBNum = $arrSql['sqls'][0]['splitdb_index'];
$this->_intUseConnectionNum = 1;
}
} else {
foreach ($arrSplitIndex as $intSplitIndex) {
if ($intSplitIndex === -1) {
$strDBInstanceName = $this->_strDBName;
} else {
$strDBInstanceName = $this->_strDBName . $intSplitIndex;
}
if (is_null($this->_arrMysql[$strDBInstanceName])) {
$ret = $this->connect($strDBInstanceName);
if (!$ret) {
$this->_arrQueryError[$strDBInstanceName] = '';
break;
}
} else {
//echo "connection exist!\n";
}
$this->_intUseConnectionNum++;
}
if ($this->_intUseConnectionNum !== count($arrSplitIndex)) {
$this->_intUseConnectionNum = 0;
return false;
}
if ($this->_intUseConnectionNum === 1) {
$this->_intLastDBNum = $arrSplitIndex[0];
}
}
//build result
switch ($fetchType) {
case Bd_DB::FETCH_OBJ:
$ret = new Bd_Db_SplitDBResult();
break;
case Bd_DB::FETCH_ASSOC:
$ret = array();
break;
case Bd_DB::FETCH_ROW:
//.........这里部分代码省略.........
开发者ID:net900621,项目名称:test,代码行数:101,代码来源:SplitDB.php
示例20: index
/**
*
* @param Request $request
* @return mixed
*/
public function index(Request $request)
{
$typing = '%' . $request->get('typing') . '%';
$matches = Journal::where('user_id', Auth::user()->id)->where('text', 'LIKE', $typing)->orderBy('date', 'desc')->get();
return transform(createCollection($matches, new JournalTransformer()));
}
开发者ID:JennySwift,项目名称:health-tracker,代码行数:11,代码来源:JournalController.php
注:本文中的transform函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论