text:
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdarg>
#include <getopt.h>

#include <string>
#include <unordered_map>

#include "ts/ts.h"
#include "ts/remap.h"
#include "headers.h"
#include "rules.h"
#include "configs.h"

// Global config, if we don't have a remap specific config.
static BgFetchConfig *gConfig;

///////////////////////////////////////////////////////////////////////////
// Hold the global ackground fetch state. This is currently shared across all
// configurations, as a singleton. ToDo: Would it ever make sense to do this
// per remap rule? Probably not.
typedef std::unordered_map<std::string, bool> OutstandingRequests;

class BgFetchState
{
public:
  static BgFetchState &
  getInstance()
  {
    static BgFetchState _instance;
    return _instance;
  }

  ~BgFetchState() { TSMutexDestroy(_lock); }
  void
  createLog(const char *log_name)
  {
    TSDebug(PLUGIN_NAME, "Creating log name %s", log_name);
    TSAssert(TS_SUCCESS == TSTextLogObjectCreate(log_name, TS_LOG_MODE_ADD_TIMESTAMP, &_log));
  }

  TSTextLogObject
  getLog()
  {
    return _log;
  }

  bool
  acquire(const std::string &url)
  {
    bool ret;

    TSMutexLock(_lock);
    if (_urls.end() == _urls.find(url)) {
      _urls[url] = true;
      ret        = true;
    } else {
      ret = false;
    }
    TSMutexUnlock(_lock);

    TSDebug(PLUGIN_NAME, "BgFetchState.acquire(): ret = %d, url = %s", ret, url.c_str());

    return ret;
  }

  bool
  release(const std::string &url)
  {
    bool ret;

    TSMutexLock(_lock);
    if (_urls.end() == _urls.find(url)) {
      ret = false;
    } else {
      _urls.erase(url);
      ret = true;
    }
    TSMutexUnlock(_lock);

    return ret;
  }

private:
  BgFetchState() : _log(nullptr), _lock(TSMutexCreate()) {}
  BgFetchState(BgFetchState const &);   // Don't Implement
  void operator=(BgFetchState const &); // Don't implement

  TSTextLogObject _log;
  OutstandingRequests _urls;
  TSMutex _lock;
};

//////////////////////////////////////////////////////////////////////////////
// Hold and manage some state for the TXN background fetch continuation.
// This is necessary, because the TXN is likely to not be available
// during the time we fetch from origin.
struct BgFetchData {
  BgFetchData()
    : hdr_loc(TS_NULL_MLOC),
      url_loc(TS_NULL_MLOC),
      vc(nullptr),
      req_io_buf(nullptr),
      resp_io_buf(nullptr),
      req_io_buf_reader(nullptr),
      resp_io_buf_reader(nullptr),
      r_vio(nullptr),
      w_vio(nullptr),
      _bytes(0),
      _cont(nullptr)
  {
    mbuf = TSMBufferCreate();
    memset(&client_ip, 0, sizeof(client_ip));
  }

  ~BgFetchData()
  {
    TSHandleMLocRelease(mbuf, TS_NULL_MLOC, hdr_loc);
    TSHandleMLocRelease(mbuf, TS_NULL_MLOC, url_loc);

    TSMBufferDestroy(mbuf);

    if (vc) {
      TSError("[%s] Destroyed BgFetchDATA while VC was alive", PLUGIN_NAME);
      TSVConnClose(vc);
      vc = nullptr;
    }

    // If we got schedule, also clean that up
    if (_cont) {
      releaseUrl();

      TSContDestroy(_cont);
      _cont = nullptr;
      TSIOBufferReaderFree(req_io_buf_reader);
      TSIOBufferDestroy(req_io_buf);
      TSIOBufferReaderFree(resp_io_buf_reader);
      TSIOBufferDestroy(resp_io_buf);
    }
  }

  bool
  acquireUrl() const
  {
    return BgFetchState::getInstance().acquire(_url);
  }
  bool
  releaseUrl() const
  {
    return BgFetchState::getInstance().release(_url);
  }

  const char *
  getUrl() const
  {
    return _url.c_str();
  }

  void
  addBytes(int64_t b)
  {
    _bytes += b;
  }

  bool initialize(TSMBuffer request, TSMLoc req_hdr, TSHttpTxn txnp);
  void schedule();
  void log(TSEvent event) const;

  TSMBuffer mbuf;
  TSMLoc hdr_loc;
  TSMLoc url_loc;
  struct sockaddr_storage client_ip;

  // This is for the actual background fetch / NetVC
  TSVConn vc;
  TSIOBuffer req_io_buf, resp_io_buf;
  TSIOBufferReader req_io_buf_reader, resp_io_buf_reader;
  TSVIO r_vio, w_vio;

private:
  std::string _url;
  int64_t _bytes;
  TSCont _cont;
};

// This sets up the data and continuation properly, this is done outside
// of the CTor, since this can actually fail. If we fail, the data is
// useless, and should be delete'd.
//
// This needs the txnp temporarily, so it can copy the pristine request
// URL. The txnp is not used once initialize() returns.
//
// Upon succesful completion, the struct should be ready to start a
// background fetch.
bool
BgFetchData::initialize(TSMBuffer request, TSMLoc req_hdr, TSHttpTxn txnp)
{
  struct sockaddr const *ip = TSHttpTxnClientAddrGet(txnp);
  bool ret                  = false;

  TSAssert(TS_NULL_MLOC == hdr_loc);
  TSAssert(TS_NULL_MLOC == url_loc);

  if (ip) {
    if (ip->sa_family == AF_INET) {
      memcpy(&client_ip, ip, sizeof(sockaddr_in));
    } else if (ip->sa_family == AF_INET6) {
      memcpy(&client_ip, ip, sizeof(sockaddr_in6));
    } else {
      TSError("[%s] Unknown address family %d", PLUGIN_NAME, ip->sa_family);
    }
  } else {
    TSError("[%s] Failed to get client host info", PLUGIN_NAME);
    return false;
  }

  hdr_loc = TSHttpHdrCreate(mbuf);
  if (TS_SUCCESS == TSHttpHdrCopy(mbuf, hdr_loc, request, req_hdr)) {
    TSMLoc p_url;

    // Now copy the pristine request URL into our MBuf
    if (TS_SUCCESS == TSHttpTxnPristineUrlGet(txnp, &request, &p_url)) {
      if (TS_SUCCESS == TSUrlClone(mbuf, request, p_url, &url_loc)) {
        TSMLoc c_url = TS_NULL_MLOC;
        int len;
        char *url = nullptr;

        // Get the cache key URL (for now), since this has better lookup behavior when using
        // e.g. the cachekey plugin.
        if (TS_SUCCESS == TSUrlCreate(request, &c_url)) {
          if (TS_SUCCESS == TSHttpTxnCacheLookupUrlGet(txnp, request, c_url)) {
            url = TSUrlStringGet(request, c_url, &len);
            TSHandleMLocRelease(request, TS_NULL_MLOC, c_url);
            TSDebug(PLUGIN_NAME, "Cache URL is %.*s", len, url);
          }
        }

        if (url) {
          _url.assign(url, len); // Save away the cache URL for later use when acquiring lock
          TSfree(static_cast<void *>(url));

          if (TS_SUCCESS == TSHttpHdrUrlSet(mbuf, hdr_loc, url_loc)) {
            // Make sure we have the correct Host: header for this request.
            const char *hostp = TSUrlHostGet(mbuf, url_loc, &len);

            if (set_header(mbuf, hdr_loc, TS_MIME_FIELD_HOST, TS_MIME_LEN_HOST, hostp, len)) {
              TSDebug(PLUGIN_NAME, "Set header Host: %.*s", len, hostp);
            }

            // Next, remove any Range: headers from our request.
            if (remove_header(mbuf, hdr_loc, TS_MIME_FIELD_RANGE, TS_MIME_LEN_RANGE) > 0) {
              TSDebug(PLUGIN_NAME, "Removed the Range: header from request");
            }
            // Everything went as planned, so we can return true
            ret = true;
          }
        }
      }
      TSHandleMLocRelease(request, TS_NULL_MLOC, p_url);
    }
  }

  return ret;
}

static int cont_bg_fetch(TSCont contp, TSEvent event, void *edata);

// Create, setup and schedule the background fetch continuation.
void
BgFetchData::schedule()
{
  TSAssert(nullptr == _cont);

  // Setup the continuation
  _cont = TSContCreate(cont_bg_fetch, TSMutexCreate());
  TSContDataSet(_cont, static_cast<void *>(this));

  // Initialize the VIO stuff (for the fetch)
  req_io_buf         = TSIOBufferCreate();
  req_io_buf_reader  = TSIOBufferReaderAlloc(req_io_buf);
  resp_io_buf        = TSIOBufferCreate();
  resp_io_buf_reader = TSIOBufferReaderAlloc(resp_io_buf);

  // Schedule
  TSContSchedule(_cont, 0, TS_THREAD_POOL_NET);
}

