Re: Re: question regarding Reflection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 02 Nov 2005 10:29:25 -0800, Manish Marathe wrote:
> ...
> My current problem is this: Below is some chunk of the scrip I am writing
> to generate test code.
> 
> include_once "Company.php";
> 
> class TestGenerator {
> 
> public function TestGenerator() {
> 
> 
> }
> public function catchReflection() {
> ...
>
> So in this script of mine I have included the Company.php above because
> the statement $classInfo = new ReflectionClass('Company'); uses it. Now
> this is just an example I have taken to see how my generator works. The
> user would use the TestGenerator something like this:
> 
> php TestGenerator.php myClass
> 
> Now is there a way that in my script I can let PHP look for a file
> myClass.php or for that matter any php file that has myClass so that I
> don't have to include it, as it is totally upto the user which file its
> gonna pass to the TestGenerator.php script to generate the test code and I

I believe it was mentioned in the other thread but just have in your
script:
  ini_set('include_path', '.');

And you script would do something like:
  require($argv[1] . '.php'); // assuming you validated argv[1]

And then you can safely do something like:
  try {
    $t = new ReflectionClass($argv[1]);
  }                                                                             
  catch(Exception $e) {
    echo "Failed trying to create {$argv[1]}\n"; 
    echo $e;
    exit();
  }

And the user runs the script with:
  php TestGenerator.php MyClass

As long as the naming convention happens to be that the class definition
must be the same as the filename (including case and without the .php of
course) this will work. Of course you could always add another argument to
your script so they can override the default include file used:

  php TestGenerator.php MyClass class.myclass.php

Where class.myclass.php is the file that defines MyClass.

HTH,

Curt.
-- 
http://news.zirzow.dyndns.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux