public function getCode() { $var = '$var_' . uniqid(true); $funcmap = $this->map; $functions = $this->functions; $namespace = $this->ns; $classes = $this->classes; foreach ($this->functions as $id => $function) { if (!$function->hasRules()) { $pos = array_search($id, $funcmap); unset($funcmap[$pos]); unset($functions[$id]); } } $code = Templates::get('body')->render(compact('namespace', 'funcmap', 'classes', 'body', 'name', 'var', 'functions'), true); return FixCode::fix($code); }
public function __construct(Configuration $config, Watch $watcher) { $this->config = $config; $collections = new Generate\Collections((array) $config->getModelPath(), $this); $this->fixPath($collections); $target = $config->getLoader(); $namespace = "ActiveMongo2\\Namspace" . uniqid(true); $rnd = uniqid(); $valns = $collections->getValidatorNS(); $validator = $collections->getValidator(); class_exists("agpmedia\\FileUtil\\File"); // preload class $args = compact('docs', 'namespace', 'mapper', 'indexes', 'self', 'collections', 'valns', 'rnd', 'validator'); $code = Template\Templates::get('documents')->render($args, true); if (strlen($code) >= 1024 * 1024) { File::write($target, $code); } else { File::write($target, FixCode::fix($code)); } $this->writeFileWatch($watcher, $collections); }