// Log format is:
//    remap-tag bytes status url
void
BgFetchData::log(TSEvent event) const
{
  TSTextLogObject log = BgFetchState::getInstance().getLog();

  if (log || TSIsDebugTagSet(PLUGIN_NAME)) {
    const char *status;

    switch (event) {
    case TS_EVENT_VCONN_EOS:
      status = "EOS";
      break;
    case TS_EVENT_VCONN_INACTIVITY_TIMEOUT:
      status = "TIMEOUT";
      break;
    case TS_EVENT_ERROR:
      status = "ERROR";
      break;
    case TS_EVENT_VCONN_READ_COMPLETE:
      status = "READ_COMP";
      break;
    default:
      status = "UNKNOWN";
      break;
    }

    // ToDo: Also deal with per-remap tagging
    TSDebug(PLUGIN_NAME, "%s %" PRId64 " %s %s", "-", _bytes, status, _url.c_str());
    if (log) {
      TSTextLogObjectWrite(log, "%s %" PRId64 " %s %s", "-", _bytes, status, _url.c_str());
    }
  }
}

//////////////////////////////////////////////////////////////////////////////
// Continuation to perform a background fill of a URL. This is pretty
// expensive (memory allocations etc.), we could eliminate maybe the
// std::string, but I think it's fine for now.
static int
cont_bg_fetch(TSCont contp, TSEvent event, void * /* edata ATS_UNUSED */)
{
  BgFetchData *data = static_cast<BgFetchData *>(TSContDataGet(contp));
  int64_t avail;

  switch (event) {
  case TS_EVENT_IMMEDIATE:
  case TS_EVENT_TIMEOUT:
    // Debug info for this particular bg fetch (put all debug in here please)
    if (TSIsDebugTagSet(PLUGIN_NAME)) {
      char buf[INET6_ADDRSTRLEN];
      const sockaddr *sockaddress = (const sockaddr *)&data->client_ip;

      switch (sockaddress->sa_family) {
      case AF_INET:
        inet_ntop(AF_INET, &(((struct sockaddr_in *)sockaddress)->sin_addr), buf, INET_ADDRSTRLEN);
        TSDebug(PLUGIN_NAME, "Client IPv4 = %s", buf);
        break;
      case AF_INET6:
        inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)sockaddress)->sin6_addr), buf, INET6_ADDRSTRLEN);
        TSDebug(PLUGIN_NAME, "Client IPv6 = %s", buf);
        break;
      default:
        TSError("[%s] Unknown address family %d", PLUGIN_NAME, sockaddress->sa_family);
        break;
      }
      TSDebug(PLUGIN_NAME, "Starting background fetch, replaying:");
      dump_headers(data->mbuf, data->hdr_loc);
    }

    // Setup the NetVC for background fetch
    TSAssert(nullptr == data->vc);
    if ((data->vc = TSHttpConnect((sockaddr *)&data->client_ip)) != nullptr) {
      TSHttpHdrPrint(data->mbuf, data->hdr_loc, data->req_io_buf);
      // We never send a body with the request. ToDo: Do we ever need to support that ?
      TSIOBufferWrite(data->req_io_buf, "\r\n", 2);

      data->r_vio = TSVConnRead(data->vc, contp, data->resp_io_buf, INT64_MAX);
      data->w_vio = TSVConnWrite(data->vc, contp, data->req_io_buf_reader, TSIOBufferReaderAvail(data->req_io_buf_reader));
    } else {
      delete data;
      TSError("[%s] Failed to connect to internal process, major malfunction", PLUGIN_NAME);
    }
    break;

  case TS_EVENT_VCONN_WRITE_COMPLETE:
    // TSVConnShutdown(data->vc, 0, 1);
    // TSVIOReenable(data->w_vio);
    TSDebug(PLUGIN_NAME, "Write Complete");
    break;

  case TS_EVENT_VCONN_READ_READY:
    avail = TSIOBufferReaderAvail(data->resp_io_buf_reader);
    data->addBytes(avail);
    TSIOBufferReaderConsume(data->resp_io_buf_reader, avail);
    TSVIONDoneSet(data->r_vio, TSVIONDoneGet(data->r_vio) + avail);
    TSVIOReenable(data->r_vio);
    break;

  case TS_EVENT_VCONN_READ_COMPLETE:
  case TS_EVENT_VCONN_EOS:
  case TS_EVENT_VCONN_INACTIVITY_TIMEOUT:
  case TS_EVENT_ERROR:
    if (event == TS_EVENT_VCONN_INACTIVITY_TIMEOUT) {
      TSDebug(PLUGIN_NAME, "Encountered Inactivity Timeout");
      TSVConnAbort(data->vc, TS_VC_CLOSE_ABORT);
    } else {
      TSVConnClose(data->vc);
    }

    TSDebug(PLUGIN_NAME, "Closing down background transaction, event= %s(%d)", TSHttpEventNameLookup(event), event);
    avail = TSIOBufferReaderAvail(data->resp_io_buf_reader);
    data->addBytes(avail);
    TSIOBufferReaderConsume(data->resp_io_buf_reader, avail);
    TSVIONDoneSet(data->r_vio, TSVIONDoneGet(data->r_vio) + avail);
    data->log(event);

    // Close, release and cleanup
    data->vc = nullptr;
    delete data;
    break;

  default:
    TSDebug(PLUGIN_NAME, "Unhandled event: %s (%d)", TSHttpEventNameLookup(event), event);
    break;
  }

  return 0;
}

///////////////////////////////////////////////////////////////////////////
// This is a TXN hook, used to verify that the response (before sending to
// originating client) is indeed cacheable. This has to be deferred, because
// we might have plugins that changes the cacheability of an Origin response.
//
static int
cont_check_cacheable(TSCont contp, TSEvent /* event ATS_UNUSED */, void *edata)
{
  // ToDo: If we want to support per-remap configurations, we have to pass along the data here
  TSHttpTxn txnp = static_cast<TSHttpTxn>(edata);
  TSMBuffer response, request;
  TSMLoc resp_hdr, req_hdr;

  if (TS_SUCCESS == TSHttpTxnServerRespGet(txnp, &response, &resp_hdr)) {
    if (TS_SUCCESS == TSHttpTxnClientReqGet(txnp, &request, &req_hdr)) {
      // Temporarily change the response status to 200 OK, so we can reevaluate cacheability.
      TSHttpHdrStatusSet(response, resp_hdr, TS_HTTP_STATUS_OK);
      bool cacheable = TSHttpTxnIsCacheable(txnp, nullptr, response);
      TSHttpHdrStatusSet(response, resp_hdr, TS_HTTP_STATUS_PARTIAL_CONTENT);

      TSDebug(PLUGIN_NAME, "Testing: request / response is cacheable?");
      if (cacheable) {
        BgFetchData *data = new BgFetchData();

        // Initialize the data structure (can fail) and acquire a privileged lock on the URL
        if (data->initialize(request, req_hdr, txnp) && data->acquireUrl()) {
          data->schedule();
        } else {
          delete data; // Not sure why this would happen, but ok.
        }
      }
      // Release the request MLoc
      TSHandleMLocRelease(request, TS_NULL_MLOC, req_hdr);
    }
    // Release the response MLoc
    TSHandleMLocRelease(response, TS_NULL_MLOC, resp_hdr);
  }

  // Reenable and continue with the state machine.
  TSContDestroy(contp);
  TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);

  return 0;
}

//////////////////////////////////////////////////////////////////////////////
// Main "plugin", which is a global READ_RESPONSE_HDR hook. Before
// initiating a background fetch, this checks:
//
//     1. Check if a background fetch is allowed for this request
// and
//     2. Is the response from origin a 206 (Partial)?
//
// We defer the check on cacheability to the SEND_RESPONSE_HDR hook, since
// there could be other plugins that modifies the response after us.
//
static int
cont_handle_response(TSCont contp, TSEvent event, void *edata)
{
  // ToDo: If we want to support per-remap configurations, we have to pass along the data here
  TSHttpTxn txnp        = static_cast<TSHttpTxn>(edata);
  BgFetchConfig *config = static_cast<BgFetchConfig *>(TSContDataGet(contp));

  if (nullptr == config) {
    // something seriously wrong..
    TSError("[%s] Can't get configurations", PLUGIN_NAME);
  } else {
    switch (event) {
    case TS_EVENT_HTTP_READ_RESPONSE_HDR:
      if (config->getRules()->bgFetchAllowed(txnp)) {
        TSMBuffer response;
        TSMLoc resp_hdr;

        if (TS_SUCCESS == TSHttpTxnServerRespGet(txnp, &response, &resp_hdr)) {
          // ToDo: Check the MIME type first, to see if it's a type we care about.
          // ToDo: Such MIME types should probably be per remap rule.

          // Only deal with 206 responses from Origin
          TSDebug(PLUGIN_NAME, "Testing: response is 206?");
          if (TS_HTTP_STATUS_PARTIAL_CONTENT == TSHttpHdrStatusGet(response, resp_hdr)) {
            // Everything looks good so far, add a TXN hook for SEND_RESPONSE_HDR
            TSCont contp = TSContCreate(cont_check_cacheable, nullptr);

            TSHttpTxnHookAdd(txnp, TS_HTTP_SEND_RESPONSE_HDR_HOOK, contp);
          }
          // Release the response MLoc
          TSHandleMLocRelease(response, TS_NULL_MLOC, resp_hdr);
        }
      }
      break;
    case TS_EVENT_HTTP_TXN_CLOSE:
      config->release(); // Release the configuration lease when txn closes
      break;
    default:
      TSError("[%s] Unknown event for this plugin", PLUGIN_NAME);
      TSDebug(PLUGIN_NAME, "unknown event for this plugin");
      break;
    }
  }

  // Reenable and continue with the state machine.
  TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
  return 0;
}

