Skip to content

Commit d9df6bd

Browse files
committed
New Table/Factory option: inclIndex (true)
1 parent a4aafa2 commit d9df6bd

5 files changed

Lines changed: 70 additions & 29 deletions

File tree

src/Debug/Framework/Laravel/LogViews.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ protected function logView(View $view)
100100
? 'blade'
101101
: \pathinfo($path, PATHINFO_EXTENSION)),
102102
));
103-
$this->viewChannel->log('view', $info, $this->viewChannel->meta('detectFiles'));
103+
$this->viewChannel->log('view', $info);
104104
}
105105

106106
/**

src/Debug/Framework/Laravel/ServiceProvider.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use bdk\ErrorHandler\Error;
2222
use Illuminate\Contracts\Http\Kernel;
2323
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
24+
use ReflectionClass;
2425

2526
/**
2627
* PhpDebugConsole
@@ -31,6 +32,7 @@ class ServiceProvider extends BaseServiceProvider
3132
protected $modelCounts = array();
3233
private $isLumen = false;
3334
private $logViews;
35+
private $logDb;
3436

3537
/**
3638
* Register services.
@@ -103,16 +105,18 @@ public function onOutput()
103105
'nested' => false,
104106
);
105107
$debug = $this->debug->getChannel($channelKey, $channelOptions);
106-
$tableInfoRows = array();
107-
$modelCounts = $this->buildModelCountTable($tableInfoRows);
108+
$modelCounts = $this->buildModelCountTable();
108109
$debug->table('Model Usage', $modelCounts, $debug->meta(array(
109-
'columnLabels' => array(
110-
\bdk\Table\Factory::KEY_INDEX => 'model',
111-
\bdk\Table\Factory::KEY_SCALAR => 'count',
110+
'columnMeta' => array(
111+
'model' => array(
112+
'attribs' => array(
113+
'scope' => 'row',
114+
),
115+
'tagName' => 'th',
116+
),
112117
),
113-
'detectFiles' => true,
114-
'sortable' => true,
115-
'totalCols' => [\bdk\Table\Factory::KEY_SCALAR],
118+
'inclIndex' => false,
119+
'totalCols' => ['count'],
116120
)));
117121
}
118122

@@ -132,25 +136,22 @@ public function shouldCollect($name, $default = false)
132136
/**
133137
* Process the stored model counts for outputting as table
134138
*
135-
* @param array $tableInfoRows gets updated with tableInfo.rows for table
136-
*
137139
* @return array
138140
*/
139-
private function buildModelCountTable(&$tableInfoRows)
141+
private function buildModelCountTable()
140142
{
141143
$modelCounts = array();
142-
$tableInfoRows = array();
143144
foreach ($this->modelCounts as $class => $count) {
144-
$ref = new \ReflectionClass($class);
145-
$modelCounts[] = $count;
146-
$tableInfoRows[] = array(
147-
'key' => $this->debug->abstracter->crateWithVals($class, array(
145+
$ref = new ReflectionClass($class);
146+
$modelCounts[] = array(
147+
'model' => $this->debug->abstracter->crateWithVals($class, array(
148148
'attribs' => array(
149149
'data-file' => $ref->getFileName(),
150150
),
151151
'type' => Type::TYPE_IDENTIFIER,
152152
'typeMore' => Type::TYPE_IDENTIFIER_CLASSNAME,
153153
)),
154+
'count' => $count,
154155
);
155156
}
156157
return $modelCounts;

src/Debug/Plugin/Method/Table.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Table implements SubscriberInterface
3636
'columnLabels' => 'option', // key => label
3737
'columnMeta' => 'option', // key => meta array
3838
'columns' => 'option', // list of keys
39+
'inclIndex' => 'option',
3940
'sortable' => 'meta',
4041
'totalCols' => 'option',
4142
];

src/Table/Factory.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Factory
3737
), // key => meta array
3838
'columns' => [], // list of keys
3939
'getValInfo' => null, // callable to get type info
40+
'inclIndex' => true,
4041
'totalCols' => [],
4142
);
4243

@@ -181,15 +182,12 @@ private static function colKeysMerge(array $curRowKeys, array $colKeys)
181182
*/
182183
private function columnKeys()
183184
{
185+
$colsIncl = \array_filter([
186+
$this->options['inclIndex'] ? self::KEY_INDEX : null,
187+
$this->meta['haveObjectRow'] ? self::KEY_CLASS_NAME : null,
188+
]);
184189
if ($this->options['columns']) {
185-
$indexAndClassKeys = \array_filter([
186-
self::KEY_INDEX,
187-
$this->meta['haveObjectRow'] ? self::KEY_CLASS_NAME : null,
188-
]);
189-
return \array_merge(
190-
$indexAndClassKeys,
191-
$this->options['columns']
192-
);
190+
return \array_merge($colsIncl, $this->options['columns']);
193191
}
194192
$colKeys = array();
195193
foreach ($this->data as $row) {
@@ -198,10 +196,11 @@ private function columnKeys()
198196
$colKeys = self::colKeysMerge($curRowKeys, $colKeys);
199197
}
200198
}
201-
if (!$this->meta['haveObjectRow']) {
202-
$colKeys = \array_diff($colKeys, [self::KEY_CLASS_NAME]);
203-
}
204-
return $colKeys;
199+
$colsRemove = \array_diff([
200+
self::KEY_INDEX,
201+
self::KEY_CLASS_NAME,
202+
], $colsIncl);
203+
return \array_diff($colKeys, $colsRemove);
205204
}
206205

207206
/**

tests/Table/FactoryTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,4 +750,44 @@ public function testColumnConsistencyAcrossRows()
750750
self::assertCount($cellCount, $row->getCells());
751751
}
752752
}
753+
754+
/**
755+
* Test inclIndex = false option excludes index column
756+
*/
757+
public function testInclIndexFalse()
758+
{
759+
$factory = new Factory();
760+
$data = [
761+
['name' => 'John', 'age' => 30],
762+
['name' => 'Jane', 'age' => 25],
763+
];
764+
765+
$table = $factory->create($data, ['inclIndex' => false]);
766+
767+
self::assertInstanceOf(self::CLASS_TABLE, $table);
768+
769+
// Check header cells - should not include index column
770+
$header = $table->getHeader();
771+
$headerCells = $header->getCells();
772+
self::assertCount(2, $headerCells); // Only 'name' and 'age'
773+
774+
// Check that first cell is not an index column
775+
$firstCell = $headerCells[0];
776+
self::assertNotEquals('', $firstCell->getValue()); // Index column label is empty string by default
777+
778+
// Check row cells - should also not include index column
779+
$rows = $table->getRows();
780+
self::assertCount(2, $rows);
781+
782+
foreach ($rows as $row) {
783+
$cells = $row->getCells();
784+
self::assertCount(2, $cells); // Only 'name' and 'age' columns
785+
}
786+
787+
// Verify meta columns don't include KEY_INDEX
788+
$meta = $table->getMeta();
789+
$columnKeys = \array_column($meta['columns'], 'key');
790+
self::assertNotContains(Factory::KEY_INDEX, $columnKeys);
791+
}
753792
}
793+

0 commit comments

Comments
 (0)