示例#1
0
 public function test_to_callable_php_file()
 {
     $data = array('A', 'B', 'C');
     $targetFile = $this->__dirData . DIRECTORY_SEPARATOR . "callable_php_file.php";
     $referenceFile = $this->__dirReferences . DIRECTORY_SEPARATOR . "callable_php_file.php";
     UtilData::to_callable_php_file($data, $targetFile);
     $this->assertFileEquals($targetFile, $referenceFile);
     $string = UtilData::to_callable_php_file($data);
     $this->assertStringEqualsFile($this->__dirReferences . DIRECTORY_SEPARATOR . "callable_php_file.php", $string);
 }
 /**
  * This method is called by the Symfony's console class.
  * @see Symfony\Component\Console\Command\Command
  * @param InputInterface $input Input interface.
  * @param OutputInterface $output Output interface.
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Load the credentials.
     $credentialsPath = $input->getOption('credentials-path');
     if (!file_exists($credentialsPath)) {
         throw new \Exception("File \"{$credentialsPath}\" does not exist.");
     }
     $credentials = (require $credentialsPath);
     // Load the public key
     $publicKeyPath = $input->getOption('public-key-path');
     $text = file_get_contents($publicKeyPath);
     if (false === $text) {
         throw new \Exception("Could not load the file that contains the public key ({$publicKeyPath}).");
     }
     $publicKey = openssl_pkey_get_public($text);
     if (false === $publicKey) {
         throw new \Exception("The given path does not contain a valid public key ({$publicKeyPath}).");
     }
     // Encode the credentials.
     $result = array();
     foreach ($credentials as $_service => $_config) {
         $encodedUser = null;
         $encodedPassword = null;
         $class = $_config['class'];
         $user = $_config['user'];
         $password = $_config['password'];
         if (false === openssl_public_encrypt($user, $encodedUser, $publicKey)) {
             throw new \Exception("An error occurred while encoding the text \"{$user}\".");
         }
         if (false === openssl_public_encrypt($password, $encodedPassword, $publicKey)) {
             throw new \Exception("An error occurred while encoding the text \"{$password}\".");
         }
         $result[$_service] = array('class' => $class, 'user' => bin2hex($encodedUser), 'password' => bin2hex($encodedPassword));
     }
     $targetFile = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'credentials.php';
     UtilData::to_callable_php_file($result, $targetFile);
 }
 /**
  * This method is called by the Symfony's console class.
  * It executes the (specific: MySql, PostgreSql...) CLI adapter.
  *
  * @param InputInterface $input Input interface.
  * @param OutputInterface $output Output interface.
  * @return bool If the execution is successful, then the method returns true.
  *         Otherwise, it returns false.
  *
  * @see \Symfony\Component\Console\Command\Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Load the configuration from a file, if required.
     $configLoaderClass = $input->getOption(CliOption::CONFIG_LOADER_CLASS_NAME);
     $parameters = [];
     // Not required in PHP... but is sucks otherwise.
     if (!is_null($configLoaderClass)) {
         /** @var \dbeurive\Backend\Cli\InterfaceConfigLoader $loader */
         $loader = new $configLoaderClass();
         $parameters = $loader->load();
     } else {
         // Get the configuration's parameters' values for the connector.
         /** @var array $_parameterSpec */
         $specificParameters = [];
         foreach ($this->__connectorParameters as $_parameterSpec) {
             $name = $_parameterSpec[InterfaceConnector::OPTION_NAME];
             $specificParameters[$name] = $input->getOption($name);
         }
         // The following options contains data used to use the API's entry points.
         $genericParameters = [DocOption::SCHEMA_PATH => $input->getOption(DocOption::SCHEMA_PATH)];
         $parameters = array_merge($genericParameters, $specificParameters);
     }
     // Check the configurations.
     $status = call_user_func("{$this->__connectorClassName}::checkConfiguration", $parameters);
     // $status = $this->_checkConfiguration($options);
     if (count($status) > 0) {
         CliWriter::echoError(implode("\n", $status));
         return false;
     }
     // Create a connector.
     /** @var \dbeurive\Backend\Cli\Adapter\Database\Connector\AbstractConnector $connector */
     $connector = new $this->__connectorClassName($parameters);
     $connector->connect();
     // Execute the schema extractor.
     $schema = $this->_getDatabaseSchema($connector);
     // Now, write the schema.
     \dbeurive\Util\UtilData::to_callable_php_file($schema, $parameters[DocOption::SCHEMA_PATH]);
     return true;
 }