Yii Integrate HP Object Storage plugin. Trouble with namespace - object

I need to integrate the HP Object Storage plugin into my Yii project. I have downloaded the Hp Object Storage plugins in http://hpcloud.github.com/HPCloud-PHP/ and follow the tutorial is here
https://blog.hpcloud.com/working-object-storage-php
Here is the structure of my project
/..
/YiiBase.php
/index.php
/protected/..
/protected/hpcloud/..
/protected/hpcloud/Bootstrap.php
In the file /protected/config/main.php, I have already included the Bootstrap:
spl_autoload_unregister(array('YiiBase','autoload')); //temporary skip yii autoload
$basePath = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..';
require_once $basePath . DIRECTORY_SEPARATOR . 'hpcloud' . DIRECTORY_SEPARATOR . 'Bootstrap.php';
use \HPCloud\Bootstrap;
Bootstrap::useAutoloader();
Bootstrap::useStreamWrappers();
// Provide credentials
$settings = array(
'account' => YOUR_ACCOUNT_NUMBER,
'secret' => YOUR_SECRET_KEY,
'tenantid' => YOUR_TENANT_ID,
'endpoint' => IDENTITY_SERVICES_URL,
);
Bootstrap::setConfiguration($settings);
spl_autoload_register(array('YiiBase','autoload'));
But it threw the exception
Fatal error: Class 'HPCloud\Storage\ObjectStorage\StreamWrapper' not found in D:\wamp\www\myproject\protected\hpcloud\Bootstrap.php on line 182
I opened Bootstrap.php to troubleshoot it
public static function useStreamWrappers() {
$swift = stream_wrapper_register( // error in line 182
\HPCloud\Storage\ObjectStorage\StreamWrapper::DEFAULT_SCHEME,
'\HPCloud\Storage\ObjectStorage\StreamWrapper'
);
$swiftfs = stream_wrapper_register(
\HPCloud\Storage\ObjectStorage\StreamWrapperFS::DEFAULT_SCHEME,
'\HPCloud\Storage\ObjectStorage\StreamWrapperFS'
);
return ($swift && $swiftfs);
}
The namespaces and paths all are correct. I could not discover the cause of error.
If I leave the plugin with a simple file index.php alone (outside Yii project folder) upon following structure, it worked fine.
\..
\index.php
\hpcloud\Bootstrap.php
The error just happed when I putted the plugin in Yii project, I think there are something wrong with namespace.
Any help is appreciated. Thanks

I discover my problem now. It's all about case sensitive.
The namespace is "HPCloud" while plugin directory name is "hpcloud".

Related

Error in setting up Twig with CodeIgniter

