Code Monkey home page Code Monkey logo

craur's People

Contributors

dracoblue avatar graste avatar hoffigk avatar llupa avatar oskarstark avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

craur's Issues

Warning on Empty-XML String should throw an Exception

This:

$ cat fail_with_empty_xml_test.php 
<?php
try
{
    $node = Craur::createFromXml('');
    assert(false);
}
catch (Exception $exception)
{
    /*
     * Great, it broke! :)
     */
}

Fails wrong:

Fatal error: DOMDocument::loadXML(): Empty string supplied as input in /Volumes/development/workspaces/craur/php/Craur.class.php on line 52 in /Volumes/development/workspaces/craur/php/vendor/naith/naith/NaithCliRunner.class.php on line 87
  [  ] fail_with_empty_xml_test.php
   -> broken! (Exit code: 255)

tostring throws an exception on empty xml-tag

am empty xml-tag for example:

<neu neu="true" neuType="Erstausstrahlung"/>

throws an exception when it is converted to a string:

[23-Mar-2015 10:44:26 Europe/Berlin] PHP Fatal error:  Method Craur::__toString() must not throw an exception in .../class.php on line 0

the error messages is very hard to debug. maybe it is a better solution to display the given xml-attributes.

It's not possible to retrieve value, if it's associative

If the value, which is returned, is a associative array it doesn't get returned.

$xml_string = file_get_contents(dirname(__FILE__) . '/fixtures/example_atom_feed.xml');
$document = Craur::createFromXml($xml_string);
// at the moment this: fails
$feed = $document->get('feed');
// at the moment this: works
$entries = $document->get('feed.entry[]');

This should be possible to do:

$feed = $document->get('feed');
$entries = $feed->get('entry[]');

composer.json should validate

composer.json doesn't validate at the moment. At least a name and description field are necessary. While at it some more information should be added (like homepage, keywords etc.).

This has the advantage, that Packagist support should be possible.

error while parsing html5 elements

i got some issues with html5 tags: "Invalid html (Tag nav invalid,...."

when i do suppress the exception:
$error = libxml_get_last_error();

    if ($error)
    {
        #throw new Exception('Invalid html (' . trim($error->message) . ', line: ' . $error->line . ', col: ' . $error->column . '): ' . $html_string);
    }

the result seems to be fine:

    $craur_node = Craur::createFromHtml($new_html_body);
    var_dump($craur_node->toJsonString());

the var_dump returns perfect valid json. maybe craur could suppress any errors containing html5 tags?

Add release script to change version information

The version information used in the CLI version of craur as well as the version number in the composer.json file should be changed. After tagging a release with a version number the current dev version should be set as well (until the next tag/release is due).

mapping methode for craur

most of the time i use craur the xml-files i do import does not got "valid default" xml-tags. for example, the xml should look like this

<item>
    <titel>foo</titel>
    <genre>bar</genre>
    <description>foo</description>
</item>

our customers delivers something like:

<item>
    <titel>hans</titel>
    <genre>peter</genre>
</item>
<item>
    <titel>test</titel>
    <description>test123</description>
</item>

so every time i need to write some custom mapping code

protected function mapCraurToArray(Craur $craur, $map,$default_value = '')
{
    foreach ($map as $craur_key => $value)
    {
        try
        {
            $target_array[$value] = $craur->get($craur_key);
        }
        catch (Exception $e)
        {
            $target_array[$value] = $default_value;
        }
    }
    return $target_array;
}

maybe something like that could be implemented in craur too.

createFromExcelFile

Possible patch based on PHPExcel:

Index: php/Craur.class.php
===================================================================
--- php/Craur.class.php (revision 763)
+++ php/Craur.class.php (working copy)
@@ -255,6 +255,39 @@
         return $craur;   
     }

+    static function createFromExcelFile($file_path, array $field_mappings)
+    {
+        $file_handle = null;
+        
+        if (!file_exists($file_path))
+        {
+            throw new Exception('Cannot open file at ' . $file_path);
+        }
+        
+        $row_number = 0;
+        
+        $current_entry = array();
+        
+        $entries = array();
+
+        $excel_object = PHPExcel_IOFactory::load($file_path);
+        
+        $rows = $excel_object->getActiveSheet()->toArray(null,true,true,true);
+        
+        foreach ($rows as $row_data)
+        {
+            $row_number++;
+            if ($row_number != 1)
+            {
+                $entries[] = CraurCsvReader::expandPathsIntoArray(array_values($row_data), $field_mappings);
+            }
+        }
+        
+        $merged_entries = CraurCsvReader::mergePathEntriesRecursive($entries);
+        
+        return new Craur($merged_entries);  
+    }
+
     public function __construct(array $data)
     {
         $this->data = $data;

Add support for database import & MySQL export

Sometimes you have a database and want to use it as source for craur. It would be handy if Craur could import this on it's own, so you don't have to wrap the pdo connection and insert each row into Craur.

allow_url_fopen != On

develop@server61 /srv/htdocs/user/oskar/Craur $ make install-dependencies
make[1]: Entering directory `/srv/htdocs/user/oskar/Craur'
#!/usr/bin/env php
Some settings on your machine make Composer unable to work properly.
Make sure that you fix the issues listed below and run this script again:

The allow_url_fopen setting is incorrect.
Add the following to the end of your `php.ini`:
    allow_url_fopen = On

The php.ini used by your command-line PHP is: /etc/php/php.ini

make[1]: *** [install-composer] Error 1
make[1]: Leaving directory `/srv/htdocs/user/oskar/Craur'
make: *** [install-dependencies] Error 2

toXmlString does not include the value of the node

This one:

<?php
error_reporting(E_ALL | E_STRICT);
require_once('../Craur.class.php');

$node = Craur::createFromJson(json_encode(array(
    'feed' => array(
        'title' => array(
            '@' => 'Example Feed',
            '@lang' => 'en'
        )
    )
)));

assert('Example Feed' === $node->get('feed.title'));
/*
 * So this Example Feed should be in the xml and json response
 */
assert(strpos($node->toJsonString(), 'Example Feed') > 0);
assert(strpos($node->toXmlString(), 'Example Feed') > 0);

fails in the second assertion:

<feed><title lang="en"></title></feed>

Correct would be:

<feed><title lang="en">Example Feed</title></feed>

Yaml support

Craur should support Yaml as format. Maybe something like ''''createFromYaml()'''.

createFromHtml does not work with html fragments

Current behaviour:

<?php
$craur = Craur::createFromHtml('<a href="http://dracoblue.net">dracoblue</a>');
assert($craur->get('html.body.a') == 'dracoblue');
assert($craur->get('html.body.a.@href') == 'http://dracoblue.net');

Expected behaviour:

<?php
$craur = Craur::createFromHtml('<a href="http://dracoblue.net">dracoblue</a>');
assert($craur->get('a') == 'dracoblue');
assert($craur->get('a.@href') == 'http://dracoblue.net');

Craur#getWithFilter

$craur->getWithFilter('my_value', $callback);

The callback would be checked with is_callable and throw an exception if the path cannot be found.

selector for entity by property

If we have the input:

<document>
  <body>
     <header name="hans">
        <mau you="me">mom</mau>
        <pau>la</pau>
    </header>
     <footer name="hans">
        emil
    </footer>
</document>

it would be great if one could do:

"document.body.header[mau=mom].pau"

to fetch "la"

or

"document.body.header[mau.@you=me].pau"

to fetch "la"

or

"document.body.header[mau=mom][]"

to fetch [{"mau" => "mom", "pau" => "la"}].

or

"document.body.footer[@name=hans]"

to fetch "emil".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.