Download the PHP package creakiwi/yaml-fixtures without Composer

On this page you can find all versions of the php package creakiwi/yaml-fixtures. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yaml-fixtures

YamlFixtures

Overview

A simple abstraction class to use yaml fixtures, instead of PHP classes, on top of DoctrineFixturesBundle. It also allows the use of particular keywords such as %self% (the reference key of the yaml definition, in case of key => mixed value declaration) or %field% (where "field" refers to a previously defined field). Finally, this bundle handle One-to-One, Many-to-One and Many-to-Many relations, with the @ prefix.

Warning

The bundle isn't currently unit tested, use it at your own risks! You might need it to bootstrap your database, but never use it once you are in production mode (this rules is also true for DoctrineFixturesBundle in my opinion).

Examples

1. Keywords usage example

Let's say you have a unique entity User composed of the following fields :

First of all, you have to extends the YamlFixtures class :

// src/Acme/DemoBundle/DataFixtures/ORM
<?php

namespace Acme\DemoBundle\DataFixtures\ORM;

use Ck\Component\YamlFixtures\YamlFixture;
use Acme\DemoBundle\Entity\User;

class LoadUserData extends YamlFixture
{
    protected function getEntity()
    {
        return new User();
    }

    protected function getFilePath()
    {
        return sprintf('%s/../Fixtures/users.yml', __DIR__);
    }

    protected function getReferencePrefix()
    {
        return 'user';
    }

    public function getOrder()
    {
        return 1;
    }
}

Now, we'll need some yaml fixtures :

# src/Acme/DemoBundle/DataFixtures/Fixtures/users.yml
alex:
    username: alex-ception
    email: [email protected]
hubert:
    username: %self% # aka "hubert"
    email: [email protected]
foo:
    username: [email protected]
    email: %username% # aka "[email protected]"
"[email protected]":
    username: %self%
    email: %self% # or %username% in this case is also possible

And that's it. You can run the standard command to generate your fixtures through DoctrineFixturesBundle.

Note that instead of the key value identification for each root elements, you could use a simple list, but you would loose the ability to use the %self% keywords or managing relationship as we will see later :

-
    username: alex-ception
    email: [email protected]
-
    username: hubert
    email: [email protected]

2. One-to-One and Many-to-One usage example

In this example I will only present a Many-to-One relationship since it's the same as the One-to-One behavior for us here (it is the ORM job to check the One-to-One particularity)

We will now add a Comment entity (allowing users to add a comment) with two fields :

Let's write the class : // src/Acme/DemoBundle/DataFixtures/ORM <?php

namespace Acme\DemoBundle\DataFixtures\ORM;

use Ck\Component\YamlFixtures\YamlFixture;
use Acme\DemoBundle\Entity\Comment;

class LoadCommentData extends YamlFixture
{
    protected function getEntity()
    {
        return new Comment();
    }

    protected function getFilePath()
    {
        return sprintf('%s/../Fixtures/comments.yml', __DIR__);
    }

    protected function getReferencePrefix()
    {
        return 'comment';
    }

    public function getOrder()
    {
        // We want to load these fixtures after, since we depends on users fixtures
        return 2;
    }
}

And the fixtures :

# src/Acme/DemoBundle/DataFixtures/Fixtures/comments.yml
comment1:
    description: "my very nice comment"
    @owner: user-alex
mycomment:
    description: "I'm an elephant"
    @owner: user-hubert
another-comment:
    description: "Boo !!!!"
    @owner: user-foo

The concept is the following, to make YamlFixture understand that owner is a relationship, you have to prefix it with the "@" character. But, to link it to some entity, you need to know which one, this is the purpose of the getReferencePrefix() method, and then you need the key of the entity. To resume :

@field: referencePrefix-entityKey

3. Many-to-Many usage example

This part will be quick since you understand the mechanism, instead of a single string on a relationship, you can use a list.

We now have a Tag entity related to comments by Many-to-Many relationship. We assume that you have the Tag entity created with correct parameters as well as the LoadTagData.

All we have to do is switch order between comments and tags :

Fixtures:

# src/Acme/DemoBundle/DataFixtures/Fixtures/tags.yml
tag1:
    name: Tag 1
tag2:
    name: Tag 2
tag3:
    name: Tag 3

# src/Acme/DemoBundle/DataFixtures/Fixtures/comments.yml
comment1:
    description: "my very nice comment"
    @owner: user-alex
    @tag:
        - tag-tag1
        - tag-tag2
mycomment:
    description: "I'm an elephant"
    @owner: user-hubert
    @tag:
        - tag-tag2
        - tag-tag3
another-comment:
    description: "Boo !!!!"
    @owner: user-foo
    @tag:
        - tag-tag1
        - tag-tag3

The only thing to know about the many-to-many relationship is that it is not pluralized, you have to let it singular, the YamlFixture will use the "add" method.


All versions of yaml-fixtures with dependencies

PHP Build Version
Package Version
Requires symfony/yaml Version ~2.3
doctrine/doctrine-fixtures-bundle Version ~2.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package creakiwi/yaml-fixtures contains the following files

Loading the files please wait ....