Ejemplo n.º 1
0
 /**
  * Test case
  */
 public function testConfigReadBase()
 {
     $this->setExpectedException('Enlight_Config_Exception');
     $adapter = new Enlight_Config_Adapter_File(array('configDir' => '/fail', 'namePrefix' => 's_', 'skipExtends' => false, 'configType' => 'ini'));
     $config = new Enlight_Config('test', array('adapter' => $adapter));
     $config->setData(array('test' => true));
     $config->write();
 }
Ejemplo n.º 2
0
 /**
  * Test case
  */
 public function testConfigFileWrite()
 {
     $adapter = new Enlight_Config_Adapter_DbTable(array('automaticSerialization' => true, 'namePrefix' => 'config_', 'nameColumn' => 'name', 'db' => $this->db));
     $config = new Enlight_Config('test', array('adapter' => $adapter, 'section' => 'test', 'allowModifications' => true));
     $config->set('test', 1)->write();
     $config = new Enlight_Config('test', array('adapter' => $adapter));
     $this->assertEquals(1, $config->get('test'));
 }
Ejemplo n.º 3
0
 public function testLoadForm2()
 {
     $this->writeConfig();
     $cfgAdapter = new Enlight_Config_Adapter_File(array('configType' => 'ini', 'configDir' => Enlight_TestHelper::Instance()->TestPath('TempFiles')));
     $formCfg = new Enlight_Config($this->testFile, array('adapter' => $cfgAdapter, 'allowModifications' => true));
     $formCfg->read();
     $form = new Enlight_Components_Form($formCfg->toArray());
     $this->assertInstanceOf('Enlight_Components_Form', $form);
 }
Ejemplo n.º 4
0
 /**
  * @param \Enlight_Controller_Request_Request $request
  * @return bool
  */
 public function isRequestAllowed(\Enlight_Controller_Request_Request $request)
 {
     $clientIp = $request->getClientIp();
     $allowedIp = $this->config->get('AllowIP');
     if (empty($allowedIp)) {
         return true;
     }
     if (empty($clientIp)) {
         return false;
     }
     return strpos($allowedIp, $clientIp) !== false;
 }
Ejemplo n.º 5
0
 /**
  * If there is a snippet missing, set the shopID and localeID to the main shop since all
  * language shops derive from it.
  *
  * @param \Enlight_Config $config
  */
 private function overwriteWithDefaultShopValues(\Enlight_Config $config)
 {
     $section = $config->getSection();
     foreach ($this->_sectionColumn as $key => $columnName) {
         switch ($columnName) {
             case 'shopID':
             case 'localeID':
                 $section[$key] = 1;
                 break;
         }
     }
     $config->setSection($section);
 }
 /**
  * @param PayPalConfig $config
  * @param CacheManager $cacheManager
  * @param string|bool $certPath path to Bundle of CA Root Certificates (see: https://curl.haxx.se/ca/cacert.pem)
  */
 public function __construct(PayPalConfig $config, CacheManager $cacheManager, $certPath = true)
 {
     $this->cacheManager = $cacheManager;
     $restUser = $config->get('paypalClientId');
     $restPw = $config->get('paypalSecret');
     $sandBoxMode = $config->get('paypalSandbox');
     if ($sandBoxMode) {
         $base_url = self::URL_SANDBOX;
     } else {
         $base_url = self::URL_LIVE;
     }
     $this->restClient = new Client(array('base_url' => $base_url, 'defaults' => array('headers' => array('PayPal-Partner-Attribution-Id' => 'ShopwareAG_Cart_PayPalPlus_1017'), 'verify' => $certPath)));
     $this->setAuth($restUser, $restPw);
 }
Ejemplo n.º 7
0
 /**
  * Constructor method
  *
  * @param array|bool $options
  */
 public function __construct($options = null)
 {
     $name = $options['name'] !== null ? $options['name'] : '';
     unset($options['name']);
     parent::__construct($name, $options);
     $this->read();
 }