I am trying to set up Twig Templating Engine with my new Codeigniter project.
But I am getting this error after setting up
Twig Exception
There are no registered paths for namespace "__main__".
I don't know what this error means. and how to solve it.
As per I am checking this is originated from the following file-
/application/vendor/twig/twig/lib/Twig/Loader/Filesystem.php:
code:
class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface
{
/** Identifier of the main namespace. */
const MAIN_NAMESPACE = '__main__';
protected $paths = array();
protected $cache = array();
protected $errorCache = array();
private $rootPath;
...
I followed this article for setting up
https://github.com/bcit-ci/CodeIgniter/wiki/Twig-PHP-Template-Engine-Implementation
Codeigniter Version- 3.1.8
Finally I made it.
I was missing this entry in autoload.php file
$autoload['config'] = array('twig');

Overload puppet default parameter in module

I want to use my own Jenkins plugin server to source plugins from. I'm using the puppet-jenkins module, but I can't seem to change the default plugin host value
The code on github has this in manifests/params:
class jenkins::params {
..
$default_plugins_host = 'https://updates.jenkins-ci.org'
..
}
So when I use this class, if I say:
class { 'jenkins':
default_plugins_host => "https://myhost.local"
}
I get Puppet (err): Invalid parameter
Or, if I try to define the value using capscase:
Jenkins::Params {
default_plugins_host => "https://specificallybrokenhost.com"
}
it isn't used by puppet. I tested this by giving it a plugin host that didn't exist, expecting the plugin installation to fail; but it was able to get plugins successfully (my assumption is that it still used jenkins-ci.org)
I was able to get this working by coping the entire module locally within library-jenkins/puppet-jenkins and changing the value, but i'd prefer not to have to resort to that
I'm using puppet-librarian and Puppet 3.3, if that helps.
the params.pp file stores private variables. This cannot be overridden.
Looking over the module is appears you can change the url from lines 67-82 of plugin.pp
if $version {
$plugins_host = $update_url ? {
undef => $::jenkins::default_plugins_host,
default => $update_url,
}
$base_url = "${plugins_host}/download/plugins/${name}/${version}/"
$search = "^${name} ${version}$"
}
else {
$plugins_host = $update_url ? {
undef => $::jenkins::default_plugins_host,
default => $update_url,
}
$base_url = "${plugins_host}/latest/"
$search = "${name} "
}
$plugins_host will use update_url if it's defined instead of default_plugins_host. if you make a default on the plugin define type you can change the default_plugins_host to update_url like so;
Jenkins::Plugin {
source_url => 'mycompany.jenkins.com',
}
I haven't tested this myself. So, let me know if it works.

Pimcore where does code go

All the examples show random pimcore code; however, I have found no explanation of where the code goes - or a complete example. I do not use pimcore for the cms. I am only interested in the object management. The code I am trying to wrte is to export objects e.g. into csv or xml.
Thanks ~
You can either create a plugin as suggested by Johan, but a quicker way is to just put the files into the /website/lib/Website folder. This folder is already added to the autoloader so you don't need to do anything else.
For example create an ObjectExporter.php under /website/lib/Website folder with this content:
<?php
namespace Website;
class ObjectExporter
{
public function exportObjects()
{
// Your code
}
}
Then you can either instantiate this class in your controller action or in a CLI script. Controller actions are within /website/controllers folder and they need to be called through http: http://localhost?controller=default&action=default
Example: /website/controllers/DefaultController.php
<?php
class DefaultController extends Website_Controller_Action {
public function defaultAction () {
$this->disableViewAutoRender();
$objectExporter = new Website\ObjectExporter();
$objectExporter->exportObjects();
}
}
(You could also add your whole code directly into action, but that would be a bit ugly solution, it of course depends)
But better and quickest way to approach such tasks is with the CLI scripts.
I like to use the /website/var/cli folder (you need to create it manually, but the /website/var folder is excluded in .htaccess by default which makes it practical for such use cases).
Example: /website/var/cli/export-objects.php
<?php
$workingDirectory = getcwd();
chdir(__DIR__);
include_once("../../../pimcore/cli/startup.php");
chdir($workingDirectory);
$objectExporter = new Website\ObjectExporter();
$objectExporter->exportObjects();
Then just run it by issuing this command in your command line:
php website/var/cli/export-objects.php
In case you wish to add special UI elements to the Pimcore backend, the way to go is with building an extension as suggested by Johan.
Igor
Here is a primcore example to export a list of object into a csv file
private function csvAction(){
$this->disableLayout();
$this->disableViewAutoRender();
$obj_list = new YourObject_List();
$obj_list->load();
/* #var $obj Object_YourObject */
$out = array();
foreach($obj_list as $obj){
$entry = array();
$entry["key"] = $obj->getKey();
$entry["Field 1"] = $obj->getField1();
$entry["Field 2"] = $obj->getField2();
$entry["Field 3"] = $obj->getField3();
$out[]=$entry;
}
$this->_helper->Csv($out, "produkt");
}
You could either create a new Plugin using admin function
Extras -> Extensions -> Create new Plugin
Add name Test
Activate plugin in list at Extras -> Extensions
You can then add the action above to plugins/Test/controllers/IndexController.php
It's also possible to add controller code in website/controllers, there is already a default controller there.
/Johan

How to get the full path of a file inClass library?

I am writing a class library and referring it in a WCF Service.
In this class library , i need to get the physical path of the app.config file.
It is working when hard coded with full physical path. But, i do not want to do this way.
Please see my code:
private static void loadConfig()
{
strConfigpath = "app.config";
log4net.Config.XmlConfigurator.Configure(new FileInfo(Path.GetFullPath(strConfigpath)) );
}
I tried using Path.GetFullPath(). But, it is giving wrong result.
I cannot use Server.MapPath() since it is not a web service or web application.
How to do this ? Ant thoughts or suggestions ?
Use the FullName property
string fileName = "app.config";
FileInfo f = new FileInfo(fileName);
string fullname = f.FullName;
f.DirectoryName; //This will give the folder path which is having the file
try something like this,
string folder = System.Web.HttpContext.Current != null ?
System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_data") : System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
refered : Get the file path of current application's config file

Why can't Kohana find my controller?

I have the following controller:
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Static extends Controller_DefaultTemplate {
public function action_index()
{
View::set_global('message', '<span class="highlight">This is a global message.</span>');
$data = array (
'siteTitle' => 'Kohana Test Site',
'siteSubtitle' => 'A site to learn Kohana',
'menu' => View::factory('blocks/menu'),
);
$view = View::factory('templates/layout', $data);
$this->request->response = $view->render();
}
}
but kohana gives me the error:
ErrorException [ Fatal Error ]: Class
'Controller_DefaultTemplate' not found
although Eclipse can find the file (via F3) and I thought Kohana was able to find all classes via autoloading?
How can I get Kohana to find the Controller_DefaultTemplate class so I can extend Controller_Static?
You must include file with definition of Controller_DefaultTemplate
The problem was that my file name defaultTemplate.php was camel case, changing it to all-lowercase defaultemplate.php enabled Kohana to find the class inside it.

Resources