/** * We want to establish a "fluid" API for the objects. * which is why most of these methods return $this. * * ( new Object() )->setup()->doCalculation()->update()->done(); */ public function __construct($mapper = null) { parent::init(); static::setupMetaAttributes(); static::setupModelAttributes(); $this->actual_model_attributes_table = static::$_model_attributes_table; $this->actual_meta_attributes_table = static::$_meta_attributes_table; $this->actual_model_settings = static::$_model_settings; $this->mapper = $mapper; Helpers::debug(get_called_class() . "::__construct"); }
<?php $config = array("database" => array("host" => "localhost", "name" => "toiletfinder", "username" => "root", "password" => "toiletpaper")); ini_set("display_errors", true); error_reporting(E_ALL); require "helpers.php"; Helpers::init($config);
$newProjectLower = strtolower($newProjectName); /* update MC current.project.php file */ $content = file_get_contents($cpFile); $content = str_replace($currentProject, $newProjectLower, $content); $fp = fopen($cpFile, 'w'); if ($fp) { fwrite($fp, $content); fclose($fp); } $currentProject = $newProjectLower; /* create new project config file */ $props = array(); $props['mycomponentCore'] = $modx->getOption('mc.core_path', null, $modx->getOption('core_path') . 'components/mycomponent/'); require_once $props['mycomponentCore'] . 'model/mycomponent/helpers.class.php'; $helpers = new Helpers($modx, $props); $helpers->init(); $newTpl = $helpers->getTpl('example.config.php'); if (empty($newTpl)) { $message = 'Could not find example.config.php'; break; } $newTpl = str_replace('Example', $newProjectName, $newTpl); $newTpl = str_replace('example', $newProjectLower, $newTpl); $configDir = $modx->getOption('mc.root', null, $modx->getOption('core_path') . 'components/mycomponent/') . '_build/config/'; if (!is_dir($configDir)) { $message = 'Config directory does not exist'; break; } $configFile = $configDir . $newProjectLower . '.config.php'; $fp = fopen($configFile, 'w'); if ($fp) {
public function createConfigFile() { $newProjectName = $this->get('packageName'); $newProjectLower = strtolower($newProjectName); $paths = $this->initPaths(); $props = array(); require_once $paths['mycomponentCore'] . 'model/mycomponent/helpers.class.php'; $props['mycomponentCore'] = $paths['myCore']; $helpers = new Helpers($this->xpdo, $props); $helpers->init(); //$helpers->tplPath = $paths['myTplPath'];echo $paths['myTplPath']; $newTpl = $helpers->getTpl('migxexample.config.php'); if (empty($newTpl)) { $this->set('errormessage', 'Could not find migxexample.config.php'); return false; } $newTpl = str_replace('Example', $newProjectName, $newTpl); $newTpl = str_replace('example', $newProjectLower, $newTpl); $configDir = $this->xpdo->getOption('mc.root', null, $this->xpdo->getOption('core_path') . 'components/mycomponent/') . '_build/config/'; if (!is_dir($configDir)) { $this->set('errormessage', 'Config directory does not exist'); return false; } $configFile = $configDir . $newProjectLower . '.config.php'; if (!file_exists($configFile)) { $fp = fopen($configFile, 'w'); if ($fp) { fwrite($fp, $newTpl); fclose($fp); } else { $this->set('errormessage', 'Could not open new config file'); return false; } $message = "Important! Edit the new config file before running any utilities:\n" . $configFile; $projects[$newProjectLower] = $configFile; /* update projects file */ $content = '<' . '?' . "php\n\n \$projects = " . var_export($projects, true) . ';' . "\n return \$projects;"; $fp = fopen($projectFile, 'w'); if ($fp) { fwrite($fp, $content); fclose($fp); } } return true; }