Example #1
0
 public static function buildParameters(Event $event)
 {
     ScriptHandler::buildParameters($event);
     $extras = $event->getComposer()->getPackage()->getExtra();
     if (!isset($extras['aliexpress-open'])) {
         throw new \InvalidArgumentException('The parameter handler needs to be configured through the extra.aliexpress-open setting.');
     }
     $configs = $extras['aliexpress-open'];
     if (!is_array($configs)) {
         throw new \InvalidArgumentException('The extra.aliexpress-open setting must be an array or a configuration object.');
     }
     if (!file_exists($configs['file']) && file_exists($extras['incenteev-parameters']['file'])) {
         $YamlParser = new Parser();
         $YamlValues = $YamlParser->parse(file_get_contents($extras['incenteev-parameters']['file']));
         $params = ['client_id' => $YamlValues[$extras['incenteev-parameters']['parameter-key']]['appKey'], 'redirect_uri' => 'urn:ietf:wg:oauth:2.0:oob', 'site' => 'aliexpress'];
         ksort($params);
         $paramsForSign = $params;
         array_walk($paramsForSign, function (&$value, $key) {
             $value = $key . $value;
         });
         $params[Api::SIGN_PARAM] = Sign::getSignString(implode("", $paramsForSign), $YamlValues[$extras['incenteev-parameters']['parameter-key']]['appKeySecret']);
         $link = "http://gw.api.alibaba.com/auth/authorize.htm?" . http_build_query($params, null, '&', PHP_QUERY_RFC3986);
         $event->getIO()->write('<comment>Goto ' . $link . ' and get temporary auth code.</comment>');
         $processor = new Processor($event->getIO());
         $processor->processFile($configs);
     }
 }
 /**
  * @dataProvider provideParameterHandlingTestCases
  */
 public function testParameterHandling($testCaseName)
 {
     $dataDir = __DIR__ . '/fixtures/testcases/' . $testCaseName;
     $testCase = array_replace_recursive(array('title' => 'unknown test', 'config' => array('file' => 'parameters.yml'), 'dist-file' => 'parameters.yml.dist', 'environment' => array(), 'interactive' => false), (array) Yaml::parse($dataDir . '/setup.yml'));
     $workingDir = sys_get_temp_dir() . '/incenteev_parameter_handler';
     $exists = $this->initializeTestCase($testCase, $dataDir, $workingDir);
     $message = sprintf('<info>%s the "%s" file</info>', $exists ? 'Updating' : 'Creating', $testCase['config']['file']);
     $this->io->write($message)->shouldBeCalled();
     $this->setInteractionExpectations($testCase);
     $this->processor->processFile($testCase['config']);
     $this->assertFileEquals($dataDir . '/expected.yml', $workingDir . '/' . $testCase['config']['file'], $testCase['title']);
 }
Example #3
0
 public static function buildParameters(Event $event)
 {
     $extras = $event->getComposer()->getPackage()->getExtra();
     if (!isset($extras['incenteev-parameters'])) {
         throw new \InvalidArgumentException('The parameter handler needs to be configured through the extra.incenteev-parameters setting.');
     }
     $configs = $extras['incenteev-parameters'];
     if (!is_array($configs)) {
         throw new \InvalidArgumentException('The extra.incenteev-parameters setting must be an array or a configuration object.');
     }
     if (array_keys($configs) !== range(0, count($configs) - 1)) {
         $configs = array($configs);
     }
     $processor = new Processor($event->getIO());
     foreach ($configs as $config) {
         if (!is_array($config)) {
             throw new \InvalidArgumentException('The extra.incenteev-parameters setting must be an array of configuration objects.');
         }
         $processor->processFile($config);
     }
 }
Example #4
0
 public static function postCreateProjectInstall(Event $event)
 {
     //        echo "Would you like to start the configuration process? [yes]: ";
     $stream = new cli\Streams();
     // Set currently working directory to root
     chdir(__DIR__ . "/../");
     $io = $event->getIO();
     self::outSolidGreen('Verifying the "config/parameters.yml" file');
     if (file_exists("config/parameters.yml")) {
         self::outSolidGreen('The file "config/parameters.yml" already exists');
         return 0;
     }
     if (!$io->isInteractive()) {
         self::outInBox(self::BG_YELLOW, self::COLOR_BLACK, [[["Warning!", self::STYLE_BRIGHT . self::STYLE_UNDERLINE], "You cannot use this application without the", ["'config/parameters.yml'", self::COLOR_GREEN_BRIGHT], "file."], ["You will have to create the", ["'config/parameters.yml'", self::COLOR_GREEN_BRIGHT], "file manually."], ["You may create one by cloning the", ["'config/parameters.yml.sample'", self::COLOR_GREEN_BRIGHT], "file, and changing the value correspondingly."], ["Without it, the application will not work."]]);
         return 0;
     }
     //set environment variable
     putenv("SLIM_API_SECRET=" . self::generateSecret(1));
     // Create the parameter file
     $processor = new Processor($io);
     $processor->processFile(["file" => "config/parameters.yml", "dist-file" => "config/parameters.yml.sample", "env-map" => ["auth.secret" => "SLIM_API_SECRET"]]);
     //remove environment variable
     putenv("SLIM_API_SECRET");
     //TODO: Create user table and insert a user from input
     //        $result = copy("config/parameters.yml.sample", "config/parameters__.yml");
     //
     //        if ( !$result ) {
     //            self::outInBox(self::BG_RED, self::COLOR_GREY_BRIGHT, [
     //                [["ERROR!",self::STYLE_BRIGHT.self::COLOR_BLACK_BRIGHT]],
     //                ["Error occurred when the process tried to create the 'config/parameters.yml' file."],
     //                ["Make sure the directory 'config' is writable and try again."],
     //            ]);
     //            return 1;
     //        }
     //        echo "'config/parameter.yml' file has been generated successfully.\n" .
     //            "You can now start your using the API. Just make sure your web server points to '" . getcwd() . "/public' path.\n" .
     //            "For more information, go to: https://github.com/slavikme/slim-api-skeleton.\n\n" .
     //            "Enjoy developing!\n\n";
     return 0;
 }