///////////////////////////////////////////////////////////////////////////
// Setup global hooks
void
TSPluginInit(int argc, const char *argv[])
{
  TSPluginRegistrationInfo info;
  static const struct option longopt[] = {{const_cast<char *>("log"), required_argument, nullptr, 'l'},
                                          {const_cast<char *>("config"), required_argument, nullptr, 'c'},
                                          {nullptr, no_argument, nullptr, '\0'}};

  info.plugin_name   = (char *)PLUGIN_NAME;
  info.vendor_name   = (char *)"Apache Software Foundation";
  info.support_email = (char *)"dev@trafficserver.apache.org";

  if (TS_SUCCESS != TSPluginRegister(&info)) {
    TSError("[%s] Plugin registration failed", PLUGIN_NAME);
  }

  TSCont cont = TSContCreate(cont_handle_response, nullptr);

  gConfig = new BgFetchConfig(cont);
  gConfig->acquire(); // Inc refcount, although this global config should never go out of scope

  while (true) {
    int opt = getopt_long(argc, (char *const *)argv, "lc", longopt, nullptr);

    switch (opt) {
    case 'l':
      BgFetchState::getInstance().createLog(optarg);
      break;
    case 'c':
      TSDebug(PLUGIN_NAME, "config file '%s'", optarg);
      gConfig->readConfig(optarg);
      break;
    }

    if (opt == -1) {
      break;
    }
  }

  TSDebug(PLUGIN_NAME, "Initialized");
  TSHttpHookAdd(TS_HTTP_READ_RESPONSE_HDR_HOOK, cont);
}

///////////////////////////////////////////////////////////////////////////
// Setup Remap mode
///////////////////////////////////////////////////////////////////////////////
// Initialize the plugin.
//
TSReturnCode
TSRemapInit(TSRemapInterface *api_info, char *errbuf, int errbuf_size)
{
  TSDebug(PLUGIN_NAME, "background fetch remap init");
  if (!api_info) {
    strncpy(errbuf, "[tsremap_init] - Invalid TSRemapInterface argument", errbuf_size - 1);
    return TS_ERROR;
  }

  if (api_info->tsremap_version < TSREMAP_VERSION) {
    snprintf(errbuf, errbuf_size - 1, "[TSRemapInit] - Incorrect API version %ld.%ld", api_info->tsremap_version >> 16,
             (api_info->tsremap_version & 0xffff));
    return TS_ERROR;
  }

  TSDebug(PLUGIN_NAME, "background fetch remap is successfully initialized");
  return TS_SUCCESS;
}

///////////////////////////////////////////////////////////////////////////////
// We don't have any specific "instances" here, at least not yet.
//
TSReturnCode
TSRemapNewInstance(int argc, char *argv[], void **ih, char * /* errbuf */, int /* errbuf_size */)
{
  TSCont cont           = TSContCreate(cont_handle_response, nullptr);
  BgFetchConfig *config = new BgFetchConfig(cont);

  config->acquire(); // Inc refcount

  // Parse the optional rules, wihch becomes a linked list of BgFetchRule's.
  if (argc > 2) {
    TSDebug(PLUGIN_NAME, "config file %s", argv[2]);
    config->readConfig(argv[2]);
  }

  *ih = (void *)config;

  return TS_SUCCESS;
}

void
TSRemapDeleteInstance(void *ih)
{
  BgFetchConfig *config = static_cast<BgFetchConfig *>(ih);

  config->release();
}

///////////////////////////////////////////////////////////////////////////////
//// This is the main "entry" point for the plugin, called for every request.
////
TSRemapStatus
TSRemapDoRemap(void *ih, TSHttpTxn txnp, TSRemapRequestInfo * /* rri */)
{
  if (nullptr == ih) {
    return TSREMAP_NO_REMAP;
  }

  TSMBuffer bufp;
  TSMLoc req_hdrs;

  if (TS_SUCCESS == TSHttpTxnClientReqGet(txnp, &bufp, &req_hdrs)) {
    TSMLoc field_loc = TSMimeHdrFieldFind(bufp, req_hdrs, TS_MIME_FIELD_RANGE, TS_MIME_LEN_RANGE);

    if (field_loc) {
      BgFetchConfig *config = static_cast<BgFetchConfig *>(ih);

      config->acquire(); // Inc refcount
      TSHttpTxnHookAdd(txnp, TS_HTTP_READ_RESPONSE_HDR_HOOK, config->getCont());
      TSHttpTxnHookAdd(txnp, TS_HTTP_TXN_CLOSE_HOOK, config->getCont());

      TSDebug(PLUGIN_NAME, "background fetch TSRemapDoRemap");
      TSHandleMLocRelease(bufp, req_hdrs, field_loc);
    }
    TSHandleMLocRelease(bufp, TS_NULL_MLOC, req_hdrs);
  }

  return TSREMAP_NO_REMAP;
}


text:
import styles from './index.css';

/**
 * @param  {string} code
 * @param  {string} language
 * @return {string}
 */
export default function code(code, language) {
  return `<pre><code class=${styles.common}>${code}\n</code></pre>\n`;
}

redpajama_set_name: RedPajamaGithub


text:
<?php

/* SonataDoctrineMongoDBAdminBundle:Form:form_admin_fields.html.twig */
class __TwigTemplate_846f885762cd8ae3b25a4a24c5b9b80f7a1453ac92662b823ff036835033194d extends Twig_Template
{
    public function __construct(Twig_Environment $env)
    {
        parent::__construct($env);

        // line 13
        $this->parent = $this->loadTemplate("SonataAdminBundle:Form:form_admin_fields.html.twig", "SonataDoctrineMongoDBAdminBundle:Form:form_admin_fields.html.twig", 13);
        $this->blocks = array(
            'sonata_admin_mongo_one_widget' => array($this, 'block_sonata_admin_mongo_one_widget'),
            'sonata_admin_mongo_many_widget' => array($this, 'block_sonata_admin_mongo_many_widget'),
            'sonata_admin_mongo_collection' => array($this, 'block_sonata_admin_mongo_collection'),
            'sonata_type_model_widget' => array($this, 'block_sonata_type_model_widget'),
            'sonata_type_model_list_widget' => array($this, 'block_sonata_type_model_list_widget'),
            'sonata_type_admin_widget' => array($this, 'block_sonata_type_admin_widget'),
            'sonata_type_collection_widget' => array($this, 'block_sonata_type_collection_widget'),
        );
    }

    protected function doGetParent(array $context)
    {
        return "SonataAdminBundle:Form:form_admin_fields.html.twig";
    }

    protected function doDisplay(array $context, array $blocks = array())
    {
        $__internal_6b00131b0a478653a04fca6cd791b3ded4f709e5748a8b637029261d06430128 = $this->env->getExtension("Symfony\\Bundle\\WebProfilerBundle\\Twig\\WebProfilerExtension");
        $__internal_6b00131b0a478653a04fca6cd791b3ded4f709e5748a8b637029261d06430128->enter($__internal_6b00131b0a478653a04fca6cd791b3ded4f709e5748a8b637029261d06430128_prof = new Twig_Profiler_Profile($this->getTemplateName(), "template", "SonataDoctrineMongoDBAdminBundle:Form:form_admin_fields.html.twig"));

        $__internal_cae5a046a4e733988437bb518dfff90788e18a28fde01924bfd0a16805adb655 = $this->env->getExtension("Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension");
        $__internal_cae5a046a4e733988437bb518dfff90788e18a28fde01924bfd0a16805adb655->enter($__internal_cae5a046a4e733988437bb518dfff90788e18a28fde01924bfd0a16805adb655_prof = new Twig_Profiler_Profile($this->getTemplateName(), "template", "SonataDoctrineMongoDBAdminBundle:Form:form_admin_fields.html.twig"));

        $this->parent->display($context, array_merge($this->blocks, $blocks));

        $__internal_6b00131b0a478653a04fca6cd791b3ded4f709e5748a8b637029261d06430128->leave($__internal_6b00131b0a478653a04fca6cd791b3ded4f709e5748a8b637029261d06430128_prof);

        $__internal_cae5a046a4e733988437bb518dfff90788e18a28fde01924bfd0a16805adb655->leave($__internal_cae5a046a4e733988437bb518dfff90788e18a28fde01924bfd0a16805adb655_prof);

    }

