OpenRasta DI issues using StructureMap - structuremap

I'm trying to use StructureMap with OpenRasta. My Configuration class implements IDependencyResolverAccessor. Here's my code to configure the container:
container.Configure(x =>
{
x.For<IFileResourceRepository>().Use(
r => new FileResourceSqlRepository(ConnectionString));
x.For<ILog>().Use(l => new FileLog(LogFileName, _logLevel));
x.For<ILogger>().Use<ProTeckLogger>();
x.For<ILogger<CodecLogSource>>().Use<ProTeckLogger<CodecLogSource>>();
x.For<ILogger<IOLogSource>>().Use<ProTeckLogger<IOLogSource>>();
x.For<ILogger<OperationModelLogSource>>().Use<ProTeckLogger<OperationModelLogSource>>();
x.For<ILogger<PipelineLogSource>>().Use<ProTeckLogger<PipelineLogSource>>();
x.SetAllProperties(
policy =>
policy.Matching(
prop => (prop.PropertyType.IsAssignableFrom(typeof (ILogger)))));
x.SetAllProperties(policy => policy.OfType<IFileResourceRepository>());
x.SetAllProperties(policy => policy.OfType<ILog>());
x.SetAllProperties(policy => policy.OfType<ILogger<CodecLogSource>>());
x.SetAllProperties(policy => policy.OfType<ILogger<IOLogSource>>());
x.SetAllProperties(policy => policy.OfType<ILogger<OperationModelLogSource>>());
x.SetAllProperties(policy => policy.OfType<ILogger<PipelineLogSource>>());
});
I'm getting the following error:
StructureMap Exception Code: 202
No Default Instance defined for PluginFamily System.Diagnostics.TraceSource, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
I suppose perhaps I'm missing a registration? Might I be doing anything else wrong?
Thanks-

It appears that I was, in fact, missing a registration. Adding this line to the container configuration appears to have resolved the issue:
x.For<TraceSource>().Use(new TraceSource("OpenRasta"));
I don't totally understand how OR uses TraceSource, but for now, I'll take working!

Related

Zend Framework 2 autoloading hybridauth Library

