コード例 #1
0
ファイル: PDOFactoryTest.php プロジェクト: alfmel/cougar
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     # Set up the encryption parameters
     Arc4::setKey("0123456789abcdeffedcba9876543210");
     Arc4::setMagic("MAGIC");
     Arc4::useCompression("true");
 }
コード例 #2
0
ファイル: Arc4Test.php プロジェクト: alfmel/cougar
 /**
  * @covers Cougar\Util\Arc4::loadParameters
  */
 public function testLoadParameters()
 {
     file_put_contents("arc4_parameters_unit_test.conf", "key = 0123456789abcdef\n" . "magic = some_value\n" . "compress = yes");
     Arc4::loadParameters("arc4_parameters_unit_test.conf");
     unlink("arc4_parameters_unit_test.conf");
     $this->assertTrue(true);
 }
コード例 #3
0
ファイル: PDOFactory.php プロジェクト: alfmel/cougar
 /**
  * Creates a new connection file with the parameters given. The username
  * and password will encoded either in ARC4 or via obfuscation. The key and
  * other pertinent values must be set up beforehand.
  *
  * @history
  * 2013.09.30:
  *   (AT)  Initial release
  * 2014.03.10:
  *   (AT)  Add support for persistent connections
  *
  * @version 2014.03.10
  * @author (AT) Alberto Trevino, Brigham Young Univ. <*****@*****.**>
  *
  * @param string $name
  *   The name of the database connection
  * @param string $environment
  *   Connection environment
  * @param string $dsn
  *   PDO DSN connection string
  * @param string $username
  *   Username
  * @param string $password
  *   Password
  * @param string $encoding
  *   Encoding to use (Arc4 or Obfuscation)
  * @param string $arc4_config_file
  *   Configuration file with ARC4 parameters
  * @param bool $persistent
  *   Whether to establish a persistent connection
  * @return string Filename of created file
  * @throws \Cougar\Exceptions\Exception
  */
 public static function createConnectionFile($name, $environment, $dsn, $username, $password, $encoding = "Arc4", $arc4_config_file = null, $persistent = false)
 {
     # Make sure we have a name
     if (!$name) {
         throw new Exception("Connection name is required");
     }
     # Come up with the filename
     if ($environment) {
         $filename = strtolower($name . "." . $environment . ".conf");
         $env = $environment;
     } else {
         $filename = strtolower($name . ".conf");
         $env = "(default)";
     }
     # Make sure we have a DSN
     if (!$dsn) {
         throw new Exception("PDO DSN is required");
     }
     # Encode the username and password
     switch ($encoding) {
         case "Arc4":
             $enc_username = Arc4::encode($username);
             $enc_password = Arc4::encode($password);
             break;
         case "Obfuscation":
             $enc_username = StringObfuscator::encode($username);
             $enc_password = StringObfuscator::encode($password);
             break;
         default:
             throw new Exception("Invalid encoding: " . $encoding);
     }
     # See if we had an ARC4 encryption file
     $arc4_config_line = "";
     if ($arc4_config_file) {
         $arc4_config_line = "arc4 = " . $arc4_config_file;
     }
     # See if the connection is persistent
     if ($persistent) {
         $persistence_string = "yes";
     } else {
         $persistence_string = "no";
     }
     # Create the contents of the file
     $file = "# Begin Database Connection File\n\n# Connection name: " . $name . "\n# Environment: " . $env . "\n\ndsn = " . $dsn . "\nusername = "******"\npassword = "******"\npersistent = " . $persistence_string . "\n" . $arc4_config_line . "\n\n# End Database connection File\n";
     # Write out the contents
     file_put_contents($filename, $file);
     # Return the filename
     return $filename;
 }