    // line 17
    public function block_sonata_admin_mongo_one_widget($context, array $blocks = array())
    {
        $__internal_c996832264328a730fe9638127b206a314732c44feb717c37ffd741217427660 = $this->env->getExtension("Symfony\\Bundle\\WebProfilerBundle\\Twig\\WebProfilerExtension");
        $__internal_c996832264328a730fe9638127b206a314732c44feb717c37ffd741217427660->enter($__internal_c996832264328a730fe9638127b206a314732c44feb717c37ffd741217427660_prof = new Twig_Profiler_Profile($this->getTemplateName(), "block", "sonata_admin_mongo_one_widget"));

        $__internal_4bce02add5265d811cabbf9dda9602816420f2cc73dcc6436dde62af9739b2f0 = $this->env->getExtension("Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension");
        $__internal_4bce02add5265d811cabbf9dda9602816420f2cc73dcc6436dde62af9739b2f0->enter($__internal_4bce02add5265d811cabbf9dda9602816420f2cc73dcc6436dde62af9739b2f0_prof = new Twig_Profiler_Profile($this->getTemplateName(), "block", "sonata_admin_mongo_one_widget"));

        // line 18
        echo "    ";
        $this->loadTemplate("SonataDoctrineMongoDBAdminBundle:CRUD:edit_mongo_one.html.twig", "SonataDoctrineMongoDBAdminBundle:Form:form_admin_fields.html.twig", 18)->display($context);

        $__internal_4bce02add5265d811cabbf9dda9602816420f2cc73dcc6436dde62af9739b2f0->leave($__internal_4bce02add5265d811cabbf9dda9602816420f2cc73dcc6436dde62af9739b2f0_prof);

        $__internal_c996832264328a730fe9638127b206a314732c44feb717c37ffd741217427660->leave($__internal_c996832264328a730fe9638127b206a314732c44feb717c37ffd741217427660_prof);

    }

    // line 21
    public function block_sonata_admin_mongo_many_widget($context, array $blocks = array())
    {
        $__internal_740186371dd6a4d14e9652289494761284b07d591378d5d106dd65fd396f5774 = $this->env->getExtension("Symfony\\Bundle\\WebProfilerBundle\\Twig\\WebProfilerExtension");
        $__internal_740186371dd6a4d14e9652289494761284b07d591378d5d106dd65fd396f5774->enter($__internal_740186371dd6a4d14e9652289494761284b07d591378d5d106dd65fd396f5774_prof = new Twig_Profiler_Profile($this->getTemplateName(), "block", "sonata_admin_mongo_many_widget"));

        $__internal_ae7f28a69bc3ed548ae02ad83fb5fcf3a36af7f50ce6c3f94c5868cea077932c = $this->env->getExtension("Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension");
        $__internal_ae7f28a69bc3ed548ae02ad83fb5fcf3a36af7f50ce6c3f94c5868cea077932c->enter($__internal_ae7f28a69bc3ed548ae02ad83fb5fcf3a36af7f50ce6c3f94c5868cea077932c_prof = new Twig_Profiler_Profile($this->getTemplateName(), "block", "sonata_admin_mongo_many_widget"));

        // line 22
        echo "    ";
        $this->loadTemplate("SonataDoctrineMongoDBAdminBundle:CRUD:edit_mongo_many.html.twig", "SonataDoctrineMongoDBAdminBundle:Form:form_admin_fields.html.twig", 22)->display($context);

        $__internal_ae7f28a69bc3ed548ae02ad83fb5fcf3a36af7f50ce6c3f94c5868cea077932c->leave($__internal_ae7f28a69bc3ed548ae02ad83fb5fcf3a36af7f50ce6c3f94c5868cea077932c_prof);

        $__internal_740186371dd6a4d14e9652289494761284b07d591378d5d106dd65fd396f5774->leave($__internal_740186371dd6a4d14e9652289494761284b07d591378d5d106dd65fd396f5774_prof);

    }

    // line 25
    public function block_sonata_admin_mongo_collection($context, array $blocks = array())
    {
        $__internal_7cd76241d40584a6febf2e8a75f3a2b3cf9a32fd15ea0f4412cd3a020f587b93 = $this->env->getExtension("Symfony\\Bundle\\WebProfilerBundle\\Twig\\WebProfilerExtension");
        $__internal_7cd76241d40584a6febf2e8a75f3a2b3cf9a32fd15ea0f4412cd3a020f587b93->enter($__internal_7cd76241d40584a6febf2e8a75f3a2b3cf9a32fd15ea0f4412cd3a020f587b93_prof = new Twig_Profiler_Profile($this->getTemplateName(), "block", "sonata_admin_mongo_collection"));

        $__internal_f008b0228a48bcdd90b438f8e692cbfa105910ecbfe5451709316d84a0adfdc4 = $this->env->getExtension("Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension");
        $__internal_f008b0228a48bcdd90b438f8e692cbfa105910ecbfe5451709316d84a0adfdc4->enter($__internal_f008b0228a48bcdd90b438f8e692cbfa105910ecbfe5451709316d84a0adfdc4_prof = new Twig_Profiler_Profile($this->getTemplateName(), "block", "sonata_admin_mongo_collection"));

        // line 26
        echo "    ";
        $this->loadTemplate("SonataDoctrineMongoDBAdminBundle:CRUD:edit_mongo_collection.html.twig", "SonataDoctrineMongoDBAdminBundle:Form:form_admin_fields.html.twig", 26)->display($context);

        $__internal_f008b0228a48bcdd90b438f8e692cbfa105910ecbfe5451709316d84a0adfdc4->leave($__internal_f008b0228a48bcdd90b438f8e692cbfa105910ecbfe5451709316d84a0adfdc4_prof);

        $__internal_7cd76241d40584a6febf2e8a75f3a2b3cf9a32fd15ea0f4412cd3a020f587b93->leave($__internal_7cd76241d40584a6febf2e8a75f3a2b3cf9a32fd15ea0f4412cd3a020f587b93_prof);

    }

