Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protected Columns #130

Open
JohnnyQ352 opened this issue Oct 14, 2024 · 1 comment
Open

Protected Columns #130

JohnnyQ352 opened this issue Oct 14, 2024 · 1 comment

Comments

@JohnnyQ352
Copy link

JohnnyQ352 commented Oct 14, 2024

I cannot read the column header or type anymore, it is protected when I use $dbf->getColumns();

I had to use Laravel ReflectionClass and do a whole loop-ta-loop to get the information. LOL

Anyway, if anyone needs a current work around here is a simple way of getting it:

$dbf = new TableReader($dir_file->getPathname());
while ($record = $dbf->nextRecord()) {
$reflectionClass = new ReflectionClass($record);
$properties = $reflectionClass->getProperties();
foreach($properties as $property) {
$property->setAccessible(true); // Make the property accessible if it's protected or private
$value = $property->getValue($record); // This gets the properties to construct the fields
// This checks that value is an object and has header as a property
if (is_object($value) && property_exists($value, 'header')) {
// $value is an object with a 'header' property
for($i=0; $i < count($value->header->columns); $i++ ){
// We do not want the info from the property named header
if($value->header->columns[$i]->name != "header"){
$fieldName = strtoupper($value->header->columns[$i]->name);
$value->header->columns[$i]->type
}
}
}
}
}

Hope this helps others for the moment.

@JohnnyQ352
Copy link
Author

JohnnyQ352 commented Oct 16, 2024

I found that this is not a problem.

I found that you created different way for obtaining the column data.

The way to do it is deep in your files and was not easy to find.

This is the way:

// Code to read table
$dbf = new TableReader($dir_file->getPathname());
$fields = $dbf->getColumns();
foreach ($fields as $field) {
echo "Field name: " . $field->getName() . "\n";
echo "Field type: " . $field->getType() . "\n";
echo "Field length: " . $field->getLength() . "\n";

/ // This is to show the data in the files fields
while ($record = $dbf->nextRecord()) {
$fieldName = $field->getName();
echo $record->$fieldName;
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant