fwolf /
fwlib
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | $pathToRoot = '../../'; |
||
| 3 | require __DIR__ . '/' . $pathToRoot . 'config.default.php'; |
||
| 4 | require __DIR__ . '/DemoRetriever.php'; |
||
| 5 | |||
| 6 | use Fwlib\Config\GlobalConfig; |
||
| 7 | use Fwlib\Html\ListView\ListView; |
||
| 8 | use Fwlib\Test\Benchmark\Benchmark; |
||
|
0 ignored issues
–
show
|
|||
| 9 | use FwlibDemo\ListView\DemoRetriever; |
||
| 10 | |||
| 11 | /*************************************** |
||
| 12 | * Prepare benchmark |
||
| 13 | **************************************/ |
||
| 14 | $bm = new Benchmark(); |
||
| 15 | $bm->start('ListView Benchmark'); |
||
| 16 | |||
| 17 | |||
| 18 | /*************************************** |
||
| 19 | * Prepare ListView instance |
||
| 20 | **************************************/ |
||
| 21 | $listView = new ListView(); |
||
| 22 | |||
| 23 | $configs = [ |
||
| 24 | 'pageSize' => 3, |
||
| 25 | 'showTopPager' => true, |
||
| 26 | 'tdAppend' => [ |
||
| 27 | 'title' => 'nowrap="nowrap"', |
||
| 28 | 'joindate' => 'nowrap="nowrap"', |
||
| 29 | ], |
||
| 30 | ]; |
||
| 31 | $listView->setConfigs($configs); |
||
| 32 | $bm->mark('ListTable object prepared'); |
||
| 33 | |||
| 34 | |||
| 35 | /*************************************** |
||
| 36 | * Prepare db and test table |
||
| 37 | **************************************/ |
||
| 38 | $db = require __DIR__ . '/inc/prepare-db-table.php'; |
||
| 39 | $bm->mark('Db prepared and test table created'); |
||
| 40 | |||
| 41 | |||
| 42 | /*************************************** |
||
| 43 | * Use person from phpcredits() as fake name |
||
| 44 | **************************************/ |
||
| 45 | $names = require __DIR__ . '/inc/get-php-credit-names.php'; |
||
| 46 | $nameCount = count($names); |
||
| 47 | $bm->mark('Fake name grabbed'); |
||
| 48 | |||
| 49 | |||
| 50 | /*************************************** |
||
| 51 | * Prepare dummy data, write to db |
||
| 52 | **************************************/ |
||
| 53 | $headers = [ |
||
| 54 | 'uuid' => 'ID', |
||
| 55 | 'title' => 'Name', |
||
| 56 | 'age' => 'Age', |
||
| 57 | 'credit' => 'Money', |
||
| 58 | 'joindate' => 'Join Date', |
||
| 59 | ]; |
||
| 60 | $data = []; |
||
| 61 | // Casual algorithm, but solid result |
||
| 62 | $seed = 42; |
||
| 63 | View Code Duplication | for ($j = 0; $j < $nameCount; $j++) { |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 64 | $seed = round((100 + $seed) / 100); |
||
| 65 | $seed = 101 + $seed * ($j + 2); |
||
| 66 | $data[$j] = [ |
||
| 67 | 'uuid' => $j, |
||
| 68 | 'title' => $names[$j], |
||
| 69 | 'age' => $seed % 40 + 20, |
||
| 70 | 'credit' => $seed, |
||
| 71 | 'joindate' => date( |
||
| 72 | 'Y-m-d H:i:s', |
||
| 73 | strtotime( |
||
| 74 | '-' . ($seed % 30) . ' days -' . ($seed % 12) . ' hours' |
||
| 75 | ) |
||
| 76 | ) |
||
| 77 | ]; |
||
| 78 | } |
||
| 79 | |||
| 80 | // Write data to db |
||
| 81 | $db->write($tableUser, $data); |
||
| 82 | $bm->mark('Fake data written to db'); |
||
| 83 | |||
| 84 | |||
| 85 | /*************************************** |
||
| 86 | * Show list 1, head and body are all manual set. |
||
| 87 | **************************************/ |
||
| 88 | $listView->setHead($headers) |
||
| 89 | ->setRowCount($nameCount); |
||
| 90 | |||
| 91 | $page = $listView->getRequest()->getPage(); |
||
| 92 | $pageSize = $configs['pageSize']; |
||
| 93 | $rows = array_slice($data, ($page - 1) * $pageSize, $pageSize); |
||
| 94 | $listView->setBody($rows); |
||
| 95 | |||
| 96 | $html1 = $listView->getHtml(); |
||
| 97 | $bm->mark('List1 generated'); |
||
| 98 | |||
| 99 | |||
| 100 | /*************************************** |
||
| 101 | * Show list 2, data are query from db with Retriever |
||
| 102 | **************************************/ |
||
| 103 | $listView->reset() |
||
| 104 | ->setHead($headers) |
||
| 105 | ->setId(2) |
||
| 106 | ->setConfig( |
||
| 107 | 'orderBy', |
||
| 108 | [ |
||
| 109 | 'age' => 'DESC', |
||
| 110 | 'credit' => 'ASC', |
||
| 111 | ] |
||
| 112 | ); |
||
| 113 | |||
| 114 | $retriever = new DemoRetriever(); |
||
| 115 | $retriever->setDb($db) |
||
| 116 | ->setTable($tableUser); |
||
| 117 | $listView->setRetriever($retriever); |
||
| 118 | |||
| 119 | // Head need not set again |
||
| 120 | |||
| 121 | $html2 = $listView->getHtml(); |
||
| 122 | $bm->mark('List2 generated'); |
||
| 123 | |||
| 124 | |||
| 125 | /*************************************** |
||
| 126 | * Show list 3, query with Retriever and apply RowDecorator |
||
| 127 | **************************************/ |
||
| 128 | $listView->reset() |
||
| 129 | ->setHead($headers) |
||
| 130 | ->setId(3) |
||
| 131 | ->setConfig( |
||
| 132 | 'orderBy', |
||
| 133 | [ |
||
| 134 | 'age' => 'ASC', |
||
| 135 | 'credit' => 'DESC', |
||
| 136 | ] |
||
| 137 | ); |
||
| 138 | |||
| 139 | // Head need not set again |
||
| 140 | |||
| 141 | // Retriever need not set again |
||
| 142 | |||
| 143 | $listView->setRowDecorator(function($row) { |
||
| 144 | $row['credit'] = number_format(round($row['credit'])); |
||
| 145 | |||
| 146 | return $row; |
||
| 147 | }); |
||
| 148 | |||
| 149 | $html3 = $listView->getHtml(); |
||
| 150 | $bm->mark('List3 generated'); |
||
| 151 | |||
| 152 | |||
| 153 | /*************************************** |
||
| 154 | * Cleanup test db |
||
| 155 | **************************************/ |
||
| 156 | require __DIR__ . '/inc/clean-db-table.php'; |
||
| 157 | $bm->mark('Cleanup, test table dropped'); |
||
| 158 | |||
| 159 | // Required to grab js lib path |
||
| 160 | $globalConfig = GlobalConfig::getInstance(); |
||
| 161 | |||
| 162 | ?> |
||
| 163 | <!DOCTYPE HTML> |
||
| 164 | <html lang='en'> |
||
| 165 | <head> |
||
| 166 | <meta charset='utf-8' /> |
||
| 167 | <title>ListTable Demo</title> |
||
| 168 | |||
| 169 | <link rel='stylesheet' href='<?php echo $pathToRoot; ?>css/reset.css' |
||
| 170 | type='text/css' media='all' /> |
||
| 171 | <link rel='stylesheet' href='<?php echo $pathToRoot; ?>css/default.css' |
||
| 172 | type='text/css' media='all' /> |
||
| 173 | <link rel='stylesheet' href='css/list-view.css' |
||
| 174 | type='text/css' media='all' /> |
||
| 175 | |||
| 176 | <style type='text/css' media='all'> |
||
| 177 | /* Write CSS below */ |
||
| 178 | .fwlib-benchmark { |
||
| 179 | margin: auto; |
||
| 180 | width: 60%; |
||
| 181 | } |
||
| 182 | </style> |
||
| 183 | |||
| 184 | |||
| 185 | <script type="text/javascript" |
||
| 186 | src="<?php echo $globalConfig->get('lib.path.jquery'); ?>"> |
||
| 187 | </script> |
||
| 188 | |||
| 189 | |||
| 190 | </head> |
||
| 191 | <body> |
||
| 192 | |||
| 193 | <?php |
||
| 194 | echo "<h2>Simple list</h2>\n"; |
||
| 195 | echo $html1; |
||
| 196 | |||
| 197 | echo "<hr />\n"; |
||
| 198 | |||
| 199 | |||
| 200 | echo "<h2>Query data with Retriever</h2>\n"; |
||
| 201 | echo $html2; |
||
| 202 | |||
| 203 | |||
| 204 | echo "<hr />\n"; |
||
| 205 | |||
| 206 | |||
| 207 | echo "<h2>Query data with Retriever and apply RowDecorator</h2>\n"; |
||
| 208 | echo $html3; |
||
| 209 | |||
| 210 | |||
| 211 | echo "<hr />\n"; |
||
| 212 | |||
| 213 | $bm->display(); |
||
| 214 | ?> |
||
| 215 | |||
| 216 | |||
| 217 | <!-- Below js MUST place after html of list table --> |
||
| 218 | <script type="text/javascript"> |
||
| 219 | // Demo of change list view with js |
||
| 220 | (function() { |
||
| 221 | // Control of single column |
||
| 222 | $(".list-view tr > td:nth-child(2)").css("background-color", "green"); |
||
| 223 | $(".list-view tr > *:nth-child(1)").css("width", "2em"); |
||
| 224 | $(".list-view tr > *:nth-child(2)").css("width", "15em"); |
||
| 225 | |||
| 226 | // If "table-layout: fixed;" is assigned, all td width will be equal, |
||
| 227 | // except manual assigned. Auto wrap will apply to long text, but overflow |
||
| 228 | // part is visible. |
||
| 229 | $(".list-view table").css("table-layout", "fixed"); |
||
| 230 | |||
| 231 | // If "table-layout: fixed;" is not assigned, width limit works only if |
||
| 232 | // in limit of content length. |
||
| 233 | var list2 = $("#list-view-2"); |
||
| 234 | list2.find("table").css("table-layout", "auto"); |
||
| 235 | list2.find("tr > *:nth-child(2)").css("width", "5%"); |
||
| 236 | }) (); |
||
| 237 | </script> |
||
| 238 | |||
| 239 | |||
| 240 | </body> |
||
| 241 | </html> |
||
| 242 |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: