Пример #1
0
    function generate()
    {
        $this->_preloadPaths();

        $this->class_name = AkInflector::camelize($this->class_name);

        $files = array(
        'model'=>AkInflector::toModelFilename($this->class_name),
        'unit_test'=>AK_TEST_DIR.DS.'unit'.DS.'app'.DS.'models'.DS.$this->underscored_model_name.'.php',
        'model_fixture.tpl'=>AK_TEST_DIR.DS.'fixtures'.DS.$this->model_path,
        'installer_fixture.tpl'=>AK_TEST_DIR.DS.'fixtures'.DS.$this->installer_path
        );

        $this->_template_vars = (array)$this;

        foreach ($files as $template=>$file_path){
            $this->save($file_path, $this->render($template));
        }

        $installer_path = AK_APP_DIR.DS.'installers'.DS.$this->underscored_model_name.'_installer.php';
        if(!file_exists($installer_path)){
            $this->save($installer_path, $this->render('installer'));
        }

        $unit_test_runner = AK_TEST_DIR.DS.'unit.php';
        if(!file_exists($unit_test_runner)){
            Ak::file_put_contents($unit_test_runner, file_get_contents(AK_FRAMEWORK_DIR.DS.'test'.DS.'app.php'));
        }

    }
Пример #2
0
    function cast()
    {
        $this->model_name = AkInflector::camelize($this->model_name);
        $this->model_file_path = AkInflector::toModelFilename($this->model_name);
        $this->controller_name = empty($this->controller_name) ? $this->model_name : (AkInflector::camelize($this->controller_name));
        $this->controller_file_path = AkInflector::toControllerFilename($this->controller_name);
        $this->controller_class_name = $this->controller_name.'Controller';
        $this->controller_human_name = AkInflector::humanize($this->controller_name);
        $this->helper_var_name = '$'.AkInflector::underscore($this->controller_name).'_helper';

        $this->singular_name = AkInflector::underscore($this->model_name);
        $this->plural_name = AkInflector::pluralize($this->singular_name);
        $this->singular_controller_name = AkInflector::underscore($this->controller_name);

        $this->files = array(
        'controller.php' => $this->controller_file_path,
        /**
         * @todo Implement generic functional tests
         */
        // 'functional_test.php' => AK_TEST_DIR.DS.'functional'.DS.'test_'.$this->controller_class_name.'.php',
        'helper.php' => AK_HELPERS_DIR.DS.trim($this->helper_var_name,'$').'.php',
        'layout' => AK_VIEWS_DIR.DS.'layouts'.DS.$this->singular_controller_name.'.tpl',
        'view_add' => AK_VIEWS_DIR.DS.$this->singular_controller_name.DS.'add.tpl',
        'view_destroy' => AK_VIEWS_DIR.DS.$this->singular_controller_name.DS.'destroy.tpl',
        'view_edit' => AK_VIEWS_DIR.DS.$this->singular_controller_name.DS.'edit.tpl',
        'view_listing' => AK_VIEWS_DIR.DS.$this->singular_controller_name.DS.'listing.tpl',
        'view_show' => AK_VIEWS_DIR.DS.$this->singular_controller_name.DS.'show.tpl',
        'form' => AK_VIEWS_DIR.DS.$this->singular_controller_name.DS.'_form.tpl',
        );

        $this->user_actions = array();
        foreach ((array)@$this->actions as $action){
            $this->user_actions[$action] = AK_VIEWS_DIR.DS.$this->singular_controller_name.DS.$action.'.tpl';
        }
    }
Пример #3
0
    function generate()
    {
        $this->_preloadPaths();

        $this->class_name = AkInflector::camelize($this->class_name);

        $files = array(
        'mailer'=>AkInflector::toModelFilename($this->class_name),
        'unit_test'=>AK_TEST_DIR.DS.'unit'.DS.'app'.DS.'models'.DS.$this->underscored_class_name.'.php'
        );

        foreach ($files as $template=>$file_path){
            $this->save($file_path, $this->render($template));
        }

        $mailer_views_folder = AK_VIEWS_DIR.DS.AkInflector::underscore($this->class_name);
        @Ak::make_dir($mailer_views_folder);

        foreach ($this->actions as $action){
            $this->assignVarToTemplate('action', $action);
            $path = $mailer_views_folder.DS.$action.'.tpl';
            $this->assignVarToTemplate('path', $path);
            $this->save($path, $this->render('view'));
        }
    }
Пример #4
0
    function _createNewTestingModel($test_model_name)
    {
        static $shutdown_called;
        switch ($test_model_name) {
            case 'AkTestNestedCategory':
                $model_source = '<?php
    class AkTestNestedCategory extends AkActiveRecord 
    {
        var $act_as = "nested_set";
    } 
?>';
                break;
            default:
                $model_source = '<?php class ' . $test_model_name . ' extends AkActiveRecord { } ?>';
                break;
        }
        $file_name = AkInflector::toModelFilename($test_model_name);
        if (!Ak::file_put_contents($file_name, $model_source)) {
            die('Ooops!, in order to perform this test, you must set your app/model permissions so this can script can create and delete files into/from it');
        }
        if (!in_array($file_name, get_included_files()) && !class_exists($test_model_name)) {
            include $file_name;
        } else {
            return false;
        }
        $this->_testing_models_to_delete[] = $file_name;
        if (!isset($shutdown_called)) {
            $shutdown_called = true;
            register_shutdown_function(array(&$this, '_deleteTestingModels'));
        }
        return true;
    }
Пример #5
0
 function cast()
 {
     $this->model_name = AkInflector::camelize($this->model_name);
     $this->model_file_path = AkInflector::toModelFilename($this->model_name);
     if (empty($this->actions) && !empty($this->controller_name) && strstr($this->controller_name, ',')) {
         $this->controller_name = '';
     }
     $this->controller_name = empty($this->controller_name) ? AkInflector::pluralize($this->model_name) : AkInflector::camelize($this->controller_name);
     $this->controller_file_path = AkInflector::toControllerFilename($this->controller_name);
     $this->controller_class_name = str_replace(array('/', '::'), '_', $this->controller_name . 'Controller');
     $this->controller_name = AkInflector::demodulize($this->controller_name);
     $this->controller_human_name = AkInflector::humanize($this->controller_name);
     $this->helper_name = (AkInflector::is_plural($this->controller_name) ? AkInflector::singularize($this->controller_name) : $this->controller_name) . 'Helper';
     $this->helper_var_name = '$' . AkInflector::underscore($this->helper_name);
     $this->singular_name = AkInflector::underscore($this->model_name);
     $this->plural_name = AkInflector::pluralize($this->singular_name);
     $this->singular_controller_name = AkInflector::underscore($this->controller_name);
     $this->module_preffix = AkInflector::underscore(substr($this->controller_class_name, 0, strrpos($this->controller_class_name, '_')));
     $this->module_preffix = empty($this->module_preffix) ? '' : DS . $this->module_preffix;
     $this->files = array('controller.php' => $this->controller_file_path, 'helper.php' => AK_HELPERS_DIR . $this->module_preffix . DS . trim($this->helper_var_name, '$') . '.php', 'layout' => AK_VIEWS_DIR . DS . 'layouts' . DS . $this->singular_controller_name . '.tpl', 'view_add' => AK_VIEWS_DIR . $this->module_preffix . DS . $this->singular_controller_name . DS . 'add.tpl', 'view_destroy' => AK_VIEWS_DIR . $this->module_preffix . DS . $this->singular_controller_name . DS . 'destroy.tpl', 'view_edit' => AK_VIEWS_DIR . $this->module_preffix . DS . $this->singular_controller_name . DS . 'edit.tpl', 'view_listing' => AK_VIEWS_DIR . $this->module_preffix . DS . $this->singular_controller_name . DS . 'listing.tpl', 'view_show' => AK_VIEWS_DIR . $this->module_preffix . DS . $this->singular_controller_name . DS . 'show.tpl', 'form' => AK_VIEWS_DIR . $this->module_preffix . DS . $this->singular_controller_name . DS . '_form.tpl');
     $this->user_actions = array();
     foreach ((array) @$this->actions as $action) {
         $this->user_actions[$action] = AK_VIEWS_DIR . $this->module_preffix . DS . $this->singular_controller_name . DS . $action . '.tpl';
     }
 }
Пример #6
0
 function generate()
 {
     $this->_preloadPaths();
     $this->class_name = AkInflector::camelize($this->class_name);
     $files = array('model' => AkInflector::toModelFilename($this->class_name), 'unit_test' => AK_TEST_DIR . DS . 'unit' . DS . 'app' . DS . 'models' . DS . $this->underscored_model_name . '.php', 'model_fixture.tpl' => AK_TEST_DIR . DS . 'fixtures' . DS . $this->model_path, 'installer_fixture.tpl' => AK_TEST_DIR . DS . 'fixtures' . DS . $this->installer_path);
     foreach ($files as $template => $file_path) {
         $this->save($file_path, $this->render($template));
     }
 }
Пример #7
0
 public function generate()
 {
     $this->_preloadPaths();
     $this->class_name = AkInflector::camelize($this->class_name);
     $files = array('model' => AkInflector::toModelFilename($this->class_name), 'unit_test' => AkConfig::getDir('test') . DS . 'unit' . DS . $this->test_file_name);
     if (!$this->active_document) {
         $files['installer'] = AkConfig::getDir('app_installers') . DS . $this->underscored_model_name . '_installer.php';
     }
     foreach ($files as $template => $file_path) {
         $this->save($file_path, $this->render($template));
     }
 }
Пример #8
0
    function _createNewTestingModel($test_model_name)
    {

        static $shutdown_called;
        switch ($test_model_name) {

            case 'AkTestPerson':
            $model_source =
            '<?php
    class AkTestPerson extends AkActiveRecord 
    { 
        function validate()
        {
            $this->validatesPresenceOf("first_name");            
        }
        
        function validateOnCreate()
        {
            $this->validatesAcceptanceOf("tos");
        }
        
        function validateOnUpdate()
        {
            $this->validatesPresenceOf("email");
        }
    
    } 
?>';
            break;

            default:
            $model_source = '<?php class '.$test_model_name.' extends AkActiveRecord { } ?>';
            break;
        }

        $file_name = AkInflector::toModelFilename($test_model_name);

        if(!Ak::file_put_contents($file_name,$model_source)){
            die('Ooops!, in order to perform this test, you must set your app/model permissions so this can script can create and delete files into/from it');
        }
        if(!in_array($file_name, get_included_files()) && !class_exists($test_model_name)){
            include($file_name);
        }else {
            return false;
        }
        $this->_testing_models_to_delete[] = $file_name;
        if(!isset($shutdown_called)){
            $shutdown_called = true;
            register_shutdown_function(array(&$this,'_deleteTestingModels'));
        }
        return true;
    }
Пример #9
0
 function _setupCloner()
 {
     $this->clone_setup_done = true;
     $this->class_to_clone = AkInflector::underscore($this->class_to_clone);
     $this->class_name = AkInflector::underscore($this->class_name);
     $this->clone_replacements = array(AkInflector::camelize($this->class_to_clone) . 'Controller' => AkInflector::camelize($this->class_name) . 'Controller', AkInflector::humanize(AkInflector::pluralize($this->class_to_clone)) => AkInflector::humanize(AkInflector::pluralize($this->class_name)), AkInflector::titleize(AkInflector::pluralize($this->class_to_clone)) => AkInflector::titleize(AkInflector::pluralize($this->class_name)), AkInflector::humanize($this->class_to_clone) => AkInflector::humanize($this->class_name), AkInflector::titleize($this->class_to_clone) => AkInflector::titleize($this->class_name), AkInflector::camelize(AkInflector::pluralize($this->class_to_clone)) => AkInflector::camelize(AkInflector::pluralize($this->class_name)), AkInflector::pluralize($this->class_to_clone) => AkInflector::pluralize($this->class_name), AkInflector::camelize($this->class_to_clone) => AkInflector::camelize($this->class_name), $this->class_to_clone => $this->class_name);
     //AK_VIEWS_DIR.DS.AkInflector::underscore($this->class_name).DS.$action.'.tpl'
     $this->files_to_clone = array(AkInflector::toModelFilename($this->class_to_clone) => AkInflector::toModelFilename($this->class_name), AK_TEST_DIR . DS . 'unit' . DS . 'test_' . $this->class_to_clone . '.php' => AK_TEST_DIR . DS . 'unit' . DS . 'test_' . $this->class_name . '.php', AK_TEST_DIR . DS . 'fixtures' . DS . AkInflector::tableize($this->class_to_clone) . '.yml' => AK_TEST_DIR . DS . 'fixtures' . DS . AkInflector::tableize($this->class_name) . '.yml', AkInflector::toControllerFilename($this->class_to_clone) => AkInflector::toControllerFilename($this->class_name), AK_TEST_DIR . DS . 'functional' . DS . 'test_' . AkInflector::camelize($this->class_to_clone . '_controller') . '.php' => AK_TEST_DIR . DS . 'functional' . DS . 'test_' . AkInflector::camelize($this->class_name . '_controller') . '.php', AK_HELPERS_DIR . DS . AkInflector::underscore("{$this->class_to_clone}_helper") . '.php' => AK_HELPERS_DIR . DS . AkInflector::underscore("{$this->class_name}_helper") . '.php');
     foreach ($this->_getControllerViews() as $view_file) {
         $this->files_to_clone[AK_VIEWS_DIR . DS . $this->class_to_clone . DS . $view_file . '.tpl'] = AK_VIEWS_DIR . DS . $this->class_name . DS . $view_file . '.tpl';
     }
     $this->files_to_clone[AK_VIEWS_DIR . DS . 'layouts' . DS . $this->class_to_clone . '.tpl'] = AK_VIEWS_DIR . DS . 'layouts' . DS . $this->class_name . '.tpl';
     foreach (Ak::dir(AK_APP_DIR . DS . 'locales' . DS . $this->class_to_clone, array('dirs' => false)) as $locale_file) {
         $this->files_to_clone[AK_APP_DIR . DS . 'locales' . DS . $this->class_to_clone . DS . $locale_file] = AK_APP_DIR . DS . 'locales' . DS . $this->class_name . DS . $locale_file;
     }
 }
Пример #10
0
 /**
  * Constructs the Observer
  * @param $subject the name or names of the Models to observe
  */
 function setObservedModels()
 {
     $args = func_get_args();
     $models = func_num_args() == 1 ? is_array($args[0]) ? $args[0] : array($args[0]) : $args;
     foreach ($models as $class_name) {
         /**
          * @todo use Ak::import() instead.
          */
         $class_name = AkInflector::camelize($class_name);
         if (!class_exists($class_name)) {
             require_once AkInflector::toModelFilename($class_name);
         }
         $model =& new $class_name();
         $this->observe(&$model);
     }
 }
Пример #11
0
 /**
  * Gets an array or a comma separated list of models. Then it includes its 
  * respective files and returns an array of available models.
  *
  * @return array available models
  */
 function import()
 {
     $args = func_get_args();
     $args = is_array($args[0]) ? $args[0] : (func_num_args() > 1 ? $args : Ak::stringToArray($args[0]));
     $models = array();
     foreach ($args as $arg) {
         $model_name = AkInflector::camelize($arg);
         if (class_exists($model_name)) {
             $models[] = $model_name;
             continue;
         }
         $model = AkInflector::toModelFilename($model_name);
         if (file_exists($model)) {
             $models[] = $model_name;
             include_once $model;
             continue;
         }
         // Shouldn't we trigger an user-error?: Unknown Model or could not find the Model
     }
     return $models;
 }
Пример #12
0
    /**
     * Gets an array or a comma separated list of models. Then it includes its 
     * respective files and returns an array of available models.
     *
     * @return unknown
     */
    function import()
    {
        $args = func_get_args();
        $args = is_array($args[0]) ? $args[0] : (func_num_args() > 1 ? $args : Ak::stringToArray($args[0]));
        $models = array();
        foreach ($args as $arg){
            $model_name = AkInflector::camelize($arg);
            $model = AkInflector::toModelFilename($model_name);
            if(file_exists($model)){
                $models[] = $model_name;
                include_once($model);
            }elseif (class_exists($model_name)){
                $models[] = $model_name;
            }
        }

        return $models;
    }
Пример #13
0
    /**
    * Constructs the Observer
    * @param $subject the name or names of the Models to observe
    */
    function setObservedModels ()
    {        
        $args = func_get_args();
        $models = func_num_args() == 1 ? ( is_array($args[0]) ? $args[0] : array($args[0]) ) : $args;

        foreach ($models as $class_name)
        {
            $class_name = AkInflector::camelize($class_name);
            include_once(AkInflector::toModelFilename($class_name));
            eval("\$model =& new $class_name();");
            $this->observe(&$model);
        }
    }
Пример #14
0
 public function _createJoinClass()
 {
     $options = $this->getOptions($this->association_id);
     $class_file_code = "<?php \n\n//This code was generated automatically by the active record hasAndBelongsToMany Method\n\n";
     $class_code = "class {$options['join_class_name']} extends {$options['join_class_extends']} {\n    public \$_avoidTableNameValidation = true;\n    public function {$options['join_class_name']}()\n    {\n        \$this->setModelName(\"{$options['join_class_name']}\");\n        \$attributes = (array)func_get_args();\n        \$this->setTableName('{$options['join_table']}', true, true);\n        \$this->init(\$attributes);\n    }\n}";
     $class_file_code .= $class_code . "\n\n?>";
     $join_file = AkInflector::toModelFilename($options['join_class_name']);
     if ($this->_automatically_create_join_model_files && !file_exists($join_file) && @Ak::file_put_contents($join_file, $class_file_code)) {
         require_once $join_file;
     } else {
         eval($class_code);
     }
     return class_exists($options['join_class_name']);
 }
Пример #15
0
    function _createNewTestingModel($test_model_name)
    {
        static $shutdown_called;
        switch ($test_model_name) {
            case 'AkTestObservedPerson':
                $model_source = '<?php
    class AkTestObservedPerson extends AkActiveRecord 
    { 
    } 
?>';
                break;
            case 'AkTestObservedAccount':
                $model_source = '<?php
    class AkTestObservedAccount extends AkActiveRecord 
    {
    } 
?>';
                break;
            case 'AkTestObservedPersonObserver':
                $model_source = '<?php
    class AkTestObservedPersonObserver extends AkObserver 
    {
        function update($state)
        {
            switch ($state)
            {
                case "new person created" :
                echo $state;
                break;
                default:
                break;
            }
        }
        
        function afterCreate(&$record)
        {
            echo $record->get("first_name")." has been email with account details";
            $this->logNotified($record,__FUNCTION__);
        }
        
        function afterSave(&$record){$this->logNotified($record,__FUNCTION__);}
        function afterValidationOnCreate(&$record){$this->logNotified($record,__FUNCTION__);}
        function afterValidationOnUpdate(&$record){$this->logNotified($record,__FUNCTION__);}
        function beforeSave(&$record){$this->logNotified($record,__FUNCTION__);
            if(!empty($record->city) && $record->city == "Carlet")
            {
                $record->state = "Valencia";
            }
        }
        function beforeCreate(&$record){$this->logNotified($record,__FUNCTION__); }
        function beforeValidationOnCreate(&$record){$this->logNotified($record,__FUNCTION__);}
        function beforeValidation(&$record){$this->logNotified($record,__FUNCTION__);}
        function afterValidation(&$record) {$this->logNotified($record,__FUNCTION__);}

        function logNotified(&$record, $function)
        {
            if(!isset($record->notified_observers[$function])){
                $record->notified_observers[$function] = 0;
            }
            $record->notified_observers[$function]++;
        }

    }
?>';
                break;
            case 'AkTestAuditor':
                $model_source = '<?php
    class AkTestAuditor extends AkObserver 
    { 
        function update($state)
        {
            switch ($state)
            {
                case "new person created" :
                echo $state;
                break;
                default:
                break;
            }
        }
        
        function afterCreate(&$record)
        {
            $record->audited = true;
        }

    }
?>';
                break;
            default:
                $model_source = '<?php class ' . $test_model_name . ' extends AkActiveRecord { } ?>';
                break;
        }
        $file_name = AkInflector::toModelFilename($test_model_name);
        if (!Ak::file_put_contents($file_name, $model_source)) {
            die('Ooops!, in order to perform this test, you must set your app/model permissions so this can script can create and delete files into/from it');
        }
        if (!in_array($file_name, get_included_files()) && !class_exists($test_model_name)) {
            include $file_name;
        } else {
            return false;
        }
        $this->_testing_models_to_delete[] = $file_name;
        if (!isset($shutdown_called)) {
            $shutdown_called = true;
            register_shutdown_function(array(&$this, '_deleteTestingModels'));
        }
        return true;
    }
Пример #16
0
    /**
    * Finder methods must instantiate through this method to work with the single-table inheritance model and
    * eager loading associations.
    * that makes it possible to create objects of different types from the same table.
    */
    function &instantiate($record, $set_as_new = true, $call_after_instantiate = true)
    {
        $inheritance_column = $this->getInheritanceColumn();
        if(!empty($record[$inheritance_column])){
            $inheritance_column = $record[$inheritance_column];
            $inheritance_model_name = AkInflector::camelize($inheritance_column);
            @require_once(AkInflector::toModelFilename($inheritance_model_name));
            if(!class_exists($inheritance_model_name)){
                trigger_error($this->t("The single-table inheritance mechanism failed to locate the subclass: '%class_name'. ".
                "This error is raised because the column '%column' is reserved for storing the class in case of inheritance. ".
                "Please rename this column if you didn't intend it to be used for storing the inheritance class ".
                "or overwrite #{self.to_s}.inheritance_column to use another column for that information.",
                array('%class_name'=>$inheritance_model_name, '%column'=>$this->getInheritanceColumn())),E_USER_ERROR);
            }
        }

        $model_name = isset($inheritance_model_name) ? $inheritance_model_name : $this->getModelName();
        $object =& new $model_name('attributes', $record);

        $object->_newRecord = $set_as_new;

        if ($call_after_instantiate) {
            $object->afterInstantiate();
            $object->notifyObservers('afterInstantiate');
        }
        (AK_CLI && AK_ENVIRONMENT == 'development') ? $object ->toString() : null;

        return $object;
    }
Пример #17
0
 protected function _includeOrGenerateModel($model_name)
 {
     $model_file_name = AkInflector::toModelFilename($model_name);
     if (file_exists($model_file_name)) {
         require_once $model_file_name;
     } else {
         if (class_exists($model_name)) {
             return true;
         }
         $model_source_code = "class " . $model_name . " extends ActiveRecord { }";
         $has_errors = @eval($model_source_code) === false;
         if ($has_errors) {
             trigger_error(Ak::t('Could not declare the model %modelname.', array('%modelname' => $model_name)), E_USER_ERROR);
         }
     }
 }
Пример #18
0
    function _createNewTestingModel($test_model_name)
    {

        static $shutdown_called;
        switch ($test_model_name) {
            case 'AkTestUser':
            $model_source =
            '<?php
    class AkTestUser extends AkActiveRecord 
    { 
        //var $expiresOnDataType = "date";
        function callBackFunctionCompose()
        {
            $args = func_get_arg(0); 
            return "<a href=\'mailto:{$args[\'email\']}\'>{$args[\'name\']}</a>"; 
        } 
        function callBackFunctionDecompose($email_link) 
        { 
            $results = sscanf($email_link, "<a href=\'mailto:%[^\']\'>%[^<]</a>"); 
            return array(\'email\'=>$results[0],\'name\'=>$results[1]); 
        } 
        function getPassword() 
        {
            parent::get("password", false);
            return "*********";
        }
        function setPassword($password)
        {
            parent::set("password", md5($password), false);
        }
    } 
?>';
            break;
            
            case 'AkTestComment':
            $model_source =
            '<?php class AkTestComment extends AkActiveRecord { 
            //var $belongsTo = "AkTestUser";
            //var $_inheritanceColumn = "ak_test_user_id";
            } ?>';
            break;
            
            
            case 'AkTestMember':
            $model_source =
            '<?php class AkTestMember extends AkTestUser { 
            //var $_inheritanceColumn = "ak_test_user_id";
                function AkTestMember(){
                    $this->setTableName("ak_test_members");
                    $this->init(@(array)func_get_args());
                }
            } ?>';
            break;

            default:
            $model_source = '<?php class '.$test_model_name.' extends AkActiveRecord { } ?>';
            break;
        }

        $file_name = AkInflector::toModelFilename($test_model_name);
        
        if(!Ak::file_put_contents($file_name,$model_source)){
            die('Ooops!, in order to perform this test, you must set your app/model permissions so this can script can create and delete files into/from it');
        }
        if(!in_array($file_name, get_included_files()) && !class_exists($test_model_name)){
            include($file_name);
        }else {
            return false;
        }
        $this->_testing_models_to_delete[] = $file_name;
        if(!isset($shutdown_called)){
            $shutdown_called = true;
            register_shutdown_function(array(&$this,'_deleteTestingModels'));
        }
        return true;
    }
Пример #19
0
 /**
  * Finder methods must instantiate through this method to work with the single-table inheritance model and
  * eager loading associations.
  * That makes it possible to create objects of different types from the same table.
  */
 public function &instantiate($record, $set_as_new = true, $call_after_instantiate = true)
 {
     $inheritance_column = $this->_ActiveRecord->getInheritanceColumn();
     if (!empty($record[$inheritance_column])) {
         $inheritance_column = $record[$inheritance_column];
         $inheritance_model_name = AkInflector::camelize($inheritance_column);
         @(require_once AkInflector::toModelFilename($inheritance_model_name));
         if (!class_exists($inheritance_model_name)) {
             trigger_error($this->_ActiveRecord->t("The single-table inheritance mechanism failed to locate the subclass: '%class_name'. " . "This error is raised because the column '%column' is reserved for storing the class in case of inheritance. " . "Please rename this column if you didn't intend it to be used for storing the inheritance class " . "or overwrite #{self.to_s}.inheritance_column to use another column for that information.", array('%class_name' => $inheritance_model_name, '%column' => $this->_ActiveRecord->getInheritanceColumn())) . AkDebug::getFileAndNumberTextForError(1), E_USER_ERROR);
         }
     }
     $model_name = isset($inheritance_model_name) ? $inheritance_model_name : $this->_ActiveRecord->getModelName();
     $object = new $model_name(array('init' => false));
     $object->_newRecord = $set_as_new;
     $object->setConnection($this->_ActiveRecord->getConnection());
     $object->beforeInstantiate($record);
     $object->init(array('attributes', $record));
     if ($call_after_instantiate) {
         $object->afterInstantiate();
         $object->notifyObservers('afterInstantiate');
     }
     return $object;
 }