Ejemplo n.º 8
0
 /**
  * @return array
  */
 protected function getProfileData()
 {
     $template = $this->bootstrap->get('template');
     $router = $this->bootstrap->get('router');
     $shop = $this->bootstrap->get('shop');
     $localeCode = $this->paypalBootstrap->getLocaleCode(true);
     $profileName = "{$shop->getHost()}{$shop->getBasePath()}[{$shop->getId()}]";
     $shopName = $this->bootstrap->get('config')->get('shopName');
     $shopName = $this->config->get('paypalBrandName', $shopName);
     $logoImage = $this->config->get('paypalLogoImage');
     $logoImage = 'string:{link file=' . var_export($logoImage, true) . ' fullPath}';
     $logoImage = $template->fetch($logoImage);
     $notifyUrl = $router->assemble(array('controller' => 'payment_paypal', 'action' => 'notify', 'forceSecure' => true));
     return array('name' => $profileName, 'presentation' => array('brand_name' => $shopName, 'logo_image' => $logoImage, 'locale_code' => $localeCode), 'input_fields' => array('allow_note' => true, 'no_shipping' => 0, 'address_override' => 1), 'flow_config' => array('bank_txn_pending_url' => $notifyUrl));
 }
 /**
  * @param Enlight_Config $config
  * @see https://github.com/paypal/sdk-core-php
  * @return Zend_Http_Client_Adapter_Curl|Zend_Http_Client_Adapter_Socket
  */
 public static function createAdapterFromConfig($config)
 {
     $curl = $config->get('paypalCurl', true);
     $sslVersion = $config->get('paypalSslVersion', 0);
     $timeout = $config->get('paypalTimeout') ?: 60;
     $userAgent = 'Shopware/' . Shopware::VERSION;
     if ($curl && extension_loaded('curl')) {
         $adapter = new Zend_Http_Client_Adapter_Curl();
         $adapter->setConfig(array('useragent' => $userAgent, 'timeout' => $timeout));
         if (!empty($config->paypalSandbox)) {
             $adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, false);
             $adapter->setCurlOption(CURLOPT_SSL_VERIFYHOST, false);
         }
         $adapter->setCurlOption(CURLOPT_TIMEOUT, $timeout);
         $adapter->setCurlOption(CURLOPT_SSLVERSION, $sslVersion);
         //$adapter->setCurlOption(CURLOPT_SSL_CIPHER_LIST, 'TLSv1');
         //$adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, 1);
         //$adapter->setCurlOption(CURLOPT_SSL_VERIFYHOST, 2);
     } else {
         $adapter = new Zend_Http_Client_Adapter_Socket();
         $adapter->setConfig(array('useragent' => $userAgent, 'timeout' => $timeout, 'ssltransport' => $sslVersion > 3 || $sslVersion == 1 ? 'tls' : 'ssl'));
     }
     return $adapter;
 }
Ejemplo n.º 10
0
 /**
  * Constructor method
  *
  * Expects a configuration parameter.
  *
  * @param Enlight_Config $config
  */
 public function __construct($config)
 {
     $wsdl = 'https://ipayment.de/service/3.0/?wsdl';
     if ($config->get('ipaymentSandbox')) {
         $this->accountData = array('accountId' => '99999', 'trxuserId' => '99998', 'trxpassword' => '0', 'adminactionpassword' => '5cfgRT34xsdedtFLdfHxj7tfwx24fe');
     } else {
         $this->accountData = array('accountId' => $config->get('ipaymentAccountId'), 'trxuserId' => $config->get('ipaymentAppId'), 'trxpassword' => $config->get('ipaymentAppPassword'), 'adminactionpassword' => $config->get('ipaymentAdminPassword'));
     }
     parent::__construct($wsdl, array('useragent' => 'Shopware ' . Shopware::VERSION));
 }
Ejemplo n.º 11
0
 /**
  * Constructor method
  *
  * @param $name
  * @param Enlight_Config|null $info
  */
 public function __construct($name, $info = null)
 {
     $this->info = new Enlight_Config($this->getInfo(), true);
     if ($info instanceof Enlight_Config) {
         $info->setAllowModifications(true);
         $updateVersion = null;
         $updateSource = null;
         if ($info->get('version') < $this->info->get('version')) {
             $updateVersion = $this->info->get('version');
             $updateSource = $this->info->get('source');
         }
         $this->info->merge($info);
         if ($updateVersion !== null) {
             $this->info->set('updateVersion', $updateVersion);
             $this->info->set('updateSource', $updateSource);
         }
     }
     $this->info->set('capabilities', $this->getCapabilities());
     parent::__construct($name);
 }
Ejemplo n.º 12
0
 /**
  * Constructor method
  *
  * Expects a configuration parameter.
  *
  * @param Enlight_Config $config
  */
 public function __construct($config)
 {
     if (!empty($config->paypalSandbox)) {
         $url = self::URL_SANDBOX;
     } else {
         $url = self::URL_LIVE;
     }
     $this->apiUsername = $config->get('paypalUsername');
     $this->apiPassword = $config->get('paypalPassword');
     $this->apiSignature = $config->get('paypalSignature');
     $this->apiVersion = $config->get('paypalVersion');
     parent::__construct($url);
     $this->setAdapter(RestClient::createAdapterFromConfig($config));
 }
Ejemplo n.º 13
0
 /**
  * Saves the Form using an Enlight_Config_Adapter to do so.
  * This is a rudimentary implementation and should be considered as beta
  *
  * @return Enlight_Components_Form
  */
 public function write()
 {
     $this->_adapter->setData($this->toArray());
     $this->_adapter->write();
     return $this;
 }
Ejemplo n.º 14
0
 public function testAutoNumArray()
 {
     $config = new Enlight_Config(array(), true);
     $config[0] = 'test1';
     $config[] = 'test2';
     $this->assertEquals('test1', $config->get(0));
     $this->assertEquals('test2', $config->get(1));
 }
Ejemplo n.º 15
0
 /**
  * Saves the data changes in the data store.
  *
  * @param      Enlight_Config $config
  * @param      array          $fields
  * @param      bool           $update
  * @return     Enlight_Config_Adapter_DbTable
  */
 public function write(Enlight_Config $config, $fields = null, $update = true)
 {
     $name = $this->_namePrefix . $config->getName() . $this->_nameSuffix;
     $section = $config->getSection();
     $dbTable = new Enlight_Components_Table(array('name' => $name, 'db' => $this->_db));
     $db = $dbTable->getAdapter();
     if ($fields === null) {
         $fields = $config->getDirtyFields();
     }
     if (empty($fields)) {
         return $this;
     }
     $updateData = array();
     $insertData = array();
     if ($this->_updatedColumn !== null) {
         $updateData[$this->_updatedColumn] = new Zend_Date();
         $insertData[$this->_updatedColumn] = new Zend_Date();
     }
     if ($this->_createdColumn !== null) {
         $insertData[$this->_createdColumn] = new Zend_Date();
     }
     $where = array();
     if ($section !== null) {
         if (is_array($this->_sectionColumn)) {
             foreach ($this->_sectionColumn as $key => $sectionColumn) {
                 if (isset($section[$key])) {
                     $where[] = $db->quoteInto($sectionColumn . '=?', $section[$key]);
                     $insertData[$sectionColumn] = $section[$key];
                 }
             }
         } else {
             $where[] = $db->quoteInto($this->_sectionColumn . '=?', $section);
             $insertData[$this->_sectionColumn] = $section;
         }
     }
     foreach ((array) $fields as $field) {
         $fieldWhere = $where;
         $fieldWhere[] = $db->quoteInto($this->_nameColumn . '=?', $field);
         $row = $dbTable->fetchRow($fieldWhere);
         if ($row !== null) {
             if ($update) {
                 $data = $updateData;
                 if ($this->_automaticSerialization) {
                     $data[$this->_valueColumn] = serialize($config->get($field));
                 } else {
                     $data[$this->_valueColumn] = $config->get($field);
                 }
                 $dbTable->update($data, $fieldWhere);
             }
         } else {
             $data = $insertData;
             $data[$this->_nameColumn] = $field;
             if ($this->_automaticSerialization) {
                 $data[$this->_valueColumn] = serialize($config->get($field));
             } else {
                 $data[$this->_valueColumn] = $config->get($field);
             }
             $dbTable->insert($data);
         }
     }
     $config->setDirtyFields(array_diff($config->getDirtyFields(), $fields));
     return $this;
 }
Ejemplo n.º 16
0
 /**
  * Constructor method
  * 
  * Expects a configuration parameter.
  *
  * @param Enlight_Config $config
  */
 public function __construct($config)
 {
     if(!empty($config->paypalSandbox)) {
         $url = self::URL_SANDBOX;
     } else {
         $url = self::URL_LIVE;
     }
     $this->apiUsername = $config->get('paypalUsername');
     $this->apiPassword = $config->get('paypalPassword');
     $this->apiSignature = $config->get('paypalSignature');
     $this->apiVersion = $config->get('paypalVersion');
     parent::__construct($url, array(
         'useragent' => 'Shopware/' . Shopware()->Config()->Version,
         'timeout' => 5,
     ));
     if (extension_loaded('curl')) {
         $adapter = new Zend_Http_Client_Adapter_Curl();
         $adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, false);
         $adapter->setCurlOption(CURLOPT_SSL_VERIFYHOST, false);
         $this->setAdapter($adapter);
     }
 }
Ejemplo n.º 17
0
    /**
     * Registers a plugin in the collection.
     *
     * @param   Shopware_Components_Plugin_Bootstrap $plugin
     * @return  bool
     */
    public function updatePlugin(Shopware_Components_Plugin_Bootstrap $plugin)
    {
        $name = $plugin->getName();
        $oldVersion = $this->getInfo($name, 'version');
        $newInfo = $plugin->getInfo();
        $newInfo = new Enlight_Config($newInfo, true);

        $result = $plugin->update($oldVersion);
        $success = is_bool($result) ? $result : !empty($result['success']);
        if ($success) {
            $newInfo->set('updateVersion', null);
            $newInfo->set('updateSource', null);
            $newInfo->set('updateDate', Zend_Date::now());
            $plugin->Info()->merge($newInfo);
            $this->registerPlugin($plugin);

            // Save events / Hooks
            $this->write();

            $form = $plugin->Form();
            if($form->hasElements()) {
                $this->Application()->Models()->persist($form);
            }
            $this->Application()->Models()->flush();

            // Clear proxy cache
            $this->Application()->Hooks()->getProxyFactory()->clearCache();
        }
        return $result;
    }
Ejemplo n.º 18
0
 /**
  * Saves the data changes to the data store.
  *
  * @param Enlight_Config $config
  * @param bool $forceWrite
  * @return Enlight_Config_Adapter_File
  */
 public function write(Enlight_Config $config, $forceWrite = false)
 {
     if (!$this->_allowWrites) {
         return $this;
     }
     $section = $config->getSection();
     $filename = $this->getFilename($config->getName());
     if (!$config->isDirty() && !$forceWrite) {
         return $this;
     }
     if (!empty($section)) {
         $base = $this->readBase($filename);
         if (is_array($section)) {
             foreach (array_reverse($section) as $sectionName) {
                 if (!isset($base->{$sectionName})) {
                     $base->{$sectionName} = array();
                 }
             }
             $sectionName = $extendingSection = array_shift($section);
             foreach ($section as $extendedSection) {
                 $base->setExtend($extendingSection, $extendedSection);
                 $extendingSection = $extendedSection;
             }
         } else {
             $sectionName = (string) $section;
         }
         $base->{$sectionName} = $config;
     } else {
         $base = $config;
     }
     $dir = dirname($filename);
     if (!file_exists($dir) || !is_writeable($dir)) {
         $old = umask(0);
         mkdir($dir, 0777, true);
         chmod($dir, 0777);
         umask($old);
     }
     if (!is_writeable($dir)) {
         return $this;
     }
     $writer = 'Enlight_Config_Writer_' . ucfirst($this->_configType);
     /** @var $writer Enlight_Config_Writer_Writer */
     $writer = new $writer(array('config' => $base, 'filename' => $filename));
     $writer->write();
     return $this;
 }
Ejemplo n.º 19
0
 /**
  * Returnswhether or not $updatePluginInfo contains a newer version than $currentPluginInfo
  *
  * @param \Enlight_Config $currentPluginInfo
  * @param \Enlight_Config $updatePluginInfo
  *
  * @return bool
  */
 public function hasInfoNewerVersion(Enlight_Config $updatePluginInfo, Enlight_Config $currentPluginInfo)
 {
     $currentVersion = $currentPluginInfo->get('version');
     $updateVersion = $updatePluginInfo->get('version');
     if (empty($updateVersion)) {
         return false;
     }
     // Exception for Pre-Installed Plugins
     if ($currentVersion == "1" && $updateVersion == "1.0.0") {
         return false;
     }
     return version_compare($updateVersion, $currentVersion, '>');
 }
