Skip to content

Instantly share code, notes, and snippets.

@Axxiss
Axxiss / fixture.php
Created March 23, 2012 08:03
Fixture definition
class LoadMediaData extends AbstractFixture implements OrderedFixtureInterface
{
public function load(ObjectManager $manager)
{
$certification = new Certification();
$certification->setCode('PG-13');
$manager->persist($certification);
$person = new Person();
$person->setName('Test person');
@Axxiss
Axxiss / config_test.yml
Created March 23, 2012 08:17
Config test environment
doctrine:
dbal:
driver: pdo_mysql
host: localhost
port:
dbname: db_test
user: user
password: pass
charset: UTF8
@Axxiss
Axxiss / load-fixtures.sh
Created March 23, 2012 08:20
Load fixtures
cd /path/to/your/project
php app/console doctrine:schema:drop --env test --force
php app/console doctrine:schema:create --env test
php app/console doctrine:fixtures:load --env test
@Axxiss
Axxiss / multiple-form.php
Created March 28, 2012 09:16
Several unrelated forms in the same page.
public function acmeAction()
{
$acme = new Acme();
$form = $this->get('form.factory')
->createNamedBuilder(new AcmeType(), 'acme_form', $acme)
->getForm();
$request = $this->getRequest();
@Axxiss
Axxiss / AcmeProvider.java
Created April 26, 2012 15:33
Custom ContentProvider Stub
public class AcmeProvider extends ContentProvider {
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
// TODO Auto-generated method stub
return 0;
}
@Override
public String getType(Uri uri) {
@Axxiss
Axxiss / AcmeProviderMembers.java
Created May 4, 2012 09:24
Memmers of AcmeProvider
//Authority and ContentProvier URI
public static final String AUTHORITY = "com.acme.provider.myapp";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/logs");
//differentiate between the different URI requests
private static final int LOG_LIST = 1;
private static final int LOG_ITEM = 2;
//content types
private static final String CONTENT_TYPE_LIST = "vnd.android.cursor.dir/vnd.myapp.logs";
@Axxiss
Axxiss / AcmeDatabaseHelper.java
Created May 4, 2012 09:38
AcmeDatabaseHelper
private static class AcmeDatabaseHelper extends SQLiteOpenHelper {
private static final String CREATE_TABLE =
"create table "
+ TABLE_NAME + " ("
+ KEY_ID + " integer primary key autoincrement, "
+ KEY_FILENAME + " TEXT"
+ ");";
@Override
public String getType(Uri uri) {
switch (uriMatcher.match(uri)) {
case LOG_LIST: return CONTENT_TYPE_LIST;
case LOG_ITEM: return CONTENT_TYPE_ITEM;
default: throw new IllegalArgumentException("Unsupported URI: " + uri);
}
}
@Override
public boolean onCreate() {
Context context = getContext();
AcmeDatabaseHelper helper = new AcmeDatabaseHelper(context);
dbLogs = helper.getWritableDatabase();
return dbLogs == null ? false : true;
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
int count;
switch (uriMatcher.match(uri)) {
case LOG_LIST:
count = dbLogs.delete(TABLE_NAME, selection, selectionArgs);
break;
case LOG_ITEM:
String segment = uri.getPathSegments().get(1);