This article has moved to this location.
In symfony, encoded classes excluded from config_autoload_yml.php. Because when symfony found the classes and read the contents, symfony can not find the words that contain abstract class|interface, final class|interface, class (preg_match_all(‘~^\s*(?:abstract\s+|final\s+)?(?:class|interface)\s+(\w+)~mi’, $content, $classes);).
There is an easy way that can be used, although this method has some shortcomings. I’m using Symfony version 1.3beta, but in symfony 1.2 or 1.3alpha it can be applied.
Let’s get started…
- Create config_handles.yml file, and put it in project config folder (sf_root_dir/config)
config/autoload.yml:
class: mysfAutoloadConfigHandler
- Create mysfAutoloadConfigHandler class that extends sfAutoloadConfigHandler, override parseFile() function, and put it in the same folder with config_handlers.yml (sf_root_dir/config)
<?php
class mysfAutoloadConfigHandler extends sfAutoloadConfigHandler
{
static public function parseFile($path, $file, $prefix)
{
$mapping = array();
$content = file_get_contents($file);
preg_match_all('~^\s*(?:abstract\s+|final\s+)?(?:class|interface)\s+(\w+)~mi',
$content, $classes);
if (count($classes[1]) == 0)
{
if (stristr($content, 'ioncube_loader') !== FALSE)
{
$explodes = explode('/', $file);
$classphp = $explodes[count($explodes)-1];
$classnames = explode('.', $classphp);
$classname = $classnames[0];
$classes = array('', array($classname));
}
}
foreach ($classes[1] as $class)
{
$localPrefix = '';
if ($prefix)
{
// FIXME: does not work for plugins installed with a symlink
preg_match('~^'.str_replace('\*', '(.+?)', preg_quote(str_replace('/',
DIRECTORY_SEPARATOR, $path), '~')).'~', str_replace('/',
DIRECTORY_SEPARATOR, $file), $match);
if (isset($match[$prefix]))
{
$localPrefix = $match[$prefix].'/';
}
}
$mapping[$localPrefix.strtolower($class)] = $file;
}
return $mapping;
}
}
-
Edit setup() function in ProjectConfiguration.class.php file
public function setup()
{
include_once(sfConfig::get('sf_root_dir').'/config/mysfAutoloadConfigHandler.class.php');
//........
$this->enablePlugins(.....);
//
}
But, the solution i proposed above still have some disadvantages:
- Not just Class files, Helper files are also included in config_autoload_yml.php
- Class name must have the same name with file name, for example: if you have a class named A (Class A), then your file should be named A (A.class.php)
PS:
Symfony libraries, log, cache and all the files in the config folder (project config folder, application config folder and modules config folder) is left unencrypted.
hola amigo, estoy tratando de ofuscar un proyecto realizado con symfony, he tratado de hacer todo lo que antes usted menciona pero no me funciona, si tiene alguna guia que me pueda dar se lo agradecería ….
gracias …
sorry for late replay..
what kind of errors did you got?
I’m working with smfony 1.2.12, and I need to obfuscate the lib directory but when you are loading classes not found, because it is encoded, I tried to experiment with the code above but still can not find the classes, do you can suggest me?
sorry for my English
I’m working with smfony 1.2.12, and I need to obfuscate the lib directory but when you are loading classes not found, because it is encoded, I tried to experiment with the code above but still can not find the classes, do you can suggest me?
sorry for my English, thanks friend
I assume you are using ioncube encoder. If you are using another encoder, replace the word ‘ioncube_loder’.
The version of encoder that i use is ‘ioncube_loader_lin_5.2.so’ (linux version). You can get the loader from here.
Make sure, your class name has the same name with the file name. for example, if you have a class ‘myClass’ (class myClass) then your file name should be myClass.class.php
If you follow step by step above, i think there’s no problem..
I’ve been using this in my production for a few months ago, and i’m using the latest symfony 1.4.4 version now.. so far so god, and i still found no problem
If you still found some errors.. may i see your ProjectConfiguration.class.php? and which files you encoded?. You can post here or send me by email to nibsirahsieu@gmail.com.
Good luck my friend.. and i’m sorry too for my english.. 😉
Below is an example of my encoded class (it’s an actions class).
thanks friend, your solution is brilliant, and it works, my email is bambinoelkilo@gmail.com, if you need help someday you tell me, thanks
glad to know.. You are welcome and thanks you too 😉
Hi, good evening! I’m using symfony 1.4. Is the same instructions? I tried that, but it’s not working. I did how you made. Do you have an idea?
I Got It! It’s really works! Thanks!