This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » symfony projects » snipeet » table prefix and phpName in schema.xml
table prefix and phpName in schema.xml [message #53529] Thu, 05 June 2008 13:25
simo  is currently offline simo
Messages: 41
Registered: May 2008
Location: Paris
Member
Hi all,

I wrote few lines of code to remove table prefix and automatically provides phpName attribute to tables on schema.xml file, respecting the CamelCase format.

You just have to provide the prefix, the source xml file and the generated xml file (if different - not compulsory).

<?php
$prefix = 'prefix_';
$filePath = 'way\to\your\xml\file';
$fileSave = 'way\to\the\generated\xml\file'; # not compulsory



function removePrefix ($string) {
  $prefix = $GLOBALS['prefix'];

  $string = str_replace($prefix, '', $string);
  $arr = split('_', $string);
  $name = '';
  foreach($arr as $row) {
    $name .= ucfirst($row);
  }

  return $name;

}

if (file_exists($filePath)) {

  $xml =simplexml_load_file($filePath);

  foreach($xml->xpath('//table') as $item) {
    $attrs = $item->attributes();
    $phpName = removePrefix ($attrs['name']);
    $item->addAttribute('phpName', $phpName);
  }

  if(isset($fileSave) && $fileSave != '') {
    $xmlFile = $fileSave;
  } else {
    $xmlFile = $filePath;
  }
  $xml->asXML($xmlFile);

} else {
  exit('Failed to open file : '. $filePath);
}
?>


Hope i'm not re-inventing the wheel and it will be usefull to you!

I guess the message has to be switched to another category.. sorry for that.

[Updated on: Thu, 05 June 2008 13:30]

Previous Topic:Does snipeet works on sf 1.0 ?
Next Topic:RSS Feed
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software