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

Barcode content validation question #193

Open
objecttothis opened this issue Mar 11, 2024 · 2 comments
Open

Barcode content validation question #193

objecttothis opened this issue Mar 11, 2024 · 2 comments

Comments

@objecttothis
Copy link

I'm replacing some deprecated Emberlabs code and php-barcode-generator has been fantastic. I think I'm going to need to do validation for the input barcode content as it doesn't seem to be built into this library. Is data validation and graceful failure something planned for this library?

@casperbakker
Copy link
Member

Thanks for the kind words.

I don't have plans for graceful failures if validation fails. This code should do basic validation of the inputs and trough an exception if it is invalid.

What are you planning? An error message on the generated barcode? Or also exceptions but more explicit?

@objecttothis
Copy link
Author

A common experience is for us, but I'm sure other users of the open source project I'm working on is where the Barcode type is selected in the settings, but an item does not have a valid barcode of that type. It sounds like me wrapping the call in a try catch block then acting appropriately based on exceptions thrown is the way to go, but here are some things I'm looking at trying to figure out:

  • Barcode type guessing. For example, in our use, we generally want EAN13 barcodes, but occasionally an ISBN-10 is in the field and some of those end in 'x', which fails on an EAN13.
  • On failure, use a backup barcode type. For now, when an exception is thrown, I can use that to use a solid backup (like CODE128)

In the end, I suppose it makes more sense for the exception to be thrown. Currently the thrown exception does state that x is not allowed or that the check digit failed. As I'm thinking through it, I think maybe my feature request would be for a type guessing function in the library or the ability to not pass the type and have it try to guess when the type is not passed. These are all things that I can implement in my code, but I thought I'd ask before doing it.

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

No branches or pull requests

2 participants