protected function getModels($module = null) { $checkModule = $module !== null; $models = []; $modelFiles = glob(Alias::get('Modules') . '/*/Models/*.php'); foreach (Alias::find('Contrib.*') as $alias) { $contribModels = glob($alias . '/*/Models/*.php'); if ($contribModels) { $modelFiles = array_merge($modelFiles, $contribModels); } } $modules = []; foreach ($modelFiles as $file) { $moduleName = basename(dirname(dirname($file))); if ($checkModule && $module == $moduleName && Mindy::app()->hasModule($moduleName) || !$checkModule && Mindy::app()->hasModule($moduleName)) { $modules[] = $moduleName; $class = str_replace('.php', '', substr($file, strpos($file, 'Modules'))); $class = str_replace('/', '\\', $class); if (is_subclass_of($class, Model::className())) { $reflectClass = new ReflectionClass($class); if ($reflectClass->isAbstract()) { continue; } $models[$class] = new $class(); } } } echo "Modules:" . PHP_EOL; echo implode(PHP_EOL, array_unique($modules)) . PHP_EOL; return $models; }
public function getDashboardClasses() { if (empty($this->dashboards)) { $path = Alias::get('application.config.dashboard') . '.php'; if (is_file($path)) { $this->dashboards = (include_once $path); } } return $this->dashboards; }
/** * @param $name * @return mixed */ public static function delete($name) { $module = Mindy::app()->getModule($name); if ($module) { $module->delete(); $path = $module->getModulePath(); } else { $path = Alias::get('Modules.' . $name); } FileHelper::removeDirectory($path); return !is_dir($path); }
protected function getSettingsModels() { $modulesPath = Alias::get('Modules'); $modules = Mindy::app()->modules; $modelsPath = []; foreach ($modules as $name => $params) { $tmpPath = $modulesPath . '/' . $name . '/Models/'; $paths = glob($tmpPath . '*Settings.php'); if (!array_key_exists($name, $modelsPath)) { $modelsPath[$name] = []; } if (is_array($paths)) { $modelsPath[$name] = array_merge($modelsPath[$name], array_map(function ($path) use($name, $tmpPath) { return 'Modules\\' . $name . '\\Models\\' . str_replace('.php', '', str_replace($tmpPath, '', $path)); }, $paths)); } } return $modelsPath; }
/** * @param $patterns * @param string $namespace * @throws Exception */ public function __construct($patterns, $namespace = '') { if (is_string($patterns)) { $tmp = Alias::get($patterns); if (!$tmp) { $tmp = $patterns; } else { $tmp .= '.php'; } if (is_file($tmp)) { $patterns = (require $tmp); } else { throw new Exception("No such urls file {$tmp}"); } if (!is_array($patterns)) { throw new Exception("Patterns must be a an array or alias to routes file: {$patterns}"); } } $this->patterns = $patterns; $this->namespace = $namespace; }
public function applyWatermark($source, $options) { if ($options && is_array($options) && isset($options['file']) && isset($options['position'])) { $file = Alias::get('www') . DIRECTORY_SEPARATOR . $options['file']; $watermark = $this->getImagine()->open($file); $position = $options['position']; $x = 0; $y = 0; $wSize = $watermark->getSize(); $sSize = $source->getSize(); $wWidth = $wSize->getWidth(); $wHeight = $wSize->getHeight(); $sWidth = $sSize->getWidth(); $sHeight = $sSize->getHeight(); $repeat = false; if (is_array($position)) { list($x, $y) = $position; } else { switch ($position) { case 'top': $x = $sWidth / 2 - $wWidth / 2; $y = 0; break; case 'bottom': $x = $sWidth / 2 - $wWidth / 2; $y = $sHeight - $wHeight; break; case 'center': $x = $sWidth / 2 - $wWidth / 2; $y = $sHeight / 2 - $wHeight / 2; break; case 'left': $x = 0; $y = $sHeight / 2 - $wHeight / 2; break; case 'right': $x = $sWidth - $wWidth; $y = $sHeight / 2 - $wHeight / 2; break; case 'top-left': $x = 0; $y = 0; break; case 'top-right': $x = $sWidth - $wWidth; $y = 0; break; case 'bottom-left': $x = 0; $y = $sHeight - $wHeight; break; case 'bottom-right': $x = $sWidth - $wWidth; $y = $sHeight - $wHeight; break; case 'repeat': $repeat = true; break; } if ($x < 0) { $x = 0; } if ($y < 0) { $y = 0; } } if ($repeat) { while ($y < $sHeight) { $appendY = $wHeight; if ($y + $appendY > $sHeight) { $appendY = $sHeight - $y; } $x = 0; while ($x < $sWidth) { $appendX = $wWidth; if ($x + $appendX > $sWidth) { $appendX = $sWidth - $x; } if ($appendY != $wHeight || $appendX != $wWidth) { $source->paste($watermark->copy()->crop(new Point(0, 0), new Box($appendX, $appendY)), new Point($x, $y)); } else { $source->paste($watermark, new Point($x, $y)); } $x += $appendX; } $y += $appendY; } } else { if ($x + $wWidth <= $sWidth && $y + $wHeight <= $sHeight) { return $source->paste($watermark, new Point($x, $y)); } } } return $source; }
protected function setUp() { parent::setUp(); $this->media = dirname(Mindy::app()->basePath) . '/media'; Alias::set('www', dirname(Mindy::app()->basePath)); }
public function actionSchemamigration($module, $model, $auto = true, $db = null) { $className = strtr("\\Modules\\{module}\\Models\\{model}", ['{module}' => ucfirst($module), '{model}' => ucfirst($model)]); if (class_exists($className) === false) { echo "Model not found in namespace: " . $className . PHP_EOL; exit(1); } $path = Alias::get('App.Modules.' . ucfirst($module) . '.Migrations'); if (!is_dir($path)) { mkdir($path); } $model = new $className(); $migration = new Migration($model, $path); $migration->setDb($db); if ($migration->hasChanges() == false) { echo "Error: " . $migration->getName() . ". No changes." . PHP_EOL; die(1); } $namespace = strtr("Modules\\{module}\\Migrations", ['{module}' => ucfirst($module)]); if ($auto) { $safeUp = $migration->getSafeUp(); $safeDown = $migration->getSafeDown(); } else { $safeUp = ''; $safeDown = ''; } if ($migration->save()) { // TODO $db $fileName = $path . DIRECTORY_SEPARATOR . $migration->getName(); $source = $this->generateTemplate($namespace, $migration->getName(), $safeUp, $safeDown); file_put_contents($fileName . '.php', $source); list(, $timestamp) = explode('_', $migration->getName()); $model = new ModelMigration(); $sync = new Sync($model); if ($sync->hasTable($model)) { $sync->create(); } echo "Migration created: " . $migration->getName() . PHP_EOL; } else { echo "Failed to save migration: " . $migration->getName() . ". No changes." . PHP_EOL; die(1); } }