Why do this in C #? In PHP, this is trivial. Use the token_get_all() function, and it will break the PHP file into a token stream, which you can use to finally define a list of classes and methods by writing a state machine.
Whatever you do, do not try to do it with regular expressions. It will be incredibly tiring and error prone.
Edit: There are three main possibilities for this:
- Do it in PHP. This will be the fastest (for development) and easiest option;
- Run the PHP script command line to do this or create a series of tokens that can be interpreted by the C # program. This is the next easy way:
- Use Phalanger , a PHP port in the .Net framework. This may be more manageable since it is still .Net code; or
- Use Quercus , the PHP port for the Java virtual machine.
Everything that will be connected with writing a PHP parser (a lot of work) or using really flash regular expressions, which will be an unreliable support nightmare.
To worry about the alleged "security flaws" of PHP, there are several issues:
- Any framework or technology stack can have security flaws. The fact that your administrator only allows .Net to protest effectively against Java simply indicates an irrational prejudice. I say this as a longtime Java developer: Java, .Net and PHP may have security flaws;
- You can run PHP from the command line so that it does not serve HTTP requests, which reduces the problem of security flaws to zero;
- If you are worried about internal security risks (from someone who has access to the mailbox), just limit the PHP CLI executable to only the executable only the group in which only your program is located.
cletus
source share