Home / Blogs / eZ Blog / Dumping classes

Dumping classes

Here's a little script I use when I have get the info from a class or classes:

 <?php
require 'autoload.php';
$cli = eZCLI::instance();
$script = eZScript::instance( array( 'description' => (
          "Displays Class attributes of either [CLASS] or all classes" ),
                                     'use-session' => false,
                                     'use-modules' => true,
                                     'use-extensions' => true ) );
$script->startup();
 
$options = $script->getOptions( "", "[class]", array() );
 
$script->initialize();
 
eZDebug::writeDebug( $options, "options" );
 
if ( count( $options['arguments'] ) >= 1 )
{
        foreach ( $options['arguments'] as $identifier ) {
                if ( is_numeric( $identifier ) ) {
                        $ContentObjectClass = eZContentClass::fetch( $identifier );
                        if (is_object($ContentObjectClass)) {
                                $identifier = $ContentObjectClass->attribute('identifier');
                        } else {
                                echo "Error: Invalid class identifier: ".$identifier."\n";
                                $script->shutdown();
                                exit();
                        }
                } 
                $classList[] = eZContentClass::fetchByIdentifier($identifier,true);
        }
} else {
        $classList = eZContentClass::fetchAllClasses();
}
 
foreach($classList as $class) {
    if (is_object($class)) {
    echo $class->attribute('id')." <--> ".$class->attribute('name')." <--> ".$class->attribute('identifier')."\n";
    $classAttributes = eZContentClass::fetchAttributes($class->attribute( 'id'),true);
    foreach ($classAttributes as $attribute) {
        echo $attribute->attribute( "id" )."|";
        echo $attribute->attribute( "name" )."|";
        echo $attribute->attribute( "identifier" )."|";
        echo $attribute->attribute( "data_type_string" );
        if ($attribute->attribute( 'is_required' ) ){
                echo "|required";
        }
        if ($attribute->attribute( 'is_searchable' ) ){
                echo "|searchable";
        }
        if ($attribute->attribute( 'is_information_collector' ) ){
                echo "|collector";
        }
        echo "\n";
    }
    } else {
        echo $class." invalid identifier, skipping.";
   }
}
$script->shutdown();
 
?>