Ejemplo n.º 20
0
 /**
  * Saves the data changes to the data store.
  *
  * @param Enlight_Config $config
  * @return Enlight_Config_Adapter_File
  */
 public function write(Enlight_Config $config)
 {
     $section = $config->getSection();
     $filename = $this->getFilename($config->getName());
     if (!empty($section)) {
         $base = $this->readBase($filename);
         $base->{$section} = $config;
     } else {
         $base = $config;
     }
     try {
         $writer = 'Zend_Config_Writer_' . ucfirst($this->_configType);
         /** @var $writer Zend_Config_Writer */
         $writer = new $writer(array('config' => $base, 'filename' => $filename));
         $writer->write();
     } catch (Zend_Exception $e) {
         throw new Enlight_Config_Exception($e->getMessage(), $e->getCode(), $e);
     }
     return $this;
 }
Ejemplo n.º 21
0
 /**
  * loads and creates the Enlight_Config based on the config
  * file placed in the config directory
  *
  * @return Enlight_Config_Adapter_File
  */
 public function initConfigAdapter()
 {
     $adapter = new Enlight_Config_Adapter_File(array('configType' => 'ini', 'configDir' => $this->Application()->AppPath('Configs')));
     Enlight_Config::setDefaultAdapter($adapter);
     return $adapter;
 }
 public function testClientAction()
 {
     $this->get('paypalClient');
     $config = $this->Request()->getParams();
     $config = new \Enlight_Config($config, true);
     // Test timeout
     $timeout = ($config->get('paypalTimeout') ?: 20) * 0.25;
     $config->set('paypalTimeout', $timeout);
     /** @var Zend_Http_Client|Client|RestClient $client */
     $client = null;
     try {
         $client = new Client($config, true);
         $data = $client->getBalance();
         for ($i = 0; isset($data['L_AMT' . $i]); $i++) {
             unset($data['L_AMT' . $i], $data['L_CURRENCYCODE' . $i]);
         }
         unset($data['VERSION']);
         if (isset($data['L_ERRORCODE0'])) {
             $data['code'] = $data['L_ERRORCODE0'];
             $data['message'] = $this->formatErrorMessage($data);
             unset($data['L_ERRORCODE0'], $data['L_SHORTMESSAGE0'], $data['L_LONGMESSAGE0'], $data['L_SEVERITYCODE0']);
         }
         if ($config->get('paypalClientId', false) && $data['ACK'] == 'Success') {
             $client = new RestClient($config);
             $data = $client->setAuthToken();
             $data = array('ACK' => 'Success') + $data;
             if (isset($data['access_token'])) {
                 $data['access_token'] = preg_replace('/[A-Z]/', '#', $data['access_token']);
             }
             unset($data['expires_in']);
         }
     } catch (Exception $e) {
         $data = array('code' => $e->getCode(), 'message' => $e->getMessage());
     }
     $data['shopware_version'] = Shopware::VERSION;
     $data['php_version'] = phpversion();
     if ($config->get('paypalCurl', true) && function_exists('curl_version')) {
         $curlVersion = curl_version();
         $data['curl_version'] = $curlVersion['version'];
         $data['system_host'] = $curlVersion['host'];
         $data['ssl_version'] = $curlVersion['ssl_version'];
         $data['libz_version'] = $curlVersion['libz_version'];
     }
     $this->View()->assign($data);
 }