I want to autoload Hybridauth external library in my module name "Account", I have included all libraries in the location
/var/www/ZendSkeletonApplication/module/Account/lib/hybridauth/Hybrid
Also in my module.php , I have the following namespaces
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__.'/src/'.__NAMESPACE__,
'hybridauth' => __DIR__.'/lib/hybridauth/Hybrid',
),
),
And in /var/www/ZendSkeletonApplication/module/Account/lib/hybridauth/Hybrid Auth.php file I have put the namespace.
namespace hybridauth;
class Hybrid_Auth {
......
In my controller I have declared the namespace as
use hybridauth\Hybrid_Auth;
But now whenever I make a call to new Hybrid_Auth( $config );, it shows error unable to load class.
I don't know what I am doing wrong here or weather I am following the correct way to autoload external libs in ZF2.
Any suggestion or Help !

Requiring apt::source as a dependency gives a syntax error

I need to add the docker source list to apt before installing docker.
I have
apt::source { 'debian-jessie':
comment => 'This is the docker Debian jessie mirror',
location => 'http://apt.dockerproject.org/repo',
release => 'debian-jessie',
repos => 'main',
key_content => '58118E89F3A912897C070ADBF76221572C52609D',
key_server => 'keyserver.ubuntu.com',
ensure => present,
include_src => false,
include_deb => true,
}
which works, and also
package {'docker-engine':
ensure => present,
before => Class['docker'],
}
which works only after a second run (I use vagrant provision, but that's not relevant to the problem).
What I would like is making the whole thing work at the first provisioning by instructing puppet to execute apt::source before docker-engine, however adding it in require is not a valid syntax:
package {'docker-engine':
ensure => present,
before => Class['docker'],
require => [
Apt::source['debian-jessie'],
]
}
How to specify this dependency?
The rest of the file looks like this:
class { 'docker':
dns => '192.168.1.1',
manage_package => false,
use_upstream_package_source=> false,
# service_name => 'docker',
docker_command => 'docker',
package_name => 'docker-engine',
service_enable => true,
service_state => 'running',
extra_parameters => ["--insecure-registry=192.168.1.0/24"],
}
include 'docker'
file { "/lib/systemd/system/docker.service":
notify => Service["docker"],
ensure => present,
owner => "root",
group => "root",
mode => 0600,
source =>"puppet:///modules/docker/etc/systemd/system/docker.service"
} ~> Exec['systemctl-daemon-reload']
Capitalize word source
require => Apt::Source['debian-jessie']
Puppet documentation states:
The general form of a resource reference is:
The resource type, capitalized (every segment must be capitalized if
the resource type includes a namespace separator [::])
An opening square bracket
The title of the resource as a string, or a comma-separated list of titles
A closing square bracket

Database driver Cake\Database\Driver\Sqlserver cannot be used due to a missing PHP extension or unmet dependency

I have installed cakephp 3.0.10 having mssql database now i have configured my wamp (php 5.5.12) with
extension=php_sqlsrv_55_ts.dll
extension=php_pdo_sqlsrv_55_ts.dll
& php info showing that sqlsrv is configured.
I have configured App.php with following code
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Sqlserver',
'persistent' => true,
'host' => 'mypc\SQLEXPRESS',
'username' => '',
'password' => '',
'database' => 'testdbname',
'encoding' => 65001,//PDO::SQLSRV_ENCODING_UTF8,
'timezone' => 'UTC',
'cacheMetadata' => true,
'quoteIdentifiers' => false,
To check whether connection is working or not i created a index.php file and fetched data from a test db created in sql magt. 2012 Now problem is cake php is not getting connected with database and it is showing following error
Database driver Cake\Database\Driver\Sqlserver cannot be used due to a missing PHP extension or unmet dependency
Exception Attributes: array (
'driver' => 'Cake\\Database\\Driver\\Sqlserver',
)
crud operation are going well in index.php ( test file ) but cakephp flashing error
Please help me to sort this out.
Thanks in advance

CakePHP iPad layout not being loaded

Ok, this is driving me somewhat nuts.
I created a mobile layout, mostly for iPads. I am using the beforeRender() function in the AppController to detect for the mobile client and switch the theme accordingly.
When I test the mobile site on my local development server using the iOS emulator, it all works perfectly fine. The theme gets loaded correctly and all. However, when I access it on the online production server, the mobile theme does not get loaded. I see the content, but without any styling.
The online test can be found here: http://www.anuragdesign.com/test/mbv
Why could that be? Any input is greatly appreciated.
Update:
Here are the relevant code pieces:
In my AppController.php
public function beforeRender() {
if($this->RequestHandler->isMobile()) {
$this->theme = 'mobile';
}
}
/lib/cake/Network/CakeRequest.php
protected $_detectors = array(
'get' => array('env' => 'REQUEST_METHOD', 'value' => 'GET'),
'post' => array('env' => 'REQUEST_METHOD', 'value' => 'POST'),
'put' => array('env' => 'REQUEST_METHOD', 'value' => 'PUT'),
'delete' => array('env' => 'REQUEST_METHOD', 'value' => 'DELETE'),
'head' => array('env' => 'REQUEST_METHOD', 'value' => 'HEAD'),
'options' => array('env' => 'REQUEST_METHOD', 'value' => 'OPTIONS'),
'ssl' => array('env' => 'HTTPS', 'value' => 1),
'ajax' => array('env' => 'HTTP_X_REQUESTED_WITH', 'value' => 'XMLHttpRequest'),
'flash' => array('env' => 'HTTP_USER_AGENT', 'pattern' => '/^(Shockwave|Adobe) Flash/'),
'mobile' => array('env' => 'HTTP_USER_AGENT', 'options' => array(
'AvantGo','DoCoMo', 'Fennec', 'iPad', 'J2ME', 'MIDP', 'NetFront', 'Nokia', 'Opera Mini', 'Opera Mobi', 'PalmOS', 'PalmSource',
'portalmmm', 'Plucker', 'ReqwirelessWeb', 'SonyEricsson', 'Symbian', 'UP\\.Browser',
'webOS', 'Windows CE', 'Windows Phone OS', 'Xiino'
)),
'requested' => array('param' => 'requested', 'value' => 1)
);
The mobile stylesheet is located in:
/app/View/Themed/mobile/webroot/css/mobile.css
and is being called in the layout file the splash page /app/View/Themed/mobile/Layouts/splash.ctp like so:
<?php echo $this->Html->css(array('reset.defaults', 'mobile', 'superfish')); ?>
Update:
debug($_SERVER['HTTP_USER_AGENT') on the online setup prodces the following output:
'Mozilla/5.0 (iPad; U; CPU OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5'
Fix (well sort of)
I did a few steps, which eventually seemed to fix it. The issue seemed to be that on the online production server it would try to serve the style sheet from the regular webroot folder, rather then my themed one. I have no idea as to why, but there you go.
So first of all, I duplicated all mobile stylesheets and put them in /app/webroot/css/ (vs where they should go /app/View/Themed/mobile/webroot/css/ . Then I also renamed any element which was used both in mobile and non-mobile views to make sure the mobile ones (located in /app/View/Themed/mobile/Elements) all had unique names.
That seemed to have worked, but all in all a rather in-concise solution. So if anyone has a better solution, I would love to hear.

rails twitter_oauth library uninitialized constant

I'm trying to use the twitter_oauth gem : http://github.com/moomerman/twitter_oauth
In my model I have:
require 'twitter_oauth'
And within a function I have:
def example
client = TwitterOAuth::Client.new(
:consumer_key => 'xxxx',
:consumer_secret => 'xxxx',
:token => "xxxx",
:secret => "xxxx")
return client
end
This seems fairly straight forward, but I can't seem to find out why I'm getting this error:
(Event being the name of the model)
uninitialized constant Event::TwitterOAuth
I can't seem to locate any conflicts with the TwitterOAuth namespace, any other thoughts?
Decided to use Grackle instead, seems to work fine

Resources