    // line 29
    public function block_sonata_type_model_widget($context, array $blocks = array())
    {
        $__internal_46e13be2522114fd537ba160aba2cec19521a83a6c5ee2e7b84d9ca5225e0cb5 = $this->env->getExtension("Symfony\\Bundle\\WebProfilerBundle\\Twig\\WebProfilerExtension");
        $__internal_46e13be2522114fd537ba160aba2cec19521a83a6c5ee2e7b84d9ca5225e0cb5->enter($__internal_46e13be2522114fd537ba160aba2cec19521a83a6c5ee2e7b84d9ca5225e0cb5_prof = new Twig_Profiler_Profile($this->getTemplateName(), "block", "sonata_type_model_widget"));

        $__internal_f8b078554c41aefdc3b7efc8f203c97d68e684f4aee5409041e4de05e1512c4b = $this->env->getExtension("Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension");
        $__internal_f8b078554c41aefdc3b7efc8f203c97d68e684f4aee5409041e4de05e1512c4b->enter($__internal_f8b078554c41aefdc3b7efc8f203c97d68e684f4aee5409041e4de05e1512c4b_prof = new Twig_Profiler_Profile($this->getTemplateName(), "block", "sonata_type_model_widget"));

        // line 30
        echo "    ";
        // line 34
        echo "
    ";
        // line 36
        echo "
    ";
        // line 37
        if (twig_test_empty($this->getAttribute((isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "field_description", array()))) {
            // line 38
            echo "        ";
            $this->displayBlock("choice_widget", $context, $blocks);
            echo "
    ";
        } elseif (($this->getAttribute($this->getAttribute(        // line 39
(isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "field_description", array()), "mappingtype", array()) == "one")) {
            // line 40
            echo "        ";
            $this->displayBlock("sonata_admin_mongo_one_widget", $context, $blocks);
            echo "
    ";
        } elseif (($this->getAttribute($this->getAttribute(        // line 41
(isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "field_description", array()), "mappingtype", array()) == "many")) {
            // line 42
            echo "        ";
            $this->displayBlock("sonata_admin_mongo_many_widget", $context, $blocks);
            echo "
    ";
        } else {
            // line 44
            echo "        ";
            // line 45
            echo "        ";
            $this->displayBlock("choice_widget", $context, $blocks);
            echo "
    ";
        }

        $__internal_f8b078554c41aefdc3b7efc8f203c97d68e684f4aee5409041e4de05e1512c4b->leave($__internal_f8b078554c41aefdc3b7efc8f203c97d68e684f4aee5409041e4de05e1512c4b_prof);

        $__internal_46e13be2522114fd537ba160aba2cec19521a83a6c5ee2e7b84d9ca5225e0cb5->leave($__internal_46e13be2522114fd537ba160aba2cec19521a83a6c5ee2e7b84d9ca5225e0cb5_prof);

    }

    // line 49
    public function block_sonata_type_model_list_widget($context, array $blocks = array())
    {
        $__internal_ce0142fd50523a0025043988e9639587d38b493df741ef4dcfe42f996011d7b5 = $this->env->getExtension("Symfony\\Bundle\\WebProfilerBundle\\Twig\\WebProfilerExtension");
        $__internal_ce0142fd50523a0025043988e9639587d38b493df741ef4dcfe42f996011d7b5->enter($__internal_ce0142fd50523a0025043988e9639587d38b493df741ef4dcfe42f996011d7b5_prof = new Twig_Profiler_Profile($this->getTemplateName(), "block", "sonata_type_model_list_widget"));

        $__internal_44205a7dd391f6f3dffc8e5778d5da5fbd54d05b87b2a1fb53993a291332e896 = $this->env->getExtension("Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension");
        $__internal_44205a7dd391f6f3dffc8e5778d5da5fbd54d05b87b2a1fb53993a291332e896->enter($__internal_44205a7dd391f6f3dffc8e5778d5da5fbd54d05b87b2a1fb53993a291332e896_prof = new Twig_Profiler_Profile($this->getTemplateName(), "block", "sonata_type_model_list_widget"));

        // line 50
        echo "
env, (isset($context["id"]) ? $context["id"] : $this->getContext($context, "id")), "html", null, true);
        echo "\" class=\"field-container\">
        env, (isset($context["id"]) ? $context["id"] : $this->getContext($context, "id")), "html", null, true);
        echo "\" class=\"field-actions\">
            env, (isset($context["id"]) ? $context["id"] : $this->getContext($context, "id")), "html", null, true);
        echo "\" class=\"field-short-description\">
                ";
        // line 53
        if ($this->getAttribute($this->getAttribute($this->getAttribute((isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "field_description", array()), "associationadmin", array()), "id", array(0 => $this->getAttribute((isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "value", array())), "method")) {
            // line 54
            echo "                    ";
            echo $this->env->getRuntime('Symfony\Bridge\Twig\Extension\HttpKernelRuntime')->renderFragment($this->env->getExtension('Symfony\Bridge\Twig\Extension\RoutingExtension')->getUrl("sonata_admin_short_object_information", array("code" => $this->getAttribute($this->getAttribute($this->getAttribute(            // line 55
(isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "field_description", array()), "associationadmin", array()), "code", array()), "objectId" => $this->getAttribute($this->getAttribute($this->getAttribute(            // line 56
(isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "field_description", array()), "associationadmin", array()), "id", array(0 => $this->getAttribute((isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "value", array())), "method"), "uniqid" => $this->getAttribute($this->getAttribute($this->getAttribute(            // line 57
(isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "field_description", array()), "associationadmin", array()), "uniqid", array()))));
            // line 58
            echo "
                ";
        } elseif (($this->getAttribute($this->getAttribute($this->getAttribute(        // line 59
(isset($context["sonata_admin"]) ? $context["sonata_admin"] : null), "field_description", array(), "any", false, true), "options", array(), "any", false, true), "placeholder", array(), "any", true, true) && $this->getAttribute($this->getAttribute($this->getAttribute((isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "field_description", array()), "options", array()), "placeholder", array()))) {
            // line 60
            echo "
                        ";
            // line 61
            echo twig_escape_filter($this->env, $this->env->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->trans($this->getAttribute($this->getAttribute($this->getAttribute((isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "field_description", array()), "options", array()), "placeholder", array()), array(), "SonataAdminBundle"), "html", null, true);
            echo "

                ";
        }
        // line 64
        echo "

                ";
        // line 67
        if ((($this->getAttribute($this->getAttribute($this->getAttribute((isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "field_description", array()), "associationadmin", array()), "hasroute", array(0 => "list"), "method") && $this->getAttribute($this->getAttribute($this->getAttribute((isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "field_description", array()), "associationadmin", array()), "isGranted", array(0 => "LIST"), "method")) && (isset($context["btn_list"]) ? $context["btn_list"] : $this->getContext($context, "btn_list")))) {
            // line 68
            echo "                    env, $this->getAttribute($this->getAttribute($this->getAttribute((isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "field_description", array()), "associationadmin", array()), "generateUrl", array(0 => "list"), "method"), "html", null, true);
            echo "\"
                       onclick=\"return start_field_dialog_form_list_";
            // line 69
            echo twig_escape_filter($this->env, (isset($context["id"]) ? $context["id"] : $this->getContext($context, "id")), "html", null, true);
            echo "(this);\"
                       class=\"btn btn-info btn-sm sonata-ba-action\"
                       title=\"";
            // line 71
            echo twig_escape_filter($this->env, $this->env->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->trans((isset($context["btn_list"]) ? $context["btn_list"] : $this->getContext($context, "btn_list")), array(), (isset($context["btn_catalogue"]) ? $context["btn_catalogue"] : $this->getContext($context, "btn_catalogue"))), "html", null, true);
            echo "\"
                            >

                        ";
            // line 74
            echo twig_escape_filter($this->env, $this->env->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->trans((isset($context["btn_list"]) ? $context["btn_list"] : $this->getContext($context, "btn_list")), array(), (isset($context["btn_catalogue"]) ? $context["btn_catalogue"] : $this->getContext($context, "btn_catalogue"))), "html", null, true);
            echo "

                ";
        }
        // line 77
        echo "
                ";
        // line 78
        if ((($this->getAttribute($this->getAttribute($this->getAttribute((isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "field_description", array()), "associationadmin", array()), "hasroute", array(0 => "create"), "method") && $this->getAttribute($this->getAttribute($this->getAttribute((isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "field_description", array()), "associationadmin", array()), "isGranted", array(0 => "CREATE"), "method")) && (isset($context["btn_add"]) ? $context["btn_add"] : $this->getContext($context, "btn_add")))) {
            // line 79
            echo "                    env, $this->getAttribute($this->getAttribute($this->getAttribute((isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "field_description", array()), "associationadmin", array()), "generateUrl", array(0 => "create"), "method"), "html", null, true);
            echo "\"
                       onclick=\"return start_field_dialog_form_add_";
            // line 80
            echo twig_escape_filter($this->env, (isset($context["id"]) ? $context["id"] : $this->getContext($context, "id")), "html", null, true);
            echo "(this);\"
                       class=\"btn btn-success btn-sm sonata-ba-action\"
                       title=\"";
            // line 82
            echo twig_escape_filter($this->env, $this->env->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->trans((isset($context["btn_add"]) ? $context["btn_add"] : $this->getContext($context, "btn_add")), array(), (isset($context["btn_catalogue"]) ? $context["btn_catalogue"] : $this->getContext($context, "btn_catalogue"))), "html", null, true);
            echo "\"
                            >

                        ";
            // line 85
            echo twig_escape_filter($this->env, $this->env->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->trans((isset($context["btn_add"]) ? $context["btn_add"] : $this->getContext($context, "btn_add")), array(), (isset($context["btn_catalogue"]) ? $context["btn_catalogue"] : $this->getContext($context, "btn_catalogue"))), "html", null, true);
            echo "

                ";
        }
        // line 88
        echo "

                ";
        // line 91
        if ((($this->getAttribute($this->getAttribute($this->getAttribute((isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "field_description", array()), "associationadmin", array()), "hasRoute", array(0 => "delete"), "method") && $this->getAttribute($this->getAttribute($this->getAttribute((isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "field_description", array()), "associationadmin", array()), "isGranted", array(0 => "DELETE"), "method")) && (isset($context["btn_delete"]) ? $context["btn_delete"] : $this->getContext($context, "btn_delete")))) {
            // line 92
            echo "                    env, (isset($context["id"]) ? $context["id"] : $this->getContext($context, "id")), "html", null, true);
            echo "(this);\"
                       class=\"btn btn-danger btn-sm sonata-ba-action\"
                       title=\"";
            // line 95
            echo twig_escape_filter($this->env, $this->env->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->trans((isset($context["btn_delete"]) ? $context["btn_delete"] : $this->getContext($context, "btn_delete")), array(), (isset($context["btn_catalogue"]) ? $context["btn_catalogue"] : $this->getContext($context, "btn_catalogue"))), "html", null, true);
            echo "\"
                            >

                        ";
            // line 98
            echo twig_escape_filter($this->env, $this->env->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->trans((isset($context["btn_delete"]) ? $context["btn_delete"] : $this->getContext($context, "btn_delete")), array(), (isset($context["btn_catalogue"]) ? $context["btn_catalogue"] : $this->getContext($context, "btn_catalogue"))), "html", null, true);
            echo "

                ";
        }
        // line 101
        echo "

            ";
        // line 105
        echo $this->env->getRuntime('Symfony\Bridge\Twig\Form\TwigRenderer')->searchAndRenderBlock((isset($context["form"]) ? $context["form"] : $this->getContext($context, "form")), 'widget');
        echo "

env, (isset($context["id"]) ? $context["id"] : $this->getContext($context, "id")), "html", null, true);
        echo "\">

    ";
        // line 113
        $this->loadTemplate("SonataDoctrineMongoDBAdminBundle:CRUD:edit_mongo_association_script.html.twig", "SonataDoctrineMongoDBAdminBundle:Form:form_admin_fields.html.twig", 113)->display($context);

        $__internal_44205a7dd391f6f3dffc8e5778d5da5fbd54d05b87b2a1fb53993a291332e896->leave($__internal_44205a7dd391f6f3dffc8e5778d5da5fbd54d05b87b2a1fb53993a291332e896_prof);

        $__internal_ce0142fd50523a0025043988e9639587d38b493df741ef4dcfe42f996011d7b5->leave($__internal_ce0142fd50523a0025043988e9639587d38b493df741ef4dcfe42f996011d7b5_prof);

    }

    // line 116
    public function block_sonata_type_admin_widget($context, array $blocks = array())
    {
        $__internal_c0ac1daab7755a973c38e27c3762ff41582bd0b26b6e60e8685d320787ce9b60 = $this->env->getExtension("Symfony\\Bundle\\WebProfilerBundle\\Twig\\WebProfilerExtension");
        $__internal_c0ac1daab7755a973c38e27c3762ff41582bd0b26b6e60e8685d320787ce9b60->enter($__internal_c0ac1daab7755a973c38e27c3762ff41582bd0b26b6e60e8685d320787ce9b60_prof = new Twig_Profiler_Profile($this->getTemplateName(), "block", "sonata_type_admin_widget"));

        $__internal_1bead7fa14fd4612ea6d1d465de4c33d87dc8144525856d8798093143c9c60e1 = $this->env->getExtension("Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension");
        $__internal_1bead7fa14fd4612ea6d1d465de4c33d87dc8144525856d8798093143c9c60e1->enter($__internal_1bead7fa14fd4612ea6d1d465de4c33d87dc8144525856d8798093143c9c60e1_prof = new Twig_Profiler_Profile($this->getTemplateName(), "block", "sonata_type_admin_widget"));

        // line 117
        echo "    ";
        // line 118
        echo "    ";
        if (($this->getAttribute($this->getAttribute((isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "field_description", array()), "mappingtype", array()) == "one")) {
            // line 119
            echo "        ";
            $this->displayBlock("sonata_admin_mongo_one_widget", $context, $blocks);
            echo "
    ";
        } elseif (($this->getAttribute($this->getAttribute(        // line 120
(isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "field_description", array()), "mappingtype", array()) == "many")) {
            // line 121
            echo "        ";
            $this->displayBlock("sonata_admin_mongo_many_widget", $context, $blocks);
            echo "
    ";
        } else {
            // line 123
            echo "        INVALID MODE : ";
            echo twig_escape_filter($this->env, (isset($context["id"]) ? $context["id"] : $this->getContext($context, "id")), "html", null, true);
            echo "
    ";
        }

        $__internal_1bead7fa14fd4612ea6d1d465de4c33d87dc8144525856d8798093143c9c60e1->leave($__internal_1bead7fa14fd4612ea6d1d465de4c33d87dc8144525856d8798093143c9c60e1_prof);

        $__internal_c0ac1daab7755a973c38e27c3762ff41582bd0b26b6e60e8685d320787ce9b60->leave($__internal_c0ac1daab7755a973c38e27c3762ff41582bd0b26b6e60e8685d320787ce9b60_prof);

    }

    // line 127
    public function block_sonata_type_collection_widget($context, array $blocks = array())
    {
        $__internal_01b23d5942f5e9fa141ab854b4573c648844e28b3e5578c50f4b6c4ec796f03e = $this->env->getExtension("Symfony\\Bundle\\WebProfilerBundle\\Twig\\WebProfilerExtension");
        $__internal_01b23d5942f5e9fa141ab854b4573c648844e28b3e5578c50f4b6c4ec796f03e->enter($__internal_01b23d5942f5e9fa141ab854b4573c648844e28b3e5578c50f4b6c4ec796f03e_prof = new Twig_Profiler_Profile($this->getTemplateName(), "block", "sonata_type_collection_widget"));

        $__internal_bb61bc547e223ecdf17eb7829bfe282ecfa1fd36bd899177a8e44774da195dae = $this->env->getExtension("Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension");
        $__internal_bb61bc547e223ecdf17eb7829bfe282ecfa1fd36bd899177a8e44774da195dae->enter($__internal_bb61bc547e223ecdf17eb7829bfe282ecfa1fd36bd899177a8e44774da195dae_prof = new Twig_Profiler_Profile($this->getTemplateName(), "block", "sonata_type_collection_widget"));

        // line 128
        echo "    ";
        if (($this->getAttribute($this->getAttribute((isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "field_description", array()), "mappingtype", array()) == "many")) {
            // line 129
            echo "        ";
            $this->displayBlock("sonata_admin_mongo_collection", $context, $blocks);
            echo "
    ";
        } else {
            // line 131
            echo "        INVALID MODE : ";
            echo twig_escape_filter($this->env, (isset($context["id"]) ? $context["id"] : $this->getContext($context, "id")), "html", null, true);
            echo " - type : sonata_type_collection - mapping : ";
            echo twig_escape_filter($this->env, $this->getAttribute($this->getAttribute((isset($context["sonata_admin"]) ? $context["sonata_admin"] : $this->getContext($context, "sonata_admin")), "field_description", array()), "mappingtype", array()), "html", null, true);
            echo "
    ";
        }

        $__internal_bb61bc547e223ecdf17eb7829bfe282ecfa1fd36bd899177a8e44774da195dae->leave($__internal_bb61bc547e223ecdf17eb7829bfe282ecfa1fd36bd899177a8e44774da195dae_prof);

        $__internal_01b23d5942f5e9fa141ab854b4573c648844e28b3e5578c50f4b6c4ec796f03e->leave($__internal_01b23d5942f5e9fa141ab854b4573c648844e28b3e5578c50f4b6c4ec796f03e_prof);

    }

    public function getTemplateName()
    {
        return "SonataDoctrineMongoDBAdminBundle:Form:form_admin_fields.html.twig";
    }

    public function isTraitable()
    {
        return false;
    }

    public function getDebugInfo()
    {
        return array (  377 => 131,  371 => 129,  368 => 128,  359 => 127,  345 => 123,  339 => 121,  337 => 120,  332 => 119,  329 => 118,  327 => 117,  318 => 116,  308 => 113,  300 => 108,  294 => 105,  288 => 101,  282 => 98,  276 => 95,  271 => 93,  268 => 92,  266 => 91,  261 => 88,  255 => 85,  249 => 82,  244 => 80,  239 => 79,  237 => 78,  234 => 77,  228 => 74,  222 => 71,  217 => 69,  212 => 68,  210 => 67,  205 => 64,  199 => 61,  196 => 60,  194 => 59,  191 => 58,  189 => 57,  188 => 56,  187 => 55,  185 => 54,  183 => 53,  179 => 52,  175 => 51,  170 => 50,  161 => 49,  147 => 45,  145 => 44,  139 => 42,  137 => 41,  132 => 40,  130 => 39,  125 => 38,  123 => 37,  120 => 36,  117 => 34,  115 => 30,  106 => 29,  95 => 26,  86 => 25,  75 => 22,  66 => 21,  55 => 18,  46 => 17,  11 => 13,);
    }

    /** @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead */
    public function getSource()
    {
        @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED);

        return $this->getSourceContext()->getCode();
    }

    public function getSourceContext()
    {
        return new Twig_Source("{#

This file is part of the Sonata package.

(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
(c) Kévin Dunglas <dunglas@gmail.com>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}

{% extends 'SonataAdminBundle:Form:form_admin_fields.html.twig' %}

{# Custom Sonata Admin Extension #}
{% block sonata_admin_mongo_one_widget %}
    {% include 'SonataDoctrineMongoDBAdminBundle:CRUD:edit_mongo_one.html.twig' %}
{% endblock %}

{% block sonata_admin_mongo_many_widget %}
    {% include 'SonataDoctrineMongoDBAdminBundle:CRUD:edit_mongo_many.html.twig' %}
{% endblock %}

{% block sonata_admin_mongo_collection %}
    {% include 'SonataDoctrineMongoDBAdminBundle:CRUD:edit_mongo_collection.html.twig' %}
{% endblock %}

{% block sonata_type_model_widget %}
    {#
        This is not the best way to do if
        TODO : improve this part
    #}

    {#model {{ sonata_admin.field_description.mappingtype }}#}

    {% if sonata_admin.field_description is empty %}
        {{ block('choice_widget') }}
    {% elseif sonata_admin.field_description.mappingtype == 'one' %}
        {{ block('sonata_admin_mongo_one_widget') }}
    {% elseif sonata_admin.field_description.mappingtype == 'many' %}
        {{ block('sonata_admin_mongo_many_widget') }}
    {% else %}
        {#INVALID MODE : {{ id }}#}
        {{ block('choice_widget') }}
    {% endif %}
{% endblock %}

{% block sonata_type_model_list_widget %}

                {% if sonata_admin.field_description.associationadmin.id(sonata_admin.value) %}
                    {{ render(url('sonata_admin_short_object_information', {
                        'code':     sonata_admin.field_description.associationadmin.code,
                        'objectId': sonata_admin.field_description.associationadmin.id(sonata_admin.value),
                        'uniqid':   sonata_admin.field_description.associationadmin.uniqid
                    })) }}
                {% elseif sonata_admin.field_description.options.placeholder is defined and sonata_admin.field_description.options.placeholder %}

                        {{ sonata_admin.field_description.options.placeholder|trans({}, 'SonataAdminBundle') }}

                {% endif %}

                {% if sonata_admin.field_description.associationadmin.hasroute('list') and sonata_admin.field_description.associationadmin.isGranted('LIST') and btn_list %}

                        {{ btn_list|trans({}, btn_catalogue) }}

                {% endif %}

                {% if sonata_admin.field_description.associationadmin.hasroute('create') and sonata_admin.field_description.associationadmin.isGranted('CREATE') and btn_add %}

                        {{ btn_add|trans({}, btn_catalogue) }}

                {% endif %}

                {% if sonata_admin.field_description.associationadmin.hasRoute('delete') and sonata_admin.field_description.associationadmin.isGranted('DELETE') and btn_delete %}

                        {{ btn_delete|trans({}, btn_catalogue) }}

                {% endif %}

            {{ form_widget(form) }}

    {% include 'SonataDoctrineMongoDBAdminBundle:CRUD:edit_mongo_association_script.html.twig' %}
{% endblock %}

{% block sonata_type_admin_widget %}
    {#admin {{ sonata_admin.field_description.mappingtype }}#}
    {% if sonata_admin.field_description.mappingtype == 'one' %}
        {{ block('sonata_admin_mongo_one_widget') }}
    {% elseif sonata_admin.field_description.mappingtype == 'many' %}
        {{ block('sonata_admin_mongo_many_widget') }}
    {% else %}
        INVALID MODE : {{ id }}
    {% endif %}
{% endblock %}

{% block sonata_type_collection_widget %}
    {% if sonata_admin.field_description.mappingtype == 'many' %}
        {{ block('sonata_admin_mongo_collection') }}
    {% else %}
        INVALID MODE : {{ id }} - type : sonata_type_collection - mapping : {{ sonata_admin.field_description.mappingtype }}
    {% endif %}
{% endblock %}
", "SonataDoctrineMongoDBAdminBundle:Form:form_admin_fields.html.twig", "/home/pi/www/vendor/sonata-project/doctrine-mongodb-admin-bundle/Sonata/DoctrineMongoDBAdminBundle/Resources/views/Form/form_admin_fields.html.twig");
    }
}


text:
<?php

namespace Sylius\Bundle\CoreBundle\Installer\Checker;

use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;

/**
 * @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
 */
final class CommandDirectoryChecker
{
    /**
     * @var string
     */
    private $name;

    /**
     * @var Filesystem
     */
    private $filesystem;

    /**
     * @param Filesystem $filesystem
     */
    public function __construct(Filesystem $filesystem)
    {
        $this->filesystem = $filesystem;
    }

    /**
     * {@inheritdoc}
     */
    public function ensureDirectoryExists($directory, OutputInterface $output)
    {
        if (!is_dir($directory)) {
            $this->createDirectory($directory, $output);
        }
    }

    /**
     * {@inheritdoc}
     */
    public function ensureDirectoryIsWritable($directory, OutputInterface $output)
    {
        try {
            $this->changePermissionsRecursively($directory, $output);
        } catch (AccessDeniedException $exception) {
            $output->writeln('');
            $output->writeln($this->createBadPermissionsMessage());

            throw new \RuntimeException(
                sprintf('Set "%s" writable recursively and run command "<comment>%s</comment>"', $exception->getMessage(), $this->name)
            );
        }
    }

    /**
     * {@inheritdoc}
     */
    public function setCommandName($name)
    {
        $this->name = $name;
    }

    /**
     * @param string $directory
     * @param OutputInterface $output
     */
    private function createDirectory($directory, OutputInterface $output)
    {
        try {
            $this->filesystem->mkdir($directory, 0755);
        } catch (IOException $exception) {
            $output->writeln('');
            $output->writeln($this->createUnexistingDirectoryMessage());

            throw new \RuntimeException(
                sprintf('Create directory "%s" and run command "<comment>%s</comment>"', realpath($directory), $this->name)
            );
        }

        $output->writeln(sprintf('<comment>Created "%s" directory.</comment>', realpath($directory)));
    }

    /**
     * @param string $directory
     * @param OutputInterface $output
     */
    private function changePermissionsRecursively($directory, OutputInterface $output)
    {
        if (is_file($directory) && is_writable($directory)) {
            return;
        }

        if (!is_writable($directory)) {
            $this->changePermissions($directory, $output);

            return;
        }

        foreach (new RecursiveDirectoryIterator($directory, \FilesystemIterator::CURRENT_AS_FILEINFO) as $subdirectory) {
            if ('.' !== $subdirectory->getFilename()[0]) {
                $this->changePermissionsRecursively($subdirectory->getPathname(), $output);
            }
        }
    }

    /**
     * @param string $directory
     * @param OutputInterface $output
     *
     * @throws AccessDeniedException if directory/file permissions cannot be changed
     */
    private function changePermissions($directory, OutputInterface $output)
    {
        try {
            $this->filesystem->chmod($directory, 0755, 0000, true);

            $output->writeln(sprintf('<comment>Changed "%s" permissions to 0755.</comment>', realpath($directory)));
        } catch (IOException $exception) {
            throw new AccessDeniedException(realpath(dirname($directory)));
        }
    }

    /**
     * @return string
     */
    private function createUnexistingDirectoryMessage()
    {
        return '<error>Cannot run command due to unexisting directory (tried to create it automatically, failed).</error>'.PHP_EOL;
    }

    /**
     * @return string
     */
    private function createBadPermissionsMessage()
    {
        return '<error>Cannot run command due to bad directory permissions (tried to change permissions to 0755).</error>'.PHP_EOL;
    }
}


text:
package org.apache.drill.exec.store.dfs.easy;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import org.apache.drill.common.exceptions.ExecutionSetupException;
import org.apache.drill.common.expression.SchemaPath;
import org.apache.drill.common.logical.FormatPluginConfig;
import org.apache.drill.common.logical.StoragePluginConfig;
import org.apache.drill.exec.physical.EndpointAffinity;
import org.apache.drill.exec.physical.base.AbstractFileGroupScan;
import org.apache.drill.exec.physical.base.FileGroupScan;
import org.apache.drill.exec.physical.base.GroupScan;
import org.apache.drill.exec.physical.base.PhysicalOperator;
import org.apache.drill.exec.physical.base.ScanStats;
import org.apache.drill.exec.planner.physical.PlannerSettings;
import org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint;
import org.apache.drill.exec.store.StoragePluginRegistry;
import org.apache.drill.exec.store.dfs.DrillFileSystem;
import org.apache.drill.exec.store.dfs.FileSelection;
import org.apache.drill.exec.store.schedule.AffinityCreator;
import org.apache.drill.exec.store.schedule.AssignmentCreator;
import org.apache.drill.exec.store.schedule.BlockMapBuilder;
import org.apache.drill.exec.store.schedule.CompleteFileWork;
import org.apache.drill.exec.store.schedule.CompleteFileWork.FileWorkImpl;
import org.apache.drill.exec.util.ImpersonationUtil;

import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterators;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;

@JsonTypeName("fs-scan")
public class EasyGroupScan extends AbstractFileGroupScan{
  private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(EasyGroupScan.class);

  private FileSelection selection;
  private final EasyFormatPlugin<?> formatPlugin;
  private int maxWidth;
  private List<SchemaPath> columns;

  private ListMultimap<Integer, CompleteFileWork> mappings;
  private List<CompleteFileWork> chunks;
  private List<EndpointAffinity> endpointAffinities;
  private String selectionRoot;

  @JsonCreator
  public EasyGroupScan(
      @JsonProperty("userName") String userName,
      @JsonProperty("files") List<String> files, //
      @JsonProperty("storage") StoragePluginConfig storageConfig, //
      @JsonProperty("format") FormatPluginConfig formatConfig, //
      @JacksonInject StoragePluginRegistry engineRegistry, //
      @JsonProperty("columns") List<SchemaPath> columns,
      @JsonProperty("selectionRoot") String selectionRoot
      ) throws IOException, ExecutionSetupException {
        this(ImpersonationUtil.resolveUserName(userName),
            FileSelection.create(null, files, selectionRoot),
            (EasyFormatPlugin<?>)engineRegistry.getFormatPlugin(storageConfig, formatConfig),
            columns,
            selectionRoot);
  }

  public EasyGroupScan(String userName, FileSelection selection, EasyFormatPlugin<?> formatPlugin, String selectionRoot)
      throws IOException {
    this(userName, selection, formatPlugin, ALL_COLUMNS, selectionRoot);
  }

  public EasyGroupScan(
      String userName,
      FileSelection selection, //
      EasyFormatPlugin<?> formatPlugin, //
      List<SchemaPath> columns,
      String selectionRoot
      ) throws IOException{
    super(userName);
    this.selection = Preconditions.checkNotNull(selection);
    this.formatPlugin = Preconditions.checkNotNull(formatPlugin, "Unable to load format plugin for provided format config.");
    this.columns = columns == null || columns.size() == 0? ALL_COLUMNS : columns;
    this.selectionRoot = selectionRoot;
    initFromSelection(selection, formatPlugin);
  }

  @JsonIgnore
  public Iterable<CompleteFileWork> getWorkIterable() {
    return new Iterable<CompleteFileWork>() {
      @Override
      public Iterator<CompleteFileWork> iterator() {
        return Iterators.unmodifiableIterator(chunks.iterator());
      }
    };
  }

  private EasyGroupScan(final EasyGroupScan that) {
    super(that.getUserName());
    selection = that.selection;
    formatPlugin = that.formatPlugin;
    columns = that.columns;
    selectionRoot = that.selectionRoot;
    chunks = that.chunks;
    endpointAffinities = that.endpointAffinities;
    maxWidth = that.maxWidth;
    mappings = that.mappings;
  }

  private void initFromSelection(FileSelection selection, EasyFormatPlugin<?> formatPlugin) throws IOException {
    final DrillFileSystem dfs = ImpersonationUtil.createFileSystem(getUserName(), formatPlugin.getFsConf());
    this.selection = selection;
    BlockMapBuilder b = new BlockMapBuilder(dfs, formatPlugin.getContext().getBits());
    this.chunks = b.generateFileWork(selection.getStatuses(dfs), formatPlugin.isBlockSplittable());
    this.maxWidth = chunks.size();
    this.endpointAffinities = AffinityCreator.getAffinityMap(chunks);
  }

  public String getSelectionRoot() {
    return selectionRoot;
  }

  @Override
  public int getMaxParallelizationWidth() {
    return maxWidth;
  }

  @Override
  public ScanStats getScanStats(final PlannerSettings settings) {
    return formatPlugin.getScanStats(settings, this);
  }

  @JsonProperty("files")
  public List<String> getFiles() {
    return selection.getFiles();
  }

  @JsonProperty("columns")
  public List<SchemaPath> getColumns() {
    return columns;
  }

  @JsonIgnore
  public FileSelection getFileSelection() {
    return selection;
  }

  @Override
  public void modifyFileSelection(FileSelection selection) {
    this.selection = selection;
  }

  @Override
  public PhysicalOperator getNewWithChildren(List<PhysicalOperator> children) throws ExecutionSetupException {
    assert children == null || children.isEmpty();
    return new EasyGroupScan(this);
  }

  @Override
  public List<EndpointAffinity> getOperatorAffinity() {
    if (endpointAffinities == null) {
        logger.debug("chunks: {}", chunks.size());
        endpointAffinities = AffinityCreator.getAffinityMap(chunks);
    }
    return endpointAffinities;
  }

  @Override
  public void applyAssignments(List<DrillbitEndpoint> incomingEndpoints) {
    mappings = AssignmentCreator.getMappings(incomingEndpoints, chunks, formatPlugin.getContext());
  }

  private void createMappings(List<EndpointAffinity> affinities) {
    List<DrillbitEndpoint> endpoints = Lists.newArrayList();
    for (EndpointAffinity e : affinities) {
      endpoints.add(e.getEndpoint());
    }
    this.applyAssignments(endpoints);
  }

  @Override
  public EasySubScan getSpecificScan(int minorFragmentId) {
    if (mappings == null) {
      createMappings(this.endpointAffinities);
    }
    assert minorFragmentId < mappings.size() : String.format(
        "Mappings length [%d] should be longer than minor fragment id [%d] but it isn't.", mappings.size(),
        minorFragmentId);

    List<CompleteFileWork> filesForMinor = mappings.get(minorFragmentId);

    Preconditions.checkArgument(!filesForMinor.isEmpty(),
        String.format("MinorFragmentId %d has no read entries assigned", minorFragmentId));

    EasySubScan subScan = new EasySubScan(getUserName(), convert(filesForMinor), formatPlugin, columns, selectionRoot);
    subScan.setOperatorId(this.getOperatorId());
    return subScan;
  }

  private List<FileWorkImpl> convert(List<CompleteFileWork> list) {
    List<FileWorkImpl> newList = Lists.newArrayList();
    for (CompleteFileWork f : list) {
      newList.add(f.getAsFileWork());
    }
    return newList;
  }

  @JsonProperty("storage")
  public StoragePluginConfig getStorageConfig() {
    return formatPlugin.getStorageConfig();
  }

  @JsonProperty("format")
  public FormatPluginConfig getFormatConfig() {
    return formatPlugin.getConfig();
  }

  @Override
  public String toString() {
    final String pattern = "EasyGroupScan [selectionRoot=%s, numFiles=%s, columns=%s, files=%s]";
    return String.format(pattern, selectionRoot, getFiles().size(), columns, getFiles());
  }

  @Override
  public String getDigest() {
    return toString();
  }

  @Override
  public GroupScan clone(List<SchemaPath> columns) {
    if (!formatPlugin.supportsPushDown()) {
      throw new IllegalStateException(String.format("%s doesn't support pushdown.", this.getClass().getSimpleName()));
    }
    EasyGroupScan newScan = new EasyGroupScan(this);
    newScan.columns = columns;
    return newScan;
  }

  @Override
  public FileGroupScan clone(FileSelection selection) throws IOException {
    EasyGroupScan newScan = new EasyGroupScan(this);
    newScan.initFromSelection(selection, formatPlugin);
    newScan.mappings = null; /* the mapping will be created later when we get specific scan
                                since the end-point affinities are not known at this time */
    return newScan;
  }

  @Override
  @JsonIgnore
  public boolean canPushdownProjects(List<SchemaPath> columns) {
    return formatPlugin.supportsPushDown();
  }

}


text:
{% extends "admin/admin_base.html" %}

{% include "_edges_common_css.html" %}

{% block page_title %}Journals{% endblock %}

{% block admin_content %}

Journals

{% endblock %}

{% block extra_js_bottom %}

    {% include "_edges_common_js.html" %}

{% endblock %}


text:
<?php
/**
 * @author Smotrov Dmitriy <dsxack@gmail.com>
 */

namespace dsxack\contextjs;

use yii\base\Application;
use yii\base\BootstrapInterface;

class Bootstrap implements BootstrapInterface {

    /**
     * Bootstrap method to be called during application bootstrap stage.
     * @param Application $app the application currently running
     */
    public function bootstrap($app) {
        if (!View::isApplicationComponent()) {
            return;
        }

        $app->on(Application::EVENT_BEFORE_ACTION, function () use ($app) {
            if ($app->request->isAjax) {
                return;
            }

            /** @var $view View */
            $view = $app->view;

            $view->registerJs(sprintf('%s.run()',
                $view->getScriptNamespace()
            ), View::POS_LOAD);
        });
    }
}


text:
use strict;
# We have to import the minecraft api module to do anything in the minecraft world
use lib 'mcpi';
use Minecraft;
use warnings;

# Create a connection to Minecraft
# Any communication with the world must use this object
my $mc = Minecraft::->create();

while(1){
    my @hits = $mc->events->pollBlockHits();
    my $numOfHits = @hits;
   # print("$numOfHits\n");
    if ($numOfHits > 0){
        foreach(@hits){print "$_\n";}

    }
    sleep(1)
}