Here is my project's structure:
app/
Life/
Forms
Formhandler.php
Page
Pagehandler.php
start.php
vendor/
composer/
autoload.php
index.php
The index.php requires start.php which then requires the composer autoload.php:
//start.php
<?php
require_once __DIR__ . '/../vendor/autoload.php';
This is a working structure, until I added Twig into the composer. Here's is what my composer.json looks like now:
{
"autoload": {
"psr-4": {
"Life\\" : "app/Life"
}
},
"require": {
"twig/twig" : "~1.0"
}
}
I far as I know, Twig doesn't support psr-4 for now and the only way I know is to require it in composer this way but with the "require" included I encounter an error like: Class 'Life\Page\Twig_Autoloader' not found.
What am I missing here?
Which code does trigger this error?
Please pay attention to which namespace you are in! It will affect the resolution of class names.
For example your error might be triggered if you are inside namespace Life\Page and are using new Twig_Autoloader(). That class should either be imported via uses or used as new \Twig_Autoloader().
Related
I am trying to create a self-executing bundle of an application, but jspm can't find what it's looking for.
I have the following folder structure
The src directory contains all of the JavaScript, but it is hosted by node as if it were the root. jspm_packages is hosted as if it were inside the root, making normal module import without a path possible (ie import React from 'react')
The app runs just fine, but when I try to build it fails because it doesn't know to look in the src directory and the jspm_packages directory for modules. Is there a way to fix this without changing the folder structure or the root-hosting?
I am ok with moving the system.config.js file into src if that makes this possible)
EDIT
This is easy if you move jspm_packages into src.
in package.json
"jspm": {
"directories": {
"baseURL": "src"
},
"configFile": "src/system.config.js"
}
This will put both system.config.js and jspm_packages in src (don't use a baseUrl in system.config.js), and bundling will work. The major drawback here is the src folder no longer contains only the project code; it now also contains library code. Performing folder searches becomes harder, and I just prefer the idea of a folder with all of my code in it.
EDIT2
After thinking about this problem more, I guess what I am really after is a method to specify an alternate path configuration during bundling. Based on my reading of the docs, this appears to be unsupported.
You can set your baseUrl to be the root (i.e. "/") and then set the path for your source code on the paths property like this:
System.config({
baseURL: "/",
paths: {
"*": "dist/*",
"github:*": "jspm_packages/github/*",
"npm:*": "jspm_packages/npm/*"
}
})
Full working example can be seen here.
Furthermore, if you need to change you paths just for bundling you could use the jspm-cli in a gulp task and override your builder configuration like this:
var jspm = require('jspm');
gulp.task('task', function () {
var builder = new jspm.Builder();
builder.loadConfigSync('pathToYourConfigFile');
builder.config({
paths: {
'*': 'pathToYourCode'
}
});
builder.bundle('yourOptionsHere');
}
I know that there are some similar questions on this topic already, but somehow none of them helped.
I want to use angular.js in a project which uses requirejs and Typescript.
I have a module, where I use angular to create a service module:
/// <reference path="../../../typings/angularjs/angular.d.ts" />
...
var services = angular.module('services', []);
...
export = services;
This code compiles withouth error, but in the created js file, there is angular.js dependency is not there:
define(["require", "exports"], function(require, exports) {
...
}
And when I run the application, the browser complains: Uncaught ReferenceError: angular is not defined
My guess is, that somehow I should import the angular besides referencing it, but none of the path's I tried works.
Here is my require.js configuration, in case it is needed:
require.config({
paths: {
angular: '../lib/angular/angular',
...
},
shim: {
angular : {exports : 'angular'},
...
}
)}
Can u help me, what is missing here?
Thanks.
When you use a reference comment:
/// <reference path="../../../typings/angularjs/angular.d.ts" />
You are telling the compiler "I will ensure this dependency is available at runtime".
If you want the module to be loaded, you need to use an import instead...
import angular = require('angular');
The zero-set-up way of doing this is to place the angular.d.ts file next to the actual angular.js file, so the path you specify in the import statement is the same either way - otherwise, use your require config to shimmy the path.
Have you tried adding the following to the top of your file
/// <amd-dependency path="angular"/>
This should make ts compiler add angular to the define list.
I am having an issue with brunch#1.7.6 not compiling bower_component css files. Similar to Separating app and vendor css in Brunch. Only the css/app.css is getting generated for me. :/
{
stylesheets: {
joinTo: {
'css/app.css': /^app/,
'css/vendor.css': /^bower_components/
}
}
Please let me know if I am doing something wrong. All seemed fine when I was using brunch#1.6.7. Did the config change with the introduction to bower being built in?
With regards to x-editable, I ran into the failure to include the bower_components css, but found that I simply had to add the specifics in the overrides section of bower.json (since it has multiple library options the main is not included in the .bower.json).
I used the following overrides successfully:
"overrides": {
"x-editable": {
"main": [
"dist/bootstrap3-editable/js/bootstrap-editable.js",
"dist/bootstrap3-editable/css/bootstrap-editable.css"
]
}
}
I'm having problems using canJS together with stealjs, i've cloned the repo of javascriptmvc (3.3 use canJS). Now i've this folder structure
/js
/can
/documentjs
/funcunit
/plugins
.
.
.
In another part of my application i've a "standalone module" e.g layout (generated using the scaffolding tool).
I load this module using "js/steal/steal.js?path/to/module/layout" inside my page and it works. If I stole some jquery plugins (e.g. located in the main js folder) inside my layout.js like so:
steal('plugins/jqueryplugin.js', 'plugins/jqueryplugin.css', function() {
// my code here
});
it still work, but when i try to add in the list of "dependecies" some component from "canJS" (even fixture.js generated with the tool...because it stoles can.fixture) it just stops to work and breaks everything. I've also tried using:
steal('that').then('this', function() {});
But i've the same results.....fail!!! anyone have any hints?
Ok i found the problem. There is nothing wrong with stealjs and canjs, but
canjs just load its own version of jquery
that will break my application. Now I need to find a way to load canjs and jquery separately (i use yii and some extensions need to have jquery loaded at a certain time so cannot wait for canjs).
Is the issue the version of jQuery or the order of dependencies?
You can configure steal via the stealconfig.js to use another version of jQuery and manage any dependencies.
An example can be found in the github repo: (this example does not show dependencies so i added one below)
https://github.com/bitovi/steal/blob/master/stealconfig.js
steal.config({
map: {
"*": {
"jquery/jquery.js": "jquery", // Map to path
"bootstrap/bootstrap.js": "bootstrap",
"can/util/util.js": "can/util/jquery/jquery.js"
}
},
paths: {
"jquery": "can/lib/jquery.1.8.3.js", // Path to jQuery
"bootstrap": "lib/bootstrap.js"
"yui/yui.js" : "can/lib/yui-3.7.3.js",
},
shim : {
jquery: {
exports: "jQuery"
},
bootstrap: { // A dependency example
'deps': ['jquery']
}
},
ext: {
js: "js",
css: "css",
less: "steal/less/less.js",
coffee: "steal/coffee/coffee.js",
ejs: "can/view/ejs/ejs.js",
mustache: "can/view/mustache/mustache.js"
}
});
Note: this is an untested example, hope this helps.
i had problem too with stealJs i have known that it work well with JavascriptMVC,
now i'm using AMD requireJs to dependency manage, an it works great with canjs.
here is the documentation http://canjs.com/guides/using-require.html, i hope that it help you!
Ok. Composer seems great.
But is more complex that deps method to add new bundles. I still donĀ“t get it.
Please someone give me a complete example on how to add a third party bundle to a symfony2 2.1.0-BETA4 installation.
The bundle I want to add is this.
Basically:
{
"require": {
"doctrine/doctrine-fixtures-bundle": "dev-master"
}
Regarding to the doc, this is how it should be set up.
And if you only want this bundle (and not DoctrineFixturesBundle):
{
"require": {
"doctrine/data-fixtures": "dev-master"
}