/**
  * Magic call
  *
  * @param string $method
  * @param array  $args
  *
  * @return mixed|object
  * @throws BadMethodCallException
  * @throws Exception
  */
 public function __call($method, $args)
 {
     if (stripos($method, 'get', 0) !== false) {
         return $this->getContainer()->get(Inflection::underscore(substr($method, 3)), $args);
     } else {
         throw new BadMethodCallException(sprintf('Method "%s" does not exist.', $method));
     }
 }
Exemplo n.º 2
0
 /**
  * Cli method
  *
  * @param CLImate $climate
  *
  * @throws \Rad\Core\Exception\MissingBundleException
  */
 public function cliMethod(CLImate $climate)
 {
     $sqlDir = VAR_DIR . DS . 'cake_orm' . DS . 'sql';
     if (!is_dir($sqlDir)) {
         mkdir($sqlDir, 0777, true);
     }
     $sql = [];
     foreach (Bundles::getLoaded() as $bundle) {
         $climate->backgroundLightGray()->info(sprintf('Bundle %s ...', $bundle));
         $path = Bundles::getPath($bundle);
         $sqlFilename = Inflection::underscore($bundle) . '.sql';
         $schemaPath = $path . DS . 'Resource' . DS . 'config' . DS . 'schema.xml';
         if (!is_file($schemaPath)) {
             $climate->lightRed(sprintf('File "%s" does not exists.', $schemaPath));
             $climate->br(2);
             continue;
         }
         $domDocument = new DOMDocument();
         $domDocument->load($schemaPath);
         $xpath = new DOMXPath($domDocument);
         $tables = $xpath->query('/database/table');
         /** @var DOMElement $table */
         foreach ($tables as $table) {
             $schemaTable = new Table($table->getAttribute('name'));
             $this->prepareTableRegistry($table, $bundle);
             $this->prepareColumn($table, $xpath, $schemaTable);
             $this->prepareForeignConstraint($table, $xpath, $schemaTable);
             $this->prepareUniqueConstraint($table, $xpath, $schemaTable);
             $this->preparePrimaryConstraint($table, $xpath, $schemaTable);
             $this->prepareIndex($table, $xpath, $schemaTable);
             $sql[$sqlDir . DS . $sqlFilename][] = $schemaTable->createSql(ConnectionManager::get('default'));
         }
         foreach ($sql as $file => $tablesSql) {
             $tmpSql = '';
             foreach ($tablesSql as $tableSql) {
                 $tmpSql .= implode(";\n", $tableSql);
                 $tmpSql .= "\n\n";
             }
             file_put_contents($file, $tmpSql);
             $climate->lightGray(sprintf('Create SQL file "%s".', $file));
         }
         $sql = [];
         $climate->info('Dump table registry config ...');
         $this->dumpTableRegistry($climate, $bundle);
         $climate->info('Dump model classes ...');
         $this->dumpModelClasses($climate, $bundle);
         $climate->br(2);
     }
 }
 /**
  * Create OAuth provider
  *
  * @param string $oAuthProvider
  *
  * @return AbstractOAuthProvider
  * @throws Exception
  */
 public static function create($oAuthProvider)
 {
     if (strpos($oAuthProvider, '\\') !== false) {
         if (class_exists($oAuthProvider)) {
             $providerInstance = new $oAuthProvider();
             if (!$providerInstance instanceof AbstractOAuthProvider) {
                 throw new Exception(sprintf('OAuth provider "%s" must be extend "AbstractOAuthProvider".', $oAuthProvider));
             }
             return $providerInstance;
         } else {
             throw new Exception(sprintf('OAuth provider "%s" does not exist.', $oAuthProvider));
         }
     }
     $oAuthClass = 'Rad\\OAuthentication\\Provider\\' . Inflection::camelize($oAuthProvider) . 'Provider';
     if (class_exists($oAuthClass)) {
         return new $oAuthClass();
     } else {
         throw new Exception(sprintf('OAuth provider "%s" does not exist.', $oAuthClass));
     }
 }
Exemplo n.º 4
0
 /**
  * Check bundle is loaded
  *
  * @param string $bundleName Bundle name
  *
  * @return bool
  */
 public static function isLoaded($bundleName)
 {
     $bundleName = Inflection::camelize($bundleName);
     return isset(self::$bundlesLoaded[$bundleName]);
 }