Ejemplo n.º 23
0
 /**
  * Registers a plugin in the collection.
  *
  * @param   Shopware_Components_Plugin_Bootstrap $plugin
  * @return  bool
  */
 public function updatePlugin(Shopware_Components_Plugin_Bootstrap $plugin)
 {
     $this->reloadStorage();
     $name = $plugin->getName();
     $oldVersion = $this->getInfo($name, 'version');
     $newInfo = $plugin->getInfo();
     $newInfo = new Enlight_Config($newInfo, true);
     unset($newInfo->source);
     $this->Application()->Events()->notify('Shopware_Plugin_PreUpdate', array('subject' => $this, 'plugin' => $plugin));
     $result = $plugin->update($oldVersion);
     $success = is_bool($result) ? $result : !empty($result['success']);
     if ($success) {
         $this->Application()->Events()->notify('Shopware_Plugin_PostUpdate', array('subject' => $this, 'plugin' => $plugin));
         $newInfo->set('updateVersion', null);
         $newInfo->set('updateSource', null);
         $newInfo->set('updateDate', Zend_Date::now());
         $plugin->Info()->merge($newInfo);
         $this->registerPlugin($plugin);
         // Save events / Hooks
         $this->write();
         $form = $plugin->Form();
         if ($form->hasElements()) {
             $this->Application()->Models()->persist($form);
         }
         $this->Application()->Models()->flush();
         Shopware()->Container()->get('shopware.snippet_database_handler')->loadToDatabase($plugin->Path() . 'Snippets/');
         Shopware()->Container()->get('shopware.snippet_database_handler')->loadToDatabase($plugin->Path() . 'snippets/');
         Shopware()->Container()->get('shopware.snippet_database_handler')->loadToDatabase($plugin->Path() . 'Resources/snippet/');
         // Clear proxy cache
         $this->Application()->Hooks()->getProxyFactory()->clearCache();
     }
     return $result;
 }
Ejemplo n.º 24
0
 /**
  * Test case
  */
 public function testConfigNamePrefix()
 {
     $dir = Enlight_TestHelper::Instance()->TestPath('TempFiles');
     $adapter = new Enlight_Config_Adapter_File(array('configDir' => $dir, 'namePrefix' => 's_', 'skipExtends' => false, 'configType' => 'ini'));
     $config = new Enlight_Config('test', array('adapter' => $adapter));
     $config->setData(array('test' => true));
     $config->write();
     $this->assertFileExists($dir . 's_test' . '.ini');
 }
Ejemplo n.º 25
0
 /**
  * Sets the default config adapter.
  *
  * @param Enlight_Config_Adapter $adapter
  * @return void
  */
 public static function setDefaultAdapter(Enlight_Config_Adapter $adapter)
 {
     self::$_defaultAdapter = $adapter;
 }
Ejemplo n.º 26
0
 /**
  * Removes the data from the data store.
  *
  * @param      Enlight_Config $config
  * @param      array          $fields
  * @param      bool           $update
  * @return     Enlight_Config_Adapter_DbTable
  */
 public function delete(Enlight_Config $config, $fields = null, $deleteDirty = false)
 {
     $name = $this->_namePrefix . $config->getName() . $this->_nameSuffix;
     $section = explode($config->getSectionSeparator(), $config->getSection());
     $dbTable = $this->getTable($this->_namespaceColumn === null ? $name : null);
     $db = $dbTable->getAdapter();
     if ($fields === null) {
         $fields = $config->getDirtyFields();
     }
     if (empty($fields)) {
         return $this;
     }
     $where = array();
     $insertData = array();
     if ($this->_namespaceColumn !== null) {
         $insertData[$this->_namespaceColumn] = $name;
         $where[] = $db->quoteInto($this->_namespaceColumn . '=?', $name);
     }
     if ($section !== null) {
         if (is_array($this->_sectionColumn)) {
             foreach ($this->_sectionColumn as $key => $sectionColumn) {
                 if (isset($section[$key])) {
                     $where[] = $db->quoteInto($sectionColumn . '=?', $section[$key]);
                     $insertData[$sectionColumn] = $section[$key];
                 }
             }
         } else {
             $where[] = $db->quoteInto($this->_sectionColumn . '=?', $section);
             $insertData[$this->_sectionColumn] = $section;
         }
     }
     foreach ((array) $fields as $field) {
         $fieldWhere = $where;
         $fieldWhere[] = $db->quoteInto($this->_nameColumn . '=?', $field);
         if (!$deleteDirty) {
             $fieldWhere[] = $db->quoteInto($this->_dirtyColumn . '=?', 0);
         }
         $row = $dbTable->fetchRow($fieldWhere);
         if ($row !== null) {
             $row->delete();
         }
     }
     return $this;
 }